[7560] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * ----------------------------------------------------------------------------- |
---|
| 4 | * Plugin Name: LMT |
---|
| 5 | * ----------------------------------------------------------------------------- |
---|
| 6 | * Author : Grum |
---|
| 7 | * email : grum@piwigo.org |
---|
| 8 | * website : http://photos.grum.fr |
---|
| 9 | * PWG user : http://forum.piwigo.org/profile.php?id=3706 |
---|
| 10 | * |
---|
| 11 | * << May the Little SpaceFrog be with you ! >> |
---|
| 12 | * |
---|
| 13 | * ----------------------------------------------------------------------------- |
---|
| 14 | * |
---|
| 15 | * See main.inc.php for release information |
---|
| 16 | * |
---|
| 17 | * manage all the ajax requests |
---|
| 18 | * ----------------------------------------------------------------------------- |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | define('PHPWG_ROOT_PATH',dirname(dirname(dirname(__FILE__))).'/'); |
---|
| 22 | |
---|
| 23 | /* |
---|
| 24 | * set ajax module in admin mode if request is used for admin interface |
---|
| 25 | */ |
---|
| 26 | if(!isset($_REQUEST['ajaxfct'])) $_REQUEST['ajaxfct']=''; |
---|
[16014] | 27 | if(preg_match('/^admin\./i', $_REQUEST['ajaxfct'])) define('IN_ADMIN', true); |
---|
| 28 | if(!defined('AJAX_CALL')) define('AJAX_CALL', true); |
---|
[7560] | 29 | |
---|
| 30 | // the common.inc.php file loads all the main.inc.php plugins files |
---|
| 31 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
| 32 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCAjax.class.inc.php'); |
---|
| 33 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCPagesNavigation.class.inc.php'); |
---|
| 34 | include_once('lmt_root.class.inc.php'); |
---|
| 35 | |
---|
| 36 | load_language('plugin.lang', LMT_PATH); |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | class LMT_Ajax extends LMT_root |
---|
| 40 | { |
---|
| 41 | /** |
---|
| 42 | * constructor |
---|
| 43 | */ |
---|
| 44 | public function __construct($prefixeTable, $filelocation) |
---|
| 45 | { |
---|
| 46 | parent::__construct($prefixeTable, $filelocation); |
---|
| 47 | $this->loadConfig(); |
---|
| 48 | $this->checkRequest(); |
---|
| 49 | $this->returnAjaxContent(); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | /** |
---|
| 53 | * check the $_REQUEST values and set default values |
---|
| 54 | * |
---|
| 55 | */ |
---|
| 56 | protected function checkRequest() |
---|
| 57 | { |
---|
| 58 | global $user; |
---|
| 59 | |
---|
[16014] | 60 | GPCAjax::checkToken(); |
---|
[7560] | 61 | if(!isset($_REQUEST['errcode'])) $_REQUEST['errcode']=''; |
---|
| 62 | |
---|
| 63 | // check if asked function is valid |
---|
| 64 | if(!($_REQUEST['ajaxfct']=='admin.img.list' or |
---|
| 65 | $_REQUEST['ajaxfct']=='admin.manage.list' |
---|
| 66 | )) $_REQUEST['ajaxfct']=''; |
---|
| 67 | |
---|
| 68 | if(preg_match('/^admin\./i', $_REQUEST['ajaxfct']) and !is_admin()) $_REQUEST['ajaxfct']=''; |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | if($_REQUEST['ajaxfct']!='admin.img.list') |
---|
| 72 | { |
---|
| 73 | if(!isset($_REQUEST['numPage']) or |
---|
| 74 | $_REQUEST['numPage'] <=0) $_REQUEST['ajaxfct']=''; |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | if(!isset($_REQUEST['filter']) || |
---|
| 78 | !($_REQUEST['filter']=="BY" || |
---|
| 79 | $_REQUEST['filter']=="BY-SA" || |
---|
| 80 | $_REQUEST['filter']=="BY-ND" || |
---|
| 81 | $_REQUEST['filter']=="BY-NC-ND" || |
---|
| 82 | $_REQUEST['filter']=="BY-NC-SA" || |
---|
| 83 | $_REQUEST['filter']=="BY-NC" || |
---|
| 84 | $_REQUEST['filter']=="CRIGHT" || |
---|
[11342] | 85 | $_REQUEST['filter']=="CLEFT" || |
---|
| 86 | $_REQUEST['filter']=="CC0" || |
---|
[15341] | 87 | $_REQUEST['filter']=="PD" |
---|
[7560] | 88 | )) |
---|
| 89 | { |
---|
| 90 | $_REQUEST['filter']=''; |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | if($_REQUEST['ajaxfct']!='admin.manage.list') |
---|
| 95 | { |
---|
| 96 | if(!isset($_REQUEST['numPage']) or |
---|
| 97 | $_REQUEST['numPage'] <=0) $_REQUEST['ajaxfct']=''; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | } //checkRequest |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | /** |
---|
| 104 | * return ajax content |
---|
| 105 | */ |
---|
| 106 | protected function returnAjaxContent() |
---|
| 107 | { |
---|
| 108 | $result="<p class='errors'>An error has occured</p>"; |
---|
| 109 | switch($_REQUEST['ajaxfct']) |
---|
| 110 | { |
---|
| 111 | case 'admin.img.list': |
---|
| 112 | $result=$this->ajax_lmt_admin_imgList($_REQUEST['numPage'], $_REQUEST['filter']); |
---|
| 113 | break; |
---|
| 114 | case 'admin.manage.list': |
---|
| 115 | $result=$this->ajax_lmt_admin_manageList($_REQUEST['numPage']); |
---|
| 116 | break; |
---|
| 117 | } |
---|
| 118 | GPCAjax::returnResult($result); |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | /*------------------------------------------------------------------------* |
---|
| 123 | * |
---|
| 124 | * ADMIN FUNCTIONS |
---|
| 125 | * |
---|
| 126 | *----------------------------------------------------------------------- */ |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | /** |
---|
| 130 | * this function returns the list of pictures with a license |
---|
| 131 | * |
---|
| 132 | * @param Integer $pagenum : page number to display |
---|
| 133 | * @param String $filter : filter to apply |
---|
| 134 | * @return String : html string, ready to be displayed |
---|
| 135 | */ |
---|
| 136 | protected function ajax_lmt_admin_imgList($pagenum, $filter) |
---|
| 137 | { |
---|
| 138 | global $conf, $template; |
---|
| 139 | |
---|
| 140 | $template->set_filename('lmt_page', |
---|
| 141 | dirname($this->getFileLocation()).'/admin/plugin_admin_listitems.tpl'); |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | $img_ids=array(); |
---|
| 145 | $img_liste = array(); |
---|
[15341] | 146 | $sql="SELECT SQL_CALC_FOUND_ROWS lmti.*, img.file, img.path, |
---|
[7560] | 147 | GROUP_CONCAT(cat.id) AS catid, |
---|
| 148 | GROUP_CONCAT(CASE WHEN cat.name IS NULL THEN '' ELSE cat.name END SEPARATOR '@sep@') AS catname, |
---|
| 149 | GROUP_CONCAT(CASE WHEN cat.permalink IS NULL THEN '' ELSE cat.permalink END SEPARATOR '@sep@') AS catpermalink, |
---|
| 150 | GROUP_CONCAT(CASE WHEN cat.dir IS NULL THEN 'V' ELSE 'P' END) AS cattype, |
---|
| 151 | lmtla.text1, lmtla.text2 |
---|
| 152 | FROM ".$this->tables["images"]." lmti |
---|
| 153 | LEFT OUTER JOIN ".$this->tables["licence_author"]." lmtla ON lmtla.id = lmti.author_id, |
---|
| 154 | ".IMAGES_TABLE." img |
---|
| 155 | LEFT OUTER JOIN ".IMAGE_CATEGORY_TABLE." imgcat ON img.id = imgcat.image_id |
---|
| 156 | LEFT OUTER JOIN ".CATEGORIES_TABLE." cat ON imgcat.category_id = cat.id |
---|
| 157 | WHERE lmti.image_id = img.id "; |
---|
| 158 | if($_REQUEST['filter']!="") |
---|
| 159 | { |
---|
| 160 | $sql.=" AND lmti.licence_type='".$_REQUEST['filter']."'"; |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | $sql.=" GROUP BY lmti.image_id ORDER BY cat.id, img.id "; |
---|
| 164 | |
---|
| 165 | if($this->config['lmt_list_maxitems']>0) |
---|
| 166 | { |
---|
| 167 | $refdbt = ($pagenum-1)*$this->config['lmt_list_maxitems']; |
---|
| 168 | $sql.=" LIMIT ".$refdbt.", ".$this->config['lmt_list_maxitems']; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | $result=pwg_query($sql); |
---|
| 172 | if($result) |
---|
| 173 | { |
---|
| 174 | while($row = pwg_db_fetch_assoc($result)) |
---|
| 175 | { |
---|
| 176 | $filenfo = pathinfo($row['path']); |
---|
| 177 | preg_match("/(.*)\./i", $filenfo["basename"], $tmp); |
---|
| 178 | $filenfo['filename'] = $tmp[1]; |
---|
| 179 | |
---|
| 180 | $tmp=array( |
---|
| 181 | 'id'=>explode(',',$row['catid']), |
---|
| 182 | 'name'=>explode('@sep@',$row['catname']), |
---|
| 183 | 'type'=>explode(',',$row['cattype']), |
---|
| 184 | 'plinks'=>explode('@sep@',$row['catpermalink']), |
---|
| 185 | 'link'=>array() |
---|
| 186 | ); |
---|
| 187 | $tmpcat=$this->makeImageDatas($tmp, $row['image_id']); |
---|
| 188 | |
---|
| 189 | $img_ids[]=$row['image_id']; |
---|
| 190 | $img_liste[]=array( |
---|
| 191 | 'id' => $row['image_id'], |
---|
| 192 | 'licence' => ($row['licence_type']=="CRIGHT")?l10n("lmt_lbl_cc_s-".strtolower($row['licence_type'])):"", |
---|
| 193 | 'licencei' => 'plugins/'.basename(LMT_PATH)."/img/".strtolower($row['licence_type'])."_80x15.png", |
---|
| 194 | 'aut_text1' => $row['text1'], |
---|
| 195 | 'aut_text2' => $row['text2'], |
---|
| 196 | 'file' => $row['file'], |
---|
| 197 | 'cat' => $tmpcat, |
---|
[16014] | 198 | 'thumb' => str_replace(PHPWG_ROOT_PATH, './', DerivativeImage::url(IMG_SQUARE, array('id'=>$row['image_id'], 'path'=>$row['path']))) |
---|
[7560] | 199 | ); |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | $sql="select FOUND_ROWS()"; |
---|
| 204 | $result=pwg_query($sql); |
---|
| 205 | $nb=pwg_db_fetch_row($result); |
---|
| 206 | |
---|
| 207 | $GPCPagesNavigation = new GPCPagesNavigation(); |
---|
| 208 | $GPCPagesNavigation->setNbItems($nb[0]); |
---|
| 209 | $GPCPagesNavigation->setNbItemsPerPage($this->config['lmt_list_maxitems']); |
---|
| 210 | $GPCPagesNavigation->setCurrentPage($pagenum); |
---|
| 211 | $GPCPagesNavigation->setOptions(array( |
---|
| 212 | "text_prev" => l10n("lmt_nav_prev"), |
---|
| 213 | "text_next" => l10n("lmt_nav_next"), |
---|
| 214 | "text_first" => l10n("lmt_nav_first"), |
---|
| 215 | "text_last" => l10n("lmt_nav_last") |
---|
| 216 | )); |
---|
| 217 | $navbar=$GPCPagesNavigation->makeNavigation("loadpage"); |
---|
| 218 | if($navbar!="") |
---|
| 219 | { |
---|
| 220 | $navbar=", ".$navbar; |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | $template->assign('imgliste', $img_liste); |
---|
| 224 | return($nb[0]." ".l10n("lmt_lst_nb_photos").$navbar."#".$template->parse('lmt_page', true)); |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | protected function ajax_lmt_admin_manageList($pagenum) |
---|
| 228 | { |
---|
| 229 | global $conf, $user, $template; |
---|
| 230 | |
---|
| 231 | $template->set_filename('lmt_page', |
---|
| 232 | dirname($this->getFileLocation()).'/admin/plugin_admin_manageitems.tpl'); |
---|
| 233 | |
---|
| 234 | if(!isset($_REQUEST['select'])) |
---|
| 235 | { |
---|
| 236 | $_REQUEST['select']="caddie"; |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | $img_liste = array(); |
---|
[15341] | 240 | $sql="SELECT SQL_CALC_FOUND_ROWS img.id as image_id, img.file, img.path, |
---|
[7560] | 241 | GROUP_CONCAT(cat.id) AS catid, |
---|
| 242 | GROUP_CONCAT(CASE WHEN cat.name IS NULL THEN '' ELSE cat.name END SEPARATOR '@sep@') AS catname, |
---|
| 243 | GROUP_CONCAT(CASE WHEN cat.permalink IS NULL THEN '' ELSE cat.permalink END SEPARATOR '@sep@') AS catpermalink, |
---|
| 244 | GROUP_CONCAT(CASE WHEN cat.dir IS NULL THEN 'V' ELSE 'P' END) AS cattype, |
---|
| 245 | lmti.licence_type, lmtla.text1, lmtla.text2 |
---|
| 246 | FROM ".CADDIE_TABLE." caddie, |
---|
| 247 | (".IMAGES_TABLE." img |
---|
| 248 | LEFT OUTER JOIN ".IMAGE_CATEGORY_TABLE." imgcat ON img.id = imgcat.image_id |
---|
| 249 | LEFT OUTER JOIN ".CATEGORIES_TABLE." cat ON imgcat.category_id = cat.id) |
---|
| 250 | LEFT OUTER JOIN ".$this->tables["images"]." AS lmti ON img.id = lmti.image_id |
---|
| 251 | LEFT OUTER JOIN ".$this->tables["licence_author"]." lmtla ON lmtla.id = lmti.author_id |
---|
| 252 | WHERE img.id = caddie.element_id |
---|
| 253 | AND caddie.user_id = '".$user['id']."' |
---|
| 254 | GROUP BY img.id |
---|
| 255 | ORDER BY cat.id, img.id "; |
---|
| 256 | |
---|
| 257 | if($this->config['lmt_list_maxitems']>0) |
---|
| 258 | { |
---|
| 259 | $refdbt = ($pagenum-1)*$this->config['lmt_list_maxitems']; |
---|
| 260 | $sql.=" LIMIT ".$refdbt.", ".$this->config['lmt_list_maxitems']; |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | $result=pwg_query($sql); |
---|
| 264 | |
---|
| 265 | if($result) |
---|
| 266 | { |
---|
| 267 | while($row = pwg_db_fetch_assoc($result)) |
---|
| 268 | { |
---|
| 269 | $filenfo = pathinfo($row['path']); |
---|
| 270 | preg_match("/(.*)\./i", $filenfo["basename"], $tmp); |
---|
| 271 | $filenfo['filename'] = $tmp[1]; |
---|
| 272 | |
---|
| 273 | $tmp=array( |
---|
| 274 | 'id'=>explode(',',$row['catid']), |
---|
| 275 | 'name'=>explode('@sep@',$row['catname']), |
---|
| 276 | 'type'=>explode(',',$row['cattype']), |
---|
| 277 | 'plinks'=>explode('@sep@',$row['catpermalink']), |
---|
| 278 | 'link'=>array() |
---|
| 279 | ); |
---|
| 280 | $tmpcat=$this->makeImageDatas($tmp, $row['image_id']); |
---|
| 281 | |
---|
| 282 | $img_liste[]=array( |
---|
| 283 | 'id' => $row['image_id'], |
---|
| 284 | 'licence' => ($row['licence_type']=="")?"DEFAULT":$row['licence_type'], |
---|
| 285 | 'licencei' => ($row['licence_type']=="")?"":'plugins/'.basename(LMT_PATH)."/img/".strtolower($row['licence_type'])."_80x15.png", |
---|
| 286 | 'aut_text1' => $row['text1'], |
---|
| 287 | 'aut_text2' => $row['text2'], |
---|
| 288 | 'file' => $row['file'], |
---|
| 289 | 'cat' => $tmpcat, |
---|
[16014] | 290 | 'thumb' => str_replace(PHPWG_ROOT_PATH, './', DerivativeImage::url(IMG_SQUARE, array('id'=>$row['image_id'], 'path'=>$row['path']))) |
---|
[7560] | 291 | ); |
---|
| 292 | } |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | $sql="select FOUND_ROWS()"; |
---|
| 296 | $result=pwg_query($sql); |
---|
| 297 | $nb=pwg_db_fetch_row($result); |
---|
| 298 | |
---|
| 299 | $GPCPagesNavigation = new GPCPagesNavigation(); |
---|
| 300 | $GPCPagesNavigation->setNbItems($nb[0]); |
---|
| 301 | $GPCPagesNavigation->setNbItemsPerPage($this->config['lmt_list_maxitems']); |
---|
| 302 | $GPCPagesNavigation->setCurrentPage($pagenum); |
---|
| 303 | $GPCPagesNavigation->setOptions(array( |
---|
| 304 | "text_prev" => l10n("lmt_nav_prev"), |
---|
| 305 | "text_next" => l10n("lmt_nav_next"), |
---|
| 306 | "text_first" => l10n("lmt_nav_first"), |
---|
| 307 | "text_last" => l10n("lmt_nav_last") |
---|
| 308 | )); |
---|
| 309 | $navbar=$GPCPagesNavigation->makeNavigation("loadpage"); |
---|
| 310 | if($navbar!="") |
---|
| 311 | { |
---|
| 312 | $navbar=", ".$navbar; |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | $template->assign('imgliste', $img_liste); |
---|
| 316 | return($nb[0]." ".l10n("lmt_lst_nb_photos").$navbar."#".$template->parse('lmt_page', true)); |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | |
---|
| 320 | |
---|
| 321 | } //class |
---|
| 322 | |
---|
| 323 | |
---|
| 324 | $returned=new LMT_Ajax($prefixeTable, __FILE__); |
---|
| 325 | ?> |
---|