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

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

[Event Cats] Help banners forgotten for feature 1335

File size: 11.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.2.0' // Add feature 1335, Possibility to display the 'Connection'
47           // link in identification block menu for generic users ;
48           // finish (?) english translation
49
50// --------------------------------------------------------------------------- => à modifier :
51                                                                               // evntcats_admin.php -> analyser un changement d'option dans la page d'options ;
52                                                                               // config.tpl         -> proposer le réglage de cette nouvelle option ;
53                                                                               // main.inc.php       -> afficher le lien si l'option le demande.
54
55// '1.1.5' // Fix bugs 1324 and 1325
56// '1.1.4' // Improve help banner
57// '1.1.3' // Better help banner management ; finalize banner texts
58// '1.1.2' // Better help banner example : some examples
59// '1.1.1' // Better help banner example ; but still no text in it
60// '1.1.0' // First bugs (1305 and 1306) corrected ;
61           // add newly created user/group association with cat/AP (was
62           // forgotten) ; begin help banner
63// '1.0.0' // Conception version
64); // ------------------------------------------------------------------------
65define(
66  'EVNTCATS_PATH',
67   PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'
68);
69define(
70  'EVNTCATS_TABLE',
71   $prefixeTable.'event_cats'
72);
73define(
74  'ROOT_URL',
75   get_absolute_root_url()
76);
77
78include_once(EVNTCATS_PATH.'include/evntcats_main_funcs.inc.php');
79
80class event_cats {
81// Sets the administration panel of the plugin
82  function plugin_admin_menu($menu) {
83    array_push($menu,
84      array(
85        'NAME' => 'Event Cats',
86        'URL'  => get_admin_plugin_menu_link(dirname(__FILE__).
87                  '/admin/evntcats_admin.php')
88      )
89    );
90    return $menu;
91  }
92} // End class
93
94$obj = new event_cats();
95
96// Adds the translation of "duplicate" link
97load_language('duplic.lang', EVNTCATS_PATH);
98
99// Admin help management
100add_event_handler('get_popup_help_content', 'ec_popup_help_content',
101 EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
102
103function ec_popup_help_content($popup_help_content, $page) {
104  return (
105   $help_content = (is_admin() and $page = 'help') ?
106    load_language($page.'.html', EVNTCATS_PATH, array('return' => true)) : false
107  ) ? $popup_help_content.$help_content : $popup_help_content;
108}
109
110//----------------------------------
111
112/**
113 *
114 * auto_log_user()
115 * the function uses the value of the argument "autolog" of the posted URL, as a code
116 * to know which username has to be logged in.
117 *
118 * @param no parameter
119 * @return no return value
120 */
121
122add_event_handler('init', 'auto_log_user');
123
124function auto_log_user() {
125  global $ec_lists;
126
127  $ec_ap  = NULL;
128  $ec_cat = NULL;
129  $ec_img = NULL;
130 
131  if (isset($_GET['autolog']) and (read_ec_conf('activated') == 1)) {
132    if (!is_a_guest()) {
133      $url = '';
134      foreach ($_GET as $item => $value) {
135        $url.= '&'.$item.'='.$value;
136      }
137      logout_user();
138      redirect(make_index_url().$url);
139    }
140    build_ec_lists();
141    foreach ($ec_lists['ec_table'] as $ec_entry) {
142      if ($code_exists = ($ec_entry['code'] == $_GET['autolog'])) break;
143    }
144    if ($code_exists) {
145      if (is_in($ec_entry['action'], 'ec_ok')) {
146        log_user($ec_entry['user_id'], false);
147        if (isset($_GET['ap'])) $ec_ap = $_GET['ap'];
148        if (isset($_GET['cat'])) $ec_cat = $_GET['cat'];
149        if (isset($_GET['img'])) $ec_img = $_GET['img'];
150        if ($ec_entry['forced'] == 'true') {
151          if (empty($ec_entry['arg1']) and !empty($ec_entry['arg2'])) {
152            $ec_ap = $ec_entry['arg2'];
153          }
154          elseif (!empty($ec_entry['arg1'])) {
155            $ec_cat = $ec_entry['arg1'];
156            if (!empty($ec_entry['arg2'])) $ec_img = $ec_entry['arg2'];
157          }
158        }
159        if (isset($ec_ap)) {
160          if (array_key_exists($ec_ap,$ec_lists['add_pages'])) {
161            redirect(
162             PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap);
163          }
164        }
165        elseif (isset($ec_cat)) {
166          if (array_key_exists($ec_cat, $ec_lists['categories'])) {
167            if (isset($ec_img)) {
168              if (ec_image_exists($ec_cat, $ec_img)) {
169                redirect(PHPWG_ROOT_PATH.'picture.php?/'.$ec_img.'/category/'.$ec_cat);
170              }
171            }
172            redirect(PHPWG_ROOT_PATH.'index.php?/category/'.$ec_cat);
173          }
174        }
175        redirect(make_index_url());
176      }
177      else {
178        if (
179         $ec_entry['action'] == 'ec_nok' or
180         $ec_entry['action'] == 'ec_nok_ap_pb'
181        ) {
182          if ($ec_entry['action'] == 'ec_nok_ap_pb') access_denied();
183          $ec_ap = $ec_entry['arg2'];
184          if (array_key_exists($ec_ap, $ec_lists['add_pages'])) {
185            redirect(
186             PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap);
187          }
188          access_denied();
189        }
190        else {
191          redirect(make_index_url());
192        }
193      }
194    }
195    else {
196      if (
197       read_ec_conf('unknown_code') == '2' and
198        array_key_exists(
199         read_ec_conf('unknown_code_ap_id'), $ec_lists['add_pages']
200        )
201       ) {
202        redirect(
203         PHPWG_ROOT_PATH.
204         'index.php?/additional_page/'.read_ec_conf('unknown_code_ap_id')
205        );
206      }
207      elseif (read_ec_conf('unknown_code') == '1' or
208       read_ec_conf('unknown_code') == '2') {
209        access_denied();
210      }
211      else {
212        redirect(make_index_url());
213      }
214    }
215  }
216}
217
218/**
219 *
220 * assign_perm_for_new_user()
221 * copies/paste groups+access+properties associations of previously connected
222 * username, to newly created username.
223 *
224 * @param no parameter
225 * @return no return value
226 */
227
228add_event_handler('register_user', 'assign_perm_for_new_user');
229
230function assign_perm_for_new_user($new_user) {
231  global $user;
232
233  if (!is_a_guest() and !is_admin()) if (
234    read_ec_conf('dup_allow') == '1' or (
235      read_ec_conf('dup_allow') == '2' and
236      dup_allowed($user['id'])
237    )
238  ) {
239    // User access
240    $result = pwg_query("
241      SELECT `cat_id`
242      FROM `".USER_ACCESS_TABLE."`
243      WHERE `user_id` = ".$user['id'].";
244    ");
245    $insert = array();
246    while ($row = mysql_fetch_assoc($result))
247     $insert[] = "(".$new_user['id'].",".$row['cat_id'].")";
248    if (!empty($insert)) pwg_query("
249      INSERT INTO `".USER_ACCESS_TABLE."`
250      VALUES ".implode(',', $insert).";
251    ");
252
253    // User groups
254    $result = pwg_query("
255      SELECT `group_id`
256      FROM `".USER_GROUP_TABLE."`
257      WHERE `user_id` = ".$user['id'].";
258    ");
259    $insert = array();
260    while ($row = mysql_fetch_assoc($result))
261     $insert[] = "(".$new_user['id'].",".$row['group_id'].")";
262    if (!empty($insert)) pwg_query("
263      INSERT INTO `".USER_GROUP_TABLE."`
264      VALUES ".implode(',', $insert).";
265    ");
266
267    // User infos
268    $result = pwg_query("
269      SELECT `level`
270      FROM `".USER_INFOS_TABLE."`
271      WHERE `user_id` = ".$user['id'].";
272    ");
273    $insert = array();
274    while ($row = mysql_fetch_assoc($result))
275     $insert[] = "(".$new_user['id'].",".$row['level'].")";
276    if (!empty($insert)) pwg_query("
277      UPDATE `".USER_INFOS_TABLE."`
278      SET `level` = ".$user['level']."
279      WHERE `user_id` = ".$new_user['id'].";
280    ");
281  }
282}
283
284/**
285 *
286 * duplicate_account_url()
287 * adds a link for duplicating the currently identified user in
288 * Identification block menu, in case the identifed user is granted to
289 * duplication. Displays also the connection link for generic users, if
290 * required in the configuration.
291 *
292 * @param no parameter
293 * @return no return value
294 */
295
296add_event_handler('blockmanager_apply', 'duplicate_account_url');
297
298function duplicate_account_url() {
299  global $lang, $template, $user;
300 
301  // Adds duplication link, if needed
302  if (!is_admin() and !is_a_guest()) if (
303    read_ec_conf('dup_allow') == '1' or (
304      read_ec_conf('dup_allow') == '2' and
305      dup_allowed($user['id'])
306    )
307  ) {
308    $template->assign('U_REGISTER', get_root_url().'register.php');
309    if (
310      read_ec_conf('duplic_display') == '1' or (
311        read_ec_conf('duplic_display') == '2' and
312        !is_generic()
313      )
314    ) {
315      $lang['Register'] = $lang['Duplicate'];
316      $lang['Create a new account'] =
317       $lang['Create a new account with same properties'];
318    }
319  }
320 
321  // Adds connection link, if needed
322  if (read_ec_conf('display_connection') == '1' and is_generic()) {
323    // Adds connection link
324    $template->assign(
325      'U_LOGIN',
326      get_root_url().'identification.php?redirect='.$_SERVER['REQUEST_URI']
327    );
328    // Removes "quick connection" fieldset (form)
329    $template->set_filenames(array(
330      'ec_no_quick_connect' =>
331      realpath(EVNTCATS_PATH.'ec_no_quick_connect.tpl')
332    ));
333    $begin = 'PLUGIN_INDEX_CONTENT_BEFORE';
334    $old_begin = $template->get_template_vars($begin);
335    $template->assign_var_from_handle($begin, 'ec_no_quick_connect');
336    $template->concat($begin, $old_begin);
337  }
338}
339
340add_event_handler(
341 'get_admin_plugin_menu_links',
342 array(&$obj, 'plugin_admin_menu')
343);
344set_plugin_data($plugin['id'], $obj);
345
346?>
Note: See TracBrowser for help on using the repository browser.