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

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

[Event Cats] Head to different help files from different tabs

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