From abb2f22b2e96a89a44ad9d36db3bf612c6f88b9f Mon Sep 17 00:00:00 2001 From: rvelices Date: Thu, 28 Aug 2008 00:32:39 +0000 Subject: - based on test_menu by grum (thanks to you) - integration of dynamic menu bar to pwg - the menubar is composed now of dynamic blocks that can be ordered/hidden - plugins can add their own blocks git-svn-id: http://piwigo.org/svn/trunk@2488 68402e56-0260-453c-a942-63ccdbb3a9ee --- plugins/AMenuManager/admin/amm_linksconfig.tpl | 9 -- plugins/AMenuManager/admin/amm_randompicconfig.tpl | 9 -- plugins/AMenuManager/amm_aim.class.inc.php | 1 + plugins/AMenuManager/amm_aip.class.inc.php | 26 +---- plugins/AMenuManager/amm_install.class.inc.php | 6 +- plugins/AMenuManager/amm_pip.class.inc.php | 113 ++++++++++----------- plugins/AMenuManager/amm_root.class.inc.php | 62 ++++++----- plugins/AMenuManager/main.inc.php | 4 +- plugins/AMenuManager/maintain.inc.php | 25 ++--- .../AMenuManager/menu_templates/menubar_links.tpl | 10 +- .../menu_templates/menubar_personalised.tpl | 6 +- .../menu_templates/menubar_randompic.tpl | 14 ++- 12 files changed, 118 insertions(+), 167 deletions(-) (limited to 'plugins/AMenuManager') diff --git a/plugins/AMenuManager/admin/amm_linksconfig.tpl b/plugins/AMenuManager/admin/amm_linksconfig.tpl index 25e6d75cc..4bce937fc 100644 --- a/plugins/AMenuManager/admin/amm_linksconfig.tpl +++ b/plugins/AMenuManager/admin/amm_linksconfig.tpl @@ -65,15 +65,6 @@ {/if} - - - - -
{'g002_setting_block_active'|@translate} - -
{'g002_setting_block_title'|@translate} diff --git a/plugins/AMenuManager/admin/amm_randompicconfig.tpl b/plugins/AMenuManager/admin/amm_randompicconfig.tpl index df70311f0..b910c2f1c 100644 --- a/plugins/AMenuManager/admin/amm_randompicconfig.tpl +++ b/plugins/AMenuManager/admin/amm_randompicconfig.tpl @@ -65,15 +65,6 @@ {/if} - - - - -
{'g002_setting_block_active'|@translate} - -
{'g002_setting_block_title'|@translate} diff --git a/plugins/AMenuManager/amm_aim.class.inc.php b/plugins/AMenuManager/amm_aim.class.inc.php index 0556fd6b1..e100020d4 100755 --- a/plugins/AMenuManager/amm_aim.class.inc.php +++ b/plugins/AMenuManager/amm_aim.class.inc.php @@ -30,6 +30,7 @@ class AMM_AIM extends AMM_root */ function init_events() { + parent::init_events(); add_event_handler('get_admin_plugin_menu_links', array(&$this, 'plugin_admin_menu') ); } diff --git a/plugins/AMenuManager/amm_aip.class.inc.php b/plugins/AMenuManager/amm_aip.class.inc.php index 9fd5ce1cb..5481fd030 100755 --- a/plugins/AMenuManager/amm_aip.class.inc.php +++ b/plugins/AMenuManager/amm_aip.class.inc.php @@ -189,7 +189,6 @@ class AMM_AIP extends AMM_root */ public function init_events() { - add_event_handler('menubar_file', array(&$this, 'plugin_public_menu') ); add_event_handler('loc_end_page_header', array(&$this->css, 'apply_CSS')); } @@ -237,10 +236,10 @@ class AMM_AIP extends AMM_root break; case 'setmenu_modspecial_sections_list': - $result=$this->ajax_amm_setmenu_mod_section_list('amm_sections_modspecial'); + $result=$this->ajax_amm_setmenu_mod_section_list('amm_sections_modspecials'); break; case 'setmenu_modspecial_sections_showhide': - $result=$this->ajax_amm_setmenu_mod_section_showhide('amm_sections_modspecial', $_REQUEST['fItem']); + $result=$this->ajax_amm_setmenu_mod_section_showhide('amm_sections_modspecials', $_REQUEST['fItem']); break; case 'personalised_list': @@ -325,7 +324,6 @@ class AMM_AIP extends AMM_root 'lnk_list' => $this->page_link.'&fAMM_tabsheet=links', 'AMM_AJAX_URL_LIST' => $this->page_link."&ajaxfct=", 'show_icons_selected' => $this->my_config['amm_links_show_icons'], - 'active_selected' => $this->my_config['amm_links_active'], 'lang_selected' => $user['language'], 'fromlang' => substr($user['language'],0,2) ); @@ -459,7 +457,6 @@ class AMM_AIP extends AMM_root protected function action_links_modify_config() { $this->my_config['amm_links_show_icons']=$_POST['famm_links_show_icons']; - $this->my_config['amm_links_active']=$_POST['famm_links_active']; $languages=get_languages(); foreach($languages as $key => $val) { @@ -473,7 +470,6 @@ class AMM_AIP extends AMM_root */ protected function action_randompic_modify_config() { - $this->my_config['amm_randompicture_active']=$_POST['famm_randompicture_active']; $this->my_config['amm_randompicture_showname']=$_POST['famm_randompicture_showname']; $this->my_config['amm_randompicture_showcomment']=$_POST['famm_randompicture_showcomment']; $languages=get_languages(); @@ -541,7 +537,6 @@ class AMM_AIP extends AMM_root $template_datas=array( 'lnk_list' => $this->page_link.'&fAMM_tabsheet=links', - 'active_selected' => $this->my_config['amm_randompicture_active'], 'showname_selected' => $this->my_config['amm_randompicture_showname'], 'showcomment_selected' => $this->my_config['amm_randompicture_showcomment'], 'lang_selected' => $user['language'], @@ -702,7 +697,7 @@ class AMM_AIP extends AMM_root */ protected function action_create_modify_personalised() { - global $menu, $user; + global $user; if($_POST['famm_modeedit']=='create') { @@ -733,14 +728,6 @@ class AMM_AIP extends AMM_root $this->modify_personalised($datas); } } - - if($_POST['famm_modeedit']=='create') - { - $menu->register('mbAMM_personalised'.$id, ($_POST['famm_personalised_nfo']=='')?$_POST['famm_personalised_title_'.$user['language']]:$_POST['famm_personalised_nfo'], 0, 'AMM'); - } - - - } @@ -812,8 +799,8 @@ class AMM_AIP extends AMM_root private function add_url($datas) { $numurl=$this->get_count_url(); - $sql="INSERT INTO ".$this->tables['urls']." (id, label, url, mode, icon, position, visible) - VALUES ('', '".$datas['label']."', '".$datas['url']."', '".$datas['mode']."', + $sql="INSERT INTO ".$this->tables['urls']." (label, url, mode, icon, position, visible) + VALUES ('".$datas['label']."', '".$datas['url']."', '".$datas['mode']."', '".$datas['icon']."', '".$numurl."', '".$datas['visible']."')"; return(pwg_query($sql)); } @@ -1053,12 +1040,9 @@ class AMM_AIP extends AMM_root // delete a section and returns a html formatted list private function ajax_amm_personalised_delete($sectionid) { - global $menu; - if(!$this->adviser_abort()) { $this->delete_personalised($sectionid); - $menu->unregister('mbAMM_personalised'.$sectionid); } return($this->ajax_amm_personalised_list()); } diff --git a/plugins/AMenuManager/amm_install.class.inc.php b/plugins/AMenuManager/amm_install.class.inc.php index 2f2bb9e47..db1926a0a 100644 --- a/plugins/AMenuManager/amm_install.class.inc.php +++ b/plugins/AMenuManager/amm_install.class.inc.php @@ -47,7 +47,7 @@ `visible` char(1) NOT NULL default 'y', PRIMARY KEY (`id`), KEY `order_key` (`position`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1", +)", "CREATE TABLE `".$this->tables['personalised']."` ( `id` int(11) NOT NULL default '0', @@ -57,10 +57,10 @@ `visible` char(1) NOT NULL default 'y', `nfo` varchar(25) NOT NULL default '', PRIMARY KEY (`id`,`lang`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1" +)" ); //$table_def array - + $tables_def = create_table_add_character_set($tables_def); $result=$this->tablef->create_tables($tables_def); return($result); } diff --git a/plugins/AMenuManager/amm_pip.class.inc.php b/plugins/AMenuManager/amm_pip.class.inc.php index dc34e1d84..6a195b052 100644 --- a/plugins/AMenuManager/amm_pip.class.inc.php +++ b/plugins/AMenuManager/amm_pip.class.inc.php @@ -38,44 +38,19 @@ class AMM_PIP extends AMM_root */ public function init_events() { - add_event_handler('loc_begin_menubar', array(&$this, 'modify_menu') ); + //TODELETE: add_event_handler('loc_begin_menubar', array(&$this, 'modify_menu') ); + parent::init_events(); + add_event_handler('blockmanager_apply', array(&$this, 'blockmanager_apply') ); } - /* --------------------------------------------------------------------------- - protected classe functions - --------------------------------------------------------------------------- */ - public function modify_menu() + public function blockmanager_apply( $menu_ref_arr ) { - global $menu, $user; - - - /* - Add a new section (links) - */ - $urls=$this->get_urls(true); - if(($this->my_config['amm_links_active']=='y')and(count($urls)>0)) - { - if($this->my_config['amm_links_show_icons']=='y') - { - for($i=0;$imy_config['amm_links_title'][$user['language']]), dirname(__FILE__).'/menu_templates/menubar_links.tpl'); - $section->set_items(array( - 'LINKS' => $urls, - 'icons' => $this->my_config['amm_links_show_icons'] - )); - $menu->add($section->get()); - } - + $menu = & $menu_ref_arr[0]; /* Add a new random picture section */ - if($this->my_config['amm_randompicture_active']=='y') + if ( ($block = $menu->get_block( 'mbAMM_randompict' ) ) != null ) { $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 FROM ".CATEGORIES_TABLE." c, ".IMAGES_TABLE." i, ".IMAGE_CATEGORY_TABLE." ic @@ -95,17 +70,43 @@ LIMIT 0,1 'name' => $nfo['name'], 'permalink' => $nfo['permalink'] ); - - $section = new Section('mbAMM_randompict', base64_decode($this->my_config['amm_randompicture_title'][$user['language']]), dirname(__FILE__).'/menu_templates/menubar_randompic.tpl'); - $section->set_items(array( + global $user; + $block->set_title( base64_decode($this->my_config['amm_randompicture_title'][$user['language']]) ); + $block->template = dirname(__FILE__).'/menu_templates/menubar_randompic.tpl'; + $block->data = array( 'LINK' => make_picture_url($nfo), 'IMG' => get_thumbnail_url($nfo), 'IMGNAME' => $nfo['imgname'], 'IMGCOMMENT' => $nfo['comment'], 'SHOWNAME' => $this->my_config['amm_randompicture_showname'], 'SHOWCOMMENT' => $this->my_config['amm_randompicture_showcomment'] - )); - $menu->add($section->get()); + ); + } + } + + /* + Add a new section (links) + */ + if ( ($block = $menu->get_block( 'mbAMM_links' ) ) != null ) + { + $urls=$this->get_urls(true); + if ( count($urls)>0 ) + { + if($this->my_config['amm_links_show_icons']=='y') + { + for($i=0;$iset_title( base64_decode($this->my_config['amm_links_title'][$user['language']]) ); + $block->template = dirname(__FILE__).'/menu_templates/menubar_links.tpl'; + + $block->data = array( + 'LINKS' => $urls, + 'icons' => $this->my_config['amm_links_show_icons'] + ); } } @@ -121,46 +122,34 @@ LIMIT 0,1 { if(!isset($id_done[$val['id']])) { - $section = new Section('mbAMM_personalised'.$val['id'], $val['title'], dirname(__FILE__).'/menu_templates/menubar_personalised.tpl'); - $section->set_items(array( - 'CONTENT' => stripslashes($val['content']))); - $menu->add($section->get()); - + if ( ($block = $menu->get_block( 'mbAMM_personalised'.$val['id'] ) ) != null ) + { + $block->set_title( $val['title'] ); + $block->template = dirname(__FILE__).'/menu_templates/menubar_personalised.tpl'; + $block->data = stripslashes($val['content']); + } $id_done[$val['id']]=""; } } } - - /* - Hide sections - */ - foreach($this->my_config['amm_sections_visible'] as $key => $val) - { - if($val=='n') - { - $menu->remove($key); - } - } - /* hide items from special & menu sections */ - foreach(array('mbMenu' => 'amm_sections_modmenu', 'mbSpecial' =>'amm_sections_modspecial') as $key0 => $val0) + foreach(array('mbMenu' => 'amm_sections_modmenu', 'mbSpecials' =>'amm_sections_modspecials') as $key0 => $val0) { - $section_menu=$menu->section($key0); - foreach($this->my_config[$val0] as $key => $val) + if ( ($block = $menu->get_block( $key0 ) ) != null ) { - if($val=='n') + foreach($this->my_config[$val0] as $key => $val) { - unset($section_menu['ITEMS'][$key]); + if($val=='n') + { + unset( $block->data[$key] ); + } } } - $menu->replace($section_menu); } - - } - + } } // AMM_PIP class diff --git a/plugins/AMenuManager/amm_root.class.inc.php b/plugins/AMenuManager/amm_root.class.inc.php index 2dfa604e0..38440a2d0 100644 --- a/plugins/AMenuManager/amm_root.class.inc.php +++ b/plugins/AMenuManager/amm_root.class.inc.php @@ -37,33 +37,28 @@ class AMM_root extends common_plugin /* this function initialize var $my_config with default values */ public function init_config() { - global $menu; - $this->my_config=array( 'amm_links_show_icons' => 'y', - 'amm_links_active' => 'y', 'amm_links_title' => array(), - 'amm_sections_visible' => array(), - 'amm_randompicture_active' => 'n', 'amm_randompicture_showname' => 'n', //n:no, o:over, u:under 'amm_randompicture_showcomment' => 'n', //n:no, o:over, u:under 'amm_randompicture_title' => array(), - 'amm_sections_modspecial' => array( - 'favorite_cat' => 'y', - 'most_visited_cat' => 'y', - 'best_rated_cat' => 'y', - 'random_cat' => 'y', - 'recent_pics_cat' => 'y', - 'recent_cats_cat' => 'y', + 'amm_sections_modspecials' => array( + 'favorites' => 'y', + 'most_visited' => 'y', + 'best_rated' => 'y', + 'random' => 'y', + 'recent_pics' => 'y', + 'recent_cats' => 'y', 'calendar' => 'y' ), 'amm_sections_modmenu' => array( 'qsearch' => 'y', - 'Tags' => 'y', - 'Search' => 'y', + 'tags' => 'y', + 'search' => 'y', 'comments' => 'y', - 'About' => 'y', - 'Notification' => 'y' + 'about' => 'y', + 'notification' => 'y' ) ); @@ -82,28 +77,39 @@ class AMM_root extends common_plugin } } - $sections=$menu->registered(); - foreach($sections as $key => $val) - { - $this->my_config['amm_sections_visible'][$key]='y'; - } } public function load_config() { - global $menu; - parent::load_config(); + } - $sections=$menu->registered(); - foreach($sections as $key => $val) + public function init_events() + { + add_event_handler('blockmanager_register_blocks', array(&$this, 'register_blocks') ); + } + + public function register_blocks( $menu_ref_arr ) + { + $menu = & $menu_ref_arr[0]; + if ($menu->get_id() != 'menubar') + return; + $menu->register_block( new RegisteredBlock( 'mbAMM_randompict', 'Random pictures', 'AMM')); + $menu->register_block( new RegisteredBlock( 'mbAMM_links', 'Links', 'AMM')); + + $sections=$this->get_sections(true); + if(count($sections)) { - if(!isset($this->my_config['amm_sections_visible'][$key])) + $id_done=array(); + foreach($sections as $key => $val) { - $this->my_config['amm_sections_visible'][$key]='y'; + if(!isset($id_done[$val['id']])) + { + $menu->register_block( new RegisteredBlock( 'mbAMM_personalised'.$val['id'], $val['title'], 'AMM')); + $id_done[$val['id']]=""; + } } } - } // return an array of urls (each url is an array) diff --git a/plugins/AMenuManager/main.inc.php b/plugins/AMenuManager/main.inc.php index 766b478e8..79cbf674a 100755 --- a/plugins/AMenuManager/main.inc.php +++ b/plugins/AMenuManager/main.inc.php @@ -43,9 +43,9 @@ define('AMM_PATH' , PHPWG_PLUGINS_PATH . AMM_DIR . '/'); define('AMM_VERSION' , '1.0.0'); // => ne pas oublier la version dans l'entĂȘte !! -global $prefixeTable, $menu; +global $prefixeTable; -if(basename($_SERVER["PHP_SELF"])=='admin.php') +if(defined('IN_ADMIN')) { //AMM admin part loaded and active only if in admin page include_once("amm_aim.class.inc.php"); diff --git a/plugins/AMenuManager/maintain.inc.php b/plugins/AMenuManager/maintain.inc.php index 543ec5c1f..3c75083c9 100755 --- a/plugins/AMenuManager/maintain.inc.php +++ b/plugins/AMenuManager/maintain.inc.php @@ -5,8 +5,8 @@ if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } ini_set('error_reporting', E_ALL); ini_set('display_errors', true); -define('AMM_DIR' , basename(dirname(__FILE__))); -define('AMM_PATH' , PHPWG_PLUGINS_PATH . AMM_DIR . '/'); +defined('AMM_DIR') || define('AMM_DIR' , basename(dirname(__FILE__))); +defined('AMM_PATH') || define('AMM_PATH' , PHPWG_PLUGINS_PATH . AMM_DIR . '/'); @include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/tables.class.inc.php'); @@ -23,11 +23,11 @@ load_language('plugin.lang', AMM_PATH); function plugin_install($plugin_id, $plugin_version, &$errors) { - global $prefixeTable, $gpc_installed, $menu; + global $prefixeTable, $gpc_installed; if($gpc_installed) { - $menu->register('mbAMM_links', 'Links', 0, 'AMM'); - $menu->register('mbAMM_randompict', 'Random pictures', 0, 'AMM'); + //$menu->register('mbAMM_links', 'Links', 0, 'AMM'); + //$menu->register('mbAMM_randompict', 'Random pictures', 0, 'AMM'); $amm=new AMM_install($prefixeTable, __FILE__); $result=$amm->install(); } @@ -47,18 +47,9 @@ function plugin_deactivate($plugin_id) function plugin_uninstall($plugin_id) { - global $prefixeTable, $gpc_installed, $menu; - if($gpc_installed) - { - $menu->unregister('mbAMM_links'); - $menu->unregister('mbAMM_randompict'); - $amm=new AMM_install($prefixeTable, __FILE__); - $result=$amm->uninstall(); - } - else - { - array_push($errors, l10n('Grum Plugin Classes is not installed')); - } + global $prefixeTable; + $amm=new AMM_install($prefixeTable, __FILE__); + $result=$amm->uninstall(); } diff --git a/plugins/AMenuManager/menu_templates/menubar_links.tpl b/plugins/AMenuManager/menu_templates/menubar_links.tpl index 927a0f2cd..205e3b66e 100644 --- a/plugins/AMenuManager/menu_templates/menubar_links.tpl +++ b/plugins/AMenuManager/menu_templates/menubar_links.tpl @@ -1,13 +1,13 @@ -{if $section.NAME!=""} -
{$section.NAME|@translate}
+{if $block->get_title() !="" } +
{$block->get_title()}
{/if}
-
    - {foreach from=$section.ITEMS.LINKS item=link} +
      data.icons=='y'}style="padding-left:4px;list-style:none;"{/if}> + {foreach from=$block->data.LINKS item=link}
    • - {if $section.ITEMS.icons=='y'}{/if} + {if $block->data.icons=='y'}{/if} {$link.label}
    • diff --git a/plugins/AMenuManager/menu_templates/menubar_personalised.tpl b/plugins/AMenuManager/menu_templates/menubar_personalised.tpl index 93c3b860b..9fada74a2 100644 --- a/plugins/AMenuManager/menu_templates/menubar_personalised.tpl +++ b/plugins/AMenuManager/menu_templates/menubar_personalised.tpl @@ -1,8 +1,8 @@ -{if $section.NAME!=""} -
      {$section.NAME|@translate}
      +{if $block->get_title() !="" } +
      {$block->get_title()}
      {/if}
      - {if $section.ITEMS.CONTENT!=""}{$section.ITEMS.CONTENT}{/if} + {$block->data}
      \ No newline at end of file diff --git a/plugins/AMenuManager/menu_templates/menubar_randompic.tpl b/plugins/AMenuManager/menu_templates/menubar_randompic.tpl index a79206103..20d7a0bf8 100644 --- a/plugins/AMenuManager/menu_templates/menubar_randompic.tpl +++ b/plugins/AMenuManager/menu_templates/menubar_randompic.tpl @@ -1,14 +1,12 @@ -{if $section.NAME!=""} -
      {$section.NAME|@translate}
      -{/if} +
      {$block->get_title()}
      - {if $section.ITEMS.IMGNAME!="" and $section.ITEMS.SHOWNAME=="o"}{$section.ITEMS.IMGNAME}
      {/if} - {if $section.ITEMS.IMGCOMMENT!="" and $section.ITEMS.SHOWCOMMENT=="o"}{$section.ITEMS.IMGCOMMENT}
      {/if} - - {if $section.ITEMS.IMGNAME!="" and $section.ITEMS.SHOWNAME=="u"}
      {$section.ITEMS.IMGNAME}{/if} - {if $section.ITEMS.IMGCOMMENT!="" and $section.ITEMS.SHOWCOMMENT=="u"}
      {$section.ITEMS.IMGCOMMENT}{/if} + {if $block->data.IMGNAME!="" and $block->data.SHOWNAME=="o"}{$block->data.IMGNAME}
      {/if} + {if $block->data.IMGCOMMENT!="" and $block->data.SHOWCOMMENT=="o"}{$block->data.IMGCOMMENT}
      {/if} + + {if $block->data.IMGNAME!="" and $block->data.SHOWNAME=="u"}
      {$block->data.IMGNAME}{/if} + {if $block->data.IMGCOMMENT!="" and $block->data.SHOWCOMMENT=="u"}
      {$block->data.IMGCOMMENT}{/if}
      \ No newline at end of file -- cgit v1.2.3