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

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

[Event Cats] Better help banner example : some examples

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