1 | <?php |
---|
2 | /* ----------------------------------------------------------------------------- |
---|
3 | class name: CommonPlugin |
---|
4 | class version : 2.1.0 |
---|
5 | plugin version : 3.0.0 |
---|
6 | date : 2010-03-30 |
---|
7 | |
---|
8 | ------------------------------------------------------------------------------ |
---|
9 | Author : Grum |
---|
10 | email : grum@grum.dnsalias.com |
---|
11 | website : http://photos.grum.dnsalias.com |
---|
12 | PWG user : http://forum.phpwebgallery.net/profile.php?id=3706 |
---|
13 | |
---|
14 | << May the Little SpaceFrog be with you ! >> |
---|
15 | ------------------------------------------------------------------------------ |
---|
16 | |
---|
17 | this class provides base functions to manage a plugin |
---|
18 | public |
---|
19 | ADMINISTRATION RELATED |
---|
20 | - manage() |
---|
21 | - pluginAdminMenu($menu) |
---|
22 | INITIALIZATION RELATED |
---|
23 | - initEvents() |
---|
24 | CONFIG RELATED |
---|
25 | - getFileLocation() |
---|
26 | - getAdminLink() |
---|
27 | - initConfig() |
---|
28 | - loadConfig() |
---|
29 | - saveConfig() |
---|
30 | - deleteConfig() |
---|
31 | |
---|
32 | protected |
---|
33 | INITIALIZATION RELATED |
---|
34 | - setTablesList($list) |
---|
35 | ------------------------------------------------------------------------------ |
---|
36 | :: HISTORY |
---|
37 | |
---|
38 | | release | date | |
---|
39 | | 2.0.0 | 2008/07/13 | * migrate to piwigo 2.0 |
---|
40 | | | | * use of PHP5 classes possibilities |
---|
41 | | | | |
---|
42 | | 2.0.1 | 2009/07/24 | * config loader : better management for arrays items |
---|
43 | | | | |
---|
44 | | 2.1.0 | 2010/03/28 | * Uses piwigo pwg_db_* functions instead of mysql_* |
---|
45 | | | | functions |
---|
46 | | | | * Update class & function names |
---|
47 | | | | |
---|
48 | | | | |
---|
49 | | | | |
---|
50 | | | | |
---|
51 | | | | |
---|
52 | | | | |
---|
53 | |
---|
54 | --------------------------------------------------------------------------- */ |
---|
55 | |
---|
56 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/gpc_version.inc.php'); // => Don't forget to update this file !! |
---|
57 | include_once('GPCCore.class.inc.php'); |
---|
58 | |
---|
59 | class CommonPlugin |
---|
60 | { |
---|
61 | private $prefixeTable; // prefixe for tables names |
---|
62 | private $page_link; //link to admin page |
---|
63 | private $fileLocation; //files plugin location on server |
---|
64 | private $displayResult_ok; |
---|
65 | private $displayResult_ko; |
---|
66 | private $plugin_name; // used for interface display |
---|
67 | private $plugin_name_files; // used for files |
---|
68 | private $plugin_admin_file = "plugin_admin"; |
---|
69 | private $debug_file; |
---|
70 | protected $tables; // list of all tables names used by plugin |
---|
71 | public $config; // array of config parameters |
---|
72 | |
---|
73 | |
---|
74 | /** |
---|
75 | * this function return true if class release if greater or equal than needed by the plugin |
---|
76 | */ |
---|
77 | static public function checkGPCRelease($major, $minor, $minor2) |
---|
78 | { |
---|
79 | $release = explode(".", GPC_VERSION); |
---|
80 | |
---|
81 | if(($release[0]>$major) || |
---|
82 | ($release[0]==$major)&&($release[1]>$minor) || |
---|
83 | ($release[0]==$major)&&($release[1]==$minor)&&($release[2]>=$minor2)) |
---|
84 | { |
---|
85 | return(true); |
---|
86 | } |
---|
87 | return(false); |
---|
88 | } |
---|
89 | |
---|
90 | /* constructor allows to initialize $prefixeTable value */ |
---|
91 | public function __construct($prefixeTable, $filelocation) |
---|
92 | { |
---|
93 | $this->debug_file="debug.txt"; |
---|
94 | |
---|
95 | $this->fileLocation=$filelocation; |
---|
96 | $this->prefixeTable=$prefixeTable; |
---|
97 | $this->page_link="admin.php?page=plugin§ion=".basename(dirname($this->getFileLocation()))."/admin/".$this->plugin_admin_file.".php"; |
---|
98 | $this->initConfig(); |
---|
99 | $this->displayResult_ok="OK"; |
---|
100 | $this->displayResult_ko="KO"; |
---|
101 | } |
---|
102 | |
---|
103 | public function __destruct() |
---|
104 | { |
---|
105 | unset($this->prefixeTable); |
---|
106 | unset($this->page_link); |
---|
107 | unset($this->fileLocation); |
---|
108 | unset($this->displayResult_ok); |
---|
109 | unset($this->displayResult_ko); |
---|
110 | unset($this->plugin_name); |
---|
111 | unset($this->plugin_name_files); |
---|
112 | unset($this->tables); |
---|
113 | unset($this->debug_file); |
---|
114 | unset($this->config); |
---|
115 | } |
---|
116 | |
---|
117 | public function getFileLocation() |
---|
118 | { |
---|
119 | return($this->fileLocation); |
---|
120 | } |
---|
121 | |
---|
122 | public function getAdminLink() |
---|
123 | { |
---|
124 | return($this->page_link); |
---|
125 | } |
---|
126 | |
---|
127 | public function setAdminLink($link) |
---|
128 | { |
---|
129 | $this->page_link=$link; |
---|
130 | return($this->page_link); |
---|
131 | } |
---|
132 | |
---|
133 | public function setPluginName($name) |
---|
134 | { |
---|
135 | $this->plugin_name=$name; |
---|
136 | return($this->plugin_name); |
---|
137 | } |
---|
138 | |
---|
139 | public function setPluginNameFiles($name) |
---|
140 | { |
---|
141 | $this->plugin_name_files=$name; |
---|
142 | return($this->plugin_name_files); |
---|
143 | } |
---|
144 | |
---|
145 | public function getPluginName() |
---|
146 | { |
---|
147 | return($this->plugin_name); |
---|
148 | } |
---|
149 | |
---|
150 | public function getPluginNameFiles() |
---|
151 | { |
---|
152 | return($this->plugin_name_files); |
---|
153 | } |
---|
154 | |
---|
155 | /* --------------------------------------------------------------------------- |
---|
156 | CONFIGURATION RELATED FUNCTIONS |
---|
157 | --------------------------------------------------------------------------- */ |
---|
158 | |
---|
159 | /* this function initialize var $config with default values */ |
---|
160 | public function initConfig() |
---|
161 | { |
---|
162 | $this->config=array(); |
---|
163 | } |
---|
164 | |
---|
165 | /* load config from CONFIG_TABLE into var $my_config */ |
---|
166 | public function loadConfig() |
---|
167 | { |
---|
168 | $this->initConfig(); |
---|
169 | return(GPCCore::loadConfig($this->plugin_name_files, $this->config)); |
---|
170 | } |
---|
171 | |
---|
172 | /* save var $my_config into CONFIG_TABLE */ |
---|
173 | public function saveConfig() |
---|
174 | { |
---|
175 | return(GPCCore::saveConfig($this->plugin_name_files, $this->config)); |
---|
176 | } |
---|
177 | |
---|
178 | /* delete config from CONFIG_TABLE */ |
---|
179 | public function deleteConfig() |
---|
180 | { |
---|
181 | return(GPCCore::deleteConfig($this->plugin_name_files)); |
---|
182 | } |
---|
183 | |
---|
184 | /* --------------------------------------------------------------------------- |
---|
185 | PLUGIN INITIALIZATION RELATED FUNCTIONS |
---|
186 | --------------------------------------------------------------------------- */ |
---|
187 | |
---|
188 | /* |
---|
189 | initialize tables list used by the plugin |
---|
190 | $list = array('table1', 'table2') |
---|
191 | $this->tables_list['table1'] = $prefixeTable.$plugin_name.'_table1' |
---|
192 | */ |
---|
193 | protected function setTablesList($list) |
---|
194 | { |
---|
195 | for($i=0;$i<count($list);$i++) |
---|
196 | { |
---|
197 | $this->tables[$list[$i]]=$this->prefixeTable.$this->plugin_name_files.'_'.$list[$i]; |
---|
198 | } |
---|
199 | } |
---|
200 | |
---|
201 | /* --------------------------------------------------------------------------- |
---|
202 | ADMINISTRATOR CONSOLE RELATED FUNCTIONS |
---|
203 | --------------------------------------------------------------------------- */ |
---|
204 | |
---|
205 | /* add plugin into administration menu */ |
---|
206 | public function pluginAdminMenu($menu) |
---|
207 | { |
---|
208 | array_push($menu, |
---|
209 | array( |
---|
210 | 'NAME' => $this->plugin_name, |
---|
211 | 'URL' => get_admin_plugin_menu_link(dirname($this->getFileLocation()). |
---|
212 | '/admin/'.$this->plugin_admin_file.'.php') |
---|
213 | )); |
---|
214 | return $menu; |
---|
215 | } |
---|
216 | |
---|
217 | /* |
---|
218 | manage plugin integration into piwigo's admin interface |
---|
219 | |
---|
220 | to be surcharged by child's classes |
---|
221 | */ |
---|
222 | public function manage() |
---|
223 | { |
---|
224 | } |
---|
225 | |
---|
226 | /* |
---|
227 | intialize plugin's events |
---|
228 | to be surcharged by child's classes |
---|
229 | */ |
---|
230 | public function initEvents() |
---|
231 | { |
---|
232 | } |
---|
233 | |
---|
234 | protected function debug($text, $rewrite=false) |
---|
235 | { |
---|
236 | if($rewrite) |
---|
237 | { |
---|
238 | $fhandle=fopen($this->debug_file, "w"); |
---|
239 | } |
---|
240 | else |
---|
241 | { |
---|
242 | $fhandle=fopen($this->debug_file, "a"); |
---|
243 | } |
---|
244 | |
---|
245 | if($fhandle) |
---|
246 | { |
---|
247 | fwrite($fhandle, date("Y-m-d h:i:s")." [".$this->plugin_name."] : ".print_r($text,true).chr(10)); |
---|
248 | fclose($fhandle); |
---|
249 | } |
---|
250 | } |
---|
251 | |
---|
252 | /* |
---|
253 | manage infos & errors display |
---|
254 | */ |
---|
255 | protected function displayResult($action_msg, $result) |
---|
256 | { |
---|
257 | global $page; |
---|
258 | |
---|
259 | if($result) |
---|
260 | { |
---|
261 | array_push($page['infos'], $action_msg); |
---|
262 | array_push($page['infos'], $this->displayResult_ok); |
---|
263 | } |
---|
264 | else |
---|
265 | { |
---|
266 | array_push($page['errors'], $action_msg); |
---|
267 | array_push($page['errors'], $this->displayResult_ko); |
---|
268 | } |
---|
269 | } |
---|
270 | } //class CommonPlugin |
---|
271 | |
---|
272 | ?> |
---|