PageRenderTime 33ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/angular/includes/helper-slideshow.php

https://bitbucket.org/adatux_/uakami
PHP | 491 lines | 354 code | 114 blank | 23 comment | 74 complexity | 89cc112d5c753c481a872bffa23ee08a MD5 | raw file
  1. <?php
  2. class avia_slideshow
  3. {
  4. var $post_id; // post id of the post containing the slider
  5. var $slides; // slide array
  6. var $slidecount = 0; // number of slides
  7. var $type; // slidehsow type: eg aviaslider, fade slider, etc
  8. var $img_size; // image size
  9. var $duration; // how long to display a slide
  10. var $autoplay; // start autorotation?
  11. var $showcaption; // show caption?
  12. var $force_slider = false; // force a slider
  13. var $show_thumbnails = false; // show thumbnails on default
  14. var $extraclass = "";
  15. var $slideClass = "";
  16. /*
  17. * Constructor initializes slideshow Vars
  18. */
  19. function avia_slideshow($post_id = false, $showcaption = true)
  20. {
  21. global $avia_config;
  22. ///if no id was passed get it
  23. if(!$post_id) $post_id = avia_get_the_ID();
  24. if(!$post_id) return false;
  25. $this->defaultSlider = 'fade_slider';
  26. $this->post_id = $post_id;
  27. $this->slides = avia_post_meta($this->post_id, 'slideshow');
  28. $this->type = avia_post_meta($this->post_id, '_slideshow_type');
  29. $this->position = avia_post_meta($this->post_id, '_slideshow_position');
  30. $this->autoplay = avia_post_meta($this->post_id, '_slideshow_autoplay');
  31. $this->duration = avia_post_meta($this->post_id, '_slideshow_duration');
  32. $this->slideshow_poster = avia_get_option('slideshow_poster');
  33. $this->modify_slide_poster();
  34. $this->link_overwrite = "";
  35. $this->showcaption = $showcaption;
  36. $this->slidecount = $this->slidecount_calc();
  37. if (!$this->type) { $this->type = $this->defaultSlider; }
  38. $this->show_thumbnails = false;
  39. $this->img_size = "featured";
  40. $this->link_overwrite = false;
  41. /*create default settings based on the slideshow selected*/
  42. switch($this->type)
  43. {
  44. case 'fade_slider':break;
  45. case 'move_slider':break;
  46. case 'aviapoly': break;
  47. case 'piecemaker' :break;
  48. }
  49. if($this->slidecount == 0)
  50. {
  51. return false;
  52. }
  53. else
  54. {
  55. return true;
  56. }
  57. }
  58. function setImageSize($size)
  59. {
  60. $this->img_size = $size;
  61. }
  62. function set_links($link)
  63. {
  64. $this->link_overwrite = $link;
  65. }
  66. function customClass($class)
  67. {
  68. $this->slideClass .= " ".$class;
  69. }
  70. function modify_slide_poster($set_new = false)
  71. {
  72. if($set_new !== false) $this->slideshow_poster = $set_new;
  73. if($this->slideshow_poster == 'default')
  74. {
  75. $this->slides = avia_post_meta($this->post_id, 'slideshow');
  76. }
  77. if($this->slideshow_poster == 'single' && (avia_is_overview() || $set_new))
  78. {
  79. if(is_array($this->slides))
  80. {
  81. $this->slides = array_slice($this->slides, 0, 1);
  82. $this->type = $this->defaultSlider;
  83. }
  84. }
  85. if($this->slideshow_poster == 'poster')
  86. {
  87. if(avia_is_overview())
  88. {
  89. if(is_array($this->slides)) { $this->slides = array_slice($this->slides, 0, 1); $this->type = $this->defaultSlider; }
  90. }
  91. else
  92. {
  93. if(is_array($this->slides) && isset($this->slides[1])) $this->slides = array_slice($this->slides, 1, count($this->slides));
  94. }
  95. }
  96. }
  97. /*calculate the slide count by checking which arrays are not empty*/
  98. function slidecount_calc()
  99. {
  100. $slidecount = 0;
  101. if(is_array($this->slides))
  102. {
  103. foreach($this->slides as $slide)
  104. {
  105. if(!empty($slide['slideshow_image']) || !empty($slide['slideshow_video'])) $slidecount++;
  106. }
  107. }
  108. return $slidecount;
  109. }
  110. function display($force = false)
  111. {
  112. if(($this->position == 'big' && !avia_is_overview()) && !$force) return false;
  113. if(avia_is_overview()) $this->autoplay = "false";
  114. return $this->slideshow();
  115. }
  116. function display_big()
  117. {
  118. if(!is_singular() || $this->position == 'small' || empty($this->position)) return false;
  119. return $this->slideshow();
  120. }
  121. function slideshow_attributes()
  122. {
  123. $data = "";
  124. $data .= "data-autorotation='".$this->autoplay."' ";
  125. $data .= "data-autorotation-timer='".$this->duration."' ";
  126. return $data;
  127. }
  128. function slide_attributes($slide)
  129. {
  130. $data = "";
  131. $button = "";
  132. $button_number = 0;
  133. $font_style = "";
  134. if(!empty($slide['caption_font'])) $font_style = "style='color:".$slide['caption_font']."'";
  135. //caption
  136. if(!empty($slide['slideshow_caption_title'])) $data .= '<h1 '.$font_style.'>'.$slide['slideshow_caption_title'].'</h1>';
  137. if(!empty($slide['slideshow_caption'])) $data .= '<div '.$font_style.' class="featured_caption">'.do_shortcode($slide['slideshow_caption']).'</div>';
  138. if(!empty($slide['slideshow_button_title'])) { $button .= $this->create_button($slide, 'slideshow_button_' ); $button_number++; }
  139. if(!empty($slide['slideshow_button2_title'])) { $button .= $this->create_button($slide, 'slideshow_button2_'); $button_number++; }
  140. if($button) $button = "<div class='button_wrap button_wrap_$button_number'>$button</div>";
  141. if($data) $data = "data-caption='".htmlentities($data.$button, ENT_QUOTES, get_bloginfo( 'charset' ))."' ";
  142. //transition
  143. if(!empty($slide['slideshow_transition']))
  144. {
  145. $data .= "data-animation='".$slide['slideshow_transition']."' ";
  146. }
  147. return $data;
  148. }
  149. function create_button($slide, $key)
  150. {
  151. $button = "";
  152. $nextSlide = '';
  153. if($slide[$key.'link'] == 'nextSlide')
  154. {
  155. $nextSlide = 'nextSlide';
  156. $button = "#";
  157. }
  158. else
  159. {
  160. $button = avia_get_link($slide, $key, false, $this->post_id);
  161. }
  162. if($button) $button = "<a class='avia-button on-primary-color primary-background primary-border caption-slideshow-button $nextSlide ".$key."class' href='$button' title='' >".$slide[$key.'title']."</a>";
  163. return $button;
  164. }
  165. function slideshow()
  166. {
  167. global $avia_config;
  168. $counter = 0;
  169. $output = "";
  170. if($this->slidecount)
  171. {
  172. $output .= "<div class='slideshow_container ".$this->slideClass."'>";
  173. $output .= " <ul class='preloading slideshow ".$this->type."' ".$this->slideshow_attributes().">";
  174. foreach($this->slides as $slide)
  175. {
  176. $counter++;
  177. //first get the image with link
  178. $image = "";
  179. if(!empty($slide['slideshow_image']))
  180. {
  181. $data = "";
  182. $data .= "data-imgh='".$avia_config['imgSize'][$this->img_size]['height']."' ";
  183. $data .= "data-imgw='".$avia_config['imgSize'][$this->img_size]['width']."' ";
  184. //get the image by passing the attachment id.
  185. $image_string = avia_image_by_id($slide['slideshow_image'], $this->img_size, 'image', $data);
  186. //if we didnt get a valid image from the above function set it directly
  187. if(!$image_string) $image_string = $slide['slideshow_image'];
  188. //apply links to the image if thats what the user wanted
  189. if(empty($this->link_overwrite))
  190. {
  191. if(!empty($slide['slideshow_video'])) $slide['slideshow_link'] = "";
  192. $image = avia_get_link($slide, 'slideshow_', $image_string, $this->post_id);
  193. }
  194. else
  195. {
  196. $image = "<a href='".$this->link_overwrite."'>".$image_string."</a>";
  197. }
  198. }
  199. //then get the video
  200. $video = "";
  201. if(!empty($slide['slideshow_video']))
  202. {
  203. if(avia_backend_is_file($slide['slideshow_video'], 'html5video'))
  204. {
  205. $video = avia_html5_video_embed($slide['slideshow_video']);
  206. }
  207. else if(strpos($slide['slideshow_video'],'<iframe') !== false)
  208. {
  209. $video = $slide['slideshow_video'];
  210. }
  211. else
  212. {
  213. global $wp_embed;
  214. $video = $wp_embed->run_shortcode("[embed]".trim($slide['slideshow_video'])."[/embed]");
  215. }
  216. }
  217. if(empty($slide['caption_position'])) $slide['caption_position'] = "";
  218. $output .= " <li ".$this->slide_attributes($slide)." class='featured featured_container".$counter++." ".$slide['caption_position']."' >".$image.$video."</li>";
  219. }
  220. $output .= " </ul>";
  221. $output .= '</div>';
  222. }
  223. return $output;
  224. }
  225. function slideshow_thumbs()
  226. {
  227. global $avia_config;
  228. $set_size = $output = "";
  229. $thumbsize = 'shop_thumbnail';
  230. $first = 'activeslideThumb';
  231. $counter = 1;
  232. if($this->slidecount >= 2)
  233. {
  234. $output = "<ul class='thumbnails_container'>";
  235. foreach($this->slides as $slide)
  236. {
  237. if($slide['slideshow_image'] != "" || $slide['slideshow_video'] != "")
  238. {
  239. ### render an image ###
  240. //get the image by passing the attachment id.
  241. $image = avia_image_by_id($slide['slideshow_image'],$thumbsize);
  242. //if we didnt get a valid image from the above function set it directly
  243. if(!$image)
  244. {
  245. $image = "<span class='empty_image'><span class='img_span'></span></span>";
  246. }
  247. else
  248. {
  249. $image = "<span class='img_span'>$image</span>";
  250. }
  251. $output .= "<li class='slideThumb slideThumb".$counter++." $first' $set_size >";
  252. $output .= $image;
  253. if(!empty($slide['slideshow_caption_title']))
  254. {
  255. $output .= "<span class='slideThumbTitle'>\n";
  256. $output .= "<strong class='slideThumbHeading rounded'>".$slide['slideshow_caption_title']."</strong>\n";
  257. $output .= "</span>\n";
  258. }
  259. $output .= "</li>";
  260. $first = "";
  261. }
  262. }
  263. $output .= "</ul>";
  264. }
  265. return $output;
  266. }
  267. ######################################################################
  268. # XML & piecemaker related functions
  269. ######################################################################
  270. function generate_xml()
  271. {
  272. if(strpos($this->type, 'piecemaker') !== false)
  273. {
  274. foreach($this->slides as $slide_element)
  275. {
  276. $this->_build_xml_slides($slide_element);
  277. $this->_build_xml_transition($slide_element);
  278. }
  279. $this->_build_xml_file();
  280. }
  281. }
  282. function activate_piecemaker()
  283. {
  284. global $avia_config;
  285. $output = "";
  286. if(empty($avia_config['swf_embed_loaded'])){
  287. $output .= '<script type="text/javascript" src="'.AVIA_BASE_URL.'slideshow/scripts/swfobject/swfobject.js"></script>'."\n";
  288. $avia_config['swf_embed_loaded'] = true;
  289. }
  290. $output .= '
  291. <script type="text/javascript">
  292. var flashvars = {};
  293. flashvars.cssSource = "'.AVIA_BASE_URL.'slideshow/piecemaker.css";
  294. flashvars.xmlSource = "'.AVIA_BASE_URL.'slideshow/piecemaker.xml.php?post_id='.$this->post_id.'";
  295. var params = {};
  296. params.play = "true";
  297. params.menu = "false";
  298. params.scale = "showall";
  299. params.wmode = "transparent";
  300. params.allowfullscreen = "true";
  301. params.allowscriptaccess = "always";
  302. params.allownetworking = "all";
  303. swfobject.embedSWF("'.AVIA_BASE_URL.'slideshow/piecemaker.swf", "slideshow_'.$this->type.$this->post_id.'", "'.($avia_config['imgSize']['featured']['width']+100).'", "'.($avia_config['imgSize']['featured']['height']+70).'", "10", null, flashvars,
  304. params, null);
  305. </script>';
  306. return $output;
  307. }
  308. function _build_xml_slides($element)
  309. {
  310. global $avia_config;
  311. $text = $url = $title = "";
  312. if(!empty($element['slideshow_caption']))
  313. {
  314. if(!empty($element['slideshow_caption_title'])) $title = '&lt;h1&gt;'.$element['slideshow_caption_title'].'&lt;/p&gt;';
  315. $text = "<Text>".$title."&lt;p&gt;".strip_tags($element['slideshow_caption'])."&lt;/p&gt;</Text>";
  316. }
  317. //apply links to the image if thats what the user wanted
  318. $url = avia_get_link($element, 'slideshow_', false, $this->post_id);
  319. if($url) $url = "<Hyperlink URL='".$url."' />";
  320. if(is_numeric($element['slideshow_image']))
  321. {
  322. $this->slides_xml .= '<Image Source="'.avia_image_by_id($element['slideshow_image'], 'featured', 'url').'" Title="'.$element['slideshow_caption_title'].'">';
  323. $this->slides_xml .= $text.$url;
  324. $this->slides_xml .= '</Image>';
  325. }
  326. else
  327. {
  328. if(avia_backend_is_file($element['slideshow_image'], 'html5video') || avia_backend_is_file($element['slideshow_image'], array('swf')))
  329. {
  330. preg_match("!^(.+?)(?:\.([^.]+))?$!", $element['slideshow_image'], $path_split);
  331. $tag = 'Video';
  332. if($path_split[2] == 'swf') $tag = 'Flash';
  333. $this->slides_xml .= '<'.$tag.' Source="'.$element['slideshow_image'].'" Title="'.$element['slideshow_caption_title'].'" Width="'.$avia_config['imgSize']['featured']['width'].'" Height="'.$avia_config['imgSize']['featured']['height'].'" Autoplay="true" >';
  334. $image = $path_split[1].'.jpg';
  335. $checkpath = $path_split[1].'-'.$avia_config['imgSize']['featured']['width'].'x'.$avia_config['imgSize']['featured']['height'].'.jpg';
  336. if(@file_get_contents($checkpath,0,NULL,0,1))
  337. {
  338. $image = $checkpath;
  339. }
  340. $this->slides_xml .= '<Image Source="'.$image.'" />';
  341. $this->slides_xml .= '</'.$tag.'>';
  342. }
  343. }
  344. }
  345. function _build_xml_transition($element)
  346. {
  347. $this->transitions_xml .= '<Transition ';
  348. if(empty($element['slice_vertical'])) $element['slice_vertical'] = '3';
  349. if(empty($element['sideward'])) $element['sideward'] = '20';
  350. if(empty($element['flip_depth'])) $element['flip_depth'] = '250';
  351. if(empty($element['easing'])) $element['easing'] = '';
  352. $this->transitions_xml .= 'Pieces="'.$element['slice_vertical'].'" ';
  353. $this->transitions_xml .= 'DepthOffset="'.$element['flip_depth'].'" ';
  354. $this->transitions_xml .= 'CubeDistance="'.$element['sideward'].'" ';
  355. $this->transitions_xml .= 'Transition="'.$element['easing'].'" ';
  356. $this->transitions_xml .= 'Delay="0.1" Time="0.7" />';
  357. }
  358. function _build_xml_file()
  359. {
  360. global $avia_config;
  361. //$color_1 = substr(avia_get_option('color_1','#000000'),1);
  362. //$color_3 = substr(avia_get_option('color_3','#ffffff'),1);
  363. $color_1 = "000000";
  364. $color_3 = "ffffff";
  365. //gerneric mask with defaults. the slider specific vars are filled in here
  366. $this->slideshow_xml .= '<?xml version="1.0" encoding="utf-8"?>
  367. <Piecemaker>
  368. <Contents>'.$this->slides_xml.'</Contents>
  369. <Settings ImageWidth="'.$avia_config['imgSize']['featured']['width'].'" ImageHeight="'.$avia_config['imgSize']['featured']['height'].'" LoaderColor="0x333333" InnerSideColor="0x222222" SideShadowAlpha="0.8" DropShadowAlpha="0.3" DropShadowDistance="25" DropShadowScale="0.95" DropShadowBlurX="40" DropShadowBlurY="4" MenuDistanceX="20" MenuDistanceY="30" MenuColor1="0x'.$color_1.'" MenuColor2="0x999999" MenuColor3="0x'.$color_3.'" ControlSize="100" ControlDistance="20" ControlColor1="0x'.$color_1.'" ControlColor2="0x'.$color_3.'" ControlAlpha="0.8" ControlAlphaOver="0.95" ControlsX="450" ControlsY="280&#xD;&#xA;" ControlsAlign="center" TooltipHeight="30" TooltipColor="0x'.$color_1.'" TooltipTextY="5" TooltipTextStyle="P-Italic" TooltipTextColor="0x'.$color_3.'" TooltipMarginLeft="5" TooltipMarginRight="7" TooltipTextSharpness="50" TooltipTextThickness="-100" InfoWidth="400" InfoBackground="0x'.$color_1.'" InfoBackgroundAlpha="0.70" InfoMargin="15" InfoSharpness="0" InfoThickness="0" Autoplay="'.$this->duration.'" FieldOfView="45"></Settings>
  370. <Transitions>'.$this->transitions_xml.'</Transitions>
  371. </Piecemaker>';
  372. }
  373. }