1 | <?php |
---|
2 | /* ----------------------------------------------------------------------------- |
---|
3 | Plugin : LMT |
---|
4 | Author : Grum |
---|
5 | email : grum@piwigo.org |
---|
6 | website : http://photos.grum.fr |
---|
7 | |
---|
8 | << May the Little SpaceFrog be with you ! >> |
---|
9 | ------------------------------------------------------------------------------ |
---|
10 | See main.inc.php for release information |
---|
11 | |
---|
12 | LMT_root : common classe for admin and public classes |
---|
13 | |
---|
14 | --------------------------------------------------------------------------- */ |
---|
15 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/CommonPlugin.class.inc.php'); |
---|
16 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCCss.class.inc.php'); |
---|
17 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCAjax.class.inc.php'); |
---|
18 | |
---|
19 | class LMT_root extends CommonPlugin |
---|
20 | { |
---|
21 | protected $css; //the css object |
---|
22 | protected $css_icn; //the css object |
---|
23 | |
---|
24 | static public $licences=array('BY', 'BY-ND', 'BY-NC', 'BY-NC-ND', 'BY-NC-SA', 'BY-SA', 'CRIGHT', 'CLEFT', 'DEFAULT'); |
---|
25 | |
---|
26 | /** |
---|
27 | * constructor |
---|
28 | */ |
---|
29 | public function __construct($prefixeTable, $filelocation) |
---|
30 | { |
---|
31 | $this->setPluginName('LMT'); |
---|
32 | $this->setPluginNameFiles("lmt"); |
---|
33 | parent::__construct($prefixeTable, $filelocation); |
---|
34 | $this->section_name=$this->getPluginNameFiles(); |
---|
35 | |
---|
36 | $this->setTablesList(array('images', 'licence_author')); |
---|
37 | |
---|
38 | $this->css = new GPCCss(dirname($this->getFileLocation()).'/'.$this->getPluginNameFiles().".css"); |
---|
39 | $this->css_icn = new GPCCss(dirname($this->getFileLocation()).'/'.$this->getPluginNameFiles()."_icn.css"); |
---|
40 | } |
---|
41 | |
---|
42 | /** |
---|
43 | * destructor |
---|
44 | */ |
---|
45 | public function __destruct() |
---|
46 | { |
---|
47 | unset($this->css); |
---|
48 | unset($this->css_icn); |
---|
49 | parent::__destruct(); |
---|
50 | } |
---|
51 | |
---|
52 | public function initEvents() |
---|
53 | { |
---|
54 | add_event_handler('blockmanager_register_blocks', array(&$this, 'register_blocks') ); |
---|
55 | } |
---|
56 | |
---|
57 | /** |
---|
58 | * menu block management |
---|
59 | */ |
---|
60 | public function register_blocks() |
---|
61 | { |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | /** |
---|
66 | * initialize default values for config var |
---|
67 | */ |
---|
68 | public function initConfig() |
---|
69 | { |
---|
70 | //global $user; |
---|
71 | $this->config=array( |
---|
72 | 'lmt_list_maxheight' => '650', |
---|
73 | 'lmt_list_maxitems' => '0', /* limit number of item displayed ; 0 : no limit */ |
---|
74 | 'lmt_licence_default' => 'BY', |
---|
75 | 'lmt_licence_default_author' => 0, |
---|
76 | 'lmt_licence_activated' => 'n', |
---|
77 | 'lmt_licence_visible' => 'n', /* y:always visible, n:only if needed */ |
---|
78 | 'lmt_licence_logo' => '80x15', /* 80x15, 88x31, text */ |
---|
79 | 'lmt_warning_visible' => 'y', /* y: display a text at the bottom of each page */ |
---|
80 | 'lmt_warning_texts' => array(), /* text displayed - multi lang */ |
---|
81 | 'lmt_redirect_activated' => 'y', /* y: the text is an url to a warning page */ |
---|
82 | 'lmt_redirect_open_target' => 'n', /* y: url are openned in a new page/tab */ |
---|
83 | 'lmt_redirect_url-by' => array(), |
---|
84 | 'lmt_redirect_url-by-nd' => array(), |
---|
85 | 'lmt_redirect_url-by-nc' => array(), |
---|
86 | 'lmt_redirect_url-by-nc-nd' => array(), |
---|
87 | 'lmt_redirect_url-by-nc-sa' => array(), |
---|
88 | 'lmt_redirect_url-by-sa' => array(), |
---|
89 | 'lmt_redirect_url-cright' => array(), |
---|
90 | 'lmt_redirect_url-cleft' => array(), |
---|
91 | ); |
---|
92 | |
---|
93 | $languages=get_languages(); |
---|
94 | foreach($languages as $key => $val) |
---|
95 | { |
---|
96 | $lang=substr($key,0,2)."/"; |
---|
97 | if($lang=="en/") { $lang=""; } |
---|
98 | $this->config['lmt_warning_texts'][$key]=''; |
---|
99 | $this->config['lmt_redirect_url-by'][$key]='http://creativecommons.org/licenses/by/2.0/'.$lang; |
---|
100 | $this->config['lmt_redirect_url-by-nd'][$key]='http://creativecommons.org/licenses/by-nd/2.0/'.$lang; |
---|
101 | $this->config['lmt_redirect_url-by-nc'][$key]='http://creativecommons.org/licenses/by-nc/2.0/'.$lang; |
---|
102 | $this->config['lmt_redirect_url-by-nc-nd'][$key]='http://creativecommons.org/licenses/by-nc-nd/2.0/'.$lang; |
---|
103 | $this->config['lmt_redirect_url-by-nc-sa'][$key]='http://creativecommons.org/licenses/by-nc-sa/2.0/'.$lang; |
---|
104 | $this->config['lmt_redirect_url-by-sa'][$key]='http://creativecommons.org/licenses/by-sa/2.0/'.$lang; |
---|
105 | $this->config['lmt_redirect_url-cright'][$key]=''; |
---|
106 | $this->config['lmt_redirect_url-cleft'][$key]=''; |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | /** |
---|
111 | * returns the admin page link |
---|
112 | */ |
---|
113 | public function getAdminLink($mode='') |
---|
114 | { |
---|
115 | if($mode=='ajax') |
---|
116 | { |
---|
117 | return('plugins/'.basename(dirname($this->getFileLocation())).'/lmt_ajax.php'); |
---|
118 | } |
---|
119 | else |
---|
120 | { |
---|
121 | return(parent::getAdminLink()); |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | /** |
---|
127 | * return the licence type for an image |
---|
128 | * |
---|
129 | * returned array |
---|
130 | * 'default' => 'y' => if no licence for the picture, return de default |
---|
131 | * licence |
---|
132 | * 'n' => if no licence for the picture, return empty values |
---|
133 | * 'licence' => the licence type |
---|
134 | * 'aut_text1' => author, text 1 |
---|
135 | * 'aut_text2' => author, text 2 |
---|
136 | * |
---|
137 | * @param Integer $image_id : the image id |
---|
138 | * @return Array |
---|
139 | */ |
---|
140 | public function getImageLicence($image_id) |
---|
141 | { |
---|
142 | |
---|
143 | $return=array( |
---|
144 | "default" => "", |
---|
145 | "licence" => "", |
---|
146 | "aut_text1" => "", |
---|
147 | "aut_text2" => "" |
---|
148 | ); |
---|
149 | $sql="SELECT lmti.licence_type, lmta.text1, lmta.text2 |
---|
150 | FROM ".$this->tables['images']." lmti |
---|
151 | LEFT OUTER JOIN ".$this->tables['licence_author']." lmta ON lmti.author_id = lmta.id |
---|
152 | WHERE lmti.image_id = '".$image_id."'"; |
---|
153 | $result=pwg_query($sql); |
---|
154 | if($result) |
---|
155 | { |
---|
156 | while($row=pwg_db_fetch_assoc($result)) |
---|
157 | { |
---|
158 | $return=array( |
---|
159 | "defaut" => "n", |
---|
160 | "licence" => $row['licence_type'], |
---|
161 | "aut_text1" => $row['text1'], |
---|
162 | "aut_text2" => $row['text2'] |
---|
163 | ); |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | if(($return["licence"]=="")&&($this->config["lmt_licence_visible"]=="y")) |
---|
168 | { |
---|
169 | $return=array( |
---|
170 | "defaut" => "y", |
---|
171 | "licence" => $this->config["lmt_licence_default"], |
---|
172 | "aut_text1" => "", |
---|
173 | "aut_text2" => "" |
---|
174 | ); |
---|
175 | |
---|
176 | $sql="SELECT * FROM ".$this->tables['licence_author']." |
---|
177 | WHERE id = '".$this->config["lmt_licence_default_author"]."'"; |
---|
178 | $result=pwg_query($sql); |
---|
179 | if($result) |
---|
180 | { |
---|
181 | while($row=pwg_db_fetch_assoc($result)) |
---|
182 | { |
---|
183 | $return["aut_text1"]=$row['text1']; |
---|
184 | $return["aut_text2"]=$row['text2']; |
---|
185 | } |
---|
186 | } |
---|
187 | } |
---|
188 | |
---|
189 | return($return); |
---|
190 | } |
---|
191 | |
---|
192 | |
---|
193 | /** |
---|
194 | * returns an array of image id with the asked licence type |
---|
195 | * if $licence = "" => return all picture with a specific licences |
---|
196 | * |
---|
197 | * @param String $licence : licence to be filtered |
---|
198 | * @return Array |
---|
199 | */ |
---|
200 | public function getImagesLicences($licence) |
---|
201 | { |
---|
202 | $sql="".$this->tables['lmt']; |
---|
203 | |
---|
204 | $result=pwg_query($sql.$sql_where.$sql_order); |
---|
205 | if($result) |
---|
206 | { |
---|
207 | $returned=array(); |
---|
208 | while($row=pwg_db_fetch_assoc($result)) |
---|
209 | { |
---|
210 | array_push($returned, $row); |
---|
211 | } |
---|
212 | return($returned); |
---|
213 | } |
---|
214 | return(false); |
---|
215 | } |
---|
216 | |
---|
217 | |
---|
218 | protected function displayResult($action_msg, $result) |
---|
219 | { |
---|
220 | global $page; |
---|
221 | |
---|
222 | if($result) |
---|
223 | { |
---|
224 | array_push($page['infos'], $action_msg); |
---|
225 | } |
---|
226 | else |
---|
227 | { |
---|
228 | array_push($page['errors'], $action_msg); |
---|
229 | } |
---|
230 | } |
---|
231 | |
---|
232 | |
---|
233 | /** |
---|
234 | * build image url (for a given category) |
---|
235 | * |
---|
236 | * |
---|
237 | */ |
---|
238 | protected function makeImageDatas($tmp, $imageId) |
---|
239 | { |
---|
240 | $tmp2=array(); |
---|
241 | foreach($tmp['id'] as $key=>$val) |
---|
242 | { |
---|
243 | $tmp2[]=array( |
---|
244 | 'id' => $tmp['id'][$key], |
---|
245 | 'name' => $tmp['name'][$key], |
---|
246 | 'type' => $tmp['type'][$key], |
---|
247 | 'plinks' => $tmp['plinks'][$key], |
---|
248 | 'link'=> make_picture_url( |
---|
249 | array( |
---|
250 | 'image_id' => $imageId, |
---|
251 | 'category' => array |
---|
252 | ( |
---|
253 | 'id' => $tmp['id'][$key], |
---|
254 | 'name' => $tmp['name'][$key], |
---|
255 | 'permalink' => $tmp['plinks'][$key] |
---|
256 | ) |
---|
257 | ) |
---|
258 | ) |
---|
259 | ); |
---|
260 | } |
---|
261 | return($tmp2); |
---|
262 | } |
---|
263 | |
---|
264 | } //class |
---|
265 | |
---|
266 | |
---|
267 | |
---|
268 | |
---|
269 | class LMT_functions |
---|
270 | { |
---|
271 | static private $tables = Array(); |
---|
272 | static private $config = Array(); |
---|
273 | |
---|
274 | /** |
---|
275 | * initialise the class |
---|
276 | * |
---|
277 | * @param String $prefixeTable : the piwigo prefixe used on tables name |
---|
278 | * @param String $pluginNameFile : the plugin name used for tables name |
---|
279 | */ |
---|
280 | static public function init($prefixeTable) |
---|
281 | { |
---|
282 | GPCCore::loadConfig(LMT_root::$pluginNameFile, self::$config); |
---|
283 | $list=LMT_root::$pluginTables; |
---|
284 | |
---|
285 | for($i=0;$i<count($list);$i++) |
---|
286 | { |
---|
287 | self::$tables[$list[$i]]=$prefixeTable.LMT_root::$pluginNameFile.'_'.$list[$i]; |
---|
288 | } |
---|
289 | } |
---|
290 | |
---|
291 | |
---|
292 | /** |
---|
293 | * return all HTML&JS code necessary to display a dialogbox to choose |
---|
294 | * geographic area |
---|
295 | */ |
---|
296 | static public function dialogBoxLMT() |
---|
297 | { |
---|
298 | global $template; |
---|
299 | |
---|
300 | $template->set_filename('lmt_choose', |
---|
301 | dirname(__FILE__).'/templates/lmt_dialog_licence_choose.tpl'); |
---|
302 | |
---|
303 | $datas=Array( |
---|
304 | 'licencesList' => array() |
---|
305 | ); |
---|
306 | |
---|
307 | foreach(LMT_root::$licences as $licence) |
---|
308 | { |
---|
309 | if($licence!='DEFAULT') |
---|
310 | { |
---|
311 | $datas['licencesList'][]=array( |
---|
312 | 'value' => $licence, |
---|
313 | 'name' => l10n('lmt_lbl_cc_s-'.strtolower($licence)) |
---|
314 | ); |
---|
315 | } |
---|
316 | } |
---|
317 | |
---|
318 | $template->assign('datas', $datas); |
---|
319 | |
---|
320 | return($template->parse('lmt_choose', true)); |
---|
321 | } |
---|
322 | } //GMaps_functions |
---|
323 | |
---|
324 | |
---|
325 | |
---|
326 | ?> |
---|