[ 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 // | plugins.php | 8 // | | 9 // | Geeklog plugin administration page. | 10 // +---------------------------------------------------------------------------+ 11 // | Copyright (C) 2000-2006 by the following authors: | 12 // | | 13 // | Authors: Tony Bibbs - tony AT tonybibbs DOT com | 14 // | Mark Limburg - mlimburg AT users DOT sourceforge DOT net | 15 // | Jason Whittenburg - jwhitten AT securitygeeks DOT com | 16 // | Dirk Haun - dirk AT haun-online DOT de | 17 // +---------------------------------------------------------------------------+ 18 // | | 19 // | This program is free software; you can redistribute it and/or | 20 // | modify it under the terms of the GNU General Public License | 21 // | as published by the Free Software Foundation; either version 2 | 22 // | of the License, or (at your option) any later version. | 23 // | | 24 // | This program is distributed in the hope that it will be useful, | 25 // | but WITHOUT ANY WARRANTY; without even the implied warranty of | 26 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 27 // | GNU General Public License for more details. | 28 // | | 29 // | You should have received a copy of the GNU General Public License | 30 // | along with this program; if not, write to the Free Software Foundation, | 31 // | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 32 // | | 33 // +---------------------------------------------------------------------------+ 34 // 35 // $Id: plugins.php,v 1.67 2006/11/18 13:21:11 dhaun Exp $ 36 37 require_once ('../lib-common.php'); 38 require_once ('auth.inc.php'); 39 40 // Uncomment the line below if you need to debug the HTTP variables being passed 41 // to the script. This will sometimes cause errors but it will allow you to see 42 // the data being passed in a POST operation 43 // echo COM_debug($_POST); 44 45 // Number of plugins to list per page 46 // We use 25 here instead of the 50 entries in other lists to leave room 47 // for the list of uninstalled plugins. 48 define ('PLUGINS_PER_PAGE', 25); 49 50 $display = ''; 51 52 if (!SEC_hasrights ('plugin.edit')) { 53 $display .= COM_siteHeader ('menu', $MESSAGE[30]); 54 $display .= COM_startBlock ($MESSAGE[30], '', 55 COM_getBlockTemplate ('_msg_block', 'header')); 56 $display .= $MESSAGE[38]; 57 $display .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer')); 58 $display .= COM_siteFooter (); 59 COM_accessLog ("User {$_USER['username']} tried to illegally access the plugin administration screen."); 60 echo $display; 61 exit; 62 } 63 64 /** 65 * Shows the plugin editor form 66 * 67 * @param string $pi_name Plugin name 68 * @param int $confirmed Flag indicated the user has confirmed an action 69 * @return string HTML for plugin editor form or error message 70 * 71 */ 72 function plugineditor ($pi_name, $confirmed = 0) 73 { 74 global $_CONF, $_TABLES, $_USER, $LANG32, $LANG_ADMIN; 75 76 $retval = ''; 77 78 if (strlen ($pi_name) == 0) { 79 $retval .= COM_startBlock ($LANG32[13], '', 80 COM_getBlockTemplate ('_msg_block', 'header')); 81 $retval .= COM_errorLog ($LANG32[12]); 82 $retval .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer')); 83 84 return $retval; 85 } 86 87 $result = DB_query("SELECT pi_homepage,pi_version,pi_gl_version,pi_enabled FROM {$_TABLES['plugins']} WHERE pi_name = '$pi_name'"); 88 if (DB_numRows($result) <> 1) { 89 // Serious problem, we got a pi_name that doesn't exist 90 // or returned more than one row 91 $retval .= COM_startBlock ($LANG32[13], '', 92 COM_getBlockTemplate ('_msg_block', 'header')); 93 $retval .= COM_errorLog ('Error in editing plugin ' . $pi_name 94 . '. Either the plugin does not exist or there is more than one row with with same pi_name. Bailing out to prevent trouble.'); 95 $retval .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer')); 96 97 return $retval; 98 } 99 100 $A = DB_fetchArray($result); 101 102 $plg_templates = new Template($_CONF['path_layout'] . 'admin/plugins'); 103 $plg_templates->set_file('editor', 'editor.thtml'); 104 $plg_templates->set_var('site_url', $_CONF['site_url']); 105 $plg_templates->set_var('site_admin_url', $_CONF['site_admin_url']); 106 $plg_templates->set_var('layout_url', $_CONF['layout_url']); 107 $plg_templates->set_var('start_block_editor', COM_startBlock ($LANG32[13], 108 '', COM_getBlockTemplate ('_admin_block', 'header'))); 109 $plg_templates->set_var('lang_save', $LANG_ADMIN['save']); 110 $plg_templates->set_var('lang_cancel', $LANG_ADMIN['cancel']); 111 $plg_templates->set_var('lang_delete', $LANG_ADMIN['delete']); 112 $plg_templates->set_var ('pi_icon', PLG_getIcon ($pi_name)); 113 if (!empty($pi_name)) { 114 $plg_templates->set_var ('delete_option', '<input type="submit" value="' 115 . $LANG_ADMIN['delete'] . '" name="mode">'); 116 } 117 $plugin_code_version = PLG_chkVersion($pi_name); 118 if (empty ($plugin_code_version)) { 119 $code_version = 'N/A'; 120 } else { 121 $code_version = $plugin_code_version; 122 } 123 $pi_installed_version = $A['pi_version']; 124 if (empty ($plugin_code_version) || 125 ($pi_installed_version == $code_version)) { 126 $plg_templates->set_var ('update_option', ''); 127 } else { 128 $plg_templates->set_var ('update_option', '<input type="submit" value="' 129 . $LANG32[34] . '" name="mode">'); 130 } 131 $plg_templates->set_var('confirmed', $confirmed); 132 $plg_templates->set_var('lang_pluginname', $LANG32[26]); 133 $plg_templates->set_var('pi_name', $pi_name); 134 $plg_templates->set_var('lang_pluginhomepage', $LANG32[27]); 135 $plg_templates->set_var('pi_homepage', $A['pi_homepage']); 136 $plg_templates->set_var('lang_pluginversion', $LANG32[28]); 137 $plg_templates->set_var('lang_plugincodeversion', $LANG32[33]); 138 $plg_templates->set_var('pi_version', $A['pi_version']); 139 $plg_templates->set_var('lang_geeklogversion', $LANG32[29]); 140 $plg_templates->set_var('pi_gl_version', $A['pi_gl_version']); 141 $plg_templates->set_var('pi_codeversion', $plugin_code_version ); 142 $plg_templates->set_var('lang_enabled', $LANG32[19]); 143 if ($A['pi_enabled'] == 1) { 144 $plg_templates->set_var('enabled_checked', 'checked="checked"'); 145 } else { 146 $plg_templates->set_var('enabled_checked', ''); 147 } 148 $plg_templates->set_var('end_block', 149 COM_endBlock (COM_getBlockTemplate ('_admin_block', 'footer'))); 150 151 $retval .= $plg_templates->parse('output', 'editor'); 152 153 return $retval; 154 } 155 156 /** 157 * Toggle status of a plugin from enabled to disabled and back 158 * 159 * @param string $pi_name name of the plugin 160 * @return void 161 * 162 */ 163 function changePluginStatus ($pi_name) 164 { 165 global $_TABLES, $_DB_table_prefix; 166 167 $pi_name = addslashes (COM_applyFilter ($pi_name)); 168 if (!empty ($pi_name)) { 169 $pi_enabled = 1; 170 if (DB_getItem ($_TABLES['plugins'], 'pi_enabled', "pi_name = '$pi_name'")) { 171 $pi_enabled = 0; 172 } 173 174 PLG_enableStateChange ($pi_name, ($pi_enabled == 1) ? true : false); 175 176 DB_query ("UPDATE {$_TABLES['plugins']} SET pi_enabled = '$pi_enabled' WHERE pi_name = '$pi_name'"); 177 } 178 } 179 180 181 /** 182 * Saves a plugin 183 * 184 * @param string $pi_name Plugin name 185 * @param string $pi_version Plugin version number 186 * @param string $pi_gl_version Geeklog version plugin is compatible with 187 * @param int $enabled Flag that indicates if plugin is enabled 188 * @param string $pi_homepage URL to homepage for plugin 189 * @return string HTML redirect or error message 190 * 191 */ 192 function saveplugin($pi_name, $pi_version, $pi_gl_version, $enabled, $pi_homepage) 193 { 194 global $_CONF, $_TABLES, $LANG32; 195 196 $retval = ''; 197 198 if (!empty ($pi_name)) { 199 if ($enabled == 'on') { 200 $enabled = 1; 201 } else { 202 $enabled = 0; 203 } 204 $pi_name = addslashes ($pi_name); 205 $pi_version = addslashes ($pi_version); 206 $pi_gl_version = addslashes ($pi_gl_version); 207 $pi_homepage = addslashes ($pi_homepage); 208 209 $currentState = DB_getItem ($_TABLES['plugins'], 'pi_enabled', 210 "pi_name= '{$pi_name}' LIMIT 1"); 211 if ($currentState != $enabled) { 212 PLG_enableStateChange ($pi_name, ($enabled == 1) ? true : false); 213 } 214 215 DB_save ($_TABLES['plugins'], 'pi_name, pi_version, pi_gl_version, pi_enabled, pi_homepage', "'$pi_name', '$pi_version', '$pi_gl_version', $enabled, '$pi_homepage'"); 216 217 $retval = COM_refresh($_CONF['site_admin_url'] . '/plugins.php?msg=28'); 218 } else { 219 $retval .= COM_siteHeader ('menu', $LANG32[13]); 220 $retval .= COM_startBlock ($LANG32[13], '', 221 COM_getBlockTemplate ('_msg_block', 'header')); 222 $retval .= COM_errorLog ('error saving plugin, no pi_name provided', 1); 223 $retval .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer')); 224 $retval .= plugineditor ($pi_name); 225 $retval .= COM_siteFooter (); 226 } 227 228 return $retval; 229 } 230 231 /** 232 * Creates list of uninstalled plugins (if any) and offers install link to them. 233 * 234 * @return string HTML containing list of uninstalled plugins 235 * 236 */ 237 function show_newplugins () 238 { 239 global $_CONF, $_TABLES, $LANG32; 240 241 $plugins = array (); 242 $plugins_dir = $_CONF['path'] . 'plugins/'; 243 $fd = opendir ($plugins_dir); 244 $index = 1; 245 $retval = ''; 246 $newplugins = array (); 247 while (($dir = @readdir ($fd)) == TRUE) { 248 if (is_dir ($plugins_dir . $dir) && ($dir <> '.') && ($dir <> '..') && 249 ($dir <> 'CVS') && (substr ($dir, 0 , 1) <> '.')) { 250 clearstatcache (); 251 // Check and see if this plugin is installed - if there is a record. 252 // If not then it's a new plugin 253 if (DB_count($_TABLES['plugins'],'pi_name',$dir) == 0) { 254 // additionally, check if a 'functions.inc' exists 255 if (file_exists ($plugins_dir . $dir . '/functions.inc')) { 256 // and finally, since we're going to link to it, check if 257 // an install script exists 258 $adminurl = $_CONF['site_admin_url']; 259 if (strrpos ($adminurl, '/') == strlen ($adminurl)) { 260 $adminurl = substr ($adminurl, 0, -1); 261 } 262 $pos = strrpos ($adminurl, '/'); 263 if ($pos === false) { 264 // didn't work out - use the URL 265 $admindir = $_CONF['site_admin_url']; 266 } else { 267 $admindir = $_CONF['path_html'] 268 . substr ($adminurl, $pos + 1); 269 } 270 $fh = @fopen ($admindir . '/plugins/' . $dir 271 . '/install.php', 'r'); 272 if ($fh) { 273 fclose ($fh); 274 $newplugins[] = $dir; 275 } 276 } 277 } 278 } 279 } 280 281 if (sizeof ($newplugins) > 0) { 282 sort ($newplugins); 283 $templdir = $_CONF['path_layout'] . 'admin/plugins'; 284 if (file_exists ($templdir . '/newpluginlist.thtml') && 285 file_exists ($templdir . '/newlistitem.thtml')) { 286 $newtemplate = new Template ($templdir); 287 $newtemplate->set_file (array ('list'=>'newpluginlist.thtml', 288 'row'=>'newlistitem.thtml')); 289 $newtemplate->set_var ('site_url', $_CONF['site_url']); 290 $newtemplate->set_var ('site_admin_url', $_CONF['site_admin_url']); 291 $newtemplate->set_var ('layout_url', $_CONF['layout_url']); 292 $newtemplate->set_var ('lang_pluginname', $LANG32[16]); 293 $newtemplate->set_var ('start_block_newlist', 294 COM_startBlock ($LANG32[14], '', 295 COM_getBlockTemplate ('_admin_block', 'header'))); 296 for ($i = 0; $i < sizeof ($newplugins); $i++) { 297 $newtemplate->set_var ('lang_install', $LANG32[22]); 298 $newtemplate->set_var ('pi_name', $newplugins[$i]); 299 $newtemplate->set_var ('row_num', $i + 1); 300 $newtemplate->set_var ('cssid', $i%2 + 1); 301 $newtemplate->set_var ('start_install_anchortag', '<a href="' 302 . $_CONF['site_admin_url'] . '/plugins/' . $newplugins[$i] 303 . '/install.php?action=install">'); 304 $newtemplate->set_var ('end_install_anchortag', '</a>'); 305 $newtemplate->parse ('plugin_list', 'row', true); 306 } 307 $newtemplate->set_var ('end_block', 308 COM_endBlock (COM_getBlockTemplate ('_admin_block', 'footer'))); 309 $newtemplate->parse ('output', 'list'); 310 $retval .= $newtemplate->finish ($newtemplate->get_var ('output')); 311 } else { 312 $retval = COM_startBlock ($LANG32[14], '', 313 COM_getBlockTemplate ('_admin_block', 'header')); 314 $retval .= '<table border="0">' . LB; 315 $retval .= '<tr><th align="left">' . $LANG32[16] .'</th></tr>' . LB; 316 for ($i = 0; $i < sizeof ($newplugins); $i++) { 317 $retval .= '<tr><td>' . $newplugins[$i] . '</td><td><a href="' 318 . $_CONF['site_admin_url'] . '/plugins/' . $newplugins[$i] 319 . '/install.php?action=install">' . $LANG32[22] 320 . '</a></td></tr>' . LB; 321 } 322 $retval .= '</table>' . LB; 323 $retval .= COM_endBlock (COM_getBlockTemplate ('_admin_block', 324 'footer')); 325 } 326 } 327 328 return $retval; 329 } 330 331 /** 332 * Updates a plugin (call its upgrade function). 333 * 334 * @param pi_name string name of the plugin to uninstall 335 * @return string HTML for error or success message 336 * 337 */ 338 function do_update ($pi_name) 339 { 340 global $_CONF, $LANG32, $LANG08, $MESSAGE, $_IMAGE_TYPE; 341 342 $retval = ''; 343 344 if (strlen ($pi_name) == 0) { 345 $retval .= COM_startBlock ($LANG32[13], '', 346 COM_getBlockTemplate ('_msg_block', 'header')); 347 $retval .= COM_errorLog ($LANG32[12]); 348 $retval .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer')); 349 350 return $retval; 351 } 352 $result = PLG_upgrade ($pi_name); 353 if ($result > 0 ) { 354 if ($result === TRUE) { // Catch returns that are just true/false 355 $retval .= COM_refresh ($_CONF['site_admin_url'] 356 . '/plugins.php?msg=60'); 357 } else { // Plugin returned a message number 358 $retval = COM_refresh ($_CONF['site_admin_url'] 359 . '/plugins.php?msg=' . $result . '&plugin=' 360 . $pi_name); 361 } 362 } else { // Plugin function returned a false 363 $timestamp = strftime ($_CONF['daytime']); 364 $retval .= COM_startBlock ($MESSAGE[40] . ' - ' . $timestamp, '', 365 COM_getBlockTemplate ('_msg_block', 'header')) 366 . '<img src="' . $_CONF['layout_url'] 367 . '/images/sysmessage.' . $_IMAGE_TYPE 368 . '" border="0" align="top" alt="">' . $LANG08[6] . '<br><br>' 369 . COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer')); 370 } 371 372 return $retval; 373 } 374 375 376 /** 377 * Uninstall a plugin (call its uninstall function). 378 * 379 * @param pi_name string name of the plugin to uninstall 380 * @return string HTML for error or success message 381 * 382 */ 383 function do_uninstall ($pi_name) 384 { 385 global $_CONF, $LANG32, $LANG08, $MESSAGE, $_IMAGE_TYPE; 386 387 $retval = ''; 388 389 if (strlen ($pi_name) == 0) { 390 $retval .= COM_startBlock ($LANG32[13], '', 391 COM_getBlockTemplate ('_msg_block', 'header')); 392 $retval .= COM_errorLog ($LANG32[12]); 393 $retval .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer')); 394 395 return $retval; 396 } 397 398 // if the plugin is disabled, load the functions.inc now 399 if (!function_exists ('plugin_uninstall_' . $pi_name)) { 400 require_once ($_CONF['path'] . 'plugins/' . $pi_name . '/functions.inc'); 401 } 402 403 if (PLG_uninstall ($pi_name)) { 404 $retval .= COM_showMessage (45); 405 } else { 406 $timestamp = strftime ($_CONF['daytime']); 407 $retval .= COM_startBlock ($MESSAGE[40] . ' - ' . $timestamp, '', 408 COM_getBlockTemplate ('_msg_block', 'header')) 409 . '<img src="' . $_CONF['layout_url'] 410 . '/images/sysmessage.' . $_IMAGE_TYPE 411 . '" border="0" align="top" alt="">' . $LANG08[6] . '<br><br>' 412 . COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer')); 413 } 414 415 return $retval; 416 } 417 418 /** 419 * List available plugins 420 * 421 * @return string formatted list of plugins 422 * 423 */ 424 function listplugins () 425 { 426 global $_CONF, $_TABLES, $LANG32, $LANG_ADMIN, $_IMAGE_TYPE; 427 require_once( $_CONF['path_system'] . 'lib-admin.php' ); 428 429 $header_arr = array( # display 'text' and use table field 'field' 430 array('text' => $LANG_ADMIN['edit'], 'field' => 'edit', 'sort' => false), 431 array('text' => $LANG32[16], 'field' => 'pi_name', 'sort' => true), 432 array('text' => $LANG32[17], 'field' => 'pi_version', 'sort' => true), 433 array('text' => $LANG32[18], 'field' => 'pi_gl_version', 'sort' => true), 434 array('text' => $LANG_ADMIN['enabled'], 'field' => 'enabled', 'sort' => false) 435 ); 436 437 $defsort_arr = array('field' => 'pi_name', 'direction' => 'asc'); 438 439 $menu_arr = array ( 440 array('url' => $_CONF['site_admin_url'], 441 'text' => $LANG_ADMIN['admin_home'])); 442 443 $text_arr = array('has_menu' => true, 444 'has_extras' => true, 445 'title' => $LANG32[5], 446 'instructions' => $LANG32[11], 447 'icon' => $_CONF['layout_url'] . '/images/icons/plugins.' 448 . $_IMAGE_TYPE, 449 'form_url' => $_CONF['site_admin_url'] . '/plugins.php'); 450 451 $query_arr = array('table' => 'plugins', 452 'sql' => "SELECT pi_name, pi_version, pi_gl_version, " 453 ."pi_enabled, pi_homepage FROM {$_TABLES['plugins']} WHERE 1=1", 454 'query_fields' => array('pi_name'), 455 'default_filter' => ''); 456 457 return ADMIN_list ('plugins', 'ADMIN_getListField_plugins', $header_arr, 458 $text_arr, $query_arr, $menu_arr, $defsort_arr); 459 460 } 461 462 // MAIN 463 $display = ''; 464 if (isset ($_POST['pluginChange'])) { 465 changePluginStatus ($_POST['pluginChange']); 466 467 // force a refresh so that the information of the plugin that was just 468 // enabled / disabled (menu entries, etc.) is displayed properly 469 header ('Location: ' . $_CONF['site_admin_url'] . '/plugins.php'); 470 exit; 471 } 472 473 $mode = ''; 474 if (isset ($_REQUEST['mode'])) { 475 $mode = $_REQUEST['mode']; 476 } 477 if (($mode == $LANG_ADMIN['delete']) && !empty ($LANG_ADMIN['delete'])) { 478 $pi_name = COM_applyFilter ($_POST['pi_name']); 479 if ($_POST['confirmed'] == 1) { 480 $display .= COM_siteHeader ('menu', $LANG32[30]); 481 $display .= do_uninstall ($pi_name); 482 $display .= listplugins (); 483 $display .= show_newplugins(); 484 $display .= COM_siteFooter (); 485 } else { // ask user for confirmation 486 $display .= COM_siteHeader ('menu', $LANG32[30]); 487 $display .= COM_startBlock ($LANG32[30], '', 488 COM_getBlockTemplate ('_msg_block', 'header')); 489 $display .= $LANG32[31]; 490 $display .= COM_endBlock(COM_getBlockTemplate ('_msg_block', 'footer')); 491 $display .= plugineditor ($pi_name, 1); 492 $display .= COM_siteFooter (); 493 } 494 495 } else if (($mode == $LANG32[34]) && !empty ($LANG32[34])) { // update 496 $pi_name = COM_applyFilter ($_POST['pi_name']); 497 $display .= COM_siteHeader ('menu', $LANG32[13]); 498 $display .= do_update ($pi_name); 499 $display .= COM_siteFooter (); 500 501 } else if ($mode == 'edit') { 502 $display .= COM_siteHeader ('menu', $LANG32[13]); 503 $display .= plugineditor (COM_applyFilter ($_GET['pi_name'])); 504 $display .= COM_siteFooter (); 505 506 } else if (($mode == $LANG_ADMIN['save']) && !empty ($LANG_ADMIN['save'])) { 507 $display .= saveplugin (COM_applyFilter ($_POST['pi_name']), 508 COM_applyFilter ($_POST['pi_version']), 509 COM_applyFilter ($_POST['pi_gl_version']), 510 COM_applyFilter ($_POST['enabled']), 511 COM_applyFilter ($_POST['pi_homepage'])); 512 513 } else { // 'cancel' or no mode at all 514 $display .= COM_siteHeader ('menu', $LANG32[5]); 515 if (isset ($_REQUEST['msg'])) { 516 $msg = COM_applyFilter ($_REQUEST['msg'], true); 517 if (!empty ($msg)) { 518 $plugin = ''; 519 if (isset ($_REQUEST['plugin'])) { 520 $plugin = COM_applyFilter ($_REQUEST['plugin']); 521 } 522 $display .= COM_showMessage ($msg, $plugin); 523 } 524 } 525 $display .= listplugins (); 526 $display .= show_newplugins(); 527 $display .= COM_siteFooter(); 528 } 529 530 echo $display; 531 532 ?>
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 |
![]() |