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

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

[Event Cats] Continue EN translation ; fix bugs 1324 and 1325 (main.inc.php version information update forgotten)

File size: 9.8 KB
Line 
1<?php
2
3/*
4Plugin Name: Event Cats
5Version: auto
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/ext/extension_svn.php?eid=326
8Author: LucMorizur
9Author URI: 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
34// Keeps file coded in UTF-8 without BOM : é
35
36if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
37
38// pour faciliter le debug - make debug easier :o)
39//ini_set('error_reporting', E_ALL);
40//ini_set('display_errors', true);
41
42global $conf, $prefixeTable, $ec_lists;
43
44define( // -------------------------------------------------------------------
45  'EVNTCATS_INFO_VERSION', // VERSION HISTORY :
46   '1.1.5'   // Fix bugs 1324 and 1325
47// '1.1.4'   // Improve help banner
48// '1.1.3'   // Better help banner management ; finalize banner texts
49// '1.1.2'   // Better help banner example : some examples
50// '1.1.1'   // Better help banner example ; but still no text in it
51// '1.1.0'   // First bugs (1305 and 1306) corrected ;
52//      add newly created user/group association with cat/AP (was forgotten) ;
53//      begin help banner
54// '1.0.0'   // Conception version
55); // ------------------------------------------------------------------------
56define(
57  'EVNTCATS_PATH',
58   PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'
59);
60define(
61  'EVNTCATS_TABLE',
62   $prefixeTable.'event_cats'
63);
64define(
65  'ROOT_URL',
66   get_absolute_root_url()
67);
68
69include_once(EVNTCATS_PATH.'include/evntcats_main_funcs.inc.php');
70
71class event_cats {
72// Sets the administration panel of the plugin
73  function plugin_admin_menu($menu) {
74    array_push($menu,
75      array(
76        'NAME' => 'Event Cats',
77        'URL'  => get_admin_plugin_menu_link(dirname(__FILE__).
78                  '/admin/evntcats_admin.php')
79      )
80    );
81    return $menu;
82  }
83} // End class
84
85$obj = new event_cats();
86
87// Adds the translation of "duplicate" link
88load_language('duplic.lang', EVNTCATS_PATH);
89
90// Admin help management
91add_event_handler('get_popup_help_content', 'ec_popup_help_content',
92 EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
93
94function ec_popup_help_content($popup_help_content, $page) {
95  return (
96   $help_content = (is_admin() and $page = 'help') ?
97    load_language($page.'.html', EVNTCATS_PATH, array('return' => true)) : false
98  ) ? $popup_help_content.$help_content : $popup_help_content;
99}
100
101//----------------------------------
102
103/**
104 *
105 * auto_log_user()
106 * the function uses the value of the argument "autolog" of the posted URL, as a code
107 * to know which username has to be logged in.
108 *
109 * @param no parameter
110 * @return no return value
111 */
112
113add_event_handler('init', 'auto_log_user');
114
115function auto_log_user() {
116  global $ec_lists;
117
118  $ec_ap  = NULL;
119  $ec_cat = NULL;
120  $ec_img = NULL;
121 
122  if (isset($_GET['autolog']) and (read_ec_conf('activated') == 1)) {
123    if (!is_a_guest()) {
124      $url = '';
125      foreach ($_GET as $item => $value) {
126        $url.= '&'.$item.'='.$value;
127      }
128      logout_user();
129      redirect(make_index_url().$url);
130    }
131    build_ec_lists();
132    foreach ($ec_lists['ec_table'] as $ec_entry) {
133      if ($code_exists = ($ec_entry['code'] == $_GET['autolog'])) break;
134    }
135    if ($code_exists) {
136      if (is_in($ec_entry['action'], 'ec_ok')) {
137        log_user($ec_entry['user_id'], false);
138        if (isset($_GET['ap'])) $ec_ap = $_GET['ap'];
139        if (isset($_GET['cat'])) $ec_cat = $_GET['cat'];
140        if (isset($_GET['img'])) $ec_img = $_GET['img'];
141        if ($ec_entry['forced'] == 'true') {
142          if (empty($ec_entry['arg1']) and !empty($ec_entry['arg2'])) {
143            $ec_ap = $ec_entry['arg2'];
144          }
145          elseif (!empty($ec_entry['arg1'])) {
146            $ec_cat = $ec_entry['arg1'];
147            if (!empty($ec_entry['arg2'])) $ec_img = $ec_entry['arg2'];
148          }
149        }
150        if (isset($ec_ap)) {
151          if (array_key_exists($ec_ap,$ec_lists['add_pages'])) {
152            redirect(
153             PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap);
154          }
155        }
156        elseif (isset($ec_cat)) {
157          if (array_key_exists($ec_cat, $ec_lists['categories'])) {
158            if (isset($ec_img)) {
159              if (ec_image_exists($ec_cat, $ec_img)) {
160                redirect(PHPWG_ROOT_PATH.'picture.php?/'.$ec_img.'/category/'.$ec_cat);
161              }
162            }
163            redirect(PHPWG_ROOT_PATH.'index.php?/category/'.$ec_cat);
164          }
165        }
166        redirect(make_index_url());
167      }
168      else {
169        if (
170         $ec_entry['action'] == 'ec_nok' or
171         $ec_entry['action'] == 'ec_nok_ap_pb'
172        ) {
173          if ($ec_entry['action'] == 'ec_nok_ap_pb') access_denied();
174          $ec_ap = $ec_entry['arg2'];
175          if (array_key_exists($ec_ap, $ec_lists['add_pages'])) {
176            redirect(
177             PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap);
178          }
179          access_denied();
180        }
181        else {
182          redirect(make_index_url());
183        }
184      }
185    }
186    else {
187      if (
188       read_ec_conf('unknown_code') == '2' and
189        array_key_exists(
190         read_ec_conf('unknown_code_ap_id'), $ec_lists['add_pages']
191        )
192       ) {
193        redirect(
194         PHPWG_ROOT_PATH.
195         'index.php?/additional_page/'.read_ec_conf('unknown_code_ap_id')
196        );
197      }
198      elseif (read_ec_conf('unknown_code') == '1' or
199       read_ec_conf('unknown_code') == '2') {
200        access_denied();
201      }
202      else {
203        redirect(make_index_url());
204      }
205    }
206  }
207}
208
209/**
210 *
211 * assign_perm_for_new_user()
212 * copies/paste groups+access+properties associations of previously connected
213 * username, to newly created username.
214 *
215 * @param no parameter
216 * @return no return value
217 */
218
219add_event_handler('register_user', 'assign_perm_for_new_user');
220
221function assign_perm_for_new_user($new_user) {
222  global $user;
223
224  if (!is_a_guest() and !is_admin()) if (
225    read_ec_conf('dup_allow') == '1' or (
226      read_ec_conf('dup_allow') == '2' and
227      dup_allowed($user['id'])
228    )
229  ) {
230    // User access
231    $result = pwg_query("
232      SELECT `cat_id`
233      FROM `".USER_ACCESS_TABLE."`
234      WHERE `user_id` = ".$user['id'].";
235    ");
236    $insert = array();
237    while ($row = mysql_fetch_assoc($result))
238     $insert[] = "(".$new_user['id'].",".$row['cat_id'].")";
239    if (!empty($insert)) pwg_query("
240      INSERT INTO `".USER_ACCESS_TABLE."`
241      VALUES ".implode(',', $insert).";
242    ");
243
244    // User groups
245    $result = pwg_query("
246      SELECT `group_id`
247      FROM `".USER_GROUP_TABLE."`
248      WHERE `user_id` = ".$user['id'].";
249    ");
250    $insert = array();
251    while ($row = mysql_fetch_assoc($result))
252     $insert[] = "(".$new_user['id'].",".$row['group_id'].")";
253    if (!empty($insert)) pwg_query("
254      INSERT INTO `".USER_GROUP_TABLE."`
255      VALUES ".implode(',', $insert).";
256    ");
257
258    // User infos
259    $result = pwg_query("
260      SELECT `level`
261      FROM `".USER_INFOS_TABLE."`
262      WHERE `user_id` = ".$user['id'].";
263    ");
264    $insert = array();
265    while ($row = mysql_fetch_assoc($result))
266     $insert[] = "(".$new_user['id'].",".$row['level'].")";
267    if (!empty($insert)) pwg_query("
268      UPDATE `".USER_INFOS_TABLE."`
269      SET `level` = ".$user['level']."
270      WHERE `user_id` = ".$new_user['id'].";
271    ");
272  }
273}
274
275/**
276 *
277 * duplicate_account_url()
278 * adds a link "Duplicate" in Identification block menu.
279 *
280 * @param no parameter
281 * @return no return value
282 */
283
284add_event_handler('blockmanager_apply', 'duplicate_account_url');
285
286function duplicate_account_url() {
287  global $lang, $template, $user;
288 
289  if (!is_admin() and !is_a_guest()) if (
290    read_ec_conf('dup_allow') == '1' or (
291      read_ec_conf('dup_allow') == '2' and
292      dup_allowed($user['id'])
293    )
294  ) {
295    $template->assign('U_REGISTER', get_root_url().'register.php');
296    if (
297      read_ec_conf('duplic_display') == '1' or (
298        read_ec_conf('duplic_display') == '2' and
299        !is_generic()
300      )
301    ) {
302      $lang['Register'] = $lang['Duplicate'];
303      $lang['Create a new account'] = $lang['Create a new account with same properties'];
304    }
305  }
306}
307
308add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') );
309set_plugin_data($plugin['id'], $obj);
310
311?>
Note: See TracBrowser for help on using the repository browser.