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

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

first commit

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