PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/mod_djimageslider/helper.php

https://github.com/techjoomla/Joomla-Extensions
PHP | 390 lines | 351 code | 37 blank | 2 comment | 74 complexity | db5eefaaddb9df918f3bc46b6ab9d92c MD5 | raw file
  1. <?php
  2. // no direct access
  3. defined('_JEXEC') or die ('Restricted access');
  4. class modDJImageSliderHelper
  5. {
  6. function getImagesFromFolder(&$params) {
  7. if(!is_numeric($max = $params->get('max_images'))) $max = 20;
  8. $folder = $params->get('image_folder');
  9. $database = JFactory::getDBO();
  10. $stitleid = $params->get('title');
  11. $simageid = $params->get('image');
  12. $query = "SELECT id FROM #__menu WHERE title = 'COM_SOBIPRO'";
  13. $database->setQuery($query);
  14. $Itemid = $database->loadResult();
  15. $query = "SELECT * FROM #__sobipro_field_data WHERE fid = $simageid AND approved = 1 LIMIT $max";
  16. $database->setQuery($query);
  17. $idat = $database->loadObjectList();
  18. foreach($idat as $idata) {
  19. $query = "SELECT a.fid,a.sid,a.baseData,b.parent
  20. FROM #__sobipro_field_data AS a ,#__sobipro_object AS b
  21. WHERE a.fid = $stitleid
  22. AND a.sid = $idata->sid
  23. AND a.sid = b.id";
  24. $database->setQuery($query);
  25. $slink = $database->loadObject();
  26. $slink->baseData = str_replace('%','',$slink->baseData);
  27. $link = $params->get('link').'&pid='.$slink->parent.'&sid='.$slink->sid.':'.str_replace(' ','-',$slink->baseData).'&Itemid='.$Itemid;
  28. $link = JRoute::_($link);
  29. $target = modDJImageSliderHelper::getSlideTarget($params->get('link'));
  30. $slide_image = unserialize(base64_decode($idata->baseData));
  31. $slides[] = (object) array('title'=>'', 'description'=>'', 'image'=>$slide_image['image'], 'link'=>$link, 'alt'=>$image, 'target'=>$target);
  32. }
  33. return $slides;
  34. }
  35. function getImagesFromDJImageSlider(&$params) {
  36. if(!is_numeric($max = $params->get('max_images'))) $max = 20;
  37. $catid = $params->get('category',0);
  38. // build query to get slides
  39. $db = &JFactory::getDBO();
  40. $query = $db->getQuery(true);
  41. $query->select('a.*');
  42. $query->from('#__djimageslider AS a');
  43. if (is_numeric($catid)) {
  44. $query->where('a.catid = ' . (int) $catid);
  45. }
  46. $query->where('a.published = 1');
  47. if($params->get('sort_by',1)) {
  48. $query->order('a.ordering ASC');
  49. } else {
  50. $query->order('RAND()');
  51. }
  52. $db->setQuery($query, 0 , $max);
  53. $slides = $db->loadObjectList();
  54. foreach($slides as $slide){
  55. $slide->link = modDJImageSliderHelper::getSlideLink($slide);
  56. $slide->description = modDJImageSliderHelper::getSlideDescription($slide, $params->get('limit_desc'));
  57. $slide->alt = $slide->title;
  58. $slide->target = modDJImageSliderHelper::getSlideTarget($slide->link);
  59. }
  60. return $slides;
  61. }
  62. function getSlideLink(&$slide) {
  63. $slide_params = new JRegistry($slide->params);
  64. $link = '';
  65. $db = &JFactory::getDBO();
  66. switch($slide_params->get('link_type', '')) {
  67. case 'menu':
  68. if ($menuid = $slide_params->get('link_menu',0)) {
  69. $menu =& JSite::getMenu();
  70. $menuitem = $menu->getItem($menuid);
  71. if($menuitem) switch($menuitem->type) {
  72. case 'component':
  73. $link = JRoute::_($menuitem->link.'&Itemid='.$menuid);
  74. break;
  75. case 'url':
  76. case 'alias':
  77. $link = JRoute::_($menuitem->link);
  78. break;
  79. }
  80. }
  81. break;
  82. case 'url':
  83. if($itemurl = $slide_params->get('link_url',0)) {
  84. $link = JRoute::_($itemurl);
  85. }
  86. break;
  87. case 'article':
  88. if ($artid = $slide_params->get('id',$slide_params->get('link_article',0))) {
  89. require_once(JPATH_BASE.DS.'components'.DS.'com_content'.DS.'models'.DS.'article.php');
  90. require_once(JPATH_BASE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');
  91. $model = new ContentModelArticle();
  92. $item = $model->getItem($artid);
  93. if($item) {
  94. $item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
  95. $link = JRoute::_(ContentHelperRoute::getArticleRoute($item->slug, $item->catid));
  96. }
  97. }
  98. break;
  99. }
  100. return $link;
  101. }
  102. function getSlideDescription($slide, $limit) {
  103. $sparams = new JRegistry($slide->params);
  104. if($sparams->get('link_type','')=='article' && empty($slide->description)){ // if article and no description then get introtext as description
  105. $artid = $sparams->get('id',$sparams->get('link_article',0));
  106. require_once(JPATH_BASE.DS.'components'.DS.'com_content'.DS.'models'.DS.'article.php');
  107. $model = new ContentModelArticle();
  108. $article = $model->getItem($artid);
  109. if($article) {
  110. $slide->description = $article->introtext;
  111. }
  112. }
  113. $desc = strip_tags($slide->description);
  114. if($limit && $limit < strlen($desc)) {
  115. $limit = strpos($desc, ' ', $limit);
  116. $desc = substr($desc, 0, $limit);
  117. if(preg_match('/[A-Za-z0-9]$/', $desc)) $desc.=' ...';
  118. $desc = nl2br($desc);
  119. } else { // no limit or limit greater than description
  120. $desc = $slide->description;
  121. }
  122. return $desc;
  123. }
  124. function getAnimationOptions(&$params) {
  125. $effect = $params->get('effect');
  126. $effect_type = $params->get('effect_type');
  127. if(!is_numeric($duration = $params->get('duration'))) $duration = 0;
  128. if(!is_numeric($delay = $params->get('delay'))) $delay = 3000;
  129. $autoplay = $params->get('autoplay');
  130. if($params->get('slider_type')==2 && !$duration) {
  131. $transition = 'linear';
  132. $duration = 600;
  133. } else switch($effect){
  134. case 'Linear':
  135. $transition = 'linear';
  136. if(!$duration) $duration = 600;
  137. break;
  138. case 'Circ':
  139. case 'Expo':
  140. case 'Back':
  141. if(!$effect_type) $transition = $effect.'.easeInOut';
  142. else $transition = $effect.'.'.$effect_type;
  143. if(!$duration) $duration = 1000;
  144. break;
  145. case 'Bounce':
  146. if(!$effect_type) $transition = $effect.'.easeOut';
  147. else $transition = $effect.'.'.$effect_type;
  148. if(!$duration) $duration = 1200;
  149. break;
  150. case 'Elastic':
  151. if(!$effect_type) $transition = $effect.'.easeOut';
  152. else $transition = $effect.'.'.$effect_type;
  153. if(!$duration) $duration = 1500;
  154. break;
  155. case 'Cubic':
  156. default:
  157. if(!$effect_type) $transition = 'Cubic.easeInOut';
  158. else $transition = 'Cubic.'.$effect_type;
  159. if(!$duration) $duration = 800;
  160. }
  161. $delay = $delay + $duration;
  162. $options = "{auto: $autoplay, transition: Fx.Transitions.$transition, duration: $duration, delay: $delay}";
  163. return $options;
  164. }
  165. function getSlideTarget($link) {
  166. if(preg_match("/^http/",$link) && !preg_match("/^".str_replace(array('/','.','-'), array('\/','\.','\-'),JURI::base())."/",$link)) {
  167. $target = '_blank';
  168. } else {
  169. $target = '_self';
  170. }
  171. return $target;
  172. }
  173. function getNavigation(&$params, &$mid) {
  174. $prev = $params->get('left_arrow');
  175. $next = $params->get('right_arrow');
  176. $play = $params->get('play_button');
  177. $pause = $params->get('pause_button');
  178. if($params->get('slider_type')==1) {
  179. if(empty($prev) || !file_exists(JPATH_ROOT.DS.$prev)) $prev = JURI::base().'/modules/mod_djimageslider/assets/up.png';
  180. if(empty($next) || !file_exists(JPATH_ROOT.DS.$next)) $next = JURI::base().'/modules/mod_djimageslider/assets/down.png';
  181. } else {
  182. if(empty($prev) || !file_exists(JPATH_ROOT.DS.$prev)) $prev = JURI::base().'/modules/mod_djimageslider/assets/prev.png';
  183. if(empty($next) || !file_exists(JPATH_ROOT.DS.$next)) $next = JURI::base().'/modules/mod_djimageslider/assets/next.png';
  184. }
  185. if(empty($play) || !file_exists(JPATH_ROOT.DS.$play)) $play = JURI::base().'/modules/mod_djimageslider/assets/play.png';
  186. if(empty($pause) || !file_exists(JPATH_ROOT.DS.$pause)) $pause = JURI::base().'/modules/mod_djimageslider/assets/pause.png';
  187. $navi = (object) array('prev'=>$prev,'next'=>$next,'play'=>$play,'pause'=>$pause);
  188. return $navi;
  189. }
  190. function getStyleSheet(&$params, &$mid) {
  191. if(!is_numeric($slide_width = $params->get('image_width'))) $slide_width = 240;
  192. if(!is_numeric($slide_height = $params->get('image_height'))) $slide_height = 160;
  193. if(!is_numeric($max = $params->get('max_images'))) $max = 20;
  194. if(!is_numeric($count = $params->get('visible_images'))) $count = 2;
  195. if(!is_numeric($spacing = $params->get('space_between_images'))) $spacing = 0;
  196. if($count<1) $count = 1;
  197. if($count>$max) $count = $max;
  198. if(!is_numeric($desc_width = $params->get('desc_width')) || $desc_width > $slide_width) $desc_width = $slide_width;
  199. if(!is_numeric($desc_bottom = $params->get('desc_bottom'))) $desc_bottom = 0;
  200. if(!is_numeric($desc_left = $params->get('desc_horizontal'))) $desc_left = 0;
  201. if(!is_numeric($arrows_top = $params->get('arrows_top'))) $arrows_top = 100;
  202. if(!is_numeric($arrows_horizontal = $params->get('arrows_horizontal'))) $arrows_horizontal = 5;
  203. if(!$params->get('show_buttons')) $play_pause = 'top: -99999px;'; else $play_pause = '';
  204. if(!$params->get('show_arrows')) $arrows = 'top: -99999px;'; else $arrows = '';
  205. if(!$params->get('show_custom_nav')) $custom_nav = 'display: none;'; else $custom_nav = '';
  206. switch($params->get('slider_type')){
  207. case 2:
  208. $slider_width = $slide_width;
  209. $slider_height = $slide_height;
  210. $image_width = $slide_width.'px';
  211. $image_height = 'auto';
  212. $padding_right = 0;
  213. $padding_bottom = 0;
  214. break;
  215. case 1:
  216. $slider_width = $slide_width;
  217. $slider_height = $slide_height * $count + $spacing * ($count - 1);
  218. $image_width = 'auto';
  219. $image_height = $slide_height.'px';
  220. $padding_right = 0;
  221. $padding_bottom = $spacing;
  222. break;
  223. case 0:
  224. default:
  225. $slider_width = $slide_width * $count + $spacing * ($count - 1);
  226. $slider_height = $slide_height;
  227. $image_width = $slide_width.'px';
  228. $image_height = 'auto';
  229. $padding_right = $spacing;
  230. $padding_bottom = 0;
  231. break;
  232. }
  233. if($params->get('fit_to')==1) {
  234. $image_width = $slide_width.'px';
  235. $image_height = 'auto';
  236. } else if($params->get('fit_to')==2) {
  237. $image_width = 'auto';
  238. $image_height = $slide_height.'px';
  239. }
  240. $css = '
  241. /* Styles for DJ Image Slider with module id '.$mid.' */
  242. #djslider-loader'.$mid.' {
  243. margin: 0 auto;
  244. position: relative;
  245. height: '.$slider_height.'px;
  246. width: '.$slider_width.'px;
  247. }
  248. #djslider'.$mid.' {
  249. margin: 0 auto;
  250. position: relative;
  251. height: '.$slider_height.'px;
  252. width: '.$slider_width.'px;
  253. display: none;
  254. }
  255. #slider-container'.$mid.' {
  256. position: absolute;
  257. overflow:hidden;
  258. left: 0;
  259. top: 0;
  260. height: '.$slider_height.'px;
  261. width: '.$slider_width.'px;
  262. }
  263. #djslider'.$mid.' ul#slider'.$mid.' {
  264. margin: 0 !important;
  265. padding: 0 !important;
  266. border: 0 !important;
  267. }
  268. #djslider'.$mid.' ul#slider'.$mid.' li {
  269. list-style: none outside !important;
  270. float: left;
  271. margin: 0 !important;
  272. border: 0 !important;
  273. padding: 0 '.$padding_right.'px '.$padding_bottom.'px 0 !important;
  274. position: relative;
  275. height: '.$slide_height.'px;
  276. width: '.$slide_width.'px;
  277. background: none;
  278. overflow: hidden;
  279. }
  280. #slider'.$mid.' li img {
  281. width: '.$image_width.';
  282. height: '.$image_height.';
  283. border: 0 !important;
  284. margin: 0 !important;
  285. }
  286. #slider'.$mid.' li a img, #slider'.$mid.' li a:hover img {
  287. border: 0 !important;
  288. }
  289. /* Slide description area */
  290. #slider'.$mid.' .slide-desc {
  291. position: absolute;
  292. bottom: '.($desc_bottom + $padding_bottom).'px;
  293. left: '.$desc_left.'px;
  294. width: '.$desc_width.'px;
  295. }
  296. #slider'.$mid.' .slide-desc-in {
  297. position: relative;
  298. }
  299. #slider'.$mid.' .slide-desc-bg {
  300. position:absolute;
  301. top: 0;
  302. left: 0;
  303. width: 100%;
  304. height: 100%;
  305. }
  306. #slider'.$mid.' .slide-desc-text {
  307. position: relative;
  308. }
  309. #slider'.$mid.' .slide-desc-text h3 {
  310. display: block !important;
  311. }
  312. /* Navigation buttons */
  313. #navigation'.$mid.' {
  314. position: relative;
  315. top: '.$arrows_top.'px;
  316. margin: 0 '.$arrows_horizontal.'px;
  317. text-align: center !important;
  318. }
  319. #prev'.$mid.' {
  320. cursor: pointer;
  321. display: block;
  322. position: absolute;
  323. left: 0;
  324. '.$arrows.'
  325. }
  326. #next'.$mid.' {
  327. cursor: pointer;
  328. display: block;
  329. position: absolute;
  330. right: 0;
  331. '.$arrows.'
  332. }
  333. #play'.$mid.',
  334. #pause'.$mid.' {
  335. cursor: pointer;
  336. display: block;
  337. position: absolute;
  338. left: 47%;
  339. '.$play_pause.'
  340. }
  341. #cust-navigation'.$mid.' {
  342. position: absolute;
  343. top: 10px;
  344. right: 10px;
  345. z-index: 15;
  346. '.$custom_nav.'
  347. }
  348. ';
  349. return $css;
  350. }
  351. }