[3681] | 1 | <?php |
---|
| 2 | /* ----------------------------------------------------------------------------- |
---|
| 3 | Plugin : Advanced Menu Manager |
---|
| 4 | Author : Grum |
---|
[3690] | 5 | email : grum@piwigo.org |
---|
| 6 | website : http://photos.grum.fr |
---|
[3681] | 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'); |
---|
[5545] | 19 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCAjax.class.inc.php'); |
---|
[3681] | 20 | |
---|
| 21 | class AMM_PIP extends AMM_root |
---|
| 22 | { |
---|
[4382] | 23 | protected $displayRandomImageBlock=true; |
---|
[3681] | 24 | |
---|
| 25 | function AMM_PIP($prefixeTable, $filelocation) |
---|
| 26 | { |
---|
| 27 | parent::__construct($prefixeTable, $filelocation); |
---|
[5545] | 28 | $this->css = new GPCCss(dirname($this->getFileLocation()).'/'.$this->getPluginNameFiles()."2.css"); |
---|
[3681] | 29 | |
---|
[5545] | 30 | $this->loadConfig(); |
---|
| 31 | $this->initEvents(); |
---|
[3681] | 32 | } |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | /* --------------------------------------------------------------------------- |
---|
| 36 | Public classe functions |
---|
| 37 | --------------------------------------------------------------------------- */ |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | /* |
---|
| 41 | initialize events call for the plugin |
---|
| 42 | */ |
---|
[5545] | 43 | public function initEvents() |
---|
[3681] | 44 | { |
---|
| 45 | //TODELETE: add_event_handler('loc_begin_menubar', array(&$this, 'modify_menu') ); |
---|
[5545] | 46 | parent::initEvents(); |
---|
[3681] | 47 | add_event_handler('loading_lang', array(&$this, 'load_lang')); |
---|
| 48 | add_event_handler('blockmanager_apply', array(&$this, 'blockmanager_apply') ); |
---|
[5545] | 49 | add_event_handler('loc_end_page_header', array(&$this->css, 'applyCSS')); |
---|
[4363] | 50 | add_event_handler('loc_end_page_tail', array(&$this, 'applyJS')); |
---|
[3681] | 51 | } |
---|
| 52 | |
---|
| 53 | /* |
---|
| 54 | load language file |
---|
| 55 | */ |
---|
| 56 | public function load_lang() |
---|
| 57 | { |
---|
| 58 | global $lang; |
---|
| 59 | |
---|
| 60 | //load_language('plugin.lang', AMM_PATH); |
---|
| 61 | |
---|
| 62 | // ajax is managed here ; this permit to use user&language properties inside |
---|
| 63 | // ajax content |
---|
| 64 | $this->return_ajax_content(); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | public function blockmanager_apply( $menu_ref_arr ) |
---|
| 68 | { |
---|
[4382] | 69 | global $user, $page; |
---|
[3681] | 70 | $menu = & $menu_ref_arr[0]; |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | /* |
---|
| 74 | Add a new random picture section |
---|
| 75 | */ |
---|
[3683] | 76 | if ( ( ($block = $menu->get_block( 'mbAMM_randompict' ) ) != null ) && ($user['nb_total_images'] > 0) ) |
---|
[3681] | 77 | { |
---|
[5545] | 78 | $block->set_title( base64_decode($this->config['amm_randompicture_title'][$user['language']]) ); |
---|
[3690] | 79 | $block->data = array( |
---|
[5545] | 80 | "delay" => $this->config['amm_randompicture_periodicchange'], |
---|
| 81 | "blockHeight" => $this->config['amm_randompicture_height'], |
---|
[3690] | 82 | "firstPicture" => $this->ajax_amm_get_random_picture() |
---|
| 83 | ); |
---|
[3681] | 84 | $block->template = dirname(__FILE__).'/menu_templates/menubar_randompic.tpl'; |
---|
| 85 | } |
---|
[4382] | 86 | else |
---|
| 87 | { |
---|
| 88 | $this->displayRandomImageBlock=false; |
---|
| 89 | } |
---|
[3681] | 90 | |
---|
| 91 | /* |
---|
| 92 | Add a new section (links) |
---|
| 93 | */ |
---|
| 94 | if ( ($block = $menu->get_block( 'mbAMM_links' ) ) != null ) |
---|
| 95 | { |
---|
| 96 | $urls=$this->get_urls(true); |
---|
| 97 | if ( count($urls)>0 ) |
---|
| 98 | { |
---|
[5545] | 99 | if($this->config['amm_links_show_icons']=='y') |
---|
[3681] | 100 | { |
---|
| 101 | for($i=0;$i<count($urls);$i++) |
---|
| 102 | { |
---|
| 103 | $urls[$i]['icon']=get_root_url().'plugins/'.AMM_DIR."/links_pictures/".$urls[$i]['icon']; |
---|
| 104 | } |
---|
| 105 | } |
---|
| 106 | |
---|
[5545] | 107 | $block->set_title( base64_decode($this->config['amm_links_title'][$user['language']]) ); |
---|
[3681] | 108 | $block->template = dirname(__FILE__).'/menu_templates/menubar_links.tpl'; |
---|
| 109 | |
---|
| 110 | $block->data = array( |
---|
| 111 | 'LINKS' => $urls, |
---|
[5545] | 112 | 'icons' => $this->config['amm_links_show_icons'] |
---|
[3681] | 113 | ); |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | /* |
---|
| 118 | Add personnal blocks random picture section |
---|
| 119 | */ |
---|
| 120 | $sections=$this->get_sections(true); |
---|
| 121 | |
---|
| 122 | if(count($sections)) |
---|
| 123 | { |
---|
| 124 | $id_done=array(); |
---|
| 125 | foreach($sections as $key => $val) |
---|
| 126 | { |
---|
| 127 | if(!isset($id_done[$val['id']])) |
---|
| 128 | { |
---|
| 129 | if ( ($block = $menu->get_block( 'mbAMM_personalised'.$val['id'] ) ) != null ) |
---|
| 130 | { |
---|
| 131 | $block->set_title( $val['title'] ); |
---|
| 132 | $block->template = dirname(__FILE__).'/menu_templates/menubar_personalised.tpl'; |
---|
| 133 | $block->data = stripslashes($val['content']); |
---|
| 134 | } |
---|
| 135 | $id_done[$val['id']]=""; |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | |
---|
[4382] | 140 | |
---|
[4389] | 141 | /* manage items from special & menu sections |
---|
| 142 | * reordering items |
---|
| 143 | * grouping items |
---|
| 144 | * managing rights to access |
---|
[3681] | 145 | */ |
---|
[4382] | 146 | $blocks=Array(); |
---|
| 147 | |
---|
[4395] | 148 | if($menu->is_hidden('mbMenu')) |
---|
| 149 | { |
---|
| 150 | // if block is hidden, make a fake to manage AMM features |
---|
| 151 | // the fake block isn't displayed |
---|
| 152 | $blocks['menu']=new DisplayBlock('amm_mbMenu'); |
---|
| 153 | $blocks['menu']->data=Array(); |
---|
| 154 | } |
---|
| 155 | else |
---|
| 156 | { |
---|
| 157 | $blocks['menu']=$menu->get_block('mbMenu'); |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | if($menu->is_hidden('mbSpecials')) |
---|
| 161 | { |
---|
| 162 | // if block is hidden, make a fake to manage AMM features |
---|
| 163 | // the fake block isn't displayed |
---|
| 164 | $blocks['special']=new DisplayBlock('amm_mbSpecial'); |
---|
| 165 | $blocks['special']->data=Array(); |
---|
| 166 | } |
---|
| 167 | else |
---|
| 168 | { |
---|
| 169 | $blocks['special']=$menu->get_block('mbSpecials'); |
---|
| 170 | } |
---|
| 171 | |
---|
[4382] | 172 | $menuItems=array_merge($blocks['menu']->data, $blocks['special']->data); |
---|
| 173 | $this->sortSectionsItems(); |
---|
| 174 | |
---|
| 175 | $blocks['menu']->data=Array(); |
---|
| 176 | $blocks['special']->data=Array(); |
---|
| 177 | |
---|
[5545] | 178 | $users=new GPCUsers(""); |
---|
| 179 | $groups=new GPCGroups(""); |
---|
[4389] | 180 | $user_groups=$this->get_user_groups($user['id']); |
---|
| 181 | |
---|
[5545] | 182 | foreach($this->config['amm_sections_items'] as $key => $val) |
---|
[3681] | 183 | { |
---|
[4382] | 184 | if(isset($menuItems[$key])) |
---|
[3681] | 185 | { |
---|
[4389] | 186 | $access=explode("/",$val['visibility']); |
---|
[5545] | 187 | $users->setAlloweds(str_replace(",", "/", $access[0])); |
---|
| 188 | $groups->setAlloweds(str_replace(",", "/", $access[1])); |
---|
[4389] | 189 | |
---|
| 190 | /* test if user status is allowed to access the menu item |
---|
| 191 | * if access is managed by group, the user have to be associated with an allowed group to access the menu item |
---|
| 192 | */ |
---|
[5545] | 193 | if($users->isAllowed($user['status']) && ( |
---|
[4389] | 194 | ($access[1]=='') || |
---|
[5545] | 195 | (($access[1]!='') && $groups->areAllowed($user_groups))) |
---|
[4389] | 196 | ) |
---|
| 197 | { |
---|
| 198 | $blocks[$val['container']]->data[$key]=$menuItems[$key]; |
---|
| 199 | } |
---|
[3681] | 200 | } |
---|
| 201 | } |
---|
[4382] | 202 | if(count($blocks['menu']->data)==0) $menu->hide_block('mbMenu'); |
---|
| 203 | if(count($blocks['special']->data)==0) $menu->hide_block('mbSpecials'); |
---|
| 204 | } |
---|
[3681] | 205 | |
---|
[4389] | 206 | |
---|
| 207 | protected function get_user_groups($user_id) |
---|
| 208 | { |
---|
| 209 | $returned=array(); |
---|
| 210 | $sql="SELECT group_id FROM ".USER_GROUP_TABLE." |
---|
| 211 | WHERE user_id = ".$user_id." "; |
---|
| 212 | $result=pwg_query($sql); |
---|
| 213 | if($result) |
---|
| 214 | { |
---|
[5427] | 215 | while($row=pwg_db_fetch_assoc($result)) |
---|
[4389] | 216 | { |
---|
| 217 | array_push($returned, $row['group_id']); |
---|
| 218 | } |
---|
| 219 | } |
---|
| 220 | return($returned); |
---|
| 221 | } |
---|
| 222 | |
---|
[3681] | 223 | /* |
---|
| 224 | return ajax content |
---|
| 225 | */ |
---|
| 226 | protected function return_ajax_content() |
---|
| 227 | { |
---|
| 228 | global $ajax, $template; |
---|
| 229 | |
---|
| 230 | if(isset($_REQUEST['ajaxfct'])) |
---|
| 231 | { |
---|
| 232 | if($_REQUEST['ajaxfct']=='randompic') |
---|
| 233 | { |
---|
| 234 | $result="<p class='errors'>".l10n('g002_error_invalid_ajax_call')."</p>"; |
---|
| 235 | switch($_REQUEST['ajaxfct']) |
---|
| 236 | { |
---|
| 237 | case 'randompic': |
---|
| 238 | $result=$this->ajax_amm_get_random_picture(); |
---|
| 239 | break; |
---|
| 240 | } |
---|
[5545] | 241 | GPCAjax::returnResult($result); |
---|
[3681] | 242 | } |
---|
| 243 | } |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | |
---|
| 247 | // return the html content for the random picture block |
---|
| 248 | private function ajax_amm_get_random_picture() |
---|
| 249 | { |
---|
[3683] | 250 | global $user; |
---|
| 251 | |
---|
[3681] | 252 | $local_tpl = new Template(AMM_PATH."menu_templates/", ""); |
---|
| 253 | $local_tpl->set_filename('body_page', |
---|
[5545] | 254 | dirname($this->getFileLocation()).'/menu_templates/menubar_randompic_inner.tpl'); |
---|
[3681] | 255 | |
---|
| 256 | $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 |
---|
[3683] | 257 | FROM ".CATEGORIES_TABLE." c, ".IMAGES_TABLE." i, ".IMAGE_CATEGORY_TABLE." ic |
---|
| 258 | WHERE c.id = ic.category_id |
---|
| 259 | AND ic.image_id = i.id |
---|
| 260 | AND i.level <= ".$user['level']." "; |
---|
| 261 | if($user['forbidden_categories']!="") |
---|
| 262 | { |
---|
| 263 | $sql.=" AND c.id NOT IN (".$user['forbidden_categories'].") "; |
---|
| 264 | } |
---|
[3681] | 265 | |
---|
[3683] | 266 | $sql.=" ORDER BY rndvalue |
---|
| 267 | LIMIT 0,1"; |
---|
[3681] | 268 | |
---|
| 269 | |
---|
| 270 | $result = pwg_query($sql); |
---|
[5427] | 271 | if($result and $nfo = pwg_db_fetch_assoc($result)) |
---|
[3681] | 272 | { |
---|
| 273 | $nfo['section']='category'; |
---|
| 274 | $nfo['category']=array( |
---|
| 275 | 'id' => $nfo['catid'], |
---|
| 276 | 'name' => $nfo['name'], |
---|
| 277 | 'permalink' => $nfo['permalink'] |
---|
| 278 | ); |
---|
| 279 | |
---|
| 280 | $template_datas = array( |
---|
| 281 | 'LINK' => make_picture_url($nfo), |
---|
| 282 | 'IMG' => get_thumbnail_url($nfo), |
---|
| 283 | 'IMGNAME' => $nfo['imgname'], |
---|
| 284 | 'IMGCOMMENT' => $nfo['comment'], |
---|
[5545] | 285 | 'SHOWNAME' => $this->config['amm_randompicture_showname'], |
---|
| 286 | 'SHOWCOMMENT' => $this->config['amm_randompicture_showcomment'] |
---|
[3681] | 287 | ); |
---|
| 288 | } |
---|
| 289 | else |
---|
| 290 | { |
---|
| 291 | $template_datas = array(); |
---|
| 292 | } |
---|
| 293 | |
---|
| 294 | $local_tpl->assign('datas', $template_datas); |
---|
| 295 | $local_tpl->assign('plugin', array('PATH' => AMM_PATH)); |
---|
| 296 | |
---|
| 297 | return($local_tpl->parse('body_page', true)); |
---|
| 298 | } |
---|
| 299 | |
---|
[4363] | 300 | |
---|
| 301 | public function applyJS() |
---|
| 302 | { |
---|
[4499] | 303 | global $user, $template, $page; |
---|
[4363] | 304 | |
---|
[5421] | 305 | if(!array_key_exists('body_id', $page)) |
---|
| 306 | { |
---|
| 307 | /* |
---|
| 308 | * it seems the error message reported on mantis:1476 is displayed because |
---|
| 309 | * the 'body_id' doesn't exist in the $page |
---|
| 310 | * |
---|
| 311 | * not abble to reproduce the error, but initializing the key to an empty |
---|
| 312 | * value if it doesn't exist may be a sufficient solution |
---|
| 313 | */ |
---|
| 314 | $page['body_id']=""; |
---|
| 315 | } |
---|
| 316 | |
---|
[4499] | 317 | if($this->displayRandomImageBlock && $page['body_id'] == 'theCategoryPage') |
---|
[4363] | 318 | { |
---|
| 319 | $local_tpl = new Template(AMM_PATH."admin/", ""); |
---|
[5545] | 320 | $local_tpl->set_filename('body_page', dirname($this->getFileLocation()).'/menu_templates/menubar_randompic.js.tpl'); |
---|
[4363] | 321 | |
---|
| 322 | $data = array( |
---|
[5545] | 323 | "delay" => $this->config['amm_randompicture_periodicchange'], |
---|
| 324 | "blockHeight" => $this->config['amm_randompicture_height'], |
---|
[4363] | 325 | "firstPicture" => $this->ajax_amm_get_random_picture() |
---|
| 326 | ); |
---|
| 327 | |
---|
| 328 | $local_tpl->assign('data', $data); |
---|
| 329 | |
---|
| 330 | $template->append('footer_elements', $local_tpl->parse('body_page', true)); |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | } |
---|
| 334 | |
---|
[3681] | 335 | } // AMM_PIP class |
---|
| 336 | |
---|
| 337 | |
---|
| 338 | ?> |
---|