PageRenderTime 62ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/uBillboard/lib/uBillboard.class.php

https://github.com/nunomorgadinho/AMMPro
PHP | 909 lines | 666 code | 99 blank | 144 comment | 44 complexity | 33318d2299f759708c3cc21d04c860a6 MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. // define general options for billboard
  3. $uds_billboard_general_options = array(
  4. 'name' => array(
  5. 'type' => 'text',
  6. 'label' => __('Billboard Name', uds_billboard_textdomain),
  7. 'unit' => '',
  8. 'tooltip' => __('Enter a name for this Billboard. You will use this name to create the Billboard on your site.', uds_billboard_textdomain),
  9. 'default' => 'billboard'
  10. ),
  11. 'width' => array(
  12. 'type' => 'text',
  13. 'label' => __('Width', uds_billboard_textdomain),
  14. 'unit' => 'px',
  15. 'tooltip' => __('Billboard Width in pixels', uds_billboard_textdomain),
  16. 'default' => 940
  17. ),
  18. 'height' => array(
  19. 'type' => 'text',
  20. 'label' => __('Height', uds_billboard_textdomain),
  21. 'unit' => 'px',
  22. 'tooltip' => __('Billboard Height in pixels', uds_billboard_textdomain),
  23. 'default' => 380
  24. ),
  25. 'autoplay' => array(
  26. 'type' => 'checkbox',
  27. 'label' => __('Autoplay', uds_billboard_textdomain),
  28. 'unit' => '',
  29. 'tooltip' => __('Automatically start playing slides, makes sense to turn this off only if Show Controls is enabled.', uds_billboard_textdomain),
  30. 'default' => 'on'
  31. ),
  32. 'pause-on-video' => array(
  33. 'type' => 'checkbox',
  34. 'label' => __('Pause on video', uds_billboard_textdomain),
  35. 'unit' => '',
  36. 'tooltip' => __('Pause playback if slide with embedded video is encountered.', uds_billboard_textdomain),
  37. 'default' => 'on'
  38. ),
  39. 'randomize' => array(
  40. 'type' => 'checkbox',
  41. 'label' => __('Shuffle Slides', uds_billboard_textdomain),
  42. 'unit' => '',
  43. 'tooltip' => __('Shuffle slides each time the slider is loaded', uds_billboard_textdomain),
  44. 'default' => ''
  45. ),
  46. 'square-size' => array(
  47. 'type' => 'text',
  48. 'label' => __('Square Size', uds_billboard_textdomain),
  49. 'unit' => 'pixels',
  50. 'tooltip' => __('Square dimension, applies only to transitions based on squares', uds_billboard_textdomain),
  51. 'default' => 100
  52. ),
  53. 'style' => array(
  54. 'type' => 'select',
  55. 'label' => __('Style', uds_billboard_textdomain),
  56. 'unit' => '',
  57. 'tooltip' => '',
  58. 'options' => array(
  59. 'dark' => __('Dark', uds_billboard_textdomain),
  60. 'bright' => __('Bright', uds_billboard_textdomain)
  61. ),
  62. 'default' => ''
  63. ),
  64. 'show-timer' => array(
  65. 'type' => 'checkbox',
  66. 'label' => __('Show Timer', uds_billboard_textdomain),
  67. 'unit' => '',
  68. 'tooltip' => __('Shows countdown until the next slide transition when playing', uds_billboard_textdomain),
  69. 'default' => 'on'
  70. ),
  71. 'controls-skin' => array(
  72. 'type' => 'select',
  73. 'label' => __('Skin', uds_billboard_textdomain),
  74. 'unit' => '',
  75. 'tooltip' => __('How the controls should look', uds_billboard_textdomain),
  76. 'options' => array(
  77. 'mini' => __('Minimal Style Controls', uds_billboard_textdomain),
  78. 'oldskool' => __('Old School uBillboard', uds_billboard_textdomain),
  79. 'oldskool-bright' => __('Bright Old School uBillboard', uds_billboard_textdomain),
  80. 'utube' => __('uTube', uds_billboard_textdomain),
  81. 'silver' => __('Silver', uds_billboard_textdomain),
  82. 'modern' => __('Modern', uds_billboard_textdomain),
  83. 'ubb-v2' => __('uBillboard v2', uds_billboard_textdomain)
  84. ),
  85. 'default' => 'oldskool'
  86. ),
  87. 'controls-position' => array(
  88. 'type' => 'select',
  89. 'label' => __('Position', uds_billboard_textdomain),
  90. 'unit' => '',
  91. 'tooltip' => '',
  92. 'options' => array(
  93. 'inside' => __('Inside', uds_billboard_textdomain),
  94. 'outside' => __('Outside', uds_billboard_textdomain)
  95. ),
  96. 'default' => 'inside'
  97. ),
  98. 'show-controls' => array(
  99. 'type' => 'select',
  100. 'label' => __('Show Controls', uds_billboard_textdomain),
  101. 'unit' => '',
  102. 'tooltip' => __('Controls enable you to switch between slides', uds_billboard_textdomain),
  103. 'options' => array(
  104. 'no' => __("Don't show controls", uds_billboard_textdomain),
  105. 'hover' => __('Show on Mouse Hover', uds_billboard_textdomain),
  106. 'yes' => __('Show at all times', uds_billboard_textdomain)
  107. ),
  108. 'default' => 'yes'
  109. ),
  110. 'show-pause' => array(
  111. 'type' => 'select',
  112. 'label' => __('Show Play/Pause', uds_billboard_textdomain),
  113. 'unit' => '',
  114. 'tooltip' => __('Display show pause button', uds_billboard_textdomain),
  115. 'options' => array(
  116. 'no' => __("Don't show Play/Pause", uds_billboard_textdomain),
  117. 'hover' => __('Show on Mouse Hover', uds_billboard_textdomain),
  118. 'yes' => __('Show at all times', uds_billboard_textdomain)
  119. ),
  120. 'default' => 'yes'
  121. ),
  122. 'show-paginator' => array(
  123. 'type' => 'select',
  124. 'label' => __('Show Paginator', uds_billboard_textdomain),
  125. 'unit' => '',
  126. 'tooltip' => __('Display pagination control', uds_billboard_textdomain),
  127. 'options' => array(
  128. 'no' => __("Don't show Paginator", uds_billboard_textdomain),
  129. 'hover' => __('Show on Mouse Hover', uds_billboard_textdomain),
  130. 'yes' => __('Show at all times', uds_billboard_textdomain)
  131. ),
  132. 'default' => 'yes'
  133. ),
  134. 'show-thumbnails' => array(
  135. 'type' => 'select',
  136. 'label' => __('Show Thumbnails', uds_billboard_textdomain),
  137. 'unit' => '',
  138. 'tooltip' => __('Small preview images for all slides', uds_billboard_textdomain),
  139. 'options' => array(
  140. 'no' => __("Don't show Thumbnails", uds_billboard_textdomain),
  141. 'hover' => __('Show on Mouse Hover', uds_billboard_textdomain),
  142. 'yes' => __('Show at all times', uds_billboard_textdomain)
  143. ),
  144. 'default' => 'yes'
  145. ),
  146. 'thumbnails-position' => array(
  147. 'type' => 'select',
  148. 'label' => __('Thumbnail Position', uds_billboard_textdomain),
  149. 'unit' => '',
  150. 'tooltip' => __('Where do you want thumbs to show', uds_billboard_textdomain),
  151. 'options' => array(
  152. 'top' => __('Top', uds_billboard_textdomain),
  153. 'bottom' => __('Bottom', uds_billboard_textdomain),
  154. 'right' => __('Right', uds_billboard_textdomain),
  155. 'left' => __('Left', uds_billboard_textdomain)
  156. ),
  157. 'default' => 'bottom'
  158. ),
  159. 'thumbnails-inside' => array(
  160. 'type' => 'checkbox',
  161. 'label' => __('Inside', uds_billboard_textdomain),
  162. 'unit' => '',
  163. 'tooltip' => __('Where do you want thumbs to show', uds_billboard_textdomain),
  164. 'default' => ''
  165. ),
  166. 'thumbnails-width' => array(
  167. 'type' => 'text',
  168. 'label' => __('Thumbnail Width', uds_billboard_textdomain),
  169. 'unit' => 'px',
  170. 'tooltip' => __('Width of the thumbnail images', uds_billboard_textdomain),
  171. 'default' => '80'
  172. ),
  173. 'thumbnails-height' => array(
  174. 'type' => 'text',
  175. 'label' => __('Thumbnail Height', uds_billboard_textdomain),
  176. 'unit' => 'px',
  177. 'tooltip' => __('Height of the thumbnail images', uds_billboard_textdomain),
  178. 'default' => '60'
  179. ),
  180. 'thumbnails-hover-color' => array(
  181. 'type' => 'color',
  182. 'unit' => '',
  183. 'label' => __('Thumbnail border hover color', uds_billboard_textdomain),
  184. 'tooltip' => __('Border color of thumbnail on mouse over', uds_billboard_textdomain),
  185. 'default' => 'red'
  186. )
  187. );
  188. class uBillboard {
  189. /**
  190. * @var array of slides in this slider
  191. */
  192. private $slides;
  193. /**
  194. * @var array of slides in this slider that have already been rendered
  195. * This is used to render slide JS in the correct order
  196. */
  197. private $slidesRendered;
  198. /**
  199. * Helper static function to transform an oldschool
  200. * uBillboard v2 style billboards array into v3 format
  201. *
  202. * @param array $billboards v2 style billboards array
  203. *
  204. * @return array of v3 billboards
  205. */
  206. public static function upgradeFromV2($billboards)
  207. {
  208. $v2 = array();
  209. foreach($billboards as $name => $bbv2) {
  210. $billboard = new uBillboard(array(
  211. 'name' => $name,
  212. 'width' => $bbv2['width'],
  213. 'height' => $bbv2['height'],
  214. 'autoplay' => $bbv2['autoplay'],
  215. 'randomize' => isset($bbv2['randomize']) ? $bbv2['randomize'] : '',
  216. 'square-size' => $bbv2['square-size'],
  217. 'style' => 'dark',
  218. 'show-timer' => '',
  219. 'controls-skin' => 'oldskool',
  220. 'controls-position' => 'inside',
  221. 'show-paginator' => $bbv2['show-paginator'] == 'on' ? 'yes' : 'no',
  222. 'show-controls' => $bbv2['show-controls'] == 'on' ? 'yes' : 'no',
  223. 'show-pause' => $bbv2['show-pause'] == 'on' ? 'yes' : 'no',
  224. 'show-thumbnails' => 'no'
  225. ));
  226. foreach($bbv2['slides'] as $slide) {
  227. $v3slide = uBillboardSlide::upgradeFromV2($slide, $bbv2, $billboard);
  228. $billboard->addSlide($v3slide);
  229. }
  230. $v2[$name] = $billboard;
  231. }
  232. $v3 = maybe_unserialize(get_option(UDS_BILLBOARD_OPTION, array()));
  233. $v3 = array_merge($v3, $v2);
  234. return $v3;
  235. }
  236. /**
  237. * Constructor, will parse $options to create uBillboard
  238. *
  239. * @param array|bool $options
  240. * @return uBillboard
  241. */
  242. public function __construct($options = false)
  243. {
  244. global $uds_billboard_general_options;
  245. foreach($uds_billboard_general_options as $key => $option) {
  246. $camelized = $this->camelize($key);
  247. if(isset($options[$key])) {
  248. $this->{$camelized} = $this->sanitizeOption($key, $options[$key]);
  249. unset($options[$key]);
  250. } else {
  251. $this->{$camelized} = $option['default'];
  252. }
  253. }
  254. $this->slides = array();
  255. $this->slidesRendered = array();
  256. }
  257. /**
  258. * Generalized getter
  259. *
  260. * @return mixed
  261. */
  262. public function __get($key)
  263. {
  264. $key = $this->camelize($key);
  265. return $this->{$key};
  266. }
  267. /**
  268. * unserialize uBillboard, reset all attributes that
  269. * are not present to their default values
  270. *
  271. * @return void
  272. */
  273. public function __wakeup()
  274. {
  275. global $uds_billboard_general_options;
  276. foreach($uds_billboard_general_options as $key => $option) {
  277. $camelized = $this->camelize($key);
  278. if(!isset($this->{$camelized})) {
  279. $this->{$camelized} = $option['default'];
  280. }
  281. }
  282. foreach($this->slides as $id => $slide) {
  283. $slide->setId($id);
  284. $slide->setSlider($this);
  285. }
  286. }
  287. /**
  288. * Importer, set up current instance based on SimpleXMLElement
  289. * XML data from an import file
  290. *
  291. * @return void
  292. */
  293. public function importFromXML($billboard)
  294. {
  295. global $uds_billboard_general_options;
  296. foreach($billboard->properties[0] as $property){
  297. foreach($uds_billboard_general_options as $key => $option) {
  298. if($property->key == $key) {
  299. $camelized = $this->camelize($key);
  300. $this->{$camelized} = (string)$property->value;
  301. }
  302. }
  303. }
  304. foreach($billboard->slides->slide as $slide) {
  305. $s = new uBillboardSlide(false, $this);
  306. $s->importFromXML($slide);
  307. $this->slides[] = $s;
  308. }
  309. }
  310. /**
  311. * Helper, make sure that this uBillboard has an unique name among other uBillboards
  312. * in this installation
  313. *
  314. * @return void
  315. */
  316. public function setUniqueName()
  317. {
  318. $billboards = array_keys(maybe_unserialize(get_option(UDS_BILLBOARD_OPTION, array())));
  319. $guess = $root = 'billboard';
  320. $i = 1;
  321. while(in_array($guess, $billboards)) {
  322. $guess = $root . '-' . $i;
  323. $i++;
  324. }
  325. $this->name = $guess;
  326. }
  327. /**
  328. * Function, adds a new slide to the end of the slide array
  329. *
  330. * @return bool success
  331. */
  332. public function addSlide($slide)
  333. {
  334. if(is_a($slide, 'uBillboardSlide')) {
  335. $this->slides[] = $slide;
  336. return true;
  337. }
  338. return false;
  339. }
  340. /**
  341. * Update current uBillboard with data from the $options array
  342. *
  343. * @param array $options
  344. *
  345. * @return void
  346. */
  347. public function update($options)
  348. {
  349. global $uds_billboard_general_options;
  350. foreach($uds_billboard_general_options as $key => $option) {
  351. $camelized = $this->camelize($key);
  352. if(isset($options[$key])) {
  353. $this->{$camelized} = $this->sanitizeOption($key, $options[$key]);
  354. unset($options[$key]);
  355. } else {
  356. $this->{$camelized} = '';
  357. }
  358. }
  359. $this->slides = uBillboardSlide::getSlides($options, $this);
  360. if(!empty($this->slides)) {
  361. foreach($this->slides as $key => $slide) {
  362. $slide->setId($key);
  363. if(!$slide->isValid()) {
  364. unset($this->slides[$key]);
  365. }
  366. }
  367. }
  368. }
  369. /**
  370. * Helper function, performs internal checks to determine if uBillboard
  371. * is valid
  372. *
  373. * @return bool
  374. */
  375. public function isValid()
  376. {
  377. return !empty($this->slides);
  378. }
  379. /**
  380. * Add empty default slide to the end of slide array
  381. *
  382. * @return void
  383. */
  384. public function addEmptySlide()
  385. {
  386. $this->slides[] = new uBillboardSlide(false, $this);
  387. }
  388. /**
  389. * Exporter, exports self in the XML format that can be read by the importer
  390. *
  391. * @return void
  392. */
  393. public function export()
  394. {
  395. global $uds_billboard_general_options;
  396. $out = ' <udsBillboard>' . "\n";
  397. $out .= ' <properties>'. "\n";
  398. foreach($uds_billboard_general_options as $key => $option) {
  399. $camelKey = $this->camelize($key);
  400. $out .= ' <property>' . "\n";
  401. $out .= ' <key>' . $key . '</key>' . "\n";
  402. $out .= ' <value><![CDATA[' . $this->{$key} . ']]></value>' . "\n";
  403. $out .= ' </property>' . "\n";
  404. }
  405. $out .= ' </properties>'. "\n";
  406. $out .= ' <slides>' . "\n";
  407. foreach($this->slides as $slide) {
  408. $out .= $slide->export();
  409. }
  410. $out .= ' </slides>' . "\n";
  411. $out .= ' </udsBillboard>' . "\n";
  412. return $out;
  413. }
  414. public function createThumbs()
  415. {
  416. $ok = true;
  417. foreach($this->slides as $slide) {
  418. $result = $slide->resizeImages(true);
  419. if(is_wp_error($result)) {
  420. $ok = false;
  421. }
  422. }
  423. return $ok;
  424. }
  425. /**
  426. * The main frontend renderer
  427. *
  428. * @param int $id ID of the current uBillboard on the currently rendered page
  429. * @return string rendered html markup
  430. */
  431. public function render($id = 0)
  432. {
  433. global $uds_bb_params; // parameters of the currently rendered billboard
  434. // store width and height into the params
  435. $uds_bb_params = array(
  436. 'width' => $this->width,
  437. 'height' => $this->height
  438. );
  439. $slides = $this->renderSlides();
  440. $controls = $this->renderControls();
  441. $out = "
  442. <!-- uBillboard ".UDS_BILLBOARD_VERSION." ID:$id -->
  443. <div class='uds-bb uds-{$this->style}' id='uds-bb-$id' style='width:{$this->width}px;height:{$this->height}px'>
  444. $controls
  445. $slides
  446. </div>
  447. <!-- END uBillboard ID:$id -->";
  448. return $out;
  449. }
  450. /**
  451. * Render JS calls for the uBillboard
  452. *
  453. * @return string rendered JS
  454. */
  455. public function renderJS($id = 0)
  456. {
  457. $autoplay = $this->autoplay === 'on' ? 'true' : 'false';
  458. $pauseOnVideo = $this->pauseOnVideo === 'on' ? 'true' : 'false';
  459. $showTimer = $this->showTimer === 'on' ? 'true' : 'false';
  460. $showControls = 'false';
  461. if($this->showControls == 'hover') $showControls = "'hover'";
  462. if($this->showControls == 'yes') $showControls = 'true';
  463. $showPause = 'false';
  464. if($this->showPause == 'hover') $showPause = "'hover'";
  465. if($this->showPause == 'yes') $showPause = 'true';
  466. $showPaginator = 'false';
  467. if($this->showPaginator == 'hover') $showPaginator = "'hover'";
  468. if($this->showPaginator == 'yes') $showPaginator = 'true';
  469. $showThumbnails = 'false';
  470. if($this->showThumbnails == 'hover') $showThumbnails = "'hover'";
  471. if($this->showThumbnails == 'yes') $showThumbnails = 'true';
  472. $thumbnailsHoverColor = $this->thumbnailsHoverColor;
  473. // Render slides' JS
  474. $slides = array();
  475. foreach($this->slidesRendered as $key => $slide) {
  476. $slides[] = $key . ': ' . $slide->renderJS();
  477. }
  478. $slides = implode(",\n\t\t\t\t\t", $slides);
  479. $scripts = "
  480. $('#uds-bb-$id').show().uBillboard({
  481. width: '{$this->width}px',
  482. height: '{$this->height}px',
  483. squareSize: '{$this->squareSize}px',
  484. autoplay: $autoplay,
  485. pauseOnVideo: $pauseOnVideo,
  486. showControls: $showControls,
  487. showPause: $showPause,
  488. showPaginator: $showPaginator,
  489. showThumbnails: $showThumbnails,
  490. showTimer: $showTimer,
  491. thumbnailHoverColor: \"#$thumbnailsHoverColor\",
  492. slides: {
  493. $slides
  494. }
  495. });
  496. ";
  497. return $scripts;
  498. }
  499. /**
  500. * Admin renderer function for every field
  501. *
  502. * @return
  503. */
  504. public function renderAdminOption($option)
  505. {
  506. global $uds_billboard_general_options;
  507. $field = $uds_billboard_general_options[$option];
  508. $camelized = $this->camelize($option);
  509. $value = $this->{$camelized};
  510. switch($uds_billboard_general_options[$option]['type']) {
  511. case 'text':
  512. $this->renderAdminOptionText($option, $field, $value);
  513. break;
  514. case 'checkbox':
  515. $this->renderAdminOptionCheckbox($option, $field, $value);
  516. break;
  517. case 'color':
  518. $this->renderAdminColorpicker($option, $field, $value);
  519. break;
  520. case 'select':
  521. $this->renderAdminOptionSelect($option, $field, $value);
  522. break;
  523. }
  524. }
  525. // Functions to render single fields in general options for each billboard
  526. public function renderAdminOptionText($option, $field, $value)
  527. {
  528. ?>
  529. <div class="uds-billboard-<?php echo $option ?> option-container">
  530. <label for="uds-billboard-<?php echo $option ?>"><?php echo $field['label'] ?></label>
  531. <input type="text" id="uds-billboard-<?php echo $option ?>" name="uds_billboard[<?php echo $option ?>]" value="<?php echo empty($value) ? $field['default'] : $value ?>" class="text" />
  532. <span class="unit"><?php echo $field['unit'] ?></span>
  533. <div class="tooltip-content"><?php echo $field['tooltip'] ?></div>
  534. <div class="clear"></div>
  535. </div>
  536. <?php
  537. }
  538. public function renderAdminOptionCheckbox($option, $field, $value)
  539. {
  540. $checked = ( $value === null ? $field['default'] : $value ) == 'on' ? 'checked="checked"' : '';
  541. ?>
  542. <div class="uds-billboard-<?php echo $option ?> option-container">
  543. <label for="uds-billboard-<?php echo $option ?>"><?php echo $field['label'] ?></label>
  544. <input type="checkbox" id="uds-billboard-<?php echo $option ?>" name="uds_billboard[<?php echo $option ?>]" <?php echo $checked ?> class="checkbox" />
  545. <span class="unit"><?php echo $field['unit'] ?></span>
  546. <div class="tooltip-content"><?php echo $field['tooltip'] ?></div>
  547. <div class="clear"></div>
  548. </div>
  549. <?php
  550. }
  551. function renderAdminOptionSelect($option, $field, $value)
  552. {
  553. $checked = ( $value === null ? $field['default'] : $value ) == 'on' ? 'checked="checked"' : '';
  554. ?>
  555. <div class="uds-billboard-<?php echo $option ?> option-container select">
  556. <label for="uds-billboard-<?php echo $option ?>"><?php echo $field['label'] ?></label>
  557. <select id="uds-billboard-<?php echo $option ?>" name="uds_billboard[<?php echo $option ?>]" class="select">
  558. <option value="" disabled="disabled"><?php echo $field['label'] ?></option>
  559. <?php foreach($field['options'] as $key => $label): ?>
  560. <option value="<?php echo $key ?>" <?php echo $key == $value ? 'selected="selected"' : '' ?>><?php echo $label ?></option>
  561. <?php endforeach; ?>
  562. </select>
  563. <span class="unit"><?php echo $field['unit'] ?></span>
  564. <div class="tooltip-content"><?php echo $field['tooltip'] ?></div>
  565. <div class="clear"></div>
  566. </div>
  567. <?php
  568. }
  569. function renderAdminColorpicker($option, $field, $value)
  570. {
  571. ?>
  572. <div class="uds-billboard-<?php echo $option ?> option-container color">
  573. <label for="uds-billboard-<?php echo $option ?>"><?php echo $field['label'] ?></label>
  574. #<input type="text" id="uds-billboard-<?php echo $option ?>" name="uds_billboard[<?php echo $option ?>]" value="<?php echo $value ?>" class="color" />
  575. <div class="tooltip-content"><?php echo $field['tooltip'] ?></div>
  576. <div class="clear"></div>
  577. </div>
  578. <?php
  579. }
  580. private function renderSlides()
  581. {
  582. $out = "<div class='uds-bb-slides'>\n";
  583. $slides = $this->slides;
  584. if($this->randomize === "on") {
  585. shuffle($slides);
  586. }
  587. $this->slides = $slides;
  588. foreach($slides as $slide) {
  589. $out .= $slide->render();
  590. $this->slidesRendered[] = $slide;
  591. }
  592. $out .= "\t\t\t</div>";
  593. return $out;
  594. }
  595. private function renderControls()
  596. {
  597. $out = "<div class='uds-bb-controls'>";
  598. switch($this->controlsSkin){
  599. case 'mini':
  600. $out .= $this->paginatorMini();
  601. break;
  602. case 'oldskool':
  603. $out .= $this->paginatorOldskool();
  604. break;
  605. case 'oldskool-bright':
  606. $out .= $this->paginatorOldskoolBright();
  607. break;
  608. case 'utube':
  609. $out .= $this->paginatoruTube();
  610. break;
  611. case 'silver':
  612. $out .= $this->paginatorSilver();
  613. break;
  614. case 'modern':
  615. $out .= $this->paginatorModern();
  616. break;
  617. case 'ubb-v2':
  618. $out .= $this->paginatorUbbv2();
  619. }
  620. if($this->showThumbnails !== 'no') {
  621. $out .= $this->thumbnails($this->slides);
  622. }
  623. $out .= "\t\t\t</div>\n";
  624. return $out;
  625. }
  626. /**
  627. * Mini paginator renderer
  628. *
  629. * @return string rendered paginator
  630. */
  631. private function paginatorMini()
  632. {
  633. $out = "
  634. <div class='uds-bb-paginator mini {$this->controlsPosition}'>
  635. <div class='uds-bb-button uds-bb-playpause'>".__('Play', uds_billboard_textdomain)."</div>
  636. <div class='uds-bb-button uds-bb-prev'>".__('Prev', uds_billboard_textdomain)."</div>
  637. <div class='uds-bb-button uds-bb-next'>".__('Next', uds_billboard_textdomain)."</div>
  638. <div class='uds-bb-position-indicator'></div>
  639. </div>
  640. ";
  641. return $out;
  642. }
  643. /**
  644. * Oldskool paginator renderer
  645. *
  646. * @return string rendered paginator
  647. */
  648. private function paginatorOldskool()
  649. {
  650. $out = "
  651. <div class='uds-bb-paginator oldskool {$this->controlsPosition}'>
  652. <div class='uds-bb-button uds-bb-playpause uds-center'><span>".__('Play', uds_billboard_textdomain)."</span></div>
  653. <div class='uds-bb-button uds-bb-prev uds-center-vertical'><span>".__('Prev', uds_billboard_textdomain)."</span></div>
  654. <div class='uds-bb-button uds-bb-next uds-center-vertical'><span>".__('Next', uds_billboard_textdomain)."</span></div>
  655. <div class='uds-bb-position-indicator-bullets'></div>
  656. </div>
  657. ";
  658. return $out;
  659. }
  660. /**
  661. * Oldskool paginator renderer
  662. *
  663. * @return string rendered paginator
  664. */
  665. private function paginatorUbbv2()
  666. {
  667. $out = "
  668. <div class='uds-bb-paginator ubbv2 {$this->controlsPosition}'>
  669. <div class='uds-bb-button uds-bb-playpause uds-center'><span>".__('Play', uds_billboard_textdomain)."</span></div>
  670. <div class='uds-bb-button uds-bb-prev uds-center-vertical'><span>".__('Prev', uds_billboard_textdomain)."</span></div>
  671. <div class='uds-bb-button uds-bb-next uds-center-vertical'><span>".__('Next', uds_billboard_textdomain)."</span></div>
  672. <div class='uds-bb-position-indicator-bullets'></div>
  673. </div>
  674. ";
  675. return $out;
  676. }
  677. /**
  678. * Oldskool bright paginator renderer
  679. *
  680. * @return string rendered paginator
  681. */
  682. private function paginatorOldskoolBright()
  683. {
  684. $out = "
  685. <div class='uds-bb-paginator oldskool-bright {$this->controlsPosition}'>
  686. <div class='uds-bb-button uds-bb-playpause uds-center'><span>".__('Play', uds_billboard_textdomain)."</span></div>
  687. <div class='uds-bb-button uds-bb-prev uds-center-vertical'><span>".__('Prev', uds_billboard_textdomain)."</span></div>
  688. <div class='uds-bb-button uds-bb-next uds-center-vertical'><span>".__('Next', uds_billboard_textdomain)."</span></div>
  689. <div class='uds-bb-position-indicator-bullets'></div>
  690. </div>
  691. ";
  692. return $out;
  693. }
  694. /**
  695. * Silver paginator renderer
  696. *
  697. * @return string rendered paginator
  698. */
  699. private function paginatorSilver()
  700. {
  701. $out = "
  702. <div class='uds-bb-paginator silver {$this->controlsPosition}'>
  703. <div class='uds-bb-button uds-bb-prev uds-center-vertical'><span>".__('Prev', uds_billboard_textdomain)."</span></div>
  704. <div class='uds-bb-button uds-bb-next uds-center-vertical'><span>".__('Next', uds_billboard_textdomain)."</span></div>
  705. <div class='uds-bb-position-indicator-bullets-container uds-center-horizontal'>
  706. <div class='uds-bb-position-indicator-bullets'></div>
  707. <div class='uds-bb-button uds-bb-playpause'><span>".__('Play', uds_billboard_textdomain)."</span></div>
  708. </div>
  709. </div>
  710. ";
  711. return $out;
  712. }
  713. /**
  714. * uTube paginator renderer
  715. *
  716. * @return string rendered paginator
  717. */
  718. private function paginatoruTube()
  719. {
  720. $out = "
  721. <div class='uds-bb-paginator uTube {$this->controlsPosition}'>
  722. <div class='uds-bb-button uds-bb-prev'><span>".__('Prev', uds_billboard_textdomain)."</span></div>
  723. <div class='uds-bb-button uds-bb-playpause uds-left'><span>".__('Play', uds_billboard_textdomain)."</span></div>
  724. <div class='uds-bb-button uds-bb-next'><span>".__('Next', uds_billboard_textdomain)."</span></div>
  725. <div class='uds-bb-position-indicator-bullets'></div>
  726. </div>
  727. ";
  728. return $out;
  729. }
  730. /**
  731. * Modern paginator renderer
  732. *
  733. * @return string rendered paginator
  734. */
  735. private function paginatorModern()
  736. {
  737. $out = "
  738. <div class='uds-bb-paginator modern {$this->controlsPosition}'>
  739. <div class='uds-bb-paginator moderncontainer'>
  740. <div class='uds-bb-button uds-bb-prev'><span>".__('Prev', uds_billboard_textdomain)."</span></div>
  741. <div class='uds-bb-button uds-bb-playpause uds-left'><span>".__('Play', uds_billboard_textdomain)."</span></div>
  742. <div class='uds-bb-button uds-bb-next'><span>".__('Next', uds_billboard_textdomain)."</span></div>
  743. <div class='uds-bb-position-indicator-bullets'></div>
  744. </div>
  745. </div>
  746. ";
  747. return $out;
  748. }
  749. /**
  750. * thumbnails renderer
  751. *
  752. * @return string thumbnails renderer
  753. */
  754. private function thumbnails($slides)
  755. {
  756. $position = $this->thumbnailsPosition;
  757. $inside = $this->thumbnailsInside === 'on' ? 'inside' : '';
  758. $skin = $this->controlsSkin;
  759. $out = "
  760. <div class='uds-bb-thumbnails $skin $position $inside'>
  761. <div class='uds-bb-thumbnail-container'>\n";
  762. foreach($slides as $slide) {
  763. $out .= $slide->renderThumb();
  764. }
  765. $out .= "\t\t\t\t\t</div>
  766. </div>\n";
  767. return $out;
  768. }
  769. /**
  770. * Make sure the option conforms to the possible value types
  771. * and definition in attribute array
  772. *
  773. * @return NULL or option
  774. */
  775. private function sanitizeOption($key, $option)
  776. {
  777. global $uds_billboard_general_options;
  778. if(!array_key_exists($key, $uds_billboard_general_options)){
  779. return NULL;
  780. }
  781. if($key == 'name') {
  782. return sanitize_title($option);
  783. }
  784. if(in_array($key, array_keys($uds_billboard_general_options))) {
  785. if($uds_billboard_general_options[$key]['type'] == 'select') {
  786. if(in_array($option, array_keys($uds_billboard_general_options[$key]['options']))) {
  787. return $option;
  788. } else {
  789. return $uds_billboard_general_options[$key]['default'];
  790. }
  791. }
  792. return $option;
  793. }
  794. return $uds_billboard_general_options[$key]['default'];
  795. }
  796. /**
  797. * Helper function to transform attributes from dash to cammelCase
  798. *
  799. * @return string camelized string
  800. */
  801. private function camelize($string)
  802. {
  803. $string = str_replace(array('-', '_'), ' ', $string);
  804. $string = ucwords($string);
  805. $string = str_replace(' ', '', $string);
  806. $string = lcfirst($string);
  807. return $string;
  808. }
  809. }
  810. ?>