Location: PHPKode > projects > Bloggie Lite > admin/plugin.php
<?

// Copyright (C) Bloggie Lite Written by : Sean
// http://www.mywebland.com , http://mybloggie.mywebland.com

// You are requested to retain this copyright notice in order to use
// this software.

//This program is free software; you can redistribute it 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 more details.

//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

if ( !defined('IN_BLOGGIE') ) {
    die("You are not allowed to access this page directly !");
}

if (!authenticate()) {
redirect($bloggie_path."/login.php");
}

function array_remove_value() {
    $args = func_get_args();
    $arr = $args[0];
    $values = array_slice($args,1);

    foreach($arr as $k=>$v) {
        if(in_array($v, $values))
            unset($arr[$k]);
     }
    return $arr;
}

function array_add_value() {
    $args = func_get_args();
    $arr = $args[0];
    $values = array_slice($args,1);

    foreach($values as $k=>$v) {
        if(!in_array($v, $arr))
        array_push($arr,$v);
    }
    return $arr;
}

if ( isset($_GET['action']) ) {
    if ('plug' == $_GET['action']) {
          $active_plugins = unserialize($pref_data["plugins"]);
        if (!in_array($_GET['plugin'], $active_plugins)) {
           $active_plugins = array_add_value($active_plugins, trim( $_GET['plugin']));
           sort($active_plugins);
           $sql = "UPDATE " .PREF_TBL." SET  setting = '".serialize($active_plugins)."' WHERE option_name = 'plugins'";
           if( !($result = $db->sql_query($sql)) ) {
               $sql_error = $db->sql_error();
               error($lang['Error'], 'SQL Query Error : '.$sql_error['message'].' !');
           }

        }
    } else if ('unplug' == $_GET['action']) {
        if (in_array($_GET['plugin'], $active_plugins)) {
           $active_plugins = array_remove_value($active_plugins, trim( $_GET['plugin']));
           sort($active_plugins);
           $sql = "UPDATE " .PREF_TBL." SET  setting = '".serialize($active_plugins)."' WHERE option_name = 'plugins'";
           if( !($result = $db->sql_query($sql)) ) {
               $sql_error = $db->sql_error();
               error($lang['Error'], 'SQL Query Error : '.$sql_error['message'].' !');
           }
        }
    }

}

// Debug code
/**   print_r ($active_plugins);
   while(list($key,$val) = each($active_plugins)) {
   echo "key = $key, val = $val<br />";      }  **/

$plugin_data = array('Plugin Name', 'Download URI', 'Plugin Description', 'Author', 'Homepage', 'Version');
 $plugins_dir = ABSDIR.'plugins/';

$handle=opendir($plugins_dir);

while ($file = readdir($handle)) {

   if(!is_dir($file) && !is_link($file) && !preg_match('|^\.+$|', $file)) {
       if (preg_match('|\.php$|', $file))
         $plugins[] = $file;
   }
}

?>
<br /><br />
<table bgcolor="#cccccc" border="0" cellspacing="1" width="100%">
  <tbody><tr>
      <td colspan="6" class="headerfont" bgcolor="#ffffff"><center><b><? echo $lang['Plugin_List'] ?></b></center></td>
  </tr>
  <tr class="subtitle">
     <td class="stdfont" align="left" bgcolor="#ffffff"><b><center><? echo $lang['Plugin'] ?></center></b></td>
     <td class="stdfont" align="left" bgcolor="#ffffff"><b><center><? echo $lang['Description'] ?></center></b></td>
     <td class="stdfont" align="left" bgcolor="#ffffff" width="60"><b><center><? echo $lang['Version'] ?></center></b></td>
     <td class="stdfont" align="left" bgcolor="#ffffff"><b><center><? echo $lang['Author'] ?></center></b></td>
     <td class="stdfont" align="left" bgcolor="#ffffff"><b><center><? echo $lang['Status'] ?></center></b></td>
     <td class="stdfont" align="left" bgcolor="#ffffff"><b><center><? echo $lang['Action'] ?></center></b></td>
   </tr>
<?
$n=0;


foreach ($plugins as $plugin) {
  if ( $n % 2 ) { $alt_clr =" class=\"whitebg\""; } else { $alt_clr = " class=\"greybg\""; }
            if (!@file_exists(@realpath($plugin)))
            {
                $plugin_file = $plugins_dir.$plugin;
                if (!@file_exists(@realpath($plugin_file)))
                {
                    error("Error", "Plugin file not found");
                }
            }
            if (!($fd = @fopen(@realpath($plugin_file), 'r')))
            {
                error("Error", 'Failed opening Plugin file ');
            }
            $plugin1 = fread($fd, filesize(realpath($plugin_file)));
            fclose($fd);
   $plugin_info = implode('', file($plugin_file));

   foreach ($plugin_data as $plugin_var) {

      $var = str_replace (" ", "_", strtolower($plugin_var));
      if ( preg_match("|".$plugin_var.":(.*)|i", $plugin_info, $data["$var"])) {
         $data["$var"]=$data["$var"][1];
      } else {
         $data["$var"]= "N/A";
      }
   }
//    print_r ( $active_plugins );
//
   //$active_plugins = unserialize($pref_data["plugins"]);
//   if ( $active_plugins ) {
       if ( is_array($active_plugins) && !empty($active_plugins) ) {
//       echo "issarray";
         foreach ($active_plugins as $active_plugin) {
//             echo $active_plugin ;               echo $plugin."<br />" ;
            if ( "" !=$active_plugin && $active_plugin == $plugin ) {
              $link_action = "<a href=".$_SERVER['PHP_SELF']."?mode=plugin&amp;action=unplug&amp;plugin=".$plugin.">".$lang['Unplug']."</a>";
              $status = $lang['Active'];
         //$checked = "";


              break;
           } else {
              $link_action = "<a href=".$_SERVER['PHP_SELF']."?mode=plugin&amp;action=plug&amp;plugin=".$plugin.">".$lang['Plug']."</a>";
              $status = $lang['Not_Active'];
//              break;
            }
         }
//      }
   } else {
      $link_action = "<a href=".$_SERVER['PHP_SELF']."?mode=plugin&amp;action=plug&amp;plugin=".$plugin.">".$lang['Plug']."</a>";
              $status = $lang['Not_Active'];
   }

//     echo $plugin;
?>
   <tr>
      <td <? echo $alt_clr ?>><center><? if ($data["download_uri"]!= "N/A") { ?><a href="<? echo $data["download_uri"] ?>"><? echo $data["plugin_name"] ?></a>
          <? } else  { echo ; } ?></center></td>
      <td <? echo $alt_clr ?>><? echo $data["plugin_description"] ?></td>
      <td <? echo $alt_clr ?>><center><? echo $data["version"] ?></center></td>
      <td <? echo $alt_clr ?>><center><? if ($data["author"] != "N/A" && $data["homepage"]!= "N/A") { ?><a href="<? echo $data["homepage"] ?>"><? echo $data["author"] ?></a>
          <? } elseif ($data["author"] == "N/A") { echo $data["author"]; } ?></center></td>
      <td <? echo $alt_clr ?>><center><? echo $status ?></center></td>
      <td <? echo $alt_clr ?>><center><? echo $link_action ?></center></td>
   </tr>
<?
$n++;
}

?>
   </tr>
</tbody>
</table>
<?



?>
Return current item: Bloggie Lite