PageRenderTime 30ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/web/app/plugins/ml-slider-pro/modules/theme_editor/theme_editor.php

https://github.com/thomasmery/sopexa-morbier
PHP | 1602 lines | 1188 code | 214 blank | 200 comment | 194 complexity | d0d8de97708ff419d226b747ea120e19 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
  1. <?php
  2. // disable direct access
  3. if ( ! defined( 'ABSPATH' ) ) exit;
  4. /**
  5. * Theme Editor
  6. */
  7. class MetaSliderThemeEditor {
  8. private $theme = array();
  9. private $theme_slug = "";
  10. private $slider_id = 0;
  11. private $slider_settings = array();
  12. /**
  13. * Constructor
  14. */
  15. public function __construct() {
  16. add_filter( 'metaslider_css', array( $this, 'get_theme_css' ), 15, 3 );
  17. add_filter( 'metaslider_css_classes', array( $this, 'get_theme_css_classes' ), 10, 3 );
  18. add_action( 'admin_menu', array( $this, 'register_theme_editor_menu' ), 9556 );
  19. add_filter( 'metaslider_get_available_themes', array( $this, 'get_theme_select_options' ), 10, 2 );
  20. }
  21. /**
  22. * Append the shadow effect type onto the list of classes applied to a slideshow
  23. */
  24. public function get_theme_css_classes( $classes, $id, $settings ) {
  25. $theme = isset( $settings['theme'] ) ? $settings['theme'] : 'default';
  26. // if we're using the theme editor, always use the currently selected theme
  27. if ( is_admin() && isset( $_REQUEST['theme_slug'] ) ) {
  28. $theme = $_REQUEST['theme_slug'];
  29. }
  30. // bail out if we're not using a custom theme
  31. if ( substr( $theme, 0, strlen( '_theme' ) ) !== '_theme' ) {
  32. return $classes;
  33. }
  34. // bail out if thumbnails are enabled
  35. if ( isset( $settings['navigation'] ) && $settings['navigation'] == 'thumbs' ) {
  36. return $classes;
  37. }
  38. // bail out if filmstrip is enabled
  39. if ( isset( $settings['navigation'] ) && $settings['navigation'] == 'filmstrip' ) {
  40. return $classes;
  41. }
  42. if ( $this->load_theme( $theme ) && isset( $this->theme['shadow'] ) && $this->theme['shadow'] != 'none' ) {
  43. return $classes .= " " . $this->theme['shadow'];
  44. }
  45. return $classes;
  46. }
  47. /**
  48. * Append custom themes to the list of theme options on the slideshow edit page.
  49. */
  50. public function get_theme_select_options( $themes, $selected_theme ) {
  51. $custom_themes = $this->get_themes();
  52. if ( !is_array( $custom_themes ) ) {
  53. return $themes;
  54. }
  55. foreach ( $custom_themes as $slug => $theme ) {
  56. $themes .= "<option value='{$slug}' class='option nivo flex responsive coin'";
  57. if ( $slug == $selected_theme ) {
  58. $themes .= " selected=selected";
  59. }
  60. $themes .= ">{$theme['title']}</option>";
  61. }
  62. return $themes;
  63. }
  64. /**
  65. * Add the theme editor menu option to WordPress
  66. */
  67. public function register_theme_editor_menu() {
  68. $page = add_submenu_page( 'metaslider', __( 'Theme Editor', 'metasliderpro' ), __( 'Theme Editor', 'metasliderpro' ), 'manage_options', 'metaslider-theme-editor', array( $this, 'process_admin_page' ) );
  69. // ensure our JavaScript is only loaded on the Meta Slider admin page
  70. add_action( 'admin_print_scripts-' . $page, array( $this, 'register_theme_editor_scripts' ) );
  71. add_action( 'admin_print_styles-' . $page, array( $this, 'register_theme_editor_styles' ) );
  72. }
  73. /**
  74. * Admin styles
  75. */
  76. public function register_theme_editor_styles() {
  77. wp_enqueue_style( 'metaslider-admin-styles', METASLIDER_ASSETS_URL . 'metaslider/admin.css', false, METASLIDER_VERSION );
  78. wp_enqueue_style( 'metasliderpro-theme-editor-styles', plugins_url( 'assets/style.css' , __FILE__ ), false, METASLIDERPRO_VERSION );
  79. wp_enqueue_style( 'metasliderpro-spectrum-style', plugins_url( 'assets/spectrum/spectrum.css' , __FILE__ ), false, METASLIDERPRO_VERSION );
  80. }
  81. /**
  82. * Admin scripts
  83. */
  84. public function register_theme_editor_scripts() {
  85. wp_enqueue_script( 'metasliderpro-spectrum', plugins_url( 'assets/spectrum/spectrum.js' , __FILE__ ), array(), METASLIDERPRO_VERSION );
  86. wp_enqueue_script( 'metasliderpro-themeEditor-script', plugins_url( 'assets/themeEditor.js' , __FILE__ ), array( 'jquery', 'metasliderpro-spectrum' ), METASLIDERPRO_VERSION );
  87. }
  88. /**
  89. * Create a new theme
  90. */
  91. public function create_theme() {
  92. $slug = '_theme_' . time();
  93. // load existing themes
  94. $themes = get_option( 'metaslider-themes' );
  95. // create a new blank theme
  96. $themes[$slug] = $this->get_theme_defaults();
  97. // save
  98. update_option( 'metaslider-themes', $themes );
  99. // load it up
  100. $this->load_theme( $slug );
  101. $_REQUEST['theme_slug'] = $slug;
  102. }
  103. /**
  104. * Return an array of all created themes
  105. */
  106. public function get_themes() {
  107. $themes = get_option( 'metaslider-themes' );
  108. return $themes;
  109. }
  110. /**
  111. * Return true if the user has created themes
  112. */
  113. private function themes_available() {
  114. $themes = $this->get_themes();
  115. return !empty( $themes );
  116. }
  117. /**
  118. * Save changes to an existing theme
  119. *
  120. * @param string $slug
  121. * @param array $themes
  122. */
  123. public function save_theme( $slug, $theme ) {
  124. foreach ( array( 'enable_custom_caption', 'enable_custom_arrows', 'enable_custom_navigation', 'arrows_always_show' ) as $checkbox ) {
  125. if ( isset( $theme[$checkbox] ) && $theme[$checkbox] == 'on' ) {
  126. $theme[$checkbox] = 'enabled';
  127. } else {
  128. $theme[$checkbox] = 'disabled';
  129. }
  130. }
  131. $themes = get_option( 'metaslider-themes' );
  132. $themes[$slug] = $theme;
  133. update_option( 'metaslider-themes', $themes );
  134. }
  135. /**
  136. * Save changes to an existing theme
  137. *
  138. * @param string $slug
  139. */
  140. public function delete_theme( $slug ) {
  141. $themes = get_option( 'metaslider-themes' );
  142. if ( isset( $themes[$slug] ) ) {
  143. unset( $themes[$slug] );
  144. update_option( 'metaslider-themes', $themes );
  145. $this->load_default_theme();
  146. return true;
  147. }
  148. return false;
  149. }
  150. /**
  151. * Load an existing theme, identified by the slug
  152. *
  153. * @param string slug
  154. * @return bool - true if theme successfully loaded
  155. */
  156. public function load_theme( $slug ) {
  157. $themes = get_option( 'metaslider-themes' );
  158. if ( isset( $themes[$slug] ) ) {
  159. $this->theme = $themes[$slug];
  160. $this->theme_slug = $slug;
  161. return true;
  162. }
  163. return false;
  164. }
  165. /**
  166. * Load an existing theme, identified by the slug
  167. *
  168. * @return bool - true if default theme found and loaded
  169. */
  170. public function load_default_theme() {
  171. $themes = get_option( 'metaslider-themes' );
  172. if ( is_array( $themes ) && count( $themes ) ) {
  173. foreach ( $themes as $theme => $vals ) {
  174. $this->theme = $vals;
  175. $this->theme_slug = $theme;
  176. $_REQUEST['theme_slug'] = $theme;
  177. return true; // theme loaded
  178. }
  179. }
  180. return false; // no themes found
  181. }
  182. /**
  183. * Contains all the settings for a default (new) theme
  184. *
  185. * @return array default theme values
  186. */
  187. private function get_theme_defaults() {
  188. $defaults = array(
  189. 'title' => 'New Theme',
  190. 'dot_fill_colour_start' => 'rgba(0,0,0,0.5)',
  191. 'dot_fill_colour_end' => 'rgba(0,0,0,0.5)',
  192. 'dot_border_colour' => 'rgba(0,0,0,1)',
  193. 'dot_border_width' => 0,
  194. 'dot_border_radius' => 10,
  195. 'dot_size' => 12,
  196. 'dot_spacing' => 4,
  197. 'active_dot_fill_colour_start' => 'rgba(0,0,0,1)',
  198. 'active_dot_fill_colour_end' => 'rgba(0,0,0,1)',
  199. 'active_dot_border_colour' => 'rgba(0,0,0,1)',
  200. 'nav_position' => 'default',
  201. 'nav_vertical_margin' => 10,
  202. 'nav_horizontal_margin' => 0,
  203. 'arrow_type' => 1,
  204. 'arrow_colour' => 'black',
  205. 'arrow_indent' => 5,
  206. 'arrow_opacity' => 70,
  207. 'outer_border_radius' => 0,
  208. 'shadow' => 'default',
  209. 'caption_position' => 'bottomLeft',
  210. 'caption_width' => 100,
  211. 'caption_align' => 'left',
  212. 'caption_vertical_margin' => 0,
  213. 'caption_horizontal_margin' => 0,
  214. 'caption_background_colour' => 'rgba(0,0,0,0.7)',
  215. 'caption_text_colour' => 'rgba(255,255,255,1)',
  216. 'caption_border_radius' => 0,
  217. 'enable_custom_caption' => 'enabled',
  218. 'enable_custom_navigation' => 'enabled',
  219. 'enable_custom_arrows' => 'enabled',
  220. 'custom_arrow_next' => 0,
  221. 'custom_arrow_prev' => 0,
  222. 'arrow_always_show' => 'disabled'
  223. );
  224. return $defaults;
  225. }
  226. /**
  227. * Get the theme setting. Fall back to returning the default theme setting.
  228. *
  229. * @param string $name
  230. */
  231. private function get_setting( $name ) {
  232. // try and get a saved setting
  233. if ( isset( $this->theme[$name] ) ) {
  234. return $this->theme[$name];
  235. }
  236. // fall back to default values
  237. $defaults = $this->get_theme_defaults();
  238. if ( isset( $defaults[$name] ) ) {
  239. return $defaults[$name];
  240. }
  241. return false;
  242. }
  243. /**
  244. * Return all available sliders
  245. *
  246. * @return array
  247. */
  248. private function get_sliders_for_preview() {
  249. $sliders = false;
  250. // list the tabs
  251. $args = array(
  252. 'post_type' => 'ml-slider',
  253. 'post_status' => 'publish',
  254. 'orderby' => 'date',
  255. 'order' => 'ASC',
  256. 'posts_per_page' => -1
  257. );
  258. $the_query = new WP_Query( $args );
  259. while ( $the_query->have_posts() ) {
  260. $the_query->the_post();
  261. $sliders[] = array(
  262. 'title' => get_the_title(),
  263. 'id' => $the_query->post->ID
  264. );
  265. }
  266. return $sliders;
  267. }
  268. /**
  269. * Work out which slider to use for the preview
  270. *
  271. * @return int|bool - ID of slideshow or false
  272. */
  273. private function get_preview_slider_id() {
  274. if ( isset( $_REQUEST['slider_id'] ) ) {
  275. return $_REQUEST['slider_id'];
  276. }
  277. $all_sliders = $this->get_sliders_for_preview();
  278. if ( is_array( $all_sliders ) && isset( $all_sliders[0]['id'] ) ) {
  279. return $all_sliders[0]['id'];
  280. }
  281. return false;
  282. }
  283. /**
  284. * Handle deleting/saving themes etc
  285. */
  286. private function process() {
  287. if ( isset( $_REQUEST['save_theme'] ) ) {
  288. $slug = $_REQUEST['theme_slug'];
  289. $theme = $_REQUEST['theme'];
  290. $this->save_theme( $slug, $theme );
  291. }
  292. if ( isset( $_REQUEST['delete_theme'] ) ) {
  293. $slug = $_REQUEST['theme_slug'];
  294. $this->delete_theme( $slug );
  295. }
  296. if ( isset( $_REQUEST['theme_slug'] ) ) {
  297. $this->load_theme( $_REQUEST['theme_slug'] );
  298. } else {
  299. $this->load_default_theme();
  300. }
  301. if ( isset( $_REQUEST['add'] ) ) {
  302. $this->create_theme();
  303. }
  304. $this->slider_id = $this->get_preview_slider_id();
  305. $this->slider_settings = get_post_meta( $this->slider_id, 'ml-slider_settings', true );
  306. }
  307. /**
  308. * Render the admin page
  309. */
  310. public function process_admin_page() {
  311. $this->process();
  312. // media library dependencies
  313. wp_enqueue_media();
  314. $arrow_style = $this->get_arrow_options();
  315. $arrow_colour = $this->get_arrow_colours();
  316. ?>
  317. <div class='metaslider metaslider_themeEditor'>
  318. <?php
  319. if ( isset( $_REQUEST['save_theme'] ) ) {
  320. echo "<div class='updated'><p>" . __( "Theme Saved. To apply the theme to a slideshow, edit the slideshow and select this theme from the theme dropdown menu.", "metasliderpro" ) . "</p></div>";
  321. }
  322. if ( $sliders = $this->get_sliders_for_preview() ) {
  323. echo "<form style='position: absolute; right: 20px; top: 27px;' accept-charset='UTF-8' action='?page=metaslider-theme-editor' method='post'>";
  324. echo "<input type='hidden' name='theme_slug' value='{$this->theme_slug}' />";
  325. echo "<select name='slider_id'>";
  326. foreach ( $sliders as $slider ) {
  327. $selected = $slider['id'] == $this->slider_id ? 'selected=selected' : '';
  328. echo "<option value='{$slider['id']}' {$selected}>{$slider['title']}</option>";
  329. }
  330. echo "</select>";
  331. echo "<input type='submit' class='button button-secondary' value='" . __( "Switch Preview Slider", "metasliderpro" ) . "' /></form>";
  332. }
  333. ?>
  334. <form accept-charset='UTF-8' action='?page=metaslider-theme-editor' method='post'>
  335. <h3 class="nav-tab-wrapper">
  336. <?php
  337. if ( $this->themes_available() ) {
  338. foreach ( $this->get_themes() as $slug => $theme ) {
  339. if ( $this->theme_slug == $slug ) {
  340. echo "<div class='nav-tab nav-tab-active'><input type='text' name='theme[title]' value='" . $theme['title'] . "' onfocus='this.style.width = ((this.value.length + 1) * 9) + \"px\"' /></div>";
  341. } else {
  342. echo "<a href='?page=metaslider-theme-editor&theme_slug={$slug}' class='nav-tab'>{$theme['title']}</a>";
  343. }
  344. }
  345. }
  346. ?>
  347. <a href="?page=metaslider-theme-editor&add=true" id="create_new_tab" class="nav-tab">+</a>
  348. </h3>
  349. <?php if ( !$this->theme_slug ) {
  350. // bail out if we have no themes
  351. return;
  352. } ?>
  353. <div class='theme_editor_left'>
  354. <input type='hidden' name='theme_slug' value='<?php echo $this->theme_slug ?>' />
  355. <input type='hidden' name='slider_id' value='<?php echo $this->slider_id ?>' />
  356. <table class='widefat settings'>
  357. <thead>
  358. <tr>
  359. <th width='40%'><?php _e( "Theme Settings", 'metasliderpro' ) ?></th>
  360. <th><input type='submit' name='save_theme' value='<?php _e( "Save", "metasliderpro" ) ?>' class='alignright button button-primary' /></th>
  361. </tr>
  362. </thead>
  363. <tbody>
  364. <tr>
  365. <td colspan='2' class='highlight'>
  366. <?php _e( "Slideshow", 'metasliderpro' ) ?>
  367. </td>
  368. </tr>
  369. <tr>
  370. <td><?php _e( "Outer Border Radius", 'metasliderpro' ) ?></td>
  371. <td>
  372. <input class='number' type='number' min='0' max='50' id='theme_outer_border_radius' name='theme[outer_border_radius]' value='<?php echo $this->get_setting( 'outer_border_radius' ); ?>' /><span class='after'><?php _e( "px", 'metasliderpro' ) ?></span>
  373. </td>
  374. </tr>
  375. <tr>
  376. <td><?php _e( "CSS3 Shadow", 'metasliderpro' ) ?><br />
  377. <small><i><?php _e( "Note: Not compatible with 'thumbnail' navigation type", 'metasliderpro' ) ?></i></small>
  378. </td>
  379. <td>
  380. <select id='shadow' name='theme[shadow]'>
  381. <option value='none' <?php if ( $this->get_setting( 'shadow' ) == 'none' ) echo 'selected=selected'?>><?php _e( "None", "metasliderpro" ) ?></option>
  382. <option value='effect0' <?php if ( $this->get_setting( 'shadow' ) == 'effect0' ) echo 'selected=selected'?>><?php _e( "Default", "metasliderpro" ) ?></option>
  383. <option value='effect1' <?php if ( $this->get_setting( 'shadow' ) == 'effect1' ) echo 'selected=selected'?>><?php _e( "Bottom", "metasliderpro" ) ?></option>
  384. <option value='effect2' <?php if ( $this->get_setting( 'shadow' ) == 'effect2' ) echo 'selected=selected'?>><?php _e( "Page Curl", "metasliderpro" ) ?></option>
  385. <option value='effect3' <?php if ( $this->get_setting( 'shadow' ) == 'effect3' ) echo 'selected=selected'?>><?php _e( "Bottom Curve", "metasliderpro" ) ?></option>
  386. <option value='effect4' <?php if ( $this->get_setting( 'shadow' ) == 'effect4' ) echo 'selected=selected'?>><?php _e( "Top and Bottom Curve", "metasliderpro" ) ?></option>
  387. <option value='effect5' <?php if ( $this->get_setting( 'shadow' ) == 'effect5' ) echo 'selected=selected'?>><?php _e( "Sides", "metasliderpro" ) ?></option>
  388. </select><br />
  389. </td>
  390. </tr>
  391. <tr>
  392. <td colspan='2' class='highlight'>
  393. <?php _e( "Caption", 'metasliderpro' ) ?>
  394. </td>
  395. </tr>
  396. <tr>
  397. <td><?php _e( "Enable Custom Caption", 'metasliderpro' ) ?></td>
  398. <td>
  399. <input type='checkbox' id='enable_custom_caption' name='theme[enable_custom_caption]' <?php if ( $this->get_setting( 'enable_custom_caption' ) == 'enabled' ) echo 'checked=checked'?> />
  400. </td>
  401. </tr>
  402. <tr>
  403. <td><?php _e( "Position", 'metasliderpro' ) ?></td>
  404. <td>
  405. <select id='caption_position' name='theme[caption_position]'>
  406. <option value='bottomLeft' <?php if ( $this->get_setting( 'caption_position' ) == 'bottomLeft' ) echo 'selected=selected'?>><?php _e( "Bottom Left", 'metasliderpro' ) ?></option>
  407. <option value='bottomRight' <?php if ( $this->get_setting( 'caption_position' ) == 'bottomRight' ) echo 'selected=selected'?>><?php _e( "Bottom Right", 'metasliderpro' ) ?></option>
  408. <option value='topLeft' <?php if ( $this->get_setting( 'caption_position' ) == 'topLeft' ) echo 'selected=selected'?>><?php _e( "Top Left", 'metasliderpro' ) ?></option>
  409. <option value='topRight' <?php if ( $this->get_setting( 'caption_position' ) == 'topRight' ) echo 'selected=selected'?>><?php _e( "Top Right", 'metasliderpro' ) ?></option>
  410. <option value='underneath' <?php if ( $this->get_setting( 'caption_position' ) == 'underneath' ) echo 'selected=selected'?>><?php _e( "Underneath", 'metasliderpro' ) ?></option>
  411. </select>
  412. </td>
  413. </tr>
  414. <tr>
  415. <td><?php _e( "Width", 'metasliderpro' ) ?></td>
  416. <td><input class='number' type='number' min='0' max='100' id='theme_caption_width' name='theme[caption_width]' value='<?php echo $this->get_setting( 'caption_width' ); ?>' /><span class='after'>%</span></td>
  417. </tr>
  418. <tr>
  419. <td><?php _e( "Border Radius", 'metasliderpro' ) ?></td>
  420. <td><input class='number' type='number' min='0' max='100' id='theme_caption_border_radius' name='theme[caption_border_radius]' value='<?php echo $this->get_setting( 'caption_border_radius' ); ?>' /><span class='after'>px</span></td>
  421. </tr>
  422. <tr>
  423. <td><?php _e( "Text Color", 'metasliderpro' ) ?></td>
  424. <td>
  425. <input type='text' class='colorpicker' id='colourpicker-caption-text-colour' name='theme[caption_text_colour]' value='<?php echo $this->get_setting( 'caption_text_colour' ); ?>' />
  426. </td>
  427. </tr>
  428. <tr>
  429. <td><?php _e( "Text Align", 'metasliderpro' ) ?></td>
  430. <td>
  431. <select id='caption_align' name='theme[caption_align]'>
  432. <option value='left' <?php if ( $this->get_setting( 'caption_align' ) == 'left' ) echo 'selected=selected'?>><?php _e( "Left", 'metasliderpro' ) ?></option>
  433. <option value='center' <?php if ( $this->get_setting( 'caption_align' ) == 'center' ) echo 'selected=selected'?>><?php _e( "Center", 'metasliderpro' ) ?></option>
  434. <option value='right' <?php if ( $this->get_setting( 'caption_align' ) == 'right' ) echo 'selected=selected'?>><?php _e( "Right", 'metasliderpro' ) ?></option>
  435. </select>
  436. </td>
  437. </tr>
  438. <tr>
  439. <td><?php _e( "Background Color", 'metasliderpro' ) ?></td>
  440. <td>
  441. <input type='text' class='colorpicker' id='colourpicker-caption-background-colour' name='theme[caption_background_colour]' value='<?php echo $this->get_setting( 'caption_background_colour' ) ?>' />
  442. </td>
  443. </tr>
  444. <tr>
  445. <td><?php _e( "Vertical Margin", 'metasliderpro' ) ?></td>
  446. <td><input class='number' type='number' min='0' max='500' id='theme_caption_vertical_margin' name='theme[caption_vertical_margin]' value='<?php echo $this->get_setting( 'caption_vertical_margin' ); ?>' /><span class='after'><?php _e( "px", 'metasliderpro' ) ?></span></td>
  447. </tr>
  448. <tr>
  449. <td><?php _e( "Horizontal Margin", 'metasliderpro' ) ?></td>
  450. <td><input class='number' type='number' min='0' max='500' id='theme_caption_horizontal_margin' name='theme[caption_horizontal_margin]' value='<?php echo $this->get_setting( 'caption_horizontal_margin' ); ?>' /><span class='after'><?php _e( "px", 'metasliderpro' ) ?></span></td>
  451. </tr>
  452. <tr>
  453. <td colspan='2' class='highlight'>
  454. <?php _e( "Arrows", 'metasliderpro' ) ?>
  455. </td>
  456. </tr>
  457. <tr>
  458. <td><?php _e( "Enable Custom Arrows", 'metasliderpro' ) ?></td>
  459. <td>
  460. <input type='checkbox' id='enable_custom_arrows' name='theme[enable_custom_arrows]' <?php if ( $this->get_setting( 'enable_custom_arrows' ) == 'enabled' ) echo 'checked=checked'?> />
  461. </td>
  462. </tr>
  463. <tr>
  464. <td><?php _e( "Built In Styles", 'metasliderpro' ) ?></td>
  465. <td>
  466. <select id='arrow_style' name='theme[arrow_type]'><?php echo $arrow_style ?></select>
  467. <select id='arrow_colour' name='theme[arrow_colour]'><?php echo $arrow_colour ?></select>
  468. </td>
  469. </tr>
  470. <tr>
  471. <td><?php _e( "Custom Prev Arrow", 'metasliderpro' ) ?></td>
  472. <td>
  473. <?php
  474. $custom_prev_arrow = $this->get_setting( 'custom_prev_arrow' );
  475. if ( $custom_prev_arrow > 0 ) {
  476. $url = wp_get_attachment_image_src( $custom_prev_arrow , 'full' );
  477. echo "<button id='open_media_manager_prev' style='display: none;'>" . __( "Select", 'metasliderpro' ) . "</button>";
  478. echo "<button id='remove_custom_prev_arrow'>" . __( "Remove", 'metasliderpro' ) . "</button>";
  479. echo "<div id='custom_prev_arrow'><img src='{$url[0]}' width='{$url[1]}' height='{$url[2]}' /></div>";
  480. echo "<input type='hidden' id='custom_prev_arrow_input' name='theme[custom_prev_arrow]' value='{$custom_prev_arrow}'>";
  481. } else {
  482. echo "<button id='open_media_manager_prev'>" . __( "Select", 'metasliderpro' ) . "</button>";
  483. echo "<button id='remove_custom_prev_arrow' style='display: none;'>" . __( "Remove", 'metasliderpro' ) . "</button>";
  484. echo "<div id='custom_prev_arrow'></div>";
  485. echo "<input type='hidden' id='custom_prev_arrow_input' name='theme[custom_prev_arrow]' value='0'>";
  486. }
  487. ?>
  488. </td>
  489. </tr>
  490. <tr>
  491. <td><?php _e( "Custom Next Arrow", 'metasliderpro' ) ?></td>
  492. <td>
  493. <?php
  494. $custom_next_arrow = $this->get_setting( 'custom_next_arrow' );
  495. if ( $custom_next_arrow > 0 ) {
  496. $url = wp_get_attachment_image_src( $custom_next_arrow , 'full' );
  497. echo "<button id='open_media_manager_next' style='display: none;'>" . __( "Select", 'metasliderpro' ) . "</button>";
  498. echo "<button id='remove_custom_next_arrow'>" . __( "Remove", 'metasliderpro' ) . "</button>";
  499. echo "<div id='custom_next_arrow'><img src='{$url[0]}' width='{$url[1]}' height='{$url[2]}' /></div>";
  500. echo "<input type='hidden' id='custom_next_arrow_input' name='theme[custom_next_arrow]' value='{$custom_next_arrow}'>";
  501. } else {
  502. echo "<button id='open_media_manager_next'>" . __( "Select", 'metasliderpro' ) . "</button>";
  503. echo "<button id='remove_custom_next_arrow' style='display: none;'>" . __( "Remove", 'metasliderpro' ) . "</button>";
  504. echo "<div id='custom_next_arrow'></div>";
  505. echo "<input type='hidden' id='custom_next_arrow_input' name='theme[custom_next_arrow]' value='0'>";
  506. }
  507. ?>
  508. </td>
  509. </tr>
  510. <tr>
  511. <td><?php _e( "Opacity", 'metasliderpro' ) ?></td>
  512. <td><input class='number' type='number' min='0' max='100' step='1' id='theme_arrow_opacity' name='theme[arrow_opacity]' value='<?php echo $this->get_setting( 'arrow_opacity' ); ?>' /><span class='after'>%</span></td>
  513. </tr>
  514. <tr>
  515. <td><?php _e( "Distance from edge", 'metasliderpro' ) ?></td>
  516. <td><input class='number' type='number' min='-50' max='50' id='theme_arrow_indent' name='theme[arrow_indent]' value='<?php echo $this->get_setting( 'arrow_indent' ); ?>' /><span class='after'><?php _e( "px", 'metasliderpro' ) ?></span></td>
  517. </tr>
  518. <tr>
  519. <td><?php _e( "Always show", 'metasliderpro' ) ?></td>
  520. <td>
  521. <input type='checkbox' id='arrows_always_show' name='theme[arrows_always_show]' <?php if ( $this->get_setting( 'arrows_always_show' ) == 'enabled' ) echo 'checked=checked'?> />
  522. </td>
  523. </tr>
  524. <tr>
  525. <tr>
  526. <td colspan='2' class='highlight'>
  527. <?php _e( "Navigation", 'metasliderpro' ) ?>
  528. </td>
  529. </tr>
  530. <tr>
  531. <td><?php _e( "Enable Custom Navigation", 'metasliderpro' ) ?></td>
  532. <td>
  533. <input type='checkbox' id='enable_custom_navigation' name='theme[enable_custom_navigation]' <?php if ( $this->get_setting( 'enable_custom_navigation' ) == 'enabled' ) echo 'checked=checked'?> />
  534. </td>
  535. </tr>
  536. <tr>
  537. <td><?php _e( "Position", 'metasliderpro' ) ?></td>
  538. <td>
  539. <select id='nav_position' name='theme[nav_position]'>
  540. <option value='default' <?php if ( $this->get_setting( 'nav_position' ) == 'default' ) echo 'selected=selected'?>><?php _e( "Default", 'metasliderpro' ) ?></option>
  541. <option value='topLeft' <?php if ( $this->get_setting( 'nav_position' ) == 'topLeft' ) echo 'selected=selected'?>><?php _e( "Top Left", 'metasliderpro' ) ?></option>
  542. <option value='topCenter' <?php if ( $this->get_setting( 'nav_position' ) == 'topCenter' ) echo 'selected=selected'?>><?php _e( "Top Center", 'metasliderpro' ) ?></option>
  543. <option value='topRight' <?php if ( $this->get_setting( 'nav_position' ) == 'topRight' ) echo 'selected=selected'?>><?php _e( "Top Right", 'metasliderpro' ) ?></option>
  544. <option value='bottomLeft' <?php if ( $this->get_setting( 'nav_position' ) == 'bottomLeft' ) echo 'selected=selected'?>><?php _e( "Bottom Left", 'metasliderpro' ) ?></option>
  545. <option value='bottomCenter' <?php if ( $this->get_setting( 'nav_position' ) == 'bottomCenter' ) echo 'selected=selected'?>><?php _e( "Bottom Center", 'metasliderpro' ) ?></option>
  546. <option value='bottomRight' <?php if ( $this->get_setting( 'nav_position' ) == 'bottomRight' ) echo 'selected=selected'?>><?php _e( "Bottom Right", 'metasliderpro' ) ?></option>
  547. </select>
  548. </td>
  549. </tr>
  550. <tr>
  551. <td><?php _e( "Vertical Margin", 'metasliderpro' ) ?></td>
  552. <td><input class='number' type='number' min='0' max='500' id='theme_nav_vertical_margin' name='theme[nav_vertical_margin]' value='<?php echo $this->get_setting( 'nav_vertical_margin' ); ?>' /><span class='after'><?php _e( "px", 'metasliderpro' ) ?></span></td>
  553. </tr>
  554. <tr>
  555. <td><?php _e( "Horizontal Margin", 'metasliderpro' ) ?></td>
  556. <td><input class='number' type='number' min='0' max='500' id='theme_nav_horizontal_margin' name='theme[nav_horizontal_margin]' value='<?php echo $this->get_setting( 'nav_horizontal_margin' ); ?>' /><span class='after'><?php _e( "px", 'metasliderpro' ) ?></span></td>
  557. </tr>
  558. <tr>
  559. <td><?php _e( "Fill Color", 'metasliderpro' ) ?></td>
  560. <td>
  561. <input type='text' class='colorpicker' id='colourpicker-fill-start' name='theme[dot_fill_colour_start]' value='<?php echo $this->get_setting( 'dot_fill_colour_start' ); ?>' />
  562. <input type='text' class='colorpicker' id='colourpicker-fill-end' name='theme[dot_fill_colour_end]' value='<?php echo $this->get_setting( 'dot_fill_colour_end' ); ?>' />
  563. </td>
  564. </tr>
  565. <tr>
  566. <td><?php _e( "Fill Color (Active)", 'metasliderpro' ) ?></td>
  567. <td>
  568. <input type='text' class='colorpicker' id='colourpicker-active-fill-start' name='theme[active_dot_fill_colour_start]' value='<?php echo $this->get_setting( 'active_dot_fill_colour_start' ); ?>' />
  569. <input type='text' class='colorpicker' id='colourpicker-active-fill-end' name='theme[active_dot_fill_colour_end]' value='<?php echo $this->get_setting( 'active_dot_fill_colour_end' ); ?>' />
  570. </td>
  571. </tr>
  572. <tr>
  573. <td><?php _e( "Border Color", 'metasliderpro' ) ?></td>
  574. <td>
  575. <input type='text' class='colorpicker' id='colourpicker-border-colour' name='theme[dot_border_colour]' value='<?php echo $this->get_setting( 'dot_border_colour' ); ?>' />
  576. </td>
  577. </tr>
  578. <tr>
  579. <td><?php _e( "Border Color (Active)", 'metasliderpro' ) ?></td>
  580. <td>
  581. <input type='text' class='colorpicker' id='colourpicker-active-border-colour' name='theme[active_dot_border_colour]' value='<?php echo $this->get_setting( 'active_dot_border_colour' ); ?>' />
  582. </td>
  583. </tr>
  584. <tr>
  585. <td><?php _e( "Size", 'metasliderpro' ) ?></td>
  586. <td><input class='number' type='number' min='0' max='50' id='theme_dot_size' name='theme[dot_size]' value='<?php echo $this->get_setting( 'dot_size' ); ?>' /><span class='after'><?php _e( "px", 'metasliderpro' ) ?></span></td>
  587. </tr>
  588. <tr>
  589. <td><?php _e( "Spacing", 'metasliderpro' ) ?></td>
  590. <td><input class='number' type='number' min='0' max='50' id='theme_dot_spacing' name='theme[dot_spacing]' value='<?php echo $this->get_setting( 'dot_spacing' ); ?>' /><span class='after'><?php _e( "px", 'metasliderpro' ) ?></span></td>
  591. </tr>
  592. <tr>
  593. <td><?php _e( "Border Width", 'metasliderpro' ) ?></td>
  594. <td><input class='number' type='number' min='0' max='50' id='theme_dot_border_width' name='theme[dot_border_width]' value='<?php echo $this->get_setting( 'dot_border_width' ); ?>' /><span class='after'><?php _e( "px", 'metasliderpro' ) ?></span></td>
  595. </tr>
  596. <tr>
  597. <td><?php _e( "Border Radius", 'metasliderpro' ) ?></td>
  598. <td><input class='number' type='number' min='0' max='50' id='theme_dot_border_radius' name='theme[dot_border_radius]' value='<?php echo $this->get_setting( 'dot_border_radius' ); ?>' /><span class='after'><?php _e( "px", 'metasliderpro' ) ?></span></td>
  599. </tr>
  600. </tbody>
  601. </table>
  602. <input type='submit' class='confirm button button-secondary' name='delete_theme' value='<?php _e("Delete Theme", "metasliderpro"); ?>' />
  603. </div>
  604. <div class='theme_editor_right'>
  605. <div style='width: 90%'>
  606. <?php echo do_shortcode( "[metaslider id=" . $this->slider_id . "]" ) ?>
  607. </div>
  608. </div>
  609. </form>
  610. </div>
  611. <?php
  612. }
  613. /**
  614. * The different arrow types are stored as a sprite, this function
  615. * returns an array containing the details required to position the
  616. * sprite correctly
  617. */
  618. public function get_arrows() {
  619. $arrows[1] = array( 'height' => 51, 'width' => 23, 'offset' => 0 );
  620. $arrows[2] = array( 'height' => 39, 'width' => 22, 'offset' => 54 );
  621. $arrows[3] = array( 'height' => 37, 'width' => 20, 'offset' => 95 );
  622. $arrows[4] = array( 'height' => 30, 'width' => 21, 'offset' => 135 );
  623. $arrows[5] = array( 'height' => 27, 'width' => 26, 'offset' => 167 );
  624. $arrows[6] = array( 'height' => 31, 'width' => 31, 'offset' => 194 );
  625. $arrows[7] = array( 'height' => 25, 'width' => 25, 'offset' => 226 );
  626. $arrows[8] = array( 'height' => 29, 'width' => 28, 'offset' => 251 );
  627. $arrows[9] = array( 'height' => 40, 'width' => 21, 'offset' => 282 );
  628. $arrows[10] = array( 'height' => 31, 'width' => 21, 'offset' => 325 );
  629. $arrows[11] = array( 'height' => 23, 'width' => 17, 'offset' => 362 );
  630. $arrows[12] = array( 'height' => 17, 'width' => 12, 'offset' => 391 );
  631. $arrows[13] = array( 'height' => 18, 'width' => 22, 'offset' => 411 );
  632. $arrows[14] = array( 'height' => 25, 'width' => 21, 'offset' => 429 );
  633. $arrows[15] = array( 'height' => 34, 'width' => 34, 'offset' => 459 );
  634. $arrows[16] = array( 'height' => 34, 'width' => 34, 'offset' => 498 );
  635. return $arrows;
  636. }
  637. /**
  638. *
  639. */
  640. private function get_selected_arrow() {
  641. $arrows = $this->get_arrows();
  642. $selected_arrow_type = $this->get_setting( 'arrow_type' );
  643. $arrow = $arrows[$selected_arrow_type];
  644. $url = plugins_url( 'assets/arrows/' , __FILE__ ) . $this->get_setting( 'arrow_colour' ) . ".png";
  645. $selected_arrow['prev'] = array(
  646. 'url' => $url,
  647. 'width' => $arrow['width'],
  648. 'height' => $arrow['height'],
  649. 'position' => "0 -" . intval( $arrow['offset'] ) . "px"
  650. );
  651. $selected_arrow['next'] = array(
  652. 'url' => $url,
  653. 'width' => $arrow['width'],
  654. 'height' => $arrow['height'],
  655. 'position' => "100% -" . intval( $arrow['offset'] ) . "px"
  656. );
  657. $custom_prev_arrow = $this->get_setting( 'custom_prev_arrow' );
  658. if ( $custom_prev_arrow > 0 ) {
  659. $img = wp_get_attachment_image_src( $custom_prev_arrow , 'full' );
  660. $selected_arrow['prev'] = array(
  661. 'url' => $img[0],
  662. 'width' => $img[1],
  663. 'height' => $img[2],
  664. 'position' => "0 0"
  665. );
  666. }
  667. $custom_next_arrow = $this->get_setting( 'custom_next_arrow' );
  668. if ( $custom_next_arrow > 0 ) {
  669. $img = wp_get_attachment_image_src( $custom_next_arrow , 'full' );
  670. $selected_arrow['next'] = array(
  671. 'url' => $img[0],
  672. 'width' => $img[1],
  673. 'height' => $img[2],
  674. 'position' => "0 0"
  675. );
  676. }
  677. return $selected_arrow;
  678. }
  679. /**
  680. * Return the CSS for the theme.
  681. */
  682. public function get_theme_css( $css, $settings, $id ) {
  683. $this->slider_id = $id;
  684. $this->slider_settings = get_post_meta( $id, 'ml-slider_settings', true );
  685. $theme_slug = $settings['theme'];
  686. // theme_slug is used for the preview in the back end. This causes the theme to load
  687. // even if the preview slideshow isn't set to use this theme
  688. if ( isset( $_REQUEST['theme_slug'] ) ) {
  689. $theme_slug = $_REQUEST['theme_slug'];
  690. }
  691. if ( substr( $theme_slug, 0, strlen( '_theme' ) ) !== '_theme' ) {
  692. return $css; // we're not using a custom theme
  693. }
  694. if ( !$this->load_theme( $theme_slug ) ) {
  695. return $css; // the theme doesn't exist (deleted maybe)
  696. }
  697. $arrow = $this->get_selected_arrow();
  698. switch ( $settings['type'] ) {
  699. case "coin":
  700. $theme_css = $this->get_coin_theme( $arrow );
  701. break;
  702. case "flex":
  703. $theme_css = $this->get_flex_theme( $arrow );
  704. break;
  705. case "nivo":
  706. $theme_css = $this->get_nivo_theme( $arrow );
  707. break;
  708. case "responsive":
  709. $theme_css = $this->get_responsive_theme( $arrow );
  710. break;
  711. }
  712. $theme_css = $this->tidy_css( $theme_css . $this->get_container_margin() );
  713. return $css . $theme_css;
  714. }
  715. /**
  716. * Properly indent the CSS for output.
  717. */
  718. private function tidy_css( $css ) {
  719. $selector = apply_filters( "metaslider_theme_editor_css_selector", $this->get_default_css_selector(), $this->slider_id );
  720. // remove all spaces
  721. $css = str_replace( " ", "", $css );
  722. // remove all line breaks
  723. $css = str_replace( "\n", "", $css );
  724. // remove all tabs
  725. $css = str_replace( "\t", "", $css );
  726. // add a blank line between each selector
  727. $css = str_replace( "}", "\n\t}\n", $css );
  728. // break each selector onto a new line
  729. $css = str_replace( "[metaslider]", "\n\t{$selector}", $css );
  730. // break each rule onto a new line
  731. $css = str_replace( ";", ";\n\t\t", $css );
  732. // break each set of rules onto a new line
  733. $css = str_replace( "{", "{\n\t\t", $css );
  734. // clean up blank lines
  735. $css = str_replace( "\t\t\n", "", $css );
  736. return "\n" . $css;
  737. }
  738. /**
  739. * @todo: detect themes that use #content and prepend selector
  740. */
  741. private function get_default_css_selector() {
  742. return ".metaslider-{$this->slider_id}";
  743. }
  744. /**
  745. * Work out the correct margin value to apply to the bottom of the slideshow
  746. */
  747. public function get_container_margin() {
  748. $position = $this->get_setting( 'nav_position' );
  749. if ( $position == 'default' ) {
  750. $margin = ( $this->get_setting( 'nav_vertical_margin' ) * 2 ) + $this->get_setting( 'dot_size' );
  751. return "[metaslider] {
  752. margin-bottom: {$margin}px;
  753. }";
  754. }
  755. }
  756. /**
  757. * Return CSS rules for the navigation positioning
  758. */
  759. public function get_nav_position_css( $important = false ) {
  760. $position = $this->get_setting( 'nav_position' );
  761. $navPosition['width'] = 'auto';
  762. $navPosition['top'] = 'auto';
  763. $navPosition['right'] = 'auto';
  764. $navPosition['bottom'] = 'auto';
  765. $navPosition['left'] = 'auto';
  766. $navPosition['position'] = 'absolute';
  767. if ( $position == 'topCenter' || $position == 'bottomCenter' || $position == 'default' ) {
  768. $navPosition['text-align'] = 'center';
  769. }
  770. if ( $position == 'topCenter' || $position == 'bottomCenter' ) {
  771. $navPosition['width'] = '100%';
  772. }
  773. if ( $position == 'topRight' || $position == 'topCenter' ) {
  774. $navPosition['top'] = 0;
  775. $navPosition['right'] = 0;
  776. }
  777. if ( $position == 'topLeft' ) {
  778. $navPosition['top'] = 0;
  779. $navPosition['left'] = 0;
  780. }
  781. if ( $position == 'bottomLeft' || $position == 'bottomCenter' ) {
  782. $navPosition['bottom'] = 0;
  783. $navPosition['left'] = 0;
  784. }
  785. if ( $position == 'bottomRight' ) {
  786. $navPosition['bottom'] = 0;
  787. $navPosition['right'] = 0;
  788. }
  789. if ( $position == 'default' ) {
  790. $navPosition['width'] = '100%';
  791. $navPosition['top'] = 'auto';
  792. $navPosition['right'] = 'auto';
  793. $navPosition['bottom'] = 'auto';
  794. $navPosition['left'] = 'auto';
  795. }
  796. $important = $important ? ' !important' : '';
  797. foreach ( $navPosition as $key => $value ) {
  798. $rules[] = $key . ": " . $value . $important . ";";
  799. }
  800. return implode( "\n ", $rules );
  801. }
  802. /**
  803. * Return the CSS required to apply the theme to nivo slider.
  804. *
  805. * @param array $settings slideshow settings
  806. * @param array $arrow arrow information
  807. * @return string theme CSS
  808. */
  809. private function get_nivo_theme( $arrow ) {
  810. $theme = "";
  811. if ( $this->get_setting( 'outer_border_radius' ) > 0 ) {
  812. $theme .= " [metaslider] .nivoSlider,
  813. [metaslider] .nivoSlider img {
  814. border-radius: {$this->get_setting( 'outer_border_radius' )}px;
  815. -webkit-border-radius: {$this->get_setting( 'outer_border_radius' )}px;
  816. -moz-border-radius: {$this->get_setting( 'outer_border_radius' )}px;
  817. }";
  818. }
  819. if ( $this->slider_settings['navigation'] != 'hidden' && $this->get_setting( 'enable_custom_navigation' ) == 'enabled' ) {
  820. $theme .= " [metaslider] .theme-default .nivo-controlNav a {
  821. padding: 0;
  822. box-shadow: none;
  823. border-style: solid;
  824. border-color: {$this->get_setting( 'dot_border_colour' )};
  825. border-radius: {$this->get_setting( 'dot_border_radius' )}px;
  826. -webkit-border-radius: {$this->get_setting( 'dot_border_radius' )}px;
  827. -moz-border-radius: {$this->get_setting( 'dot_border_radius' )}px;
  828. border-width: {$this->get_setting( 'dot_border_width' )}px;
  829. border: {$this->get_setting( 'dot_border_width' )}px solid {$this->get_setting( 'dot_border_colour' )};
  830. line-height: {$this->get_setting( 'dot_size' )}px;
  831. width: {$this->get_setting( 'dot_size' )}px;
  832. height: {$this->get_setting( 'dot_size' )}px;
  833. margin-left: {$this->get_setting( 'dot_spacing' )}px;
  834. margin-right: {$this->get_setting( 'dot_spacing' )}px;
  835. background: {$this->rgba_to_rgb( 'dot_fill_colour_start' )};
  836. background: {$this->get_setting( 'dot_fill_colour_start' )};
  837. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from({$this->get_setting( 'dot_fill_colour_start' )}), to({$this->get_setting( 'dot_fill_colour_end' )}));
  838. background: -webkit-linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  839. background: -moz-linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  840. background: -ms-linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  841. background: -o-linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  842. background: linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  843. }
  844. [metaslider] .theme-default .nivo-controlNav a.active {
  845. border: {$this->get_setting( 'dot_border_width' )}px solid {$this->get_setting( 'active_dot_border_colour' )};
  846. background: {$this->rgba_to_rgb( 'active_dot_fill_colour_start' )};
  847. background: {$this->get_setting( 'active_dot_fill_colour_start' )};
  848. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from({$this->get_setting( 'active_dot_fill_colour_start' )}), to({$this->get_setting( 'active_dot_fill_colour_end' )}));
  849. background: -webkit-linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  850. background: -moz-linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  851. background: -ms-linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  852. background: -o-linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  853. background: linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  854. }
  855. [metaslider] .theme-default .nivo-controlNav {
  856. line-height: {$this->get_setting( 'dot_size' )}px;
  857. padding: 0;
  858. background: transparent;
  859. z-index: 99;
  860. margin-top: {$this->get_setting( 'nav_vertical_margin' )}px;
  861. margin-bottom: {$this->get_setting( 'nav_vertical_margin' )}px;
  862. margin-left: {$this->get_setting( 'nav_horizontal_margin' )}px;
  863. margin-right: {$this->get_setting( 'nav_horizontal_margin' )}px;
  864. {$this->get_nav_position_css()}
  865. }";
  866. }
  867. if ( $this->get_setting( 'enable_custom_caption' ) == 'enabled' ) {
  868. $theme .= " [metaslider] .theme-default .nivo-caption {
  869. opacity: 1;
  870. margin: {$this->get_setting( 'caption_vertical_margin' )}px {$this->get_setting( 'caption_horizontal_margin' )}px;
  871. color: {$this->get_setting( 'caption_text_colour' )};
  872. background: {$this->rgba_to_rgb( 'caption_background_colour' )};
  873. background: {$this->get_setting( 'caption_background_colour' )};
  874. {$this->get_caption_position_css()}
  875. {$this->get_caption_text_align_css()}
  876. border-radius: {$this->get_setting( 'caption_border_radius' )}px;
  877. -webkit-border-radius: {$this->get_setting( 'caption_border_radius' )}px;
  878. -moz-border-radius: {$this->get_setting( 'caption_border_radius' )}px;
  879. }";
  880. }
  881. if ( $this->get_setting( 'enable_custom_arrows' ) == 'enabled' ) {
  882. $theme .= " [metaslider] .theme-default .nivoSlider:hover .nivo-directionNav a {
  883. opacity: {$this->get_arrow_opacity_hover()};
  884. }
  885. [metaslider] .theme-default .nivo-prevNav {
  886. left: {$this->get_setting( 'arrow_indent' )}px;
  887. background: transparent url(" . $arrow['prev']['url'] . ") " . $arrow['prev']['position'] . ";
  888. width: " . $arrow['prev']['width'] . "px;
  889. height: " . $arrow['prev']['height'] . "px;
  890. margin-top: -" . ( $arrow['prev']['height'] / 2 ) . "px;
  891. opacity: {$this->get_arrow_opacity()};
  892. }
  893. [metaslider] .theme-default .nivo-nextNav {
  894. right: {$this->get_setting( 'arrow_indent' )}px;
  895. background: transparent url(" . $arrow['next']['url'] . ") " . $arrow['next']['position'] . ";
  896. width: " . $arrow['next']['width'] . "px;
  897. height: " . $arrow['next']['height'] . "px;
  898. margin-top: -" . ( $arrow['next']['height'] / 2 ) . "px;
  899. opacity: {$this->get_arrow_opacity()};
  900. }";
  901. }
  902. $theme .= " [metaslider] .theme-default .nivoSlider {
  903. -webkit-box-shadow: none;
  904. -moz-box-shadow: none;
  905. box-shadow: none;
  906. overflow: visible;
  907. }";
  908. return $theme;
  909. }
  910. /**
  911. * Return the CSS required to apply the theme to responsive slides.
  912. *
  913. * @param int $id slideshow ID
  914. * @param array $settings slideshow settings
  915. * @param array $arrow arrow information
  916. * @return string theme CSS
  917. */
  918. private function get_responsive_theme( $arrow ) {
  919. $theme = "";
  920. if ( $this->get_setting( 'outer_border_radius' ) > 0 ) {
  921. $theme .= " [metaslider] .rslides,
  922. [metaslider] .rslides img {
  923. border-radius: {$this->get_setting( 'outer_border_radius' )}px;
  924. -webkit-border-radius: {$this->get_setting( 'outer_border_radius' )}px;
  925. -moz-border-radius: {$this->get_setting( 'outer_border_radius' )}px;
  926. }";
  927. }
  928. if ( $this->slider_settings['navigation'] != 'hidden' && $this->get_setting( 'enable_custom_navigation' ) == 'enabled' ) {
  929. $theme .= " [metaslider] .rslides_tabs li {
  930. line-height: {$this->get_setting( 'dot_size' )}px;
  931. }
  932. [metaslider] .rslides_tabs li a {
  933. padding: 0;
  934. box-shadow: none;
  935. text-indent: -9999px;
  936. border-style: solid;
  937. display: inline-block;
  938. border-color: {$this->get_setting( 'dot_border_colour' )};
  939. border-radius: {$this->get_setting( 'dot_border_radius' )}px;
  940. -webkit-border-radius: {$this->get_setting( 'dot_border_radius' )}px;
  941. -moz-border-radius: {$this->get_setting( 'dot_border_radius' )}px;
  942. border-width: {$this->get_setting( 'dot_border_width' )}px;
  943. border: {$this->get_setting( 'dot_border_width' )}px solid {$this->get_setting( 'dot_border_colour' )};
  944. line-height: {$this->get_setting( 'dot_size' )}px;
  945. width: {$this->get_setting( 'dot_size' )}px;
  946. height: {$this->get_setting( 'dot_size' )}px;
  947. margin-left: {$this->get_setting( 'dot_spacing' )}px;
  948. margin-right: {$this->get_setting( 'dot_spacing' )}px;
  949. background: {$this->rgba_to_rgb( 'dot_fill_colour_start' )};
  950. background: {$this->get_setting( 'dot_fill_colour_start' )};
  951. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from({$this->get_setting( 'dot_fill_colour_start' )}), to({$this->get_setting( 'dot_fill_colour_end' )}));
  952. background: -webkit-linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  953. background: -moz-linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  954. background: -ms-linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  955. background: -o-linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  956. background: linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  957. }
  958. [metaslider] .rslides_tabs li.rslides_here a {
  959. border: {$this->get_setting( 'dot_border_width' )}px solid {$this->get_setting( 'active_dot_border_colour' )};
  960. background: {$this->rgba_to_rgb( 'active_dot_fill_colour_start' )};
  961. background: {$this->get_setting( 'active_dot_fill_colour_start' )};
  962. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from({$this->get_setting( 'active_dot_fill_colour_start' )}), to({$this->get_setting( 'active_dot_fill_colour_end' )}));
  963. background: -webkit-linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  964. background: -moz-linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  965. background: -ms-linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  966. background: -o-linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  967. background: linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  968. }
  969. [metaslider] .rslides_tabs {
  970. line-height: {$this->get_setting( 'dot_size' )}px;
  971. padding: 0 !important;
  972. background: transparent;
  973. z-index: 99;
  974. margin: {$this->get_setting( 'nav_vertical_margin' )}px {$this->get_setting( 'nav_horizontal_margin' )}px;
  975. {$this->get_nav_position_css()}
  976. }";
  977. }
  978. if ( $this->get_setting( 'enable_custom_caption' ) == 'enabled' ) {
  979. $theme .= " [metaslider] .rslides .caption-wrap {
  980. opacity: 1;
  981. margin: {$this->get_setting( 'caption_vertical_margin' )}px {$this->get_setting( 'caption_horizontal_margin' )}px;
  982. color: {$this->get_setting( 'caption_text_colour' )};
  983. background: {$this->rgba_to_rgb( 'caption_background_colour' )};
  984. background: {$this->get_setting( 'caption_background_colour' )};
  985. {$this->get_caption_position_css()}
  986. {$this->get_caption_text_align_css()}
  987. border-radius: {$this->get_setting( 'caption_border_radius' )}px;
  988. -webkit-border-radius: {$this->get_setting( 'caption_border_radius' )}px;
  989. -moz-border-radius: {$this->get_setting( 'caption_border_radius' )}px;
  990. }";
  991. }
  992. if ( $this->get_setting( 'enable_custom_arrows' ) == 'enabled' ) {
  993. $theme .= " [metaslider] .rslides_nav {
  994. padding: 0;
  995. text-indent: -9999px;
  996. background-color: transparent;
  997. margin-top: -" . ( $arrow['prev']['height'] / 2 ) . "px;
  998. opacity: " . $this->get_setting( 'arrow_opacity' ) / 100 . ";
  999. }
  1000. [metaslider] .rslides_nav.prev {
  1001. left: {$this->get_setting( 'arrow_indent' )}px;
  1002. background: transparent url(" . $arrow['prev']['url'] . ") " . $arrow['prev']['position'] . ";
  1003. width: " . $arrow['prev']['width'] . "px;
  1004. height: " . $arrow['prev']['height'] . "px;
  1005. }
  1006. [metaslider] .rslides_nav.next {
  1007. right: {$this->get_setting( 'arrow_indent' )}px;
  1008. background: transparent url(" . $arrow['next']['url'] . ") " . $arrow['next']['position'] . ";
  1009. width: " . $arrow['next']['width'] . "px;
  1010. height: " . $arrow['next']['height'] . "px;
  1011. }";
  1012. }
  1013. return $theme;
  1014. }
  1015. /**
  1016. * Return the CSS required to apply the theme to coin slider.
  1017. *
  1018. * @param int $id slideshow ID
  1019. * @param array $settings slideshow settings
  1020. * @param array $arrow arrow information
  1021. * @return string theme CSS
  1022. */
  1023. private function get_coin_theme( $arrow ) {
  1024. $theme = "";
  1025. if ( $this->slider_settings['navigation'] != 'hidden' && $this->get_setting( 'enable_custom_navigation' ) == 'enabled' ) {
  1026. $theme .= " [metaslider] .cs-buttons a {
  1027. padding: 0;
  1028. box-shadow: none;
  1029. text-indent: -9999px;
  1030. border-style: solid;
  1031. display: inline-block;
  1032. border-color: {$this->get_setting( 'dot_border_colour' )};
  1033. border-radius: {$this->get_setting( 'dot_border_radius' )}px;
  1034. -webkit-border-radius: {$this->get_setting( 'dot_border_radius' )}px;
  1035. -moz-border-radius: {$this->get_setting( 'dot_border_radius' )}px;
  1036. border-width: {$this->get_setting( 'dot_border_width' )}px;
  1037. border: {$this->get_setting( 'dot_border_width' )}px solid {$this->get_setting( 'dot_border_colour' )};
  1038. line-height: {$this->get_setting( 'dot_size' )}px;
  1039. width: {$this->get_setting( 'dot_size' )}px;
  1040. height: {$this->get_setting( 'dot_size' )}px;
  1041. margin-left: {$this->get_setting( 'dot_spacing' )}px;
  1042. margin-right: {$this->get_setting( 'dot_spacing' )}px;
  1043. background: {$this->rgba_to_rgb( 'dot_fill_colour_start' )};
  1044. background: {$this->get_setting( 'dot_fill_colour_start' )};
  1045. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from({$this->get_setting( 'dot_fill_colour_start' )}), to({$this->get_setting( 'dot_fill_colour_end' )}));
  1046. background: -webkit-linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  1047. background: -moz-linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  1048. background: -ms-linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  1049. background: -o-linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  1050. background: linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  1051. }
  1052. [metaslider] .cs-buttons a.cs-active {
  1053. border: {$this->get_setting( 'dot_border_width' )}px solid {$this->get_setting( 'active_dot_border_colour' )};
  1054. background: {$this->rgba_to_rgb( 'active_dot_fill_colour_start' )};
  1055. background: {$this->get_setting( 'active_dot_fill_colour_start' )};
  1056. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from({$this->get_setting( 'active_dot_fill_colour_start' )}), to({$this->get_setting( 'active_dot_fill_colour_end' )}));
  1057. background: -webkit-linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  1058. background: -moz-linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  1059. background: -ms-linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  1060. background: -o-linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  1061. background: linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  1062. }
  1063. [metaslider] .cs-buttons {
  1064. line-height: {$this->get_setting( 'dot_size' )}px;
  1065. padding: 0 !important;
  1066. background: transparent !important;
  1067. z-index: 99;
  1068. margin: {$this->get_setting( 'nav_vertical_margin' )}px {$this->get_setting( 'nav_horizontal_margin' )}px;
  1069. {$this->get_nav_position_css( true )}
  1070. }";
  1071. }
  1072. if ( $this->get_setting( 'enable_custom_caption' ) == 'enabled' ) {
  1073. $theme .= " [metaslider] .cs-title {
  1074. margin: {$this->get_setting( 'caption_vertical_margin' )}px {$this->get_setting( 'caption_horizontal_margin' )}px;
  1075. color: {$this->get_setting( 'caption_text_colour' )};
  1076. background: {$this->rgba_to_rgb( 'caption_background_colour' )};
  1077. background: {$this->get_setting( 'caption_background_colour' )};
  1078. {$this->get_caption_position_css( true )}
  1079. {$this->get_caption_text_align_css()}
  1080. border-radius: {$this->get_setting( 'caption_border_radius' )}px;
  1081. -webkit-border-radius: {$this->get_setting( 'caption_border_radius' )}px;
  1082. -moz-border-radius: {$this->get_setting( 'caption_border_radius' )}px;
  1083. }";
  1084. }
  1085. if ( $this->get_setting( 'enable_custom_arrows' ) == 'enabled' ) {
  1086. $theme .= " [metaslider] .cs-prev,
  1087. [metaslider] .cs-next {
  1088. padding: 0 !important;
  1089. text-indent: -9999px;
  1090. background-color: transparent;
  1091. margin-top: -" . ( $arrow['prev']['height'] / 2 ) . "px !important;
  1092. top: 50% !important;
  1093. opacity: " . $this->get_setting( 'arrow_opacity' ) / 100 . "!important;
  1094. }
  1095. [metaslider] .cs-prev {
  1096. left: {$this->get_setting( 'arrow_indent' )}px !important;
  1097. background: transparent url(" . $arrow['prev']['url'] . ") " . $arrow['prev']['position'] . ";
  1098. width: " . $arrow['prev']['width'] . "px;
  1099. height: " . $arrow['prev']['height'] . "px;
  1100. }
  1101. [metaslider] .cs-next {
  1102. right: {$this->get_setting( 'arrow_indent' )}px !important;
  1103. background: transparent url(" . $arrow['next']['url'] . ") " . $arrow['next']['position'] . ";
  1104. width: " . $arrow['next']['width'] . "px;
  1105. height: " . $arrow['next']['height'] . "px;
  1106. }";
  1107. }
  1108. if ( $this->get_setting( 'arrows_always_show' ) == 'enabled' ) {
  1109. $theme .= " [metaslider] #cs-navigation-metaslider_{$id} {
  1110. display: block !important;
  1111. }";
  1112. }
  1113. return $theme;
  1114. }
  1115. /**
  1116. * Return the CSS required to apply the theme to flex slider.
  1117. *
  1118. * @param int $id slideshow ID
  1119. * @param array $settings slideshow settings
  1120. * @param array $arrow arrow information
  1121. * @return string theme CSS
  1122. */
  1123. private function get_flex_theme( $arrow ) {
  1124. $theme = "";
  1125. if ( $this->get_setting( 'outer_border_radius' ) > 0 ) {
  1126. $theme .= " [metaslider] .flexslider,
  1127. [metaslider] .flexslider img {
  1128. border-radius: {$this->get_setting( 'outer_border_radius' )}px;
  1129. -webkit-border-radius: {$this->get_setting( 'outer_border_radius' )}px;
  1130. -moz-border-radius: {$this->get_setting( 'outer_border_radius' )}px;
  1131. }";
  1132. }
  1133. if ( $this->slider_settings['navigation'] != 'hidden' && $this->get_setting( 'enable_custom_navigation' ) == 'enabled' ) {
  1134. $theme .= " [metaslider] .flexslider .flex-control-paging li a,
  1135. [metaslider] .flexslider .flex-control-paging li a:hover {
  1136. padding: 0;
  1137. box-shadow: none;
  1138. text-indent: -9999px;
  1139. border-style: solid;
  1140. display: inline-block;
  1141. border-color: {$this->get_setting( 'dot_border_colour' )};
  1142. border-radius: {$this->get_setting( 'dot_border_radius' )}px;
  1143. -webkit-border-radius: {$this->get_setting( 'dot_border_radius' )}px;
  1144. -moz-border-radius: {$this->get_setting( 'dot_border_radius' )}px;
  1145. border-width: {$this->get_setting( 'dot_border_width' )}px;
  1146. border: {$this->get_setting( 'dot_border_width' )}px solid {$this->get_setting( 'dot_border_colour' )};
  1147. line-height: {$this->get_setting( 'dot_size' )}px;
  1148. width: {$this->get_setting( 'dot_size' )}px;
  1149. height: {$this->get_setting( 'dot_size' )}px;
  1150. margin: 0 {$this->get_setting( 'dot_spacing' )}px;
  1151. background: {$this->rgba_to_rgb( 'dot_fill_colour_start' )};
  1152. background: {$this->get_setting( 'dot_fill_colour_start' )};
  1153. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from({$this->get_setting( 'dot_fill_colour_start' )}), to({$this->get_setting( 'dot_fill_colour_end' )}));
  1154. background: -webkit-linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  1155. background: -moz-linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  1156. background: -ms-linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  1157. background: -o-linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  1158. background: linear-gradient(top, {$this->get_setting( 'dot_fill_colour_start' )}, {$this->get_setting( 'dot_fill_colour_end' )});
  1159. }
  1160. [metaslider] .flexslider .flex-control-paging li {
  1161. margin: 0;
  1162. text-indent: 0;
  1163. width: auto;
  1164. }
  1165. [metaslider] .flexslider .flex-control-paging li a.flex-active {
  1166. border: {$this->get_setting( 'dot_border_width' )}px solid {$this->get_setting( 'active_dot_border_colour' )};
  1167. background: {$this->rgba_to_rgb( 'active_dot_fill_colour_start' )};
  1168. background: {$this->get_setting( 'active_dot_fill_colour_start' )};
  1169. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from({$this->get_setting( 'active_dot_fill_colour_start' )}), to({$this->get_setting( 'active_dot_fill_colour_end' )}));
  1170. background: -webkit-linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  1171. background: -moz-linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  1172. background: -ms-linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  1173. background: -o-linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  1174. background: linear-gradient(top, {$this->get_setting( 'active_dot_fill_colour_start' )}, {$this->get_setting( 'active_dot_fill_colour_end' )});
  1175. }
  1176. [metaslider] .flexslider .flex-control-paging {
  1177. line-height: {$this->get_setting( 'dot_size' )}px;
  1178. z-index: 99;
  1179. padding: 0;
  1180. text-align: left;
  1181. margin: {$this->get_setting( 'nav_vertical_margin' )}px {$this->get_setting( 'nav_horizontal_margin' )}px;
  1182. {$this->get_nav_position_css()}
  1183. }";
  1184. }
  1185. if ( $this->get_setting( 'enable_custom_caption' ) == 'enabled' ) {
  1186. $theme .= " [metaslider] .flexslider .caption-wrap {
  1187. opacity: 1;
  1188. margin: {$this->get_setting( 'caption_vertical_margin' )}px {$this->get_setting( 'caption_horizontal_margin' )}px;
  1189. color: {$this->get_setting( 'caption_text_colour' )};
  1190. background: {$this->rgba_to_rgb( 'caption_background_colour' )};
  1191. background: {$this->get_setting( 'caption_background_colour' )};
  1192. {$this->get_caption_position_css()}
  1193. {$this->get_caption_text_align_css()}
  1194. border-radius: {$this->get_setting( 'caption_border_radius' )}px;
  1195. -webkit-border-radius: {$this->get_setting( 'caption_border_radius' )}px;
  1196. -moz-border-radius: {$this->get_setting( 'caption_border_radius' )}px;
  1197. }";
  1198. }
  1199. if ( $this->get_setting( 'enable_custom_arrows' ) == 'enabled' ) {
  1200. $theme .= " [metaslider] .flexslider .flex-direction-nav .flex-prev {
  1201. background: transparent url(" . $arrow['prev']['url'] . ") " . $arrow['prev']['position'] . " no-repeat;
  1202. margin-top: -" . ( $arrow['prev']['height'] / 2 ) . "px;
  1203. width: " . $arrow['prev']['width'] . "px;
  1204. height: " . $arrow['prev']['height'] . "px;
  1205. opacity: {$this->get_arrow_opacity()};
  1206. left: {$this->get_arrow_indent()};
  1207. padding: 0;
  1208. }
  1209. [metaslider] .flexslider .flex-direction-nav .flex-next {
  1210. background: transparent url(" . $arrow['next']['url'] . ") " . $arrow['next']['position'] . " no-repeat;
  1211. margin-top: -" . ( $arrow['next']['height'] / 2 ) . "px;
  1212. width: " . $arrow['next']['width'] . "px;
  1213. height: " . $arrow['next']['height'] . "px;
  1214. opacity: {$this->get_arrow_opacity()};
  1215. right: {$this->get_arrow_indent()};
  1216. padding: 0;
  1217. }
  1218. [metaslider] .flexslider:hover .flex-direction-nav .flex-prev {
  1219. left: {$this->get_arrow_indent_hover()};
  1220. opacity: {$this->get_arrow_opacity_hover()};
  1221. }
  1222. [metaslider] .flexslider:hover .flex-direction-nav .flex-next {
  1223. right: {$this->get_arrow_indent_hover()};
  1224. opacity: {$this->get_arrow_opacity_hover()};
  1225. }";
  1226. }
  1227. return $theme;
  1228. }
  1229. /**
  1230. * Convert RGBA to RGB (for browsers that don't support RGBA)
  1231. */
  1232. private function rgba_to_rgb( $setting ) {
  1233. $rgba_value = $this->get_setting( $setting );
  1234. // find the "(X, X, X, X)" value
  1235. preg_match( '/\((.*?)\)/', $rgba_value, $match );
  1236. if ( isset( $match ) ) {
  1237. // split into separate values
  1238. $rgb_vals = explode( ",", $match[1] );
  1239. $r = isset( $rgb_vals[0] ) ? $rgb_vals[0] : 0;
  1240. $g = isset( $rgb_vals[1] ) ? $rgb_vals[1] : 0;
  1241. $b = isset( $rgb_vals[2] ) ? $rgb_vals[2] : 0;
  1242. // return RGB value (without alpha)
  1243. return "rgb({$r}, {$g}, {$b})";
  1244. }
  1245. // default: return rgb code for black;
  1246. return "rgb(0, 0, 0)";
  1247. }
  1248. /**
  1249. * Return the arrow indent
  1250. */
  1251. public function get_arrow_indent() {
  1252. if ( $this->get_setting( 'arrows_always_show' ) == 'enabled' ) {
  1253. return $this->get_setting( 'arrow_indent' ) . 'px';
  1254. }
  1255. return $this->get_setting( 'arrow_indent' ) - 5 . 'px';
  1256. }
  1257. /**
  1258. * Return the arrow indent when hovering over the slideshow
  1259. */
  1260. public function get_arrow_indent_hover() {
  1261. return $this->get_setting( 'arrow_indent' ) . 'px';
  1262. }
  1263. /**
  1264. * Return the arrow opacity when hovering over the slideshow
  1265. */
  1266. public function get_arrow_opacity_hover() {
  1267. return $this->get_setting( 'arrow_opacity' ) / 100;
  1268. }
  1269. /**
  1270. * Return the arrow opacity
  1271. */
  1272. public function get_arrow_opacity() {
  1273. if ( $this->get_setting( 'arrows_always_show' ) == 'enabled' ) {
  1274. return $this->get_setting( 'arrow_opacity' ) / 100;
  1275. }
  1276. return 0;
  1277. }
  1278. /**
  1279. * Return CSS rules for the caption positioning
  1280. *
  1281. * @param array $settings
  1282. * @param bool $important
  1283. * @return string
  1284. */
  1285. public function get_caption_text_align_css() {
  1286. $position = $this->get_setting( 'caption_align' );
  1287. if ( $position != 'left' ) {
  1288. return "text-align: {$position};";
  1289. }
  1290. }
  1291. /**
  1292. * Return CSS rules for the caption positioning
  1293. *
  1294. * @param array $settings
  1295. * @param bool $important
  1296. * @return string
  1297. */
  1298. public function get_caption_position_css( $important = false ) {
  1299. $position = $this->get_setting( 'caption_position' );
  1300. $width = $this->get_setting( 'caption_width' );
  1301. $captionPosition['width'] = $width . "%";
  1302. $captionPosition['top'] = 'auto';
  1303. $captionPosition['right'] = 'auto';
  1304. $captionPosition['bottom'] = 'auto';
  1305. $captionPosition['left'] = 'auto';
  1306. $captionPosition['clear'] = 'none';
  1307. $captionPosition['position'] = 'absolute';
  1308. if ( $position == 'topCenter' || $position == 'bottomCenter' ) {
  1309. $captionPosition['width'] = '100%';
  1310. }
  1311. if ( $position == 'topRight' ) {
  1312. $captionPosition['top'] = 0;
  1313. $captionPosition['right'] = 0;
  1314. }
  1315. if ( $position == 'topLeft' ) {
  1316. $captionPosition['top'] = 0;
  1317. $captionPosition['left'] = 0;
  1318. }
  1319. if ( $position == 'bottomLeft' ) {
  1320. $captionPosition['bottom'] = 0;
  1321. $captionPosition['left'] = 0;
  1322. }
  1323. if ( $position == 'bottomRight' ) {
  1324. $captionPosition['bottom'] = 0;
  1325. $captionPosition['right'] = 0;
  1326. }
  1327. if ( $position == 'underneath' ) {
  1328. $captionPosition['width'] = '100%';
  1329. $captionPosition['top'] = 'auto';
  1330. $captionPosition['right'] = 'auto';
  1331. $captionPosition['bottom'] = 'auto';
  1332. $captionPosition['left'] = 'auto';
  1333. $captionPosition['clear'] = 'both';
  1334. $captionPosition['position'] = 'relative';
  1335. }
  1336. $important = $important ? ' !important' : '';
  1337. foreach ( $captionPosition as $key => $value ) {
  1338. $rules[] = $key . ": " . $value . $important . ";";
  1339. }
  1340. return implode( "\n ", $rules );
  1341. }
  1342. /**
  1343. * Return an HTML select list of the available arrow options
  1344. *
  1345. * @return string
  1346. */
  1347. public function get_arrow_options() {
  1348. $arrow_select_options = "";
  1349. $selected_arrow_type = $this->get_setting( 'arrow_type' );
  1350. $arrows = $this->get_arrows();
  1351. foreach ( $arrows as $id => $vals ) {
  1352. $arrow_select_options .= "<option value='{$id}' data-height='{$vals['height']}' data-width='{$vals['width']}' data-offset='{$vals['offset']}'";
  1353. if ( $id == $selected_arrow_type ) {
  1354. $arrow_select_options .= " selected=selected";
  1355. }
  1356. $arrow_select_options .= ">" . __( "Type", 'metasliderpro' ) . " {$id}</option>";
  1357. }
  1358. return $arrow_select_options;
  1359. }
  1360. /**
  1361. * Return an HTML select list of the available arrow colours
  1362. *
  1363. * @return string
  1364. */
  1365. public function get_arrow_colours() {
  1366. $selected_arrow_colour = $this->get_setting( 'arrow_colour' );
  1367. $colours = array(
  1368. __("Black", "metasliderpro") => 'black',
  1369. __("Blue", "metasliderpro") => 'blue',
  1370. __("Green", "metasliderpro") => 'green',
  1371. __("Grey", "metasliderpro") => 'grey',
  1372. __("Navy", "metasliderpro") => 'navy',
  1373. __("Purple", "metasliderpro") => 'purple',
  1374. __("Red", "metasliderpro") => 'red',
  1375. __("White", "metasliderpro") => 'white',
  1376. __("Yellow", "metasliderpro") => 'yellow'
  1377. );
  1378. $arrow_colour_options = "";
  1379. foreach ( $colours as $name => $colour ) {
  1380. $arrow_colour_options .= "<option value='{$colour}' data-url='" . plugins_url( 'assets/arrows/' , __FILE__ ) . $colour . ".png'";
  1381. if ( $colour == $selected_arrow_colour ) {
  1382. $arrow_colour_options .= " selected=selected";
  1383. }
  1384. $arrow_colour_options .= ">" . $name . "</option>";
  1385. }
  1386. return $arrow_colour_options;
  1387. }
  1388. }