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

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

[event cats] First commit, with files this time

File size: 9.5 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, $ec_conf,
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
55// $ec_conf initalization / check
56if ($t = mysql_fetch_row(pwg_query("
57 SELECT `value`
58 FROM `".CONFIG_TABLE."`
59 WHERE `param` = 'event_cats';
60"))) {
61  $ec_conf = explode(',' , $t[0]);
62}
63else {
64  $ec_conf = array();
65}
66
67include_once(EVNTCATS_PATH.'include/evntcats_funcs.inc.php');
68
69class event_cats {
70// Sets the administration panel of the plugin
71  function plugin_admin_menu($menu) {
72    array_push($menu,
73      array(
74        'NAME' => 'Event Cats',
75        'URL'  => get_admin_plugin_menu_link(dirname(__FILE__).
76                  '/admin/evntcats_admin.php')
77      )
78    );
79    return $menu;
80  }
81} // End class
82
83$obj = new event_cats();
84
85// Admin help management
86add_event_handler('get_popup_help_content', 'ec_popup_help_content',
87 EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
88
89function ec_popup_help_content($popup_help_content, $page) {
90  return (
91   $help_content = ($page == 'event_cats' and is_admin()) ?
92    load_language('help.html', EVNTCATS_PATH, array('return' => true)) : false
93  ) ? $popup_help_content.$help_content : $popup_help_content;
94}
95                                                                                     // Mettre en place l'autoid, qu'on voie si ça marche !
96
97//----------------------------------
98
99/**
100 *
101 * auto_log_user()
102 * the function uses the value of the argument "autolog" of the posted URL, as a code
103 * to know which username has to be logged in.
104 *
105 * @param no parameter
106 * @return no return value
107 */
108
109add_event_handler('init', 'auto_log_user');
110
111function auto_log_user() {
112  global $ec_conf, $ec_lists;
113
114  $ec_ap  = NULL;
115  $ec_cat = NULL;
116  $ec_img = NULL;
117
118  if (isset($_GET['autolog']) and ($ec_conf['activated'] == 1)) {
119    if (!is_a_guest()) logout_user();
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 (isset($_GET['ap'])) $ec_ap = $_GET['ap'];
126      if (strpos($ec_entry['action'], 'ec_ok') !== false) {
127        log_user($ec_entry['user_id'], false);
128        if (isset($_GET['cat'])) $ec_cat = $_GET['cat'];
129        if (isset($_GET['img'])) $ec_img = $_GET['img'];
130        if (
131         $ec_entry['forced'] == 'true' and
132         $ec_entry['action'] != 'ec_forced_pb'
133        ) {
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 (mysql_fetch_row(pwg_query('
152               SELECT *
153               FROM `'.IMAGE_CATEGORY_TABLE.'`
154               WHERE `category_id` = '.$ec_cat.'
155                AND `image_id` = '.$ec_img
156              ))) {
157                redirect(PHPWG_ROOT_PATH.'picture.php?/'.$ec_img.'/category/'.$ec_cat);
158              }
159            }
160            redirect(PHPWG_ROOT_PATH.'index.php?/category/'.$ec_cat);
161          }
162        }
163        else {
164          redirect(make_index_url());
165        }
166      }
167      else {
168        if ($ec_entry['action'] == 'ec_nok') {
169          if (isset($ec_ap)) {
170            if (array_key_exists($ec_ap,$ec_lists['add_pages'])) {
171              redirect(
172               PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap);
173            }
174          }
175          access_denied();
176        }
177        else {
178          redirect(make_index_url());
179        }
180      }
181    }
182    else {
183      if (
184       $ec_conf['unknown_code'] == 2 and
185        array_key_exists(
186         $ec_conf['unknown_code_ap_id'], $ec_lists['add_pages']
187        )
188       ) {
189        redirect(
190         PHPWG_ROOT_PATH.
191         'index.php?/additional_page/'.$ec_conf['unknown_code_ap_id']
192        );
193      }
194      elseif ($ec_conf['unknown_code'] == 1 or
195       $ec_conf['unknown_code'] == 2) {
196        access_denied();
197      }
198      else {
199        redirect(make_index_url());
200      }
201    }
202  }
203}
204
205/**
206 *
207 * assign_perm_for_new_user()
208 * copies/paste groups+access+properties associations of previously connected
209 * username, to newly created username.
210 *
211 * @param no parameter
212 * @return no return value
213 */
214
215add_event_handler('register_user', 'assign_perm_for_new_user');
216
217function assign_perm_for_new_user($new_user)
218{ /*
219  global $user;
220
221  if (!is_a_guest() and !is_admin())
222  {
223    // User access
224    $query = 'SELECT cat_id FROM '.USER_ACCESS_TABLE.' WHERE user_id = '.$user['id'].';';
225    $result = pwg_query($query);
226    $insert = array();
227    while ($row = mysql_fetch_assoc($result))
228    {
229      $insert[] = '('.$new_user['id'].','.$row['cat_id'].')';
230    }
231    if (!empty($insert))
232    {
233      pwg_query('INSERT INTO '.USER_ACCESS_TABLE.' VALUES '.implode(',', $insert).';');
234    }
235
236    // User groups
237    $query = 'SELECT group_id FROM '.USER_GROUP_TABLE.' WHERE user_id = '.$user['id'].';';
238    $result = pwg_query($query);
239    $insert = array();
240    while ($row = mysql_fetch_assoc($result))
241    {
242      $insert[] = '('.$new_user['id'].','.$row['group_id'].')';
243    }
244    if (!empty($insert))
245    {
246      pwg_query('INSERT INTO '.USER_GROUP_TABLE.' VALUES '.implode(',', $insert).';');
247    }
248
249    // User infos
250    $query = 'SELECT level FROM '.USER_INFOS_TABLE.' WHERE user_id = '.$user['id'].';';
251    $result = pwg_query($query);
252    $insert = array();
253    while ($row = mysql_fetch_assoc($result))
254    {
255      $insert[] = '('.$new_user['id'].','.$row['level'].')';
256    }
257    if (!empty($insert))
258    {
259      $query = 'UPDATE '.USER_INFOS_TABLE.' SET level = '.$user['level'].' WHERE user_id = '.$new_user['id'].';';
260      pwg_query($query);
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{ /*
278  global $conf, $lang, $template;
279
280  if ($conf['allow_user_registration'] and !is_admin() and !is_a_guest())
281    and !is_admin() and !is_a_guest())
282  {
283    $template->assign( 'U_REGISTER', get_root_url().'register.php');
284    $lang['Create a new account'] = l10n('Duplicate account');
285    $lang['Register'] = l10n('Duplicate');
286  } */
287}
288
289// copying/pasting the following lines from same file in plugin LLGBO2,
290// because it looks like it's useful :-/ .....   
291               /*
292add_event_handler('render_element_content',
293  array(&$obj,'MyPictureOptions'),  EVENT_HANDLER_PRIORITY_NEUTRAL-1,  2  );   */
294add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') );
295set_plugin_data($plugin['id'], $obj);
296
297?>
Note: See TracBrowser for help on using the repository browser.