source: trunk/admin/include/functions_plugins.inc.php @ 1580

Last change on this file since 1580 was 1580, checked in by rvelices, 18 years ago
  • plugins can add now their page to the admin page
  • new plugin (event_tracer) that demonstrate it and useful to see all calls

to trigger_event

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
5// +-----------------------------------------------------------------------+
6// | branch        : BSF (Best So Far)
7// | file          : $Id: functions_plugins.inc.php 1580 2006-10-27 00:25:02Z rvelices $
8// | last update   : $Date: 2006-10-27 00:25:02 +0000 (Fri, 27 Oct 2006) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 1580 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27function get_plugins()
28{
29  $plugins = array();
30
31  $dir = opendir(PHPWG_PLUGINS_PATH);
32  while ($file = readdir($dir))
33  {
34    if ($file!='.' and $file!='..')
35    {
36      $path = PHPWG_PLUGINS_PATH.$file;
37      if (is_dir($path) and !is_link($path)
38          and preg_match('/^[a-zA-Z0-9-_]+$/', $file )
39          and file_exists($path.'/index.php')
40          )
41      {
42        $plugin = array('name'=>'?', 'version'=>'?', 'uri'=>'', 'description'=>'');
43        $plg_data = implode( '', file($path.'/index.php') );
44
45        if ( preg_match("|Plugin Name: (.*)|i", $plg_data, $val) )
46        {
47          $plugin['name'] = trim( $val[1] );
48        }
49        if (preg_match("|Version: (.*)|i", $plg_data, $val))
50        {
51          $plugin['version'] = trim($val[1]);
52        }
53        if ( preg_match("|Plugin URI: (.*)|i", $plg_data, $val) )
54        {
55          $plugin['uri'] = $val[1];
56        }
57        if ( preg_match("|Description: (.*)|i", $plg_data, $val) )
58        {
59          $plugin['description'] = trim($val[1]);
60        }
61        $plugins[$file] = $plugin;
62      }
63    }
64  }
65  closedir($dir);
66  return $plugins;
67}
68
69function activate_plugin($plugin_name)
70{
71  global $conf;
72  $arr = get_active_plugins(false);
73  array_push($arr, $plugin_name);
74  if ($arr != array_unique($arr) )
75    return false; // just added the same one
76  $conf['active_plugins'] = implode(',', $arr);
77  pwg_query('
78UPDATE '.CONFIG_TABLE.'
79  SET value="'.$conf['active_plugins'].'"
80  WHERE param="active_plugins"');
81  return true;
82}
83
84function deactivate_plugin($plugin_name)
85{
86  global $conf;
87  $arr = get_active_plugins(false);
88  $idx = array_search($plugin_name, $arr);
89  if ($idx!==false)
90  {
91    unset( $arr[$idx] );
92    $conf['active_plugins'] = implode(',', $arr);
93    pwg_query('
94UPDATE '.CONFIG_TABLE.'
95  SET value="'.$conf['active_plugins'].'"
96  WHERE param="active_plugins"');
97    return true;
98  }
99  return false;
100}
101
102/*allows plugins to add their content to the administration page*/
103function add_plugin_admin_menu($title, $func)
104{
105  global $page;
106
107  $uid = md5( var_export($func, true) );
108  $page['plugin_admin_menu'][] =
109    array(
110      'title' => $title,
111      'function' => $func,
112      'uid' => $uid
113    );
114}
115
116?>
Note: See TracBrowser for help on using the repository browser.