source: extensions/set_plugins/main.inc.php @ 11100

Last change on this file since 11100 was 11100, checked in by cljosse, 13 years ago

[extensions] set_plugins add listing of last set/unset plugins

File size: 4.0 KB
RevLine 
[11072]1<?php 
2/*
[11100]3Version: 1.0.3
[11073]4Plugin Name: set_plugins
5Plugin URI: http://piwigo.org/ext/extension_view.php?eid=550
[11072]6Author: cljosse
7Description: Active/déactive tous les plugins installés.
8*/
9
10// Chech whether we are indeed included by Piwigo.
11if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
12
13// Define the path to our plugin.
14define('SET_PLUGINS_PATH', PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/');
15load_language('plugin.lang', SET_PLUGINS_PATH);
16// Hook on to an event to show the administration page.
[11093]17
[11072]18add_event_handler('get_admin_plugin_menu_links', 'set_plugins_admin_menu');
19// Add an entry to the 'Plugins' menu.
20function set_plugins_admin_menu($menu) {
21  array_push(
22    $menu,
23    array(
24      'NAME'  => 'Set_plugins',
25      'URL'   => get_admin_plugin_menu_link(dirname(__FILE__)).'/admin.php'
26    )
27  );
28  return $menu;
29}
30
[11093]31add_event_handler('loc_end_page_header','set_plugins_add'); 
[11072]32function set_plugins_add() {
[11093]33  global $user, $template, $val,$page,$conf;
[11072]34  if (!isset($page['body_id'])) return;
35
36  switch($page['body_id']){
[11093]37          case  'theAdminPage':     
[11072]38      switch($page['page']){
[11093]39                    case 'plugins_list':                     
40            if(!isset($template)) return ;     
41             Affiche_set_plugins();
42//============================================================
43                break;
[11072]44
[11093]45 case 'plugin': 
46
47
48        break;
49
50                                //==============================================================================
51                                } 
52                 
53                break;
54
55
56}
57
58       
59return false;
60 }
61
62 
63function Affiche_set_plugins(){
64  global $user, $template, $val,$page,$conf;
65    include_once(SET_PLUGINS_PATH."include/constants.php");       
66    include_once(SET_PLUGINS_PATH.'include/affiche.php');
67    $all_tpl_vars = $template->get_template_vars('plugins');
68 
69    if(!$all_tpl_vars)  return;     
70 
[11072]71$val_state="";
72
73if(  isset($_POST['unset_plugins']) || isset($_POST['set_plugins'])  ){
74 if(isset($_POST['unset_plugins'])  ) 
75                    $val_state='inactive';
76      elseif(isset($_POST['set_plugins'])  ) 
77        $val_state='active';
78      $nb=isset($_POST['nb'])?$_POST['nb']:$nb ;
79   
[11074]80    if($val_state!=""){ 
[11093]81    if($val_state=="activate")
82        $sens ="DESC";
83    else
84        $sens="ASC";
85
86    //==== pré-liste ===
[11074]87      $query = 'SELECT *
88                FROM ' . PLUGINS_TABLE . '
89           WHERE `state` NOT LIKE "'.$val_state. '" AND id!="' . "set_plugins" . '"
[11093]90            ORDER BY `id` '.$sens.'
[11074]91           LIMIT '.$nb.'
92      ';
93          $result = pwg_query($query);
[11093]94   
95
96 
[11072]97      $query = '
98      UPDATE '.PLUGINS_TABLE.'
99      SET state="'.$val_state.'"
100      WHERE `state` NOT LIKE "'.$val_state. '" AND id!="' . "set_plugins" . '"
[11093]101      ORDER BY `id`  '.$sens.'
102       LIMIT '.$nb.'
[11072]103      ;';
[11074]104
105       pwg_query($query);
[11093]106 
[11074]107    $data = array();
108    if($result)
109    while ($row = pwg_db_fetch_assoc($result))
110    {
[11093]111 
112     $url =  $row['id'] ;$vers= $row['version'];
[11074]113      array_push($data, array('plugin' => $url,'version'=>$vers) );
114    }
[11093]115     
[11072]116      unset ($_POST); 
117        $redirect_url = get_root_url().'admin.php?page='.$_GET['page'];
118         $config=array();
119             $config = array(
[11074]120                          'state' => $val_state,
121                          'list'=>$data,
[11072]122                          'nb' =>$nb
123                      );
124
[11093]125        conf_update_param('set_plugins', pwg_db_real_escape_string(serialize($config)));
[11072]126        redirect($redirect_url);
127    }
128}
[11093]129 
130
[11072]131               $template->set_filenames(
132                array(
133                  'plugin' => dirname(__FILE__).'/admin.tpl'
134                )         
135              );
136              $template->set_filenames(
137              array(    'cl_plugin' => dirname(__FILE__).'/admin.tpl'  )         
138              );
139
[11093]140 
141 //===========================================================
[11072]142              $bpplus=$template->parse('cl_plugin', true);
143              $template-> assign('ADMIN_CONTENT',$bpplus); 
[11093]144             
[11072]145              $bpplus=$template->parse('plugins', true);
146              $template-> concat('ADMIN_CONTENT',$bpplus); 
147
148}
149?>
Note: See TracBrowser for help on using the repository browser.