> * * ----------------------------------------------------------------------------- * * See main.inc.php for release information * * manage all the ajax requests * ----------------------------------------------------------------------------- */ define('PHPWG_ROOT_PATH',dirname(dirname(dirname(__FILE__))).'/'); /* * set ajax module in admin mode if request is used for admin interface */ if(!isset($_REQUEST['ajaxfct'])) $_REQUEST['ajaxfct']=''; if(preg_match('/^admin\./i', $_REQUEST['ajaxfct'])) define('IN_ADMIN', true); if(!defined('AJAX_CALL')) define('AJAX_CALL', true); // the common.inc.php file loads all the main.inc.php plugins files include_once(PHPWG_ROOT_PATH.'include/common.inc.php' ); include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCAjax.class.inc.php'); include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCPagesNavigation.class.inc.php'); include_once('lmt_root.class.inc.php'); load_language('plugin.lang', LMT_PATH); class LMT_Ajax extends LMT_root { /** * constructor */ public function __construct($prefixeTable, $filelocation) { parent::__construct($prefixeTable, $filelocation); $this->loadConfig(); $this->checkRequest(); $this->returnAjaxContent(); } /** * check the $_REQUEST values and set default values * */ protected function checkRequest() { global $user; GPCAjax::checkToken(); if(!isset($_REQUEST['errcode'])) $_REQUEST['errcode']=''; // check if asked function is valid if(!($_REQUEST['ajaxfct']=='admin.img.list' or $_REQUEST['ajaxfct']=='admin.manage.list' )) $_REQUEST['ajaxfct']=''; if(preg_match('/^admin\./i', $_REQUEST['ajaxfct']) and !is_admin()) $_REQUEST['ajaxfct']=''; if($_REQUEST['ajaxfct']!='admin.img.list') { if(!isset($_REQUEST['numPage']) or $_REQUEST['numPage'] <=0) $_REQUEST['ajaxfct']=''; if(!isset($_REQUEST['filter']) || !($_REQUEST['filter']=="BY" || $_REQUEST['filter']=="BY-SA" || $_REQUEST['filter']=="BY-ND" || $_REQUEST['filter']=="BY-NC-ND" || $_REQUEST['filter']=="BY-NC-SA" || $_REQUEST['filter']=="BY-NC" || $_REQUEST['filter']=="CRIGHT" || $_REQUEST['filter']=="CLEFT" || $_REQUEST['filter']=="CC0" || $_REQUEST['filter']=="PD" )) { $_REQUEST['filter']=''; } } if($_REQUEST['ajaxfct']!='admin.manage.list') { if(!isset($_REQUEST['numPage']) or $_REQUEST['numPage'] <=0) $_REQUEST['ajaxfct']=''; } } //checkRequest /** * return ajax content */ protected function returnAjaxContent() { $result="
An error has occured
"; switch($_REQUEST['ajaxfct']) { case 'admin.img.list': $result=$this->ajax_lmt_admin_imgList($_REQUEST['numPage'], $_REQUEST['filter']); break; case 'admin.manage.list': $result=$this->ajax_lmt_admin_manageList($_REQUEST['numPage']); break; } GPCAjax::returnResult($result); } /*------------------------------------------------------------------------* * * ADMIN FUNCTIONS * *----------------------------------------------------------------------- */ /** * this function returns the list of pictures with a license * * @param Integer $pagenum : page number to display * @param String $filter : filter to apply * @return String : html string, ready to be displayed */ protected function ajax_lmt_admin_imgList($pagenum, $filter) { global $conf, $template; $template->set_filename('lmt_page', dirname($this->getFileLocation()).'/admin/plugin_admin_listitems.tpl'); $img_ids=array(); $img_liste = array(); $sql="SELECT SQL_CALC_FOUND_ROWS lmti.*, img.file, img.path, GROUP_CONCAT(cat.id) AS catid, GROUP_CONCAT(CASE WHEN cat.name IS NULL THEN '' ELSE cat.name END SEPARATOR '@sep@') AS catname, GROUP_CONCAT(CASE WHEN cat.permalink IS NULL THEN '' ELSE cat.permalink END SEPARATOR '@sep@') AS catpermalink, GROUP_CONCAT(CASE WHEN cat.dir IS NULL THEN 'V' ELSE 'P' END) AS cattype, lmtla.text1, lmtla.text2 FROM ".$this->tables["images"]." lmti LEFT OUTER JOIN ".$this->tables["licence_author"]." lmtla ON lmtla.id = lmti.author_id, ".IMAGES_TABLE." img LEFT OUTER JOIN ".IMAGE_CATEGORY_TABLE." imgcat ON img.id = imgcat.image_id LEFT OUTER JOIN ".CATEGORIES_TABLE." cat ON imgcat.category_id = cat.id WHERE lmti.image_id = img.id "; if($_REQUEST['filter']!="") { $sql.=" AND lmti.licence_type='".$_REQUEST['filter']."'"; } $sql.=" GROUP BY lmti.image_id ORDER BY cat.id, img.id "; if($this->config['lmt_list_maxitems']>0) { $refdbt = ($pagenum-1)*$this->config['lmt_list_maxitems']; $sql.=" LIMIT ".$refdbt.", ".$this->config['lmt_list_maxitems']; } $result=pwg_query($sql); if($result) { while($row = pwg_db_fetch_assoc($result)) { $filenfo = pathinfo($row['path']); preg_match("/(.*)\./i", $filenfo["basename"], $tmp); $filenfo['filename'] = $tmp[1]; $tmp=array( 'id'=>explode(',',$row['catid']), 'name'=>explode('@sep@',$row['catname']), 'type'=>explode(',',$row['cattype']), 'plinks'=>explode('@sep@',$row['catpermalink']), 'link'=>array() ); $tmpcat=$this->makeImageDatas($tmp, $row['image_id']); $img_ids[]=$row['image_id']; $img_liste[]=array( 'id' => $row['image_id'], 'licence' => ($row['licence_type']=="CRIGHT")?l10n("lmt_lbl_cc_s-".strtolower($row['licence_type'])):"", 'licencei' => 'plugins/'.basename(LMT_PATH)."/img/".strtolower($row['licence_type'])."_80x15.png", 'aut_text1' => $row['text1'], 'aut_text2' => $row['text2'], 'file' => $row['file'], 'cat' => $tmpcat, 'thumb' => str_replace(PHPWG_ROOT_PATH, './', DerivativeImage::url(IMG_SQUARE, array('id'=>$row['image_id'], 'path'=>$row['path']))) ); } } $sql="select FOUND_ROWS()"; $result=pwg_query($sql); $nb=pwg_db_fetch_row($result); $GPCPagesNavigation = new GPCPagesNavigation(); $GPCPagesNavigation->setNbItems($nb[0]); $GPCPagesNavigation->setNbItemsPerPage($this->config['lmt_list_maxitems']); $GPCPagesNavigation->setCurrentPage($pagenum); $GPCPagesNavigation->setOptions(array( "text_prev" => l10n("lmt_nav_prev"), "text_next" => l10n("lmt_nav_next"), "text_first" => l10n("lmt_nav_first"), "text_last" => l10n("lmt_nav_last") )); $navbar=$GPCPagesNavigation->makeNavigation("loadpage"); if($navbar!="") { $navbar=", ".$navbar; } $template->assign('imgliste', $img_liste); return($nb[0]." ".l10n("lmt_lst_nb_photos").$navbar."#".$template->parse('lmt_page', true)); } protected function ajax_lmt_admin_manageList($pagenum) { global $conf, $user, $template; $template->set_filename('lmt_page', dirname($this->getFileLocation()).'/admin/plugin_admin_manageitems.tpl'); if(!isset($_REQUEST['select'])) { $_REQUEST['select']="caddie"; } $img_liste = array(); $sql="SELECT SQL_CALC_FOUND_ROWS img.id as image_id, img.file, img.path, GROUP_CONCAT(cat.id) AS catid, GROUP_CONCAT(CASE WHEN cat.name IS NULL THEN '' ELSE cat.name END SEPARATOR '@sep@') AS catname, GROUP_CONCAT(CASE WHEN cat.permalink IS NULL THEN '' ELSE cat.permalink END SEPARATOR '@sep@') AS catpermalink, GROUP_CONCAT(CASE WHEN cat.dir IS NULL THEN 'V' ELSE 'P' END) AS cattype, lmti.licence_type, lmtla.text1, lmtla.text2 FROM ".CADDIE_TABLE." caddie, (".IMAGES_TABLE." img LEFT OUTER JOIN ".IMAGE_CATEGORY_TABLE." imgcat ON img.id = imgcat.image_id LEFT OUTER JOIN ".CATEGORIES_TABLE." cat ON imgcat.category_id = cat.id) LEFT OUTER JOIN ".$this->tables["images"]." AS lmti ON img.id = lmti.image_id LEFT OUTER JOIN ".$this->tables["licence_author"]." lmtla ON lmtla.id = lmti.author_id WHERE img.id = caddie.element_id AND caddie.user_id = '".$user['id']."' GROUP BY img.id ORDER BY cat.id, img.id "; if($this->config['lmt_list_maxitems']>0) { $refdbt = ($pagenum-1)*$this->config['lmt_list_maxitems']; $sql.=" LIMIT ".$refdbt.", ".$this->config['lmt_list_maxitems']; } $result=pwg_query($sql); if($result) { while($row = pwg_db_fetch_assoc($result)) { $filenfo = pathinfo($row['path']); preg_match("/(.*)\./i", $filenfo["basename"], $tmp); $filenfo['filename'] = $tmp[1]; $tmp=array( 'id'=>explode(',',$row['catid']), 'name'=>explode('@sep@',$row['catname']), 'type'=>explode(',',$row['cattype']), 'plinks'=>explode('@sep@',$row['catpermalink']), 'link'=>array() ); $tmpcat=$this->makeImageDatas($tmp, $row['image_id']); $img_liste[]=array( 'id' => $row['image_id'], 'licence' => ($row['licence_type']=="")?"DEFAULT":$row['licence_type'], 'licencei' => ($row['licence_type']=="")?"":'plugins/'.basename(LMT_PATH)."/img/".strtolower($row['licence_type'])."_80x15.png", 'aut_text1' => $row['text1'], 'aut_text2' => $row['text2'], 'file' => $row['file'], 'cat' => $tmpcat, 'thumb' => str_replace(PHPWG_ROOT_PATH, './', DerivativeImage::url(IMG_SQUARE, array('id'=>$row['image_id'], 'path'=>$row['path']))) ); } } $sql="select FOUND_ROWS()"; $result=pwg_query($sql); $nb=pwg_db_fetch_row($result); $GPCPagesNavigation = new GPCPagesNavigation(); $GPCPagesNavigation->setNbItems($nb[0]); $GPCPagesNavigation->setNbItemsPerPage($this->config['lmt_list_maxitems']); $GPCPagesNavigation->setCurrentPage($pagenum); $GPCPagesNavigation->setOptions(array( "text_prev" => l10n("lmt_nav_prev"), "text_next" => l10n("lmt_nav_next"), "text_first" => l10n("lmt_nav_first"), "text_last" => l10n("lmt_nav_last") )); $navbar=$GPCPagesNavigation->makeNavigation("loadpage"); if($navbar!="") { $navbar=", ".$navbar; } $template->assign('imgliste', $img_liste); return($nb[0]." ".l10n("lmt_lst_nb_photos").$navbar."#".$template->parse('lmt_page', true)); } } //class $returned=new LMT_Ajax($prefixeTable, __FILE__); ?>