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

Last change on this file since 16698 was 16698, checked in by mistic100, 12 years ago

-update menu when the temp collection is created
-update BatchDownloader confirmation message

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