[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 | --------------------------------------------------------------------------- */ |
---|
[7560] | 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'); |
---|
[3396] | 18 | |
---|
[7560] | 19 | class LMT_root extends CommonPlugin |
---|
| 20 | { |
---|
| 21 | protected $css; //the css object |
---|
| 22 | protected $css_icn; //the css object |
---|
[3396] | 23 | |
---|
[7560] | 24 | static public $licences=array('BY', 'BY-ND', 'BY-NC', 'BY-NC-ND', 'BY-NC-SA', 'BY-SA', 'CRIGHT', 'CLEFT', 'DEFAULT'); |
---|
[3396] | 25 | |
---|
[7560] | 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(); |
---|
[3396] | 35 | |
---|
[7560] | 36 | $this->setTablesList(array('images', 'licence_author')); |
---|
[3396] | 37 | |
---|
[7560] | 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 | } |
---|
[3396] | 41 | |
---|
[7560] | 42 | /** |
---|
| 43 | * destructor |
---|
| 44 | */ |
---|
| 45 | public function __destruct() |
---|
| 46 | { |
---|
| 47 | unset($this->css); |
---|
| 48 | unset($this->css_icn); |
---|
| 49 | parent::__destruct(); |
---|
| 50 | } |
---|
[3396] | 51 | |
---|
[7560] | 52 | public function initEvents() |
---|
| 53 | { |
---|
| 54 | add_event_handler('blockmanager_register_blocks', array(&$this, 'register_blocks') ); |
---|
| 55 | } |
---|
[5548] | 56 | |
---|
[7560] | 57 | /** |
---|
| 58 | * menu block management |
---|
| 59 | */ |
---|
| 60 | public function register_blocks() |
---|
| 61 | { |
---|
| 62 | } |
---|
[3396] | 63 | |
---|
| 64 | |
---|
[7560] | 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 | ); |
---|
[3396] | 92 | |
---|
[7560] | 93 | $languages=get_languages(); |
---|
| 94 | foreach($languages as $key => $val) |
---|
[3396] | 95 | { |
---|
[7560] | 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]=''; |
---|
[3396] | 107 | } |
---|
[7560] | 108 | } |
---|
[3396] | 109 | |
---|
[7560] | 110 | /** |
---|
| 111 | * returns the admin page link |
---|
| 112 | */ |
---|
| 113 | public function getAdminLink($mode='') |
---|
| 114 | { |
---|
| 115 | if($mode=='ajax') |
---|
[3396] | 116 | { |
---|
[7560] | 117 | return('plugins/'.basename(dirname($this->getFileLocation())).'/lmt_ajax.php'); |
---|
[3396] | 118 | } |
---|
[7560] | 119 | else |
---|
[3396] | 120 | { |
---|
[7560] | 121 | return(parent::getAdminLink()); |
---|
[3396] | 122 | } |
---|
[7560] | 123 | } |
---|
[3396] | 124 | |
---|
| 125 | |
---|
[7560] | 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 | { |
---|
[3396] | 142 | |
---|
[7560] | 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) |
---|
[3396] | 155 | { |
---|
[7560] | 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 | } |
---|
[3396] | 165 | } |
---|
| 166 | |
---|
[7560] | 167 | if(($return["licence"]=="")&&($this->config["lmt_licence_visible"]=="y")) |
---|
[3396] | 168 | { |
---|
| 169 | $return=array( |
---|
[7560] | 170 | "defaut" => "y", |
---|
| 171 | "licence" => $this->config["lmt_licence_default"], |
---|
[3396] | 172 | "aut_text1" => "", |
---|
| 173 | "aut_text2" => "" |
---|
| 174 | ); |
---|
[7560] | 175 | |
---|
| 176 | $sql="SELECT * FROM ".$this->tables['licence_author']." |
---|
| 177 | WHERE id = '".$this->config["lmt_licence_default_author"]."'"; |
---|
[3396] | 178 | $result=pwg_query($sql); |
---|
| 179 | if($result) |
---|
| 180 | { |
---|
[5431] | 181 | while($row=pwg_db_fetch_assoc($result)) |
---|
[3396] | 182 | { |
---|
[7560] | 183 | $return["aut_text1"]=$row['text1']; |
---|
| 184 | $return["aut_text2"]=$row['text2']; |
---|
[3396] | 185 | } |
---|
| 186 | } |
---|
[7560] | 187 | } |
---|
[3396] | 188 | |
---|
[7560] | 189 | return($return); |
---|
| 190 | } |
---|
[3396] | 191 | |
---|
| 192 | |
---|
[7560] | 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']; |
---|
[3396] | 203 | |
---|
[7560] | 204 | $result=pwg_query($sql.$sql_where.$sql_order); |
---|
| 205 | if($result) |
---|
[3396] | 206 | { |
---|
[7560] | 207 | $returned=array(); |
---|
| 208 | while($row=pwg_db_fetch_assoc($result)) |
---|
[3396] | 209 | { |
---|
[7560] | 210 | array_push($returned, $row); |
---|
[4396] | 211 | } |
---|
[7560] | 212 | return($returned); |
---|
[3396] | 213 | } |
---|
[7560] | 214 | return(false); |
---|
| 215 | } |
---|
[3396] | 216 | |
---|
[7560] | 217 | |
---|
[5548] | 218 | protected function displayResult($action_msg, $result) |
---|
[3396] | 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 | |
---|
[7560] | 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 | } |
---|
[3396] | 263 | |
---|
[7560] | 264 | } //class |
---|
[3396] | 265 | |
---|
| 266 | |
---|
[7560] | 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 | |
---|
[3396] | 326 | ?> |
---|