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
Line 
1<?php 
2/*
3Version: 1.0.3
4Plugin Name: set_plugins
5Plugin URI: http://piwigo.org/ext/extension_view.php?eid=550
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.
17
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
31add_event_handler('loc_end_page_header','set_plugins_add'); 
32function set_plugins_add() {
33  global $user, $template, $val,$page,$conf;
34  if (!isset($page['body_id'])) return;
35
36  switch($page['body_id']){
37          case  'theAdminPage':     
38      switch($page['page']){
39                    case 'plugins_list':                     
40            if(!isset($template)) return ;     
41             Affiche_set_plugins();
42//============================================================
43                break;
44
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 
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   
80    if($val_state!=""){ 
81    if($val_state=="activate")
82        $sens ="DESC";
83    else
84        $sens="ASC";
85
86    //==== pré-liste ===
87      $query = 'SELECT *
88                FROM ' . PLUGINS_TABLE . '
89           WHERE `state` NOT LIKE "'.$val_state. '" AND id!="' . "set_plugins" . '"
90            ORDER BY `id` '.$sens.'
91           LIMIT '.$nb.'
92      ';
93          $result = pwg_query($query);
94   
95
96 
97      $query = '
98      UPDATE '.PLUGINS_TABLE.'
99      SET state="'.$val_state.'"
100      WHERE `state` NOT LIKE "'.$val_state. '" AND id!="' . "set_plugins" . '"
101      ORDER BY `id`  '.$sens.'
102       LIMIT '.$nb.'
103      ;';
104
105       pwg_query($query);
106 
107    $data = array();
108    if($result)
109    while ($row = pwg_db_fetch_assoc($result))
110    {
111 
112     $url =  $row['id'] ;$vers= $row['version'];
113      array_push($data, array('plugin' => $url,'version'=>$vers) );
114    }
115     
116      unset ($_POST); 
117        $redirect_url = get_root_url().'admin.php?page='.$_GET['page'];
118         $config=array();
119             $config = array(
120                          'state' => $val_state,
121                          'list'=>$data,
122                          'nb' =>$nb
123                      );
124
125        conf_update_param('set_plugins', pwg_db_real_escape_string(serialize($config)));
126        redirect($redirect_url);
127    }
128}
129 
130
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
140 
141 //===========================================================
142              $bpplus=$template->parse('cl_plugin', true);
143              $template-> assign('ADMIN_CONTENT',$bpplus); 
144             
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.