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

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

[Event Cats] Add "Event Cats" fieldset in admin category modification page ;
modify header information about developpement period of all files

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