source: extensions/AdminTools/include/events.inc.php @ 25979

Last change on this file since 25979 was 25979, checked in by mistic100, 10 years ago

remove useless SQL queries, don't change user on admin pages, fix theme and language overwrites, fix toolbar overlap, colorbox max width

File size: 7.7 KB
RevLine 
[25617]1<?php
2defined('ADMINTOOLS_PATH') or die('Hacking attempt!');
3
[25655]4/**
5 * Add main toolbar to current page
6 * @trigger loc_after_page_header
7 */
[25617]8function admintools_add_public_controller()
9{
[25845]10  global $MultiView, $conf, $template, $page, $user, $picture;
[25617]11
[25915]12  if (script_basename() == 'picture' and empty($picture['current']))
13  {
14    return;
15  }
16
[25845]17  $url_root = get_root_url();
18  $tpl_vars = array();
19
20  if ($MultiView->is_admin())
21  { // full options for admin
22    $tpl_vars['U_SITE_ADMIN'] =     $url_root . 'admin.php?page=';
23    $tpl_vars['MULTIVIEW'] =        $MultiView->get_data();
24    $tpl_vars['USER'] =             $MultiView->get_user();
25    $tpl_vars['CURRENT_USERNAME'] = $user['id']==$conf['guest_id'] ? l10n('guest') : $user['username'];
26    $tpl_vars['DELETE_CACHE'] =     isset($conf['multiview_invalidate_cache']);
27
[25979]28    if (($admin_lang = $MultiView->get_user_language()) !== false)
29    {
30      include_once(PHPWG_ROOT_PATH . 'include/functions_mail.inc.php');
31      switch_lang_to($admin_lang);
32    }
[25845]33  }
34  else if (script_basename() == 'picture' and $picture['current']['added_by'] == $user['id'])
35  { // only "edit" button for photo owner
36  }
37  else
[25617]38  {
39    return;
40  }
41
[25845]42  $tpl_vars['U_SELF'] = $MultiView->get_clean_url(true);
[25617]43
[25845]44  // photo page
[25617]45  if (script_basename() == 'picture')
46  {
47    $url_self = duplicate_picture_url();
48    $tpl_vars['IS_PICTURE'] = true;
49
[25845]50    // admin can add to caddie and set representattive
51    if ($MultiView->is_admin())
52    {
53      $template->clear_assign(array(
54        'U_SET_AS_REPRESENTATIVE',
55        'U_PHOTO_ADMIN',
56        'U_CADDIE',
57        ));
[25617]58
[25845]59      $template->set_prefilter('picture', 'admintools_remove_privacy');
[25654]60
[25845]61      $tpl_vars['U_CADDIE'] = add_url_params(
62        $url_self,
63        array('action'=>'add_to_caddie')
64        );
65
66      $query = '
[25675]67SELECT element_id FROM ' . CADDIE_TABLE . '
68  WHERE element_id = ' . $page['image_id'] .'
69;';
[25845]70      $tpl_vars['IS_IN_CADDIE'] = pwg_db_num_rows(pwg_query($query)) > 0;
[25629]71
[25845]72      if (isset($page['category']))
73      {
74        $tpl_vars['CATEGORY_ID'] = $page['category']['id'];
[25629]75
[25845]76        $tpl_vars['U_SET_REPRESENTATIVE'] = add_url_params(
77          $url_self,
78          array('action'=>'set_as_representative')
79          );
[25629]80
[25979]81        $tpl_vars['IS_REPRESENTATIVE'] = $page['category']['representative_picture_id'] == $page['image_id'];
[25845]82      }
83
84      $tpl_vars['U_ADMIN_EDIT'] = $url_root . 'admin.php?page=photo-' . $page['image_id']
85        .(isset($page['category']) ? '&amp;cat_id=' . $page['category']['id'] : '');
[25617]86    }
87
[25845]88    $tpl_vars['U_DELETE'] = add_url_params(
89      $url_self, array(
90        'delete'=>'',
91        'pwg_token'=>get_pwg_token()
92        )
[25617]93      );
[25654]94
[25817]95    // gets tags (full available list is loaded in ajax)
[25845]96    include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php');
97
[25654]98    $query = '
99SELECT id, name
100  FROM '.IMAGE_TAG_TABLE.' AS it
101    JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id
102  WHERE image_id = '.$page['image_id'].'
103;';
104    $tag_selection = get_taglist($query);
105
106    $tpl_vars['QUICK_EDIT'] = array(
[25791]107      'img' =>                $picture['current']['derivatives']['square']->get_url(),
[25675]108      'name' =>               $picture['current']['name'],
109      'comment' =>            $picture['current']['comment'],
110      'author' =>             $picture['current']['author'],
111      'level' =>              $picture['current']['level'],
112      'date_creation' =>      substr($picture['current']['date_creation'], 0, 10),
[25654]113      'date_creation_time' => substr($picture['current']['date_creation'], 11, 5),
[25675]114      'tag_selection' =>      $tag_selection,
[25654]115      );
[25617]116  }
[25845]117  // album page (admin only)
118  else if ($MultiView->is_admin() and @$page['section'] == 'categories' and isset($page['category']))
[25617]119  {
120    $url_self = duplicate_index_url();
121
122    $tpl_vars['IS_CATEGORY'] = true;
123    $tpl_vars['CATEGORY_ID'] = $page['category']['id'];
124
125    $template->clear_assign(array(
126      'U_EDIT',
127      'U_CADDIE',
128      ));
129
[25845]130    $tpl_vars['U_ADMIN_EDIT'] = $url_root . 'admin.php?page=album-' . $page['category']['id'];
[25617]131
132    if (!empty($page['items']))
133    {
134      $tpl_vars['U_CADDIE'] = add_url_params(
135        $url_self,
136        array('caddie'=>1)
137        );
138    }
[25655]139
[25791]140    $tpl_vars['QUICK_EDIT'] = array(
141      'img' =>      null,
142      'name' =>     $page['category']['name'],
143      'comment' =>  $page['category']['comment'],
144      );
145
146    if (!empty($page['category']['representative_picture_id']))
147    {
148      $query = '
[25675]149SELECT * FROM '.IMAGES_TABLE.'
150  WHERE id = '. $page['category']['representative_picture_id'] .'
151;';
[25791]152      $image_infos = pwg_db_fetch_assoc(pwg_query($query));
[25655]153
[25791]154      $tpl_vars['QUICK_EDIT']['img'] = DerivativeImage::get_one(IMG_SQUARE, $image_infos)->get_url();
155    }
[25617]156  }
157
158
159  $template->assign(array(
[25916]160    'ADMINTOOLS_PATH' => './plugins/' . ADMINTOOLS_ID .'/',
[25617]161    'ato' => $tpl_vars,
162  ));
163
[25675]164  $template->set_filename('ato_public_controller', realpath(ADMINTOOLS_PATH . 'template/public_controller.tpl'));
165  $template->parse('ato_public_controller');
[25655]166
[25979]167  if ($MultiView->is_admin() && @$admin_lang !== false)
[25845]168  {
169    switch_lang_back();
170  }
[25654]171}
172
[25655]173/**
174 * Disable privacy level switchbox
175 */
[25654]176function admintools_remove_privacy($content)
177{
178  $search = '{if $display_info.privacy_level and isset($available_permission_levels)}';
179  $replace = '{if false}';
180  return str_replace($search, $replace, $content);
181}
182
[25655]183/**
184 * Save picture form
185 * @trigger loc_begin_picture
186 */
[25654]187function admintools_save_picture()
188{
[25845]189  global $page, $conf, $MultiView, $user, $picture;
[25654]190
[25916]191  if (!isset($_GET['delete']) and !isset($_POST['action']) and @$_POST['action'] != 'quick_edit')
[25915]192  {
193    return;
194  }
195
[25845]196  $query = 'SELECT added_by FROM '. IMAGES_TABLE .' WHERE id = '. $page['image_id'] .';';
197  list($added_by) = pwg_db_fetch_row(pwg_query($query));
198
[25915]199  if (!$MultiView->is_admin() and $user['id'] != $added_by)
[25791]200  {
201    return;
202  }
203
[25654]204  if (isset($_GET['delete']) and get_pwg_token()==@$_GET['pwg_token'])
205  {
206    include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php');
207
208    delete_elements(array($page['image_id']), true);
209    invalidate_user_cache();
210
211    if (isset($page['category']))
212    {
213      redirect(
214        make_index_url(
215          array(
216            'category' => $page['category']
217            )
218          )
219        );
220    }
221
222    redirect(make_index_url());
223  }
224
[25915]225  if ($_POST['action'] == 'quick_edit')
[25654]226  {
227    include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php');
228
229    $data = array(
[25675]230      'name' =>   $_POST['name'],
[25654]231      'author' => $_POST['author'],
232      );
233
[25845]234    if ($MultiView->is_admin())
235    {
236      $data['level'] = $_POST['level'];
237    }
238
[25654]239    if ($conf['allow_html_descriptions'])
240    {
241      $data['comment'] = @$_POST['comment'];
242    }
243    else
244    {
245      $data['comment'] = strip_tags(@$_POST['comment']);
246    }
247
248    if (!empty($_POST['date_creation']) and strtotime($_POST['date_creation']) !== false)
249    {
250      $data['date_creation'] = $_POST['date_creation'] .' '. $_POST['date_creation_time'];
251    }
252
253    single_update(
254      IMAGES_TABLE,
255      $data,
256      array('id' => $page['image_id'])
257      );
258
259    $tag_ids = array();
260    if (!empty($_POST['tags']))
261    {
262      $tag_ids = get_tag_ids($_POST['tags']);
263    }
264    set_tags($tag_ids, $page['image_id']);
265  }
[25655]266}
267
268/**
269 * Save category form
270 * @trigger loc_begin_index
271 */
272function admintools_save_category()
273{
[25791]274  global $page, $conf, $MultiView;
275
276  if (!$MultiView->is_admin())
277  {
278    return;
279  }
[25845]280
[25655]281  if (@$_POST['action'] == 'quick_edit')
282  {
283    $data = array(
284      'name' => $_POST['name'],
285      );
286
287    if ($conf['allow_html_descriptions'])
288    {
289      $data['comment'] = @$_POST['comment'];
290    }
291    else
292    {
293      $data['comment'] = strip_tags(@$_POST['comment']);
294    }
295
296    single_update(
297      CATEGORIES_TABLE,
298      $data,
299      array('id' => $page['category']['id'])
300      );
[25845]301
[25655]302    redirect(duplicate_index_url());
303  }
[25617]304}
Note: See TracBrowser for help on using the repository browser.