source: extensions/event_cats/main.inc.php @ 4239

Last change on this file since 4239 was 4239, checked in by LucMorizur, 14 years ago

[Event Cats] Improve configuration parameters management

File size: 8.9 KB
Line 
1<?php
2
3/*
4Plugin Name: Event Cats
5Version: 1.0.0
6Description: A single URL can be enough to be identified, and a user can duplicate his account to create a new one getting immediately the same properties. / On peut être identifié grâce à un simple URL, et on peut dupliquer son compte pour créer un nouveau compte ayant immédiatement les mêmes propriétés.
7Plugin URI: http://piwigo.org/svn/extensions/event_cats
8Author: P@t, LucMorizur
9Author URI: http://www.gauchon.fr, http://lucmorizur.free.fr
10*/
11
12// +-----------------------------------------------------------------------+
13// | Piwigo - a PHP based picture gallery                                  |
14// +-----------------------------------------------------------------------+
15// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
16// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
17// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
18// +-----------------------------------------------------------------------+
19// | This program is free software; you can redistribute it and/or modify  |
20// | it under the terms of the GNU General Public License as published by  |
21// | the Free Software Foundation                                          |
22// |                                                                       |
23// | This program is distributed in the hope that it will be useful, but   |
24// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
25// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
26// | General Public License for more details.                              |
27// |                                                                       |
28// | You should have received a copy of the GNU General Public License     |
29// | along with this program; if not, write to the Free Software           |
30// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
31// | USA.                                                                  |
32// +-----------------------------------------------------------------------+
33
34if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
35
36// pour faciliter le debug - make debug easier :o)
37//ini_set('error_reporting', E_ALL);
38//ini_set('display_errors', true);
39
40global $conf, $prefixeTable, $ec_lists, $ec_debug,
41  $ec_ap_ok;   // whether Additional Pages is installed and activated
42
43define('EVNTCATS_INFO_VERSION','1.0.0');
44define('EVNTCATS_PATH',PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)). '/');
45define('EVNTCATS_TABLE',$prefixeTable.'event_cats');
46define('ROOT_URL',get_absolute_root_url());
47
48$ec_ap_ok = defined('AP_DIR');
49
50if (!isset($ec_lists)) $ec_lists = array();
51
52include_once(EVNTCATS_PATH.'include/evntcats_main_funcs.inc.php');
53
54class event_cats {
55// Sets the administration panel of the plugin
56  function plugin_admin_menu($menu) {
57    array_push($menu,
58      array(
59        'NAME' => 'Event Cats',
60        'URL'  => get_admin_plugin_menu_link(dirname(__FILE__).
61                  '/admin/evntcats_admin.php')
62      )
63    );
64    return $menu;
65  }
66} // End class
67
68$obj = new event_cats();
69
70// Admin help management
71add_event_handler('get_popup_help_content', 'ec_popup_help_content',
72 EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
73
74function ec_popup_help_content($popup_help_content, $page) {
75  return (
76   $help_content = ($page == 'event_cats' and is_admin()) ?
77    load_language('help.html', EVNTCATS_PATH, array('return' => true)) : false
78  ) ? $popup_help_content.$help_content : $popup_help_content;
79}
80
81//----------------------------------
82
83/**
84 *
85 * auto_log_user()
86 * the function uses the value of the argument "autolog" of the posted URL, as a code
87 * to know which username has to be logged in.
88 *
89 * @param no parameter
90 * @return no return value
91 */
92
93add_event_handler('init', 'auto_log_user');
94
95function auto_log_user() {
96  global $ec_lists;
97
98  $ec_ap  = NULL;
99  $ec_cat = NULL;
100  $ec_img = NULL;
101
102  if (isset($_GET['autolog']) and (read_ec_conf('activated') == 1)) {
103    if (!is_a_guest()) {
104      $url = '';
105      foreach ($_GET as $item => $value) {
106        $url.= '&'.$item.'='.$value;
107      }
108      logout_user();
109      redirect(make_index_url().$url);
110    }
111    build_ec_lists();
112    foreach ($ec_lists['ec_table'] as $ec_entry) {
113      if ($code_exists = ($ec_entry['code'] == $_GET['autolog'])) break;
114    }
115    if ($code_exists) {
116      if (is_in($ec_entry['action'], 'ec_ok')) {
117        log_user($ec_entry['user_id'], false);
118        if (isset($_GET['ap'])) $ec_ap = $_GET['ap'];
119        if (isset($_GET['cat'])) $ec_cat = $_GET['cat'];
120        if (isset($_GET['img'])) $ec_img = $_GET['img'];
121        if ($ec_entry['forced'] == 'true') {
122          if (empty($ec_entry['arg1']) and !empty($ec_entry['arg2'])) {
123            $ec_ap = $ec_entry['arg2'];
124          }
125          elseif (!empty($ec_entry['arg1'])) {
126            $ec_cat = $ec_entry['arg1'];
127            if (!empty($ec_entry['arg2'])) $ec_img = $ec_entry['arg2'];
128          }
129        }
130        if (isset($ec_ap)) {
131          if (array_key_exists($ec_ap,$ec_lists['add_pages'])) {
132            redirect(
133             PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap);
134          }
135        }
136        elseif (isset($ec_cat)) {
137          if (array_key_exists($ec_cat, $ec_lists['categories'])) {
138            if (isset($ec_img)) {
139              if (ec_image_exists($ec_cat, $ec_img)) {
140                redirect(PHPWG_ROOT_PATH.'picture.php?/'.$ec_img.'/category/'.$ec_cat);
141              }
142            }
143            redirect(PHPWG_ROOT_PATH.'index.php?/category/'.$ec_cat);
144          }
145        }
146        redirect(make_index_url());
147      }
148      else {
149        if (
150         $ec_entry['action'] == 'ec_nok' or
151         $ec_entry['action'] == 'ec_nok_ap_pb'
152        ) {
153          if ($ec_entry['action'] == 'ec_nok_ap_pb') access_denied();
154          $ec_ap = $ec_entry['arg2'];
155          if (array_key_exists($ec_ap, $ec_lists['add_pages'])) {
156            redirect(
157             PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap);
158          }
159          access_denied();
160        }
161        else {
162          redirect(make_index_url());
163        }
164      }
165    }
166    else {
167      if (
168       read_ec_conf('unknown_code') == 2 and
169        array_key_exists(
170         read_ec_conf('unknown_code_ap_id'), $ec_lists['add_pages']
171        )
172       ) {
173        redirect(
174         PHPWG_ROOT_PATH.
175         'index.php?/additional_page/'.read_ec_conf('unknown_code_ap_id')
176        );
177      }
178      elseif (read_ec_conf('unknown_code') == 1 or
179       read_ec_conf('unknown_code') == 2) {
180        access_denied();
181      }
182      else {
183        redirect(make_index_url());
184      }
185    }
186  }
187}
188
189/**
190 *
191 * assign_perm_for_new_user()
192 * copies/paste groups+access+properties associations of previously connected
193 * username, to newly created username.
194 *
195 * @param no parameter
196 * @return no return value
197 */
198
199add_event_handler('register_user', 'assign_perm_for_new_user');
200
201function assign_perm_for_new_user($new_user)
202{
203  global $user;
204
205  if (!is_a_guest() and !is_admin())
206  {
207    // User access
208    $query = 'SELECT cat_id FROM '.USER_ACCESS_TABLE.' WHERE user_id = '.$user['id'].';';
209    $result = pwg_query($query);
210    $insert = array();
211    while ($row = mysql_fetch_assoc($result))
212    {
213      $insert[] = '('.$new_user['id'].','.$row['cat_id'].')';
214    }
215    if (!empty($insert))
216    {
217      pwg_query('INSERT INTO '.USER_ACCESS_TABLE.' VALUES '.implode(',', $insert).';');
218    }
219
220    // User groups
221    $query = 'SELECT group_id FROM '.USER_GROUP_TABLE.' WHERE user_id = '.$user['id'].';';
222    $result = pwg_query($query);
223    $insert = array();
224    while ($row = mysql_fetch_assoc($result))
225    {
226      $insert[] = '('.$new_user['id'].','.$row['group_id'].')';
227    }
228    if (!empty($insert))
229    {
230      pwg_query('INSERT INTO '.USER_GROUP_TABLE.' VALUES '.implode(',', $insert).';');
231    }
232
233    // User infos
234    $query = 'SELECT level FROM '.USER_INFOS_TABLE.' WHERE user_id = '.$user['id'].';';
235    $result = pwg_query($query);
236    $insert = array();
237    while ($row = mysql_fetch_assoc($result))
238    {
239      $insert[] = '('.$new_user['id'].','.$row['level'].')';
240    }
241    if (!empty($insert))
242    {
243      $query = 'UPDATE '.USER_INFOS_TABLE.' SET level = '.$user['level'].' WHERE user_id = '.$new_user['id'].';';
244      pwg_query($query);
245    }
246  }
247}
248
249/**
250 *
251 * duplicate_account_url()
252 * adds a link "Duplicate" in Identification block menu.
253 *
254 * @param no parameter
255 * @return no return value
256 */
257
258add_event_handler('blockmanager_apply', 'duplicate_account_url');
259
260function duplicate_account_url() {
261  global $lang, $template;
262 
263  if (is_admin() and read_ec_conf('reg_display') == '0')
264   change_ec_conf('reg_display', '1;'.$lang['Register']);
265  if (!is_admin() and !is_a_guest()) {
266    $template->assign( 'U_REGISTER', get_root_url().'register.php');
267    $lang['Create a new account'] = l10n('Duplicate account');
268    $lang['Register'] = l10n('Duplicate');
269  }
270}
271
272add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') );
273set_plugin_data($plugin['id'], $obj);
274
275?>
Note: See TracBrowser for help on using the repository browser.