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