includes/plugins.php
author Dan
Tue, 12 Feb 2008 22:17:58 -0500
changeset 419 b8b4e38825db
parent 411 d1a95497b68f
child 464 8063eace5b67
permissions -rw-r--r--
Unsuccessful attempt at fixing "dismiss"/"close manager" buttons in ACL editor; non-breaking change to template API to allow plugins to add "normal" sidebar widgets in addition to the special "raw" block type, specified as the third parameter to $template->sidebar_widget(). Defaults to false, which is old behavior; new behavior (enabled by passing TRUE as the 3rd param) means that the content of the block is primarily block-level links.

<?php

/*
 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
 * Version 1.1.2 (Caoineag alpha 2)
 * Copyright (C) 2006-2007 Dan Fuhry
 *
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
 */
 
class pluginLoader {
  var $hook_list;
  var $load_list;
  var $loaded_plugins;
  var $system_plugins = Array('SpecialUserFuncs.php','SpecialUserPrefs.php','SpecialPageFuncs.php','SpecialAdmin.php','SpecialCSS.php','SpecialUpdownload.php','SpecialSearch.php','PrivateMessages.php','SpecialGroups.php', 'SpecialRecentChanges.php');
  function loadAll() 
  {
    $dir = ENANO_ROOT.'/plugins/';
    
    $this->load_list = Array();
    
    $plugins = Array();
    
    // Open a known directory, and proceed to read its contents
    
    if (is_dir($dir))
    {
      if ($dh = opendir($dir))
      {
        while (($file = readdir($dh)) !== false)
        {
          if(preg_match('#^(.*?)\.php$#is', $file))
          {
            if(getConfig('plugin_'.$file) == '1' || in_array($file, $this->system_plugins))
            {
              $this->load_list[] = $dir . $file;
              $plugid = substr($file, 0, strlen($file)-4);
              $f = @file_get_contents($dir . $file);
              if ( empty($f) )
                continue;
              $f = explode("\n", $f);
              $f = array_slice($f, 2, 7);
              $f[0] = substr($f[0], 13);
              $f[1] = substr($f[1], 12);
              $f[2] = substr($f[2], 13);
              $f[3] = substr($f[3], 8 );
              $f[4] = substr($f[4], 9 );
              $f[5] = substr($f[5], 12);
              $plugins[$plugid] = Array();
              $plugins[$plugid]['name'] = $f[0];
              $plugins[$plugid]['uri']  = $f[1];
              $plugins[$plugid]['desc'] = $f[2];
              $plugins[$plugid]['auth'] = $f[3];
              $plugins[$plugid]['vers'] = $f[4];
              $plugins[$plugid]['aweb'] = $f[5];
            }
          }
        }
        closedir($dh);
      }
    }
    $this->loaded_plugins = $plugins;
    //die('<pre>'.htmlspecialchars(print_r($plugins, true)).'</pre>');
  }
  function setHook($name, $opts = Array()) {
    /*
    $r = Array();
    if(isset($this->hook_list[$name])) {
      for($i=0;$i<sizeof($this->hook_list[$name]);$i++) {
        $ret = eval($this->hook_list[$name][$i]);
        if($ret !== null) $r[] = $ret;
      }
    }
    if(sizeof($r) > 0) return $r;
    else return false;
    */
    if(isset($this->hook_list[$name]) && is_array($this->hook_list[$name]))
    {
      return array(implode("\n", $this->hook_list[$name]));
    }
    else
    {
      return Array();
    }
  }
  function attachHook($name, $code) {
    if(!isset($this->hook_list[$name]))
    {
      $this->hook_list[$name] = Array();
    }
    $this->hook_list[$name][] = $code;
  }
  function loaded($plugid)
  {
    return isset( $this->loaded_plugins[$plugid] );
  }
}

?>