1 | <?php |
---|
2 | /* ----------------------------------------------------------------------------- |
---|
3 | class name: common_plugin |
---|
4 | class version: 2.0 |
---|
5 | date: 2008-07-13 |
---|
6 | |
---|
7 | ------------------------------------------------------------------------------ |
---|
8 | Author : Grum |
---|
9 | email : grum@grum.dnsalias.com |
---|
10 | website : http://photos.grum.dnsalias.com |
---|
11 | PWG user : http://forum.phpwebgallery.net/profile.php?id=3706 |
---|
12 | |
---|
13 | << May the Little SpaceFrog be with you ! >> |
---|
14 | ------------------------------------------------------------------------------ |
---|
15 | |
---|
16 | this class provides base functions to manage a plugin |
---|
17 | public |
---|
18 | ADMINISTRATION RELATED |
---|
19 | - manage() |
---|
20 | - plugin_admin_menu($menu) |
---|
21 | INITIALIZATION RELATED |
---|
22 | - init_events() |
---|
23 | CONFIG RELATED |
---|
24 | - get_filelocation() |
---|
25 | - get_admin_link() |
---|
26 | - init_config() |
---|
27 | - load_config() |
---|
28 | - save_config() |
---|
29 | - delete_config() |
---|
30 | |
---|
31 | protected |
---|
32 | INITIALIZATION RELATED |
---|
33 | - set_tables_list($list) |
---|
34 | ------------------------------------------------------------------------------ |
---|
35 | :: HISTORY |
---|
36 | |
---|
37 | 2.0.0 - 2008-07-13 |
---|
38 | migrate to piwigo 2.0 ; use of PHP5 classes possibilities |
---|
39 | |
---|
40 | --------------------------------------------------------------------------- */ |
---|
41 | |
---|
42 | class common_plugin |
---|
43 | { |
---|
44 | protected $prefixeTable; // prefixe for tables names |
---|
45 | protected $page_link; //link to admin page |
---|
46 | protected $filelocation; //files plugin location on server |
---|
47 | protected $display_result_ok; |
---|
48 | protected $display_result_ko; |
---|
49 | protected $plugin_name; // used for interface display |
---|
50 | protected $plugin_name_files; // used for files |
---|
51 | protected $plugin_admin_file = "plugin_admin"; |
---|
52 | protected $tables; // list of all tables names used by plugin |
---|
53 | public $my_config; // array of config parameters |
---|
54 | |
---|
55 | /* constructor allows to initialize $prefixeTable value */ |
---|
56 | public function common_plugin($prefixeTable, $filelocation) |
---|
57 | { |
---|
58 | $this->filelocation=$filelocation; |
---|
59 | $this->prefixeTable=$prefixeTable; |
---|
60 | $this->page_link="admin.php?page=plugin§ion=". basename(dirname($this->filelocation))."/admin/".$this->plugin_admin_file.".php"; |
---|
61 | //$this->page_link=get_admin_plugin_menu_link($filelocation); |
---|
62 | $this->init_config(); |
---|
63 | $this->display_result_ok="OK"; |
---|
64 | $this->display_result_ko="KO"; |
---|
65 | } |
---|
66 | |
---|
67 | public function get_filelocation() |
---|
68 | { |
---|
69 | return($this->filelocation); |
---|
70 | } |
---|
71 | |
---|
72 | public function get_admin_link() |
---|
73 | { |
---|
74 | return($this->page_link); |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | /* --------------------------------------------------------------------------- |
---|
79 | CONFIGURATION RELATED FUNCTIONS |
---|
80 | --------------------------------------------------------------------------- */ |
---|
81 | |
---|
82 | /* this function initialize var $my_config with default values */ |
---|
83 | public function init_config() |
---|
84 | { |
---|
85 | $this->my_config=array(); |
---|
86 | } |
---|
87 | |
---|
88 | /* load config from CONFIG_TABLE into var $my_config */ |
---|
89 | public function load_config() |
---|
90 | { |
---|
91 | $this->init_config(); |
---|
92 | $sql="SELECT value FROM ".CONFIG_TABLE." |
---|
93 | WHERE param = '".$this->plugin_name_files."_config'"; |
---|
94 | $result=pwg_query($sql); |
---|
95 | if($result) |
---|
96 | { |
---|
97 | $row=mysql_fetch_row($result); |
---|
98 | if(is_string($row[0])) |
---|
99 | { |
---|
100 | $config = unserialize($row[0]); |
---|
101 | reset($config); |
---|
102 | while (list($key, $val) = each($config)) |
---|
103 | { $this->my_config[$key] =$val; } |
---|
104 | } |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | /* save var $my_config into CONFIG_TABLE */ |
---|
109 | public function save_config() |
---|
110 | { |
---|
111 | $sql="REPLACE INTO ".CONFIG_TABLE." |
---|
112 | VALUES('".$this->plugin_name_files."_config', '" |
---|
113 | .serialize($this->my_config)."', '')"; |
---|
114 | $result=pwg_query($sql); |
---|
115 | if($result) |
---|
116 | { return true; } |
---|
117 | else |
---|
118 | { return false; } |
---|
119 | } |
---|
120 | |
---|
121 | /* delete config from CONFIG_TABLE */ |
---|
122 | public function delete_config() |
---|
123 | { |
---|
124 | $sql="DELETE FROM ".CONFIG_TABLE." |
---|
125 | WHERE param='".$this->plugin_name_files."_config'"; |
---|
126 | $result=pwg_query($sql); |
---|
127 | if($result) |
---|
128 | { return true; } |
---|
129 | else |
---|
130 | { return false; } |
---|
131 | } |
---|
132 | |
---|
133 | /* --------------------------------------------------------------------------- |
---|
134 | PLUGIN INITIALIZATION RELATED FUNCTIONS |
---|
135 | --------------------------------------------------------------------------- */ |
---|
136 | |
---|
137 | /* |
---|
138 | initialize tables list used by the plugin |
---|
139 | $list = array('table1', 'table2') |
---|
140 | $this->tables_list['table1'] = $prefixeTable.$plugin_name.'_table1' |
---|
141 | */ |
---|
142 | protected function set_tables_list($list) |
---|
143 | { |
---|
144 | for($i=0;$i<count($list);$i++) |
---|
145 | { |
---|
146 | $this->tables[$list[$i]]=$this->prefixeTable.$this->plugin_name_files.'_'.$list[$i]; |
---|
147 | } |
---|
148 | } |
---|
149 | |
---|
150 | /* --------------------------------------------------------------------------- |
---|
151 | ADMINISTRATOR CONSOLE RELATED FUNCTIONS |
---|
152 | --------------------------------------------------------------------------- */ |
---|
153 | |
---|
154 | /* add plugin into administration menu */ |
---|
155 | public function plugin_admin_menu($menu) |
---|
156 | { |
---|
157 | array_push($menu, |
---|
158 | array( |
---|
159 | 'NAME' => $this->plugin_name, |
---|
160 | 'URL' => get_admin_plugin_menu_link(dirname($this->filelocation). |
---|
161 | '/admin/'.$this->plugin_admin_file.'.php') |
---|
162 | )); |
---|
163 | return $menu; |
---|
164 | } |
---|
165 | |
---|
166 | /* |
---|
167 | manage plugin integration into piwigo's admin interface |
---|
168 | |
---|
169 | to be surcharged by child's classes |
---|
170 | */ |
---|
171 | public function manage() |
---|
172 | { |
---|
173 | } |
---|
174 | |
---|
175 | /* |
---|
176 | intialize plugin's events |
---|
177 | to be surcharged by child's classes |
---|
178 | */ |
---|
179 | public function init_events() |
---|
180 | { |
---|
181 | } |
---|
182 | |
---|
183 | protected function debug($text) |
---|
184 | { |
---|
185 | global $page; |
---|
186 | array_push($page['infos'], "DEBUG MODE: ".$text); |
---|
187 | } |
---|
188 | |
---|
189 | /* |
---|
190 | manage infos & errors display |
---|
191 | */ |
---|
192 | protected function display_result($action_msg, $result) |
---|
193 | { |
---|
194 | global $page; |
---|
195 | |
---|
196 | if($result) |
---|
197 | { |
---|
198 | array_push($page['infos'], $action_msg); |
---|
199 | array_push($page['infos'], $this->display_result_ok); |
---|
200 | } |
---|
201 | else |
---|
202 | { |
---|
203 | array_push($page['errors'], $action_msg); |
---|
204 | array_push($page['errors'], $this->display_result_ko); |
---|
205 | } |
---|
206 | } |
---|
207 | } //class common_plugin |
---|
208 | |
---|
209 | ?> |
---|