source: extensions/UserCollections/include/events.inc.php @ 17657

Last change on this file since 17657 was 17657, checked in by mistic100, 8 years ago

consolidate upgrade process, remote filter_var function (PHP 5.2)

File size: 7.0 KB
Line 
1<?php
2defined('USER_COLLEC_PATH') or die('Hacking attempt!');
3
4# this file contains all functions directly called by the triggers #
5
6
7/* define page section from url */
8function user_collections_section_init()
9{
10  global $tokens, $page, $conf;
11
12  if ($tokens[0] == 'collections')
13  {
14    $page['section'] = 'collections';
15    $page['title'] = '<a href="'.get_absolute_root_url().'">'.l10n('Home').'</a>'.$conf['level_separator'].'<a href="'.USER_COLLEC_PUBLIC.'">'.l10n('Collections').'</a>';
16   
17    if (in_array(@$tokens[1], array('edit','view','list')))
18    {
19       $page['sub_section'] = $tokens[1];
20    }
21    else
22    {
23      $page['sub_section'] = 'list';
24    }
25   
26    if (!empty($tokens[2]))
27    {
28      $page['col_id'] = $tokens[2];
29    }
30  }
31}
32
33/* collections section */
34function user_collections_page()
35{
36  global $page;
37
38  if (isset($page['section']) and $page['section'] == 'collections')
39  {
40    include(USER_COLLEC_PATH . '/include/collections.inc.php');
41  }
42}
43
44
45/* add buttons on thumbnails list */
46function user_collections_index_actions()
47{
48  if (is_a_guest()) return;
49 
50  global $page, $UserCollection;
51     
52  // add image to collection list
53  if ( isset($_GET['collection_toggle']) and  preg_match('#^[0-9]+$#', $_GET['collection_toggle']) )
54  {
55    if (empty($UserCollection))
56    {
57      $UserCollection = new UserCollection(get_current_collection_id(true));
58    }
59    $UserCollection->toggleImage($_GET['collection_toggle']);
60    redirect(duplicate_index_url(array(), array('collection_toggle')));
61  }
62}
63
64function user_collections_thumbnails_list($tpl_thumbnails_var, $pictures)
65{
66  if (is_a_guest()) return $tpl_thumbnails_var;
67 
68  global $page, $template, $UserCollection;
69 
70  // the prefilter is different on collection page
71  if (isset($page['section']) and ($page['section'] == 'collections' or $page['section'] == 'download')) return $tpl_thumbnails_var;
72 
73  // get existing collections
74  $col_id = get_current_collection_id(false);
75  if (empty($UserCollection) and $col_id !== false)
76  {
77    $UserCollection = new UserCollection($col_id);
78    $collection = $UserCollection->getImages();
79  }
80  else if (!empty($UserCollection))
81  {
82    $collection = $UserCollection->getImages();
83  }
84  else
85  {
86    $collection = array();
87  }
88 
89  // if the collection is created we don't use AJAX to force menu refresh
90  if ($col_id === false)
91  {
92    $template->assign('NO_AJAX', true);
93  }
94 
95 
96  $self_url = duplicate_index_url(array(), array('collection_toggle')); 
97 
98  foreach ($tpl_thumbnails_var as &$thumbnail)
99  {
100    if (in_array($thumbnail['id'], $collection))
101    {
102      $thumbnail['COLLECTION_SELECTED'] = true;
103    }
104  }
105  unset($thumbnail);
106 
107  // thumbnails buttons
108  $template->assign(array(
109    'USER_COLLEC_PATH' => USER_COLLEC_PATH,
110    'collection_toggle_url' =>  add_url_params($self_url, array('collection_toggle'=>'')),
111    ));
112  $template->set_prefilter('index_thumbnails', 'user_collections_thumbnails_list_prefilter');
113 
114  return $tpl_thumbnails_var;
115}
116
117function user_collections_thumbnails_list_prefilter($content, &$smarty)
118{
119  // add links
120  $search = '<span class="wrap1">';
121  $replace = $search.'
122{strip}<a class="addCollection" href="{$collection_toggle_url}{$thumbnail.id}" data-id="{$thumbnail.id}" rel="nofollow">
123{if $COL_ID or $thumbnail.COLLECTION_SELECTED}
124{\'Remove from collection\'|@translate}&nbsp;<img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/image_delete.png" title="{\'Remove from collection\'|@translate}">
125{else}
126{\'Add to collection\'|@translate}&nbsp;<img src="{$ROOT_URL}{$USER_COLLEC_PATH}template/image_add.png" title="{\'Add to collection\'|@translate}">
127{/if}
128</a>{/strip}';
129
130  // custom CSS and AJAX request
131  $content.= file_get_contents(USER_COLLEC_PATH.'template/thumbnails_css_js.tpl');
132
133  return str_replace($search, $replace, $content);
134}
135
136
137/* add button on picture page */
138function user_collections_picture_page()
139{
140  if (is_a_guest()) return;
141 
142  global $template, $picture, $UserCollection;
143 
144  // add image to collection list
145  if ( isset($_GET['action']) and $_GET['action'] == 'collection_toggle' )
146  {
147    if (empty($UserCollection))
148    {
149      $UserCollection = new UserCollection(get_current_collection_id(true));
150    }
151   
152    $UserCollection->toggleImage($picture['current']['id']);
153    redirect(duplicate_picture_url());
154  }
155 
156  // get existing collection
157  if (empty($UserCollection) and ($col_id = get_current_collection_id(false)) !== false)
158  {
159    $UserCollection = new UserCollection($col_id);
160    $collection = $UserCollection->isInSet($picture['current']['id']);
161  }
162  else if (!empty($UserCollection))
163  {
164    $collection = $UserCollection->isInSet($picture['current']['id']);
165  }
166  else
167  {
168    $collection = false;
169  } 
170 
171  $url = add_url_params(duplicate_picture_url(), array('action'=>'collection_toggle'));   
172 
173  $button = '
174<a href="'.$url.'" title="'.($collection?l10n('Remove from collection'):l10n('Add to collection')).'" class="pwg-state-default pwg-button" rel="nofollow">
175  <span class="pwg-icon" style="background:url(\''.get_root_url().USER_COLLEC_PATH.'template/image_'.($collection?'delete':'add').'.png\') center center no-repeat;"> </span>
176  <span class="pwg-button-text">'.($collection?l10n('Remove from collection'):l10n('Add to collection')).'</span>
177</a>';
178  // $template->add_picture_button($button, 50);
179  $template->concat('PLUGIN_PICTURE_ACTIONS', $button);
180}
181
182
183/* menu block */
184function user_collections_add_menublock($menu_ref_arr)
185{
186  if (is_a_guest()) return;
187 
188  $menu = &$menu_ref_arr[0];
189  if ($menu->get_id() != 'menubar') return;
190   
191  $menu->register_block(new RegisteredBlock('mbUserCollection', l10n('Collections'), 'UserCollection'));
192}
193
194function user_collections_applymenu($menu_ref_arr)
195{
196  $max = 6;
197 
198  global $template, $conf, $user, $UserCollection;
199  $menu = &$menu_ref_arr[0];
200 
201  if (($block = $menu->get_block('mbUserCollection')) != null)
202  {
203    $query = '
204SELECT *
205  FROM '.COLLECTIONS_TABLE.'
206  WHERE user_id = '.$user['id'].'
207  ORDER BY
208    active DESC,
209    date_creation DESC
210;';
211    $collections = array_values(hash_from_query($query, 'id'));
212   
213    $data['collections'] = array();
214    for ($i=0; $i<$max && $i<count($collections); $i++)
215    {
216      $collections[$i]['U_EDIT'] = USER_COLLEC_PUBLIC.'edit/'.$collections[$i]['id'];
217      array_push($data['collections'], $collections[$i]);
218    }
219   
220    $data['NB_COL'] = count($collections);
221    if ($data['NB_COL'] > $max)
222    {
223      $data['MORE'] = count($collections)-$max;
224    }
225   
226    $data['U_LIST'] = USER_COLLEC_PUBLIC;
227    $data['U_CREATE'] = add_url_params(USER_COLLEC_PUBLIC, array('action'=>'new','col_id'=>'0','redirect'=>'true'));
228   
229    $template->set_template_dir(USER_COLLEC_PATH . 'template/');
230    $block->set_title('<a href="'.USER_COLLEC_PUBLIC.'">'.l10n('Collections').'</a>');
231    $block->template = 'menublock_user_collec.tpl';
232    $block->data = $data;
233  }
234}
235
236?>
Note: See TracBrowser for help on using the repository browser.