PageRenderTime 58ms 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

Large files files are truncated, but you can click here to view the full file

  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_d…

Large files files are truncated, but you can click here to view the full file