1. <?php
  2. /*
  3. * @package Joomla 1.5
  4. * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
  5. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  6. *
  7. * @component Phoca Component
  8. * @copyright Copyright (C) Jan Pavelka www.phoca.cz
  9. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  10. */
  11. defined('_JEXEC') or die();
  12. jimport( 'joomla.application.component.view');
  13. phocagalleryimport('phocagallery.access.access');
  14. phocagalleryimport('phocagallery.path.path');
  15. phocagalleryimport('phocagallery.file.file');
  16. phocagalleryimport('phocagallery.render.renderinfo');
  17. phocagalleryimport('phocagallery.picasa.picasa');
  18.  
  19. class PhocaGalleryViewCategories extends JView
  20. {
  21. function display($tpl = null) {
  22.  
  23. global $mainframe;
  24. $user = &JFactory::getUser();
  25. $uri = &JFactory::getURI();
  26. $path = &PhocaGalleryPath::getPath();
  27. $params = &$mainframe->getParams();
  28. $tmpl = array();
  29. $tmplGeo = array();
  30.  
  31. $this->_setLibraries();
  32.  
  33. // PARAMS - - - - - - - - - -
  34. $image_categories_size = $params->get( 'image_categories_size', 4 );
  35. $medium_image_width = (int)$params->get( 'medium_image_width', 100 ) + 18;
  36. $medium_image_height = (int)$params->get( 'medium_image_height', 100 ) + 18;
  37. $small_image_width = (int)$params->get( 'small_image_width', 50 ) + 18;
  38. $small_image_height = (int)$params->get( 'small_image_height', 50 ) + 18;
  39. $tmpl['phocagallerywidth'] = $params->get( 'phocagallery_width', '' );
  40. $tmpl['categoriescolumns'] = $params->get( 'categories_columns', 1 );
  41. $tmpl['displayrating'] = $params->get( 'display_rating', 0 );
  42. $tmpl['phocagallerycenter'] = $params->get( 'phocagallery_center', '');
  43. $tmpl['categoriesimageordering']= $params->get( 'categories_image_ordering', 9 );
  44. $tmpl['displayimagecategories'] = $params->get( 'display_image_categories', 1 );// Display or hide image beside the category name
  45. $display_categories_geotagging = $params->get( 'display_categories_geotagging', 0 );// Display Geo CATEGORIES VIEW
  46. // Access Category - display category in CATEGORIES VIEW, which user cannot access
  47. $display_access_category = $params->get( 'display_access_category', 1 );
  48. $display_empty_categories = $params->get( 'display_empty_categories', 0 );
  49. $hideCatArray = explode( ';', trim( $params->get( 'hide_categories', '' ) ) );
  50. $tmpl['equalpercentagewidth'] = $params->get( 'equal_percentage_width');
  51. $tmpl['categoriesdisplayavatar']= $params->get( 'categories_display_avatar');
  52. $tmpl['categoriesboxwidth'] = $params->get( 'categories_box_width');
  53. $tmpl['gallerymetakey'] = $params->get( 'gallery_metakey', '' );
  54. $tmpl['gallerymetadesc'] = $params->get( 'gallery_metadesc', '' );
  55.  
  56.  
  57.  
  58.  
  59.  
  60. // Correct Picasa Images - get Info
  61. switch($image_categories_size) {
  62. // medium
  63. case 1:
  64. case 5:
  65. $tmpl['picasa_correct_width'] = (int)$params->get( 'medium_image_width', 100 );
  66. $tmpl['picasa_correct_height'] = (int)$params->get( 'medium_image_height', 100 );
  67. break;
  68.  
  69. case 0:
  70. case 4:
  71. default:
  72. $tmpl['picasa_correct_width'] = (int)$params->get( 'small_image_width', 50 );
  73. $tmpl['picasa_correct_height'] = (int)$params->get( 'small_image_height', 50 );
  74. break;
  75. }
  76.  
  77. // - - - - - - - - - - - - - - -
  78.  
  79. // Get background for the image
  80. phocagalleryimport('phocagallery.image.imagefront');
  81. $catImg = PhocaGalleryImageFront::getCategoriesImageBackground($image_categories_size, $small_image_width, $small_image_height, $medium_image_height, $medium_image_width);
  82.  
  83. $tmpl['imagebg'] = $catImg->image;
  84. $tmpl['imagewidth'] = $catImg->width;
  85.  
  86.  
  87. //$total = $this->get('total');
  88. //$tmpl['pagination'] = &$this->get('pagination');
  89.  
  90. // Image next to Category in Categories View is ordered by Random as default
  91. phocagalleryimport('phocagallery.ordering.ordering');
  92. $categoriesImageOrdering = PhocaGalleryOrdering::getOrderingString($tmpl['categoriesimageordering']);
  93.  
  94. // MODEL
  95. $model = &$this->getModel();
  96. $items = $this->get('data');
  97.  
  98.  
  99. // Add link and unset the categories which user cannot see (if it is enabled in params)
  100. // If it will be unset while access view, we must sort the keys from category array - ACCESS
  101. $unSet = 0;
  102.  
  103. foreach ($items as $key => $item) {
  104.  
  105. // Unset empty categories if it is set
  106. if ($display_empty_categories == 0) {
  107. if($items[$key]->numlinks < 1) {
  108. unset($items[$key]);
  109. $unSet = 1;
  110. continue;
  111. }
  112. }
  113.  
  114. // Unset hidden category
  115. if (!empty($hideCatArray) && is_array($hideCatArray)) {
  116. $unSetHCA = 0;
  117. foreach ($hideCatArray as $valueHCA) {
  118. if((int)trim($valueHCA) == $items[$key]->id) {
  119. unset($items[$key]);
  120. $unSet = 1;
  121. $unSetHCA = 1;
  122. break;
  123. }
  124. }
  125. if ($unSetHCA == 1) {
  126. continue;
  127. }
  128. }
  129.  
  130.  
  131. // Link
  132. $items[$key]->link = JRoute::_('index.php?option=com_phocagallery&view=category&id='. $item->slug.'&Itemid='. JRequest::getVar('Itemid', 0, '', 'int') );
  133.  
  134. // USER RIGHT - ACCESS - - - - -
  135. // First Check - check if we can display category
  136. $rightDisplay = 1;
  137. if (!empty($items[$key])) {
  138.  
  139. $rightDisplay = PhocaGalleryAccess::getUserRight('accessuserid', $items[$key]->accessuserid, $items[$key]->access, $user->get('aid', 0), $user->get('id', 0), $display_access_category);
  140. }
  141. // Second Check - if we can display hidden category, set Key icon for them
  142. // if we don't have access right to see them
  143. // Display Key Icon (in case we want to display unaccessable categories in list view)
  144. $rightDisplayKey = 1;
  145.  
  146. if ($display_access_category == 1) {
  147. // we simulate that we want not to display unaccessable categories
  148. // so if we get rightDisplayKey = 0 then the key will be displayed
  149. if (!empty($items[$key])) {
  150. $rightDisplayKey = PhocaGalleryAccess::getUserRight('accessuserid', $items[$key]->accessuserid, $items[$key]->access, $user->get('aid', 0), $user->get('id', 0), 0); // 0 - simulation
  151. }
  152. }
  153.  
  154. // DISPLAY AVATAR, IMAGE(ordered), IMAGE(not ordered, not recursive) OR FOLDER ICON
  155. $displayAvatar = 0;
  156. if($tmpl['categoriesdisplayavatar'] == 1 && isset($items[$key]->avatar) && $items[$key]->avatar !='' && $items[$key]->avatarapproved == 1 && $items[$key]->avatarpublished == 1) {
  157. $sizeString = PhocaGalleryImageFront::getSizeString($image_categories_size);
  158. $pathAvatarAbs = $path->avatar_abs .'thumbs'.DS.'phoca_thumb_'.$sizeString.'_'. $items[$key]->avatar;
  159. $pathAvatarRel = $path->avatar_rel . 'thumbs/phoca_thumb_'.$sizeString.'_'. $items[$key]->avatar;
  160. if (JFile::exists($pathAvatarAbs)){
  161. $items[$key]->linkthumbnailpath = $pathAvatarRel;
  162. $displayAvatar = 1;
  163. }
  164. }
  165. if ($displayAvatar == 0) {
  166. if (isset($items[$key]->extid) && $items[$key]->extid != '') {
  167. if ($tmpl['categoriesimageordering'] != 10) {
  168. $imagePic = PhocaGalleryImageFront::getRandomImageRecursive($items[$key]->id, $categoriesImageOrdering, 1);
  169. $fileThumbnail = PhocaGalleryImageFront::displayCategoriesExtImgOrFolder($imagePic->exts,$imagePic->extm, $imagePic->extw,$imagePic->exth, $image_categories_size, $rightDisplayKey);
  170. } else {
  171. $fileThumbnail = PhocaGalleryImageFront::displayCategoriesExtImgOrFolder($items[$key]->exts,$items[$key]->extm, $items[$key]->extw, $items[$key]->exth, $image_categories_size, $rightDisplayKey);
  172. }
  173.  
  174. $items[$key]->linkthumbnailpath = $fileThumbnail->rel;
  175. $items[$key]->extw = $fileThumbnail->extw;
  176. $items[$key]->exth = $fileThumbnail->exth;
  177. $items[$key]->extpic = $fileThumbnail->extpic;
  178. } else {
  179. if ($tmpl['categoriesimageordering'] != 10) {
  180. $items[$key]->filename = PhocaGalleryImageFront::getRandomImageRecursive($items[$key]->id, $categoriesImageOrdering);
  181. }
  182. $fileThumbnail = PhocaGalleryImageFront::displayCategoriesImageOrFolder($items[$key]->filename, $image_categories_size, $rightDisplayKey);
  183. $items[$key]->linkthumbnailpath = $fileThumbnail->rel;
  184. }
  185. }
  186.  
  187. if ($rightDisplay == 0) {
  188. unset($items[$key]);
  189. $unSet = 1;
  190. }
  191. // - - - - - - - - - - - - - - -
  192.  
  193. }
  194.  
  195. $tmpl['mtb'] = PhocaGalleryRenderInfo::getPhocaIc((int)$params->get( 'display_phoca_info', 1 ));
  196.  
  197. // ACCESS - - - - - -
  198. // In case we unset some category from the list, we must sort the array new
  199. if ($unSet == 1) {
  200. $items = array_values($items);
  201. }
  202. // - - - - - - - - - - - - - - - -
  203.  
  204. // Do Pagination - we can do it after reducing all unneeded items, not before
  205. $totalCount = count($items);
  206. $model->setTotal($totalCount);
  207. $tmpl['pagination'] = &$this->get('pagination');
  208. $items = array_slice($items,(int)$tmpl['pagination']->limitstart, (int)$tmpl['pagination']->limit);
  209. // - - - - - - - - - - - - - - - -
  210.  
  211.  
  212. // Display Image of Categories Description
  213. if ($params->get('image') != -1) {
  214. $attribs['align'] = $params->get('image_align');
  215. $attribs['hspace'] = 6;
  216. // Use the static HTML library to build the image tag
  217. $tmpl['image'] = JHTML::_('image', 'images/stories/'.$params->get('image'), JText::_('Phoca Gallery'), $attribs);
  218. }
  219. $tmpl['ab'] = base64_decode('PGRpdiBzdHlsZT0idGV4dC1hbGlnbjogY2VudGVyOyBjb2xvcjogcmdiKDIxMSwgMjExLCAyMTEpOyI+UG93ZXJlZCBieSA8YSBocmVmPSJodHRwOi8vd3d3LnBob2NhLmN6IiBzdHlsZT0idGV4dC1kZWNvcmF0aW9uOiBub25lOyIgdGFyZ2V0PSJfYmxhbmsiIHRpdGxlPSJQaG9jYS5jeiI+UGhvY2E8L2E+IDxhIGhyZWY9Imh0dHA6Ly93d3cucGhvY2EuY3ovcGhvY2FnYWxsZXJ5IiBzdHlsZT0idGV4dC1kZWNvcmF0aW9uOiBub25lOyIgdGFyZ2V0PSJfYmxhbmsiIHRpdGxlPSJQaG9jYSBHYWxsZXJ5Ij5HYWxsZXJ5PC9hPjwvZGl2Pg0K');
  220. // ACTION
  221. $tmpl['action'] = $uri->toString();
  222.  
  223. // ASSIGN
  224. $this->assignRef('tmpl', $tmpl);
  225. $this->assignRef('params', $params);
  226. $this->assignRef('categories', $items);
  227.  
  228. // Meta data
  229. if ($tmpl['gallerymetakey'] != '') {
  230. $mainframe->addMetaTag('keywords', $tmpl['gallerymetakey']);
  231. }
  232. if ($tmpl['gallerymetadesc'] != '') {
  233. $mainframe->addMetaTag('description', $tmpl['gallerymetadesc']);
  234. }
  235.  
  236.  
  237. if ($display_categories_geotagging == 1) {
  238.  
  239. // PARAMS - - - - - - - - - -
  240. $tmplGeo['categorieslng'] = $params->get( 'categories_lng', '' );
  241. $tmplGeo['categorieslat'] = $params->get( 'categories_lat', '' );
  242. $tmplGeo['categorieszoom'] = $params->get( 'categories_zoom', 2 );
  243. $tmplGeo['googlemapsapikey'] = $params->get( 'google_maps_api_key', '' );
  244. $tmplGeo['categoriesmapwidth'] = $params->get( 'categories_map_width', '' );
  245. $tmplGeo['categoriesmapheight'] = $params->get( 'categorires_map_height', 500 );
  246. // - - - - - - - - - - - - - - -
  247.  
  248. // if no lng and lat will be added, Phoca Gallery will try to find it in categories
  249. if ($tmplGeo['categorieslat'] == '' || $tmplGeo['categorieslng'] == '') {
  250. phocagalleryimport('phocagallery.geo.geo');
  251. $latLng = PhocaGalleryGeo::findLatLngFromCategory($items);
  252. $tmplGeo['categorieslng'] = $latLng['lng'];
  253. $tmplGeo['categorieslat'] = $latLng['lat'];
  254. }
  255.  
  256. $this->assignRef('tmplGeo', $tmplGeo);
  257. parent::display('map');
  258. } else {
  259. parent::display($tpl);
  260. }
  261. }
  262.  
  263. function _setLibraries() {
  264.  
  265. $document = &JFactory::getDocument();
  266.  
  267. // Libraries
  268. $library = &PhocaGalleryLibrary::getLibrary();
  269. $libraries['pg-css-ie'] = $library->getLibrary('pg-css-ie');
  270.  
  271. // CSS for IE 8
  272. if ( $libraries['pg-css-ie']->value == 0 ) {
  273. $document->addCustomTag("<!--[if lt IE 8]>\n<link rel=\"stylesheet\" href=\""
  274. .JURI::base(true)
  275. ."/components/com_phocagallery/assets/phocagalleryieall.css\" type=\"text/css\" />\n<![endif]-->");
  276. $library->setLibrary('pg-css-ie', 1);
  277. }
  278.  
  279. // CSS
  280. JHTML::stylesheet( 'phocagallery.css', 'components/com_phocagallery/assets/' );
  281. }
  282. }
  283. ?>