Serendipity PHP Cross Reference Blogging Systems

Source: /include/admin/plugins.inc.php - 590 lines - 28549 bytes - Summary - Text - Print

   1  <?php # $Id$
   2  # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
   3  # All rights reserved.  See LICENSE file for licensing details
   4  
   5  if (IN_serendipity !== true) {
   6      die ('Don\'t hack!');
   7  }
   8  
   9  if (!serendipity_checkPermission('adminPlugins')) {
  10      return;
  11  }
  12  
  13  include_once  S9Y_INCLUDE_PATH . 'include/plugin_api.inc.php';
  14  include_once  S9Y_INCLUDE_PATH . 'include/plugin_internal.inc.php';
  15  include_once  S9Y_INCLUDE_PATH . 'include/functions_entries_admin.inc.php';
  16  include_once  S9Y_INCLUDE_PATH . 'include/functions_plugins_admin.inc.php';
  17  
  18  if (isset($_GET['serendipity']['plugin_to_move']) && isset($_GET['submit']) && serendipity_checkFormToken()) {
  19      if (isset($_GET['serendipity']['event_plugin'])) {
  20          $plugins = serendipity_plugin_api::enum_plugins('event', false);
  21      } else {
  22          $plugins = serendipity_plugin_api::enum_plugins('event', true);
  23      }
  24  
  25      /* Renumber the sort order to be certain that one actually exists
  26          Also look for the one we're going to move */
  27      $idx_to_move = -1;
  28      for($idx = 0; $idx < count($plugins); $idx++) {
  29          $plugins[$idx]['sort_order'] = $idx;
  30  
  31          if ($plugins[$idx]['name'] == $_GET['serendipity']['plugin_to_move']) {
  32              $idx_to_move = $idx;
  33          }
  34      }
  35  
  36      /* If idx_to_move is still -1 then we never found it (shouldn't happen under normal conditions)
  37          Also make sure the swaping idx is around */
  38      if ($idx_to_move >= 0 && (($_GET['submit'] == 'move down' && $idx_to_move < (count($plugins)-1)) || ($_GET['submit'] == 'move up' && $idx_to_move > 0))) {
  39  
  40          /* Swap the one were moving with the one that's in the spot we're moving to */
  41          $tmp = $plugins[$idx_to_move]['sort_order'];
  42  
  43          $plugins[$idx_to_move]['sort_order'] = (int)$plugins[$idx_to_move + ($_GET['submit'] == 'move down' ? 1 : -1)]['sort_order'];
  44          $plugins[$idx_to_move + ($_GET['submit'] == 'move down' ? 1 : -1)]['sort_order'] = (int)$tmp;
  45  
  46          /* Update table */
  47          foreach($plugins as $plugin) {
  48              $key = serendipity_db_escape_string($plugin['name']);
  49              serendipity_db_query("UPDATE {$serendipity['dbPrefix']}plugins SET sort_order = {$plugin['sort_order']} WHERE name='$key'");
  50          }
  51      }
  52  
  53      /* TODO: Moving The first Right oriented plugin up,
  54              or the last left oriented plugin down
  55              should not be displayed to the user as an option.
  56              It's a behavior which really has no meaning. */
  57  }
  58  
  59  if (isset($_GET['serendipity']['plugin_to_conf'])) {
  60      /* configure a specific instance */
  61      $plugin =& serendipity_plugin_api::load_plugin($_GET['serendipity']['plugin_to_conf']);
  62  
  63      if (!($plugin->protected === FALSE || $plugin->serendipity_owner == '0' || $plugin->serendipity_owner == $serendipity['authorid'] || serendipity_checkPermission('adminPluginsMaintainOthers'))) {
  64          return;
  65      }
  66  
  67      $bag  = new serendipity_property_bag;
  68      $plugin->introspect($bag);
  69  
  70      if (method_exists($plugin, 'performConfig')) {
  71          $plugin->performConfig($bag);
  72      }
  73  
  74      $name = htmlspecialchars($bag->get('name'));
  75      $desc = htmlspecialchars($bag->get('description'));
  76      $license = htmlspecialchars($bag->get('license'));
  77  
  78      $documentation = $bag->get('website');
  79  
  80      $config_names = $bag->get('configuration');
  81      $config_groups = $bag->get('config_groups');
  82  
  83      if (isset($_POST['SAVECONF']) && serendipity_checkFormToken()) {
  84          /* enum properties and set their values */
  85  
  86          $save_errors = array();
  87          foreach ($config_names as $config_item) {
  88              $cbag = new serendipity_property_bag;
  89              if ($plugin->introspect_config_item($config_item, $cbag)) {
  90                  $value    = $_POST['serendipity']['plugin'][$config_item];
  91  
  92                  $validate = $plugin->validate($config_item, $cbag, $value);
  93  
  94                  if ($validate === true) {
  95  //                    echo $config_item . " validated: $validate<br />\n";
  96  
  97                      if (!empty($_POST['serendipity']['plugin']['override'][$config_item])) {
  98                          $value = $_POST['serendipity']['plugin']['override'][$config_item];
  99                      }
 100  
 101                      if (is_array($_POST['serendipity']['plugin']['activate'][$config_item])) {
 102                          $values = explode(',', $value);
 103                          $out_values = array();
 104                          foreach($values AS $out_value) {
 105                              if (!isset($_POST['serendipity']['plugin']['activate'][$config_item][$out_value])) {
 106                                  continue;
 107                              }
 108  
 109                              $out_values[] = $out_value;
 110                          }
 111                          $value = implode(',', $out_values);
 112                      }
 113  
 114                      $plugin->set_config($config_item, $value);
 115                  } else {
 116                      $save_errors[] = $validate;
 117                  }
 118              }
 119          }
 120  
 121          $plugin->cleanup();
 122      }
 123  ?>
 124  
 125  <?php if ( isset($save_errors) && is_array($save_errors) && count($save_errors) > 0 ) { ?>
 126      <div class="serendipityAdminMsgError">
 127      <img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="<?php echo serendipity_getTemplateFile('admin/img/admin_msg_error.png'); ?>" alt="" />
 128      <?php
 129      echo ERROR . ":<br />\n";
 130      echo "<ul>\n";
 131      foreach($save_errors AS $save_error) {
 132          echo '<li>' . $save_error . "</li>\n";
 133      }
 134      echo "</ul>\n";
 135      ?>
 136      </div>
 137  <?php } elseif ( isset($_POST['SAVECONF'])) { ?>
 138      <div class="serendipityAdminMsgSuccess"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="<?php echo serendipity_getTemplateFile('admin/img/admin_msg_success.png'); ?>" alt="" /><?php echo DONE .': '. sprintf(SETTINGS_SAVED_AT, serendipity_strftime('%H:%M:%S')); ?></div>
 139  <?php } ?>
 140  
 141  <form method="post" name="serendipityPluginConfigure">
 142      <?php echo serendipity_setFormToken(); ?>
 143      <table cellpadding="5" style="border: 1px dashed" width="90%" align="center">
 144          <tr>
 145              <th width="100"><?php echo NAME; ?></th>
 146              <td><?php echo $name; ?> (<em><?php echo get_class($plugin); ?></em>)</td>
 147          </tr>
 148  
 149          <tr>
 150              <th style="vertical-align: top"><?php echo DESCRIPTION; ?></th>
 151              <td>
 152              <?php
 153                  echo $desc;
 154                  if (!empty($documentation)) {
 155                      echo '<br /><a href="' . htmlspecialchars($documentation) . '">' . PLUGIN_DOCUMENTATION . '</a>';
 156                  }
 157  
 158                  if (@file_exists(dirname($plugin->pluginFile) . '/ChangeLog')) {
 159                      echo '<br /><a href="plugins/' . $plugin->act_pluginPath . '/ChangeLog">' . PLUGIN_DOCUMENTATION_CHANGELOG . '</a>';
 160                  }
 161  
 162                  if (@file_exists(dirname($plugin->pluginFile) . '/documentation_' . $serendipity['lang'] . '.html')) {
 163                      echo '<br /><a href="plugins/' . $plugin->act_pluginPath . '/documentation_' . $serendipity['lang'] . '.html">' . PLUGIN_DOCUMENTATION_LOCAL . '</a>';
 164                  } elseif (@file_exists(dirname($plugin->pluginFile) . '/documentation_en.html')) {
 165                      echo '<br /><a href="plugins/' . $plugin->act_pluginPath . '/documentation_en.html">' . PLUGIN_DOCUMENTATION_LOCAL . '</a>';
 166                  } elseif (@file_exists(dirname($plugin->pluginFile) . '/documentation.html')) {
 167                      echo '<br /><a href="plugins/' . $plugin->act_pluginPath . '/documentation.html">' . PLUGIN_DOCUMENTATION_LOCAL . '</a>';
 168                  } elseif (@file_exists(dirname($plugin->pluginFile) . '/README')) {
 169                      echo '<br /><a href="plugins/' . $plugin->act_pluginPath . '/README">' . PLUGIN_DOCUMENTATION_LOCAL . '</a>';
 170                  }
 171              ?>
 172              </td>
 173          </tr>
 174           <?php
 175              if (!empty($license)) {
 176                  echo '<tr><th>'.MEDIA_PROPERTY_COPYRIGHT.'</th><td>'.$license.'</td></tr>';
 177              }
 178          ?>
 179      </table>
 180  <br />
 181  
 182  <?php serendipity_plugin_config($plugin, $bag, $name, $desc, $config_names, true, true, true, true, 'plugin', $config_groups); ?>
 183  </form>
 184  <?php
 185  
 186  } elseif ( $serendipity['GET']['adminAction'] == 'addnew' ) {
 187  ?>
 188  <?php if ( $serendipity['GET']['type'] == 'event' ) { ?>
 189      <h2><?php echo EVENT_PLUGINS ?></h2>
 190  <?php } else { ?>
 191      <h2><?php echo SIDEBAR_PLUGINS ?></h2>
 192  <?php } ?>
 193  <br />
 194  <?php
 195      $foreignPlugins = $pluginstack = $errorstack = array();
 196      serendipity_plugin_api::hook_event('backend_plugins_fetchlist', $foreignPlugins);
 197      $pluginstack = array_merge((array)$foreignPlugins['pluginstack'], $pluginstack);
 198      $errorstack  = array_merge((array)$foreignPlugins['errorstack'], $errorstack);
 199  
 200      $plugins = serendipity_plugin_api::get_installed_plugins();
 201      $classes = serendipity_plugin_api::enum_plugin_classes(($serendipity['GET']['type'] === 'event'));
 202      usort($classes, 'serendipity_pluginListSort');
 203  
 204      $counter    = 0;
 205      foreach ($classes as $class_data) {
 206          $pluginFile =  serendipity_plugin_api::probePlugin($class_data['name'], $class_data['classname'], $class_data['pluginPath']);
 207          $plugin     =& serendipity_plugin_api::getPluginInfo($pluginFile, $class_data, $serendipity['GET']['type']);
 208  
 209          if (is_object($plugin)) {
 210              // Object is returned when a plugin could not be cached.
 211              $bag = new serendipity_property_bag;
 212              $plugin->introspect($bag);
 213  
 214              // If a foreign plugin is upgradable, keep the new version number.
 215              if (isset($foreignPlugins['pluginstack'][$class_data['name']]) && $foreignPlugins['pluginstack'][$class_data['name']]['upgradable']) {
 216                  $class_data['upgrade_version'] = $foreignPlugins['pluginstack'][$class_data['name']]['upgrade_version'];
 217              }
 218  
 219              $props = serendipity_plugin_api::setPluginInfo($plugin, $pluginFile, $bag, $class_data, 'local', $foreignPlugins);
 220  
 221              $counter++;
 222          } elseif (is_array($plugin)) {
 223              // Array is returned if a plugin could be fetched from info cache
 224              $props = $plugin;
 225          } else {
 226              $props = false;
 227          }
 228  
 229          if (is_array($props)) {
 230              if (version_compare($props['version'], $props['upgrade_version'], '<')) {
 231                  $props['upgradable']      = true;
 232                  $props['customURI']      .= $foreignPlugins['baseURI'] . $foreignPlugins['upgradeURI'];
 233              }
 234  
 235              $props['installable']  = !($props['stackable'] === false && in_array($class_data['true_name'], $plugins));
 236              $props['requirements'] = unserialize($props['requirements']);
 237  
 238              if (empty($props['changelog']) && @file_exists(dirname($plugin->pluginFile) . '/ChangeLog')) {
 239                  $props['changelog'] = 'plugins/' . $props['pluginPath'] . '/ChangeLog';
 240              }
 241  
 242              if (empty($props['local_documentation'])) {
 243                  if (@file_exists(dirname($props['plugin_file']) . '/documentation_' . $serendipity['lang'] . '.html')) {
 244                      $props['local_documentation'] = 'plugins/' . $props['pluginPath'] . '/documentation_' . $serendipity['lang'] . '.html';
 245                  } elseif (@file_exists(dirname($props['plugin_file']) . '/documentation_en.html')) {
 246                      $props['local_documentation'] = 'plugins/' . $props['pluginPath'] . '/documentation_en.html';
 247                  } elseif (@file_exists(dirname($props['plugin_file']) . '/documentation.html')) {
 248                      $props['local_documentation'] = 'plugins/' . $props['pluginPath'] . '/documentation.html';
 249                  } elseif (@file_exists(dirname($props['plugin_file']) . '/README')) {
 250                      $props['local_documentation'] = 'plugins/' . $props['pluginPath'] . '/README';
 251                  }
 252              }
 253  
 254              $pluginstack[$class_data['true_name']] = $props;
 255          } else {
 256              // False is returned if a plugin could not be instantiated
 257              $errorstack[] = $class_data['true_name'];
 258          }
 259      }
 260  
 261      usort($pluginstack, 'serendipity_pluginListSort');
 262      $pluggroups     = array();
 263      $pluggroups[''] = array();
 264      foreach($pluginstack AS $plugname => $plugdata) {
 265          if ($serendipity['GET']['only_group'] == 'ALL') {
 266              $pluggroups['ALL'][] = $plugdata;
 267          } elseif ($serendipity['GET']['only_group'] == 'UPGRADE' && $plugdata['upgradable']) {
 268              $pluggroups['UPGRADE'][] = $plugdata;
 269          } elseif (is_array($plugdata['groups'])) {
 270              foreach($plugdata['groups'] AS $group) {
 271                  $pluggroups[$group][] = $plugdata;
 272              }
 273          } else {
 274              $pluggroups[''][] = $plugdata;
 275          }
 276      }
 277      ksort($pluggroups);
 278  
 279      foreach($errorstack as $e_idx => $e_name) {
 280          echo ERROR . ': ' . $e_name . '<br />';
 281      }
 282  
 283      if ($serendipity['GET']['only_group'] == 'UPGRADE') {
 284          serendipity_plugin_api::hook_event('backend_pluginlisting_header_upgrade', $pluggroups);
 285      }
 286  ?>
 287  <table cellspacing="0" cellpadding="0" border="0" width="100%">
 288  <?php
 289      $available_groups = array_keys($pluggroups);
 290      foreach($pluggroups AS $pluggroup => $groupstack) {
 291          if (empty($pluggroup)) {
 292          ?>
 293      <tr>
 294          <td colspan="2" class="serendipity_pluginlist_header">
 295              <form action="serendipity_admin.php" method="get">
 296                  <?php echo serendipity_setFormToken(); ?>
 297                  <input type="hidden" name="serendipity[adminModule]" value="plugins" />
 298                  <input type="hidden" name="serendipity[adminAction]" value="addnew" />
 299                  <input type="hidden" name="serendipity[type]" value="<?php echo htmlspecialchars($serendipity['GET']['type']); ?>" />
 300                  <?php echo FILTERS; ?>: <select name="serendipity[only_group]">
 301              <?php foreach((array)$available_groups AS $available_group) {
 302                      ?>
 303                      <option value="<?php echo $available_group; ?>" <?php echo ($serendipity['GET']['only_group'] == $available_group ? 'selected="selected"' : ''); ?>><?php echo serendipity_groupname($available_group); ?>
 304              <?php } ?>
 305                      <option value="ALL" <?php echo ($serendipity['GET']['only_group'] == 'ALL' ? 'selected="selected"' : ''); ?>><?php echo ALL_CATEGORIES; ?>
 306                      <option value="UPGRADE" <?php echo ($serendipity['GET']['only_group'] == 'UPGRADE' ? 'selected="selected"' : ''); ?>><?php echo WORD_NEW; ?>
 307                  </select>
 308                  <input class="serendipityPrettyButton input_button" type="submit" value="<?php echo GO; ?>" />
 309              </form>
 310          </td>
 311      </tr>
 312          <?php
 313              if (!empty($serendipity['GET']['only_group'])) {
 314                  continue;
 315              }
 316          } elseif (!empty($serendipity['GET']['only_group']) && $pluggroup != $serendipity['GET']['only_group']) {
 317              continue;
 318          } else {
 319          ?>
 320      <tr>
 321          <td colspan="2" class="serendipity_pluginlist_section"><strong><?php echo serendipity_groupname($pluggroup); ?></strong></td>
 322      </tr>
 323          <?php
 324          }
 325  ?>
 326      <tr>
 327          <td><strong>Plugin</strong></td>
 328          <td width="100" align="center"><strong>Action</strong></td>
 329      </tr>
 330  <?php
 331          foreach ($groupstack as $plug) {
 332              $jsLine = " onmouseout=\"document.getElementById('serendipity_plugin_". $plug['class_name'] ."').className='';\"";
 333              $jsLine .= " onmouseover=\"document.getElementById('serendipity_plugin_". $plug['class_name'] ."').className='serendipity_PluginAdminHighlight';\"";
 334  
 335              $pluginInfo = $notice = array();
 336  
 337              if (!empty($plug['author'])) {
 338                  $pluginInfo[] = AUTHOR  . ': ' . $plug['author'];
 339              }
 340  
 341              if (!empty($plug['version'])) {
 342                  $pluginInfo[] = VERSION  . ': ' . $plug['version'];
 343              }
 344  
 345              if (!empty($plug['website'])) {
 346                  $pluginInfo[] = '<a href="' . htmlspecialchars($plug['website']) . '">' . PLUGIN_DOCUMENTATION . '</a>';
 347              }
 348  
 349              if (!empty($plug['local_documentation'])) {
 350                  $pluginInfo[] = '<a href="' . htmlspecialchars($plug['local_documentation']) . '">' . PLUGIN_DOCUMENTATION_LOCAL . '</a>';
 351              }
 352  
 353              if (!empty($plug['changelog'])) {
 354                  $pluginInfo[] = '<a href="' . htmlspecialchars($plug['changelog']) . '">' . PLUGIN_DOCUMENTATION_CHANGELOG . '</a>';
 355              }
 356  
 357              if (!empty($plug['upgrade_version']) && $plug['upgrade_version'] != $plug['version']) {
 358                  $pluginInfo[] = sprintf(UPGRADE_TO_VERSION, $plug['upgrade_version']);
 359              }
 360  
 361              if (!empty($plug['pluginlocation']) && $plug['pluginlocation'] != 'local') {
 362                  $pluginInfo[] = '(' . htmlspecialchars($plug['pluginlocation']) . ')';
 363                  $installimage = serendipity_getTemplateFile('admin/img/install_now_' . strtolower($plug['pluginlocation']) . '.png');
 364              } else {
 365                  $installimage = serendipity_getTemplateFile('admin/img/install_now.png');
 366              }
 367  
 368              if (!isset($plug['customURI'])) {
 369                  $plug['customURI'] = '';
 370              }
 371  
 372              if ( !empty($plug['requirements']['serendipity']) && version_compare($plug['requirements']['serendipity'], serendipity_getCoreVersion($serendipity['version']), '>') ) {
 373                  $notice['requirements_failures'][] = 's9y ' . $plug['requirements']['serendipity'];
 374              }
 375  
 376              if ( !empty($plug['requirements']['php']) && version_compare($plug['requirements']['php'], phpversion(), '>') ) {
 377                  $notice['requirements_failures'][] = 'PHP ' . $plug['requirements']['php'];
 378              }
 379  
 380              /* Enable after Smarty 2.6.7 upgrade.
 381               * TODO: How can we get current Smarty version here? $smarty is not created!
 382              if ( !empty($plug['requirements']['smarty']) && version_compare($plug['requirements']['smarty'], '2.6.7', '>') ) {
 383                  $notice['requirements_failures'][] = 'Smarty: ' . $plug['requirements']['smarty'];
 384              }
 385              */
 386  
 387              if (count($notice['requirements_failures']) > 0) {
 388                  $plug['requirements_fail'] = true;
 389              }
 390  
 391  ?>
 392      <tr id="serendipity_plugin_<?php echo $plug['class_name']; ?>">
 393          <td colspan="2" <?php echo $jsLine ?>>
 394              <table width="100%" cellpadding="3" cellspacing="0" border="0">
 395                  <tr>
 396                      <td><strong><?php echo $plug['name'] ?></strong></td>
 397                      <td width="100" align="center" valign="middle" rowspan="3">
 398                          <?php if ( $plug['requirements_fail'] == true ) { ?>
 399                              <span style="color: #cccccc"><?php printf(UNMET_REQUIREMENTS, implode(', ', $notice['requirements_failures'])); ?></span>
 400                          <?php } elseif ( $plug['upgradable'] == true ) { ?>
 401                              <a href="?serendipity[adminModule]=plugins&amp;serendipity[pluginPath]=<?php echo $plug['pluginPath']; ?>&amp;serendipity[install_plugin]=<?php echo $plug['plugin_class'] . $plug['customURI'] ?>"><img src="<?php echo serendipity_getTemplateFile('admin/img/upgrade_now.png') ?>" title="<?php echo UPGRADE ?>" alt="<?php echo UPGRADE ?>" border="0" /></a>
 402                          <?php } elseif ($plug['installable'] == true) { ?>
 403                              <a href="?serendipity[adminModule]=plugins&amp;serendipity[pluginPath]=<?php echo $plug['pluginPath']; ?>&amp;serendipity[install_plugin]=<?php echo $plug['plugin_class'] . $plug['customURI'] ?>"><img src="<?php echo $installimage ?>" title="<?php echo INSTALL ?>" alt="<?php echo INSTALL ?>" border="0" /></a>
 404                          <?php } else { ?>
 405                              <span style="color: #cccccc"><?php echo ALREADY_INSTALLED ?></span>
 406                          <?php } ?>
 407                      </td>
 408                  </tr>
 409                  <tr>
 410                      <td style="padding-left: 10px"><?php echo $plug['description'] ?></td>
 411                  </tr>
 412  <?php       if (count($pluginInfo) > 0) { ?>
 413                  <tr>
 414                      <td style="padding-left: 10px; font-size: x-small">(<?php echo $plug['class_name']; ?>) <?php echo implode('; ', $pluginInfo); ?></td>
 415                  </tr>
 416  <?php       } ?>
 417              </table>
 418          </td>
 419      </tr>
 420  <?php
 421          }
 422      }
 423  ?>
 424      <tr>
 425          <td colspan="2" align="right"><?php printf(PLUGIN_AVAILABLE_COUNT, count($pluginstack)); ?></td>
 426      </tr>
 427  </table>
 428  
 429  <?php
 430  } else {
 431      /* show general plugin list */
 432  
 433      /* get sidebar locations */
 434      serendipity_smarty_init();
 435  
 436      if (is_array($template_config)) {
 437          $template_vars =& serendipity_loadThemeOptions($template_config);
 438      }
 439  
 440      $col_assoc = array(
 441          'event_col'  => 'event',
 442          'eventh_col' => 'eventh'
 443      );
 444      if (isset($template_vars['sidebars'])) {
 445          $sidebars = explode(',', $template_vars['sidebars']);
 446      } elseif (isset($serendipity['sidebars'])) {
 447          $sidebars = $serendipity['sidebars'];
 448      } else {
 449          $sidebars = array('left', 'hide', 'right');
 450      }
 451  
 452      foreach($sidebars AS $sidebar) {
 453          $col_assoc[$sidebar . '_col'] = $sidebar;
 454      }
 455  
 456      /* preparse Javascript-generated input */
 457      if (isset($_POST['SAVE']) && !empty($_POST['serendipity']['pluginorder'])) {
 458          $parts = explode(':', $_POST['serendipity']['pluginorder']);
 459  
 460          foreach($parts AS $sidepart) {
 461              preg_match('@^(.+)\((.*)\)$@imsU', $sidepart, $matches);
 462              if (!isset($col_assoc[$matches[1]])) {
 463                  continue;
 464              }
 465              $pluginsidelist = explode(',', $matches[2]);
 466              foreach($pluginsidelist AS $pluginname) {
 467                  $pluginname = trim(urldecode(str_replace(array('s9ycid', '-'), array('', '%'), $pluginname)));
 468  
 469                  if (empty($pluginname)) {
 470                      continue;
 471                  }
 472                  $serendipity['POST']['placement'][$pluginname] = $col_assoc[$matches[1]];
 473                  $new_order[] = $pluginname;
 474  
 475              }
 476          }
 477  
 478          if (is_array($new_order)) {
 479              foreach($new_order AS $new_order_pos => $order_plugin) {
 480                  serendipity_db_query("UPDATE {$serendipity['dbPrefix']}plugins SET sort_order = ". (int)$new_order_pos . " WHERE name='" . serendipity_db_escape_string($order_plugin) . "'");
 481              }
 482          }
 483      }
 484  
 485      if (isset($_POST['SAVE']) && isset($_POST['serendipity']['placement']) && serendipity_checkFormToken()) {
 486          foreach ($_POST['serendipity']['placement'] as $plugin_name => $placement) {
 487              serendipity_plugin_api::update_plugin_placement(
 488                  addslashes($plugin_name),
 489                  addslashes($placement)
 490              );
 491  
 492              serendipity_plugin_api::update_plugin_owner(
 493                  addslashes($plugin_name),
 494                  addslashes($_POST['serendipity']['ownership'][$plugin_name])
 495              );
 496          }
 497      }
 498  
 499      if (isset($serendipity['GET']['install_plugin'])) {
 500          $authorid = $serendipity['authorid'];
 501          if (serendipity_checkPermission('adminPluginsMaintainOthers')) {
 502              $authorid = '0';
 503          }
 504  
 505          $fetchplugin_data = array('GET'     => &$serendipity['GET'],
 506                                    'install' => true);
 507          serendipity_plugin_api::hook_event('backend_plugins_fetchplugin', $fetchplugin_data);
 508  
 509          if ($fetchplugin_data['install']) {
 510              $serendipity['debug']['pluginload'] = array();
 511              $inst = serendipity_plugin_api::create_plugin_instance($serendipity['GET']['install_plugin'], null, (serendipity_plugin_api::is_event_plugin($serendipity['GET']['install_plugin']) ? 'event': 'right'), $authorid, serendipity_db_escape_string($serendipity['GET']['pluginPath']));
 512  
 513              /* Load the new plugin */
 514              $plugin = &serendipity_plugin_api::load_plugin($inst);
 515              if (!is_object($plugin)) {
 516                  echo "DEBUG: Plugin " . htmlspecialchars($inst) . " not an object: " . htmlspecialchars(print_r($plugin, true)) 
 517                       . ".<br />Input: " . htmlspecialchars(print_r($serendipity['GET'], true)) . ".<br /><br />\n\nThis error 
 518                       can happen if a plugin was not properly downloaded (check your plugins directory if the requested plugin 
 519                       was downloaded) or the inclusion of a file failed (permissions?)<br />\n";
 520                  echo "Backtrace:<br />\n" . nl2br(htmlspecialchars(implode("\n", $serendipity['debug']['pluginload']))) . "<br />";
 521              }
 522              $bag  = new serendipity_property_bag;
 523              $plugin->introspect($bag);
 524  
 525              serendipity_plugin_api::hook_event('backend_plugins_install', $serendipity['GET']['install_plugin'], $fetchplugin_data);
 526  
 527              if ($bag->is_set('configuration')) {
 528                  /* Only play with the plugin if there is something to play with */
 529                  echo '<script type="text/javascript">location.href = \'' . $serendipity['baseURL'] . 'serendipity_admin.php?serendipity[adminModule]=plugins&serendipity[plugin_to_conf]=' . $inst . '\';</script>';
 530                  die();
 531              } else {
 532                  /* If no config is available, redirect to plugin overview, because we do not want that a user can install the plugin a second time via accidental browser refresh */
 533                  echo '<script type="text/javascript">location.href = \'' . $serendipity['baseURL'] . 'serendipity_admin.php?serendipity[adminModule]=plugins\';</script>';
 534                  die();
 535              }
 536          } else {
 537              serendipity_plugin_api::hook_event('backend_plugins_update', $serendipity['GET']['install_plugin'], $fetchplugin_data);
 538          }
 539      }
 540  
 541      if (isset($_POST['REMOVE']) && serendipity_checkFormToken()) {
 542          if (is_array($_POST['serendipity']['plugin_to_remove'])) {
 543              foreach ($_POST['serendipity']['plugin_to_remove'] as $key) {
 544                  $plugin =& serendipity_plugin_api::load_plugin($key);
 545  
 546                  if ($plugin->serendipity_owner == '0' || $plugin->serendipity_owner == $serendipity['authorid'] || serendipity_checkPermission('adminPluginsMaintainOthers')) {
 547                      serendipity_plugin_api::remove_plugin_instance($key);
 548                  }
 549              }
 550          }
 551      }
 552  ?>
 553  
 554  <?php if (isset($_POST['SAVE'])) { ?>
 555      <div class="serendipityAdminMsgSuccess"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="<?php echo serendipity_getTemplateFile('admin/img/admin_msg_success.png'); ?>" alt="" /><?php echo DONE .': '. sprintf(SETTINGS_SAVED_AT, serendipity_strftime('%H:%M:%S')); ?></div>
 556  <?php } ?>
 557  
 558      <div><?php echo BELOW_IS_A_LIST_OF_INSTALLED_PLUGINS ?></div>
 559  <?php
 560      if (!isset($serendipity['eyecandy']) || serendipity_db_bool($serendipity['eyecandy'])) {
 561          echo '<script src="' . serendipity_getTemplateFile('dragdrop.js') . '" type="text/javascript"></script>';
 562          echo '<div class="warning js_warning"><em>' . PREFERENCE_USE_JS_WARNING . '</em></div>';
 563      }
 564  
 565      serendipity_plugin_api::hook_event('backend_pluginlisting_header', $serendipity['eyecandy']);
 566  ?>
 567      <br />
 568  
 569      <h3><?php echo SIDEBAR_PLUGINS ?></h3>
 570      <a href="?serendipity[adminModule]=plugins&amp;serendipity[adminAction]=addnew" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/install.png') ?>" style="border: 0px none ; vertical-align: middle; display: inline;" alt="" /><?php echo sprintf(CLICK_HERE_TO_INSTALL_PLUGIN, SIDEBAR_PLUGIN) ?></a>
 571      <?php serendipity_plugin_api::hook_event('backend_plugins_sidebar_header', $serendipity); ?>
 572      <?php show_plugins(false, $sidebars); ?>
 573  
 574      <br />
 575      <br />
 576  
 577      <h3><?php echo EVENT_PLUGINS ?></h3>
 578      <a href="?serendipity[adminModule]=plugins&amp;serendipity[adminAction]=addnew&amp;serendipity[type]=event" class="serendipityIconLink"><img src="<?php echo serendipity_getTemplateFile('admin/img/install.png') ?>" style="border: 0px none ; vertical-align: middle; display: inline;" alt="" /><?php echo sprintf(CLICK_HERE_TO_INSTALL_PLUGIN, EVENT_PLUGIN) ?></a>
 579      <?php serendipity_plugin_api::hook_event('backend_plugins_event_header', $serendipity); ?>
 580      <?php show_plugins(true); ?>
 581  
 582      <?php if (count($serendipity['memSnaps']) > 0) { ?>
 583      <h3>Memory Usage</h3>
 584      <div>
 585          <pre><?php print_r($serendipity['memSnaps']); ?></pre>
 586      </div>
 587      <?php } ?>
 588  <?php
 589  }
 590  /* vim: set sts=4 ts=4 expandtab : */

title

Description

title

Description

title

Description

title

title

Body