includes/plugins.php
author Dan
Tue, 08 Apr 2008 20:31:58 -0400
changeset 524 26287ae2449d
parent 519 94214ec0871c
child 527 21e11f564463
permissions -rw-r--r--
Pretty much pseudo-commit to make Hg let me merge some stuff in, only change was the "system plugin" key in $plugin_meta in PluginManager
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
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
     5
 * Version 1.1.3 (Caoineag alpha 3)
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
     6
 * Copyright (C) 2006-2007 Dan Fuhry
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
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    66
    $dir = ENANO_ROOT.'/plugins/';
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    67
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    68
    $this->load_list = Array();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    69
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    70
    $plugins = Array();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    71
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    72
    // Open a known directory, and proceed to read its contents
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    73
    
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    74
    if (is_dir($dir))
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    75
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    76
      if ($dh = opendir($dir))
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    77
      {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    78
        while (($file = readdir($dh)) !== false)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    79
        {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    80
          if(preg_match('#^(.*?)\.php$#is', $file))
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    81
          {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    82
            if(getConfig('plugin_'.$file) == '1' || in_array($file, $this->system_plugins))
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    83
            {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    84
              $this->load_list[] = $dir . $file;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    85
              $plugid = substr($file, 0, strlen($file)-4);
378
c1c7fa6b329f Got Enano to load even if there are no plugins; added caching for decrypted session keys to significantly improve performance (in theory at least)
Dan
parents: 322
diff changeset
    86
              $f = @file_get_contents($dir . $file);
c1c7fa6b329f Got Enano to load even if there are no plugins; added caching for decrypted session keys to significantly improve performance (in theory at least)
Dan
parents: 322
diff changeset
    87
              if ( empty($f) )
c1c7fa6b329f Got Enano to load even if there are no plugins; added caching for decrypted session keys to significantly improve performance (in theory at least)
Dan
parents: 322
diff changeset
    88
                continue;
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    89
              $f = explode("\n", $f);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    90
              $f = array_slice($f, 2, 7);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    91
              $f[0] = substr($f[0], 13);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    92
              $f[1] = substr($f[1], 12);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    93
              $f[2] = substr($f[2], 13);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    94
              $f[3] = substr($f[3], 8 );
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    95
              $f[4] = substr($f[4], 9 );
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    96
              $f[5] = substr($f[5], 12);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    97
              $plugins[$plugid] = Array();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    98
              $plugins[$plugid]['name'] = $f[0];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
    99
              $plugins[$plugid]['uri']  = $f[1];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   100
              $plugins[$plugid]['desc'] = $f[2];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   101
              $plugins[$plugid]['auth'] = $f[3];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   102
              $plugins[$plugid]['vers'] = $f[4];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   103
              $plugins[$plugid]['aweb'] = $f[5];
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   104
            }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   105
          }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   106
        }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   107
        closedir($dh);
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   108
      }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   109
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   110
    $this->loaded_plugins = $plugins;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   111
    //die('<pre>'.htmlspecialchars(print_r($plugins, true)).'</pre>');
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   112
  }
464
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   113
  
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
   * 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
   116
   * 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
   117
   * values should be eval'ed.
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   118
   * @example <code>
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   119
   $code = $plugins->setHook('my_hook_name');
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   120
   foreach ( $code as $cmd )
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   121
   {
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   122
     eval($cmd);
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   123
   }
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   124
   </code>
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   125
   * @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
   126
   * @param array Deprecated.
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   127
   */
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   128
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   129
  function setHook($name, $opts = Array()) {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   130
    if(isset($this->hook_list[$name]) && is_array($this->hook_list[$name]))
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   131
    {
379
82b991bee797 Minor and hopefully non-breaking change to plugin loader to possibly double performance at hook points
Dan
parents: 378
diff changeset
   132
      return array(implode("\n", $this->hook_list[$name]));
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   133
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   134
    else
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   135
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   136
      return Array();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   137
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   138
  }
464
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
  /**
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   141
   * 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
   142
   * 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
   143
   * @example Simple example: <code>
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   144
   $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
   145
   </code>
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   146
   * @example More complicated example: <code>
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   147
   $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
   148
   
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   149
   // 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
   150
   function myplugin_parser_ext(&$text)
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   151
   {
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   152
     $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
   153
   }
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   154
   </code>
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
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   157
  function attachHook($name, $code) {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   158
    if(!isset($this->hook_list[$name]))
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   159
    {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   160
      $this->hook_list[$name] = Array();
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   161
    }
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   162
    $this->hook_list[$name][] = $code;
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   163
  }
464
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   164
  
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   165
  /**
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   166
   * 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
   167
   * @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
   168
   * @return bool
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   169
   */
8063eace5b67 Documented includes/plugins.php to try and help plugin developers a little.
Dan
parents: 411
diff changeset
   170
  
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   171
  function loaded($plugid)
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   172
  {
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   173
    return isset( $this->loaded_plugins[$plugid] );
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   174
  }
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
   175
  
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
  /**
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
   * 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
   178
   <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
   179
   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
   180
       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
   181
           '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
   182
           // 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
   183
             '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
   184
             '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
   185
           '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
   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
       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
   188
           ...
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
     );
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
   </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
   192
   * @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
   193
   * @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
   194
   * @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
   195
   */
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
  
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
  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
   198
  {
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
    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
   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
      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
   202
    }
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
    $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
   204
    $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
   205
    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
   206
    {
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
      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
   208
    }
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
    
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
    $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
   211
            . '(([\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
   212
            . '[\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
   213
            . '([\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
   214
            . '\*\*!\*/'              // 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
   215
            . '#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
   216
            
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
   217
    // 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
   218
    
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
   219
    $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
   220
    
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
   221
    $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
   222
    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
   223
    {
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
   224
      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
   225
        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
   226
      
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
   227
      $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
   228
      // 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
   229
      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
   230
      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
   231
      {
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
        $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
   233
        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
   234
        {
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
   235
          $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
   236
          $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
   237
        }
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
   238
      }
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
   239
      
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
   240
      $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
   241
      $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
   242
      $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
   243
      $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
   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
    
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
    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
   247
  }
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
  
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
   249
  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
   250
  {
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
   251
    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
   252
    $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
   253
    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
   254
    {
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
   255
      $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
   256
    }
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
   257
    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
   258
  }
1
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   259
}
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   260
fe660c52c48f Adding /includes
dan@scribus.fuhry.local.fuhry.local
parents:
diff changeset
   261
?>