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

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

[Event Cats] Add character "é" in all files so to keep them coded in UTF-8 w/o BOM

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