PageRenderTime 57ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/ml-slider/ml-slider.php

https://gitlab.com/gevvvvv/Tumo-Workshop-Cafe
PHP | 1723 lines | 1241 code | 285 blank | 197 comment | 91 complexity | 0974614afabd255a0a6dbc616ee1833d MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1

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

  1. <?php
  2. /*
  3. * Meta Slider. Slideshow plugin for WordPress.
  4. *
  5. * Plugin Name: Meta Slider
  6. * Plugin URI: http://www.metaslider.com
  7. * Description: Easy to use slideshow plugin. Create SEO optimised responsive slideshows with Nivo Slider, Flex Slider, Coin Slider and Responsive Slides.
  8. * Version: 2.9.1
  9. * Author: Matcha Labs
  10. * Author URI: http://www.matchalabs.com
  11. * License: GPL-2.0+
  12. * Copyright: 2014 Matcha Labs LTD
  13. *
  14. * Text Domain: metaslider
  15. * Domain Path: /languages/
  16. */
  17. if ( ! defined( 'ABSPATH' ) ) {
  18. exit; // disable direct access
  19. }
  20. if ( ! class_exists( 'MetaSliderPlugin' ) ) :
  21. /**
  22. * Register the plugin.
  23. *
  24. * Display the administration panel, insert JavaScript etc.
  25. */
  26. class MetaSliderPlugin {
  27. /**
  28. * @var string
  29. */
  30. public $version = '2.9.1';
  31. /**
  32. * @var MetaSlider
  33. */
  34. public $slider = null;
  35. /**
  36. * Init
  37. */
  38. public static function init() {
  39. $metaslider = new self();
  40. }
  41. /**
  42. * Constructor
  43. */
  44. public function __construct() {
  45. $this->define_constants();
  46. $this->includes();
  47. $this->setup_actions();
  48. $this->setup_filters();
  49. $this->setup_shortcode();
  50. $this->register_slide_types();
  51. }
  52. /**
  53. * Define Meta Slider constants
  54. */
  55. private function define_constants() {
  56. define( 'METASLIDER_VERSION', $this->version );
  57. define( 'METASLIDER_BASE_URL', trailingslashit( plugins_url( 'ml-slider' ) ) );
  58. define( 'METASLIDER_ASSETS_URL', trailingslashit( METASLIDER_BASE_URL . 'assets' ) );
  59. define( 'METASLIDER_PATH', plugin_dir_path( __FILE__ ) );
  60. }
  61. /**
  62. * All Meta Slider classes
  63. */
  64. private function plugin_classes() {
  65. return array(
  66. 'metaslider' => METASLIDER_PATH . 'inc/slider/metaslider.class.php',
  67. 'metacoinslider' => METASLIDER_PATH . 'inc/slider/metaslider.coin.class.php',
  68. 'metaflexslider' => METASLIDER_PATH . 'inc/slider/metaslider.flex.class.php',
  69. 'metanivoslider' => METASLIDER_PATH . 'inc/slider/metaslider.nivo.class.php',
  70. 'metaresponsiveslider' => METASLIDER_PATH . 'inc/slider/metaslider.responsive.class.php',
  71. 'metaslide' => METASLIDER_PATH . 'inc/slide/metaslide.class.php',
  72. 'metaimageslide' => METASLIDER_PATH . 'inc/slide/metaslide.image.class.php',
  73. 'metasliderimagehelper' => METASLIDER_PATH . 'inc/metaslider.imagehelper.class.php',
  74. 'metaslidersystemcheck' => METASLIDER_PATH . 'inc/metaslider.systemcheck.class.php',
  75. 'metaslider_widget' => METASLIDER_PATH . 'inc/metaslider.widget.class.php',
  76. 'simple_html_dom' => METASLIDER_PATH . 'inc/simple_html_dom.php'
  77. );
  78. }
  79. /**
  80. * Load required classes
  81. */
  82. private function includes() {
  83. $autoload_is_disabled = defined( 'METASLIDER_AUTOLOAD_CLASSES' ) && METASLIDER_AUTOLOAD_CLASSES === false;
  84. if ( function_exists( "spl_autoload_register" ) && ! ( $autoload_is_disabled ) ) {
  85. // >= PHP 5.2 - Use auto loading
  86. if ( function_exists( "__autoload" ) ) {
  87. spl_autoload_register( "__autoload" );
  88. }
  89. spl_autoload_register( array( $this, 'autoload' ) );
  90. } else {
  91. // < PHP5.2 - Require all classes
  92. foreach ( $this->plugin_classes() as $id => $path ) {
  93. if ( is_readable( $path ) && ! class_exists( $id ) ) {
  94. require_once( $path );
  95. }
  96. }
  97. }
  98. }
  99. /**
  100. * Autoload Meta Slider classes to reduce memory consumption
  101. */
  102. public function autoload( $class ) {
  103. $classes = $this->plugin_classes();
  104. $class_name = strtolower( $class );
  105. if ( isset( $classes[$class_name] ) && is_readable( $classes[$class_name] ) ) {
  106. require_once( $classes[$class_name] );
  107. }
  108. }
  109. /**
  110. * Register the [metaslider] shortcode.
  111. */
  112. private function setup_shortcode() {
  113. add_shortcode( 'metaslider', array( $this, 'register_shortcode' ) );
  114. add_shortcode( 'ml-slider', array( $this, 'register_shortcode' ) ); // backwards compatibility
  115. }
  116. /**
  117. * Hook Meta Slider into WordPress
  118. */
  119. private function setup_actions() {
  120. add_action( 'admin_menu', array( $this, 'register_admin_menu' ), 9553 );
  121. add_action( 'init', array( $this, 'register_post_type' ) );
  122. add_action( 'init', array( $this, 'register_taxonomy' ) );
  123. add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
  124. add_action( 'admin_footer', array( $this, 'admin_footer' ), 11 );
  125. add_action( 'media_upload_vimeo', array( $this, 'upgrade_to_pro_tab' ) );
  126. add_action( 'media_upload_youtube', array( $this, 'upgrade_to_pro_tab' ) );
  127. add_action( 'media_upload_post_feed', array( $this, 'upgrade_to_pro_tab' ) );
  128. add_action( 'media_upload_layer', array( $this, 'upgrade_to_pro_tab' ) );
  129. add_action( 'admin_post_metaslider_preview', array( $this, 'do_preview' ) );
  130. add_action( 'widgets_init', array( $this, 'register_metaslider_widget' ) );
  131. if ( defined( 'METASLIDER_ENABLE_RESOURCE_MANAGER' ) && METASLIDER_ENABLE_RESOURCE_MANAGER === true ) {
  132. add_action( 'template_redirect', array( $this, 'start_resource_manager'), 0 );
  133. }
  134. }
  135. /**
  136. * Hook Meta Slider into WordPress
  137. */
  138. private function setup_filters() {
  139. add_filter( 'media_upload_tabs', array( $this, 'custom_media_upload_tab_name' ), 998 );
  140. add_filter( 'media_view_strings', array( $this, 'custom_media_uploader_tabs' ), 5 );
  141. add_filter( 'media_buttons_context', array( $this, 'insert_metaslider_button' ) );
  142. // add 'go pro' link to plugin options
  143. $plugin = plugin_basename( __FILE__ );
  144. add_filter( "plugin_action_links_{$plugin}", array( $this, 'upgrade_to_pro_link' ) );
  145. }
  146. /**
  147. * Register Meta Slider widget
  148. */
  149. public function register_metaslider_widget() {
  150. register_widget( 'MetaSlider_Widget' );
  151. }
  152. /**
  153. * Register ML Slider post type
  154. */
  155. public function register_post_type() {
  156. register_post_type( 'ml-slider', array(
  157. 'query_var' => false,
  158. 'rewrite' => false,
  159. 'public' => true,
  160. 'exclude_from_search' => true,
  161. 'publicly_queryable' => false,
  162. 'show_in_nav_menus' => false,
  163. 'show_ui' => false,
  164. 'labels' => array(
  165. 'name' => 'Meta Slider'
  166. )
  167. )
  168. );
  169. }
  170. /**
  171. * Register taxonomy to store slider => slides relationship
  172. */
  173. public function register_taxonomy() {
  174. register_taxonomy( 'ml-slider', 'attachment', array(
  175. 'hierarchical' => true,
  176. 'public' => false,
  177. 'query_var' => false,
  178. 'rewrite' => false
  179. )
  180. );
  181. }
  182. /**
  183. * Register our slide types
  184. */
  185. private function register_slide_types() {
  186. $image = new MetaImageSlide();
  187. }
  188. /**
  189. * Add the menu page
  190. */
  191. public function register_admin_menu() {
  192. $title = apply_filters( 'metaslider_menu_title', "Meta Slider" );
  193. $page = add_menu_page( $title, $title, 'edit_others_posts', 'metaslider', array(
  194. $this, 'render_admin_page'
  195. ), METASLIDER_ASSETS_URL . 'metaslider/matchalabs.png', 9501 );
  196. // ensure our JavaScript is only loaded on the Meta Slider admin page
  197. add_action( 'admin_print_scripts-' . $page, array( $this, 'register_admin_scripts' ) );
  198. add_action( 'admin_print_styles-' . $page, array( $this, 'register_admin_styles' ) );
  199. add_action( 'load-' . $page, array( $this, 'help_tab' ) );
  200. }
  201. /**
  202. * Shortcode used to display slideshow
  203. *
  204. * @return string HTML output of the shortcode
  205. */
  206. public function register_shortcode( $atts ) {
  207. if ( !isset( $atts['id'] ) ) {
  208. return false;
  209. }
  210. // handle [metaslider id=123 restrict_to=home]
  211. if ( isset( $atts['restrict_to'] ) && $atts['restrict_to'] == 'home' && ! is_front_page() ) {
  212. return;
  213. }
  214. // we have an ID to work with
  215. $slider = get_post( $atts['id'] );
  216. // check the slider is published and the ID is correct
  217. if ( ! $slider || $slider->post_status != 'publish' || $slider->post_type != 'ml-slider' ) {
  218. return "<!-- meta slider {$atts['id']} not found -->";
  219. }
  220. // lets go
  221. $this->set_slider( $atts['id'], $atts );
  222. $this->slider->enqueue_scripts();
  223. return $this->slider->render_public_slides();
  224. }
  225. /**
  226. * Initialise translations
  227. */
  228. public function load_plugin_textdomain() {
  229. load_plugin_textdomain( 'metaslider', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
  230. }
  231. /**
  232. * Add the help tab to the screen.
  233. */
  234. public function help_tab() {
  235. $screen = get_current_screen();
  236. // documentation tab
  237. $screen->add_help_tab( array(
  238. 'id' => 'documentation',
  239. 'title' => __( 'Documentation', 'metaslider' ),
  240. 'content' => "<p><a href='http://www.metaslider.com/documentation/' target='blank'>Meta Slider Documentation</a></p>",
  241. )
  242. );
  243. }
  244. /**
  245. * Rehister admin styles
  246. */
  247. public function register_admin_styles() {
  248. wp_enqueue_style( 'metaslider-admin-styles', METASLIDER_ASSETS_URL . 'metaslider/admin.css', false, METASLIDER_VERSION );
  249. wp_enqueue_style( 'metaslider-colorbox-styles', METASLIDER_ASSETS_URL . 'colorbox/colorbox.css', false, METASLIDER_VERSION );
  250. wp_enqueue_style( 'metaslider-tipsy-styles', METASLIDER_ASSETS_URL . 'tipsy/tipsy.css', false, METASLIDER_VERSION );
  251. do_action( 'metaslider_register_admin_styles' );
  252. }
  253. /**
  254. * Register admin JavaScript
  255. */
  256. public function register_admin_scripts() {
  257. // media library dependencies
  258. wp_enqueue_media();
  259. // plugin dependencies
  260. wp_enqueue_script( 'jquery-ui-core', array( 'jquery' ) );
  261. wp_enqueue_script( 'jquery-ui-sortable', array( 'jquery', 'jquery-ui-core' ) );
  262. wp_enqueue_script( 'metaslider-colorbox', METASLIDER_ASSETS_URL . 'colorbox/jquery.colorbox-min.js', array( 'jquery' ), METASLIDER_VERSION );
  263. wp_enqueue_script( 'metaslider-tipsy', METASLIDER_ASSETS_URL . 'tipsy/jquery.tipsy.js', array( 'jquery' ), METASLIDER_VERSION );
  264. wp_enqueue_script( 'metaslider-admin-script', METASLIDER_ASSETS_URL . 'metaslider/admin.js', array( 'jquery', 'metaslider-tipsy', 'media-upload' ), METASLIDER_VERSION );
  265. wp_dequeue_script( 'link' ); // WP Posts Filter Fix (Advanced Settings not toggling)
  266. wp_dequeue_script( 'ai1ec_requirejs' ); // All In One Events Calendar Fix (Advanced Settings not toggling)
  267. $this->localize_admin_scripts();
  268. do_action( 'metaslider_register_admin_scripts' );
  269. }
  270. /**
  271. * Localise admin script
  272. */
  273. public function localize_admin_scripts() {
  274. wp_localize_script( 'metaslider-admin-script', 'metaslider', array(
  275. 'url' => __( "URL", "metaslider" ),
  276. 'caption' => __( "Caption", "metaslider" ),
  277. 'new_window' => __( "New Window", "metaslider" ),
  278. 'confirm' => __( "Are you sure?", "metaslider" ),
  279. 'ajaxurl' => admin_url( 'admin-ajax.php' ),
  280. 'resize_nonce' => wp_create_nonce( 'metaslider_resize' ),
  281. 'addslide_nonce' => wp_create_nonce( 'metaslider_addslide' ),
  282. 'iframeurl' => admin_url( 'admin-post.php?action=metaslider_preview' ),
  283. 'useWithCaution' => __( "Caution: This setting is for advanced developers only. If you're unsure, leave it checked.", "metaslider" )
  284. )
  285. );
  286. }
  287. /**
  288. * Outputs a blank page containing a slideshow preview (for use in the 'Preview' iFrame)
  289. */
  290. public function do_preview() {
  291. remove_action('wp_footer', 'wp_admin_bar_render', 1000);
  292. if ( isset( $_GET['slider_id'] ) && absint( $_GET['slider_id'] ) > 0 ) {
  293. $id = absint( $_GET['slider_id'] );
  294. echo "<!DOCTYPE html>";
  295. echo "<html><head>";
  296. echo "<style>body, html { overflow: hidden; margin: 0; padding: 0; }</style>";
  297. echo "</head><body>";
  298. echo do_shortcode("[metaslider id={$id}]");
  299. wp_footer();
  300. echo "</body></html>";
  301. }
  302. die();
  303. }
  304. /**
  305. * Check our WordPress installation is compatible with Meta Slider
  306. */
  307. public function do_system_check() {
  308. $systemCheck = new MetaSliderSystemCheck();
  309. $systemCheck->check();
  310. }
  311. /**
  312. * Update the tab options in the media manager
  313. */
  314. public function custom_media_uploader_tabs( $strings ) {
  315. //update strings
  316. if ( ( isset( $_GET['page'] ) && $_GET['page'] == 'metaslider' ) ) {
  317. $strings['insertMediaTitle'] = __( "Image", "metaslider" );
  318. $strings['insertIntoPost'] = __( "Add to slider", "metaslider" );
  319. // remove options
  320. if ( isset( $strings['createGalleryTitle'] ) ) unset( $strings['createGalleryTitle'] );
  321. if ( isset( $strings['insertFromUrlTitle'] ) ) unset( $strings['insertFromUrlTitle'] );
  322. }
  323. return $strings;
  324. }
  325. /**
  326. * Add extra tabs to the default wordpress Media Manager iframe
  327. *
  328. * @var array existing media manager tabs
  329. */
  330. public function custom_media_upload_tab_name( $tabs ) {
  331. $metaslider_tabs = array( 'post_feed', 'layer', 'youtube', 'vimeo' );
  332. // restrict our tab changes to the meta slider plugin page
  333. if ( ( isset( $_GET['page'] ) && $_GET['page'] == 'metaslider' ) || ( isset( $_GET['tab'] ) && in_array( $_GET['tab'], $metaslider_tabs ) ) ) {
  334. $newtabs = array();
  335. if ( function_exists( 'is_plugin_active' ) && ! is_plugin_active( 'ml-slider-pro/ml-slider-pro.php' ) ) {
  336. $newtabs = array(
  337. 'post_feed' => __( "Post Feed", "metaslider" ),
  338. 'vimeo' => __( "Vimeo", "metaslider" ),
  339. 'youtube' => __( "YouTube", "metaslider" ),
  340. 'layer' => __( "Layer Slide", "metaslider" )
  341. );
  342. }
  343. if ( isset( $tabs['nextgen'] ) )
  344. unset( $tabs['nextgen'] );
  345. if ( is_array( $tabs ) ) {
  346. return array_merge( $tabs, $newtabs );
  347. } else {
  348. return $newtabs;
  349. }
  350. }
  351. return $tabs;
  352. }
  353. /**
  354. * Set the current slider
  355. */
  356. public function set_slider( $id, $shortcode_settings = array() ) {
  357. $type = 'flex';
  358. if ( isset( $shortcode_settings['type'] ) ) {
  359. $type = $shortcode_settings['type'];
  360. } else if ( $settings = get_post_meta( $id, 'ml-slider_settings', true ) ) {
  361. if ( is_array( $settings ) && isset( $settings['type'] ) ) {
  362. $type = $settings['type'];
  363. }
  364. }
  365. if ( ! in_array( $type, array( 'flex', 'coin', 'nivo', 'responsive' ) ) ) {
  366. $type = 'flex';
  367. }
  368. $this->slider = $this->create_slider( $type, $id, $shortcode_settings );
  369. }
  370. /**
  371. * Create a new slider based on the sliders type setting
  372. */
  373. private function create_slider( $type, $id, $shortcode_settings ) {
  374. switch ( $type ) {
  375. case( 'coin' ):
  376. return new MetaCoinSlider( $id, $shortcode_settings );
  377. case( 'flex' ):
  378. return new MetaFlexSlider( $id, $shortcode_settings );
  379. case( 'nivo' ):
  380. return new MetaNivoSlider( $id, $shortcode_settings );
  381. case( 'responsive' ):
  382. return new MetaResponsiveSlider( $id, $shortcode_settings );
  383. default:
  384. return new MetaFlexSlider( $id, $shortcode_settings );
  385. }
  386. }
  387. /**
  388. * Handle slide uploads/changes.
  389. */
  390. public function admin_process() {
  391. // this function should only ever be called from the Meta Slider admin page.
  392. if ( ! is_admin() ) {
  393. return;
  394. }
  395. // handle switching view
  396. if ( isset( $_GET['view'] ) ) {
  397. $this->switch_view();
  398. }
  399. // default to the latest slider
  400. $slider_id = $this->find_slider( 'modified', 'DESC' );
  401. // delete a slider
  402. if ( isset( $_GET['delete'] ) ) {
  403. $slider_id = $this->delete_slider( absint( $_GET['delete'] ) );
  404. }
  405. // load a slider by ID
  406. if ( isset( $_REQUEST['id'] ) ) {
  407. $temp_id = absint( $_REQUEST['id'] );
  408. // check valid post ID
  409. if ( get_post( $temp_id ) ) {
  410. $slider_id = $temp_id;
  411. }
  412. }
  413. // create a new slider
  414. if ( isset( $_GET['add'] ) ) {
  415. $slider_id = $this->add_slider();
  416. }
  417. // finally, set the slider
  418. if ( $slider_id > 0 ) {
  419. $this->set_slider( $slider_id );
  420. }
  421. }
  422. /**
  423. *
  424. */
  425. private function switch_view() {
  426. global $user_ID;
  427. $view = $_GET['view'];
  428. $allowed_views = array('tabs', 'dropdown');
  429. if ( ! in_array( $view, $allowed_views ) ) {
  430. return;
  431. }
  432. delete_user_meta( $user_ID, "metaslider_view" );
  433. if ( $view == 'dropdown' ) {
  434. add_user_meta( $user_ID, "metaslider_view", "dropdown");
  435. }
  436. }
  437. /**
  438. * Create a new slider
  439. */
  440. private function add_slider() {
  441. // check nonce
  442. check_admin_referer( "metaslider_add_slider" );
  443. $defaults = array();
  444. // if possible, take a copy of the last edited slider settings in place of default settings
  445. if ( $last_modified = $this->find_slider( 'modified', 'DESC' ) ) {
  446. $defaults = get_post_meta( $last_modified, 'ml-slider_settings', true );
  447. }
  448. // insert the post
  449. $id = wp_insert_post( array(
  450. 'post_title' => __( "New Slider", "metaslider" ),
  451. 'post_status' => 'publish',
  452. 'post_type' => 'ml-slider'
  453. )
  454. );
  455. // use the default settings if we can't find anything more suitable.
  456. if ( empty( $defaults ) ) {
  457. $slider = new MetaSlider( $id, array() );
  458. $defaults = $slider->get_default_parameters();
  459. }
  460. // insert the post meta
  461. add_post_meta( $id, 'ml-slider_settings', $defaults, true );
  462. // create the taxonomy term, the term is the ID of the slider itself
  463. wp_insert_term( $id, 'ml-slider' );
  464. return $id;
  465. }
  466. /**
  467. * Delete a slider (send it to trash)
  468. *
  469. * @param int $id
  470. */
  471. private function delete_slider( $id ) {
  472. // check nonce
  473. check_admin_referer( "metaslider_delete_slider" );
  474. // send the post to trash
  475. wp_update_post( array(
  476. 'ID' => $id,
  477. 'post_status' => 'trash'
  478. )
  479. );
  480. return $this->find_slider( 'date', 'DESC' );
  481. }
  482. /**
  483. * Find a single slider ID. For example, last edited, or first published.
  484. *
  485. * @param string $orderby field to order.
  486. * @param string $order direction (ASC or DESC).
  487. * @return int slider ID.
  488. */
  489. private function find_slider( $orderby, $order ) {
  490. $args = array(
  491. 'force_no_custom_order' => true,
  492. 'post_type' => 'ml-slider',
  493. 'num_posts' => 1,
  494. 'post_status' => 'publish',
  495. 'suppress_filters' => 1, // wpml, ignore language filter
  496. 'orderby' => $orderby,
  497. 'order' => $order
  498. );
  499. $the_query = new WP_Query( $args );
  500. while ( $the_query->have_posts() ) {
  501. $the_query->the_post();
  502. return $the_query->post->ID;
  503. }
  504. wp_reset_query();
  505. return false;
  506. }
  507. /**
  508. * Get sliders. Returns a nicely formatted array of currently
  509. * published sliders.
  510. *
  511. * @param string $sort_key
  512. * @return array all published sliders
  513. */
  514. private function all_meta_sliders( $sort_key = 'date' ) {
  515. $sliders = false;
  516. // list the tabs
  517. $args = array(
  518. 'post_type' => 'ml-slider',
  519. 'post_status' => 'publish',
  520. 'orderby' => $sort_key,
  521. 'suppress_filters' => 1, // wpml, ignore language filter
  522. 'order' => 'ASC',
  523. 'posts_per_page' => -1
  524. );
  525. $args = apply_filters( 'metaslider_all_meta_sliders_args', $args );
  526. $the_query = new WP_Query( $args );
  527. while ( $the_query->have_posts() ) {
  528. $the_query->the_post();
  529. $active = $this->slider && ( $this->slider->id == $the_query->post->ID ) ? true : false;
  530. $sliders[] = array(
  531. 'active' => $active,
  532. 'title' => get_the_title(),
  533. 'id' => $the_query->post->ID
  534. );
  535. }
  536. wp_reset_query();
  537. return $sliders;
  538. }
  539. /**
  540. * Compare array values
  541. *
  542. * @param array $elem1
  543. * @param array $elem2
  544. * @return bool
  545. */
  546. private function compare_elems( $elem1, $elem2 ) {
  547. return $elem1['priority'] > $elem2['priority'];
  548. }
  549. /**
  550. *
  551. * @param array $aFields - array of field to render
  552. * @return string
  553. */
  554. public function build_settings_rows( $aFields ) {
  555. // order the fields by priority
  556. uasort( $aFields, array( $this, "compare_elems" ) );
  557. $return = "";
  558. // loop through the array and build the settings HTML
  559. foreach ( $aFields as $id => $row ) {
  560. // checkbox input type
  561. if ( $row['type'] == 'checkbox' ) {
  562. $return .= "<tr><td class='tipsy-tooltip' title=\"{$row['helptext']}\">{$row['label']}</td><td><input class='option {$row['class']} {$id}' type='checkbox' name='settings[{$id}]' {$row['checked']} />";
  563. if ( isset( $row['after'] ) ) {
  564. $return .= "<span class='after'>{$row['after']}</span>";
  565. }
  566. $return .= "</td></tr>";
  567. }
  568. // navigation row
  569. if ( $row['type'] == 'navigation' ) {
  570. $navigation_row = "<tr class='{$row['type']}'><td class='tipsy-tooltip' title=\"{$row['helptext']}\">{$row['label']}</td><td><ul>";
  571. foreach ( $row['options'] as $k => $v ) {
  572. if ( $row['value'] === true && $k === 'true' ) {
  573. $checked = checked( true, true, false );
  574. } else if ( $row['value'] === false && $k === 'false' ) {
  575. $checked = checked( true, true, false );
  576. } else {
  577. $checked = checked( $k, $row['value'], false );
  578. }
  579. $disabled = $k == 'thumbnails' ? 'disabled' : '';
  580. $navigation_row .= "<li><label><input type='radio' name='settings[{$id}]' value='{$k}' {$checked} {$disabled}/>{$v['label']}</label></li>";
  581. }
  582. $navigation_row .= "</ul></td></tr>";
  583. $return .= apply_filters( 'metaslider_navigation_options', $navigation_row, $this->slider );
  584. }
  585. // navigation row
  586. if ( $row['type'] == 'radio' ) {
  587. $navigation_row = "<tr class='{$row['type']}'><td class='tipsy-tooltip' title=\"{$row['helptext']}\">{$row['label']}</td><td><ul>";
  588. foreach ( $row['options'] as $k => $v ) {
  589. $checked = checked( $k, $row['value'], false );
  590. $class = isset( $v['class'] ) ? $v['class'] : "";
  591. $navigation_row .= "<li><label><input type='radio' name='settings[{$id}]' value='{$k}' {$checked} class='radio {$class}'/>{$v['label']}</label></li>";
  592. }
  593. $navigation_row .= "</ul></td></tr>";
  594. $return .= apply_filters( 'metaslider_navigation_options', $navigation_row, $this->slider );
  595. }
  596. // header/divider row
  597. if ( $row['type'] == 'divider' ) {
  598. $return .= "<tr class='{$row['type']}'><td colspan='2' class='divider'><b>{$row['value']}</b></td></tr>";
  599. }
  600. // slideshow select row
  601. if ( $row['type'] == 'slider-lib' ) {
  602. $return .= "<tr class='{$row['type']}'><td colspan='2' class='slider-lib-row'>";
  603. foreach ( $row['options'] as $k => $v ) {
  604. $checked = checked( $k, $row['value'], false );
  605. $return .= "<input class='select-slider' id='{$k}' rel='{$k}' type='radio' name='settings[type]' value='{$k}' {$checked} />
  606. <label for='{$k}'>{$v['label']}</label>";
  607. }
  608. $return .= "</td></tr>";
  609. }
  610. // number input type
  611. if ( $row['type'] == 'number' ) {
  612. $return .= "<tr class='{$row['type']}'><td class='tipsy-tooltip' title=\"{$row['helptext']}\">{$row['label']}</td><td><input class='option {$row['class']} {$id}' type='number' min='{$row['min']}' max='{$row['max']}' step='{$row['step']}' name='settings[{$id}]' value='{$row['value']}' /><span class='after'>{$row['after']}</span></td></tr>";
  613. }
  614. // select drop down
  615. if ( $row['type'] == 'select' ) {
  616. $return .= "<tr class='{$row['type']}'><td class='tipsy-tooltip' title=\"{$row['helptext']}\">{$row['label']}</td><td><select class='option {$row['class']} {$id}' name='settings[{$id}]'>";
  617. foreach ( $row['options'] as $k => $v ) {
  618. $selected = selected( $k, $row['value'], false );
  619. $return .= "<option class='{$v['class']}' value='{$k}' {$selected}>{$v['label']}</option>";
  620. }
  621. $return .= "</select></td></tr>";
  622. }
  623. // theme drop down
  624. if ( $row['type'] == 'theme' ) {
  625. $return .= "<tr class='{$row['type']}'><td class='tipsy-tooltip' title=\"{$row['helptext']}\">{$row['label']}</td><td><select class='option {$row['class']} {$id}' name='settings[{$id}]'>";
  626. $themes = "";
  627. foreach ( $row['options'] as $k => $v ) {
  628. $selected = selected( $k, $row['value'], false );
  629. $themes .= "<option class='{$v['class']}' value='{$k}' {$selected}>{$v['label']}</option>";
  630. }
  631. $return .= apply_filters( 'metaslider_get_available_themes', $themes, $this->slider->get_setting( 'theme' ) );
  632. $return .= "</select></td></tr>";
  633. }
  634. // text input type
  635. if ( $row['type'] == 'text' ) {
  636. $return .= "<tr class='{$row['type']}'><td class='tipsy-tooltip' title=\"{$row['helptext']}\">{$row['label']}</td><td><input class='option {$row['class']} {$id}' type='text' name='settings[{$id}]' value='{$row['value']}' /></td></tr>";
  637. }
  638. // text input type
  639. if ( $row['type'] == 'textarea' ) {
  640. $return .= "<tr class='{$row['type']}'><td class='tipsy-tooltip' title=\"{$row['helptext']}\" colspan='2'>{$row['label']}</td></tr><tr><td colspan='2'><textarea class='option {$row['class']} {$id}' name='settings[{$id}]' />{$row['value']}</textarea></td></tr>";
  641. }
  642. // text input type
  643. if ( $row['type'] == 'title' ) {
  644. $return .= "<tr class='{$row['type']}'><td class='tipsy-tooltip' title=\"{$row['helptext']}\">{$row['label']}</td><td><input class='option {$row['class']} {$id}' type='text' name='{$id}' value='{$row['value']}' /></td></tr>";
  645. }
  646. }
  647. return $return;
  648. }
  649. /**
  650. * Return an indexed array of all easing options
  651. *
  652. * @return array
  653. */
  654. private function get_easing_options() {
  655. $options = array(
  656. 'linear', 'swing', 'jswing', 'easeInQuad', 'easeOutQuad', 'easeInOutQuad',
  657. 'easeInCubic', 'easeOutCubic', 'easeInOutCubic', 'easeInQuart',
  658. 'easeOutQuart', 'easeInOutQuart', 'easeInQuint', 'easeOutQuint',
  659. 'easeInOutQuint', 'easeInSine', 'easeOutSine', 'easeInOutSine',
  660. 'easeInExpo', 'easeOutExpo', 'easeInOutExpo', 'easeInCirc', 'easeOutCirc',
  661. 'easeInOutCirc', 'easeInElastic', 'easeOutElastic', 'easeInOutElastic',
  662. 'easeInBack', 'easeOutBack', 'easeInOutBack', 'easeInBounce', 'easeOutBounce',
  663. 'easeInOutBounce'
  664. );
  665. foreach ( $options as $option ) {
  666. $return[$option] = array(
  667. 'label' => ucfirst( preg_replace( '/(\w+)([A-Z])/U', '\\1 \\2', $option ) ),
  668. 'class' => ''
  669. );
  670. }
  671. return $return;
  672. }
  673. /**
  674. * Output the slideshow selector.
  675. *
  676. * Show tabs or a dropdown list depending on the users saved preference.
  677. */
  678. public function print_slideshow_selector() {
  679. global $user_ID;
  680. $add_url = wp_nonce_url( "?page=metaslider&amp;add=true", "metaslider_add_slider" );
  681. if ( $tabs = $this->all_meta_sliders() ) {
  682. if ( $this->get_view() == 'tabs' ) {
  683. echo "<div style='display: none;' id='screen-options-switch-view-wrap'><a class='switchview dashicons-before dashicons-welcome-view-site' href='?page=metaslider&amp;view=dropdown'>" . __("Switch to Dropdown view", "metaslider") . "</a></div>";
  684. echo "<h3 class='nav-tab-wrapper'>";
  685. foreach ( $tabs as $tab ) {
  686. if ( $tab['active'] ) {
  687. echo "<div class='nav-tab nav-tab-active'><input type='text' name='title' value='" . $tab['title'] . "' onfocus='this.style.width = ((this.value.length + 1) * 9) + \"px\"' /></div>";
  688. } else {
  689. echo "<a href='?page=metaslider&amp;id={$tab['id']}' class='nav-tab'>" . $tab['title'] . "</a>";
  690. }
  691. }
  692. echo "<a href='{$add_url}' id='create_new_tab' class='nav-tab'>+</a>";
  693. echo "</h3>";
  694. } else {
  695. if ( isset( $_GET['add'] ) && $_GET['add'] == 'true' ) {
  696. echo "<div id='message' class='updated'><p>" . __( "New slideshow created. Click 'Add Slide' to get started!", "metaslider" ) . "</p></div>";
  697. }
  698. echo "<div style='display: none;' id='screen-options-switch-view-wrap'><a class='switchview dashicons-before dashicons-welcome-view-site' href='?page=metaslider&amp;view=tabs'>" . __("Switch to Tab view", "metaslider") . "</a></div>";
  699. echo "<div class='dropdown_container'><label for='select-slider'>" . __("Select Slider", "metaslider") . ": </label>";
  700. echo "<select name='select-slider' onchange='if (this.value) window.location.href=this.value'>";
  701. $tabs = $this->all_meta_sliders( 'title' );
  702. foreach ( $tabs as $tab ) {
  703. $selected = $tab['active'] ? " selected" : "";
  704. if ( $tab['active'] ) {
  705. $title = $tab['title'];
  706. }
  707. echo "<option value='?page=metaslider&amp;id={$tab['id']}'{$selected}>{$tab['title']}</option>";
  708. }
  709. echo "</select> " . __( 'or', "metaslider" ) . " ";
  710. echo "<a href='{$add_url}'>" . __( 'Add New Slideshow', "metaslider" ) . "</a></div>";
  711. }
  712. } else {
  713. echo "<h3 class='nav-tab-wrapper'>";
  714. echo "<a href='{$add_url}' id='create_new_tab' class='nav-tab'>+</a>";
  715. echo "<div class='bubble'>" . __( "Create your first slideshow", "metaslider" ) . "</div>";
  716. echo "</h3>";
  717. }
  718. }
  719. /**
  720. * Return the users saved view preference.
  721. */
  722. public function get_view() {
  723. global $user_ID;
  724. if ( get_user_meta( $user_ID, "metaslider_view", true ) ) {
  725. return get_user_meta( $user_ID, "metaslider_view", true );
  726. }
  727. return 'tabs';
  728. }
  729. /**
  730. * Render the admin page (tabs, slides, settings)
  731. */
  732. public function render_admin_page() {
  733. $this->admin_process();
  734. $this->upgrade_to_pro_cta();
  735. $this->do_system_check();
  736. $slider_id = $this->slider ? $this->slider->id : 0;
  737. ?>
  738. <script type='text/javascript'>
  739. var metaslider_slider_id = <?php echo $slider_id; ?>;
  740. var metaslider_pro_active = <?php echo function_exists( 'is_plugin_active' ) && is_plugin_active( 'ml-slider-pro/ml-slider-pro.php' ) ? 'true' : 'false' ?>;
  741. </script>
  742. <div class="wrap metaslider">
  743. <form accept-charset="UTF-8" action="?page=metaslider&amp;id=<?php echo $slider_id ?>" method="post">
  744. <?php
  745. if ( $this->slider ) {
  746. wp_nonce_field( 'metaslider_save_' . $this->slider->id );
  747. }
  748. $this->print_slideshow_selector();
  749. if ( ! $this->slider ) {
  750. return;
  751. }
  752. ?>
  753. <div id='poststuff'>
  754. <div id='post-body' class='metabox-holder columns-2'>
  755. <div id='post-body-content'>
  756. <div class="left">
  757. <table class="widefat sortable">
  758. <thead>
  759. <tr>
  760. <th style="width: 100px;">
  761. <h3><?php _e( "Slides", "metaslider" ) ?></h3>
  762. </th>
  763. <th>
  764. <a href='#' class='button alignright add-slide' data-editor='content' title='<?php _e( "Add Slide", "metaslider" ) ?>'>
  765. <span class='wp-media-buttons-icon'></span> <?php _e( "Add Slide", "metaslider" ) ?>
  766. </a>
  767. </th>
  768. </tr>
  769. </thead>
  770. <tbody>
  771. <?php
  772. $this->slider->render_admin_slides();
  773. ?>
  774. </tbody>
  775. </table>
  776. </div>
  777. </div>
  778. <div id="postbox-container-1" class="postbox-container">
  779. <div id="side-sortables" class="meta-box-sortables">
  780. <div class='right'>
  781. <div class="ms-postbox" id="metaslider_configuration">
  782. <h3 class='configuration'>
  783. <?php _e( "Settings", "metaslider" ) ?>
  784. <input class='alignright button button-primary' type='submit' name='save' id='ms-save' value='<?php _e( "Save", "metaslider" ) ?>' />
  785. <input class='alignright button button-primary' type='submit' name='preview' id='ms-preview' value='<?php _e( "Save & Preview", "metaslider" ) ?>' data-slider_id='<?php echo $this->slider->id ?>' data-slider_width='<?php echo $this->slider->get_setting( 'width' ) ?>' data-slider_height='<?php echo $this->slider->get_setting( 'height' ) ?>' />
  786. <span class="spinner"></span>
  787. </h3>
  788. <div class="inside">
  789. <table class="widefat settings">
  790. <tbody>
  791. <?php
  792. $aFields = array(
  793. 'type' => array(
  794. 'priority' => 0,
  795. 'type' => 'slider-lib',
  796. 'value' => $this->slider->get_setting( 'type' ),
  797. 'options' => array(
  798. 'flex' => array( 'label' => __( "Flex Slider", "metaslider" ) ),
  799. 'responsive' => array( 'label' => __( "R. Slides", "metaslider" ) ),
  800. 'nivo' => array( 'label' => __( "Nivo Slider", "metaslider" ) ),
  801. 'coin' => array( 'label' => __( "Coin Slider", "metaslider" ) )
  802. )
  803. ),
  804. 'width' => array(
  805. 'priority' => 10,
  806. 'type' => 'number',
  807. 'size' => 3,
  808. 'min' => 0,
  809. 'max' => 9999,
  810. 'step' => 1,
  811. 'value' => $this->slider->get_setting( 'width' ),
  812. 'label' => __( "Width", "metaslider" ),
  813. 'class' => 'coin flex responsive nivo',
  814. 'helptext' => __( "Slideshow width", "metaslider" ),
  815. 'after' => __( "px", "metaslider" )
  816. ),
  817. 'height' => array(
  818. 'priority' => 20,
  819. 'type' => 'number',
  820. 'size' => 3,
  821. 'min' => 0,
  822. 'max' => 9999,
  823. 'step' => 1,
  824. 'value' => $this->slider->get_setting( 'height' ),
  825. 'label' => __( "Height", "metaslider" ),
  826. 'class' => 'coin flex responsive nivo',
  827. 'helptext' => __( "Slideshow height", "metaslider" ),
  828. 'after' => __( "px", "metaslider" )
  829. ),
  830. 'effect' => array(
  831. 'priority' => 30,
  832. 'type' => 'select',
  833. 'value' => $this->slider->get_setting( 'effect' ),
  834. 'label' => __( "Effect", "metaslider" ),
  835. 'class' => 'effect coin flex responsive nivo',
  836. 'helptext' => __( "Slide transition effect", "metaslider" ),
  837. 'options' => array(
  838. 'random' => array( 'class' => 'option coin nivo' , 'label' => __( "Random", "metaslider" ) ),
  839. 'swirl' => array( 'class' => 'option coin', 'label' => __( "Swirl", "metaslider" ) ),
  840. 'rain' => array( 'class' => 'option coin', 'label' => __( "Rain", "metaslider" ) ),
  841. 'straight' => array( 'class' => 'option coin', 'label' => __( "Straight", "metaslider" ) ),
  842. 'sliceDown' => array( 'class' => 'option nivo', 'label' => __( "Slide Down", "metaslider" ) ),
  843. 'sliceUp' => array( 'class' => 'option nivo', 'label' => __( "Slice Up", "metaslider" ) ),
  844. 'sliceUpLeft' => array( 'class' => 'option nivo', 'label' => __( "Slide Up Left", "metaslider" ) ),
  845. 'sliceUpDown' => array( 'class' => 'option nivo', 'label' => __( "Slice Up Down", "metaslider" ) ),
  846. 'slideUpDownLeft' => array( 'class' => 'option nivo', 'label' => __( "Slide Up Down Left", "metaslider" ) ),
  847. 'fold' => array( 'class' => 'option nivo', 'label' => __( "Fold", "metaslider" ) ),
  848. 'fade' => array( 'class' => 'option nivo flex responsive', 'label' => __( "Fade", "metaslider" ) ),
  849. 'slideInRight' => array( 'class' => 'option nivo', 'label' => __( "Slide In Right", "metaslider" ) ),
  850. 'slideInLeft' => array( 'class' => 'option nivo', 'label' => __( "Slide In Left", "metaslider" ) ),
  851. 'boxRandom' => array( 'class' => 'option nivo', 'label' => __( "Box Random", "metaslider" ) ),
  852. 'boxRain' => array( 'class' => 'option nivo', 'label' => __( "Box Rain", "metaslider" ) ),
  853. 'boxRainReverse' => array( 'class' => 'option nivo', 'label' => __( "Box Rain Reverse", "metaslider" ) ),
  854. 'boxRainGrowReverse' => array( 'class' => 'option nivo', 'label' => __( "Box Rain Grow Reverse", "metaslider" ) ),
  855. 'slide' => array( 'class' => 'option flex', 'label' => __( "Slide", "metaslider" ) )
  856. ),
  857. ),
  858. 'theme' => array(
  859. 'priority' => 40,
  860. 'type' => 'theme',
  861. 'value' => $this->slider->get_setting( 'theme' ),
  862. 'label' => __( "Theme", "metaslider" ),
  863. 'class' => 'effect coin flex responsive nivo',
  864. 'helptext' => __( "Slideshow theme", "metaslider" ),
  865. 'options' => array(
  866. 'default' => array( 'class' => 'option nivo flex coin responsive' , 'label' => __( "Default", "metaslider" ) ),
  867. 'dark' => array( 'class' => 'option nivo', 'label' => __( "Dark (Nivo)", "metaslider" ) ),
  868. 'light' => array( 'class' => 'option nivo', 'label' => __( "Light (Nivo)", "metaslider" ) ),
  869. 'bar' => array( 'class' => 'option nivo', 'label' => __( "Bar (Nivo)", "metaslider" ) ),
  870. ),
  871. ),
  872. 'links' => array(
  873. 'priority' => 50,
  874. 'type' => 'checkbox',
  875. 'label' => __( "Arrows", "metaslider" ),
  876. 'class' => 'option coin flex nivo responsive',
  877. 'checked' => $this->slider->get_setting( 'links' ) == 'true' ? 'checked' : '',
  878. 'helptext' => __( "Show the previous/next arrows", "metaslider" )
  879. ),
  880. 'navigation' => array(
  881. 'priority' => 60,
  882. 'type' => 'navigation',
  883. 'label' => __( "Navigation", "metaslider" ),
  884. 'class' => 'option coin flex nivo responsive',
  885. 'value' => $this->slider->get_setting( 'navigation' ),
  886. 'helptext' => __( "Show the slide navigation bullets", "metaslider" ),
  887. 'options' => array(
  888. 'false' => array( 'label' => __( "Hidden", "metaslider" ) ),
  889. 'true' => array( 'label' => __( "Dots", "metaslider" ) ),
  890. )
  891. ),
  892. );
  893. if ( $this->get_view() == 'dropdown' ) {
  894. $aFields['title'] = array(
  895. 'type' => 'title',
  896. 'priority' => 5,
  897. 'class' => 'option flex nivo responsive coin',
  898. 'value' => get_the_title($this->slider->id),
  899. 'label' => __( "Title", "metaslider" ),
  900. 'helptext' => __( "Slideshow title", "metaslider" )
  901. );
  902. }
  903. $aFields = apply_filters( 'metaslider_basic_settings', $aFields, $this->slider );
  904. echo $this->build_settings_rows( $aFields );
  905. ?>
  906. </tbody>
  907. </table>
  908. </div>
  909. </div>
  910. <div class="ms-postbox ms-toggle closed" id="metaslider_advanced_settings">
  911. <div class="handlediv" title="Click to toggle"><br></div><h3 class="hndle"><span><?php _e( "Advanced Settings", "metaslider" ) ?></span></h3>
  912. <div class="inside">
  913. <table>
  914. <tbody>
  915. <?php
  916. $aFields = array(

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