1<?php 2/* 3 * e107 website system 4 * 5 * Copyright (C) 2008-2013 e107 Inc (e107.org) 6 * Released under the terms and conditions of the 7 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) 8 * 9 * News Administration 10 * 11*/ 12 13require_once('../class2.php'); 14 15if (!getperms('H|N|H0|H1|H2|H3|H4|H5')) 16{ 17 e107::redirect('admin'); 18 exit; 19} 20 21e107::coreLan('newspost', true); 22 23 24e107::css('inline', " 25 26.submitnews.modal-body { height: 500px; overflow-y: scroll; } 27 28"); 29 30class news_admin extends e_admin_dispatcher 31{ 32 33 protected $modes = array( 34 'main' => array( 35 'controller' => 'news_admin_ui', 36 'path' => null, 37 'ui' => 'news_form_ui', 38 'uipath' => null, 39 'perm' => null 40 ), 41 'cat' => array( 42 'controller' => 'news_cat_ui', 43 'path' => null, 44 'ui' => 'news_cat_form_ui', 45 'uipath' => null 46 ), 47 'sub' => array( 48 'controller' => 'news_sub_ui', 49 'path' => null, 50 'ui' => 'news_sub_form_ui', 51 'uipath' => null, 52 'perm' => null 53 ) 54 ); 55 56 57 protected $access = array(); // as below, but uses userclasses instead of admin perms eg. e_UC_* or numeric userclass value. 58 59 60 //Route access. (equivalent of getperms() for each mode/action ) 61 protected $perm = array( 62 'main/list' => 'H|H0|H1|H2', 63 'main/create' => 'H|H0', 64 'main/edit' => 'H|H1', // edit button and inline editing in list mode. 65 'main/delete' => 'H|H2', // delete button in list mode. 66 'cat/list' => 'H', 67 'cat/create' => 'H|H3|H4|H5', 68 'cat/edit' => 'H|H4', // edit button and inline editing in list mode. 69 'cat/delete' => 'H|H5', // delete button in list mode. 70 'main/settings' => '0', 71 'sub/list' => 'N' 72 ); 73 74 75 76 protected $adminMenu = array( 77 'main/list' => array('caption'=> LAN_LIST), 78 'main/create' => array('caption'=> NWSLAN_45), // Create/Edit News Item 79 // 'cat/list' => array('caption'=> NWSLAN_46, 'perm' => '7'), // Category List 80 'other' => array('divider'=> true), 81 'cat/list' => array('caption'=> LAN_CATEGORIES), // Create Category. 82 'cat/create' => array('caption'=> LAN_NEWS_63), // Category List 83 'other2' => array('divider'=> true), 84 'main/settings' => array('caption'=> LAN_PREFS), // Preferences 85 // 'main/submitted' => array('caption'=> LAN_NEWS_64, 'perm' => 'N'), // Submitted News 86 'sub/list' => array('caption'=> NWSLAN_47), // Submitted News 87 // 'main/maint' => array('caption'=> LAN_NEWS_55, 'perm' => '0') // Maintenance 88 ); 89 90 protected $adminMenuIcon = 'e-news-24'; 91 92 93 protected $adminMenuAliases = array( 94 'main/edit' => 'main/list', 95 'cat/edit' => 'cat/list' 96 ); 97 98 protected $menuTitle = ADLAN_0; 99 100 function init() 101 { 102 103 104 if(!empty($_GET['sub']) && $_GET['action'] == 'create') 105 { 106 $this->adminMenu['sub/list']['selected'] = true; 107 $this->getResponse()->setTitle(NWSLAN_47); 108 } 109 110 111 112 } 113 114 115} 116 117 118class news_cat_ui extends e_admin_ui 119{ 120 protected $pluginTitle = ADLAN_0; // "News" 121 protected $pluginName = 'core'; 122 protected $eventName = 'news-category'; 123 protected $table = "news_category"; 124 protected $pid = "category_id"; 125 protected $perPage = 0; //no limit 126 protected $batchDelete = false; 127 protected $batchExport = true; 128 protected $sortField = 'category_order'; 129 protected $listOrder = "category_order ASC"; 130 131 protected $tabs = array(LAN_GENERAL, LAN_ADVANCED); 132 133 protected $fields = array( 134 'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'), 135 'category_id' => array('title'=> LAN_ID, 'type' => 'number', 'width' =>'5%', 'forced'=> TRUE, 'readonly'=>TRUE), 136 'category_icon' => array('title'=> LAN_ICON, 'type' => 'icon', 'data' => 'str', 'width' => '100px', 'thclass' => 'center', 'class'=>'center', 'readParms'=>array('legacy'=>'{e_IMAGE}icons/'), 'writeParms' => 'glyphs=1', 'readonly'=>FALSE, 'batch' => FALSE, 'filter'=>FALSE), // thumb=60&thumb_urlraw=0&thumb_aw=60 137 'category_name' => array('title'=> LAN_TITLE, 'type' => 'text', 'data'=>'str', 'inline'=>true, 'width' => 'auto', 'thclass' => 'left', 'readonly'=>FALSE, 'validate' => true, 'writeParms'=>array('size'=>'xxlarge')), 138 139 'category_meta_description' => array('title'=> LAN_DESCRIPTION, 'type' => 'textarea', 'data'=>'str', 'inline'=>true, 'width' => 'auto', 'thclass' => 'left','readParms' => 'expand=...&truncate=150&bb=1', 'readonly'=>FALSE, 'writeParms'=>array('size'=>'xxlarge')), 140 'category_meta_keywords' => array('title'=> LAN_KEYWORDS, 'type' => 'tags', 'data'=>'str', 'inline'=>true, 'width' => 'auto', 'thclass' => 'left', 'readonly'=>FALSE), 141 'category_sef' => array('title'=> LAN_SEFURL, 'type' => 'text', 'data'=>'str', 'inline'=>true, 'width' => 'auto', 'readonly'=>FALSE, 'writeParms'=>array('size'=>'xxlarge', 'sef'=>'category_name')), // Display name 142 'category_manager' => array('title'=> LAN_MANAGER,'type' => 'userclass', 'tab'=>1, 'inline'=>true, 'width' => 'auto', 'data' => 'int','batch'=>TRUE, 'filter'=>TRUE), 143 'category_template' => array('title'=> LAN_TEMPLATE, 'type' => 'layouts', 'tab'=>1, 'width'=>'auto', 'thclass' => 'left', 'class'=> 'left', 'writeParms' => array(),'help'=>'Template to use as the default view' ), 144 145 'category_order' => array('title'=> LAN_ORDER, 'type' => 'text', 'tab'=>1, 'width' => 'auto', 'thclass' => 'right', 'class'=> 'right' ), 146 'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'batch'=>true, 'filter'=>true, 'width' => '10%', 'forced'=>TRUE, 'thclass' => 'center last', 'class' => 'center', 'sort' => true) 147 ); 148 149 protected $fieldpref = array('checkboxes', 'category_icon', 'category_id', 'category_name', 'category_description', 'category_sef', 'category_manager', 'category_order', 'options'); 150 151 // protected $newspost; 152 153 function init() 154 { 155 $this->fields['category_template']['writeParms'] = array('plugin' => 'news', 'id' => 'news', 'merge' => false, 'default' => '('.LAN_OPTIONAL.')'); 156 // $this->newspost = new admin_newspost; 157 } 158 159 160 161 162 163 // function createPage() 164 // { 165 // $this->newspost->show_categories(); 166 // } 167 168 public function beforeCreate($new_data, $old_data) 169 { 170 if(empty($new_data['category_sef'])) 171 { 172 $new_data['category_sef'] = eHelper::title2sef($new_data['category_name']); 173 } 174 else 175 { 176 $new_data['category_sef'] = eHelper::secureSef($new_data['category_sef']); 177 } 178 179 $sef = e107::getParser()->toDB($new_data['category_sef']); 180 181 if(e107::getDb()->count('news_category', '(*)', "category_sef='{$sef}'")) 182 { 183 e107::getMessage()->addError(LAN_NEWS_65); 184 return false; 185 } 186 187 if(empty($new_data['category_order'])) 188 { 189 $c = e107::getDb()->count('news_category'); 190 $new_data['category_order'] = $c ? $c : 0; 191 } 192 193 return $new_data; 194 } 195 196 197 public function beforeUpdate($new_data, $old_data, $id) 198 { 199 if(isset($new_data['category_sef']) && empty($new_data['category_sef'])) 200 { 201 $new_data['category_sef'] = eHelper::title2sef($new_data['category_name']); 202 } 203 204 $sef = e107::getParser()->toDB($new_data['category_sef']); 205 206 /* $message = "Error: sef: ".$sef." id: ".$id."\n"; 207 $message .= print_r($new_data,true); 208 file_put_contents(e_LOG.'uiAjaxResponseInline.log', $message."\n\n", FILE_APPEND);*/ 209 210 if(e107::getDb()->count('news_category', '(*)', "category_sef='{$sef}' AND category_id !=".intval($id))) 211 { 212 e107::getMessage()->addError(LAN_NEWS_65); 213 return false; 214 } 215 216 return $new_data; 217 } 218 219} 220 221class news_cat_form_ui extends e_admin_form_ui 222{ 223 224} 225 226 227 228 229 230// Submitted News Area. 231 232 233class news_sub_ui extends e_admin_ui 234{ 235 protected $pluginTitle = ADLAN_0; // "News" 236 protected $pluginName = 'core'; 237 protected $table = "submitnews"; 238 protected $pid = "submitnews_id"; 239 protected $perPage = 10; //no limit 240 protected $batchDelete = true; 241 protected $formQuery = "mode=main&action=create"; 242 protected $listOrder = "submitnews_id desc"; 243 244 245 246// submitnews_id submitnews_name submitnews_email submitnews_title submitnews_category submitnews_item submitnews_datestamp submitnews_ip submitnews_auth submitnews_file 247 protected $fields = array( 248 'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'), 249 'submitnews_id' => array('title'=> LAN_ID, 'type' => 'number', 'width' =>'5%', 'forced'=> TRUE, 'readonly'=>TRUE), 250 'submitnews_datestamp' => array('title' => LAN_NEWS_32, 'type' => 'datestamp', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false), 251 252 'submitnews_title' => array('title'=> LAN_TITLE, 'type' => 'method', 'width' => '35%', 'thclass' => 'left', 'readonly'=>TRUE), 253 254 'submitnews_category' => array('title'=> LAN_CATEGORY, 'type' => 'dropdown', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>FALSE), 255 'submitnews_description' => array('title'=> LAN_DESCRIPTION, 'type' => 'textarea', 'width' => 'auto', 'thclass' => 'left','readParms' => 'expand=...&truncate=150&bb=1', 'readonly'=>TRUE), 256 'submitnews_name' => array('title'=> LAN_AUTHOR, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>TRUE), 257 'submitnews_ip' => array('title'=> LAN_IP, 'type' => 'ip', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>TRUE), 258 'submitnews_auth' => array('title'=> " ", 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'class'=> 'left', 'readParms'=>"link=1" ), 259 'options' => array('title'=> LAN_OPTIONS, 'type' => "method", 'width' => '10%', 'forced'=>TRUE, 'thclass' => 'center last', 'class' => 'right') 260 ); 261 262 protected $fieldpref = array('checkboxes', 'submitnews_id', 'submitnews_datestamp', 'submitnews_title', 'submitnews_category', 'submitnews_name', 'options'); 263 264 protected $newspost; 265 266 protected $cats; 267 268 function init() 269 { 270 $sql = e107::getDb(); 271 $sql->gen("SELECT category_id,category_name FROM #news_category"); 272 while($row = $sql->fetch()) 273 { 274 $cat = $row['category_id']; 275 $this->cats[$cat] = $row['category_name']; 276 } 277 asort($this->cats); 278 $this->fields['submitnews_category']['writeParms'] = $this->cats; 279 // $this->newspost = new admin_newspost; 280 } 281 282 // function createPage() 283 // { 284 // $this->newspost->show_categories(); 285 // } 286 287 public function beforeCreate($new_data, $old_data) 288 { 289 290 } 291 292 293 public function beforeUpdate($new_data, $old_data, $id) 294 { 295 296 } 297 298} 299 300class news_sub_form_ui extends e_admin_form_ui 301{ 302 303 304 305 function submitnews_title($cur,$val) 306 { 307 $tp = e107::getParser(); 308 $row = $this->getController()->getListModel(); 309 310 $submitnews_id = $row->get('submitnews_id'); 311 $submitnews_title = $row->get('submitnews_title'); 312 $submitnews_file = $row->get('submitnews_file'); 313 $submitnews_item = $row->get('submitnews_item'); 314 315 // $text .= "<a href='#submitted_".$submitnews_id."' class='e-modal' >"; 316 317 318 $text = "<a data-toggle='modal' href='#submitted_".$submitnews_id."' data-cache='false' data-target='#submitted_".$submitnews_id."' class='e-tip' title='".LAN_PREVIEW."'>"; 319 $text .= $tp->toHTML($submitnews_title,FALSE,'emotes_off, no_make_clickable'); 320 $text .= '</a>'; 321 322 $text .= ' 323 324 <div id="submitted_'.$submitnews_id.'" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true"> 325 <div class="modal-dialog modal-lg" > 326 <div class="modal-content"> 327 <div class="modal-header"> 328 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 329 <h4>'.$tp->toHTML($submitnews_title,false,'TITLE').'</h4> 330 </div> 331 <div class="submitnews modal-body"> 332 <p>'; 333 334 $text .= $tp->toHTML($submitnews_item,TRUE); 335 336 if($submitnews_file) 337 { 338 $tmp = explode(',',$submitnews_file); 339 340 $text .= "<br />"; 341 342 343 foreach($tmp as $imgfile) 344 { 345 if(strpos("{e_UPLOAD}",$imgfile) === false) 346 { 347 $imgfile = e_UPLOAD.$imgfile; 348 } 349 350 $url = $tp->thumbUrl($imgfile,array('aw'=>400),true); 351 $text .= "<br /><img src='".$url."' alt='".$imgfile."' />"; 352 } 353 } 354 355 356 $text .= '</p> 357 </div> 358 <div class="modal-footer"> 359 <a href="#" data-dismiss="modal" class="btn btn-primary">'.LAN_NEWS_67.'</a> 360 </div> 361 </div> 362 </div></div>'; 363 364 return $text; 365 366 367 368 } 369 370 // Override the default Options field. 371 function options($parms, $value, $id, $attributes) 372 { 373 374 if($attributes['mode'] == 'read') 375 { 376 $text = "<div class='btn-group'>"; 377 $approved = $this->getController()->getListModel()->get('submitnews_auth'); // approved; 378 379 380 $row = $this->getController()->getListModel(); 381 382 $submitnews_id = $row->get('submitnews_id'); 383 $submitnews_title = $row->get('submitnews_title'); 384 $submitnews_file = $row->get('submitnews_file'); 385 $submitnews_item = $row->get('submitnews_item'); 386 387 // $text .= "<a href='#submitted_".$submitnews_id."' class='e-modal' >"; 388 389 390 $text = "<a class='btn btn-default btn-secondary btn-large' data-toggle='modal' href='#submitted_".$submitnews_id."' data-cache='false' data-target='#submitted_".$submitnews_id."' title='".LAN_PREVIEW."'>".ADMIN_VIEW_ICON."</a>"; 391 392 393 394 395 if($approved == 0) 396 { 397 //$text = $this->submit_image('submitnews['.$id.']', 1, 'execute', NWSLAN_58); 398 $text .= "<a class='btn btn-default btn-secondary btn-large' title=\"".LAN_NEWS_96."\" href='".e_SELF."?mode=main&action=create&sub={$id}'>".ADMIN_EXECUTE_ICON."</a>"; 399 // NWSLAN_103; 400 } 401 else // Already submitted; 402 { 403 404 } 405 406 $text .= $this->submit_image('etrigger_delete['.$id.']', $id, 'delete', LAN_DELETE.' [ ID: '.$id.' ]', array('class' => 'btn btn-default btn-secondary btn-large action delete')); 407 $text .= "</div>"; 408 return $text; 409 } 410 } 411 412} 413 414 415 416 417 418 419// Main News Area. 420 421class news_admin_ui extends e_admin_ui 422{ 423 protected $pluginTitle = ADLAN_0; // "News" 424 protected $pluginName = 'core'; 425 protected $eventName = 'news'; 426 protected $table = "news"; 427 protected $pid = "news_id"; 428 protected $perPage = 10; //no limit 429 protected $batchDelete = true; 430 protected $batchExport = true; 431 protected $batchCopy = true; 432 protected $batchLink = true; 433 protected $listQry = "SELECT n.*, nc.category_name, nc.category_sef, u.user_id,u.user_name FROM `#news` AS n 434 LEFT JOIN `#news_category` AS nc ON n.news_category = nc.category_id 435 LEFT JOIN `#user` AS u ON n.news_author = u.user_id "; // without any Order or Limit. 436 437 protected $listOrder = "news_id desc"; 438 439 protected $tabs = array(LAN_NEWS_52, 'SEO', LAN_NEWS_53); 440 441 protected $url = array( 442 'route' => 'news/view/item', 443 'name' => 'news_title', 444 'description' => 'news_summary', 445 'vars'=> array('news_id' => true, 'news_sef' => true, 'category_id' => 'news_category', 'category_sef' => true) 446 ); // 'link' only needed if profile not provided. 447 448 449 450 protected $fields = array( 451 'checkboxes' => array('title' => '', 'type' => null, 'width' => '3%', 'thclass' => 'center first', 'class' => 'center', 'nosort' => true, 'toggle' => 'news_selected', 'forced' => TRUE), 452 'news_id' => array('title' => LAN_ID, 'type' => 'text', 'width' => '5%', 'thclass' => 'center', 'class' => 'center', 'nosort' => false, 'readParms'=>'link=sef&target=blank'), 453 'news_thumbnail' => array('title' => NWSLAN_67, 'type' => 'method', 'data'=>'str', 'width' => '110px', 'thclass' => 'center', 'class' => "center", 'nosort' => false, 'readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60', 'readonly'=>false), 454 'news_title' => array('title' => LAN_TITLE, 'type' => 'text', 'data'=>'safestr', 'filter'=>true, 'tab'=>0, 'writeParms'=> array('required'=> 1, 'size'=>'block-level'), 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false), 455 'news_summary' => array('title' => LAN_SUMMARY, 'type' => 'text', 'data'=>'safestr', 'filter'=>true, 'tab'=>0, 'inline'=>true, 'writeParms'=>'size=block-level', 'width' => 'auto', 'thclass' => 'left', 'class' => 'left', 'nosort' => false), 456 'news_body' => array('title' => "", 'type' => 'method', 'data'=>'str', 'tab'=>0, 'nolist'=>true, 'writeParms'=>'nolabel=1', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false), 457 'news_extended' => array('title' => "", 'type' => null, 'data'=>'str', 'tab'=>0, 'nolist'=>true, 'writeParms'=>'nolabel=1', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false), 458 459 'news_meta_keywords' => array('title' => LAN_KEYWORDS, 'type' => 'tags', 'data'=>'safestr', 'filter'=>true, 'tab'=>1, 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false), 460 'news_meta_description' => array('title' => LAN_DESCRIPTION,'type' => 'textarea', 'data'=>'safestr','filter'=>true, 'tab'=>1, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'writeParms'=>array('size'=>'xxlarge')), 461 'news_meta_robots' => array('title' => LAN_ROBOTS, 'type' => 'dropdown', 'data'=>'safestr', 'tab'=>1, 'inline'=>true, 'readParms'=>array('type'=>'checkboxes'), 'writeParms'=>array('multiple'=>1), 'width' => 'auto', 'thclass' => 'left', 'class' => 'left', 'nosort' => false, 'batch'=>true, 'filter'=>true), 462 463 'news_sef' => array('title' => LAN_SEFURL, 'type' => 'text', 'batch'=>1, 'data'=>'str', 'tab'=>1, 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'writeParms'=>array('size'=>'xxlarge', 'show'=>1, 'sef'=>'news_title')), 464 'news_ping' => array('title' => LAN_PING, 'type' => 'checkbox', 'tab'=>1, 'data'=>false, 'writeParms'=>'value=0', 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false), 465 466 'news_author' => array('title' => LAN_AUTHOR, 'type' => 'method', 'tab'=>2, 'readParms'=>'idField=user_id&nameField=user_name', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false), 467 'news_datestamp' => array('title' => LAN_NEWS_32, 'type' => 'datestamp', 'data'=>'int', 'tab'=>2, 'writeParms'=>'type=datetime', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'filter'=>true), 468 'news_category' => array('title' => NWSLAN_6, 'type' => 'dropdown', 'data'=>'int', 'tab'=>0, 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'batch'=>true, 'filter'=>true), 469 'news_start' => array('title' => LAN_START, 'type' => 'datestamp', 'data'=>'int', 'tab'=>2, 'writeParms'=>'type=datetime', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false), 470 'news_end' => array('title' => LAN_END, 'type' => 'datestamp', 'data'=>'int', 'tab'=>2, 'writeParms'=>'type=datetime', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false), 471 'news_class' => array('title' => LAN_VISIBILITY, 'type' => 'userclass', 'tab'=>2, 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'batch'=>true, 'filter'=>true), 472 473 'news_template' => array('title' => LAN_TEMPLATE, 'type' => 'method', 'data'=>'safestr', 'tab'=>2, 'inline'=>true, 'writeParms'=>array('plugin'=>'news', 'id'=>'news_view', 'area'=> 'front', 'merge'=>false), 'width' => 'auto', 'thclass' => 'left', 'class' => 'left', 'nosort' => false, 'batch'=>true, 'filter'=>true), 474 475 'news_render_type' => array('title' => LAN_LOCATION, 'type' => 'dropdown', 'data'=>'safestr', 'tab'=>2, 'inline'=>true, 'readParms'=>array('type'=>'checkboxes'), 'width' => 'auto', 'thclass' => 'left', 'class' => 'left', 'nosort' => false, 'batch'=>true, 'filter'=>true), 476 477 'news_sticky' => array('title' => LAN_NEWS_28, 'type' => 'boolean', 'data'=>'int', 'tab'=>2, 'width' => 'auto', 'thclass' => 'center', 'inline'=>true, 'class' => 'center', 'nosort' => false, 'batch'=>true, 'filter'=>true), 478 'news_allow_comments' => array('title' => LAN_COMMENTS, 'type' => 'boolean', 'data'=>'int', 'tab'=>2, 'writeParms'=>'inverse=1', 'width' => 'auto', 'thclass' => 'center', 'class' => 'center', 'nosort' => false,'batch'=>true, 'filter'=>true,'readParms'=>'reverse=1'), 479 'news_comment_total' => array('title' => LAN_NEWS_60, 'type' => 'number', 'data'=>'int', 'tab'=>2, 'noedit'=>true, 'width' => '10%', 'thclass' => '', 'class' => null, 'nosort' => false), 480 // admin_news_notify 481 'news_email_notify' => array('title' => LAN_NEWS_103, 'type' => 'checkbox', 'tab'=>2, 'data'=>false, 'writeParms'=>array('show'=>1, 'tdClassRight'=>'form-inline'), 'help'=>LAN_NEWS_109), 482 'submitted_id' => array('title' => LAN_NEWS_68, 'type' => 'hidden', 'tab'=>2, 'data'=>false, 'writeParms'=>'show=0'), 483 'options' => array('title' => LAN_OPTIONS, 'type' => null, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center', 'nosort' => true, 'forced' => TRUE) 484 485 ); 486 487 protected $fieldpref = array('checkboxes','news_id', 'news_thumbnail', 'news_title', 'news_datestamp', 'news_category', 'news_class', 'options'); 488 489 /* //TODO 490 protected $prefs = array( 491 492 'news_category' => array('title' => NWSLAN_127, 'type' => 'dropdown', 'help'=> "Determines how the default news page should appear."), 493 'news_ping_services' => array('title' => "Ping Services", 'type' => 'textarea', 'data'=> 'help'=> ">Notify these services when you create/update news items. <br />One per line."), 494 495 496 497 ); 498 */ 499 500 protected $cats = array(); 501 protected $newspost; 502 protected $addons = array(); 503 504 protected $news_renderTypes = array( // TODO Placement location and template should be separate. 505 506 '0' => LAN_NEWS_69, 507 '1' => LAN_NEWS_70, 508 '4' => LAN_NEWS_71, 509 '2' => LAN_NEWS_72, 510 '3' => LAN_NEWS_73, 511 '5' => LAN_NEWS_74, 512 '6' => LAN_NEWS_97, 513 //'5' => LAN_NEWS_75 514 ); 515 516 public function beforeCreate($new_data, $old_data) 517 { 518 if(!empty($new_data['news_thumbnail']) && !empty($_GET['sub'])) // From SubmitNews. 519 { 520 $new_data['news_thumbnail'] = $this->processSubNewsImages($new_data['news_thumbnail']); 521 } 522 523 524 $new_data['news_thumbnail'] = $this->processThumbs($new_data['news_thumbnail']); 525 526 if(empty($new_data['news_datestamp'])) 527 { 528 $new_data['news_datestamp'] = time(); 529 } 530 531 532 533 $new_data['news_sef'] = empty($new_data['news_sef']) ? eHelper::title2sef($new_data['news_title']) : eHelper::secureSef($new_data['news_sef']); 534 535 $this->checkSEFSimilarity($new_data); 536 537 538 $tmp = explode(chr(35), $new_data['news_author']); 539 $new_data['news_author'] = intval($tmp[0]); 540 541 if(E107_DBG_SQLQUERIES) 542 { 543 e107::getMessage()->addInfo("<h3>Raw _POST data</h3>".print_a($_POST,true)); 544 } 545 546 return $new_data; 547 } 548 549 private function processSubNewsImages($row) 550 { 551 $new = array(); 552 foreach($row as $k=>$v) 553 { 554 if(empty($v)) 555 { 556 continue; 557 } 558 559 $f = str_replace('{e_UPLOAD}','',$v); 560 561 if($bbpath = e107::getMedia()->importFile($f,'news', e_UPLOAD.$f)) 562 { 563 $new[] = $bbpath; 564 } 565 } 566 567 568 e107::getMessage()->addDebug("<h3>Processing/importing SubNews Images</h3>".print_a($new,true)); 569 570 return implode(",",$new); 571 572 573 574 575 } 576 577 578 public function beforeUpdate($new_data, $old_data, $id) 579 { 580 if(!empty($new_data['news_thumbnail'])) 581 { 582 $new_data['news_thumbnail'] = $this->processThumbs($new_data['news_thumbnail']); 583 } 584 585 if(isset($new_data['news_datestamp']) && empty($new_data['news_datestamp'])) 586 { 587 $new_data['news_datestamp'] = time(); 588 } 589 590 if(isset($new_data['news_sef']) && empty($new_data['news_sef']) && !empty($new_data['news_title'])) 591 { 592 $new_data['news_sef'] = eHelper::title2sef($new_data['news_title']); 593 } 594 595 596 $this->checkSEFSimilarity($new_data); 597 598 if(!empty($new_data['news_author'])) 599 { 600 $tmp = explode(chr(35), $new_data['news_author']); 601 $new_data['news_author'] = intval($tmp[0]); 602 } 603 604 if(E107_DBG_SQLQUERIES) 605 { 606 e107::getMessage()->addInfo("<h3>Raw _POST data</h3>".print_a($_POST,true)); 607 } 608 609 return $new_data; 610 } 611 612 613 /** 614 * Display a warning if there is a mismatch with the SEF Url. 615 * @param $new_data 616 */ 617 private function checkSEFSimilarity($new_data) 618 { 619 if(e_LANGUAGE === "Japanese" || e_LANGUAGE === "Korean") 620 { 621 return null; 622 } 623 624 625 $expectedSEF = eHelper::title2sef($new_data['news_title']); 626 similar_text($expectedSEF,$new_data['news_sef'],$percSimilar); 627 628 if($percSimilar < 60) 629 { 630 e107::getMessage()->addWarning(LAN_NEWS_108); // The SEF URL is unlike the title of your news item. 631 } 632 633 634 } 635 636 637 public function afterCreate($new_data, $old_data, $id) 638 { 639 640 if(!empty($_POST['news_email_notify'])) 641 { 642 $this->triggerNotify($new_data); 643 } 644 645 if(!empty($new_data['submitted_id'])) 646 { 647 e107::getDb()->update('submitnews', "submitnews_auth = 1 WHERE submitnews_id = ".intval($new_data['submitted_id'])." LIMIT 1"); 648 } 649 650 if(!empty($new_data['news_sef']) && ($existingSef = e107::getDb()->retrieve('news', 'news_sef', "news_sef = '".$new_data['news_sef']."' AND news_id != ".$id))) 651 { 652 $existingLAN = e107::getParser()->lanVars(LAN_NEWS_95,$existingSef,true ); 653 e107::getMessage()->addWarning($existingLAN); 654 } 655 656 657 $this->processPings(); 658 e107::getEvent()->trigger('newspost',$new_data); 659 // e107::getEvent()->trigger('admin_news_created',$new_data); 660 $evdata = array('method'=>'create', 'table'=>'news', 'id'=>$id, 'plugin'=>'news', 'function'=>'submit_item'); 661 e107::getMessage()->addInfo(e107::getEvent()->triggerHook($evdata)); 662 $this->clearCache(); 663 } 664 665 666 667 public function afterUpdate($new_data, $old_data, $id) 668 { 669 670 // e107::getMessage()->addInfo(print_a($new_data,true)); 671 672 if(!empty($_POST['news_email_notify'])) 673 { 674 $this->triggerNotify($new_data); 675 } 676 677 $this->processPings(); 678 679 e107::getEvent()->trigger('newsupd', $new_data); 680 // e107::getEvent()->trigger('admin_news_updated',$new_data); 681 682 $this->clearCache(); 683 684 if(!empty($new_data['news_sef']) && ($existingSef = e107::getDb()->retrieve('news', 'news_sef', "news_sef = '".$new_data['news_sef']."' AND news_id != ".$id))) 685 { 686 $existingLAN = e107::getParser()->lanVars(LAN_NEWS_95,$existingSef,true ); 687 e107::getMessage()->addWarning($existingLAN); 688 } 689 690 //$ecache->clear("nq_news_"); - supported by cache::clear() now 691 //$ecache->clear("nomd5_news_"); supported by cache::clear() now 692 693 694 $evdata = array('method'=>'update', 'table'=>'news', 'id'=>$id, 'plugin'=>'news', 'function'=>'submit_item'); 695 e107::getMessage()->addInfo(e107::getEvent()->triggerHook($evdata)); 696 } 697 698 699 700 701 // Trigger the news email notification trigger. (@see admin->notify ) 702 private function triggerNotify($new_data) 703 { 704 $visibility = explode(",", $new_data['news_class']); 705 706 if(in_array(e_UC_PUBLIC, $visibility)) 707 { 708 e107::getEvent()->trigger('admin_news_notify',$new_data); 709 e107::getMessage()->addSuccess(LAN_NEWS_105); 710 } 711 else 712 { 713 e107::getMessage()->addWarning(LAN_NEWS_106); 714 } 715 716 717 } 718 719 720 721 public function afterDelete($deleted_data, $id, $deleted_check) 722 { 723 $this->clearCache(); 724 } 725 726 function clearCache() 727 { 728 $ecache = e107::getCache(); 729 $ecache->clear("news.php"); //TODO change it to 'news_*' everywhere 730 $ecache->clear("news_", false, true); //NEW global news cache prefix 731 $ecache->clear("othernews"); //TODO change it to 'news_other' everywhere 732 $ecache->clear("othernews2"); //TODO change it to 'news_other2' everywhere 733 734 735 //$ecache->clear("nq_news_"); - supported by cache::clear() now 736 //$ecache->clear("nomd5_news_"); supported by cache::clear() now 737 return $this; 738 } 739 740 /** 741 * For future use: multiple-images. 742 */ 743 private function processThumbs($postedImage) 744 { 745 if(is_array($postedImage)) 746 { 747 return implode(",", $postedImage); 748 } 749 else 750 { 751 return $postedImage; 752 } 753 754 } 755 756 757// 758 759 760 function ukfield($a, $b) // custom sort order on create/edit pags. 761 { 762 763 $newOrder = array ( 764 'checkboxes', 765 'news_id', 766 'news_category', 767 'news_title' , 768 'news_summary', 769 'news_template', 770 'news_render_type', 771 772 'news_body', 773 'news_extended', 774 'news_thumbnail', 775 776 'news_sef' , 777 'news_meta_keywords', 778 'news_meta_description' , 779 'news_meta_robots' , 780 'news_ping', 781 782 'news_email_notify', 783 'news_allow_comments' , 784 'news_start' , 785 'news_end' , 786 'news_author' , 787 'news_datestamp' , 788 'news_class', 789 'news_sticky', 790 791 'news_comment_total' , 792 'submitted_id', 793 'options' ); 794 795 796 797 foreach($this->addons as $plug=>$config) 798 { 799 if(!empty($config['fields'])) 800 { 801 foreach($config['fields'] as $field=>$tmp) 802 { 803 $newOrder[] = "x_".$plug."_".$field; 804 // echo $field; 805 } 806 } 807 } 808 809 810 811 $order = array_flip($newOrder); 812 813 if($order[$a] == $order[$b]) 814 { 815 return 0; 816 } 817 818 return ($order[$a] < $order[$b]) ? -1 : 1; 819 820 } 821 822 function handleListImageBbcodeBatch($selected, $field, $value) 823 { 824 $sql = e107::getDb(); 825 826 $status = array(); 827 828 $ids = implode(",", e107::getParser()->filter($selected,'int')); 829 830 if($data = $sql->retrieve("news","news_id,news_body","news_id IN (".$ids.") ",true)) 831 { 832 foreach($data as $row) 833 { 834 $id = $row['news_id']; 835 $update = array( 836 'news_body' => e107::getBB()->imgToBBcode($row['news_body'], true), 837 'WHERE' => 'news_id = '.$row['news_id'] 838 ); 839 840 $status[$id] = $sql->update('news',$update) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; 841 } 842 843 } 844 845 $mes = e107::getMessage(); 846 847 foreach($status as $k=>$v) 848 { 849 $mes->add(LAN_UPDATED.": ".$k, $v); 850 } 851 852 $this->clearCache(); 853 854 return true; 855 } 856 857 858 859 860 861 function init() 862 { 863 864 $this->addons = e107::getAddonConfig('e_admin',null, 'config', $this); 865 866 if(!empty($_POST['save_prefs'])) 867 { 868 $this->saveSettings(); 869 } 870 871 if(e_DEBUG == true) // allowing manual fixing of comment total in DEBUG mode. 872 { 873 $this->fields['news_comment_total']['noedit'] = false; 874 $this->fields['news_comment_total']['inline'] = true; 875 } 876 877 878 $this->fields['news_email_notify']['writeParms']['post'] = "<span class='radio-inline radio inline'><a class='e-modal btn btn-xs btn-mini btn-primary' data-modal-caption='".ADLAN_149."' href='notify.php?iframe=1&type=admin_news_notify#/tab-news-events'>".LAN_CONFIGURE."</a></span>"; 879 880 // e107::getMessage()->addDebug(print_a($_POST,true)); 881 882 if($this->getAction() == 'create' || $this->getAction() == 'edit') 883 { 884 uksort($this->fields, array($this, 'ukfield')); 885 886 // $fieldKeys = array_keys($this->fields); 887 // print_a($fieldKeys); 888 889 if(!empty($_GET['sub'])) 890 { 891 $this->loadSubmitted($_GET['sub']); 892 } 893 894 } 895 896 897 if(deftrue('e_DEBUG')) 898 { 899 $this->batchOptions['Modify News body'] = array('image_bbcode'=>"Convert all images in news-body to [img] bbcodes."); 900 } 901 902 903 if(deftrue("ADMINUI_NEWS_VISIBILITY_MULTIPLE")) // bc workaround for those who need it. Add to e107_config.php . 904 { 905 $this->fields['news_class']['type'] = 'userclasses'; 906 } 907 908 // $mod = $this->getModel(); 909 // $info = print_a($mod, true); 910 911 // e107::getMessage()->addInfo($info); 912 913 914 915 916 $sql = e107::getDb(); 917 $sql->gen("SELECT category_id,category_name FROM #news_category"); 918 while($row = $sql->fetch()) 919 { 920 $cat = $row['category_id']; 921 $this->cats[$cat] = $row['category_name']; 922 } 923 asort($this->cats); 924 $this->fields['news_category']['writeParms']['optArray'] = $this->cats; 925 $this->fields['news_category']['writeParms']['size'] = 'xlarge'; 926 $this->fields['news_render_type']['writeParms']['optArray'] = $this->news_renderTypes; // array(NWSLAN_75,NWSLAN_76,NWSLAN_77,NWSLAN_77." 2","Featurebox"); 927 $this->fields['news_render_type']['writeParms']['multiple'] = 1; 928 929 $this->fields['news_meta_robots']['writeParms']['optArray'] = e107::getSingleton('eResponse')->getRobotTypes(); 930 $this->fields['news_meta_robots']['writeParms']['title'] = e107::getSingleton('eResponse')->getRobotDescriptions(); 931 $this->fields['news_meta_robots']['writeParms']['multiple'] = 1; 932 // $this->fields['news_meta_robots']['writeParms']['default'] = 'blank'; 933 // $this->newspost = new admin_newspost; 934 // $this->newspost->news_renderTypes = $this->news_renderTypes; 935 // $this->newspost->observer(); 936 937 } 938 939 940 function saveSettings() 941 { 942 if(!getperms('0')) 943 { 944 $this->noPermissions(); 945 } 946 947 948 $temp = array(); 949 $temp['newsposts'] = intval($_POST['newsposts']); 950 $temp['newsposts_archive'] = intval($_POST['newsposts_archive']); 951 $temp['newsposts_archive_title'] = e107::getParser()->toDB($_POST['newsposts_archive_title']); 952 $temp['news_cats'] = intval($_POST['news_cats']); 953 $temp['nbr_cols'] = intval($_POST['nbr_cols']); 954 $temp['subnews_attach'] = intval($_POST['subnews_attach']); 955 $temp['subnews_resize'] = intval($_POST['subnews_resize']); 956 $temp['subnews_attach_minsize'] = e107::getParser()->filter($_POST['subnews_attach_minsize']); 957 $temp['subnews_class'] = intval($_POST['subnews_class']); 958 $temp['subnews_htmlarea'] = intval($_POST['subnews_htmlarea']); 959 $temp['news_subheader'] = e107::getParser()->toDB($_POST['news_subheader']); 960 $temp['news_newdateheader'] = intval($_POST['news_newdateheader']); 961 $temp['news_unstemplate'] = intval($_POST['news_unstemplate']); 962 $temp['news_editauthor'] = intval($_POST['news_editauthor']); 963 $temp['news_ping_services'] = explode("\n",$_POST['news_ping_services']); 964 $temp['news_default_template'] = preg_replace('#[^\w\pL\-]#u', '', $_POST['news_default_template']); 965 $temp['news_list_limit'] = intval($_POST['news_list_limit']); 966 $temp['news_list_templates'] = e107::getParser()->toDB($_POST['news_list_templates']); 967 $temp['news_cache_timeout'] = intval($_POST['news_cache_timeout']); 968 969 e107::getConfig()->updatePref($temp); 970 971 if(e107::getConfig()->save(false)) 972 { 973 e107::getAdminLog()->logArrayDiffs($temp, e107::getPref(), 'NEWS_06'); 974 $this->clearCache(); 975 } 976 } 977 978 979 980 981 function processPings() 982 { 983 984 // Ping Changes to Services. 985 $pingServices = e107::getPref('news_ping_services'); 986 //TODO Use Ajax with progress-bar. 987 988 $mes = e107::getMessage(); 989 990 $mes->addDebug(LAN_NEWS_107,'default',true); 991 992 if(!empty($_POST['news_ping']) && (count($pingServices)>0) && (in_array(e_UC_PUBLIC, $_POST['news_class']))) 993 { 994 $mes->addDebug("Initiating ping",'default',true); 995 996 include (e_HANDLER.'xmlrpc/xmlrpc.inc.php'); 997 include (e_HANDLER.'xmlrpc/xmlrpcs.inc.php'); 998 include (e_HANDLER.'xmlrpc/xmlrpc_wrappers.inc.php'); 999 1000 $extendedServices = array('blogsearch.google.com'); 1001 1002 $port = 80; 1003 1004 foreach($pingServices as $fullUrl) 1005 { 1006 $fullUrl = str_replace("http://","", trim($fullUrl)); 1007 list($server,$path) = explode("/",$fullUrl, 2); 1008 1009 $path = "/".$path; 1010 1011 $weblog_name = SITENAME; 1012 $weblog_url = $_SERVER['HTTP_HOST'].e_HTTP; 1013 $changes_url = $_SERVER['HTTP_HOST'].e107::getUrl()->create('news/view/item', $_POST); // $_SERVER['HTTP_HOST'].e_HTTP."news.php?extend.".$_POST['news_id']; 1014 $cat_or_rss = $_SERVER['HTTP_HOST'].e_PLUGIN_ABS."rss_menu/rss.php?1.2"; 1015 $extended = (in_array($server, $extendedServices)) ? true : false; 1016 1017 if($this->ping($server, $port, $path, $weblog_name, $weblog_url, $changes_url, $cat_or_rss, $extended)) 1018 { 1019 e107::getMessage()->addInfo("Successfully Pinged: ".$server .' with:<br />url: '.$changes_url .'<br />rss: '.$cat_or_rss , 'default', true); 1020 } 1021 else 1022 { 1023 e107::getMessage()->addDebug("Ping failed!: ".$server .' with: '.$changes_url , 'default', true); 1024 } 1025 1026 } 1027 1028 } 1029 else 1030 { 1031 // $mes->addDebug('Ping not triggerred','default',true); 1032 // $mes->addDebug("Services: ".print_a($pingServices, true),'default', true); 1033 // $mes->addDebug("Userclass: ".print_a($_POST['news_class'],true),'default', true); 1034 1035 } 1036 1037 } 1038 1039 1040 /* Multi-purpose ping for any XML-RPC server that supports the Weblogs.Com interface. */ 1041 function ping($xml_rpc_server, $xml_rpc_port, $xml_rpc_path, $weblog_name, $weblog_url, $changes_url, $cat_or_rss='', $extended = false) 1042 { 1043 $mes = e107::getMessage(); 1044 $log = e107::getAdminLog(); 1045 1046 $mes->addDebug("Attempting to ping: ".$xml_rpc_server, 'default', true); 1047 1048 1049 $name_param = new xmlrpcval($weblog_name, 'string'); 1050 $url_param = new xmlrpcval($weblog_url, 'string'); 1051 $changes_param = new xmlrpcval($changes_url, 'string'); 1052 $cat_or_rss_param = new xmlrpcval($cat_or_rss, 'string'); 1053 $method_name = ($extended) ? "weblogUpdates.extendedPing" : "weblogUpdates.ping"; 1054 1055 if ($cat_or_rss != "") 1056 { 1057 $params = array($name_param, $url_param, $changes_param, $cat_or_rss_param); 1058 $call_text = "$method_name(\"$weblog_name\", \"$weblog_url\", \"$changes_url\", \"$cat_or_rss\")"; 1059 } 1060 else 1061 { 1062 if ($changes_url != "") 1063 { 1064 $params = array($name_param, $url_param, $changes_param); 1065 $call_text = "$method_name(\"$weblog_name\", \"$weblog_url\", \"$changes_url\")"; 1066 } 1067 else 1068 { 1069 $params = array($name_param, $url_param); 1070 $call_text = "$method_name(\"$weblog_name\", \"$weblog_url\")"; 1071 } 1072 } 1073 1074 // create the message 1075 $message = new xmlrpcmsg($method_name, $params); 1076 $client = new xmlrpc_client($xml_rpc_path, $xml_rpc_server, $xml_rpc_port); 1077 $response = $client->send($message); 1078 1079 $this->log_ping("Request: " . $call_text); 1080 $this->log_ping($message->serialize(), true); 1081 1082 if ($response == 0) 1083 { 1084 $error_text = "Error: " . $xml_rpc_server . ": " . $client->errno . " " . $client->errstring; 1085 $this->report_error($error_text); 1086 $this->log_ping($error_text); 1087 $log->addArray(array('status'=>LAN_ERROR, 'service'=>$xml_rpc_server, 'url'=> $changes_url, 'response'=>$client->errstring))->save('PING_01'); 1088 1089 return false; 1090 } 1091 1092 if ($response->faultCode() != 0) 1093 { 1094 $error_text = "Error: " . $xml_rpc_server . ": " . $response->faultCode() . " " . $response->faultString(); 1095 $this->report_error($error_text); 1096 $log->addArray(array('status'=>LAN_ERROR, 'service'=>$xml_rpc_server, 'url'=> $changes_url, 'response'=>$response->faultString()))->save('PING_01'); 1097 1098 return false; 1099 } 1100 1101 $response_value = $response->value(); 1102 if ($this->debug) 1103 { 1104 $this->report_error($response_value->serialize()); 1105 } 1106 1107 $this->log_ping($response_value->serialize(), true); 1108 1109 /** @var xmlrpcval $fl_error */ 1110 $fl_error = $response_value->structmem('flerror'); 1111 1112 /** @var xmlrpcval $message */ 1113 $message = $response_value->structmem('message'); 1114 1115 // read the response 1116 if ($fl_error->scalarval() != false) 1117 { 1118 $error_text = "Error: " . $xml_rpc_server . ": " . $message->scalarval(); 1119 $this->report_error($error_text); 1120 $log->addArray(array('status'=>LAN_ERROR, 'service'=>$xml_rpc_server, 'url'=> $changes_url, 'response'=>$message->scalarval()))->save('PING_01'); 1121 1122 // $this->log_ping($error_text); 1123 return false; 1124 } 1125 1126 $log->addArray(array('status'=>LAN_OK, 'service'=>$xml_rpc_server, 'url'=> $changes_url, 'response'=>$message->scalarval()))->save('PING_01'); 1127 1128 return true; 1129 } 1130 1131 1132 1133 // save ping data to a log file 1134 function log_ping($message, $xml_data = false) 1135 { 1136 $message = $xml_data." ".$message; 1137 file_put_contents(e_LOG."news_ping.log", $message, FILE_APPEND); 1138 } 1139 1140 // sDisplay Ping errors. 1141 function report_error($message) 1142 { 1143 e107::getMessage()->addError($message, 'default', true); 1144 } 1145 1146 1147 1148 function submittedPage() 1149 { 1150 $this->newspost->show_submitted_news(); 1151 } 1152 1153 function maintPage() 1154 { 1155 1156 } 1157 1158 private function _optrange($num, $zero = true) 1159 { 1160 $tmp = range(0, $num < 0 ? 0 : $num); 1161 if(!$zero) unset($tmp[0]); 1162 return $tmp; 1163 } 1164 1165 function settingsPage() 1166 { 1167 // return $this->newspost->show_news_prefs(); 1168 1169 $pref = e107::getPref(); 1170 $frm = e107::getForm(); 1171 1172 $sefbaseDiz = str_replace(array("[br]","[","]"), array("<br />","<a href='".e_ADMIN_ABS."eurl.php'>","</a>"), NWSLAN_128 ); 1173 $pingOpt = array('placeholder'=>LAN_NEWS_87); 1174 $pingVal = (!empty($pref['news_ping_services'])) ? implode("\n",$pref['news_ping_services']) : ''; 1175 1176 $newsTemplates = array(); 1177 1178 if($newInfo = e107::getTemplateInfo('news', 'news', null, 'front', true)) //TODO 'category'=>'Categories'? research 'Use non-standard template for news layout' and integrate here. 1179 { 1180 foreach($newInfo as $k=>$val) 1181 { 1182 $newsTemplates[$k] = $val['title']; 1183 } 1184 1185 } 1186 else 1187 { 1188 $newsTemplates = array('default'=>LAN_DEFAULT, 'list'=>LAN_LIST); 1189 } 1190 1191 $text = " 1192 <form method='post' action='".e_REQUEST_URI."' id='core-newspost-settings-form'>"; 1193 1194 $tab1 = " 1195 1196 <table class='table adminform'> 1197 <colgroup> 1198 <col class='col-label' /> 1199 <col class='col-control' /> 1200 </colgroup> 1201 <tbody> 1202 <tr> 1203 <td>".NWSLAN_127."</td> 1204 <td> 1205 ".$frm->select('news_default_template', $newsTemplates, $pref['news_default_template'])." 1206 <div class='field-help'>".LAN_NEWS_88."</div> 1207 </td> 1208 </tr> 1209 1210 <tr> 1211 <td>".NWSLAN_88."</td> 1212 <td> 1213 ".$frm->select('newsposts', $this->_optrange(50, false), $pref['newsposts'])." 1214 </td> 1215 </tr> 1216 1217 <tr> 1218 <td>".LAN_NEWS_91."</td> 1219 <td> 1220 ".$frm->select('news_list_limit', $this->_optrange(50, false), $pref['news_list_limit'])." 1221 <div class='field-help'>".LAN_NEWS_92."</div> 1222 </td> 1223 </tr> 1224 1225 <tr> 1226 <td>".LAN_NEWS_93."</td> 1227 <td> 1228 ".$frm->checkboxes('news_list_templates', $this->news_renderTypes, varset($pref['news_list_templates'],0), array('useKeyValues' => 1))." 1229 <div class='field-help'>".LAN_NEWS_94."</div> 1230 </td> 1231 </tr> 1232 <tr> 1233 <td>".LAN_NEWS_98."</td> 1234 <td> 1235 ".$frm->textarea('news_ping_services', $pingVal, 4, 100, $pingOpt)." 1236 <div class='field-help'>".LAN_NEWS_89."<br />".LAN_NEWS_90."</div> 1237 </td> 1238 </tr>"; 1239 1240 1241 $tab1 .= " 1242 <tr> 1243 <td>".LAN_NEWS_110."</td> 1244 <td> 1245 ".$frm->number('news_cache_timeout',varset($pref['news_cache_timeout'],0), 6)." 1246 <div class='field-help'>".LAN_NEWS_111."</div> 1247 </td> 1248 </tr>"; 1249 1250 1251 $tab1 .= " 1252 1253 <tr> 1254 <td>".NWSLAN_86."</td> 1255 <td> 1256 ".$frm->radio_switch('news_cats', $pref['news_cats'])." 1257 </td> 1258 </tr> 1259 <tr> 1260 <td>".NWSLAN_87."</td> 1261 <td> 1262 ".$frm->select('nbr_cols', $this->_optrange(6, false), $pref['nbr_cols'])." 1263 </td> 1264 </tr> 1265 <tr> 1266 <td>".NWSLAN_115."</td> 1267 <td id='newsposts-archive-cont'> 1268 ".$frm->select('newsposts_archive', $this->_optrange(intval($pref['newsposts']) - 1), intval($pref['newsposts_archive']))." 1269 <div class='field-help'>".NWSLAN_116."</div> 1270 </td> 1271 </tr> 1272 <tr> 1273 <td>".NWSLAN_117."</td> 1274 <td> 1275 ".$frm->text('newsposts_archive_title', $pref['newsposts_archive_title'])." 1276 </td> 1277 </tr> 1278 <tr> 1279 <td>".LAN_NEWS_51."</td> 1280 <td> 1281 ".$frm->uc_select('news_editauthor', vartrue($pref['news_editauthor']), 'nobody,main,admin,classes')." 1282 </td> 1283 </tr> 1284 "; 1285 1286 1287 1288 1289 $imageSizes = array( 1290 1291 '400×300' => '400x300', 1292 '640×480' => '640x480', 1293 '800×600' => '800x600', 1294 '1024×768' => '1024x768', 1295 '1600×1200' => '2 MP (1600×1200)', 1296 '2272×1704' => '4 MP (2272×1704)', 1297 '2816×2112' => '6 MP (2816×2112)', 1298 '3264×2448' => '8 MP (3264×2448)', 1299 // 10 MP (3648×2736) 1300 // 12 MP (4096×3072) 1301 1302 ); 1303 1304 1305 1306 1307 1308 $tab2 = "<table class='table adminform'> 1309 <colgroup> 1310 <col class='col-label' /> 1311 <col class='col-control' /> 1312 </colgroup> 1313 <tbody> 1314 1315 <tr> 1316 <td>".NWSLAN_106."</td> 1317 <td> 1318 ".$frm->uc_select('subnews_class', $pref['subnews_class'], 'nobody,public,guest,member,admin,classes')." 1319 </td> 1320 </tr> 1321 <tr> 1322 <td>".NWSLAN_107."</td> 1323 <td> 1324 ".$frm->radio_switch('subnews_htmlarea', $pref['subnews_htmlarea'])." 1325 </td> 1326 </tr> 1327 <tr> 1328 <td>".NWSLAN_100."</td> 1329 <td> 1330 ".$frm->radio_switch('subnews_attach', $pref['subnews_attach'])." 1331 </td> 1332 </tr> 1333 <tr> 1334 <td>".LAN_NEWS_99."</td> 1335 <td> 1336 ".$frm->select('subnews_attach_minsize', $imageSizes, varset($pref['subnews_attach_minsize'], null), null, LAN_NEWS_100)." 1337 </td> 1338 </tr> 1339 <tr> 1340 <td>".NWSLAN_101."</td> 1341 <td> 1342 ".$frm->number('subnews_resize', $pref['subnews_resize'], 5, 'size=6&class=tbox')." 1343 <div class='field-help'>".NWSLAN_102."</div> 1344 </td> 1345 </tr> 1346 <tr> 1347 <td>".NWSLAN_120."</td> 1348 <td> 1349 ".$frm->bbarea('news_subheader', stripcslashes(vartrue($pref['news_subheader'])), 2, 'helpb')." 1350 </td> 1351 </tr> 1352 </tbody> 1353 </table> 1354 "; 1355 1356 $tab1 .= " 1357 <tr> 1358 <td>".NWSLAN_111."</td> 1359 <td> 1360 <div class='auto-toggle-area autocheck'> 1361 ".$frm->radio_switch('news_newdateheader', $pref['news_newdateheader'])." 1362 <div class='field-help'>".NWSLAN_112."</div> 1363 </div> 1364 </td> 1365 </tr> 1366 <tr> 1367 <td>".NWSLAN_113."</td> 1368 <td> 1369 <div class='auto-toggle-area autocheck'> 1370 ".$frm->radio_switch('news_unstemplate', vartrue($pref['news_unstemplate']))." 1371 <div class='field-help'>".NWSLAN_114."</div> 1372 </div> 1373 </td> 1374 </tr> 1375 1376 </tbody> 1377 </table>"; 1378 1379 $text .= $frm->tabs(array( 1380 'general' => array('caption'=>LAN_GENERAL, 'text'=>$tab1), 1381 'subnews' => array('caption'=>LAN_NEWS_101, 'text'=>$tab2) 1382 )); 1383 1384 1385 $text .= " 1386 1387 <div class='buttons-bar center'> 1388 ".$frm->admin_button('save_prefs', LAN_UPDATE, 'update')." 1389 </div> 1390 </fieldset> 1391 </form> 1392 "; 1393 return e107::getMessage()->render().$text; 1394 // e107::getRender()->tablerender(NWSLAN_90, e107::getMessage()->render().$text); 1395 1396 } 1397 1398 1399 function noPermissions($qry = '') 1400 { 1401 $url = e_SELF.($qry ? '?'.$qry : ''); 1402 if($qry !== e_QUERY) 1403 { 1404 $mes = e107::getMessage(); 1405 $mes->add('Insufficient permissions!', E_MESSAGE_ERROR, true); 1406 session_write_close(); 1407 header('Location: '.$url); 1408 } 1409 exit; 1410 } 1411 1412 1413 private function processSubmittedMedia($data) 1414 { 1415 if(empty($data)) 1416 { 1417 return false; 1418 } 1419 1420 $row = json_decode($data,true); 1421 $text = ''; 1422 foreach($row as $k) 1423 { 1424 if(!empty($k)) 1425 { 1426 $text .= $k."\n\n"; 1427 } 1428 } 1429 1430 return $text; 1431 1432 } 1433 1434 1435 function loadSubmitted($id) 1436 { 1437 $sql = e107::getDb(); 1438 $tp = e107::getParser(); 1439 1440 if ($sql->select("submitnews", "*", "submitnews_id=".intval($id))) 1441 { 1442 $row = $sql->fetch(); 1443 $data['news_title'] = $tp->dataFilter($row['submitnews_title']); 1444 $data['news_body'] = $row['submitnews_item']; 1445 $data['news_category'] = intval( $row['submitnews_category']); 1446 $data['news_body'] .= "\n[[b]".NWSLAN_49." {$row['submitnews_name']}[/b]]"; 1447 1448 if($mediaData = $this->processSubmittedMedia($row['submitnews_media'])) 1449 { 1450 $data['news_body'] .= "\n\n---\n\n".$mediaData; 1451 } 1452 1453 if(e107::getPref('wysiwyg',false)!==false) 1454 { 1455 $data['news_body'] = nl2br($data['news_body']); 1456 } 1457 1458 $data['news_author'] = $row['submitnews_user']; 1459 1460 $data['news_thumbnail'] = $row['submitnews_file']; // implode(",",$thumbs); 1461 $data['news_sef'] = eHelper::dasherize($data['news_title']); 1462 1463 $data['news_meta_keywords'] = $row['submitnews_keywords']; 1464 $data['news_summary'] = $row['submitnews_summary']; 1465 $data['news_meta_description'] = $row['submitnews_description']; 1466 1467 $data['submitted_id'] = $id; 1468 1469 foreach($data as $k=>$v) 1470 { 1471 $this->getModel()->setData($k, $v); // Override Table data. 1472 } 1473 1474 if(e_DEBUG) 1475 { 1476 e107::getMessage()->addDebug(print_a($data,true)); 1477 } 1478 } 1479 1480 1481 1482 } 1483 1484 1485 1486 1487 1488 function preCreate() 1489 { 1490 if($_GET['action'] == "edit" && !$_POST['preview']) 1491 { 1492 if(!isset($_POST['submit_news'])) 1493 { 1494 if(e107::getDb()->select('news', '*', 'news_id='.intval($_GET['id']))) 1495 { 1496 $row = e107::getDb()->fetch(); 1497 1498 // if(!isset($this->news_categories[$row['news_category']])) 1499 { 1500 // $this->noPermissions(); 1501 } 1502 1503 $_POST['news_title'] = $row['news_title']; 1504 $_POST['news_sef'] = $row['news_sef']; 1505 $_POST['news_body'] = $row['news_body']; 1506 $_POST['news_author'] = $row['news_author']; 1507 $_POST['news_extended'] = $row['news_extended']; 1508 $_POST['news_allow_comments'] = $row['news_allow_comments']; 1509 $_POST['news_class'] = $row['news_class']; 1510 $_POST['news_summary'] = $row['news_summary']; 1511 $_POST['news_sticky'] = $row['news_sticky']; 1512 $_POST['news_datestamp'] = ($_POST['news_datestamp']) ? $_POST['news_datestamp'] : $row['news_datestamp']; 1513 1514 $_POST['cat_id'] = $row['news_category']; 1515 $_POST['news_start'] = $row['news_start']; 1516 $_POST['news_end'] = $row['news_end']; 1517 $_POST['comment_total'] = e107::getDb()->db_Count("comments", "(*)", " WHERE comment_item_id={$row['news_id']} AND comment_type='0'"); 1518 $_POST['news_render_type'] = $row['news_render_type']; 1519 $_POST['news_thumbnail'] = $row['news_thumbnail']; 1520 $_POST['news_meta_keywords'] = $row['news_meta_keywords']; 1521 $_POST['news_meta_description'] = $row['news_meta_description']; 1522 } 1523 } 1524 else // on submit 1525 { 1526 if(!empty($_POST['news_meta_keywords'])) $_POST['news_meta_keywords'] = eHelper::formatMetaKeys($_POST['news_meta_keywords']); 1527 } 1528 1529 } 1530 } 1531} 1532 1533 1534class news_form_ui extends e_admin_form_ui 1535{ 1536 1537 function news_template($curVal,$mode) 1538 { 1539 if($mode === 'read') 1540 { 1541 return $curVal; 1542 } 1543 1544 1545 if($mode === 'write') 1546 { 1547 1548 if($tmp = e107::getTemplate('news', 'news', 'view')) 1549 { 1550 return LAN_DEFAULT; 1551 } 1552 1553 if($tmp = e107::getLayouts('news', 'news_view', 'front', null, false, false)) 1554 { 1555 return $this->select('news_template', $tmp, $curVal, array('size'=>'xlarge')); 1556 } 1557 1558 1559 return LAN_DEFAULT; 1560 } 1561 1562 } 1563 1564 1565 function news_author($curVal, $mode) 1566 { 1567 1568 1569 1570 1571 $pref = e107::pref('core'); 1572 $sql = e107::getDb(); 1573 1574 1575 if($mode == 'read') 1576 { 1577 $row = $this->getController()->getListModel()->getData(); 1578 // $att = $this->getController()->getFieldAttr('news_author'); 1579 // $att = array('readParms'=> array(['__idval']=>$row['user_id'idField=user_id&nameField=user_name'); 1580 return $row['user_name']; 1581 } 1582 1583 1584 1585 $text = ""; 1586 1587 if(!getperms('0') && !check_class($pref['news_editauthor'])) 1588 { 1589 1590 $auth = ($curVal) ? intval($curVal) : USERID; 1591 $sql->select("user", "user_name", "user_id={$auth} LIMIT 1"); 1592 $row = $sql->fetch(); 1593 $text .= "<input type='hidden' name='news_author' value='".$auth.chr(35).$row['user_name']."' />"; 1594 $text .= "<a href='".e107::getUrl()->create('user/profile/view', 'name='.$row['user_name'].'&id='.$curVal)."'>".$row['user_name']."</a>"; 1595 } 1596 else // allow master admin to 1597 { 1598 $text .= $this->select_open('news_author', array('size'=>'xlarge')); 1599 $qry = "SELECT user_id,user_name,user_admin FROM #user WHERE user_perms = '0' OR user_perms = '0.' OR user_perms REGEXP('(^|,)(H)(,|$)') "; 1600 1601 if(!empty($curVal)) 1602 { 1603 $qry .= " OR user_id = ".intval($curVal); // make sure existing author is included. 1604 } 1605 1606 if($pref['subnews_class'] && $pref['subnews_class']!= e_UC_GUEST && $pref['subnews_class']!= e_UC_NOBODY) 1607 { 1608 if($pref['subnews_class']== e_UC_MEMBER) 1609 { 1610 $qry .= " OR user_ban != 1 ORDER BY user_class DESC, user_name";// limit to avoid long page loads. 1611 } 1612 elseif($pref['subnews_class']== e_UC_ADMIN) 1613 { 1614 $qry .= " OR user_admin = 1 ORDER BY user_name"; 1615 } 1616 else 1617 { 1618 $qry .= " OR FIND_IN_SET(".intval($pref['subnews_class']).", user_class) ORDER BY user_name"; 1619 } 1620 } 1621 1622 // print_a($pref['subnews_class']); 1623 1624 1625 $sql->gen($qry); 1626 while($row = $sql->fetch()) 1627 { 1628 if(vartrue($curVal)) 1629 { 1630 $sel = ($curVal == $row['user_id']); 1631 } 1632 else 1633 { 1634 $sel = (USERID == $row['user_id']); 1635 } 1636 1637 $username = $row['user_name']; 1638 1639 if(!empty($row['user_admin'])) 1640 { 1641 $username .= " *"; 1642 } 1643 1644 1645 $text .= $this->option($username, $row['user_id'].chr(35).$row['user_name'], $sel); 1646 } 1647 1648 $text .= "</select> 1649 "; 1650 1651 1652 } 1653 1654 return $text; 1655 1656 } 1657 1658 1659 1660 1661 1662 1663 1664 function news_body($curVal,$mode) 1665 { 1666 $frm = e107::getForm(); 1667 $tp = e107::getParser(); 1668 1669 if($mode == 'read') 1670 { 1671 return '...'; 1672 } 1673 1674 1675 $curValExt = $this->getController()->getModel()->get('news_extended'); 1676 1677 1678 $text = '<ul class="nav nav-tabs"> 1679 <li class="active"><a href="#news-body-container" data-toggle="tab">'.NWSLAN_13.'</a></li> 1680 <li><a href="#news-extended-container" data-toggle="tab">'.NWSLAN_14.'</a></li> 1681 </ul> 1682 <div class="tab-content">'; 1683 1684 1685 $val = strstr($curVal, "[img]http") ? $curVal : str_replace("[img]../", "[img]", $curVal); 1686 $text .= "<div id='news-body-container' class='tab-pane active'>"; 1687 $text .= $frm->bbarea('news_body', $val, 'news', 'news', 'large'); 1688 $text .= "</div>"; 1689 $text .= "<div id='news-extended-container' class='tab-pane'>"; 1690 1691 $val = (strstr($curValExt, "[img]http") ? $curValExt : str_replace("[img]../", "[img]",$curValExt)); 1692 $text .= $frm->bbarea('news_extended', $val, 'extended', 'news','large'); 1693 1694 $text .= "</div> 1695 </div>"; 1696 1697 return $text; 1698 1699 } 1700 1701 1702 1703 1704 1705 function news_thumbnail($curval,$mode) 1706 { 1707 1708 if($mode == 'read') 1709 { 1710 if(strpos($curval, ",")!==false) 1711 { 1712 $tmp = explode(",",$curval); 1713 $curval = $tmp[0]; 1714 } 1715 1716 if(empty($curval)) 1717 { 1718 return ''; 1719 } 1720 1721 $vparm = array('thumb'=>'tag','w'=> 80); 1722 1723 if($thumb = e107::getParser()->toVideo($curval,$vparm)) 1724 { 1725 return $thumb; 1726 } 1727 1728 if($curval[0] != "{") 1729 { 1730 $curval = "{e_IMAGE}newspost_images/".$curval; 1731 } 1732 1733 $url = e107::getParser()->thumbUrl($curval,'aw=80'); 1734 $link = e107::getParser()->replaceConstants($curval); 1735 1736 return "<a class='e-modal' href='{$link}'><img src='{$url}' alt='".basename($curval)."' /></a>"; 1737 } 1738 1739 1740 if($mode == 'write') 1741 { 1742 $paths = array(); 1743 1744 if(!empty($_GET['sub'])) 1745 { 1746 $thumbTmp = explode(",",$curval); 1747 foreach($thumbTmp as $key=>$path) 1748 { 1749 $url = ($path[0] == '{') ? $path : e_TEMP.$path; 1750 $paths[] = e107::getParser()->thumbUrl($url,'aw=800'); ; 1751 } 1752 1753 } 1754 1755 1756 $tp = e107::getParser(); 1757 $frm = e107::getForm(); 1758 1759 // $text .= $frm->imagepicker('news_thumbnail[0]', $curval ,'','media=news&video=1'); 1760 $thumbTmp = explode(",",$curval); 1761 1762 foreach($thumbTmp as $key=>$path) 1763 { 1764 if(!empty($path) && (strpos($path, ",") == false) && $path[0] != "{" && $tp->isVideo($path) === false )//BC compat 1765 { 1766 // $thumbTmp[$key] = "{e_IMAGE}newspost_images/".$path; 1767 } 1768 } 1769 1770 $text = "<div class='mediaselector-multi'>"; 1771 $text .= $frm->imagepicker('news_thumbnail[0]', varset($thumbTmp[0]), varset($paths[0]), array('media' => 'news+', 'video' => 1, 'legacyPath' => '{e_IMAGE}newspost_images')); 1772 $text .= $frm->imagepicker('news_thumbnail[1]', varset($thumbTmp[1]), varset($paths[1]), array('media' => 'news+', 'video' => 1, 'legacyPath' => '{e_IMAGE}newspost_images')); 1773 $text .= $frm->imagepicker('news_thumbnail[2]', varset($thumbTmp[2]), varset($paths[2]), array('media' => 'news+', 'video' => 1, 'legacyPath' => '{e_IMAGE}newspost_images')); 1774 $text .= $frm->imagepicker('news_thumbnail[3]', varset($thumbTmp[3]), varset($paths[3]), array('media' => 'news+', 'video' => 1, 'legacyPath' => '{e_IMAGE}newspost_images')); 1775 $text .= $frm->imagepicker('news_thumbnail[4]', varset($thumbTmp[4]), varset($paths[4]), array('media' => 'news+', 'video' => 1, 'legacyPath' => '{e_IMAGE}newspost_images')); 1776 $text .= "</div>"; 1777 // $text .= "<div class='field-help'>Insert image/video into designated area of template.</div>"; 1778 return $text; 1779 } 1780 1781 1782 1783 } 1784 1785 1786 1787 1788 function news_title($value, $mode) 1789 { 1790 if($mode == 'read') 1791 { 1792 $news_item = $this->getController()->getListModel()->toArray(); 1793 $url = e107::getUrl()->create('news/view/item', $news_item); 1794 return "<a class='e-tip' href='{$url}' title='".LAN_NEWS_102."' rel='external'>".$value."</a>"; 1795 } 1796 return $value; 1797 } 1798} 1799 1800 1801 1802new news_admin(); 1803require_once(e_ADMIN."auth.php"); 1804e107::getAdminUI()->runPage(); 1805 1806 1807 1808if(!e_AJAX_REQUEST) 1809{ 1810 require_once("footer.php"); 1811} 1812 1813exit; 1814