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

Last change on this file since 31810 was 26672, checked in by LucMorizur, 10 years ago

Compatibility with Piwigo version 2.6

File size: 12.3 KB
RevLine 
[3969]1<?php
[3964]2
3/*
4Plugin Name: Event Cats
[10054]5Version: auto
[3970]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.
[6269]7Plugin URI: http://piwigo.org/ext/extension_view.php?eid=326
[4418]8Author: LucMorizur
9Author URI: http://lucmorizur.free.fr
[3964]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
[8956]34// Keeps file coded in UTF-8 without BOM : é
[4421]35
[3964]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
[5058]42global $conf, $prefixeTable, $ec_lists, $template;
[3964]43
[4329]44define( // -------------------------------------------------------------------
[8956]45  'EVNTCATS_INFO_VERSION', // VERSION HISTORY :
[26672]46   '1.2.8' // Complies with Piwigo 2.6
47// '1.2.7' // Complies with Piwigo 2.5
[21996]48// '1.2.6' // Fix bug 2267 « "Test" link in "autolog entries" admin page
[10458]49//            doesn't work », and small improvements
50// '1.2.5' // Compatibility with Piwigo 2.2 (svn:10052)
[10059]51// '1.2.4' // Fix bug 2135: Constant ROOT_URL already defined; replaced by
[8956]52//         // EC_ROOT_URL
[7099]53// '1.2.3' // Re-fix bug 1432 :-/ ...
[6269]54// '2.1.0' // When done, will simplfy and allow EC management from categories
55//            management pages in admin pages... yes yes...
[6425]56// '1.2.2' // Corrections for Piwigo 2.1 compatibility
[6269]57// '1.2.1' // Improve EN translation thanks to Tosca
[4612]58// '1.2.0' // Add feature 1335, Possibility to display the 'Connection'
[8956]59//         // link in identification block menu for generic users ;
[4612]60//         // finish (yes !) english translation
[4553]61// '1.1.5' // Fix bugs 1324 and 1325
62// '1.1.4' // Improve help banner
[8956]63// '1.1.3' // Better help banner management ; finalize banner texts
64// '1.1.2' // Better help banner example : some examples
65// '1.1.1' // Better help banner example ; but still no text in it
66// '1.1.0' // First bugs (1305 and 1306) corrected ;
[4553]67           // add newly created user/group association with cat/AP (was
[8956]68           // forgotten) ; begin help banner
[4553]69// '1.0.0' // Conception version
[4329]70); // ------------------------------------------------------------------------
71define(
72  'EVNTCATS_PATH',
73   PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)).'/'
74);
75define(
76  'EVNTCATS_TABLE',
77   $prefixeTable.'event_cats'
78);
79define(
[8956]80  'EC_ROOT_URL',
[4329]81   get_absolute_root_url()
82);
[3964]83
[4169]84include_once(EVNTCATS_PATH.'include/evntcats_main_funcs.inc.php');
[3964]85
86class event_cats {
87// Sets the administration panel of the plugin
88  function plugin_admin_menu($menu) {
89    array_push($menu,
90      array(
91        'NAME' => 'Event Cats',
92        'URL'  => get_admin_plugin_menu_link(dirname(__FILE__).
93                  '/admin/evntcats_admin.php')
94      )
95    );
96    return $menu;
97  }
98} // End class
99
100$obj = new event_cats();
101
[4282]102// Adds the translation of "duplicate" link
[4338]103load_language('duplic.lang', EVNTCATS_PATH);
[4282]104
[3964]105// Admin help management
106add_event_handler('get_popup_help_content', 'ec_popup_help_content',
107 EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
108
109function ec_popup_help_content($popup_help_content, $page) {
110  return (
[6425]111   $help_content = (is_admin() and $page == 'help') ?
[8956]112    load_language($page.'.html', EVNTCATS_PATH, array('return' => true)) : false
[3964]113  ) ? $popup_help_content.$help_content : $popup_help_content;
114}
115
116//----------------------------------
117
118/**
119 *
120 * auto_log_user()
[8956]121 * the function uses the value of the argument "autolog" of the posted URL, as a code
122 * to know which username has to be logged in.
[3964]123 *
124 * @param no parameter
125 * @return no return value
126 */
127
128add_event_handler('init', 'auto_log_user');
129
130function auto_log_user() {
[4554]131  global $ec_lists;
[3964]132
133  $ec_ap  = NULL;
134  $ec_cat = NULL;
135  $ec_img = NULL;
[4247]136 
[8956]137  if (isset($_GET['autolog']) and (read_ec_conf('activated') == 1)) {
[3975]138    if (!is_a_guest()) {
139      $url = '';
[6269]140      foreach ($_GET as $item => $value) {
[10458]141        if ($url != '') $url.='&';
142        $url.= $item.'='.$value;
[6269]143      }
[3975]144      logout_user();
[10458]145      redirect(get_absolute_root_url().'index.php?'.$url);
[3975]146    }
[3964]147    build_ec_lists();
148    foreach ($ec_lists['ec_table'] as $ec_entry) {
149      if ($code_exists = ($ec_entry['code'] == $_GET['autolog'])) break;
150    }
151    if ($code_exists) {
[3985]152      if (is_in($ec_entry['action'], 'ec_ok')) {
[3964]153        log_user($ec_entry['user_id'], false);
[3971]154        if (isset($_GET['ap'])) $ec_ap = $_GET['ap'];
[3964]155        if (isset($_GET['cat'])) $ec_cat = $_GET['cat'];
156        if (isset($_GET['img'])) $ec_img = $_GET['img'];
[4092]157        if ($ec_entry['forced'] == 'true') {
[3964]158          if (empty($ec_entry['arg1']) and !empty($ec_entry['arg2'])) {
159            $ec_ap = $ec_entry['arg2'];
160          }
161          elseif (!empty($ec_entry['arg1'])) {
162            $ec_cat = $ec_entry['arg1'];
163            if (!empty($ec_entry['arg2'])) $ec_img = $ec_entry['arg2'];
164          }
165        }
166        if (isset($ec_ap)) {
167          if (array_key_exists($ec_ap,$ec_lists['add_pages'])) {
168            redirect(
169             PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap);
170          }
171        }
172        elseif (isset($ec_cat)) {
173          if (array_key_exists($ec_cat, $ec_lists['categories'])) {
174            if (isset($ec_img)) {
[4157]175              if (ec_image_exists($ec_cat, $ec_img)) {
[8956]176                redirect(PHPWG_ROOT_PATH.'picture.php?/'.$ec_img.'/category/'.$ec_cat);
[3964]177              }
178            }
[4554]179            redirect(PHPWG_ROOT_PATH.'index.php?/category/'.$ec_cat);
[3964]180          }
181        }
[3971]182        redirect(make_index_url());
[3964]183      }
184      else {
[3971]185        if (
186         $ec_entry['action'] == 'ec_nok' or
187         $ec_entry['action'] == 'ec_nok_ap_pb'
188        ) {
189          if ($ec_entry['action'] == 'ec_nok_ap_pb') access_denied();
190          $ec_ap = $ec_entry['arg2'];
191          if (array_key_exists($ec_ap, $ec_lists['add_pages'])) {
192            redirect(
193             PHPWG_ROOT_PATH.'index.php?/additional_page/'.$ec_ap);
[3964]194          }
195          access_denied();
196        }
197        else {
198          redirect(make_index_url());
199        }
200      }
201    }
202    else {
203      if (
[4371]204       read_ec_conf('unknown_code') == '2' and
[3964]205        array_key_exists(
[3971]206         read_ec_conf('unknown_code_ap_id'), $ec_lists['add_pages']
[3964]207        )
208       ) {
209        redirect(
210         PHPWG_ROOT_PATH.
[3971]211         'index.php?/additional_page/'.read_ec_conf('unknown_code_ap_id')
[3964]212        );
213      }
[4371]214      elseif (read_ec_conf('unknown_code') == '1' or
215       read_ec_conf('unknown_code') == '2') {
[3964]216        access_denied();
217      }
218      else {
219        redirect(make_index_url());
220      }
221    }
222  }
223}
224
225/**
226 *
227 * assign_perm_for_new_user()
228 * copies/paste groups+access+properties associations of previously connected
229 * username, to newly created username.
230 *
231 * @param no parameter
232 * @return no return value
233 */
234
235add_event_handler('register_user', 'assign_perm_for_new_user');
236
[4371]237function assign_perm_for_new_user($new_user) {
[3964]238  global $user;
239
[8956]240  if (!is_a_guest() and !is_admin()) if (
241    read_ec_conf('dup_allow') == '1' or (
242      read_ec_conf('dup_allow') == '2' and
243      dup_allowed($user['id'])
244    )
245  ) {
246    // User access
247    $result = pwg_query("
248      SELECT `cat_id`
249      FROM `".USER_ACCESS_TABLE."`
250      WHERE `user_id` = ".$user['id'].";
251    ");
252    $insert = array();
[21652]253    while ($row = pwg_db_fetch_assoc($result))
[8956]254     $insert[] = "(".$new_user['id'].",".$row['cat_id'].")";
255    if (!empty($insert)) pwg_query("
256      INSERT INTO `".USER_ACCESS_TABLE."`
257      VALUES ".implode(',', $insert).";
258    ");
[3964]259
[8956]260    // User groups
261    $result = pwg_query("
262      SELECT `group_id`
263      FROM `".USER_GROUP_TABLE."`
264      WHERE `user_id` = ".$user['id'].";
265    ");
266    $insert = array();
[21652]267    while ($row = pwg_db_fetch_assoc($result))
[8956]268     $insert[] = "(".$new_user['id'].",".$row['group_id'].")";
269    if (!empty($insert)) pwg_query("
270      INSERT INTO `".USER_GROUP_TABLE."`
271      VALUES ".implode(',', $insert).";
272    ");
[3964]273
[8956]274    // User infos
275    $result = pwg_query("
276      SELECT `level`
277      FROM `".USER_INFOS_TABLE."`
278      WHERE `user_id` = ".$user['id'].";
279    ");
280    $insert = array();
[21652]281    while ($row = pwg_db_fetch_assoc($result))
[8956]282     $insert[] = "(".$new_user['id'].",".$row['level'].")";
283    if (!empty($insert)) pwg_query("
284      UPDATE `".USER_INFOS_TABLE."`
285      SET `level` = ".$user['level']."
286      WHERE `user_id` = ".$new_user['id'].";
287    ");
[3971]288  }
[3964]289}
290
291/**
292 *
293 * duplicate_account_url()
[4553]294 * adds a link for duplicating the currently identified user in
295 * Identification block menu, in case the identifed user is granted to
296 * duplication. Displays also the connection link for generic users, if
297 * required in the configuration.
[3964]298 *
[6269]299 * ec_duplicate_prefilter
300 * is used to modify the "quick connect" block in identification menu block,
301 * so that visitors identifying themselves this way, are redirected to the
302 * page they're currently displaying, instead of home page. This
303 * functionnality has been added at version 2.1.0 in Piwigo core
304 * (see bug:1484 Redirection after quickconnect), thus it is useless to
305 * implement it from here for Piwigo versions higher or equal to 2.1.0.
306 *
[3964]307 * @param no parameter
308 * @return no return value
309 */
310
311add_event_handler('blockmanager_apply', 'duplicate_account_url');
312
[6269]313function ec_duplicate_prefilter($content, &$smarty) {
314  $search = "<legend>{'Quick connect'|@translate}</legend>";
315  $addon = '<input type="hidden" name="redirect" value="{$U_REDIRECT}">';
316  $replacement = "<legend>{'Quick connect'|@translate}</legend>".$addon;
317  return str_replace($search, $replacement, $content);
318}
319
[3971]320function duplicate_account_url() {
[4554]321  global $lang, $template, $user;
[6269]322 
[8956]323  if (version_compare(PHPWG_VERSION, '2.1.0', '<')) {
324    // Makes the "quick connect" fieldset able to redirect to current page
325    // after user identification, just as does the "connection" link.
326    $template->assign(array('U_REDIRECT' => $_SERVER['REQUEST_URI']));
327    $template->set_prefilter('menubar', 'ec_duplicate_prefilter');
328  }
329 
330  // Adds duplication link, if needed
331  if (!is_admin() and !is_a_guest()) if (
332    read_ec_conf('dup_allow') == '1' or (
333      read_ec_conf('dup_allow') == '2' and
334      dup_allowed($user['id'])
335    )
336  ) {
337    $template->assign('U_REGISTER', get_root_url().'register.php');
[4329]338    if (
[8956]339      read_ec_conf('duplic_display') == '1' or (
340        read_ec_conf('duplic_display') == '2' and
341        !is_generic()
[4329]342      )
343    ) {
[8956]344      $lang['Register'] = $lang['Duplicate'];
345      $lang['Create a new account'] =
346       $lang['Create a new account with same properties'];
[4329]347    }
[3971]348  }
[8956]349 
350  // Adds connection link, if needed
351  if (read_ec_conf('display_connection') == '1' and is_generic()) {
352    // Adds connection link
353    $template->assign(
354      'U_LOGIN',
355      get_root_url().'identification.php?redirect='.$_SERVER['REQUEST_URI']
356    );
357  }
[3964]358}
359
[4553]360add_event_handler(
361 'get_admin_plugin_menu_links',
362 array(&$obj, 'plugin_admin_menu')
363);
[3964]364set_plugin_data($plugin['id'], $obj);
365
366?>
Note: See TracBrowser for help on using the repository browser.