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

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

[Event Cats] Continue duplication management

File size: 9.0 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
50include_once(EVNTCATS_PATH.'include/evntcats_main_funcs.inc.php');
51
52class event_cats {
53// Sets the administration panel of the plugin
54  function plugin_admin_menu($menu) {
55    array_push($menu,
56      array(
57        'NAME' => 'Event Cats',
58        'URL'  => get_admin_plugin_menu_link(dirname(__FILE__).
59                  '/admin/evntcats_admin.php')
60      )
61    );
62    return $menu;
63  }
64} // End class
65
66$obj = new event_cats();
67
68// Admin help management
69add_event_handler('get_popup_help_content', 'ec_popup_help_content',
70 EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
71
72function ec_popup_help_content($popup_help_content, $page) {
73  return (
74   $help_content = ($page == 'event_cats' and is_admin()) ?
75    load_language('help.html', EVNTCATS_PATH, array('return' => true)) : false
76  ) ? $popup_help_content.$help_content : $popup_help_content;
77}
78
79//----------------------------------
80
81/**
82 *
83 * auto_log_user()
84 * the function uses the value of the argument "autolog" of the posted URL, as a code
85 * to know which username has to be logged in.
86 *
87 * @param no parameter
88 * @return no return value
89 */
90
91add_event_handler('init', 'auto_log_user');
92
93function auto_log_user() {
94  global $ec_lists;
95
96  $ec_ap  = NULL;
97  $ec_cat = NULL;
98  $ec_img = NULL;
99
100  // For compatibility ; must be removed
101  if (isset($_GET['log'])) $_GET['autolog'] = $_GET['log'];
102  // For compatibility ; must be removed
103 
104  if (isset($_GET['autolog']) and (read_ec_conf('activated') == 1)) {
105    if (!is_a_guest()) {
106      $url = '';
107      foreach ($_GET as $item => $value) {
108        $url.= '&'.$item.'='.$value;
109      }
110      logout_user();
111      redirect(make_index_url().$url);
112    }
113    build_ec_lists();
114    foreach ($ec_lists['ec_table'] as $ec_entry) {
115      if ($code_exists = ($ec_entry['code'] == $_GET['autolog'])) break;
116    }
117    if ($code_exists) {
118      if (is_in($ec_entry['action'], 'ec_ok')) {
119        log_user($ec_entry['user_id'], false);
120        if (isset($_GET['ap'])) $ec_ap = $_GET['ap'];
121        if (isset($_GET['cat'])) $ec_cat = $_GET['cat'];
122        if (isset($_GET['img'])) $ec_img = $_GET['img'];
123        if ($ec_entry['forced'] == 'true') {
124          if (empty($ec_entry['arg1']) and !empty($ec_entry['arg2'])) {
125            $ec_ap = $ec_entry['arg2'];
126          }
127          elseif (!empty($ec_entry['arg1'])) {
128            $ec_cat = $ec_entry['arg1'];
129            if (!empty($ec_entry['arg2'])) $ec_img = $ec_entry['arg2'];
130          }
131        }
132        if (isset($ec_ap)) {
133          if (array_key_exists($ec_ap,$ec_lists['add_pages'])) {
134            redirect(
135             PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap);
136          }
137        }
138        elseif (isset($ec_cat)) {
139          if (array_key_exists($ec_cat, $ec_lists['categories'])) {
140            if (isset($ec_img)) {
141              if (ec_image_exists($ec_cat, $ec_img)) {
142                redirect(PHPWG_ROOT_PATH.'picture.php?/'.$ec_img.'/category/'.$ec_cat);
143              }
144            }
145            redirect(PHPWG_ROOT_PATH.'index.php?/category/'.$ec_cat);
146          }
147        }
148        redirect(make_index_url());
149      }
150      else {
151        if (
152         $ec_entry['action'] == 'ec_nok' or
153         $ec_entry['action'] == 'ec_nok_ap_pb'
154        ) {
155          if ($ec_entry['action'] == 'ec_nok_ap_pb') access_denied();
156          $ec_ap = $ec_entry['arg2'];
157          if (array_key_exists($ec_ap, $ec_lists['add_pages'])) {
158            redirect(
159             PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap);
160          }
161          access_denied();
162        }
163        else {
164          redirect(make_index_url());
165        }
166      }
167    }
168    else {
169      if (
170       read_ec_conf('unknown_code') == 2 and
171        array_key_exists(
172         read_ec_conf('unknown_code_ap_id'), $ec_lists['add_pages']
173        )
174       ) {
175        redirect(
176         PHPWG_ROOT_PATH.
177         'index.php?/additional_page/'.read_ec_conf('unknown_code_ap_id')
178        );
179      }
180      elseif (read_ec_conf('unknown_code') == 1 or
181       read_ec_conf('unknown_code') == 2) {
182        access_denied();
183      }
184      else {
185        redirect(make_index_url());
186      }
187    }
188  }
189}
190
191/**
192 *
193 * assign_perm_for_new_user()
194 * copies/paste groups+access+properties associations of previously connected
195 * username, to newly created username.
196 *
197 * @param no parameter
198 * @return no return value
199 */
200
201add_event_handler('register_user', 'assign_perm_for_new_user');
202
203function assign_perm_for_new_user($new_user)
204{
205  global $user;
206
207  if (!is_a_guest() and !is_admin())
208  {
209    // User access
210    $query = 'SELECT cat_id FROM '.USER_ACCESS_TABLE.' WHERE user_id = '.$user['id'].';';
211    $result = pwg_query($query);
212    $insert = array();
213    while ($row = mysql_fetch_assoc($result))
214    {
215      $insert[] = '('.$new_user['id'].','.$row['cat_id'].')';
216    }
217    if (!empty($insert))
218    {
219      pwg_query('INSERT INTO '.USER_ACCESS_TABLE.' VALUES '.implode(',', $insert).';');
220    }
221
222    // User groups
223    $query = 'SELECT group_id FROM '.USER_GROUP_TABLE.' WHERE user_id = '.$user['id'].';';
224    $result = pwg_query($query);
225    $insert = array();
226    while ($row = mysql_fetch_assoc($result))
227    {
228      $insert[] = '('.$new_user['id'].','.$row['group_id'].')';
229    }
230    if (!empty($insert))
231    {
232      pwg_query('INSERT INTO '.USER_GROUP_TABLE.' VALUES '.implode(',', $insert).';');
233    }
234
235    // User infos
236    $query = 'SELECT level FROM '.USER_INFOS_TABLE.' WHERE user_id = '.$user['id'].';';
237    $result = pwg_query($query);
238    $insert = array();
239    while ($row = mysql_fetch_assoc($result))
240    {
241      $insert[] = '('.$new_user['id'].','.$row['level'].')';
242    }
243    if (!empty($insert))
244    {
245      $query = 'UPDATE '.USER_INFOS_TABLE.' SET level = '.$user['level'].' WHERE user_id = '.$new_user['id'].';';
246      pwg_query($query);
247    }
248  }
249}
250
251/**
252 *
253 * duplicate_account_url()
254 * adds a link "Duplicate" in Identification block menu.
255 *
256 * @param no parameter
257 * @return no return value
258 */
259
260add_event_handler('blockmanager_apply', 'duplicate_account_url');
261
262function duplicate_account_url() {
263  global $lang, $template;
264 
265  if (!is_admin() and !is_a_guest()) {
266    $template->assign( 'U_REGISTER', get_root_url().'register.php');
267    if (isset($lang['Duplicate account']))
268     $lang['Create a new account'] = l10n('Duplicate account');
269    if (isset($lang['Register']))
270     $lang['Register'] = l10n('Duplicate');
271  }
272}
273
274add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') );
275set_plugin_data($plugin['id'], $obj);
276
277?>
Note: See TracBrowser for help on using the repository browser.