PageRenderTime 1324ms CodeModel.GetById 32ms RepoModel.GetById 3ms app.codeStats 0ms

/wp-content/plugins/revslider/inc_php/revslider_output.class.php

https://github.com/alniko009/magic
PHP | 1274 lines | 858 code | 275 blank | 141 comment | 200 complexity | 50148a3982820976acfae1a710ab972d MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. class RevSliderOutput{
  3. private static $sliderSerial = 0;
  4. private $sliderHtmlID;
  5. private $sliderHtmlID_wrapper;
  6. private $slider;
  7. private $oneSlideMode = false;
  8. private $oneSlideData;
  9. private $previewMode = false; //admin preview mode
  10. private $slidesNumIndex;
  11. private $sliderLang = null;
  12. /**
  13. *
  14. * check the put in string
  15. * return true / false if the put in string match the current page.
  16. */
  17. public static function isPutIn($putIn,$emptyIsFalse = false){
  18. $putIn = strtolower($putIn);
  19. $putIn = trim($putIn);
  20. if($emptyIsFalse && empty($putIn))
  21. return(false);
  22. if($putIn == "homepage"){ //filter by homepage
  23. if(is_front_page() == false)
  24. return(false);
  25. }
  26. else //case filter by pages
  27. if(!empty($putIn)){
  28. $arrPutInPages = array();
  29. $arrPagesTemp = explode(",", $putIn);
  30. foreach($arrPagesTemp as $page){
  31. if(is_numeric($page) || $page == "homepage")
  32. $arrPutInPages[] = $page;
  33. }
  34. if(!empty($arrPutInPages)){
  35. //get current page id
  36. $currentPageID = "";
  37. if(is_front_page() == true)
  38. $currentPageID = "homepage";
  39. else{
  40. global $post;
  41. if(isset($post->ID))
  42. $currentPageID = $post->ID;
  43. }
  44. //do the filter by pages
  45. if(array_search($currentPageID, $arrPutInPages) === false)
  46. return(false);
  47. }
  48. }
  49. return(true);
  50. }
  51. /**
  52. *
  53. * put the rev slider slider on the html page.
  54. * @param $data - mixed, can be ID ot Alias.
  55. */
  56. public static function putSlider($sliderID,$putIn=""){
  57. $isPutIn = self::isPutIn($putIn);
  58. if($isPutIn == false)
  59. return(false);
  60. $output = new RevSliderOutput();
  61. $output->putSliderBase($sliderID);
  62. $slider = $output->getSlider();
  63. return($slider);
  64. }
  65. /**
  66. *
  67. * set language
  68. */
  69. public function setLang($lang){
  70. $this->sliderLang = $lang;
  71. }
  72. /**
  73. *
  74. * set one slide mode for preview
  75. */
  76. public function setOneSlideMode($data){
  77. $this->oneSlideMode = true;
  78. $this->oneSlideData = $data;
  79. }
  80. /**
  81. *
  82. * set preview mode
  83. */
  84. public function setPreviewMode(){
  85. $this->previewMode = true;
  86. }
  87. /**
  88. *
  89. * get the last slider after the output
  90. */
  91. public function getSlider(){
  92. return($this->slider);
  93. }
  94. /**
  95. *
  96. * get slide full width video data
  97. */
  98. private function getSlideFullWidthVideoData(RevSlide $slide){
  99. $response = array("found"=>false);
  100. //deal full width video:
  101. $enableVideo = $slide->getParam("enable_video","false");
  102. if($enableVideo != "true")
  103. return($response);
  104. $videoID = $slide->getParam("video_id","");
  105. $videoID = trim($videoID);
  106. if(empty($videoID))
  107. return($response);
  108. $response["found"] = true;
  109. $videoType = is_numeric($videoID)?"vimeo":"youtube";
  110. $videoAutoplay = $slide->getParam("video_autoplay");
  111. $videoNextslide = $slide->getParam("video_nextslide");
  112. $response["type"] = $videoType;
  113. $response["videoID"] = $videoID;
  114. $response["autoplay"] = UniteFunctionsRev::strToBool($videoAutoplay);
  115. $response["nextslide"] = UniteFunctionsRev::strToBool($videoNextslide);
  116. return($response);
  117. }
  118. /**
  119. *
  120. * put full width video layer
  121. */
  122. private function putFullWidthVideoLayer($videoData){
  123. if($videoData["found"] == false)
  124. return(false);
  125. $autoplay = UniteFunctionsRev::boolToStr($videoData["autoplay"]);
  126. $nextslide = UniteFunctionsRev::boolToStr($videoData["nextslide"]);
  127. $htmlParams = 'data-x="0" data-y="0" data-speed="500" data-start="10" data-easing="easeOutBack"';
  128. $videoID = $videoData["videoID"];
  129. if($videoData["type"] == "youtube"): //youtube
  130. ?>
  131. <div class="tp-caption fade fullscreenvideo" data-nextslideatend="<?php echo $nextslide?>" data-autoplay="<?php echo $autoplay?>" <?php echo $htmlParams?>><iframe src="http://www.youtube.com/embed/<?php echo $videoID?>?hd=1&amp;wmode=opaque&amp;controls=1&amp;showinfo=0;rel=0;" width="100%" height="100%"></iframe></div>
  132. <?php
  133. else: //vimeo
  134. ?>
  135. <div class="tp-caption fade fullscreenvideo" data-nextslideatend="<?php echo $nextslide?>" data-autoplay="<?php echo $autoplay?>" <?php echo $htmlParams?>><iframe src="http://player.vimeo.com/video/<?php echo $videoID?>?title=0&amp;byline=0&amp;portrait=0;api=1" width="100%" height="100%"></iframe></div>
  136. <?php
  137. endif;
  138. }
  139. /**
  140. *
  141. * filter the slides for one slide preview
  142. */
  143. private function filterOneSlide($slides){
  144. $oneSlideID = $this->oneSlideData["slideid"];
  145. $oneSlideParams = UniteFunctionsRev::getVal($this->oneSlideData, "params");
  146. $oneSlideLayers = UniteFunctionsRev::getVal($this->oneSlideData, "layers");
  147. if(gettype($oneSlideParams) == "object")
  148. $oneSlideParams = (array)$oneSlideParams;
  149. if(gettype($oneSlideLayers) == "object")
  150. $oneSlideLayers = (array)$oneSlideLayers;
  151. if(!empty($oneSlideLayers))
  152. $oneSlideLayers = UniteFunctionsRev::convertStdClassToArray($oneSlideLayers);
  153. $newSlides = array();
  154. foreach($slides as $slide){
  155. $slideID = $slide->getID();
  156. if($slideID == $oneSlideID){
  157. if(!empty($oneSlideParams))
  158. $slide->setParams($oneSlideParams);
  159. if(!empty($oneSlideLayers))
  160. $slide->setLayers($oneSlideLayers);
  161. $newSlides[] = $slide; //add 2 slides
  162. $newSlides[] = $slide;
  163. }
  164. }
  165. return($newSlides);
  166. }
  167. /**
  168. *
  169. * put the slider slides
  170. */
  171. private function putSlides(){
  172. $sliderType = $this->slider->getParam("slider_type");
  173. $publishedOnly = true;
  174. if($this->previewMode == true && $this->oneSlideMode == true){
  175. $previewSlideID = UniteFunctionsRev::getVal($this->oneSlideData, "slideid");
  176. $previewSlide = new RevSlide();
  177. $previewSlide->initByID($previewSlideID);
  178. $slides = array($previewSlide);
  179. }else{
  180. $slides = $this->slider->getSlidesForOutput($publishedOnly,$this->sliderLang);
  181. }
  182. $this->slidesNumIndex = $this->slider->getSlidesNumbersByIDs(true);
  183. if(empty($slides)):
  184. ?>
  185. <div class="no-slides-text">
  186. No slides found, please add some slides
  187. </div>
  188. <?php
  189. endif;
  190. $thumbWidth = $this->slider->getParam("thumb_width",100);
  191. $thumbHeight = $this->slider->getParam("thumb_height",50);
  192. $slideWidth = $this->slider->getParam("width",900);
  193. $slideHeight = $this->slider->getParam("height",300);
  194. $navigationType = $this->slider->getParam("navigaion_type","none");
  195. $isThumbsActive = ($navigationType == "thumb")?true:false;
  196. //for one slide preview
  197. if($this->oneSlideMode == true)
  198. $slides = $this->filterOneSlide($slides);
  199. ?>
  200. <ul>
  201. <?php
  202. foreach($slides as $index => $slide){
  203. $params = $slide->getParams();
  204. //check if date is set
  205. $date_from = $slide->getParam("date_from","");
  206. $date_to = $slide->getParam("date_to","");
  207. if($date_from != ""){
  208. $date_from = strtotime($date_from);
  209. if(time() < $date_from) continue;
  210. }
  211. if($date_to != ""){
  212. $date_to = strtotime($date_to);
  213. if(time() > $date_to) continue;
  214. }
  215. $transition = $slide->getParam("slide_transition","random");
  216. $slotAmount = $slide->getParam("slot_amount","7");
  217. $urlSlideImage = $slide->getImageUrl();
  218. //get image alt
  219. $imageFilename = $slide->getImageFilename();
  220. $info = pathinfo($imageFilename);
  221. $alt = $info["filename"];
  222. //get thumb url
  223. $htmlThumb = "";
  224. if($isThumbsActive == true){
  225. $urlThumb = $slide->getParam("slide_thumb","");
  226. if(empty($urlThumb)){ //try to get resized thumb
  227. $pathThumb = $slide->getImageFilepath();
  228. if(!empty($pathThumb))
  229. $urlThumb = UniteBaseClassRev::getImageUrl($pathThumb,$thumbWidth,$thumbHeight,true);
  230. }
  231. //if not - put regular image:
  232. if(empty($urlThumb))
  233. $urlThumb = $slide->getImageUrl();
  234. $htmlThumb = 'data-thumb="'.$urlThumb.'" ';
  235. }
  236. //get link
  237. $htmlLink = "";
  238. $enableLink = $slide->getParam("enable_link","false");
  239. if($enableLink == "true"){
  240. $linkType = $slide->getParam("link_type","regular");
  241. switch($linkType){
  242. //---- normal link
  243. default:
  244. case "regular":
  245. $link = $slide->getParam("link","");
  246. $linkOpenIn = $slide->getParam("link_open_in","same");
  247. $htmlTarget = "";
  248. if($linkOpenIn == "new")
  249. $htmlTarget = ' data-target="_blank"';
  250. $htmlLink = "data-link=\"$link\" $htmlTarget ";
  251. break;
  252. //---- link to slide
  253. case "slide":
  254. $slideLink = UniteFunctionsRev::getVal($params, "slide_link");
  255. if(!empty($slideLink) && $slideLink != "nothing"){
  256. //get slide index from id
  257. if(is_numeric($slideLink))
  258. $slideLink = UniteFunctionsRev::getVal($this->slidesNumIndex, $slideLink);
  259. if(!empty($slideLink))
  260. $htmlLink = "data-link=\"slide\" data-linktoslide=\"$slideLink\" ";
  261. }
  262. break;
  263. }
  264. //set link position:
  265. $linkPos = UniteFunctionsRev::getVal($params, "link_pos","front");
  266. if($linkPos == "back")
  267. $htmlLink .= ' data-slideindex="back"';
  268. }
  269. //set delay
  270. $htmlDelay = "";
  271. $delay = $slide->getParam("delay","");
  272. if(!empty($delay) && is_numeric($delay))
  273. $htmlDelay = "data-delay=\"$delay\" ";
  274. //get duration
  275. $htmlDuration = "";
  276. $duration = $slide->getParam("transition_duration","");
  277. if(!empty($duration) && is_numeric($duration))
  278. $htmlDuration = "data-masterspeed=\"$duration\" ";
  279. //get rotation
  280. $htmlRotation = "";
  281. $rotation = $slide->getParam("transition_rotation","");
  282. if(!empty($rotation)){
  283. $rotation = (int)$rotation;
  284. if($rotation != 0){
  285. if($rotation > 720 && $rotation != 999)
  286. $rotation = 720;
  287. if($rotation < -720)
  288. $rotation = -720;
  289. }
  290. $htmlRotation = "data-rotate=\"$rotation\" ";
  291. }
  292. $fullWidthVideoData = $this->getSlideFullWidthVideoData($slide);
  293. //set full width centering.
  294. $htmlImageCentering = "";
  295. $fullWidthCentering = $slide->getParam("fullwidth_centering","false");
  296. if($sliderType == "fullwidth" && $fullWidthCentering == "true")
  297. $htmlImageCentering = ' data-fullwidthcentering="on"';
  298. //set first slide transition
  299. $htmlFirstTrans = "";
  300. $startWithSlide = $this->slider->getStartWithSlideSetting();
  301. if($index == $startWithSlide){
  302. $firstTransActive = $this->slider->getParam("first_transition_active","false");
  303. if($firstTransActive == "true"){
  304. $firstTransition = $this->slider->getParam("first_transition_type","fade");
  305. $htmlFirstTrans .= " data-fstransition=\"$firstTransition\"";
  306. $firstDuration = $this->slider->getParam("first_transition_duration","300");
  307. if(!empty($firstDuration) && is_numeric($firstDuration))
  308. $htmlFirstTrans .= " data-fsmasterspeed=\"$firstDuration\"";
  309. $firstSlotAmount = $this->slider->getParam("first_transition_slot_amount","7");
  310. if(!empty($firstSlotAmount) && is_numeric($firstSlotAmount))
  311. $htmlFirstTrans .= " data-fsslotamount=\"$firstSlotAmount\"";
  312. }
  313. }//first trans
  314. $htmlParams = $htmlDuration.$htmlLink.$htmlThumb.$htmlDelay.$htmlRotation.$htmlFirstTrans;
  315. $bgType = $slide->getParam("background_type","image");
  316. $styleImage = "";
  317. $urlImageTransparent = UniteBaseClassRev::$url_plugin."images/transparent.png";
  318. switch($bgType){
  319. case "trans":
  320. $urlSlideImage = $urlImageTransparent;
  321. break;
  322. case "solid":
  323. $urlSlideImage = $urlImageTransparent;
  324. $slideBGColor = $slide->getParam("slide_bg_color","#d0d0d0");
  325. $styleImage = "style='background-color:{$slideBGColor}'";
  326. break;
  327. }
  328. //additional params
  329. $imageAddParams = "";
  330. $lazyLoad = $this->slider->getParam("lazy_load","off");
  331. if($lazyLoad == "on"){
  332. $imageAddParams .= "data-lazyload=\"$urlSlideImage\"";
  333. $urlSlideImage = UniteBaseClassRev::$url_plugin."images/dummy.png";
  334. }
  335. $imageAddParams .= $htmlImageCentering;
  336. //Html
  337. ?>
  338. <li data-transition="<?php echo $transition?>" data-slotamount="<?php echo $slotAmount?>" <?php echo $htmlParams?>>
  339. <img src="<?php echo $urlSlideImage?>" <?php echo $styleImage?> alt="<?php echo $alt?>" <?php echo $imageAddParams?>>
  340. <?php //put video:
  341. if($fullWidthVideoData["found"] == true) //backward compatability
  342. $this->putFullWidthVideoLayer($fullWidthVideoData);
  343. $this->putCreativeLayer($slide)
  344. ?>
  345. </li>
  346. <?php
  347. } //get foreach
  348. ?>
  349. </ul>
  350. <?php
  351. }
  352. /**
  353. *
  354. * get html5 layer html from data
  355. */
  356. private function getHtml5LayerHtml($data){
  357. $urlPoster = UniteFunctionsRev::getVal($data, "urlPoster");
  358. $urlMp4 = UniteFunctionsRev::getVal($data, "urlMp4");
  359. $urlWebm = UniteFunctionsRev::getVal($data, "urlWebm");
  360. $urlOgv = UniteFunctionsRev::getVal($data, "urlOgv");
  361. $width = UniteFunctionsRev::getVal($data, "width");
  362. $height = UniteFunctionsRev::getVal($data, "height");
  363. $fullwidth = UniteFunctionsRev::getVal($data, "fullwidth");
  364. $fullwidth = UniteFunctionsRev::strToBool($fullwidth);
  365. if($fullwidth == true){
  366. $width = "100%";
  367. $height = "100%";
  368. }
  369. $htmlPoster = "";
  370. if(!empty($urlPoster))
  371. $htmlPoster = "poster='{$urlPoster}'";
  372. $htmlMp4 = "";
  373. if(!empty($urlMp4))
  374. $htmlMp4 = "<source src='{$urlMp4}' type='video/mp4' />";
  375. $htmlWebm = "";
  376. if(!empty($urlWebm))
  377. $htmlWebm = "<source src='{$urlWebm}' type='video/webm' />";
  378. $htmlOgv = "";
  379. if(!empty($urlOgv))
  380. $htmlOgv = "<source src='{$urlOgv}' type='video/ogg' />";
  381. $html = "<video class=\"video-js vjs-default-skin\" controls preload=\"none\" width=\"{$width}\" height=\"{$height}\" \n";
  382. $html .= $htmlPoster ." data-setup=\"{}\"> \n";
  383. $html .= $htmlMp4."\n";
  384. $html .= $htmlWebm."\n";
  385. $html .= $htmlOgv."\n";
  386. $html .= "</video>\n";
  387. return($html);
  388. }
  389. /**
  390. *
  391. * put creative layer
  392. */
  393. private function putCreativeLayer(RevSlide $slide){
  394. $layers = $slide->getLayers();
  395. if(empty($layers))
  396. return(false);
  397. ?>
  398. <?php foreach($layers as $layer):
  399. $type = UniteFunctionsRev::getVal($layer, "type","text");
  400. //set if video full screen
  401. $isFullWidthVideo = false;
  402. if($type == "video"){
  403. $videoData = UniteFunctionsRev::getVal($layer, "video_data");
  404. if(!empty($videoData)){
  405. $videoData = (array)$videoData;
  406. $isFullWidthVideo = UniteFunctionsRev::getVal($videoData, "fullwidth");
  407. $isFullWidthVideo = UniteFunctionsRev::strToBool($isFullWidthVideo);
  408. }else
  409. $videoData = array();
  410. }
  411. $class = UniteFunctionsRev::getVal($layer, "style");
  412. $animation = UniteFunctionsRev::getVal($layer, "animation","fade");
  413. //set output class:
  414. $outputClass = "tp-caption ". trim($class);
  415. $outputClass = trim($outputClass) . " ";
  416. $outputClass .= trim($animation);
  417. $left = UniteFunctionsRev::getVal($layer, "left",0);
  418. $top = UniteFunctionsRev::getVal($layer, "top",0);
  419. $speed = UniteFunctionsRev::getVal($layer, "speed",300);
  420. $time = UniteFunctionsRev::getVal($layer, "time",0);
  421. $easing = UniteFunctionsRev::getVal($layer, "easing","easeOutExpo");
  422. $randomRotate = UniteFunctionsRev::getVal($layer, "random_rotation","false");
  423. $randomRotate = UniteFunctionsRev::boolToStr($randomRotate);
  424. $text = UniteFunctionsRev::getVal($layer, "text");
  425. $htmlVideoAutoplay = "";
  426. $htmlVideoNextSlide = "";
  427. //set html:
  428. $html = "";
  429. switch($type){
  430. default:
  431. case "text":
  432. $html = $text;
  433. $html = do_shortcode($html);
  434. break;
  435. case "image":
  436. $urlImage = UniteFunctionsRev::getVal($layer, "image_url");
  437. $html = '<img src="'.$urlImage.'" alt="'.$text.'">';
  438. $imageLink = UniteFunctionsRev::getVal($layer, "link","");
  439. if(!empty($imageLink)){
  440. $openIn = UniteFunctionsRev::getVal($layer, "link_open_in","same");
  441. $target = "";
  442. if($openIn == "new")
  443. $target = ' target="_blank"';
  444. $html = '<a href="'.$imageLink.'"'.$target.'>'.$html.'</a>';
  445. }
  446. break;
  447. case "video":
  448. $videoType = trim(UniteFunctionsRev::getVal($layer, "video_type"));
  449. $videoID = trim(UniteFunctionsRev::getVal($layer, "video_id"));
  450. $videoWidth = trim(UniteFunctionsRev::getVal($layer, "video_width"));
  451. $videoHeight = trim(UniteFunctionsRev::getVal($layer, "video_height"));
  452. $videoArgs = trim(UniteFunctionsRev::getVal($layer, "video_args"));
  453. if($isFullWidthVideo == true){
  454. $videoWidth = "100%";
  455. $videoHeight = "100%";
  456. }
  457. switch($videoType){
  458. case "youtube":
  459. if(empty($videoArgs))
  460. $videoArgs = GlobalsRevSlider::DEFAULT_YOUTUBE_ARGUMENTS;
  461. $html = "<iframe src='http://www.youtube.com/embed/{$videoID}?{$videoArgs}' width='{$videoWidth}' height='{$videoHeight}' style='width:{$videoWidth}px;height:{$videoHeight}px;'></iframe>";
  462. break;
  463. case "vimeo":
  464. if(empty($videoArgs))
  465. $videoArgs = GlobalsRevSlider::DEFAULT_VIMEO_ARGUMENTS;
  466. $html = "<iframe src='http://player.vimeo.com/video/{$videoID}?{$videoArgs}' width='{$videoWidth}' height='{$videoHeight}' style='width:{$videoWidth}px;height:{$videoHeight}px;'></iframe>";
  467. break;
  468. case "html5":
  469. $html = $this->getHtml5LayerHtml($videoData);
  470. break;
  471. default:
  472. UniteFunctionsRev::throwError("wrong video type: $videoType");
  473. break;
  474. }
  475. //set video autoplay, with backward compatability
  476. if(array_key_exists("autoplay", $videoData))
  477. $videoAutoplay = UniteFunctionsRev::getVal($videoData, "autoplay");
  478. else //backword compatability
  479. $videoAutoplay = UniteFunctionsRev::getVal($layer, "video_autoplay");
  480. $videoAutoplay = UniteFunctionsRev::strToBool($videoAutoplay);
  481. if($videoAutoplay == true)
  482. $htmlVideoAutoplay = ' data-autoplay="true"';
  483. $videoNextSlide = UniteFunctionsRev::getVal($videoData, "nextslide");
  484. $videoNextSlide = UniteFunctionsRev::strToBool($videoNextSlide);
  485. if($videoNextSlide == true)
  486. $htmlVideoNextSlide = ' data-nextslideatend="true"';
  487. break;
  488. }
  489. //handle end transitions:
  490. $endTime = trim(UniteFunctionsRev::getVal($layer, "endtime"));
  491. $htmlEnd = "";
  492. if(!empty($endTime)){
  493. $htmlEnd = "data-end=\"$endTime\"";
  494. $endSpeed = trim(UniteFunctionsRev::getVal($layer, "endspeed"));
  495. if(!empty($endSpeed))
  496. $htmlEnd .= " data-endspeed=\"$endSpeed\"";
  497. $endEasing = trim(UniteFunctionsRev::getVal($layer, "endeasing"));
  498. if(!empty($endSpeed) && $endEasing != "nothing")
  499. $htmlEnd .= " data-endeasing=\"$endEasing\"";
  500. //add animation to class
  501. $endAnimation = trim(UniteFunctionsRev::getVal($layer, "endanimation"));
  502. if(!empty($endAnimation) && $endAnimation != "auto")
  503. $outputClass .= " ".$endAnimation;
  504. }
  505. //slide link
  506. $htmlLink = "";
  507. $slideLink = UniteFunctionsRev::getVal($layer, "link_slide");
  508. if(!empty($slideLink) && $slideLink != "nothing" && $slideLink != "scroll_under"){
  509. //get slide index from id
  510. if(is_numeric($slideLink))
  511. $slideLink = UniteFunctionsRev::getVal($this->slidesNumIndex, $slideLink);
  512. if(!empty($slideLink))
  513. $htmlLink = " data-linktoslide=\"$slideLink\"";
  514. }
  515. //scroll under the slider
  516. if($slideLink == "scroll_under"){
  517. $outputClass .= " tp-scrollbelowslider";
  518. $scrollUnderOffset = UniteFunctionsRev::getVal($layer, "scrollunder_offset");
  519. if(!empty($scrollUnderOffset))
  520. $htmlLink .= " data-scrolloffset=\"{$scrollUnderOffset}\"";
  521. }
  522. //hidden under resolution
  523. $htmlHidden = "";
  524. $layerHidden = UniteFunctionsRev::getVal($layer, "hiddenunder");
  525. if($layerHidden == "true" || $layerHidden == "1")
  526. $htmlHidden = ' data-captionhidden="on"';
  527. $htmlParams = $htmlEnd.$htmlLink.$htmlVideoAutoplay.$htmlVideoNextSlide.$htmlHidden;
  528. //set positioning options
  529. $alignHor = UniteFunctionsRev::getVal($layer,"align_hor","left");
  530. $alignVert = UniteFunctionsRev::getVal($layer, "align_vert","top");
  531. $htmlPosX = "";
  532. $htmlPosY = "";
  533. switch($alignHor){
  534. default:
  535. case "left":
  536. $htmlPosX = "data-x=\"{$left}\" \n";
  537. break;
  538. case "center":
  539. $htmlPosX = "data-x=\"center\" data-hoffset=\"{$left}\" \n";
  540. break;
  541. case "right":
  542. $left = (int)$left*-1;
  543. $htmlPosX = "data-x=\"right\" data-hoffset=\"{$left}\" \n";
  544. break;
  545. }
  546. switch($alignVert){
  547. default:
  548. case "top":
  549. $htmlPosY = "data-y=\"{$top}\" ";
  550. break;
  551. case "middle":
  552. $htmlPosY = "data-y=\"center\" data-voffset=\"{$top}\" ";
  553. break;
  554. case "bottom":
  555. $top = (int)$top*-1;
  556. $htmlPosY = "data-y=\"bottom\" data-voffset=\"{$top}\" ";
  557. break;
  558. }
  559. //set corners
  560. $htmlCorners = "";
  561. if($type == "text"){
  562. $cornerLeft = UniteFunctionsRev::getVal($layer, "corner_left");
  563. $cornerRight = UniteFunctionsRev::getVal($layer, "corner_right");
  564. switch($cornerLeft){
  565. case "curved":
  566. $htmlCorners .= "<div class='frontcorner'></div>";
  567. break;
  568. case "reverced":
  569. $htmlCorners .= "<div class='frontcornertop'></div>";
  570. break;
  571. }
  572. switch($cornerRight){
  573. case "curved":
  574. $htmlCorners .= "<div class='backcorner'></div>";
  575. break;
  576. case "reverced":
  577. $htmlCorners .= "<div class='backcornertop'></div>";
  578. break;
  579. }
  580. //add resizeme class
  581. $resizeme = UniteFunctionsRev::getVal($layer, "resizeme");
  582. if($resizeme == "true" || $resizeme == "1")
  583. $outputClass .= ' tp-resizeme';
  584. }//end text related layer
  585. //make some modifications for the full screen video
  586. if($isFullWidthVideo == true){
  587. $htmlPosX = "data-x=\"0\""."\n";
  588. $htmlPosY = "data-y=\"0\""."\n";
  589. $outputClass .= " fullscreenvideo";
  590. }
  591. ?>
  592. <div class="<?php echo $outputClass?>"
  593. <?php echo $htmlPosX?>
  594. <?php echo $htmlPosY?>
  595. data-speed="<?php echo $speed?>"
  596. data-start="<?php echo $time?>"
  597. data-easing="<?php echo $easing?>" <?php echo $htmlParams?> ><?php echo $html?>
  598. <?php echo $htmlCorners?>
  599. </div>
  600. <?php
  601. endforeach;
  602. }
  603. /**
  604. *
  605. * put slider javascript
  606. */
  607. private function putJS(){
  608. $params = $this->slider->getParams();
  609. $sliderType = $this->slider->getParam("slider_type");
  610. $optFullWidth = ($sliderType == "fullwidth")?"on":"off";
  611. $optFullScreen = "off";
  612. if($sliderType == "fullscreen"){
  613. $optFullWidth = "on";
  614. $optFullScreen = "on";
  615. }
  616. $noConflict = $this->slider->getParam("jquery_noconflict","on");
  617. //set thumb amount
  618. $numSlides = $this->slider->getNumSlides(true);
  619. $thumbAmount = (int)$this->slider->getParam("thumb_amount","5");
  620. if($thumbAmount > $numSlides)
  621. $thumbAmount = $numSlides;
  622. //get stop slider options
  623. $stopSlider = $this->slider->getParam("stop_slider","off");
  624. $stopAfterLoops = $this->slider->getParam("stop_after_loops","0");
  625. $stopAtSlide = $this->slider->getParam("stop_at_slide","2");
  626. if($stopSlider == "off"){
  627. $stopAfterLoops = "-1";
  628. $stopAtSlide = "-1";
  629. }
  630. // set hide navigation after
  631. $hideThumbs = $this->slider->getParam("hide_thumbs","200");
  632. if(is_numeric($hideThumbs) == false)
  633. $hideThumbs = "0";
  634. else{
  635. $hideThumbs = (int)$hideThumbs;
  636. if($hideThumbs < 10)
  637. $hideThumbs = 10;
  638. }
  639. $alwaysOn = $this->slider->getParam("navigaion_always_on","false");
  640. if($alwaysOn == "true")
  641. $hideThumbs = "0";
  642. $sliderID = $this->slider->getID();
  643. //treat hide slider at limit
  644. $hideSliderAtLimit = $this->slider->getParam("hide_slider_under","0",RevSlider::VALIDATE_NUMERIC);
  645. if(!empty($hideSliderAtLimit))
  646. $hideSliderAtLimit++;
  647. //this option is disabled in full width slider
  648. if($sliderType == "fullwidth")
  649. $hideSliderAtLimit = "0";
  650. $hideCaptionAtLimit = $this->slider->getParam("hide_defined_layers_under","0",RevSlider::VALIDATE_NUMERIC);;
  651. if(!empty($hideCaptionAtLimit))
  652. $hideCaptionAtLimit++;
  653. $hideAllCaptionAtLimit = $this->slider->getParam("hide_all_layers_under","0",RevSlider::VALIDATE_NUMERIC);;
  654. if(!empty($hideAllCaptionAtLimit))
  655. $hideAllCaptionAtLimit++;
  656. //start_with_slide
  657. $startWithSlide = $this->slider->getStartWithSlideSetting();
  658. //modify navigation type (backward compatability)
  659. $arrowsType = $this->slider->getParam("navigation_arrows","nexttobullets");
  660. switch($arrowsType){
  661. case "verticalcentered":
  662. $arrowsType = "solo";
  663. break;
  664. }
  665. $videoJsPath = UniteBaseClassRev::$url_plugin."rs-plugin/videojs/";
  666. ?>
  667. <script type="text/javascript">
  668. var tpj=jQuery;
  669. <?php if($noConflict == "on"):?>
  670. tpj.noConflict();
  671. <?php endif;?>
  672. var revapi<?php echo $sliderID?>;
  673. tpj(document).ready(function() {
  674. if (tpj.fn.cssOriginal != undefined)
  675. tpj.fn.css = tpj.fn.cssOriginal;
  676. if(tpj('#<?php echo $this->sliderHtmlID?>').revolution == undefined)
  677. revslider_showDoubleJqueryError('#<?php echo $this->sliderHtmlID?>');
  678. else
  679. revapi<?php echo $sliderID?> = tpj('#<?php echo $this->sliderHtmlID?>').show().revolution(
  680. {
  681. delay:<?php echo $this->slider->getParam("delay","9000",RevSlider::FORCE_NUMERIC)?>,
  682. startwidth:<?php echo $this->slider->getParam("width","900")?>,
  683. startheight:<?php echo $this->slider->getParam("height","300")?>,
  684. hideThumbs:<?php echo $hideThumbs?>,
  685. thumbWidth:<?php echo $this->slider->getParam("thumb_width","100",RevSlider::FORCE_NUMERIC)?>,
  686. thumbHeight:<?php echo $this->slider->getParam("thumb_height","50",RevSlider::FORCE_NUMERIC)?>,
  687. thumbAmount:<?php echo $thumbAmount?>,
  688. navigationType:"<?php echo $this->slider->getParam("navigaion_type","none")?>",
  689. navigationArrows:"<?php echo $arrowsType?>",
  690. navigationStyle:"<?php echo $this->slider->getParam("navigation_style","round")?>",
  691. touchenabled:"<?php echo $this->slider->getParam("touchenabled","on")?>",
  692. onHoverStop:"<?php echo $this->slider->getParam("stop_on_hover","on")?>",
  693. navigationHAlign:"<?php echo $this->slider->getParam("navigaion_align_hor","center")?>",
  694. navigationVAlign:"<?php echo $this->slider->getParam("navigaion_align_vert","bottom")?>",
  695. navigationHOffset:<?php echo $this->slider->getParam("navigaion_offset_hor","0",RevSlider::FORCE_NUMERIC)?>,
  696. navigationVOffset:<?php echo $this->slider->getParam("navigaion_offset_vert","20",RevSlider::FORCE_NUMERIC)?>,
  697. soloArrowLeftHalign:"<?php echo $this->slider->getParam("leftarrow_align_hor","left")?>",
  698. soloArrowLeftValign:"<?php echo $this->slider->getParam("leftarrow_align_vert","center")?>",
  699. soloArrowLeftHOffset:<?php echo $this->slider->getParam("leftarrow_offset_hor","20",RevSlider::FORCE_NUMERIC)?>,
  700. soloArrowLeftVOffset:<?php echo $this->slider->getParam("leftarrow_offset_vert","0",RevSlider::FORCE_NUMERIC)?>,
  701. soloArrowRightHalign:"<?php echo $this->slider->getParam("rightarrow_align_hor","right")?>",
  702. soloArrowRightValign:"<?php echo $this->slider->getParam("rightarrow_align_vert","center")?>",
  703. soloArrowRightHOffset:<?php echo $this->slider->getParam("rightarrow_offset_hor","20",RevSlider::FORCE_NUMERIC)?>,
  704. soloArrowRightVOffset:<?php echo $this->slider->getParam("rightarrow_offset_vert","0",RevSlider::FORCE_NUMERIC)?>,
  705. shadow:<?php echo $this->slider->getParam("shadow_type","2")?>,
  706. fullWidth:"<?php echo $optFullWidth?>",
  707. fullScreen:"<?php echo $optFullScreen?>",
  708. stopLoop:"<?php echo $stopSlider?>",
  709. stopAfterLoops:<?php echo $stopAfterLoops?>,
  710. stopAtSlide:<?php echo $stopAtSlide?>,
  711. shuffle:"<?php echo $this->slider->getParam("shuffle","off") ?>",
  712. hideSliderAtLimit:<?php echo $hideSliderAtLimit?>,
  713. hideCaptionAtLimit:<?php echo $hideCaptionAtLimit?>,
  714. hideAllCaptionAtLilmit:<?php echo $hideAllCaptionAtLimit?>,
  715. startWithSlide:<?php echo $startWithSlide?>,
  716. videoJsPath:"<?php echo $videoJsPath?>",
  717. fullScreenOffsetContainer: "<?php echo $this->slider->getParam("fullscreen_offset_container","");?>"
  718. });
  719. }); //ready
  720. </script>
  721. <?php
  722. }
  723. /**
  724. *
  725. * put inline error message in a box.
  726. */
  727. public function putErrorMessage($message){
  728. ?>
  729. <div style="width:800px;height:300px;margin-bottom:10px;border:1px solid black;margin:0px auto;">
  730. <div style="padding-left:20px;padding-right:20px;line-height:1.5;padding-top:40px;color:red;font-size:16px;text-align:left;">
  731. <?php _e("Revolution Slider Error",REVSLIDER_TEXTDOMAIN)?>: <?php echo $message?>
  732. </div>
  733. </div>
  734. <?php
  735. }
  736. /**
  737. *
  738. * fill the responsitive slider values for further output
  739. */
  740. private function getResponsitiveValues(){
  741. $sliderWidth = (int)$this->slider->getParam("width");
  742. $sliderHeight = (int)$this->slider->getParam("height");
  743. $percent = $sliderHeight / $sliderWidth;
  744. $w1 = (int) $this->slider->getParam("responsitive_w1",0);
  745. $w2 = (int) $this->slider->getParam("responsitive_w2",0);
  746. $w3 = (int) $this->slider->getParam("responsitive_w3",0);
  747. $w4 = (int) $this->slider->getParam("responsitive_w4",0);
  748. $w5 = (int) $this->slider->getParam("responsitive_w5",0);
  749. $w6 = (int) $this->slider->getParam("responsitive_w6",0);
  750. $sw1 = (int) $this->slider->getParam("responsitive_sw1",0);
  751. $sw2 = (int) $this->slider->getParam("responsitive_sw2",0);
  752. $sw3 = (int) $this->slider->getParam("responsitive_sw3",0);
  753. $sw4 = (int) $this->slider->getParam("responsitive_sw4",0);
  754. $sw5 = (int) $this->slider->getParam("responsitive_sw5",0);
  755. $sw6 = (int) $this->slider->getParam("responsitive_sw6",0);
  756. $arrItems = array();
  757. //add main item:
  758. $arr = array();
  759. $arr["maxWidth"] = -1;
  760. $arr["minWidth"] = $w1;
  761. $arr["sliderWidth"] = $sliderWidth;
  762. $arr["sliderHeight"] = $sliderHeight;
  763. $arrItems[] = $arr;
  764. //add item 1:
  765. if(empty($w1))
  766. return($arrItems);
  767. $arr = array();
  768. $arr["maxWidth"] = $w1-1;
  769. $arr["minWidth"] = $w2;
  770. $arr["sliderWidth"] = $sw1;
  771. $arr["sliderHeight"] = floor($sw1 * $percent);
  772. $arrItems[] = $arr;
  773. //add item 2:
  774. if(empty($w2))
  775. return($arrItems);
  776. $arr["maxWidth"] = $w2-1;
  777. $arr["minWidth"] = $w3;
  778. $arr["sliderWidth"] = $sw2;
  779. $arr["sliderHeight"] = floor($sw2 * $percent);
  780. $arrItems[] = $arr;
  781. //add item 3:
  782. if(empty($w3))
  783. return($arrItems);
  784. $arr["maxWidth"] = $w3-1;
  785. $arr["minWidth"] = $w4;
  786. $arr["sliderWidth"] = $sw3;
  787. $arr["sliderHeight"] = floor($sw3 * $percent);
  788. $arrItems[] = $arr;
  789. //add item 4:
  790. if(empty($w4))
  791. return($arrItems);
  792. $arr["maxWidth"] = $w4-1;
  793. $arr["minWidth"] = $w5;
  794. $arr["sliderWidth"] = $sw4;
  795. $arr["sliderHeight"] = floor($sw4 * $percent);
  796. $arrItems[] = $arr;
  797. //add item 5:
  798. if(empty($w5))
  799. return($arrItems);
  800. $arr["maxWidth"] = $w5-1;
  801. $arr["minWidth"] = $w6;
  802. $arr["sliderWidth"] = $sw5;
  803. $arr["sliderHeight"] = floor($sw5 * $percent);
  804. $arrItems[] = $arr;
  805. //add item 6:
  806. if(empty($w6))
  807. return($arrItems);
  808. $arr["maxWidth"] = $w6-1;
  809. $arr["minWidth"] = 0;
  810. $arr["sliderWidth"] = $sw6;
  811. $arr["sliderHeight"] = floor($sw6 * $percent);
  812. $arrItems[] = $arr;
  813. return($arrItems);
  814. }
  815. /**
  816. *
  817. * put responsitive inline styles
  818. */
  819. private function putResponsitiveStyles(){
  820. $bannerWidth = $this->slider->getParam("width");
  821. $bannerHeight = $this->slider->getParam("height");
  822. $arrItems = $this->getResponsitiveValues();
  823. ?>
  824. <style type='text/css'>
  825. #<?php echo $this->sliderHtmlID?>, #<?php echo $this->sliderHtmlID_wrapper?> { width:<?php echo $bannerWidth?>px; height:<?php echo $bannerHeight?>px;}
  826. <?php
  827. foreach($arrItems as $item):
  828. $strMaxWidth = "";
  829. if($item["maxWidth"] >= 0)
  830. $strMaxWidth = "and (max-width: {$item["maxWidth"]}px)";
  831. ?>
  832. @media only screen and (min-width: <?php echo $item["minWidth"]?>px) <?php echo $strMaxWidth?> {
  833. #<?php echo $this->sliderHtmlID?>, #<?php echo $this->sliderHtmlID_wrapper?> { width:<?php echo $item["sliderWidth"]?>px; height:<?php echo $item["sliderHeight"]?>px;}
  834. }
  835. <?php
  836. endforeach;
  837. echo "</style>";
  838. }
  839. /**
  840. *
  841. * modify slider settings for preview mode
  842. */
  843. private function modifyPreviewModeSettings(){
  844. $params = $this->slider->getParams();
  845. $params["js_to_body"] = "false";
  846. $this->slider->setParams($params);
  847. }
  848. /**
  849. *
  850. * put html slider on the html page.
  851. * @param $data - mixed, can be ID ot Alias.
  852. */
  853. //TODO: settings google font, position, margin, background color, alt image text
  854. public function putSliderBase($sliderID){
  855. try{
  856. self::$sliderSerial++;
  857. $this->slider = new RevSlider();
  858. $this->slider->initByMixed($sliderID);
  859. //modify settings for admin preview mode
  860. if($this->previewMode == true)
  861. $this->modifyPreviewModeSettings();
  862. //set slider language
  863. $isWpmlExists = UniteWpmlRev::isWpmlExists();
  864. $useWpml = $this->slider->getParam("use_wpml","off");
  865. if( $isWpmlExists && $useWpml == "on"){
  866. if($this->previewMode == false)
  867. $this->sliderLang = UniteFunctionsWPRev::getCurrentLangCode();
  868. }
  869. //edit html before slider
  870. $htmlBeforeSlider = "";
  871. if($this->slider->getParam("load_googlefont","false") == "true"){
  872. $googleFont = $this->slider->getParam("google_font");
  873. $htmlBeforeSlider = "<link rel='stylesheet' id='rev-google-font' href='http://fonts.googleapis.com/css?family={$googleFont}' type='text/css' media='all' />";
  874. }
  875. //pub js to body handle
  876. if($this->slider->getParam("js_to_body","false") == "true"){
  877. $urlIncludeJS = UniteBaseClassRev::$url_plugin."rs-plugin/js/jquery.themepunch.revolution.min.js";
  878. $htmlBeforeSlider .= "<script type='text/javascript' src='$urlIncludeJS'></script>";
  879. }
  880. //the initial id can be alias
  881. $sliderID = $this->slider->getID();
  882. $bannerWidth = $this->slider->getParam("width",null,RevSlider::VALIDATE_NUMERIC,"Slider Width");
  883. $bannerHeight = $this->slider->getParam("height",null,RevSlider::VALIDATE_NUMERIC,"Slider Height");
  884. $sliderType = $this->slider->getParam("slider_type");
  885. //set wrapper height
  886. $wrapperHeigh = 0;
  887. $wrapperHeigh += $this->slider->getParam("height");
  888. //add thumb height
  889. if($this->slider->getParam("navigaion_type") == "thumb"){
  890. $wrapperHeigh += $this->slider->getParam("thumb_height");
  891. }
  892. $this->sliderHtmlID = "rev_slider_".$sliderID."_".self::$sliderSerial;
  893. $this->sliderHtmlID_wrapper = $this->sliderHtmlID."_wrapper";
  894. $containerStyle = "";
  895. $sliderPosition = $this->slider->getParam("position","center");
  896. //set position:
  897. if($sliderType != "fullscreen"){
  898. switch($sliderPosition){
  899. case "center":
  900. default:
  901. $containerStyle .= "margin:0px auto;";
  902. break;
  903. case "left":
  904. $containerStyle .= "float:left;";
  905. break;
  906. case "right":
  907. $containerStyle .= "float:right;";
  908. break;
  909. }
  910. }
  911. //add background color
  912. $backgrondColor = trim($this->slider->getParam("background_color"));
  913. if(!empty($backgrondColor))
  914. $containerStyle .= "background-color:$backgrondColor;";
  915. //set padding
  916. $containerStyle .= "padding:".$this->slider->getParam("padding","0")."px;";
  917. //set margin:
  918. if($sliderType != "fullscreen"){
  919. if($sliderPosition != "center"){
  920. $containerStyle .= "margin-left:".$this->slider->getParam("margin_left","0")."px;";
  921. $containerStyle .= "margin-right:".$this->slider->getParam("margin_right","0")."px;";
  922. }
  923. $containerStyle .= "margin-top:".$this->slider->getParam("margin_top","0")."px;";
  924. $containerStyle .= "margin-bottom:".$this->slider->getParam("margin_bottom","0")."px;";
  925. }
  926. //set height and width:
  927. $bannerStyle = "display:none;";
  928. //add background image (to banner style)
  929. $showBackgroundImage = $this->slider->getParam("show_background_image","false");
  930. if($showBackgroundImage == "true"){
  931. $backgroundImage = $this->slider->getParam("background_image");
  932. if(!empty($backgroundImage))
  933. $bannerStyle .= "background-image:url($backgroundImage);background-repeat:no-repeat;";
  934. }
  935. //set wrapper and slider class:
  936. $sliderWrapperClass = "rev_slider_wrapper";
  937. $sliderClass = "rev_slider";
  938. $putResponsiveStyles = false;
  939. switch($sliderType){
  940. default:
  941. case "fixed":
  942. $bannerStyle .= "height:{$bannerHeight}px;width:{$bannerWidth}px;";
  943. $containerStyle .= "height:{$bannerHeight}px;width:{$bannerWidth}px;";
  944. break;
  945. case "responsitive":
  946. $putResponsiveStyles = true;
  947. break;
  948. case "fullwidth":
  949. $sliderWrapperClass .= " fullwidthbanner-container";
  950. $sliderClass .= " fullwidthabanner";
  951. $bannerStyle .= "max-height:{$bannerHeight}px;height:{$bannerHeight};";
  952. $containerStyle .= "max-height:{$bannerHeight}px;";
  953. break;
  954. case "fullscreen":
  955. $sliderWrapperClass .= " fullscreen-container";
  956. $sliderClass .= " fullscreenbanner";
  957. break;
  958. }
  959. $htmlTimerBar = "";
  960. $timerBar = $this->slider->getParam("show_timerbar","top");
  961. if($timerBar == "true")
  962. $timerBar = $this->slider->getParam("timebar_position","top");
  963. switch($timerBar){
  964. case "top":
  965. $htmlTimerBar = '<div class="tp-bannertimer"></div>';
  966. break;
  967. case "bottom":
  968. $htmlTimerBar = '<div class="tp-bannertimer tp-bottom"></div>';
  969. break;
  970. }
  971. //check inner / outer border
  972. $paddingType = $this->slider->getParam("padding_type","outter");
  973. if($paddingType == "inner")
  974. $sliderWrapperClass .= " tp_inner_padding";
  975. global $revSliderVersion;
  976. ?>
  977. <!-- START REVOLUTION SLIDER <?php echo $revSliderVersion?> <?php echo $sliderType?> mode -->
  978. <?php
  979. if($putResponsiveStyles == true)
  980. $this->putResponsitiveStyles(); ?>
  981. <?php echo $htmlBeforeSlider?>
  982. <div id="<?php echo $this->sliderHtmlID_wrapper?>" class="<?php echo $sliderWrapperClass?>" style="<?php echo $containerStyle?>">
  983. <div id="<?php echo $this->sliderHtmlID ?>" class="<?php echo $sliderClass?>" style="<?php echo $bannerStyle?>">
  984. <?php $this->putSlides()?>
  985. <?php echo $htmlTimerBar?>
  986. </div>
  987. </div>
  988. <?php
  989. $this->putJS();
  990. ?>
  991. <!-- END REVOLUTION SLIDER -->
  992. <?php
  993. }catch(Exception $e){
  994. $message = $e->getMessage();
  995. $this->putErrorMessage($message);
  996. }
  997. }
  998. }
  999. ?>