1 | <?php |
---|
2 | /* ----------------------------------------------------------------------------- |
---|
3 | Plugin : Advanced Menu Manager |
---|
4 | Author : Grum |
---|
5 | email : grum@piwigo.org |
---|
6 | website : http://photos.grum.fr |
---|
7 | PWG user : http://forum.phpwebgallery.net/profile.php?id=3706 |
---|
8 | |
---|
9 | << May the Little SpaceFrog be with you ! >> |
---|
10 | ------------------------------------------------------------------------------ |
---|
11 | See main.inc.php for release information |
---|
12 | |
---|
13 | PIP classe => manage integration in public interface |
---|
14 | |
---|
15 | --------------------------------------------------------------------------- */ |
---|
16 | if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } |
---|
17 | |
---|
18 | include_once(PHPWG_PLUGINS_PATH.'AMenuManager/amm_root.class.inc.php'); |
---|
19 | include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/ajax.class.inc.php'); |
---|
20 | |
---|
21 | class AMM_PIP extends AMM_root |
---|
22 | { |
---|
23 | protected $ajax; |
---|
24 | protected $displayRandomImageBlock=true; |
---|
25 | |
---|
26 | function AMM_PIP($prefixeTable, $filelocation) |
---|
27 | { |
---|
28 | parent::__construct($prefixeTable, $filelocation); |
---|
29 | $this->ajax = new Ajax(); |
---|
30 | $this->css = new css(dirname($this->filelocation).'/'.$this->plugin_name_files."2.css"); |
---|
31 | |
---|
32 | $this->load_config(); |
---|
33 | $this->init_events(); |
---|
34 | } |
---|
35 | |
---|
36 | |
---|
37 | /* --------------------------------------------------------------------------- |
---|
38 | Public classe functions |
---|
39 | --------------------------------------------------------------------------- */ |
---|
40 | |
---|
41 | |
---|
42 | /* |
---|
43 | initialize events call for the plugin |
---|
44 | */ |
---|
45 | public function init_events() |
---|
46 | { |
---|
47 | //TODELETE: add_event_handler('loc_begin_menubar', array(&$this, 'modify_menu') ); |
---|
48 | parent::init_events(); |
---|
49 | add_event_handler('loading_lang', array(&$this, 'load_lang')); |
---|
50 | add_event_handler('blockmanager_apply', array(&$this, 'blockmanager_apply') ); |
---|
51 | add_event_handler('loc_end_page_header', array(&$this->css, 'apply_CSS')); |
---|
52 | add_event_handler('loc_end_page_tail', array(&$this, 'applyJS')); |
---|
53 | } |
---|
54 | |
---|
55 | /* |
---|
56 | load language file |
---|
57 | */ |
---|
58 | public function load_lang() |
---|
59 | { |
---|
60 | global $lang; |
---|
61 | |
---|
62 | //load_language('plugin.lang', AMM_PATH); |
---|
63 | |
---|
64 | // ajax is managed here ; this permit to use user&language properties inside |
---|
65 | // ajax content |
---|
66 | $this->return_ajax_content(); |
---|
67 | } |
---|
68 | |
---|
69 | public function blockmanager_apply( $menu_ref_arr ) |
---|
70 | { |
---|
71 | global $user, $page; |
---|
72 | $menu = & $menu_ref_arr[0]; |
---|
73 | |
---|
74 | |
---|
75 | /* |
---|
76 | Add a new random picture section |
---|
77 | */ |
---|
78 | if ( ( ($block = $menu->get_block( 'mbAMM_randompict' ) ) != null ) && ($user['nb_total_images'] > 0) ) |
---|
79 | { |
---|
80 | $block->set_title( base64_decode($this->my_config['amm_randompicture_title'][$user['language']]) ); |
---|
81 | $block->data = array( |
---|
82 | "delay" => $this->my_config['amm_randompicture_periodicchange'], |
---|
83 | "blockHeight" => $this->my_config['amm_randompicture_height'], |
---|
84 | "firstPicture" => $this->ajax_amm_get_random_picture() |
---|
85 | ); |
---|
86 | $block->template = dirname(__FILE__).'/menu_templates/menubar_randompic.tpl'; |
---|
87 | } |
---|
88 | else |
---|
89 | { |
---|
90 | $this->displayRandomImageBlock=false; |
---|
91 | } |
---|
92 | |
---|
93 | /* |
---|
94 | Add a new section (links) |
---|
95 | */ |
---|
96 | if ( ($block = $menu->get_block( 'mbAMM_links' ) ) != null ) |
---|
97 | { |
---|
98 | $urls=$this->get_urls(true); |
---|
99 | if ( count($urls)>0 ) |
---|
100 | { |
---|
101 | if($this->my_config['amm_links_show_icons']=='y') |
---|
102 | { |
---|
103 | for($i=0;$i<count($urls);$i++) |
---|
104 | { |
---|
105 | $urls[$i]['icon']=get_root_url().'plugins/'.AMM_DIR."/links_pictures/".$urls[$i]['icon']; |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | $block->set_title( base64_decode($this->my_config['amm_links_title'][$user['language']]) ); |
---|
110 | $block->template = dirname(__FILE__).'/menu_templates/menubar_links.tpl'; |
---|
111 | |
---|
112 | $block->data = array( |
---|
113 | 'LINKS' => $urls, |
---|
114 | 'icons' => $this->my_config['amm_links_show_icons'] |
---|
115 | ); |
---|
116 | } |
---|
117 | } |
---|
118 | |
---|
119 | /* |
---|
120 | Add personnal blocks random picture section |
---|
121 | */ |
---|
122 | $sections=$this->get_sections(true); |
---|
123 | |
---|
124 | if(count($sections)) |
---|
125 | { |
---|
126 | $id_done=array(); |
---|
127 | foreach($sections as $key => $val) |
---|
128 | { |
---|
129 | if(!isset($id_done[$val['id']])) |
---|
130 | { |
---|
131 | if ( ($block = $menu->get_block( 'mbAMM_personalised'.$val['id'] ) ) != null ) |
---|
132 | { |
---|
133 | $block->set_title( $val['title'] ); |
---|
134 | $block->template = dirname(__FILE__).'/menu_templates/menubar_personalised.tpl'; |
---|
135 | $block->data = stripslashes($val['content']); |
---|
136 | } |
---|
137 | $id_done[$val['id']]=""; |
---|
138 | } |
---|
139 | } |
---|
140 | } |
---|
141 | |
---|
142 | |
---|
143 | /* manage items from special & menu sections |
---|
144 | * reordering items |
---|
145 | * grouping items |
---|
146 | * managing rights to access |
---|
147 | */ |
---|
148 | $blocks=Array(); |
---|
149 | $blocks['menu']=$menu->get_block('mbMenu'); |
---|
150 | $blocks['special']=$menu->get_block('mbSpecials'); |
---|
151 | |
---|
152 | $menuItems=array_merge($blocks['menu']->data, $blocks['special']->data); |
---|
153 | $this->sortSectionsItems(); |
---|
154 | |
---|
155 | $blocks['menu']->data=Array(); |
---|
156 | $blocks['special']->data=Array(); |
---|
157 | |
---|
158 | $users=new users(""); |
---|
159 | $groups=new groups(""); |
---|
160 | $user_groups=$this->get_user_groups($user['id']); |
---|
161 | |
---|
162 | foreach($this->my_config['amm_sections_items'] as $key => $val) |
---|
163 | { |
---|
164 | if(isset($menuItems[$key])) |
---|
165 | { |
---|
166 | $access=explode("/",$val['visibility']); |
---|
167 | $users->set_alloweds(str_replace(",", "/", $access[0])); |
---|
168 | $groups->set_alloweds(str_replace(",", "/", $access[1])); |
---|
169 | |
---|
170 | /* test if user status is allowed to access the menu item |
---|
171 | * if access is managed by group, the user have to be associated with an allowed group to access the menu item |
---|
172 | */ |
---|
173 | if($users->is_allowed($user['status']) && ( |
---|
174 | ($access[1]=='') || |
---|
175 | (($access[1]!='') && $groups->are_allowed($user_groups))) |
---|
176 | ) |
---|
177 | { |
---|
178 | $blocks[$val['container']]->data[$key]=$menuItems[$key]; |
---|
179 | } |
---|
180 | } |
---|
181 | } |
---|
182 | if(count($blocks['menu']->data)==0) $menu->hide_block('mbMenu'); |
---|
183 | if(count($blocks['special']->data)==0) $menu->hide_block('mbSpecials'); |
---|
184 | } |
---|
185 | |
---|
186 | |
---|
187 | protected function get_user_groups($user_id) |
---|
188 | { |
---|
189 | $returned=array(); |
---|
190 | $sql="SELECT group_id FROM ".USER_GROUP_TABLE." |
---|
191 | WHERE user_id = ".$user_id." "; |
---|
192 | $result=pwg_query($sql); |
---|
193 | if($result) |
---|
194 | { |
---|
195 | while($row=mysql_fetch_assoc($result)) |
---|
196 | { |
---|
197 | array_push($returned, $row['group_id']); |
---|
198 | } |
---|
199 | } |
---|
200 | return($returned); |
---|
201 | } |
---|
202 | |
---|
203 | /* |
---|
204 | return ajax content |
---|
205 | */ |
---|
206 | protected function return_ajax_content() |
---|
207 | { |
---|
208 | global $ajax, $template; |
---|
209 | |
---|
210 | if(isset($_REQUEST['ajaxfct'])) |
---|
211 | { |
---|
212 | if($_REQUEST['ajaxfct']=='randompic') |
---|
213 | { |
---|
214 | $result="<p class='errors'>".l10n('g002_error_invalid_ajax_call')."</p>"; |
---|
215 | switch($_REQUEST['ajaxfct']) |
---|
216 | { |
---|
217 | case 'randompic': |
---|
218 | $result=$this->ajax_amm_get_random_picture(); |
---|
219 | break; |
---|
220 | } |
---|
221 | $this->ajax->return_result($result); |
---|
222 | } |
---|
223 | } |
---|
224 | } |
---|
225 | |
---|
226 | |
---|
227 | // return the html content for the random picture block |
---|
228 | private function ajax_amm_get_random_picture() |
---|
229 | { |
---|
230 | global $user; |
---|
231 | |
---|
232 | $local_tpl = new Template(AMM_PATH."menu_templates/", ""); |
---|
233 | $local_tpl->set_filename('body_page', |
---|
234 | dirname($this->filelocation).'/menu_templates/menubar_randompic_inner.tpl'); |
---|
235 | |
---|
236 | $sql="SELECT i.id as image_id, i.file as image_file, i.comment, i.path, i.tn_ext, c.id as catid, c.name, c.permalink, RAND() as rndvalue, i.name as imgname |
---|
237 | FROM ".CATEGORIES_TABLE." c, ".IMAGES_TABLE." i, ".IMAGE_CATEGORY_TABLE." ic |
---|
238 | WHERE c.id = ic.category_id |
---|
239 | AND ic.image_id = i.id |
---|
240 | AND i.level <= ".$user['level']." "; |
---|
241 | if($user['forbidden_categories']!="") |
---|
242 | { |
---|
243 | $sql.=" AND c.id NOT IN (".$user['forbidden_categories'].") "; |
---|
244 | } |
---|
245 | |
---|
246 | $sql.=" ORDER BY rndvalue |
---|
247 | LIMIT 0,1"; |
---|
248 | |
---|
249 | |
---|
250 | $result = pwg_query($sql); |
---|
251 | if($result and $nfo = mysql_fetch_array($result)) |
---|
252 | { |
---|
253 | $nfo['section']='category'; |
---|
254 | $nfo['category']=array( |
---|
255 | 'id' => $nfo['catid'], |
---|
256 | 'name' => $nfo['name'], |
---|
257 | 'permalink' => $nfo['permalink'] |
---|
258 | ); |
---|
259 | |
---|
260 | $template_datas = array( |
---|
261 | 'LINK' => make_picture_url($nfo), |
---|
262 | 'IMG' => get_thumbnail_url($nfo), |
---|
263 | 'IMGNAME' => $nfo['imgname'], |
---|
264 | 'IMGCOMMENT' => $nfo['comment'], |
---|
265 | 'SHOWNAME' => $this->my_config['amm_randompicture_showname'], |
---|
266 | 'SHOWCOMMENT' => $this->my_config['amm_randompicture_showcomment'] |
---|
267 | ); |
---|
268 | } |
---|
269 | else |
---|
270 | { |
---|
271 | $template_datas = array(); |
---|
272 | } |
---|
273 | |
---|
274 | $local_tpl->assign('datas', $template_datas); |
---|
275 | $local_tpl->assign('plugin', array('PATH' => AMM_PATH)); |
---|
276 | |
---|
277 | return($local_tpl->parse('body_page', true)); |
---|
278 | } |
---|
279 | |
---|
280 | |
---|
281 | public function applyJS() |
---|
282 | { |
---|
283 | global $user, $template; |
---|
284 | |
---|
285 | if($this->displayRandomImageBlock) |
---|
286 | { |
---|
287 | $local_tpl = new Template(AMM_PATH."admin/", ""); |
---|
288 | $local_tpl->set_filename('body_page', dirname($this->filelocation).'/menu_templates/menubar_randompic.js.tpl'); |
---|
289 | |
---|
290 | $data = array( |
---|
291 | "delay" => $this->my_config['amm_randompicture_periodicchange'], |
---|
292 | "blockHeight" => $this->my_config['amm_randompicture_height'], |
---|
293 | "firstPicture" => $this->ajax_amm_get_random_picture() |
---|
294 | ); |
---|
295 | |
---|
296 | $local_tpl->assign('data', $data); |
---|
297 | |
---|
298 | $template->append('footer_elements', $local_tpl->parse('body_page', true)); |
---|
299 | } |
---|
300 | |
---|
301 | } |
---|
302 | |
---|
303 | } // AMM_PIP class |
---|
304 | |
---|
305 | |
---|
306 | ?> |
---|