1 | <?php |
---|
2 | /* ----------------------------------------------------------------------------- |
---|
3 | Plugin : Advanced Menu Manager |
---|
4 | Author : Grum |
---|
5 | email : grum@grum.dnsalias.com |
---|
6 | website : http://photos.grum.dnsalias.com |
---|
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 | AMM_root : root classe for plugin |
---|
14 | |
---|
15 | --------------------------------------------------------------------------- */ |
---|
16 | |
---|
17 | if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } |
---|
18 | |
---|
19 | include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/common_plugin.class.inc.php'); |
---|
20 | |
---|
21 | class AMM_root extends common_plugin |
---|
22 | { |
---|
23 | function AMM_root($prefixeTable, $filelocation) |
---|
24 | { |
---|
25 | $this->plugin_name="Advanced Menu Manager"; |
---|
26 | $this->plugin_name_files="amm"; |
---|
27 | parent::__construct($prefixeTable, $filelocation); |
---|
28 | |
---|
29 | $list=array('urls', 'personalised'); |
---|
30 | $this->set_tables_list($list); |
---|
31 | } |
---|
32 | |
---|
33 | /* --------------------------------------------------------------------------- |
---|
34 | common AIP & PIP functions |
---|
35 | --------------------------------------------------------------------------- */ |
---|
36 | |
---|
37 | /* this function initialize var $my_config with default values */ |
---|
38 | public function init_config() |
---|
39 | { |
---|
40 | $this->my_config=array( |
---|
41 | 'amm_links_show_icons' => 'y', |
---|
42 | 'amm_links_title' => array(), |
---|
43 | 'amm_randompicture_showname' => 'n', //n:no, o:over, u:under |
---|
44 | 'amm_randompicture_showcomment' => 'n', //n:no, o:over, u:under |
---|
45 | 'amm_randompicture_title' => array(), |
---|
46 | 'amm_sections_modspecials' => array( |
---|
47 | 'favorites' => 'y', |
---|
48 | 'most_visited' => 'y', |
---|
49 | 'best_rated' => 'y', |
---|
50 | 'random' => 'y', |
---|
51 | 'recent_pics' => 'y', |
---|
52 | 'recent_cats' => 'y', |
---|
53 | 'calendar' => 'y' |
---|
54 | ), |
---|
55 | 'amm_sections_modmenu' => array( |
---|
56 | 'qsearch' => 'y', |
---|
57 | 'tags' => 'y', |
---|
58 | 'search' => 'y', |
---|
59 | 'comments' => 'y', |
---|
60 | 'about' => 'y', |
---|
61 | 'notification' => 'y' |
---|
62 | ) |
---|
63 | ); |
---|
64 | |
---|
65 | $languages=get_languages(); |
---|
66 | foreach($languages as $key => $val) |
---|
67 | { |
---|
68 | if($key=='fr_FR') |
---|
69 | { |
---|
70 | $this->my_config['amm_links_title'][$key]=base64_encode('Liens'); |
---|
71 | $this->my_config['amm_randompicture_title'][$key]=base64_encode('Une image au hasard'); |
---|
72 | } |
---|
73 | else |
---|
74 | { |
---|
75 | $this->my_config['amm_links_title'][$key]=base64_encode('Links'); |
---|
76 | $this->my_config['amm_randompicture_title'][$key]=base64_encode('A random picture'); |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | } |
---|
81 | |
---|
82 | public function load_config() |
---|
83 | { |
---|
84 | parent::load_config(); |
---|
85 | } |
---|
86 | |
---|
87 | public function init_events() |
---|
88 | { |
---|
89 | add_event_handler('blockmanager_register_blocks', array(&$this, 'register_blocks') ); |
---|
90 | } |
---|
91 | |
---|
92 | public function register_blocks( $menu_ref_arr ) |
---|
93 | { |
---|
94 | $menu = & $menu_ref_arr[0]; |
---|
95 | if ($menu->get_id() != 'menubar') |
---|
96 | return; |
---|
97 | $menu->register_block( new RegisteredBlock( 'mbAMM_randompict', 'Random pictures', 'AMM')); |
---|
98 | $menu->register_block( new RegisteredBlock( 'mbAMM_links', 'Links', 'AMM')); |
---|
99 | |
---|
100 | $sections=$this->get_sections(true); |
---|
101 | if(count($sections)) |
---|
102 | { |
---|
103 | $id_done=array(); |
---|
104 | foreach($sections as $key => $val) |
---|
105 | { |
---|
106 | if(!isset($id_done[$val['id']])) |
---|
107 | { |
---|
108 | $menu->register_block( new RegisteredBlock( 'mbAMM_personalised'.$val['id'], $val['title'], 'AMM')); |
---|
109 | $id_done[$val['id']]=""; |
---|
110 | } |
---|
111 | } |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | // return an array of urls (each url is an array) |
---|
116 | protected function get_urls($only_visible=false) |
---|
117 | { |
---|
118 | $returned=array(); |
---|
119 | $sql="SELECT * FROM ".$this->tables['urls']; |
---|
120 | if($only_visible) |
---|
121 | { |
---|
122 | $sql.=" WHERE visible = 'y' "; |
---|
123 | } |
---|
124 | $sql.=" ORDER BY position"; |
---|
125 | $result=pwg_query($sql); |
---|
126 | if($result) |
---|
127 | { |
---|
128 | while($row=mysql_fetch_array($result)) |
---|
129 | { |
---|
130 | $row['label']=stripslashes($row['label']); |
---|
131 | $returned[]=$row; |
---|
132 | } |
---|
133 | } |
---|
134 | return($returned); |
---|
135 | } |
---|
136 | |
---|
137 | //return number of url |
---|
138 | protected function get_count_url($only_visible=false) |
---|
139 | { |
---|
140 | $returned=0; |
---|
141 | $sql="SELECT count(id) FROM ".$this->tables['urls']; |
---|
142 | if($only_visible) |
---|
143 | { |
---|
144 | $sql.=" WHERE visible = 'y' "; |
---|
145 | } |
---|
146 | $result=pwg_query($sql); |
---|
147 | if($result) |
---|
148 | { |
---|
149 | $tmp=mysql_fetch_row($result); |
---|
150 | $returned=$tmp[0]; |
---|
151 | } |
---|
152 | return($returned); |
---|
153 | } |
---|
154 | |
---|
155 | // return an array of sections (each section is an array) |
---|
156 | protected function get_sections($only_visible=false, $lang="", $only_with_content=true) |
---|
157 | { |
---|
158 | global $user; |
---|
159 | |
---|
160 | if($lang=="") |
---|
161 | { |
---|
162 | $lang=$user['language']; |
---|
163 | } |
---|
164 | |
---|
165 | $returned=array(); |
---|
166 | $sql="SELECT * FROM ".$this->tables['personalised']." |
---|
167 | WHERE (lang = '*' OR lang = '".$lang."') "; |
---|
168 | if($only_visible) |
---|
169 | { |
---|
170 | $sql.=" AND visible = 'y' "; |
---|
171 | } |
---|
172 | if($only_with_content) |
---|
173 | { |
---|
174 | $sql.=" AND content != '' "; |
---|
175 | } |
---|
176 | $sql.=" ORDER BY id, lang DESC "; |
---|
177 | $result=pwg_query($sql); |
---|
178 | if($result) |
---|
179 | { |
---|
180 | while($row=mysql_fetch_array($result)) |
---|
181 | { |
---|
182 | $returned[]=$row; |
---|
183 | } |
---|
184 | } |
---|
185 | return($returned); |
---|
186 | } |
---|
187 | |
---|
188 | |
---|
189 | |
---|
190 | } // amm_root class |
---|
191 | |
---|
192 | |
---|
193 | ?> |
---|