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

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

[Event Cats] Simplify language loading

(See http://code.piwigo.org/issues/show/1248 )

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