[ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 3 /* Reminder: always indent with 4 spaces (no tabs). */ 4 // +---------------------------------------------------------------------------+ 5 // | Geeklog 1.4 | 6 // +---------------------------------------------------------------------------+ 7 // | syndication.php | 8 // | | 9 // | Geeklog content syndication administration | 10 // +---------------------------------------------------------------------------+ 11 // | Copyright (C) 2003-2006 by the following authors: | 12 // | | 13 // | Authors: Dirk Haun - dirk AT haun-online DOT de | 14 // | Michael Jervis - mike AT fuckingbrit DOT com | 15 // +---------------------------------------------------------------------------+ 16 // | | 17 // | This program is free software; you can redistribute it and/or | 18 // | modify it under the terms of the GNU General Public License | 19 // | as published by the Free Software Foundation; either version 2 | 20 // | of the License, or (at your option) any later version. | 21 // | | 22 // | This program is distributed in the hope that it will be useful, | 23 // | but WITHOUT ANY WARRANTY; without even the implied warranty of | 24 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 25 // | GNU General Public License for more details. | 26 // | | 27 // | You should have received a copy of the GNU General Public License | 28 // | along with this program; if not, write to the Free Software Foundation, | 29 // | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 30 // | | 31 // +---------------------------------------------------------------------------+ 32 // 33 // $Id: syndication.php,v 1.49 2006/08/19 13:59:28 dhaun Exp $ 34 35 36 require_once ('../lib-common.php'); 37 require_once ('auth.inc.php'); 38 39 if (!SEC_hasRights ('syndication.edit')) { 40 $display .= COM_siteHeader ('menu', $MESSAGE[30]) 41 . COM_startBlock ($MESSAGE[30], '', 42 COM_getBlockTemplate ('_msg_block', 'header')) 43 . $MESSAGE[34] 44 . COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer')) 45 . COM_siteFooter (); 46 COM_accessLog("User {$_USER['username']} tried to illegally access the content syndication administration screen."); 47 echo $display; 48 exit; 49 } 50 51 /** 52 * Toggle status of a feed from enabled to disabled and back 53 * 54 * @param int $fid ID of the feed 55 * @return void 56 * 57 */ 58 function changeFeedStatus ($fid) 59 { 60 global $_TABLES; 61 62 $feed_id = addslashes (COM_applyFilter ($fid, true)); 63 if (!empty ($fid)) { 64 $is_enabled = 1; 65 if (DB_getItem ($_TABLES['syndication'], 'is_enabled', "fid = '$fid'")) { 66 $is_enabled = 0; 67 } 68 DB_query ("UPDATE {$_TABLES['syndication']} SET is_enabled = '$is_enabled' WHERE fid = '$fid'"); 69 } 70 } 71 72 /** 73 * Get a list of feed formats from the feed parser factory. 74 * 75 * @return array array of names of feed formats (and versions) 76 * 77 */ 78 function find_feedFormats () 79 { 80 global $_CONF; 81 82 // Import the feed handling classes: 83 require_once ($_CONF['path_system'] 84 . '/classes/syndication/parserfactory.class.php'); 85 86 $factory = new FeedParserFactory (); 87 $formats = $factory->getFeedTypes (); 88 sort ($formats); 89 90 return $formats; 91 } 92 93 /** 94 * Create a list of feed types that Geeklog offers. 95 * 96 * @return string an array with id/name pairs for every feed 97 * 98 */ 99 function get_geeklogFeeds () 100 { 101 global $_CONF, $_TABLES, $LANG33; 102 103 $options = array (); 104 105 $sql = "SELECT tid,topic FROM {$_TABLES['topics']} WHERE perm_anon >= 2 ORDER BY "; 106 if ($_CONF['sortmethod'] == 'alpha') { 107 $sql .= 'topic ASC'; 108 } else { 109 $sql .= 'sortnum'; 110 } 111 $result = DB_query ($sql); 112 $num = DB_numRows ($result); 113 114 if ($num > 0) { 115 $options[] = array ('id' => '::all', 'name' => $LANG33[23]); 116 } 117 118 for ($i = 0; $i < $num; $i++) { 119 $A = DB_fetchArray ($result); 120 $options[] = array ('id' => $A['tid'], 'name' => '-- ' . $A['topic']); 121 } 122 123 return $options; 124 } 125 126 function listfeeds() 127 { 128 global $_CONF, $_TABLES, $LANG_ADMIN, $LANG33, $_IMAGE_TYPE; 129 require_once( $_CONF['path_system'] . 'lib-admin.php' ); 130 $retval = ''; 131 132 $header_arr = array( # dislay 'text' and use table field 'field' 133 array('text' => $LANG_ADMIN['edit'], 'field' => 'edit', 'sort' => false), 134 array('text' => $LANG_ADMIN['title'], 'field' => 'title', 'sort' => true), 135 array('text' => $LANG_ADMIN['type'], 'field' => 'type', 'sort' => true), 136 array('text' => $LANG33[17], 'field' => 'format', 'sort' => true), 137 array('text' => $LANG33[16], 'field' => 'filename', 'sort' => true), 138 array('text' => $LANG_ADMIN['topic'], 'field' => 'header_tid', 'sort' => true), 139 array('text' => $LANG33[18], 'field' => 'updated', 'sort' => true), 140 array('text' => $LANG_ADMIN['enabled'], 'field' => 'is_enabled', 'sort' => true) 141 ); 142 143 $defsort_arr = array('field' => 'title', 'direction' => 'asc'); 144 145 $menu_arr = array ( 146 array('url' => $_CONF['site_admin_url'] . '/syndication.php?mode=edit', 147 'text' => $LANG_ADMIN['create_new']), 148 array('url' => $_CONF['site_admin_url'], 149 'text' => $LANG_ADMIN['admin_home']) 150 ); 151 152 $text_arr = array('has_menu' => true, 153 'has_extras' => true, 154 'title' => $LANG33[10], 'instructions' => $LANG33[13], 155 'icon' => $_CONF['layout_url'] . '/images/icons/syndication.' . $_IMAGE_TYPE, 156 'form_url' => $_CONF['site_admin_url'] . "/syndication.php"); 157 158 $query_arr = array('table' => 'syndication', 159 'sql' => "SELECT *,UNIX_TIMESTAMP(updated) AS date FROM {$_TABLES['syndication']} WHERE 1=1", 160 'query_fields' => array('title', 'filename'), 161 'default_filter' => ''); 162 163 $retval .= ADMIN_list ("syndication", "ADMIN_getListField_syndication", $header_arr, $text_arr, 164 $query_arr, $menu_arr, $defsort_arr); 165 return $retval; 166 } 167 168 /** 169 * Display the feed editor. 170 * 171 * @param int $fid feed id (0 for new feeds) 172 * @param string $type type of feed, e.g. 'geeklog' 173 * @return string HTML for the feed editor 174 * 175 */ 176 function editfeed ($fid = 0, $type = '') 177 { 178 global $_CONF, $_TABLES, $LANG33, $LANG_ADMIN, $MESSAGE; 179 180 if ($fid > 0) { 181 $result = DB_query ("SELECT *,UNIX_TIMESTAMP(updated) AS date FROM {$_TABLES['syndication']} WHERE fid = '$fid'"); 182 $A = DB_fetchArray ($result); 183 $fid = $A['fid']; 184 } 185 if ($fid == 0) { 186 if (!empty ($type)) { // set defaults 187 $A['fid'] = $fid; 188 $A['type'] = $type; 189 $A['topic'] = '::all'; 190 $A['header_tid'] = 'none'; 191 $A['format'] = 'RSS-2.0'; 192 $A['limits'] = $_CONF['rdf_limit']; 193 $A['content_length'] = $_CONF['rdf_storytext']; 194 $A['title'] = $_CONF['site_name']; 195 $A['description'] = $_CONF['site_slogan']; 196 $A['feedlogo'] = ''; 197 $A['filename'] = ''; 198 $A['charset'] = $_CONF['default_charset']; 199 $A['language'] = $_CONF['rdf_language']; 200 $A['is_enabled'] = 1; 201 $A['updated'] = ''; 202 $A['update_info'] = ''; 203 $A['date'] = time (); 204 } else { 205 return COM_refresh ($_CONF['site_admin_url'] . '/syndication.php'); 206 } 207 } 208 209 $retval = ''; 210 211 $feed_template = new Template ($_CONF['path_layout'] . 'admin/syndication'); 212 $feed_template->set_file ('editor', 'feededitor.thtml'); 213 214 $feed_template->set_var ('site_url', $_CONF['site_url']); 215 $feed_template->set_var ('site_admin_url', $_CONF['site_admin_url']); 216 $feed_template->set_var ('layout_url', $_CONF['layout_url']); 217 218 $feed_template->set_var ('start_feed_editor', COM_startBlock ($LANG33[24], 219 '', COM_getBlockTemplate ('_admin_block', 'header'))); 220 $feed_template->set_var ('end_block', 221 COM_endBlock (COM_getBlockTemplate ('_admin_block', 'footer'))); 222 223 $feed_template->set_var ('lang_feedtitle', $LANG33[25]); 224 $feed_template->set_var ('lang_enabled', $LANG33[19]); 225 $feed_template->set_var ('lang_format', $LANG33[17]); 226 $feed_template->set_var ('lang_limits', $LANG33[26]); 227 $feed_template->set_var ('lang_content_length', $LANG33[27]); 228 $feed_template->set_var ('lang_clen_explain', $LANG33[28]); 229 $feed_template->set_var ('lang_description', $LANG33[29]); 230 $feed_template->set_var ('lang_feedlogo', $LANG33[49]); 231 $feed_template->set_var ('lang_feedlogo_explain', $LANG33[50]); 232 $feed_template->set_var ('lang_filename', $LANG33[16]); 233 $feed_template->set_var ('lang_updated', $LANG33[30]); 234 $feed_template->set_var ('lang_type', $LANG33[15]); 235 $feed_template->set_var ('lang_charset', $LANG33[31]); 236 $feed_template->set_var ('lang_language', $LANG33[32]); 237 $feed_template->set_var ('lang_topic', $LANG33[33]); 238 239 if ($A['header_tid'] == 'all') { 240 $feed_template->set_var('all_selected', 'selected="selected"'); 241 } elseif ($A['header_tid'] == 'none') { 242 $feed_template->set_var('none_selected', 'selected="selected"'); 243 } 244 245 $feed_template->set_var('lang_header_all', $LANG33[43]); 246 $feed_template->set_var('lang_header_none', $LANG33[44]); 247 $feed_template->set_var('lang_header_topic', $LANG33[45]); 248 $feed_template->set_var('header_topic_options', 249 COM_topicList('tid,topic', $A['header_tid'], 1, true)); 250 $feed_template->set_var('lang_save', $LANG_ADMIN['save']); 251 $feed_template->set_var('lang_cancel', $LANG_ADMIN['cancel']); 252 if ($A['fid'] > 0) { 253 $delbutton = '<input type="submit" value="' . $LANG_ADMIN['delete'] 254 . '" name="mode"%s>'; 255 $jsconfirm = ' onclick="return confirm(\'' . $MESSAGE[76] . '\');"'; 256 $feed_template->set_var ('delete_option', 257 sprintf ($delbutton, $jsconfirm)); 258 $feed_template->set_var ('delete_option_no_confirmation', 259 sprintf ($delbutton, '')); 260 } 261 $feed_template->set_var ('feed_id', $A['fid']); 262 $feed_template->set_var ('feed_title', $A['title']); 263 $feed_template->set_var ('feed_description', $A['description']); 264 $feed_template->set_var ('feed_logo', $A['feedlogo']); 265 $feed_template->set_var ('feed_content_length', $A['content_length']); 266 $feed_template->set_var ('feed_filename', $A['filename']); 267 $feed_template->set_var ('feed_type', $A['type']); 268 $feed_template->set_var ('feed_type_display', ucwords ($A['type'])); 269 $feed_template->set_var ('feed_charset', $A['charset']); 270 $feed_template->set_var ('feed_language', $A['language']); 271 272 $nicedate = COM_getUserDateTimeFormat ($A['date']); 273 $feed_template->set_var ('feed_updated', $nicedate[0]); 274 275 $formats = find_feedFormats (); 276 $selection = '<select name="format">' . LB; 277 foreach ($formats as $f) { 278 // if one changes this format below ('name-version'), also change parsing 279 // in COM_siteHeader. It uses explode( "-" , $string ) 280 $selection .= '<option value="' . $f['name'] . '-' . $f['version'] 281 . '"'; 282 if ($A['format'] == $f['name'] . '-' . $f['version']) { 283 $selection .= ' selected="selected"'; 284 } 285 $selection .= '>' . ucwords ($f['name'] . ' ' . $f['version']) 286 . '</option>' . LB; 287 } 288 $selection .= '</select>' . LB; 289 $feed_template->set_var ('feed_format', $selection); 290 291 $limits = $A['limits']; 292 $hours = false; 293 if (substr ($A['limits'], -1) == 'h') { 294 $limits = substr ($A['limits'], 0, -1); 295 $hours = true; 296 } 297 $selection = '<select name="limits_in">' . LB; 298 $selection .= '<option value="0"'; 299 if (!$hours) { 300 $selection .= ' selected="selected"'; 301 } 302 $selection .= '>' . $LANG33[34] . '</option>' . LB; 303 $selection .= '<option value="1"'; 304 if ($hours) { 305 $selection .= ' selected="selected"'; 306 } 307 $selection .= '>' . $LANG33[35] . '</option>' . LB; 308 $selection .= '</select>' . LB; 309 $feed_template->set_var ('feed_limits', $limits); 310 $feed_template->set_var ('feed_limits_what', $selection); 311 312 if ($A['type'] == 'geeklog') { 313 $options = get_geeklogFeeds (); 314 } else { 315 $result = DB_query("SELECT pi_enabled FROM {$_TABLES['plugins']} WHERE pi_name='{$A['type']}'"); 316 if($result) 317 { 318 $P = DB_fetchArray($result); 319 if($P['pi_enabled'] == 0) 320 { 321 echo COM_refresh($_CONF['site_admin_url'].'/syndication.php?msg=80'); 322 exit; 323 } 324 } 325 $options = PLG_getFeedNames ($A['type']); 326 } 327 $selection = '<select name="topic">' . LB; 328 foreach ($options as $o) { 329 $selection .= '<option value="' . $o['id'] . '"'; 330 if ($A['topic'] == $o['id']) { 331 $selection .= ' selected="selected"'; 332 } 333 $selection .= '>' . $o['name'] . '</option>' . LB; 334 } 335 $selection .= '</select>' . LB; 336 $feed_template->set_var ('feed_topic', $selection); 337 338 if ($A['is_enabled'] == 1) { 339 $feed_template->set_var ('is_enabled', 'checked="checked"'); 340 } else { 341 $feed_template->set_var ('is_enabled', ''); 342 } 343 344 $retval .= $feed_template->finish ($feed_template->parse ('output', 345 'editor')); 346 return $retval; 347 } 348 349 /** 350 * Create a new feed. This is an extra step to take once you have a plugin 351 * installed that supports the new Feed functions in the Plugin API. This 352 * will let you select for which plugin (or Geeklog) you're creating the feed. 353 * 354 * @return string HTML for the complete page (selection or feed editor) 355 * 356 */ 357 function newfeed () 358 { 359 global $_CONF, $LANG33; 360 361 $retval = ''; 362 363 $plugins = PLG_supportingFeeds (); 364 if (sizeof ($plugins) == 0) { 365 // none of the installed plugins are supporting feeds 366 // - go directly to the feed editor 367 $retval = COM_siteHeader ('menu', $LANG33[11]) 368 . editfeed (0, 'geeklog') 369 . COM_siteFooter (); 370 } else { 371 $selection = '<select name="type">' . LB; 372 $selection .= '<option value="geeklog">Geeklog</option>' . LB; 373 foreach ($plugins as $p) { 374 $selection .= '<option value="' . $p . '">' . ucwords ($p) 375 . '</option>' . LB; 376 } 377 $selection .= '</select>' . LB; 378 379 $feed_template = new Template ($_CONF['path_layout'] 380 . 'admin/syndication'); 381 $feed_template->set_file ('type', 'selecttype.thtml'); 382 383 $feed_template->set_var ('site_url', $_CONF['site_url']); 384 $feed_template->set_var ('site_admin_url', $_CONF['site_admin_url']); 385 $feed_template->set_var ('layout_url', $_CONF['layout_url']); 386 387 $feed_template->set_var ('type_selection', $selection); 388 389 $feed_template->set_var ('lang_explain', $LANG33[37]); 390 $feed_template->set_var ('lang_go', $LANG33[1]); 391 392 $retval .= COM_siteHeader ('menu', $LANG33[11]); 393 $retval .= COM_startBlock ($LANG33[36], '', 394 COM_getBlockTemplate ('_admin_block', 'header')); 395 $retval .= $feed_template->finish ($feed_template->parse ('output', 396 'type')); 397 $retval .= COM_endBlock (COM_getBlockTemplate ('_admin_block', 'footer')); 398 $retval .= COM_siteFooter (); 399 } 400 401 return $retval; 402 } 403 404 /** 405 * Save feed. 406 * 407 * @param array $A 408 * @return string HTML redirect on success or feed editor + error message 409 * 410 */ 411 function savefeed ($A) 412 { 413 global $_CONF, $_TABLES, $LANG33; 414 415 foreach ($A as $name => $value) { 416 $A[$name] = COM_stripslashes ($value); 417 } 418 419 if ($A['is_enabled'] == 'on') { 420 $A['is_enabled'] = 1; 421 } else { 422 $A['is_enabled'] = 0; 423 } 424 if (empty ($A['title']) || empty ($A['description']) || 425 empty ($A['filename'])) { 426 $retval = COM_siteHeader ('menu', $LANG33[38]) 427 . COM_startBlock ($LANG33[38], '', 428 COM_getBlockTemplate ('_msg_block', 'header')) 429 . $LANG33[39] 430 . COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer')) 431 . editfeed ($A['fid'], $A['type']) 432 . COM_siteFooter (); 433 return $retval; 434 } 435 436 $result = DB_query("SELECT COUNT(*) AS count FROM {$_TABLES['syndication']} WHERE filename = '{$A['filename']}' AND (fid <> '{$A['fid']}')"); 437 $C = DB_fetchArray($result); 438 if ($C['count'] > 0) { 439 $retval = COM_siteHeader ('menu', $LANG33[52]) 440 . COM_startBlock ($LANG33[52], '', 441 COM_getBlockTemplate ('_msg_block', 'header')) 442 . $LANG33[51] 443 . COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer')) 444 . editfeed ($A['fid'], $A['type']) 445 . COM_siteFooter (); 446 return $retval; 447 } 448 449 if ($A['limits'] <= 0) { 450 $retval = COM_siteHeader ('menu', $LANG33[38]) 451 . COM_startBlock ($LANG33[38], '', 452 COM_getBlockTemplate ('_msg_block', 'header')) 453 . $LANG33[40] 454 . COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer')) 455 . editfeed ($A['fid'], $A['type']) 456 . COM_siteFooter (); 457 return $retval; 458 } 459 if ($A['limits_in'] == 1) { 460 $A['limits'] .= 'h'; 461 } 462 463 // we can compensate if these are missing ... 464 if (empty ($A['charset'])) { 465 $A['charset'] = $_CONF['default_charset']; 466 if (empty ($A['charset'])) { 467 $A['charset'] = 'UTF-8'; 468 } 469 } 470 if (empty ($A['language'])) { 471 $A['language'] = $_CONF['rdf_language']; 472 if (empty ($A['language'])) { 473 $A['language'] = $_CONF['locale']; 474 } 475 } 476 if (empty ($A['content_length']) || ($A['content_length'] < 0)) { 477 $A['content_length'] = 0; 478 } 479 480 foreach ($A as $name => $value) { 481 $A[$name] = addslashes ($value); 482 } 483 484 DB_save ($_TABLES['syndication'], 'fid,type,topic,header_tid,format,limits,content_length,title,description,feedlogo,filename,charset,language,is_enabled,updated,update_info', 485 "{$A['fid']},'{$A['type']}','{$A['topic']}','{$A['header_tid']}','{$A['format']}','{$A['limits']}',{$A['content_length']},'{$A['title']}','{$A['description']}','{$A['feedlogo']}','{$A['filename']}','{$A['charset']}','{$A['language']}',{$A['is_enabled']},'0000-00-00 00:00:00',NULL"); 486 487 if ($A['fid'] == 0) { 488 $A['fid'] = DB_insertId (); 489 } 490 SYND_updateFeed ($A['fid']); 491 492 return COM_refresh ($_CONF['site_admin_url'] . '/syndication.php?msg=58'); 493 } 494 495 /** 496 * Delete a feed. 497 * 498 * @param int $fid feed id 499 * @return string HTML redirect 500 * 501 */ 502 function deletefeed ($fid) 503 { 504 global $_CONF, $_TABLES; 505 506 if ($fid > 0) { 507 DB_delete ($_TABLES['syndication'], 'fid', $fid); 508 509 return COM_refresh ($_CONF['site_admin_url'] 510 . '/syndication.php?msg=59'); 511 } 512 513 return COM_refresh ($_CONF['site_admin_url'] . '/syndication.php'); 514 } 515 516 517 // MAIN 518 $display = ''; 519 520 if ($_CONF['backend'] && isset ($_POST['feedChange'])) { 521 changeFeedStatus ($_POST['feedChange']); 522 } 523 $mode = ''; 524 if (isset($_REQUEST['mode'])) { 525 $mode = $_REQUEST['mode']; 526 } 527 if ($mode == 'edit') { 528 if (empty ($_REQUEST['fid'])) { 529 $display .= newfeed (); 530 } else { 531 $display .= COM_siteHeader ('menu', $LANG33[24]) 532 . editfeed (COM_applyFilter($_REQUEST['fid'])) 533 . COM_siteFooter (); 534 } 535 } 536 else if (($mode == $LANG33[1]) && !empty ($LANG33[1])) 537 { 538 $display .= COM_siteHeader ('menu', $LANG33[24]) 539 . editfeed (0, COM_applyFilter($_REQUEST['type'])) 540 . COM_siteFooter (); 541 } 542 else if (($mode == $LANG_ADMIN['save']) && !empty ($LANG_ADMIN['save'])) 543 { 544 $display .= savefeed ($_POST); 545 } 546 else if (($mode == $LANG_ADMIN['delete']) && !empty ($LANG_ADMIN['delete'])) 547 { 548 $display .= deletefeed (COM_applyFilter($_REQUEST['fid'])); 549 } 550 else 551 { 552 $display .= COM_siteHeader ('menu', $LANG33[10]); 553 if (isset ($_REQUEST['msg'])) { 554 $display .= COM_showMessage (COM_applyFilter($_REQUEST['msg'])); 555 } 556 $display .= listfeeds(); 557 $display .= COM_siteFooter (); 558 } 559 560 echo $display; 561 562 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |