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