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

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

[Event Cats] Continue help

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