source: tags/release-1_7_3/admin/include/functions_plugins.inc.php @ 29511

Last change on this file since 29511 was 2137, checked in by rvelices, 17 years ago
  • fix plugin menu link broken with xamp (realpath behaves differently) (merge from trunk to branch 1_7)
  • added some meta_robots (noindex and nofollow) on popuphelp, search_rules and search seaction (googlebot gets crazy)
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
5// +-----------------------------------------------------------------------+
6// | file          : $Id: functions_plugins.inc.php 2137 2007-10-16 01:45:26Z rvelices $
7// | last update   : $Date: 2007-10-16 01:45:26 +0000 (Tue, 16 Oct 2007) $
8// | last modifier : $Author: rvelices $
9// | revision      : $Revision: 2137 $
10// +-----------------------------------------------------------------------+
11// | This program is free software; you can redistribute it and/or modify  |
12// | it under the terms of the GNU General Public License as published by  |
13// | the Free Software Foundation                                          |
14// |                                                                       |
15// | This program is distributed in the hope that it will be useful, but   |
16// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
17// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
18// | General Public License for more details.                              |
19// |                                                                       |
20// | You should have received a copy of the GNU General Public License     |
21// | along with this program; if not, write to the Free Software           |
22// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
23// | USA.                                                                  |
24// +-----------------------------------------------------------------------+
25
26/* Returns an array of plugins defined in the plugin directory
27*/
28function get_fs_plugins()
29{
30  $plugins = array();
31
32  $dir = opendir(PHPWG_PLUGINS_PATH);
33  while ($file = readdir($dir))
34  {
35    if ($file!='.' and $file!='..')
36    {
37      $path = PHPWG_PLUGINS_PATH.$file;
38      if (is_dir($path) and !is_link($path)
39          and preg_match('/^[a-zA-Z0-9-_]+$/', $file )
40          and file_exists($path.'/main.inc.php')
41          )
42      {
43        $plugin = array(
44            'name'=>$file,
45            'version'=>'0',
46            'uri'=>'',
47            'description'=>'',
48            'author'=>'',
49          );
50        $plg_data = implode( '', file($path.'/main.inc.php') );
51
52        if ( preg_match("|Plugin Name: (.*)|", $plg_data, $val) )
53        {
54          $plugin['name'] = trim( $val[1] );
55        }
56        if (preg_match("|Version: (.*)|", $plg_data, $val))
57        {
58          $plugin['version'] = trim($val[1]);
59        }
60        if ( preg_match("|Plugin URI: (.*)|", $plg_data, $val) )
61        {
62          $plugin['uri'] = trim($val[1]);
63        }
64        if ( preg_match("|Description: (.*)|", $plg_data, $val) )
65        {
66          $plugin['description'] = trim($val[1]);
67        }
68        if ( preg_match("|Author: (.*)|", $plg_data, $val) )
69        {
70          $plugin['author'] = trim($val[1]);
71        }
72        if ( preg_match("|Author URI: (.*)|", $plg_data, $val) )
73        {
74          $plugin['author uri'] = trim($val[1]);
75        }
76        // IMPORTANT SECURITY !
77        $plugin = array_map('htmlspecialchars', $plugin);
78        $plugins[$file] = $plugin;
79      }
80    }
81  }
82  closedir($dir);
83  return $plugins;
84}
85
86/**
87 * Retrieves an url for a plugin page.
88 * @param string file - php script full name
89 */
90function get_admin_plugin_menu_link($file)
91{
92  global $page;
93  $real_file = realpath($file);
94  $url = get_root_url().'admin.php?page=plugin';
95  if (false!==$real_file)
96  {
97    $real_plugin_path = rtrim(realpath(PHPWG_PLUGINS_PATH), '\\/');
98    $file = substr($real_file, strlen($real_plugin_path)+1);
99    $file = str_replace('\\', '/', $file);//Windows
100    $url .= '&amp;section='.urlencode($file);
101  }
102  else if (isset($page['errors']))
103  {
104    array_push($page['errors'], 'PLUGIN ERROR: "'.$file.'" is not a valid file');
105  }
106  return $url;
107}
108
109?>
Note: See TracBrowser for help on using the repository browser.