PageRenderTime 50ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/lhgallery/ajaximages.php

http://hppg.googlecode.com/
PHP | 965 lines | 766 code | 195 blank | 4 comment | 218 complexity | ee2d42581bd415e8f8f80fbac6739a5e MD5 | raw file
Possible License(s): GPL-3.0, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. $tpl = erLhcoreClassTemplate::getInstance( 'lhgallery/ajaximages.tpl.php');
  3. $Image = erLhcoreClassGallery::getSession()->load( 'erLhcoreClassModelGalleryImage', (int)$Params['user_parameters']['image_id'] );
  4. $mode = isset($Params['user_parameters_unordered']['mode']) ? $Params['user_parameters_unordered']['mode'] : 'album';
  5. $direction = (isset($Params['user_parameters_unordered']['direction']) && $Params['user_parameters_unordered']['direction'] == 'left') ? $Params['user_parameters_unordered']['direction'] : 'right';
  6. $resolutions = erConfigClassLhConfig::getInstance()->getSetting( 'site', 'resolutions' );
  7. $resolution = isset($Params['user_parameters_unordered']['resolution']) && key_exists($Params['user_parameters_unordered']['resolution'],$resolutions) ? $Params['user_parameters_unordered']['resolution'] : '';
  8. $appendResolutionMode = $resolution != '' ? '/(resolution)/'.$resolution : '';
  9. $modeMatch = $Params['user_parameters_unordered']['match'] == 'all' ? 'all' : '';
  10. $appendMatchMode = $modeMatch == 'all' ? '/(match)/all' : '';
  11. $albumMatch = is_numeric($Params['user_parameters_unordered']['album']) ? (int)$Params['user_parameters_unordered']['album'] : '';
  12. $appendAlbumMode = $albumMatch != '' ? '/(album)/'.$albumMatch : '';
  13. $Params['user_parameters_unordered']['color'] = filter_var((array)$Params['user_parameters_unordered']['color'],FILTER_VALIDATE_INT,FILTER_REQUIRE_ARRAY);
  14. $Params['user_parameters_unordered']['ncolor'] = filter_var((array)$Params['user_parameters_unordered']['ncolor'],FILTER_VALIDATE_INT,FILTER_REQUIRE_ARRAY);
  15. $filterArray = array();
  16. $appendMysqlIndex = array();
  17. if ($resolution != ''){
  18. $filterArray['pwidth'] = $resolutions[$resolution]['width'];
  19. $filterArray['pheight'] = $resolutions[$resolution]['height'];
  20. $appendMysqlIndex[] = 'res';
  21. }
  22. if ( is_numeric($albumMatch) ) {
  23. $filterArray['album_id'] = $albumMatch;
  24. }
  25. $filterArray['approved'] = 1;
  26. $keywordDecoded = '';
  27. $tpl->set('direction',$direction);
  28. $ignore_fields = array('filesize','total_filesize','ctime','owner_id','pic_rating','votes','caption','keywords','pic_raw_ip','approved','mtime','comtime','anaglyph','rtime');
  29. if ($mode == 'album')
  30. {
  31. // Index hint for mysql
  32. $useIndexHint = array(
  33. 'new' => 'pid_6',
  34. 'newasc' => 'pid_6',
  35. 'popular' => 'pid_7',
  36. 'popularasc' => 'pid_7',
  37. 'lasthits' => 'pid_8',
  38. 'lasthitsasc' => 'pid_8',
  39. 'lastcommented' => 'pid_10',
  40. 'lastcommentedasc' => 'pid_10',
  41. 'toprated' => 'pid_9',
  42. 'topratedasc' => 'pid_9',
  43. 'lastrated' => 'a_rated_gen',
  44. 'lastratedasc' => 'a_rated_gen',
  45. //Hint if resolution filter is used
  46. 'new_res' => 'aid',
  47. 'newasc_res' => 'aid',
  48. 'popular_res' => 'pid_11',
  49. 'popularasc_res' => 'pid_11',
  50. 'lasthits_res' => 'aid_2',
  51. 'lasthitsasc_res' => 'aid_2',
  52. 'lastcommented_res' => 'aid_4',
  53. 'lastcommentedasc_res' => 'aid_4',
  54. 'toprated_res' => 'aid_3',
  55. 'topratedasc_res' => 'aid_3',
  56. 'lastrated_res' => 'a_rated_gen_res',
  57. 'lastratedasc_res' => 'a_rated_gen_res',
  58. );
  59. $sortModes = array(
  60. 'new' => 'pid DESC',
  61. 'newasc' => 'pid ASC',
  62. 'popular' => 'hits DESC, pid DESC',
  63. 'popularasc' => 'hits ASC, pid ASC',
  64. 'lasthits' => 'mtime DESC, pid DESC',
  65. 'lasthitsasc' => 'mtime ASC, pid ASC',
  66. 'lastcommented' => 'comtime DESC, pid DESC',
  67. 'lastcommentedasc' => 'comtime ASC, pid ASC',
  68. 'toprated' => 'pic_rating DESC, votes DESC, pid DESC',
  69. 'topratedasc' => 'pic_rating ASC, votes ASC, pid ASC',
  70. 'lastrated' => 'rtime DESC, pid DESC',
  71. 'lastratedasc' => 'rtime ASC, pid ASC'
  72. );
  73. $modeSort = isset($Params['user_parameters_unordered']['sort']) && key_exists($Params['user_parameters_unordered']['sort'],$sortModes) ? $Params['user_parameters_unordered']['sort'] : 'new';
  74. $modeSQL = $sortModes[$modeSort];
  75. $modeIndex = $modeSort;
  76. if (count($appendMysqlIndex) > 0) {
  77. $modeIndex .= '_'.implode('_',$appendMysqlIndex);
  78. }
  79. if ($modeSort == 'new') {
  80. if ($direction == 'left') {
  81. $imagesAjax = erLhcoreClassModelGalleryImage::getImages(array('ignore_fields' => $ignore_fields, 'smart_select' => true, 'use_index' => $useIndexHint[$modeIndex],'cache_key' => 'album_image_'.CSCacheAPC::getMem()->getCacheVersion('album_'.$Image->aid),'limit' => 6,'sort' => 'pid ASC','filter' => array('aid' => $Image->aid)+(array)$filterArray,'filtergt' => array('pid' => $Image->pid)));
  82. $imagesAjax = array_reverse($imagesAjax);
  83. } else $imagesAjax = erLhcoreClassModelGalleryImage::getImages(array('ignore_fields' => $ignore_fields, 'smart_select' => true,'use_index' => $useIndexHint[$modeIndex],'cache_key' => 'album_image_'.CSCacheAPC::getMem()->getCacheVersion('album_'.$Image->aid),'limit' => 6,'filter' => array('aid' => $Image->aid)+(array)$filterArray,'filterlt' => array('pid' => $Image->pid)));
  84. } elseif ($modeSort == 'newasc') {
  85. if ($direction == 'left') {
  86. $imagesAjax = erLhcoreClassModelGalleryImage::getImages(array('ignore_fields' => $ignore_fields, 'smart_select' => true,'use_index' => $useIndexHint[$modeIndex],'cache_key' => 'album_image_'.CSCacheAPC::getMem()->getCacheVersion('album_'.$Image->aid).$modeSort,'limit' => 6,'sort' => 'pid DESC','filter' => array('aid' => $Image->aid)+(array)$filterArray,'filterlt' => array('pid' => $Image->pid)));
  87. $imagesAjax = array_reverse($imagesAjax);
  88. } else $imagesAjax = erLhcoreClassModelGalleryImage::getImages(array('ignore_fields' => $ignore_fields, 'smart_select' => true,'use_index' => $useIndexHint[$modeIndex],'sort' => 'pid ASC','cache_key' => 'album_image_'.CSCacheAPC::getMem()->getCacheVersion('album_'.$Image->aid).$modeSort,'limit' => 6,'filter' => array('aid' => $Image->aid)+(array)$filterArray,'filtergt' => array('pid' => $Image->pid)));
  89. } elseif ($modeSort == 'popular') {
  90. $cache = CSCacheAPC::getMem();
  91. $cacheKeyImage = 'album_mode_image_ajaxslides_pid_sort_popular_'.$Image->pid.'_popular_version_'.$cache->getCacheVersion('most_popular_version',time(),1500).'_version_'.$cache->getCacheVersion('album_'.$Image->aid).'_album_id_'.$Image->aid.'_direction_'.$direction.'_filter_'.erLhcoreClassGallery::multi_implode(',',$filterArray);
  92. if (($imagesAjax = $cache->restore($cacheKeyImage)) === false)
  93. {
  94. $session = erLhcoreClassGallery::getSession();
  95. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  96. $q2 = $q->subSelect();
  97. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  98. $filterSQLArray = array();
  99. $filterSQLString = '';
  100. $filterSQLArray[] = $q2->expr->eq( 'approved', $q2->bindValue( 1 ) );
  101. if ($resolution != '') {
  102. $filterSQLArray[] = $q2->expr->eq( 'pwidth', $q2->bindValue( $resolutions[$resolution]['width'] ) );
  103. $filterSQLArray[] = $q2->expr->eq( 'pheight', $q2->bindValue( $resolutions[$resolution]['height'] ) );
  104. }
  105. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  106. if ($direction == 'left') {
  107. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->gt( 'hits', $q2->bindValue( $Image->hits ) ). ' OR '.$q2->expr->eq( 'hits', $q2->bindValue( $Image->hits ) ).' AND '.$q2->expr->gt( 'pid', $q2->bindValue( $Image->pid ) ).')' )
  108. ->orderBy('hits ASC, pid ASC')
  109. ->limit( 6 );
  110. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  111. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  112. $imagesAjax = array_reverse($imagesAjax);
  113. } else {
  114. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->lt( 'hits', $q2->bindValue( $Image->hits ) ). ' OR '.$q2->expr->eq( 'hits', $q2->bindValue( $Image->hits ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ).')' )
  115. ->orderBy('hits DESC, pid DESC')
  116. ->limit( 6 );
  117. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  118. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  119. }
  120. $cache->store($cacheKeyImage,$imagesAjax,0);
  121. }
  122. } elseif ($modeSort == 'popularasc') {
  123. $cache = CSCacheAPC::getMem();
  124. $cacheKeyImage = 'album_mode_image_ajaxslides_pid_sort_popularasc_'.$Image->pid.'_popular_version_'.$cache->getCacheVersion('most_popular_version',time(),1500).'_version_'.$cache->getCacheVersion('album_'.$Image->aid).'_album_id_'.$Image->aid.'_direction_'.$direction.'_filter_'.erLhcoreClassGallery::multi_implode(',',$filterArray);
  125. if (($imagesAjax = $cache->restore($cacheKeyImage)) === false)
  126. {
  127. $session = erLhcoreClassGallery::getSession();
  128. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  129. $q2 = $q->subSelect();
  130. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  131. $filterSQLArray = array();
  132. $filterSQLString = '';
  133. $filterSQLArray[] = $q2->expr->eq( 'approved', $q2->bindValue( 1 ) );
  134. if ($resolution != '') {
  135. $filterSQLArray[] = $q2->expr->eq( 'pwidth', $q2->bindValue( $resolutions[$resolution]['width'] ) );
  136. $filterSQLArray[] = $q2->expr->eq( 'pheight', $q2->bindValue( $resolutions[$resolution]['height'] ) );
  137. }
  138. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  139. if ($direction == 'left') {
  140. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->lt( 'hits', $q2->bindValue( $Image->hits ) ). ' OR '.$q2->expr->eq( 'hits', $q2->bindValue( $Image->hits ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ) .')')
  141. ->orderBy('hits DESC, pid DESC')
  142. ->limit( 6 );
  143. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  144. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  145. $imagesAjax = array_reverse($imagesAjax);
  146. } else {
  147. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->gt( 'hits', $q2->bindValue( $Image->hits ) ). ' OR '.$q2->expr->eq( 'hits', $q2->bindValue( $Image->hits ) ).' AND '.$q2->expr->gt( 'pid', $q2->bindValue( $Image->pid ) ).')' )
  148. ->orderBy('hits ASC, pid ASC')
  149. ->limit( 6 );
  150. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  151. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  152. }
  153. $cache->store($cacheKeyImage,$imagesAjax,0);
  154. }
  155. } elseif ($modeSort == 'lasthits') {
  156. $cache = CSCacheAPC::getMem();
  157. $cacheKeyImage = 'album_mode_image_ajaxslides_pid_sort_lasthits_'.$Image->pid.'_lasthits_version_'.$cache->getCacheVersion('last_hits_version',time(),600).'_version_'.$cache->getCacheVersion('album_'.$Image->aid).'_album_id_'.$Image->aid.'_direction_'.$direction.'_filter_'.erLhcoreClassGallery::multi_implode(',',$filterArray);
  158. if (($imagesAjax = $cache->restore($cacheKeyImage)) === false)
  159. {
  160. $session = erLhcoreClassGallery::getSession();
  161. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  162. $q2 = $q->subSelect();
  163. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  164. $filterSQLArray = array();
  165. $filterSQLString = '';
  166. $filterSQLArray[] = $q2->expr->eq( 'approved', $q2->bindValue( 1 ) );
  167. if ($resolution != '') {
  168. $filterSQLArray[] = $q2->expr->eq( 'pwidth', $q2->bindValue( $resolutions[$resolution]['width'] ) );
  169. $filterSQLArray[] = $q2->expr->eq( 'pheight', $q2->bindValue( $resolutions[$resolution]['height'] ) );
  170. }
  171. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  172. if ($direction == 'left') {
  173. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->gt( 'mtime', $q2->bindValue( $Image->mtime ) ). ' OR '.$q2->expr->eq( 'mtime', $q2->bindValue( $Image->mtime ) ).' AND '.$q2->expr->gt( 'pid', $q2->bindValue( $Image->pid ) ).')' )
  174. ->orderBy('mtime ASC, pid ASC')
  175. ->limit( 6 );
  176. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  177. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  178. $imagesAjax = array_reverse($imagesAjax);
  179. } else {
  180. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->lt( 'mtime', $q2->bindValue( $Image->mtime ) ). ' OR '.$q2->expr->eq( 'mtime', $q2->bindValue( $Image->mtime ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ) .')')
  181. ->orderBy('mtime DESC, pid DESC')
  182. ->limit( 6 );
  183. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  184. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  185. }
  186. $cache->store($cacheKeyImage,$imagesAjax,0);
  187. }
  188. } elseif ($modeSort == 'lasthitsasc') {
  189. $cache = CSCacheAPC::getMem();
  190. $cacheKeyImage = 'album_mode_image_ajaxslides_pid_sort_lasthitsasc_'.$Image->pid.'_lasthits_version_'.$cache->getCacheVersion('last_hits_version',time(),600).'_version_'.$cache->getCacheVersion('album_'.$Image->aid).'_album_id_'.$Image->aid.'_direction_'.$direction.'_filter_'.erLhcoreClassGallery::multi_implode(',',$filterArray);
  191. if (($imagesAjax = $cache->restore($cacheKeyImage)) === false)
  192. {
  193. $session = erLhcoreClassGallery::getSession();
  194. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  195. $q2 = $q->subSelect();
  196. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  197. $filterSQLArray = array();
  198. $filterSQLString = '';
  199. $filterSQLArray[] = $q2->expr->eq( 'approved', $q2->bindValue( 1 ) );
  200. if ($resolution != '') {
  201. $filterSQLArray[] = $q2->expr->eq( 'pwidth', $q2->bindValue( $resolutions[$resolution]['width'] ) );
  202. $filterSQLArray[] = $q2->expr->eq( 'pheight', $q2->bindValue( $resolutions[$resolution]['height'] ) );
  203. }
  204. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  205. if ($direction == 'left') {
  206. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ( '.$q2->expr->lt( 'mtime', $q2->bindValue( $Image->mtime ) ). ' OR '.$q2->expr->eq( 'mtime', $q2->bindValue( $Image->mtime ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ).')' )
  207. ->orderBy('mtime DESC, pid DESC')
  208. ->limit( 6 );
  209. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  210. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  211. $imagesAjax = array_reverse($imagesAjax);
  212. } else {
  213. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->gt( 'mtime', $q2->bindValue( $Image->mtime ) ). ' OR '.$q2->expr->eq( 'mtime', $q2->bindValue( $Image->mtime ) ).' AND '.$q2->expr->gt( 'pid', $q2->bindValue( $Image->pid ) ) .')')
  214. ->orderBy('mtime ASC, pid ASC')
  215. ->limit( 6 );
  216. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  217. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  218. }
  219. $cache->store($cacheKeyImage,$imagesAjax,0);
  220. }
  221. } elseif ($modeSort == 'lastcommented') {
  222. $cache = CSCacheAPC::getMem();
  223. $cacheKeyImage = 'album_mode_image_ajaxslides_pid_sort_lastcommented_'.$Image->pid.'_lastcommented_version_'.$cache->getCacheVersion('last_commented_'.$Image->aid).'_version_'.$cache->getCacheVersion('album_'.$Image->aid).'_album_id_'.$Image->aid.'_direction_'.$direction.'_filter_'.erLhcoreClassGallery::multi_implode(',',$filterArray);
  224. if (($imagesAjax = $cache->restore($cacheKeyImage)) === false)
  225. {
  226. $session = erLhcoreClassGallery::getSession();
  227. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  228. $q2 = $q->subSelect();
  229. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  230. $filterSQLArray = array();
  231. $filterSQLString = '';
  232. $filterSQLArray[] = $q2->expr->eq( 'approved', $q2->bindValue( 1 ) );
  233. if ($resolution != '') {
  234. $filterSQLArray[] = $q2->expr->eq( 'pwidth', $q2->bindValue( $resolutions[$resolution]['width'] ) );
  235. $filterSQLArray[] = $q2->expr->eq( 'pheight', $q2->bindValue( $resolutions[$resolution]['height'] ) );
  236. }
  237. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  238. if ($direction == 'left') {
  239. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->gt( 'comtime', $q2->bindValue( $Image->comtime ) ). ' OR '.$q2->expr->eq( 'comtime', $q2->bindValue( $Image->comtime ) ).' AND '.$q2->expr->gt( 'pid', $q2->bindValue( $Image->pid ) ) .')')
  240. ->orderBy('comtime ASC, pid ASC')
  241. ->limit( 6 );
  242. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  243. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  244. $imagesAjax = array_reverse($imagesAjax);
  245. } else {
  246. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->lt( 'comtime', $q2->bindValue( $Image->comtime ) ). ' OR '.$q2->expr->eq( 'comtime', $q2->bindValue( $Image->comtime ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ) .')')
  247. ->orderBy('comtime DESC, pid DESC')
  248. ->limit( 6 );
  249. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  250. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  251. }
  252. $cache->store($cacheKeyImage,$imagesAjax,0);
  253. }
  254. } elseif ($modeSort == 'lastcommentedasc') {
  255. $cache = CSCacheAPC::getMem();
  256. $cacheKeyImage = 'album_mode_image_ajaxslides_pid_sort_lastcommentedasc_'.$Image->pid.'_lastcommented_version_'.$cache->getCacheVersion('last_commented_'.$Image->aid).'_version_'.$cache->getCacheVersion('album_'.$Image->aid).'_album_id_'.$Image->aid.'_direction_'.$direction.'_filter_'.erLhcoreClassGallery::multi_implode(',',$filterArray);
  257. if (($imagesAjax = $cache->restore($cacheKeyImage)) === false)
  258. {
  259. $session = erLhcoreClassGallery::getSession();
  260. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  261. $q2 = $q->subSelect();
  262. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  263. $filterSQLArray = array();
  264. $filterSQLString = '';
  265. $filterSQLArray[] = $q2->expr->eq( 'approved', $q2->bindValue( 1 ) );
  266. if ($resolution != '') {
  267. $filterSQLArray[] = $q2->expr->eq( 'pwidth', $q2->bindValue( $resolutions[$resolution]['width'] ) );
  268. $filterSQLArray[] = $q2->expr->eq( 'pheight', $q2->bindValue( $resolutions[$resolution]['height'] ) );
  269. }
  270. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  271. if ($direction == 'left') {
  272. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->lt( 'comtime', $q2->bindValue( $Image->comtime ) ). ' OR '.$q2->expr->eq( 'comtime', $q2->bindValue( $Image->comtime ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ).')' )
  273. ->orderBy('comtime DESC, pid DESC')
  274. ->limit( 6 );
  275. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  276. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  277. $imagesAjax = array_reverse($imagesAjax);
  278. } else {
  279. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->gt( 'comtime', $q2->bindValue( $Image->comtime ) ). ' OR '.$q2->expr->eq( 'comtime', $q2->bindValue( $Image->comtime ) ).' AND '.$q2->expr->gt( 'pid', $q2->bindValue( $Image->pid ) ) .')')
  280. ->orderBy('comtime ASC, pid ASC')
  281. ->limit( 6 );
  282. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  283. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  284. }
  285. $cache->store($cacheKeyImage,$imagesAjax,0);
  286. }
  287. } elseif ($modeSort == 'lastrated') {
  288. $cache = CSCacheAPC::getMem();
  289. $cacheKeyImage = 'album_mode_image_ajaxslides_pid_sort_lastrated_'.$Image->pid.'_lastrated_version_'.$cache->getCacheVersion('last_rated_'.$Image->aid).'_version_'.$cache->getCacheVersion('album_'.$Image->aid).'_album_id_'.$Image->aid.'_direction_'.$direction.'_filter_'.erLhcoreClassGallery::multi_implode(',',$filterArray);
  290. if (($imagesAjax = $cache->restore($cacheKeyImage)) === false)
  291. {
  292. $session = erLhcoreClassGallery::getSession();
  293. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  294. $q2 = $q->subSelect();
  295. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  296. $filterSQLArray = array();
  297. $filterSQLString = '';
  298. $filterSQLArray[] = $q2->expr->eq( 'approved', $q2->bindValue( 1 ) );
  299. if ($resolution != '') {
  300. $filterSQLArray[] = $q2->expr->eq( 'pwidth', $q2->bindValue( $resolutions[$resolution]['width'] ) );
  301. $filterSQLArray[] = $q2->expr->eq( 'pheight', $q2->bindValue( $resolutions[$resolution]['height'] ) );
  302. }
  303. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  304. if ($direction == 'left') {
  305. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->gt( 'rtime', $q2->bindValue( $Image->rtime ) ). ' OR '.$q2->expr->eq( 'rtime', $q2->bindValue( $Image->rtime ) ).' AND '.$q2->expr->gt( 'pid', $q2->bindValue( $Image->pid ) ) .')')
  306. ->orderBy('rtime ASC, pid ASC')
  307. ->limit( 6 );
  308. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  309. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  310. $imagesAjax = array_reverse($imagesAjax);
  311. } else {
  312. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->lt( 'rtime', $q2->bindValue( $Image->rtime ) ). ' OR '.$q2->expr->eq( 'rtime', $q2->bindValue( $Image->rtime ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ) .')')
  313. ->orderBy('rtime DESC, pid DESC')
  314. ->limit( 6 );
  315. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  316. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  317. }
  318. $cache->store($cacheKeyImage,$imagesAjax,0);
  319. }
  320. } elseif ($modeSort == 'lastratedasc') {
  321. $cache = CSCacheAPC::getMem();
  322. $cacheKeyImage = 'album_mode_image_ajaxslides_pid_sort_lastratedasc_'.$Image->pid.'_lastrated_version_'.$cache->getCacheVersion('last_rated_'.$Image->aid).'_version_'.$cache->getCacheVersion('album_'.$Image->aid).'_album_id_'.$Image->aid.'_direction_'.$direction.'_filter_'.erLhcoreClassGallery::multi_implode(',',$filterArray);
  323. if (($imagesAjax = $cache->restore($cacheKeyImage)) === false)
  324. {
  325. $session = erLhcoreClassGallery::getSession();
  326. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  327. $q2 = $q->subSelect();
  328. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  329. $filterSQLArray = array();
  330. $filterSQLString = '';
  331. $filterSQLArray[] = $q2->expr->eq( 'approved', $q2->bindValue( 1 ) );
  332. if ($resolution != '') {
  333. $filterSQLArray[] = $q2->expr->eq( 'pwidth', $q2->bindValue( $resolutions[$resolution]['width'] ) );
  334. $filterSQLArray[] = $q2->expr->eq( 'pheight', $q2->bindValue( $resolutions[$resolution]['height'] ) );
  335. }
  336. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  337. if ($direction == 'left') {
  338. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->lt( 'rtime', $q2->bindValue( $Image->rtime ) ). ' OR '.$q2->expr->eq( 'rtime', $q2->bindValue( $Image->rtime ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ).')' )
  339. ->orderBy('rtime DESC, pid DESC')
  340. ->limit( 6 );
  341. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  342. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  343. $imagesAjax = array_reverse($imagesAjax);
  344. } else {
  345. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->gt( 'rtime', $q2->bindValue( $Image->rtime ) ). ' OR '.$q2->expr->eq( 'rtime', $q2->bindValue( $Image->rtime ) ).' AND '.$q2->expr->gt( 'pid', $q2->bindValue( $Image->pid ) ) .')')
  346. ->orderBy('rtime ASC, pid ASC')
  347. ->limit( 6 );
  348. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  349. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  350. }
  351. $cache->store($cacheKeyImage,$imagesAjax,0);
  352. }
  353. } elseif ($modeSort == 'toprated') {
  354. $cache = CSCacheAPC::getMem();
  355. $cacheKeyImage = 'album_mode_image_ajaxslides_pid_sort_toprated_'.$Image->pid.'_toprated_version_'.$cache->getCacheVersion('top_rated_'.$Image->aid).'_version_'.$cache->getCacheVersion('album_'.$Image->aid).'_album_id_'.$Image->aid.'_direction_'.$direction.'_filter_'.erLhcoreClassGallery::multi_implode(',',$filterArray);
  356. if (($imagesAjax = $cache->restore($cacheKeyImage)) === false)
  357. {
  358. $session = erLhcoreClassGallery::getSession();
  359. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  360. $q2 = $q->subSelect();
  361. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  362. $filterSQLArray = array();
  363. $filterSQLString = '';
  364. $filterSQLArray[] = $q2->expr->eq( 'approved', $q2->bindValue( 1 ) );
  365. if ($resolution != '') {
  366. $filterSQLArray[] = $q2->expr->eq( 'pwidth', $q2->bindValue( $resolutions[$resolution]['width'] ) );
  367. $filterSQLArray[] = $q2->expr->eq( 'pheight', $q2->bindValue( $resolutions[$resolution]['height'] ) );
  368. }
  369. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  370. if ($direction == 'left') {
  371. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->gt( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ). ' OR '.$q2->expr->eq( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ).' AND '.$q2->expr->gt( 'votes', $q2->bindValue( $Image->votes ) ).' OR '.$q2->expr->eq( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ).' AND '.$q2->expr->eq( 'votes', $q2->bindValue( $Image->votes ) ).' AND '.$q2->expr->gt( 'pid', $q2->bindValue( $Image->pid ) ).')')
  372. ->orderBy('pic_rating ASC, votes ASC, pid ASC')
  373. ->limit( 6 );
  374. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  375. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  376. $imagesAjax = array_reverse($imagesAjax);
  377. } else {
  378. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->lt( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ). ' OR '.$q2->expr->eq( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ).' AND '.$q2->expr->lt( 'votes', $q2->bindValue( $Image->votes ) ).' OR '.$q2->expr->eq( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ).' AND '.$q2->expr->eq( 'votes', $q2->bindValue( $Image->votes ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ).')')
  379. ->orderBy('pic_rating DESC, votes DESC, pid DESC')
  380. ->limit( 6 );
  381. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  382. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  383. }
  384. $cache->store($cacheKeyImage,$imagesAjax,0);
  385. }
  386. } elseif ($modeSort == 'topratedasc') {
  387. $cache = CSCacheAPC::getMem();
  388. $cacheKeyImage = 'album_mode_image_ajaxslides_pid_sort_topratedasc_'.$Image->pid.'_toprated_version_'.$cache->getCacheVersion('top_rated_'.$Image->aid).'_version_'.$cache->getCacheVersion('album_'.$Image->aid).'_album_id_'.$Image->aid.'_direction_'.$direction.'_filter_'.erLhcoreClassGallery::multi_implode(',',$filterArray);
  389. if (($imagesAjax = $cache->restore($cacheKeyImage)) === false)
  390. {
  391. $session = erLhcoreClassGallery::getSession();
  392. $q = $session->createFindQuery( 'erLhcoreClassModelGalleryImage', $ignore_fields );
  393. $q2 = $q->subSelect();
  394. $q2->select( 'pid' )->from( 'lh_gallery_images' );
  395. $filterSQLArray = array();
  396. $filterSQLString = '';
  397. $filterSQLArray[] = $q2->expr->eq( 'approved', $q2->bindValue( 1 ) );
  398. if ($resolution != '') {
  399. $filterSQLArray[] = $q2->expr->eq( 'pwidth', $q2->bindValue( $resolutions[$resolution]['width'] ) );
  400. $filterSQLArray[] = $q2->expr->eq( 'pheight', $q2->bindValue( $resolutions[$resolution]['height'] ) );
  401. }
  402. $filterSQLString = implode(' AND ',$filterSQLArray).' AND ';
  403. if ($direction == 'left') {
  404. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->lt( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ). ' OR '.$q2->expr->eq( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ).' AND '.$q2->expr->lt( 'votes', $q2->bindValue( $Image->votes ) ).' OR '.$q2->expr->eq( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ).' AND '.$q2->expr->eq( 'votes', $q2->bindValue( $Image->votes ) ).' AND '.$q2->expr->lt( 'pid', $q2->bindValue( $Image->pid ) ).')')
  405. ->orderBy('pic_rating DESC, votes DESC, pid DESC')
  406. ->limit( 6 );
  407. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  408. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  409. $imagesAjax = array_reverse($imagesAjax);
  410. } else {
  411. $q2->where( $filterSQLString.$q2->expr->eq( 'aid', $q2->bindValue( $Image->aid ) ).' AND ('.$q2->expr->gt( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ). ' OR '.$q2->expr->eq( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ).' AND '.$q2->expr->gt( 'votes', $q2->bindValue( $Image->votes ) ).' OR '.$q2->expr->eq( 'pic_rating', $q2->bindValue( $Image->pic_rating ) ).' AND '.$q2->expr->eq( 'votes', $q2->bindValue( $Image->votes ) ).' AND '.$q2->expr->gt( 'pid', $q2->bindValue( $Image->pid ) ).')')
  412. ->orderBy('pic_rating ASC, votes ASC, pid ASC')
  413. ->limit( 6 );
  414. $q->innerJoin( $q->alias( $q2, 'items' ), 'lh_gallery_images.pid', 'items.pid' );
  415. $imagesAjax = $session->find( $q, 'erLhcoreClassModelGalleryImage' );
  416. }
  417. $cache->store($cacheKeyImage,$imagesAjax,0);
  418. }
  419. }
  420. $hasMoreImages = 'false';
  421. if (count($imagesAjax) > 5) {
  422. $hasMoreImages = 'true';
  423. if ($direction == 'left') {
  424. $imagesAjax = array_slice($imagesAjax,1,5);
  425. } else {
  426. $imagesAjax = array_slice($imagesAjax,0,5);
  427. }
  428. }
  429. $imagesFound = count($imagesAjax);
  430. reset($imagesAjax);
  431. $ImageLast = current($imagesAjax);
  432. $LeftImagePID = $ImageLast->pid;
  433. end($imagesAjax);
  434. $ImageLast = current($imagesAjax);
  435. $RightImagePID = $ImageLast->pid;
  436. $tpl->set('imagesAjax',$imagesAjax);
  437. $urlAppend = $modeSort != 'new' ? '/(sort)/'.$modeSort : '';
  438. $urlAppend .= $appendResolutionMode;
  439. $tpl->set('urlAppend',$urlAppend);
  440. } elseif ($mode == 'search') {
  441. $sortModes = array(
  442. 'new' => '@id DESC',
  443. 'newasc' => '@id ASC',
  444. 'popular' => 'hits DESC, @id DESC',
  445. 'popularasc' => 'hits ASC, @id ASC',
  446. 'lasthits' => 'mtime DESC, @id DESC',
  447. 'lasthitsasc' => 'mtime ASC, @id ASC',
  448. 'lastcommented' => 'comtime DESC, @id DESC',
  449. 'lastcommentedasc' => 'comtime ASC, @id ASC',
  450. 'toprated' => 'pic_rating DESC, votes DESC, @id DESC',
  451. 'topratedasc' => 'pic_rating ASC, votes ASC, @id ASC',
  452. 'relevance' => '@relevance DESC, @id DESC',
  453. 'relevanceasc' => '@relevance ASC, @id ASC',
  454. 'lastrated' => 'rtime DESC, @id DESC',
  455. 'lastratedasc' => 'rtime ASC, @id ASC'
  456. );
  457. $modeSort = isset($Params['user_parameters_unordered']['sort']) && key_exists($Params['user_parameters_unordered']['sort'],$sortModes) ? $Params['user_parameters_unordered']['sort'] : 'relevance';
  458. $modeSQL = $sortModes[$modeSort];
  459. $imagesAjax = array();
  460. // Because sphinx view already includes this filter
  461. unset($filterArray['approved']);
  462. $filterColor = array();
  463. $nfilterColor = array();
  464. // Color filter in search mode
  465. $appendColorMode = '';
  466. $pallete_id = (array)$Params['user_parameters_unordered']['color'];
  467. $npallete_id = (array)$Params['user_parameters_unordered']['ncolor'];
  468. sort($pallete_id);
  469. sort($npallete_id);
  470. $pallete_items_number = count($pallete_id);
  471. if ($pallete_items_number > 0) {
  472. if ($pallete_items_number > erConfigClassLhConfig::getInstance()->getSetting( 'color_search', 'maximum_filters')) {
  473. $pallete_id = array_slice($pallete_id,0,erConfigClassLhConfig::getInstance()->getSetting( 'color_search', 'maximum_filters'));
  474. $pallete_items_number = erConfigClassLhConfig::getInstance()->getSetting( 'color_search', 'maximum_filters');
  475. }
  476. $filterColor = $pallete_id;
  477. $appendColorMode = '/(color)/'.implode('/',$pallete_id);
  478. }
  479. $npallete_items_number = count($npallete_id);
  480. if ($npallete_items_number > 0) {
  481. if ($npallete_items_number > erConfigClassLhConfig::getInstance()->getSetting( 'color_search', 'maximum_filters')) {
  482. $npallete_id = array_slice($npallete_id,0,erConfigClassLhConfig::getInstance()->getSetting( 'color_search', 'maximum_filters'));
  483. $npallete_items_number = erConfigClassLhConfig::getInstance()->getSetting( 'color_search', 'maximum_filters');
  484. }
  485. $nfilterColor = $npallete_id;
  486. $appendColorMode .= '/(ncolor)/'.implode('/',$npallete_id);
  487. }
  488. $keywordDecoded = trim(str_replace('+',' ',urldecode($Params['user_parameters_unordered']['keyword'])));
  489. $hasMoreImages = 'false';
  490. if ($modeSort == 'relevance') {
  491. $relevanceCurrentImage = erLhcoreClassGallery::searchSphinx(array('MatchMode' => $modeMatch, 'color_filter' => $filterColor, 'ncolor_filter' => $nfilterColor,'relevance' => true, 'SearchLimit' => 1,'keyword' => $keywordDecoded,'sort' => '@relevance DESC, @id DESC','Filter' => array('@id' => $Image->pid)));
  492. if ($direction == 'left') {
  493. $totalPhotos = erLhcoreClassGallery::searchSphinx(array('ignore_fields' => $ignore_fields, 'MatchMode' => $modeMatch, 'ncolor_filter' => $nfilterColor, 'color_filter' => $filterColor,'filtergt' => array('pid' => $Image->pid),'Filter' => (array)$filterArray+array('@weight' => $relevanceCurrentImage),'SearchLimit' => 6,'keyword' => $keywordDecoded,'sort' => '@relevance ASC, @id ASC'));
  494. if ($totalPhotos['total_found'] < 6) { // We have check is there any better matches images on left
  495. $totalPhotosHigher = erLhcoreClassGallery::searchSphinx(array('ignore_fields' => $ignore_fields, 'MatchMode' => $modeMatch, 'ncolor_filter' => $nfilterColor, 'color_filter' => $filterColor,'filtergt' => array('@weight' => $relevanceCurrentImage),'Filter' => $filterArray,'SearchLimit' => 6,'keyword' => $keywordDecoded,'sort' => '@relevance ASC, @id ASC'));
  496. if ($totalPhotosHigher['total_found'] > 0 && $totalPhotos['total_found'] > 0) {
  497. $totalPhotos['list'] = (array)$totalPhotos['list'] + (array)$totalPhotosHigher['list'];
  498. } elseif ($totalPhotosHigher['total_found'] > 0) {
  499. $totalPhotos['list'] = $totalPhotosHigher['list'];
  500. }
  501. $totalPhotos['total_found'] += $totalPhotosHigher['total_found'];
  502. }
  503. if ($totalPhotos['total_found'] > 0){
  504. $imagesAjax = $totalPhotos['list'];
  505. if (count($imagesAjax) > 5) {
  506. $imagesAjax = array_slice($imagesAjax,0,5);
  507. $hasMoreImages = 'true';
  508. }
  509. $imagesAjax = array_reverse($imagesAjax);
  510. }
  511. } else {
  512. $totalPhotos = erLhcoreClassGallery::searchSphinx(array('ignore_fields' => $ignore_fields, 'MatchMode' => $modeMatch, 'ncolor_filter' => $nfilterColor, 'color_filter' => $filterColor,'filterlt' => array('pid' => $Image->pid-1),'Filter' => (array)$filterArray+array('@weight' => $relevanceCurrentImage),'SearchLimit' => 6,'keyword' => $keywordDecoded,'sort' => '@relevance DESC, @id DESC'));
  513. if ($totalPhotos['total_found'] < 6) { // We have check is there any better matches images on left
  514. $totalPhotosHigher = erLhcoreClassGallery::searchSphinx(array('ignore_fields' => $ignore_fields, 'MatchMode' => $modeMatch, 'ncolor_filter' => $nfilterColor, 'color_filter' => $filterColor,'filterlt' => array('@weight' => $relevanceCurrentImage-1),'Filter' => $filterArray,'SearchLimit' => 6,'keyword' => $keywordDecoded,'sort' => '@relevance DESC, @id DESC'));
  515. if ($totalPhotosHigher['total_found'] > 0 && $totalPhotos['total_found'] > 0) {
  516. $totalPhotos['list'] = (array)$totalPhotos['list'] + (array)$totalPhotosHigher['list'];
  517. } elseif ($totalPhotosHigher['total_found'] > 0) {
  518. $totalPhotos['list'] = $totalPhotosHigher['list'];
  519. }
  520. $totalPhotos['total_found'] += $totalPhotosHigher['total_found'];
  521. }
  522. if ($totalPhotos['total_found'] > 0){
  523. $imagesAjax = $totalPhotos['list'];
  524. }
  525. }
  526. } elseif ($modeSort == 'relevanceasc') {
  527. $relevanceCurrentImage = erLhcoreClassGallery::searchSphinx(array('ignore_fields' => $ignore_fields, 'MatchMode' => $modeMatch, 'ncolor_filter' => $nfilterColor, 'color_filter' => $filterColor,'relevance' => true, 'SearchLimit' => 1,'keyword' => $keywordDecoded,'sort' => '@relevance DESC, @id DESC','Filter' => array('@id' => $Image->pid)));
  528. if ($direction == 'left') {
  529. $totalPhotos = erLhcoreClassGallery::searchSphinx(array('ignore_fields' => $ignore_fields, 'MatchMode' => $modeMatch, 'ncolor_filter' => $nfilterColor, 'color_filter' => $filterColor,'filterlt' => array('pid' => $Image->pid-1),'Filter' => (array)$filterArray+array('@weight' => $relevanceCurrentImage),'SearchLimit' => 6,'keyword' => $keywordDecoded,'sort' => '@relevance DESC, @id DESC'));
  530. if ($totalPhotos['total_found'] < 6) { // We have check is there any better matches images on left
  531. $totalPhotosHigher = erLhcoreClassGallery::searchSphinx(array('MatchMode' => $modeMatch, 'ncolor_filter' => $nfilterColor, 'color_filter' => $filterColor,'filterlt' => array('@weight' => $relevanceCurrentImage-1),'Filter' => $filterArray,'SearchLimit' => 6,'keyword' => $keywordDecoded,'sort' => '@relevance DESC, @id DESC'));
  532. if ($totalPhotosHigher['total_found'] > 0 && $totalPhotos['total_found'] > 0) {
  533. $totalPhotos['list'] = (array)$totalPhotos['list'] + (array)$totalPhotosHigher['list'];
  534. } elseif ($totalPhotosHigher['total_found'] > 0) {
  535. $totalPhotos['list'] = $totalPhotosHigher['list'];
  536. }
  537. $totalPhotos['total_found'] += $totalPhotosHigher['total_found'];
  538. }
  539. if ($totalPhotos['total_found'] > 0){
  540. $imagesAjax = $totalPhotos['list'];
  541. if (count($imagesAjax) > 5) {
  542. $imagesAjax = array_slice($imagesAjax,0,5);
  543. $hasMoreImages = 'true';
  544. }
  545. $imagesAjax = array_reverse($imagesAjax);
  546. }
  547. } else {
  548. $totalPhotos = erLhcoreClassGallery::searchSphinx(array('ignore_fields' => $ignore_fields, 'MatchMode' => $modeMatch, 'ncolor_filter' => $nfilterColor, 'color_filter' => $filterColor,'filtergt' => array('pid' => $Image->pid),'Filter' => (array)$filterArray+array('@weight' => $relevanceCurrentImage),'SearchLimit' => 6,'keyword' => $keywordDecoded,'sort' => '@relevance ASC, @id ASC'));
  549. if ($totalPhotos['total_found'] < 6) { // We have check is there any better matches images on left
  550. $totalPhotosHigher = erLhcoreClassGallery::searchSphinx(array('ignore_fields' => $ignore_fields, 'MatchMode' => $modeMatch, 'ncolor_filter' => $nfilterColor, 'color_filter' => $filterColor,'filtergt' => array('@weight' => $relevanceCurrentImage),'Filter' => $filterArray,'SearchLimit' => 6,'keyword' => $keywordDecoded,'sort' => '@relevance ASC, @id ASC'));
  551. if ($totalPhotosHigher['total_found'] > 0 && $totalPhotos['total_found'] > 0) {
  552. $totalPhotos['list'] = (array)$totalPhotos['list'] + (array)$totalPhotosHigher['list'];
  553. } elseif ($totalPhotosHigher['total_found'] > 0) {
  554. $totalPhotos['list'] = $totalPhotosHigher['list'];
  555. }
  556. $totalPhotos['total_found'] += $totalPhotosHigher['total_found'];
  557. }
  558. if ($totalPhotos['total_found'] > 0):
  559. $imagesAjax = $totalPhotos['list'];
  560. endif;
  561. }
  562. } elseif ($modeSort == 'new') {
  563. if ($direction == 'left'){
  564. $totalPhotos = erLhcoreClassGallery::searchSphinx(array('ignore_fields' => $ignore_fields, 'MatchMode' => $modeMatch, 'ncolor_filter' => $nfilterColor, 'color_filter' => $filterColor,'SearchLimit' => 6,'keyword' => $keywordDecoded,'sort' => '@id ASC','Filter' => $filterArray,'filtergt' => array('pid' => $Image->pid)));
  565. if ($totalPhotos['total_found'] > 0):
  566. $imagesAjax = $totalPhotos['list'];
  567. $imagesAjax = array_reverse($imagesAjax);
  568. endif;
  569. } else {
  570. $totalPhotos = erLhcoreClassGallery::searchSphinx(array('ignore_fields' => $ignore_fields, 'MatchMode' => $modeMatch, 'ncolor_filter' => $nfilterColor, 'color_filter' => $filterColor,'SearchLimit' => 6,'keyword' => $keywordDecoded,'sort' => '@id DESC','Filter' => $filterArray,'filterlt' => array('pid' => $Image->pid-1)));
  571. if ($totalPhotos['total_found'] > 0):
  572. $imagesAjax = $totalPhotos['list'];
  573. endif;
  574. }
  575. } elseif ($modeSort == 'newasc') {
  576. if ($direction == 'left'){
  577. $totalPhotos = erLhcoreClassGallery::searchSphinx(array('ignore_fields' => $ignore_fields, 'MatchMode' => $modeMatch, 'ncolor_filter' => $nfilterColor, 'color_filter' => $filterColor,'SearchLimit' => 6,'keyword' => $keywordDecoded,'sort' => '@id DESC','Filter' => $filterArray,'filterlt' => array('pid' => $Image->pid-1)));
  578. if ($totalPhotos['total_found'] > 0):
  579. $imagesAjax = $totalPhotos['list'];
  580. $imagesAjax = array_reverse($imagesAjax);
  581. endif;
  582. } else {
  583. $totalPhotos = erLhcoreClassGallery::searchSphinx(array('ignore_fields' => $ignore_fields, 'MatchMode' => $modeMatch, 'ncolor_filter' => $nfilterColor, 'color_filter' => $filterColor,'SearchLimit' => 6,'keyword' => $keywordDecoded,'sort' => '@id ASC','Filter' => $filterArray,'filtergt' => array('pid' => $Image->pid)));
  584. if ($totalPhotos['total_found'] > 0):
  585. $imagesAjax = $totalPhotos['list'];
  586. endif;
  587. }
  588. } elseif ($modeSort == 'popular') {
  589. if ($direction == 'left'){
  590. $totalPhotos = erLhcoreClassGallery::searchSphinx(array('ignore_fields' => $ignore_fields, 'MatchMode' => $modeMatch, 'ncolor_filter' => $nfilterColor, 'color_filter' => $filterColor,'custom_filter' => array('filter_name' => 'myfilter','filter' => 'hits,(hits > '.$Image->hits.' OR (hits = '.$Image->hits.' AND @id > '.$Image->pid.')) AS myfilter'),'Filter' => $filterArray,'SearchLimit' => 6,'keyword' => $keywordDecoded,'sort' => 'hits ASC, @id ASC'));
  591. if ($totalPhotos['total_found'] > 0):
  592. $imagesAjax = $totalPhotos['list'];
  593. $imagesAjax = array_reverse($imagesAjax);
  594. endif;
  595. } else {
  596. $totalPhotos = erLhcoreClassGallery::searchSphinx(array('ignore_fields' => $ignore_fields, 'MatchMode' => $modeMatch, 'ncolor_filter' => $nfilterColor, 'color_filter' => $filterColor,'custom_filter' => array('filter_name' => 'myfilter','filter' => 'hits,(hits < '.$Image->hits.' OR (hits = '.$Image->hits.' AND @id < '.$Image->pid.')) AS myfilter'),'Filter' => $filterArray,'SearchLimit' => 6,'keyword' => $keywordDecoded,'sort' => 'hits DESC, @id DESC'));
  597. if ($totalPhotos['total_found'] > 0):
  598. $imagesAjax = $totalPhotos['list'];
  599. endif;
  600. }
  601. } elseif ($modeSort == 'popularasc') {
  602. if ($direction

Large files files are truncated, but you can click here to view the full file