[3396] | 1 | <?php |
---|
| 2 | /* ----------------------------------------------------------------------------- |
---|
| 3 | Plugin : LMT |
---|
| 4 | Author : Grum |
---|
| 5 | email : grum@piwigo.org |
---|
[4396] | 6 | website : http://photos.grum.fr |
---|
[3396] | 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 | |
---|
[4396] | 14 | --------------------------------------------------------------------------- */ |
---|
[3396] | 15 | include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/common_plugin.class.inc.php'); |
---|
| 16 | include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/css.class.inc.php'); |
---|
| 17 | include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/ajax.class.inc.php'); |
---|
| 18 | global $ajax; |
---|
| 19 | |
---|
| 20 | class LMT_root extends common_plugin |
---|
| 21 | { |
---|
| 22 | protected $css; //the css object |
---|
| 23 | protected $css_icn; //the css object |
---|
| 24 | |
---|
| 25 | protected $licences=array('BY', 'BY-ND', 'BY-NC', 'BY-NC-ND', 'BY-NC-SA', 'BY-SA', 'CRIGHT', 'CLEFT', 'DEFAULT'); |
---|
| 26 | |
---|
| 27 | public function LMT_root($prefixeTable, $filelocation) |
---|
| 28 | { |
---|
| 29 | $this->plugin_name='LMT'; |
---|
| 30 | $this->plugin_name_files="lmt"; |
---|
| 31 | parent::common_plugin($prefixeTable, $filelocation); |
---|
| 32 | $this->section_name=$this->plugin_name_files; |
---|
| 33 | |
---|
| 34 | $this->set_tables_list(array('images', 'licence_author', 'licence_doc')); |
---|
| 35 | |
---|
| 36 | |
---|
| 37 | $this->css = new css(dirname($this->filelocation).'/'.$this->plugin_name_files.".css"); |
---|
| 38 | $this->css_icn = new css(dirname($this->filelocation).'/'.$this->plugin_name_files."_icn.css"); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | public function init_events() |
---|
| 42 | { |
---|
| 43 | add_event_handler('blockmanager_register_blocks', array(&$this, 'register_blocks') ); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | /* |
---|
| 47 | menu block management |
---|
| 48 | */ |
---|
| 49 | public function register_blocks() |
---|
| 50 | { |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | /* |
---|
| 56 | surchage of common_plugin->save_config function |
---|
| 57 | */ |
---|
| 58 | public function save_config() |
---|
| 59 | { |
---|
| 60 | if(parent::save_config()) |
---|
| 61 | { |
---|
| 62 | $this->css->make_CSS($this->generate_CSS()); |
---|
| 63 | $this->css_icn->make_CSS($this->generate_CSS2()); |
---|
| 64 | return(true); |
---|
| 65 | } |
---|
| 66 | return(false); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | /* |
---|
| 70 | surchage of common_plugin->save_config function |
---|
| 71 | */ |
---|
| 72 | public function load_config() |
---|
| 73 | { |
---|
| 74 | parent::load_config(); |
---|
| 75 | if(!$this->css->css_file_exists()) |
---|
| 76 | { |
---|
| 77 | $this->css->make_CSS($this->generate_CSS()); |
---|
| 78 | } |
---|
| 79 | if(!$this->css_icn->css_file_exists()) |
---|
| 80 | { |
---|
| 81 | $this->css_icn->make_CSS($this->generate_CSS2()); |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | /* |
---|
[4396] | 86 | intialize default values |
---|
[3396] | 87 | */ |
---|
| 88 | public function init_config() |
---|
| 89 | { |
---|
| 90 | //global $user; |
---|
| 91 | $this->my_config=array( |
---|
| 92 | 'lmt_mouseovercolor' => '303030', /**/ |
---|
| 93 | 'lmt_list_maxheight' => '650', |
---|
| 94 | 'lmt_list_maxitems' => '0', /* limit number of item displayed ; 0 : no limit */ |
---|
[4396] | 95 | 'lmt_licence_default' => 'BY', |
---|
| 96 | 'lmt_licence_default_author' => 0, |
---|
[3396] | 97 | 'lmt_licence_activated' => 'n', |
---|
| 98 | 'lmt_licence_visible' => 'n', /* y:always visible, n:only if needed */ |
---|
| 99 | 'lmt_licence_logo' => '80x15', /* 80x15, 88x31, text */ |
---|
[4396] | 100 | 'lmt_warning_visible' => 'y', /* y: display a text at the bottom of each page */ |
---|
[3396] | 101 | 'lmt_warning_texts' => array(), /* text displayed - multi lang */ |
---|
[4396] | 102 | 'lmt_redirect_activated' => 'y', /* y: the text is an url to a warning page */ |
---|
| 103 | 'lmt_redirect_open_target' => 'n', /* y: url are openned in a new page/tab */ |
---|
| 104 | 'lmt_redirect_url-by' => array(), |
---|
| 105 | 'lmt_redirect_url-by-nd' => array(), |
---|
| 106 | 'lmt_redirect_url-by-nc' => array(), |
---|
| 107 | 'lmt_redirect_url-by-nc-nd' => array(), |
---|
| 108 | 'lmt_redirect_url-by-nc-sa' => array(), |
---|
| 109 | 'lmt_redirect_url-by-sa' => array(), |
---|
| 110 | 'lmt_redirect_url-cright' => array(), |
---|
| 111 | 'lmt_redirect_url-cleft' => array(), |
---|
[3396] | 112 | ); |
---|
| 113 | |
---|
| 114 | $languages=get_languages(); |
---|
| 115 | foreach($languages as $key => $val) |
---|
| 116 | { |
---|
| 117 | $lang=substr($key,0,2)."/"; |
---|
| 118 | if($lang=="en/") { $lang=""; } |
---|
| 119 | $this->my_config['lmt_warning_texts'][$key]=''; |
---|
| 120 | $this->my_config['lmt_redirect_url-by'][$key]='http://creativecommons.org/licenses/by/2.0/'.$lang; |
---|
| 121 | $this->my_config['lmt_redirect_url-by-nd'][$key]='http://creativecommons.org/licenses/by-nd/2.0/'.$lang; |
---|
| 122 | $this->my_config['lmt_redirect_url-by-nc'][$key]='http://creativecommons.org/licenses/by-nc/2.0/'.$lang; |
---|
| 123 | $this->my_config['lmt_redirect_url-by-nc-nd'][$key]='http://creativecommons.org/licenses/by-nc-nd/2.0/'.$lang; |
---|
| 124 | $this->my_config['lmt_redirect_url-by-nc-sa'][$key]='http://creativecommons.org/licenses/by-nc-sa/2.0/'.$lang; |
---|
| 125 | $this->my_config['lmt_redirect_url-by-sa'][$key]='http://creativecommons.org/licenses/by-sa/2.0/'.$lang; |
---|
| 126 | $this->my_config['lmt_redirect_url-cright'][$key]=''; |
---|
| 127 | $this->my_config['lmt_redirect_url-cleft'][$key]=''; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | /* |
---|
| 133 | generate the css code |
---|
| 134 | */ |
---|
| 135 | protected function generate_CSS() |
---|
| 136 | { |
---|
| 137 | $text = " |
---|
| 138 | .TableRow:hover |
---|
| 139 | { |
---|
| 140 | background-color:#".$this->my_config['lmt_mouseovercolor']."; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | .formtable |
---|
| 144 | { |
---|
| 145 | text-align:justify; |
---|
| 146 | display:block; |
---|
| 147 | margin-top:0px; |
---|
| 148 | margin-bottom:0px; |
---|
| 149 | width:100%; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | .formtable tr { |
---|
| 153 | vertical-align:top; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | .littlefont { font-size:90%; } |
---|
| 157 | table.littlefont th { text-align:center; padding:3px;padding-left:9px;padding-right:9px; } |
---|
| 158 | table.littlefont td { text-align:left; padding:0px;padding-left:3px;padding-right:3px; } |
---|
| 159 | |
---|
| 160 | .lmt_page |
---|
| 161 | { |
---|
| 162 | text-align:justify; |
---|
| 163 | margin:8px; |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | .lmt { |
---|
[4396] | 167 | text-align:justify; |
---|
[3396] | 168 | } |
---|
| 169 | |
---|
| 170 | #list { |
---|
| 171 | width:100%; |
---|
| 172 | overflow-y:scroll; |
---|
| 173 | min-height:250px; |
---|
| 174 | max-height:650px; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | #ullist li { |
---|
| 178 | width:300px; |
---|
[4396] | 179 | display:block; |
---|
[3396] | 180 | float:left; |
---|
| 181 | text-align:left; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | #ullist label { |
---|
| 185 | float:left; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | #ullist li table { |
---|
| 189 | margin:0px; |
---|
| 190 | text-align:left; |
---|
| 191 | width:300px; |
---|
| 192 | font-size:80%; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | #ullist li tr { |
---|
| 196 | vertical-align:top; |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | .content ul.thumbnails span.extendwrap1 { |
---|
| 200 | margin:0px; |
---|
| 201 | cursor:pointer; |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | .is_on, .is_off { |
---|
| 205 | z-index:20; |
---|
| 206 | width:12px; |
---|
| 207 | height:12px; |
---|
| 208 | display:block; |
---|
| 209 | cursor:pointer; |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | .is_on { |
---|
| 213 | background:url(./img/cb_on.png); |
---|
| 214 | } |
---|
| 215 | .is_off { |
---|
| 216 | background:url(./img/cb_off.png); |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | .icnhelp { |
---|
| 220 | weight:bold; |
---|
| 221 | text-decoration:none; |
---|
| 222 | cursor:help; |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | .hinthlp { |
---|
| 226 | position:absolute; |
---|
| 227 | max-width:400px; |
---|
| 228 | border:1px solid #000000; |
---|
| 229 | background:#ffffa0; |
---|
| 230 | color:#000000; |
---|
| 231 | top:0px; |
---|
[4396] | 232 | left:-450px; |
---|
[3396] | 233 | padding:2px; |
---|
| 234 | text-align:justify; |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | "; |
---|
| 238 | return($text); |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | /* |
---|
[4396] | 242 | generate the css code |
---|
[3396] | 243 | */ |
---|
| 244 | protected function generate_CSS2() |
---|
| 245 | { |
---|
| 246 | $text = " |
---|
| 247 | .logo80x15 { |
---|
| 248 | position:relative; |
---|
| 249 | top:4px; |
---|
| 250 | margin-right:4px; |
---|
| 251 | border:0px none; |
---|
| 252 | } |
---|
| 253 | |
---|
| 254 | .logo88x31 { |
---|
| 255 | position:relative; |
---|
| 256 | margin-right:4px; |
---|
| 257 | border:0px none; |
---|
| 258 | } |
---|
| 259 | |
---|
| 260 | #theImage img.logo80x15, #theImage img.logo88x31 { |
---|
| 261 | border:0px none; |
---|
[4396] | 262 | padding:0px; |
---|
[3396] | 263 | } |
---|
| 264 | |
---|
| 265 | .licencetag { |
---|
| 266 | display:block; |
---|
| 267 | padding-top:10px; |
---|
| 268 | font-size:80%; |
---|
| 269 | } |
---|
| 270 | "; |
---|
| 271 | return($text); |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | |
---|
| 275 | |
---|
| 276 | |
---|
| 277 | /* ------------------------------------------------------------------------- |
---|
| 278 | return the licence type for an image |
---|
| 279 | $default = 'y' => if no licence for the picture, return de default licence |
---|
| 280 | 'n' => if no licence for the picture, return empty values |
---|
| 281 | ------------------------------------------------------------------------- */ |
---|
| 282 | public function get_image_licence($image_id) |
---|
| 283 | { |
---|
| 284 | |
---|
| 285 | $return=array( |
---|
| 286 | "default" => "", |
---|
| 287 | "licence" => "", |
---|
| 288 | "aut_text1" => "", |
---|
| 289 | "aut_text2" => "" |
---|
| 290 | ); |
---|
[4396] | 291 | $sql="SELECT lmti.licence_type, lmta.text1, lmta.text2 |
---|
[3396] | 292 | FROM ".$this->tables['images']." lmti |
---|
| 293 | LEFT OUTER JOIN ".$this->tables['licence_author']." lmta ON lmti.author_id = lmta.id |
---|
| 294 | WHERE lmti.image_id = '".$image_id."'"; |
---|
| 295 | $result=pwg_query($sql); |
---|
| 296 | if($result) |
---|
| 297 | { |
---|
| 298 | while($row=mysql_fetch_array($result)) |
---|
| 299 | { |
---|
| 300 | $return=array( |
---|
| 301 | "defaut" => "n", |
---|
| 302 | "licence" => $row['licence_type'], |
---|
| 303 | "aut_text1" => $row['text1'], |
---|
| 304 | "aut_text2" => $row['text2'] |
---|
| 305 | ); |
---|
| 306 | } |
---|
| 307 | } |
---|
| 308 | |
---|
| 309 | if(($return["licence"]=="")&&($this->my_config["lmt_licence_visible"]=="y")) |
---|
| 310 | { |
---|
| 311 | $return=array( |
---|
| 312 | "defaut" => "y", |
---|
| 313 | "licence" => $this->my_config["lmt_licence_default"], |
---|
| 314 | "aut_text1" => "", |
---|
| 315 | "aut_text2" => "" |
---|
| 316 | ); |
---|
| 317 | |
---|
[4396] | 318 | $sql="SELECT * FROM ".$this->tables['licence_author']." |
---|
[3396] | 319 | WHERE id = '".$this->my_config["lmt_licence_default_author"]."'"; |
---|
| 320 | $result=pwg_query($sql); |
---|
[4396] | 321 | if($result) |
---|
[3396] | 322 | { |
---|
| 323 | while($row=mysql_fetch_array($result)) |
---|
| 324 | { |
---|
| 325 | $return["aut_text1"]=$row['text1']; |
---|
| 326 | $return["aut_text2"]=$row['text2']; |
---|
| 327 | } |
---|
| 328 | } |
---|
| 329 | } |
---|
| 330 | |
---|
[4396] | 331 | return($return); |
---|
[3396] | 332 | } |
---|
| 333 | |
---|
| 334 | |
---|
| 335 | /* ------------------------------------------------------------------------- |
---|
| 336 | returns an array of image id with the licence type |
---|
| 337 | if $licence = "" => return all picture with a specific licences |
---|
| 338 | ------------------------------------------------------------------------- */ |
---|
| 339 | public function get_images_licences($licence) |
---|
| 340 | { |
---|
| 341 | $sql="".$this->tables['lmt']; |
---|
| 342 | |
---|
| 343 | $result=pwg_query($sql.$sql_where.$sql_order); |
---|
| 344 | if($result) |
---|
| 345 | { |
---|
| 346 | $returned=array(); |
---|
| 347 | while($row=mysql_fetch_assoc($result)) |
---|
| 348 | { |
---|
| 349 | array_push($returned, $row); |
---|
| 350 | } |
---|
| 351 | return($returned); |
---|
[4396] | 352 | } |
---|
| 353 | return(false); |
---|
[3396] | 354 | } |
---|
| 355 | |
---|
| 356 | protected function display_result($action_msg, $result) |
---|
| 357 | { |
---|
| 358 | global $page; |
---|
| 359 | |
---|
| 360 | if($result) |
---|
| 361 | { |
---|
| 362 | array_push($page['infos'], $action_msg); |
---|
| 363 | } |
---|
| 364 | else |
---|
| 365 | { |
---|
| 366 | array_push($page['errors'], $action_msg); |
---|
| 367 | } |
---|
| 368 | } |
---|
| 369 | |
---|
| 370 | |
---|
| 371 | /* --------------------------------------------------------------------------- |
---|
| 372 | ajax functions |
---|
| 373 | --------------------------------------------------------------------------- */ |
---|
| 374 | |
---|
| 375 | |
---|
| 376 | } //class |
---|
| 377 | |
---|
| 378 | ?> |
---|