includes/plugins.php
author Dan
Sun, 15 Jun 2008 01:30:00 -0400
changeset 573 43e7254afdb4
parent 568 3700f7124c2b
child 590 03a60844c7c5
permissions -rw-r--r--
Renamed some functions (that were new in this release anyway) due to compatibility broken with PunBB bridge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     1
<?php
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     2
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     3
/*
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     4
 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
536
218a627eb53e Rebrand as 1.1.4 (Caoineag alpha 4)
Dan
parents: 529
diff changeset
     5
 * Version 1.1.4 (Caoineag alpha 4)
218a627eb53e Rebrand as 1.1.4 (Caoineag alpha 4)
Dan
parents: 529
diff changeset
     6
 * Copyright (C) 2006-2008 Dan Fuhry
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     7
 *
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     8
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     9
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    10
 *
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    12
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    13
 */
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    14
 
464
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    15
/**
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    16
 * Class used to handle and process plugin requests and loading. Singleton.
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    17
 * @package Enano
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    18
 * @author Dan Fuhry <dan@enanocms.org>
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    19
 * @copyright (C) 2006-2008 Enano Project
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    20
 * @license GNU General Public License <http://enanocms.org/Special:GNU_General_Public_License>
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    21
 */
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    22
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    23
class pluginLoader {
464
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    24
  
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    25
  /**
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    26
   * The list of hooks registered.
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    27
   * @var array
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    28
   * @access private
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    29
   */
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    30
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    31
  var $hook_list;
464
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    32
  
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    33
  /**
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    34
   * The list of plugins that should be loaded. Used only by common.php.
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    35
   * @var array
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    36
   * @access private
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    37
   */
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    38
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    39
  var $load_list;
464
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    40
  
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    41
  /**
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    42
   * The list of plugins that are loaded currently. This is only used by the loaded() method which in turn is
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    43
   * used by template files with the <!-- IFPLUGIN --> special tag.
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    44
   * @var array
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    45
   * @access private
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    46
   */
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    47
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    48
  var $loaded_plugins;
464
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    49
  
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    50
  /**
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    51
   * The list of plugins that are always loaded because they're part of the Enano core. This cannot be modified
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    52
   * by any external code because user plugins are loaded after the load_list is calculated. Can be useful in
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    53
   * alternative administration panel frameworks that need the list of system plugins.
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    54
   * @var array
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    55
   */
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    56
  
403
2c9745b5c09d Started on a Special:RecentChanges page, more to come.
Dan
parents: 387
diff changeset
    57
  var $system_plugins = Array('SpecialUserFuncs.php','SpecialUserPrefs.php','SpecialPageFuncs.php','SpecialAdmin.php','SpecialCSS.php','SpecialUpdownload.php','SpecialSearch.php','PrivateMessages.php','SpecialGroups.php', 'SpecialRecentChanges.php');
464
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    58
  
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    59
  /**
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    60
   * Name kept for compatibility. Effectively a constructor. Calculates the list of plugins that should be loaded
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    61
   * and puts that list in the $load_list property. Plugin developers have absolutely no use for this whatsoever.
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    62
   */
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
    63
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    64
  function loadAll() 
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    65
  {
527
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
    66
    global $db, $session, $paths, $template, $plugins; // Common objects
568
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 560
diff changeset
    67
    
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 560
diff changeset
    68
    // if we're in an upgrade, just skip this step
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 560
diff changeset
    69
    if ( defined('IN_ENANO_UPGRADE') )
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 560
diff changeset
    70
    {
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 560
diff changeset
    71
      $this->load_list = array();
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 560
diff changeset
    72
      return false;
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 560
diff changeset
    73
    }
3700f7124c2b A bit of UX improvement to upgrade UI; updated readme for 1.1.4
Dan
parents: 560
diff changeset
    74
    
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    75
    $dir = ENANO_ROOT.'/plugins/';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    76
    
527
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
    77
    $this->load_list = $this->system_plugins;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
    78
    $q = $db->sql_query('SELECT plugin_filename, plugin_version FROM ' . table_prefix . 'plugins WHERE plugin_flags & ~' . PLUGIN_DISABLED . ' = plugin_flags;');
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
    79
    if ( !$q )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
    80
      $db->_die();
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    81
    
527
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
    82
    while ( $row = $db->fetchrow() )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
    83
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
    84
      $this->load_list[] = $row['plugin_filename'];
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
    85
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
    86
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
    87
    $this->loaded_plugins = $this->get_plugin_list($this->load_list);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    88
    
527
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
    89
    // check for out-of-date plugins
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
    90
    foreach ( $this->load_list as $i => $plugin )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    91
    {
527
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
    92
      if ( in_array($plugin, $this->system_plugins) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
    93
        continue;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
    94
      if ( $this->loaded_plugins[$plugin]['status'] & PLUGIN_OUTOFDATE )
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    95
      {
527
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
    96
        // it's out of date, don't load
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
    97
        unset($this->load_list[$i]);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
    98
        unset($this->loaded_plugins[$plugin]);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    99
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   100
    }
527
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   101
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   102
    $this->load_list = array_unique($this->load_list);
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   103
  }
464
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   104
  
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   105
  /**
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   106
   * Name kept for compatibility. This method is used to add a new hook into the code somewhere. Plugins are encouraged
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   107
   * to set hooks and hook into other plugins in a fail-safe way, this encourages reuse of code. Returns an array, whose
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   108
   * values should be eval'ed.
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   109
   * @example <code>
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   110
   $code = $plugins->setHook('my_hook_name');
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   111
   foreach ( $code as $cmd )
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   112
   {
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   113
     eval($cmd);
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   114
   }
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   115
   </code>
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   116
   * @param string The name of the hook.
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   117
   * @param array Deprecated.
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   118
   */
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   119
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   120
  function setHook($name, $opts = Array()) {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   121
    if(isset($this->hook_list[$name]) && is_array($this->hook_list[$name]))
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   122
    {
379
82b991bee797 Minor and hopefully non-breaking change to plugin loader to possibly double performance at hook points
Dan
parents: 378
diff changeset
   123
      return array(implode("\n", $this->hook_list[$name]));
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   124
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   125
    else
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   126
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   127
      return Array();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   128
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   129
  }
464
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   130
  
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   131
  /**
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   132
   * Attaches to a hook effectively scheduling some code to be run at that point. You should try to keep hooks clean by
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   133
   * making a function that has variables that need to be modified passed by reference.
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   134
   * @example Simple example: <code>
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   135
   $plugins->attachHook('render_wikiformat_pre', '$text = str_replace("Goodbye, Mr. Chips", "Hello, Mr. Carrots", $text);');
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   136
   </code>
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   137
   * @example More complicated example: <code>
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   138
   $plugins->attachHook('render_wikiformat_pre', 'myplugin_parser_ext($text);');
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   139
   
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   140
   // Notice that $text is passed by reference.
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   141
   function myplugin_parser_ext(&$text)
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   142
   {
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   143
     $text = str_replace("Goodbye, Mr. Chips", "Hello, Mr. Carrots", $text);
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   144
   }
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   145
   </code>
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   146
   */
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   147
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   148
  function attachHook($name, $code) {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   149
    if(!isset($this->hook_list[$name]))
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   150
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   151
      $this->hook_list[$name] = Array();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   152
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   153
    $this->hook_list[$name][] = $code;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   154
  }
464
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   155
  
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   156
  /**
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   157
   * Tell whether a plugin is loaded or not.
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   158
   * @param string The filename of the plugin
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   159
   * @return bool
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   160
   */
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   161
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   162
  function loaded($plugid)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   163
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   164
    return isset( $this->loaded_plugins[$plugid] );
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   165
  }
507
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   166
  
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   167
  /**
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   168
   * Parses all special comment blocks in a plugin and returns an array in the format:
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   169
   <code>
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   170
   array(
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   171
       0 => array(
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   172
           'block' => 'upgrade',
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   173
           // parsed from the block's parameters section
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   174
             'release_from' => '1.0b1',
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   175
             'release_to' => '1.0b2',
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   176
           'value' => 'foo'
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   177
         ),
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   178
       1 => array(
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   179
           ...
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   180
         )
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   181
     );
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   182
   </code>
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   183
   * @param string Path to plugin file
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   184
   * @param string Optional. The type of block to fetch. If this is specified, only the block type specified will be read, all others will be discarded.
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   185
   * @return array
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   186
   */
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   187
  
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   188
  public static function parse_plugin_blocks($file, $type = false)
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   189
  {
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   190
    if ( !file_exists($file) )
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   191
    {
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   192
      return array();
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   193
    }
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   194
    $blocks = array();
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   195
    $contents = @file_get_contents($file);
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   196
    if ( empty($contents) )
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   197
    {
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   198
      return array();
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   199
    }
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   200
    
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   201
    $regexp = '#^/\*\*!([a-z0-9_]+)'  // block header and type
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   202
            . '(([\s]+[a-z0-9_]+[\s]*=[\s]*".+?"[\s]*;)*)' // parameters
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   203
            . '[\s]*\*\*' . "\n"      // spacing and header close
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   204
            . '([\w\W]+?)' . "\n"     // value
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   205
            . '\*\*!\*/'              // closing comment
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   206
            . '#m';
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   207
            
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   208
    // Match out all blocks
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   209
    $results = preg_match_all($regexp, $contents, $blocks);
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   210
    
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   211
    $return = array();
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   212
    foreach ( $blocks[0] as $i => $_ )
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   213
    {
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   214
      if ( is_string($type) && $blocks[1][$i] !== $type )
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   215
        continue;
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   216
      
519
94214ec0871c Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents: 507
diff changeset
   217
      $value =& $blocks[4][$i];
94214ec0871c Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents: 507
diff changeset
   218
      // parse includes
94214ec0871c Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents: 507
diff changeset
   219
      preg_match_all('/^!include [\'"]?(.+?)[\'"]?$/m', $value, $includes);
94214ec0871c Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents: 507
diff changeset
   220
      foreach ( $includes[0] as $i => $replace )
94214ec0871c Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents: 507
diff changeset
   221
      {
94214ec0871c Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents: 507
diff changeset
   222
        $filename = ENANO_ROOT . '/' . $includes[1][$i];
94214ec0871c Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents: 507
diff changeset
   223
        if ( @file_exists( $filename ) && @is_readable( $filename ) )
94214ec0871c Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents: 507
diff changeset
   224
        {
94214ec0871c Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents: 507
diff changeset
   225
          $contents = @file_get_contents($filename);
94214ec0871c Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents: 507
diff changeset
   226
          $value = str_replace_once($replace, $contents, $value);
94214ec0871c Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents: 507
diff changeset
   227
        }
94214ec0871c Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents: 507
diff changeset
   228
      }
94214ec0871c Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents: 507
diff changeset
   229
      
507
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   230
      $el = self::parse_vars($blocks[2][$i]);
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   231
      $el['block'] = $blocks[1][$i];
519
94214ec0871c Started work on the new plugin manager and associated management code. Very incomplete at this point and not usable.
Dan
parents: 507
diff changeset
   232
      $el['value'] = $value;
507
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   233
      $return[] = $el;
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   234
    }
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   235
    
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   236
    return $return;
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   237
  }
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   238
  
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   239
  private static function parse_vars($var_block)
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   240
  {
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   241
    preg_match_all('/[\s]+([a-z0-9_]+)[\s]*=[\s]*"(.+?)";/', $var_block, $matches);
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   242
    $return = array();
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   243
    foreach ( $matches[0] as $i => $_ )
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   244
    {
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   245
      $return[ $matches[1][$i] ] = $matches[2][$i];
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   246
    }
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   247
    return $return;
586fd7d3202d Fixed some stray version numbers (again!); added support for Diffie-Hellman logins in the normal login form (not AJAX) - even works in IE
Dan
parents: 464
diff changeset
   248
  }
527
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   249
  
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   250
  /**
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   251
   * Reads all plugins in the filesystem and cross-references them with the database, providing a very complete summary of plugins
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   252
   * on the site.
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   253
   * @param array If specified, will restrict scanned files to this list. Defaults to null, which means all PHP files will be scanned.
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   254
   * @return array
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   255
   */
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   256
  
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   257
  function get_plugin_list($restrict = null)
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   258
  {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   259
    global $db, $session, $paths, $template, $plugins; // Common objects
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   260
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   261
    // Scan all plugins
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   262
    $plugin_list = array();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   263
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   264
    if ( $dirh = @opendir( ENANO_ROOT . '/plugins' ) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   265
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   266
      while ( $dh = @readdir($dirh) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   267
      {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   268
        if ( !preg_match('/\.php$/i', $dh) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   269
          continue;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   270
        
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   271
        if ( is_array($restrict) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   272
          if ( !in_array($dh, $restrict) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   273
            continue;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   274
          
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   275
        $fullpath = ENANO_ROOT . "/plugins/$dh";
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   276
        // it's a PHP file, attempt to read metadata
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   277
        // pass 1: try to read a !info block
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   278
        $blockdata = $this->parse_plugin_blocks($fullpath, 'info');
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   279
        if ( empty($blockdata) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   280
        {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   281
          // no !info block, check for old header
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   282
          $fh = @fopen($fullpath, 'r');
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   283
          if ( !$fh )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   284
            // can't read, bail out
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   285
            continue;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   286
          $plugin_data = array();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   287
          for ( $i = 0; $i < 8; $i++ )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   288
          {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   289
            $plugin_data[] = @fgets($fh, 8096);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   290
          }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   291
          // close our file handle
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   292
          fclose($fh);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   293
          // is the header correct?
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   294
          if ( trim($plugin_data[0]) != '<?php' || trim($plugin_data[1]) != '/*' )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   295
          {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   296
            // nope. get out.
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   297
            continue;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   298
          }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   299
          // parse all the variables
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   300
          $plugin_meta = array();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   301
          for ( $i = 2; $i <= 7; $i++ )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   302
          {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   303
            if ( !preg_match('/^([A-z0-9 ]+?): (.+?)$/', trim($plugin_data[$i]), $match) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   304
              continue 2;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   305
            $plugin_meta[ strtolower($match[1]) ] = $match[2];
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   306
          }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   307
        }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   308
        else
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   309
        {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   310
          // parse JSON block
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   311
          $plugin_data =& $blockdata[0]['value'];
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   312
          $plugin_data = enano_clean_json(enano_trim_json($plugin_data));
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   313
          try
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   314
          {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   315
            $plugin_meta_uc = enano_json_decode($plugin_data);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   316
          }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   317
          catch ( Exception $e )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   318
          {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   319
            continue;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   320
          }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   321
          // convert all the keys to lowercase
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   322
          $plugin_meta = array();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   323
          foreach ( $plugin_meta_uc as $key => $value )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   324
          {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   325
            $plugin_meta[ strtolower($key) ] = $value;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   326
          }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   327
        }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   328
        if ( !isset($plugin_meta) || !is_array(@$plugin_meta) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   329
        {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   330
          // parsing didn't work.
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   331
          continue;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   332
        }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   333
        // check for required keys
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   334
        $required_keys = array('plugin name', 'plugin uri', 'description', 'author', 'version', 'author uri');
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   335
        foreach ( $required_keys as $key )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   336
        {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   337
          if ( !isset($plugin_meta[$key]) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   338
            // not set, skip this plugin
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   339
            continue 2;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   340
        }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   341
        // decide if it's a system plugin
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   342
        $plugin_meta['system plugin'] = in_array($dh, $this->system_plugins);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   343
        // reset installed variable
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   344
        $plugin_meta['installed'] = false;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   345
        $plugin_meta['status'] = 0;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   346
        // all checks passed
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   347
        $plugin_list[$dh] = $plugin_meta;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   348
      }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   349
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   350
    // gather info about installed plugins
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   351
    $q = $db->sql_query('SELECT plugin_id, plugin_filename, plugin_version, plugin_flags FROM ' . table_prefix . 'plugins;');
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   352
    if ( !$q )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   353
      $db->_die();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   354
    while ( $row = $db->fetchrow() )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   355
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   356
      if ( !isset($plugin_list[ $row['plugin_filename'] ]) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   357
      {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   358
        // missing plugin file, don't report (for now)
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   359
        continue;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   360
      }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   361
      $filename =& $row['plugin_filename'];
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   362
      $plugin_list[$filename]['installed'] = true;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   363
      $plugin_list[$filename]['status'] = PLUGIN_INSTALLED;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   364
      $plugin_list[$filename]['plugin id'] = $row['plugin_id'];
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   365
      if ( $row['plugin_version'] != $plugin_list[$filename]['version'] )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   366
      {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   367
        $plugin_list[$filename]['status'] |= PLUGIN_OUTOFDATE;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   368
        $plugin_list[$filename]['version installed'] = $row['plugin_version'];
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   369
      }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   370
      if ( $row['plugin_flags'] & PLUGIN_DISABLED )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   371
      {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   372
        $plugin_list[$filename]['status'] |= PLUGIN_DISABLED;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   373
      }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   374
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   375
    $db->free_result();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   376
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   377
    // sort it all out by filename
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   378
    ksort($plugin_list);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   379
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   380
    // done
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   381
    return $plugin_list;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   382
  }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   383
  
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   384
  /**
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   385
   * Installs a plugin.
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   386
   * @param string Filename of plugin.
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   387
   * @param array The list of plugins as output by pluginLoader::get_plugin_list(). If not passed, the function is called, possibly wasting time.
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   388
   * @return array JSON-formatted but not encoded response
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   389
   */
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   390
  
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   391
  function install_plugin($filename, $plugin_list = null)
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   392
  {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   393
    global $db, $session, $paths, $template, $plugins; // Common objects
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   394
    global $lang;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   395
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   396
    if ( !$plugin_list )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   397
      $plugin_list = $this->get_plugin_list();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   398
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   399
    // we're gonna need this
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   400
    require_once ( ENANO_ROOT . '/includes/sql_parse.php' );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   401
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   402
    switch ( true ): case true:
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   403
      
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   404
    // is the plugin in the directory and awaiting installation?
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   405
    if ( !isset($plugin_list[$filename]) || (
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   406
        isset($plugin_list[$filename]) && $plugin_list[$filename]['installed']
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   407
      ))
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   408
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   409
      $return = array(
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   410
        'mode' => 'error',
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   411
        'error' => 'Invalid plugin specified.',
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   412
        'debug' => $filename
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   413
      );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   414
      break;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   415
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   416
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   417
    $dataset =& $plugin_list[$filename];
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   418
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   419
    // load up the installer schema
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   420
    $schema = $this->parse_plugin_blocks( ENANO_ROOT . '/plugins/' . $filename, 'install' );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   421
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   422
    $sql = array();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   423
    if ( !empty($schema) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   424
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   425
      // parse SQL
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   426
      $parser = new SQL_Parser($schema[0]['value'], true);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   427
      $parser->assign_vars(array(
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   428
        'TABLE_PREFIX' => table_prefix
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   429
        ));
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   430
      $sql = $parser->parse();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   431
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   432
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   433
    // schema is final, check queries
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   434
    foreach ( $sql as $query )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   435
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   436
      if ( !$db->check_query($query) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   437
      {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   438
        // aww crap, a query is bad
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   439
        $return = array(
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   440
          'mode' => 'error',
528
43535769970b Fixed some bad language string references in plugin management API
Dan
parents: 527
diff changeset
   441
          'error' => $lang->get('acppl_err_upgrade_bad_query'),
527
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   442
        );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   443
        break 2;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   444
      }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   445
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   446
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   447
    // this is it, perform installation
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   448
    foreach ( $sql as $query )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   449
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   450
      if ( substr($query, 0, 1) == '@' )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   451
      {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   452
        $query = substr($query, 1);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   453
        $db->sql_query($query);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   454
      }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   455
      else
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   456
      {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   457
        if ( !$db->sql_query($query) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   458
          $db->die_json();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   459
      }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   460
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   461
    
529
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   462
    // log action
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   463
    $time        = time();
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   464
    $ip_db       = $db->escape($_SERVER['REMOTE_ADDR']);
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   465
    $username_db = $db->escape($session->username);
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   466
    $file_db     = $db->escape($filename);
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   467
    $q = $db->sql_query('INSERT INTO '.table_prefix."logs(log_type, action, time_id, edit_summary, author, page_text) VALUES\n"
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   468
                      . "  ('security', 'plugin_install', $time, '$ip_db', '$username_db', '$file_db');");
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   469
    if ( !$q )
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   470
      $db->_die();
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   471
    
527
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   472
    // register plugin
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   473
    $version_db = $db->escape($dataset['version']);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   474
    $filename_db = $db->escape($filename);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   475
    $flags = PLUGIN_INSTALLED;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   476
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   477
    $q = $db->sql_query('INSERT INTO ' . table_prefix . "plugins ( plugin_version, plugin_filename, plugin_flags )\n"
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   478
                      . "  VALUES ( '$version_db', '$filename_db', $flags );");
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   479
    if ( !$q )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   480
      $db->die_json();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   481
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   482
    $return = array(
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   483
      'success' => true
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   484
    );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   485
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   486
    endswitch;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   487
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   488
    return $return;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   489
  }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   490
  
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   491
  /**
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   492
   * Uninstalls a plugin, removing it completely from the database and calling any custom uninstallation code the plugin specifies.
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   493
   * @param string Filename of plugin.
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   494
   * @param array The list of plugins as output by pluginLoader::get_plugin_list(). If not passed, the function is called, possibly wasting time.
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   495
   * @return array JSON-formatted but not encoded response
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   496
   */
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   497
  
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   498
  function uninstall_plugin($filename, $plugin_list = null)
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   499
  {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   500
    global $db, $session, $paths, $template, $plugins; // Common objects
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   501
    global $lang;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   502
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   503
    if ( !$plugin_list )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   504
      $plugin_list = $this->get_plugin_list();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   505
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   506
    // we're gonna need this
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   507
    require_once ( ENANO_ROOT . '/includes/sql_parse.php' );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   508
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   509
    switch ( true ): case true:
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   510
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   511
    // is the plugin in the directory and already installed?
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   512
    if ( !isset($plugin_list[$filename]) || (
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   513
        isset($plugin_list[$filename]) && !$plugin_list[$filename]['installed']
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   514
      ))
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   515
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   516
      $return = array(
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   517
        'mode' => 'error',
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   518
        'error' => 'Invalid plugin specified.',
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   519
      );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   520
      break;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   521
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   522
    // get plugin id
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   523
    $dataset =& $plugin_list[$filename];
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   524
    if ( empty($dataset['plugin id']) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   525
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   526
      $return = array(
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   527
        'mode' => 'error',
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   528
        'error' => 'Couldn\'t retrieve plugin ID.',
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   529
      );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   530
      break;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   531
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   532
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   533
    // load up the installer schema
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   534
    $schema = $this->parse_plugin_blocks( ENANO_ROOT . '/plugins/' . $filename, 'uninstall' );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   535
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   536
    $sql = array();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   537
    if ( !empty($schema) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   538
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   539
      // parse SQL
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   540
      $parser = new SQL_Parser($schema[0]['value'], true);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   541
      $parser->assign_vars(array(
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   542
        'TABLE_PREFIX' => table_prefix
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   543
        ));
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   544
      $sql = $parser->parse();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   545
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   546
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   547
    // schema is final, check queries
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   548
    foreach ( $sql as $query )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   549
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   550
      if ( !$db->check_query($query) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   551
      {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   552
        // aww crap, a query is bad
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   553
        $return = array(
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   554
          'mode' => 'error',
528
43535769970b Fixed some bad language string references in plugin management API
Dan
parents: 527
diff changeset
   555
          'error' => $lang->get('acppl_err_upgrade_bad_query'),
527
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   556
        );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   557
        break 2;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   558
      }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   559
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   560
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   561
    // this is it, perform uninstallation
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   562
    foreach ( $sql as $query )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   563
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   564
      if ( substr($query, 0, 1) == '@' )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   565
      {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   566
        $query = substr($query, 1);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   567
        $db->sql_query($query);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   568
      }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   569
      else
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   570
      {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   571
        if ( !$db->sql_query($query) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   572
          $db->die_json();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   573
      }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   574
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   575
    
529
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   576
    // log action
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   577
    $time        = time();
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   578
    $ip_db       = $db->escape($_SERVER['REMOTE_ADDR']);
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   579
    $username_db = $db->escape($session->username);
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   580
    $file_db     = $db->escape($filename);
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   581
    $q = $db->sql_query('INSERT INTO '.table_prefix."logs(log_type, action, time_id, edit_summary, author, page_text) VALUES\n"
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   582
                      . "  ('security', 'plugin_uninstall', $time, '$ip_db', '$username_db', '$file_db');");
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   583
    if ( !$q )
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   584
      $db->_die();
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   585
    
527
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   586
    // deregister plugin
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   587
    $q = $db->sql_query('DELETE FROM ' . table_prefix . "plugins WHERE plugin_id = {$dataset['plugin id']};");
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   588
    if ( !$q )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   589
      $db->die_json();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   590
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   591
    $return = array(
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   592
      'success' => true
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   593
    );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   594
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   595
    endswitch;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   596
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   597
    return $return;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   598
  }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   599
  
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   600
  /**
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   601
   * Very intelligently upgrades a plugin to the version specified in the filesystem.
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   602
   * @param string Filename of plugin.
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   603
   * @param array The list of plugins as output by pluginLoader::get_plugin_list(). If not passed, the function is called, possibly wasting time.
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   604
   * @return array JSON-formatted but not encoded response
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   605
   */
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   606
  
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   607
  function upgrade_plugin($filename, $plugin_list = null)
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   608
  {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   609
    global $db, $session, $paths, $template, $plugins; // Common objects
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   610
    global $lang;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   611
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   612
    if ( !$plugin_list )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   613
      $plugin_list = $this->get_plugin_list();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   614
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   615
    // we're gonna need this
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   616
    require_once ( ENANO_ROOT . '/includes/sql_parse.php' );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   617
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   618
    switch ( true ): case true:
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   619
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   620
    // is the plugin in the directory and already installed?
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   621
    if ( !isset($plugin_list[$filename]) || (
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   622
        isset($plugin_list[$filename]) && !$plugin_list[$filename]['installed']
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   623
      ))
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   624
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   625
      $return = array(
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   626
        'mode' => 'error',
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   627
        'error' => 'Invalid plugin specified.',
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   628
      );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   629
      break;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   630
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   631
    // get plugin id
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   632
    $dataset =& $plugin_list[$filename];
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   633
    if ( empty($dataset['plugin id']) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   634
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   635
      $return = array(
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   636
        'mode' => 'error',
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   637
        'error' => 'Couldn\'t retrieve plugin ID.',
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   638
      );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   639
      break;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   640
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   641
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   642
    //
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   643
    // Here we go with the main upgrade process. This is the same logic that the
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   644
    // Enano official upgrader uses, in fact it's the same SQL parser. We need
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   645
    // list of all versions of the plugin to continue, though.
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   646
    //
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   647
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   648
    if ( !isset($dataset['version list']) || ( isset($dataset['version list']) && !is_array($dataset['version list']) ) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   649
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   650
      // no version list - update the version number but leave the rest alone
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   651
      $version = $db->escape($dataset['version']);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   652
      $q = $db->sql_query('UPDATE ' . table_prefix . "plugins SET plugin_version = '$version' WHERE plugin_id = {$dataset['plugin id']};");
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   653
      if ( !$q )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   654
        $db->die_json();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   655
      
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   656
      // send an error and notify the user even though it was technically a success
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   657
      $return = array(
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   658
        'mode' => 'error',
528
43535769970b Fixed some bad language string references in plugin management API
Dan
parents: 527
diff changeset
   659
        'error' => $lang->get('acppl_err_upgrade_not_supported'),
527
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   660
      );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   661
      break;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   662
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   663
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   664
    // build target list
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   665
    $versions  = $dataset['version list'];
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   666
    $indices   = array_flip($versions);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   667
    $installed = $dataset['version installed'];
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   668
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   669
    // is the current version upgradeable?
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   670
    if ( !isset($indices[$installed]) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   671
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   672
      $return = array(
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   673
        'mode' => 'error',
528
43535769970b Fixed some bad language string references in plugin management API
Dan
parents: 527
diff changeset
   674
        'error' => $lang->get('acppl_err_upgrade_bad_version'),
527
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   675
      );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   676
      break;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   677
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   678
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   679
    // does the plugin support upgrading to its own version?
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   680
    if ( !isset($indices[$installed]) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   681
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   682
      $return = array(
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   683
        'mode' => 'error',
528
43535769970b Fixed some bad language string references in plugin management API
Dan
parents: 527
diff changeset
   684
        'error' => $lang->get('acppl_err_upgrade_bad_target_version'),
527
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   685
      );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   686
      break;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   687
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   688
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   689
    // list out which versions to do
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   690
    $index_start = @$indices[$installed] + 1;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   691
    $index_stop  = @$indices[$dataset['version']];
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   692
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   693
    // Are we trying to go backwards?
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   694
    if ( $index_stop <= $index_start )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   695
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   696
      $return = array(
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   697
        'mode' => 'error',
528
43535769970b Fixed some bad language string references in plugin management API
Dan
parents: 527
diff changeset
   698
        'error' => $lang->get('acppl_err_upgrade_to_older'),
527
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   699
      );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   700
      break;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   701
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   702
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   703
    // build the list of version sets
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   704
    $ver_previous = $installed;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   705
    $targets = array();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   706
    for ( $i = $index_start; $i <= $index_stop; $i++ )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   707
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   708
      $targets[] = array($ver_previous, $versions[$i]);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   709
      $ver_previous = $versions[$i];
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   710
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   711
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   712
    // parse out upgrade sections in plugin file
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   713
    $plugin_blocks = $this->parse_plugin_blocks( ENANO_ROOT . '/plugins/' . $filename, 'upgrade' );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   714
    $sql_blocks = array();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   715
    foreach ( $plugin_blocks as $block )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   716
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   717
      if ( !isset($block['from']) || !isset($block['to']) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   718
      {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   719
        continue;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   720
      }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   721
      $key = "{$block['from']} TO {$block['to']}";
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   722
      $sql_blocks[$key] = $block['value'];
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   723
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   724
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   725
    // do version list check
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   726
    // for now we won't fret if a specific version set isn't found, we'll just
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   727
    // not do that version and assume there were no DB changes.
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   728
    foreach ( $targets as $i => $target )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   729
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   730
      list($from, $to) = $target;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   731
      $key = "$from TO $to";
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   732
      if ( !isset($sql_blocks[$key]) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   733
      {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   734
        unset($targets[$i]);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   735
      }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   736
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   737
    $targets = array_values($targets);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   738
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   739
    // parse and finalize schema
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   740
    $schema = array();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   741
    foreach ( $targets as $i => $target )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   742
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   743
      list($from, $to) = $target;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   744
      $key = "$from TO $to";
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   745
      try
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   746
      {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   747
        $parser = new SQL_Parser($sql_blocks[$key], true);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   748
      }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   749
      catch ( Exception $e )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   750
      {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   751
        $return = array(
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   752
          'mode' => 'error',
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   753
          'error' => 'SQL parser init exception',
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   754
          'debug' => "$e"
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   755
        );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   756
        break 2;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   757
      }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   758
      $parser->assign_vars(array(
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   759
        'TABLE_PREFIX' => table_prefix
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   760
        ));
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   761
      $parsed = $parser->parse();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   762
      foreach ( $parsed as $query )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   763
      {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   764
        $schema[] = $query;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   765
      }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   766
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   767
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   768
    // schema is final, check queries
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   769
    foreach ( $schema as $query )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   770
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   771
      if ( !$db->check_query($query) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   772
      {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   773
        // aww crap, a query is bad
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   774
        $return = array(
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   775
          'mode' => 'error',
528
43535769970b Fixed some bad language string references in plugin management API
Dan
parents: 527
diff changeset
   776
          'error' => $lang->get('acppl_err_upgrade_bad_query'),
527
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   777
        );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   778
        break 2;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   779
      }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   780
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   781
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   782
    // this is it, perform upgrade
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   783
    foreach ( $schema as $query )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   784
    {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   785
      if ( substr($query, 0, 1) == '@' )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   786
      {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   787
        $query = substr($query, 1);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   788
        $db->sql_query($query);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   789
      }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   790
      else
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   791
      {
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   792
        if ( !$db->sql_query($query) )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   793
          $db->die_json();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   794
      }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   795
    }
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   796
    
529
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   797
    // log action
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   798
    $time        = time();
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   799
    $ip_db       = $db->escape($_SERVER['REMOTE_ADDR']);
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   800
    $username_db = $db->escape($session->username);
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   801
    $file_db     = $db->escape($filename);
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   802
    $q = $db->sql_query('INSERT INTO '.table_prefix."logs(log_type, action, time_id, edit_summary, author, page_text) VALUES\n"
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   803
                      . "  ('security', 'plugin_upgrade', $time, '$ip_db', '$username_db', '$file_db');");
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   804
    if ( !$q )
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   805
      $db->_die();
7803c9db3506 Implemented security logging for plugin management
Dan
parents: 528
diff changeset
   806
    
527
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   807
    // update version number
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   808
    $version = $db->escape($dataset['version']);
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   809
    $q = $db->sql_query('UPDATE ' . table_prefix . "plugins SET plugin_version = '$version' WHERE plugin_id = {$dataset['plugin id']};");
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   810
    if ( !$q )
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   811
      $db->die_json();
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   812
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   813
    // all done :-)
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   814
    $return = array(
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   815
      'success' => true
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   816
    );
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   817
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   818
    endswitch;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   819
    
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   820
    return $return;
21e11f564463 (Hopefully) finished new plugin manager and implemented the utilization of it. Still HIGHLY experimental.
Dan
parents: 519
diff changeset
   821
  }
555
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   822
  
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   823
  /**
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   824
   * Re-imports the language strings from a plugin.
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   825
   * @param string File name
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   826
   * @return array Enano JSON response protocol
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   827
   */
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   828
  
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   829
  function reimport_plugin_strings($filename, $plugin_list = null)
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   830
  {
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   831
    global $db, $session, $paths, $template, $plugins; // Common objects
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   832
    global $lang;
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   833
    
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   834
    if ( !$plugin_list )
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   835
      $plugin_list = $this->get_plugin_list();
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   836
    
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   837
    switch ( true ): case true:
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   838
    
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   839
    // is the plugin in the directory and already installed?
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   840
    if ( !isset($plugin_list[$filename]) || (
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   841
        isset($plugin_list[$filename]) && !$plugin_list[$filename]['installed']
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   842
      ))
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   843
    {
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   844
      $return = array(
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   845
        'mode' => 'error',
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   846
        'error' => 'Invalid plugin specified.',
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   847
      );
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   848
      break;
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   849
    }
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   850
    // get plugin data
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   851
    $dataset =& $plugin_list[$filename];
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   852
    
560
8981dcf7d485 Added re-import function to plugin manager
Dan
parents: 555
diff changeset
   853
    // check for a language block
8981dcf7d485 Added re-import function to plugin manager
Dan
parents: 555
diff changeset
   854
    $blocks = self::parse_plugin_blocks(ENANO_ROOT . '/plugins/' . $filename, 'language');
8981dcf7d485 Added re-import function to plugin manager
Dan
parents: 555
diff changeset
   855
    if ( count($blocks) < 1 )
8981dcf7d485 Added re-import function to plugin manager
Dan
parents: 555
diff changeset
   856
    {
8981dcf7d485 Added re-import function to plugin manager
Dan
parents: 555
diff changeset
   857
      return array(
8981dcf7d485 Added re-import function to plugin manager
Dan
parents: 555
diff changeset
   858
          'mode' => 'error',
8981dcf7d485 Added re-import function to plugin manager
Dan
parents: 555
diff changeset
   859
          'error' => $lang->get('acppl_err_import_no_strings')
8981dcf7d485 Added re-import function to plugin manager
Dan
parents: 555
diff changeset
   860
        );
8981dcf7d485 Added re-import function to plugin manager
Dan
parents: 555
diff changeset
   861
    }
8981dcf7d485 Added re-import function to plugin manager
Dan
parents: 555
diff changeset
   862
    
555
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   863
    $result = $lang->import_plugin(ENANO_ROOT . '/plugins/' . $filename);
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   864
    if ( $result )
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   865
    {
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   866
      return array(
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   867
        'success' => true
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   868
      );
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   869
    }
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   870
    else
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   871
    {
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   872
      return array(
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   873
        'mode' => 'error',
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   874
        'error' => 'Language API returned error'
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   875
      );
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   876
    }
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   877
    
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   878
    endswitch;
ac4c6a7f01d8 Added user preference for disabling visual effects in Javascript applets; added re-import button to installed plugins
Dan
parents: 536
diff changeset
   879
  }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   880
}
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   881
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   882
?>