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

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

[Event Cats] Duplication management : found last problem :-) !

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