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

Last change on this file since 3975 was 3975, checked in by LucMorizur, 15 years ago

[Event Cats] Logout if not guest when "autolog" detected

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