1 | <?php |
---|
2 | /* ----------------------------------------------------------------------------- |
---|
3 | Plugin : Advanced Menu Manager |
---|
4 | Author : Grum |
---|
5 | email : grum@grum.fr |
---|
6 | website : http://photos.grum.fr |
---|
7 | PWG user : http://forum.piwigo.org/profile.php?id=3706 |
---|
8 | |
---|
9 | << May the Little SpaceFrog be with you ! >> |
---|
10 | ------------------------------------------------------------------------------ |
---|
11 | See main.inc.php for release information |
---|
12 | |
---|
13 | AMM_root : root class for plugin |
---|
14 | |
---|
15 | --------------------------------------------------------------------------- */ |
---|
16 | |
---|
17 | if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } |
---|
18 | |
---|
19 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/CommonPlugin.class.inc.php'); |
---|
20 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCUsersGroups.class.inc.php'); |
---|
21 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCCss.class.inc.php'); |
---|
22 | |
---|
23 | |
---|
24 | class AMM_root extends CommonPlugin |
---|
25 | { |
---|
26 | protected $css; //the css object |
---|
27 | protected $defaultMenus = array( |
---|
28 | 'favorites' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 0, 'translation' => 'My favorites'), |
---|
29 | 'most_visited' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 1, 'translation' => 'Most visited'), |
---|
30 | 'best_rated' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 2, 'translation' => 'Best rated'), |
---|
31 | 'random' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 3, 'translation' => 'Random pictures'), |
---|
32 | 'recent_pics' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 4, 'translation' => 'Recent pictures'), |
---|
33 | 'recent_cats' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 5, 'translation' => 'Recent categories'), |
---|
34 | 'calendar' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 6, 'translation' => 'Calendar'), |
---|
35 | 'qsearch' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 0, 'translation' => 'Quick search'), |
---|
36 | 'tags' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 1, 'translation' => 'Tags'), |
---|
37 | 'search' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 2, 'translation' => 'Search'), |
---|
38 | 'comments' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 3, 'translation' => 'Comments'), |
---|
39 | 'about' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 4, 'translation' => 'About'), |
---|
40 | 'rss' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 5, 'translation' => 'Notification') |
---|
41 | ); |
---|
42 | |
---|
43 | public function __construct($prefixeTable, $filelocation) |
---|
44 | { |
---|
45 | $this->setPluginName("Advanced Menu Manager"); |
---|
46 | $this->setPluginNameFiles("amm"); |
---|
47 | parent::__construct($prefixeTable, $filelocation); |
---|
48 | |
---|
49 | $list=array('urls', 'personalised'); |
---|
50 | $this->setTablesList($list); |
---|
51 | } |
---|
52 | |
---|
53 | public function __destruct() |
---|
54 | { |
---|
55 | unset($this->css); |
---|
56 | unset($this->defaultMenus); |
---|
57 | parent::__destruct(); |
---|
58 | } |
---|
59 | |
---|
60 | /* --------------------------------------------------------------------------- |
---|
61 | common AIP & PIP functions |
---|
62 | --------------------------------------------------------------------------- */ |
---|
63 | |
---|
64 | /* this function initialize var $my_config with default values */ |
---|
65 | public function initConfig() |
---|
66 | { |
---|
67 | $this->config=array( |
---|
68 | 'amm_links_show_icons' => 'y', |
---|
69 | 'amm_links_title' => array(), |
---|
70 | 'amm_randompicture_showname' => 'n', //n:no, o:over, u:under |
---|
71 | 'amm_randompicture_showcomment' => 'n', //n:no, o:over, u:under |
---|
72 | 'amm_randompicture_periodicchange' => 0, //0: no periodic change ; periodic change in milliseconds |
---|
73 | 'amm_randompicture_height' => 0, //0: automatic, otherwise it's the fixed height in pixels |
---|
74 | 'amm_randompicture_title' => array(), |
---|
75 | 'amm_sections_items' => $this->defaultMenus |
---|
76 | ); |
---|
77 | |
---|
78 | $languages=get_languages(); |
---|
79 | foreach($languages as $key => $val) |
---|
80 | { |
---|
81 | if($key=='fr_FR') |
---|
82 | { |
---|
83 | $this->config['amm_links_title'][$key]=base64_encode('Liens'); |
---|
84 | $this->config['amm_randompicture_title'][$key]=base64_encode('Une image au hasard'); |
---|
85 | } |
---|
86 | else |
---|
87 | { |
---|
88 | $this->config['amm_links_title'][$key]=base64_encode('Links'); |
---|
89 | $this->config['amm_randompicture_title'][$key]=base64_encode('A random picture'); |
---|
90 | } |
---|
91 | } |
---|
92 | } |
---|
93 | |
---|
94 | public function loadConfig() |
---|
95 | { |
---|
96 | parent::loadConfig(); |
---|
97 | } |
---|
98 | |
---|
99 | public function initEvents() |
---|
100 | { |
---|
101 | add_event_handler('blockmanager_register_blocks', array(&$this, 'register_blocks') ); |
---|
102 | } |
---|
103 | |
---|
104 | public function register_blocks( $menu_ref_arr ) |
---|
105 | { |
---|
106 | $menu = & $menu_ref_arr[0]; |
---|
107 | if ($menu->get_id() != 'menubar') |
---|
108 | return; |
---|
109 | $menu->register_block( new RegisteredBlock( 'mbAMM_randompict', 'Random pictures', 'AMM')); |
---|
110 | $menu->register_block( new RegisteredBlock( 'mbAMM_links', 'Links', 'AMM')); |
---|
111 | |
---|
112 | $sections=$this->get_sections(true); |
---|
113 | if(count($sections)) |
---|
114 | { |
---|
115 | $id_done=array(); |
---|
116 | foreach($sections as $key => $val) |
---|
117 | { |
---|
118 | if(!isset($id_done[$val['id']])) |
---|
119 | { |
---|
120 | $menu->register_block( new RegisteredBlock( 'mbAMM_personalised'.$val['id'], $val['title'], 'AMM')); |
---|
121 | $id_done[$val['id']]=""; |
---|
122 | } |
---|
123 | } |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | // return an array of urls (each url is an array) |
---|
128 | protected function get_urls($only_visible=false) |
---|
129 | { |
---|
130 | $returned=array(); |
---|
131 | $sql="SELECT * FROM ".$this->tables['urls']; |
---|
132 | if($only_visible) |
---|
133 | { |
---|
134 | $sql.=" WHERE visible = 'y' "; |
---|
135 | } |
---|
136 | $sql.=" ORDER BY position"; |
---|
137 | $result=pwg_query($sql); |
---|
138 | if($result) |
---|
139 | { |
---|
140 | while($row=pwg_db_fetch_assoc($result)) |
---|
141 | { |
---|
142 | $row['label']=stripslashes($row['label']); |
---|
143 | $returned[]=$row; |
---|
144 | } |
---|
145 | } |
---|
146 | return($returned); |
---|
147 | } |
---|
148 | |
---|
149 | //return number of url |
---|
150 | protected function get_count_url($only_visible=false) |
---|
151 | { |
---|
152 | $returned=0; |
---|
153 | $sql="SELECT count(id) FROM ".$this->tables['urls']; |
---|
154 | if($only_visible) |
---|
155 | { |
---|
156 | $sql.=" WHERE visible = 'y' "; |
---|
157 | } |
---|
158 | $result=pwg_query($sql); |
---|
159 | if($result) |
---|
160 | { |
---|
161 | $tmp=pwg_db_fetch_row($result); |
---|
162 | $returned=$tmp[0]; |
---|
163 | } |
---|
164 | return($returned); |
---|
165 | } |
---|
166 | |
---|
167 | // return an array of sections (each section is an array) |
---|
168 | protected function get_sections($only_visible=false, $lang="", $only_with_content=true) |
---|
169 | { |
---|
170 | global $user; |
---|
171 | |
---|
172 | if($lang=="") |
---|
173 | { |
---|
174 | $lang=$user['language']; |
---|
175 | } |
---|
176 | |
---|
177 | $returned=array(); |
---|
178 | $sql="SELECT * FROM ".$this->tables['personalised']." |
---|
179 | WHERE (lang = '*' OR lang = '".$lang."') "; |
---|
180 | if($only_visible) |
---|
181 | { |
---|
182 | $sql.=" AND visible = 'y' "; |
---|
183 | } |
---|
184 | if($only_with_content) |
---|
185 | { |
---|
186 | $sql.=" AND content != '' "; |
---|
187 | } |
---|
188 | $sql.=" ORDER BY id, lang DESC "; |
---|
189 | $result=pwg_query($sql); |
---|
190 | if($result) |
---|
191 | { |
---|
192 | while($row=pwg_db_fetch_assoc($result)) |
---|
193 | { |
---|
194 | $returned[]=$row; |
---|
195 | } |
---|
196 | } |
---|
197 | return($returned); |
---|
198 | } |
---|
199 | |
---|
200 | |
---|
201 | protected function sortSectionsItemsCompare($a, $b) |
---|
202 | { |
---|
203 | if($a['container']==$b['container']) |
---|
204 | { |
---|
205 | if($a['order']==$b['order']) return(0); |
---|
206 | return(($a['order']<$b['order'])?-1:1); |
---|
207 | } |
---|
208 | else return(($a['container']<$b['container'])?-1:1); |
---|
209 | } |
---|
210 | |
---|
211 | protected function sortSectionsItems() |
---|
212 | { |
---|
213 | uasort($this->config['amm_sections_items'], array($this, "sortSectionsItemsCompare")); |
---|
214 | } |
---|
215 | |
---|
216 | } // amm_root class |
---|
217 | |
---|
218 | |
---|
219 | |
---|
220 | ?> |
---|