PageRenderTime 68ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

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

https://gitlab.com/haque.mdmanzurul/barongbarong
PHP | 1251 lines | 872 code | 226 blank | 153 comment | 65 complexity | a467c71215b38cc5f0def3fc49b259f7 MD5 | raw 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: 3.1.1
  9. * Author: Matcha Labs
  10. * Author URI: http://www.metaslider.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 = '3.1.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( 'widgets_init', array( $this, 'register_metaslider_widget' ) );
  126. add_action( 'admin_post_metaslider_preview', array( $this, 'do_preview' ) );
  127. add_action( 'admin_post_metaslider_hide_go_pro_page', array( $this, 'hide_go_pro_page' ) );
  128. add_action( 'admin_post_metaslider_switch_view', array( $this, 'switch_view' ) );
  129. if ( defined( 'METASLIDER_ENABLE_RESOURCE_MANAGER' ) && METASLIDER_ENABLE_RESOURCE_MANAGER === true ) {
  130. add_action( 'template_redirect', array( $this, 'start_resource_manager'), 0 );
  131. }
  132. }
  133. /**
  134. * Hook Meta Slider into WordPress
  135. */
  136. private function setup_filters() {
  137. add_filter( 'media_upload_tabs', array( $this, 'custom_media_upload_tab_name' ), 998 );
  138. add_filter( 'media_view_strings', array( $this, 'custom_media_uploader_tabs' ), 5 );
  139. add_filter( 'media_buttons_context', array( $this, 'insert_metaslider_button' ) );
  140. // add 'go pro' link to plugin options
  141. $plugin = plugin_basename( __FILE__ );
  142. add_filter( "plugin_action_links_{$plugin}", array( $this, 'upgrade_to_pro_link' ) );
  143. }
  144. /**
  145. * Register Meta Slider widget
  146. */
  147. public function register_metaslider_widget() {
  148. register_widget( 'MetaSlider_Widget' );
  149. }
  150. /**
  151. * Register ML Slider post type
  152. */
  153. public function register_post_type() {
  154. register_post_type( 'ml-slider', array(
  155. 'query_var' => false,
  156. 'rewrite' => false,
  157. 'public' => true,
  158. 'exclude_from_search' => true,
  159. 'publicly_queryable' => false,
  160. 'show_in_nav_menus' => false,
  161. 'show_ui' => false,
  162. 'labels' => array(
  163. 'name' => 'Meta Slider'
  164. )
  165. )
  166. );
  167. }
  168. /**
  169. * Register taxonomy to store slider => slides relationship
  170. */
  171. public function register_taxonomy() {
  172. register_taxonomy( 'ml-slider', 'attachment', array(
  173. 'hierarchical' => true,
  174. 'public' => false,
  175. 'query_var' => false,
  176. 'rewrite' => false
  177. )
  178. );
  179. }
  180. /**
  181. * Register our slide types
  182. */
  183. private function register_slide_types() {
  184. $image = new MetaImageSlide();
  185. }
  186. /**
  187. * Add the menu page
  188. */
  189. public function register_admin_menu() {
  190. global $user_ID;
  191. $title = apply_filters( 'metaslider_menu_title', 'Meta Slider' );
  192. $capability = apply_filters( 'metaslider_capability', 'edit_others_posts' );
  193. $page = add_menu_page( $title, $title, $capability, '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. if ( ! is_plugin_active( 'ml-slider-pro/ml-slider-pro.php' ) && get_user_meta( $user_ID, "metaslider_hide_go_pro", true ) !== 'true' ) {
  201. $page = add_submenu_page(
  202. 'metaslider',
  203. __( 'Go Pro!', 'metaslider' ),
  204. __( 'Go Pro!', 'metaslider' ),
  205. $capability,
  206. 'metaslider-go-pro',
  207. array( $this, 'go_pro_page' )
  208. );
  209. add_action( 'admin_print_styles-' . $page, array( $this, 'register_admin_styles' ) );
  210. }
  211. }
  212. /**
  213. * Go Pro page content
  214. */
  215. public function go_pro_page() {
  216. $hide_link = '<a href="' . admin_url( "admin-post.php?action=metaslider_hide_go_pro_page" ) . '">Hide this page</a>';
  217. $link = apply_filters( 'metaslider_hoplink', 'http://www.metaslider.com/upgrade/' );
  218. $link .= '?utm_source=lite&amp;utm_medium=nag&amp;utm_campaign=pro';
  219. $gopro_link = "<a class='button button-primary' href='{$link}'>Find out more</a>";
  220. $support_link = '<a href="https://wordpress.org/support/plugin/ml-slider">Support</a>';
  221. $documentation_link = '<a href="http://www.metaslider.com/documentation/">Documentation</a>';
  222. ?>
  223. <h2>Supercharge Your Sliders with Meta Slider Pro!</h2>
  224. <ul class='metaslider_gopro'>
  225. <li>Create <b>animated HTML slides</b> using the drag &amp; drop layer editor (WYSIWYG)</li>
  226. <li>Insert <b>YouTube</b> and <b>Vimeo</b> videos into your slideshows</li>
  227. <li>Automatically populate your slideshows with your <b>latest blog posts</b> or custom post types</li>
  228. <li>Customize the look of your slideshows with the <b>Theme Editor</b> (25+ settings including custom arrow images, dot colors and caption styling)</li>
  229. <li>Give your slideshows a gallery feel with <b>thumbnail navigation</b></li>
  230. <li>Feature <b>WooCommerce</b> products in your slideshows</li>
  231. <li>Show your latest events from <b>The Events Calendar</b> plugin</li>
  232. <li><b>Easy to install</B> - Meta Slider Pro installs as a seperate plugin alongside Meta Slider and seamlessly adds in the new functionality</li>
  233. <li><b>Easy to update</b> - new updates will be displayed on your plugins page (just like your other plugins!)</li>
  234. <li>Upgrade with confidence with our <b>30 day no questions money back guarantee</b></li>
  235. <li>Meta Slider Pro users receive <b>priority support</b> from our dedicated team, were on hand to help you get the most of Meta Slider</li>
  236. </ul>
  237. <p><?php echo $gopro_link; ?></p>
  238. <p><?php echo $support_link; ?> <?php echo $documentation_link; ?></p>
  239. <p><em>Don't want to see this? <?php echo $hide_link; ?></em></p>
  240. <?php
  241. }
  242. /**
  243. * Store the users preference to hide the go pro page.
  244. */
  245. public function hide_go_pro_page() {
  246. global $user_ID;
  247. if ( ! get_user_meta( $user_ID, "metaslider_hide_go_pro" ) ) {
  248. add_user_meta( $user_ID, "metaslider_hide_go_pro", "true" );
  249. }
  250. wp_redirect( admin_url( "admin.php?page=metaslider" ) );
  251. }
  252. /**
  253. * Shortcode used to display slideshow
  254. *
  255. * @return string HTML output of the shortcode
  256. */
  257. public function register_shortcode( $atts ) {
  258. extract( shortcode_atts( array(
  259. 'id' => false,
  260. 'restrict_to' => false
  261. ), $atts, 'metaslider' ) );
  262. if ( ! $id ) {
  263. return false;
  264. }
  265. // handle [metaslider id=123 restrict_to=home]
  266. if ($restrict_to && $restrict_to == 'home' && ! is_front_page()) {
  267. return;
  268. }
  269. if ($restrict_to && $restrict_to != 'home' && ! is_page( $restrict_to ) ) {
  270. return;
  271. }
  272. // we have an ID to work with
  273. $slider = get_post( $id );
  274. // check the slider is published and the ID is correct
  275. if ( ! $slider || $slider->post_status != 'publish' || $slider->post_type != 'ml-slider' ) {
  276. return "<!-- meta slider {$atts['id']} not found -->";
  277. }
  278. // lets go
  279. $this->set_slider( $id, $atts );
  280. $this->slider->enqueue_scripts();
  281. return $this->slider->render_public_slides();
  282. }
  283. /**
  284. * Initialise translations
  285. */
  286. public function load_plugin_textdomain() {
  287. load_plugin_textdomain( 'metaslider', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
  288. }
  289. /**
  290. * Add the help tab to the screen.
  291. */
  292. public function help_tab() {
  293. $screen = get_current_screen();
  294. // documentation tab
  295. $screen->add_help_tab( array(
  296. 'id' => 'documentation',
  297. 'title' => __( 'Documentation', 'metaslider' ),
  298. 'content' => "<p><a href='http://www.metaslider.com/documentation/' target='blank'>Meta Slider Documentation</a></p>",
  299. )
  300. );
  301. }
  302. /**
  303. * Rehister admin styles
  304. */
  305. public function register_admin_styles() {
  306. wp_enqueue_style( 'metaslider-admin-styles', METASLIDER_ASSETS_URL . 'metaslider/admin.css', false, METASLIDER_VERSION );
  307. wp_enqueue_style( 'metaslider-colorbox-styles', METASLIDER_ASSETS_URL . 'colorbox/colorbox.css', false, METASLIDER_VERSION );
  308. wp_enqueue_style( 'metaslider-tipsy-styles', METASLIDER_ASSETS_URL . 'tipsy/tipsy.css', false, METASLIDER_VERSION );
  309. do_action( 'metaslider_register_admin_styles' );
  310. }
  311. /**
  312. * Register admin JavaScript
  313. */
  314. public function register_admin_scripts() {
  315. // media library dependencies
  316. wp_enqueue_media();
  317. // plugin dependencies
  318. wp_enqueue_script( 'jquery-ui-core', array( 'jquery' ) );
  319. wp_enqueue_script( 'jquery-ui-sortable', array( 'jquery', 'jquery-ui-core' ) );
  320. wp_enqueue_script( 'metaslider-colorbox', METASLIDER_ASSETS_URL . 'colorbox/jquery.colorbox-min.js', array( 'jquery' ), METASLIDER_VERSION );
  321. wp_enqueue_script( 'metaslider-tipsy', METASLIDER_ASSETS_URL . 'tipsy/jquery.tipsy.js', array( 'jquery' ), METASLIDER_VERSION );
  322. wp_enqueue_script( 'metaslider-admin-script', METASLIDER_ASSETS_URL . 'metaslider/admin.js', array( 'jquery', 'metaslider-tipsy', 'media-upload' ), METASLIDER_VERSION );
  323. wp_dequeue_script( 'link' ); // WP Posts Filter Fix (Advanced Settings not toggling)
  324. wp_dequeue_script( 'ai1ec_requirejs' ); // All In One Events Calendar Fix (Advanced Settings not toggling)
  325. $this->localize_admin_scripts();
  326. do_action( 'metaslider_register_admin_scripts' );
  327. }
  328. /**
  329. * Localise admin script
  330. */
  331. public function localize_admin_scripts() {
  332. wp_localize_script( 'metaslider-admin-script', 'metaslider', array(
  333. 'url' => __( "URL", "metaslider" ),
  334. 'caption' => __( "Caption", "metaslider" ),
  335. 'new_window' => __( "New Window", "metaslider" ),
  336. 'confirm' => __( "Are you sure?", "metaslider" ),
  337. 'ajaxurl' => admin_url( 'admin-ajax.php' ),
  338. 'resize_nonce' => wp_create_nonce( 'metaslider_resize' ),
  339. 'addslide_nonce' => wp_create_nonce( 'metaslider_addslide' ),
  340. 'iframeurl' => admin_url( 'admin-post.php?action=metaslider_preview' ),
  341. 'useWithCaution' => __( "Caution: This setting is for advanced developers only. If you're unsure, leave it checked.", "metaslider" )
  342. )
  343. );
  344. }
  345. /**
  346. * Outputs a blank page containing a slideshow preview (for use in the 'Preview' iFrame)
  347. */
  348. public function do_preview() {
  349. remove_action('wp_footer', 'wp_admin_bar_render', 1000);
  350. if ( isset( $_GET['slider_id'] ) && absint( $_GET['slider_id'] ) > 0 ) {
  351. $id = absint( $_GET['slider_id'] );
  352. ?>
  353. <!DOCTYPE html>
  354. <html>
  355. <head>
  356. <style type='text/css'>
  357. body, html {
  358. overflow: hidden;
  359. margin: 0;
  360. padding: 0;
  361. }
  362. </style>
  363. <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
  364. <meta http-equiv="Pragma" content="no-cache" />
  365. <meta http-equiv="Expires" content="0" />
  366. </head>
  367. <body>
  368. <?php echo do_shortcode("[metaslider id={$id}]"); ?>
  369. <?php wp_footer(); ?>
  370. </body>
  371. </html>
  372. <?php
  373. }
  374. die();
  375. }
  376. /**
  377. * Check our WordPress installation is compatible with Meta Slider
  378. */
  379. public function do_system_check() {
  380. $systemCheck = new MetaSliderSystemCheck();
  381. $systemCheck->check();
  382. }
  383. /**
  384. * Update the tab options in the media manager
  385. */
  386. public function custom_media_uploader_tabs( $strings ) {
  387. //update strings
  388. if ( ( isset( $_GET['page'] ) && $_GET['page'] == 'metaslider' ) ) {
  389. $strings['insertMediaTitle'] = __( "Image", "metaslider" );
  390. $strings['insertIntoPost'] = __( "Add to slider", "metaslider" );
  391. // remove options
  392. if ( isset( $strings['createGalleryTitle'] ) ) unset( $strings['createGalleryTitle'] );
  393. if ( isset( $strings['insertFromUrlTitle'] ) ) unset( $strings['insertFromUrlTitle'] );
  394. }
  395. return $strings;
  396. }
  397. /**
  398. * Add extra tabs to the default wordpress Media Manager iframe
  399. *
  400. * @var array existing media manager tabs
  401. */
  402. public function custom_media_upload_tab_name( $tabs ) {
  403. // restrict our tab changes to the meta slider plugin page
  404. if ( isset( $_GET['page'] ) && $_GET['page'] == 'metaslider' ) {
  405. if ( isset( $tabs['nextgen'] ) ) {
  406. unset( $tabs['nextgen'] );
  407. }
  408. }
  409. return $tabs;
  410. }
  411. /**
  412. * Set the current slider
  413. */
  414. public function set_slider( $id, $shortcode_settings = array() ) {
  415. $type = 'flex';
  416. if ( isset( $shortcode_settings['type'] ) ) {
  417. $type = $shortcode_settings['type'];
  418. } else if ( $settings = get_post_meta( $id, 'ml-slider_settings', true ) ) {
  419. if ( is_array( $settings ) && isset( $settings['type'] ) ) {
  420. $type = $settings['type'];
  421. }
  422. }
  423. if ( ! in_array( $type, array( 'flex', 'coin', 'nivo', 'responsive' ) ) ) {
  424. $type = 'flex';
  425. }
  426. $this->slider = $this->create_slider( $type, $id, $shortcode_settings );
  427. }
  428. /**
  429. * Create a new slider based on the sliders type setting
  430. */
  431. private function create_slider( $type, $id, $shortcode_settings ) {
  432. switch ( $type ) {
  433. case( 'coin' ):
  434. return new MetaCoinSlider( $id, $shortcode_settings );
  435. case( 'flex' ):
  436. return new MetaFlexSlider( $id, $shortcode_settings );
  437. case( 'nivo' ):
  438. return new MetaNivoSlider( $id, $shortcode_settings );
  439. case( 'responsive' ):
  440. return new MetaResponsiveSlider( $id, $shortcode_settings );
  441. default:
  442. return new MetaFlexSlider( $id, $shortcode_settings );
  443. }
  444. }
  445. /**
  446. * Handle slide uploads/changes.
  447. */
  448. public function admin_process() {
  449. // this function should only ever be called from the Meta Slider admin page.
  450. if ( ! is_admin() ) {
  451. return;
  452. }
  453. $capability = apply_filters( 'metaslider_capability', 'edit_others_posts' );
  454. if ( ! current_user_can( $capability ) ) {
  455. return;
  456. }
  457. // default to the latest slider
  458. $slider_id = $this->find_slider( 'modified', 'DESC' );
  459. // delete a slider
  460. if ( isset( $_GET['delete'] ) ) {
  461. $slider_id = $this->delete_slider( absint( $_GET['delete'] ) );
  462. }
  463. // load a slider by ID
  464. if ( isset( $_REQUEST['id'] ) ) {
  465. $temp_id = absint( $_REQUEST['id'] );
  466. // check valid post ID
  467. if ( get_post( $temp_id ) ) {
  468. $slider_id = $temp_id;
  469. }
  470. }
  471. // create a new slider
  472. if ( isset( $_GET['add'] ) ) {
  473. $slider_id = $this->add_slider();
  474. }
  475. // finally, set the slider
  476. if ( $slider_id > 0 ) {
  477. $this->set_slider( $slider_id );
  478. }
  479. }
  480. /**
  481. *
  482. */
  483. public function switch_view() {
  484. global $user_ID;
  485. $view = $_GET['view'];
  486. $allowed_views = array('tabs', 'dropdown');
  487. if ( ! in_array( $view, $allowed_views ) ) {
  488. return;
  489. }
  490. delete_user_meta( $user_ID, "metaslider_view" );
  491. if ( $view == 'dropdown' ) {
  492. add_user_meta( $user_ID, "metaslider_view", "dropdown");
  493. }
  494. wp_redirect( admin_url( "admin.php?page=metaslider" ) );
  495. }
  496. /**
  497. * Create a new slider
  498. */
  499. private function add_slider() {
  500. // check nonce
  501. check_admin_referer( "metaslider_add_slider" );
  502. $defaults = array();
  503. // if possible, take a copy of the last edited slider settings in place of default settings
  504. if ( $last_modified = $this->find_slider( 'modified', 'DESC' ) ) {
  505. $defaults = get_post_meta( $last_modified, 'ml-slider_settings', true );
  506. }
  507. // insert the post
  508. $id = wp_insert_post( array(
  509. 'post_title' => __( "New Slider", "metaslider" ),
  510. 'post_status' => 'publish',
  511. 'post_type' => 'ml-slider'
  512. )
  513. );
  514. // use the default settings if we can't find anything more suitable.
  515. if ( empty( $defaults ) ) {
  516. $slider = new MetaSlider( $id, array() );
  517. $defaults = $slider->get_default_parameters();
  518. }
  519. // insert the post meta
  520. add_post_meta( $id, 'ml-slider_settings', $defaults, true );
  521. // create the taxonomy term, the term is the ID of the slider itself
  522. wp_insert_term( $id, 'ml-slider' );
  523. return $id;
  524. }
  525. /**
  526. * Delete a slider (send it to trash)
  527. *
  528. * @param int $id
  529. */
  530. private function delete_slider( $id ) {
  531. // check nonce
  532. check_admin_referer( "metaslider_delete_slider" );
  533. // send the post to trash
  534. wp_update_post( array(
  535. 'ID' => $id,
  536. 'post_status' => 'trash'
  537. )
  538. );
  539. return $this->find_slider( 'date', 'DESC' );
  540. }
  541. /**
  542. * Find a single slider ID. For example, last edited, or first published.
  543. *
  544. * @param string $orderby field to order.
  545. * @param string $order direction (ASC or DESC).
  546. * @return int slider ID.
  547. */
  548. private function find_slider( $orderby, $order ) {
  549. $args = array(
  550. 'force_no_custom_order' => true,
  551. 'post_type' => 'ml-slider',
  552. 'num_posts' => 1,
  553. 'post_status' => 'publish',
  554. 'suppress_filters' => 1, // wpml, ignore language filter
  555. 'orderby' => $orderby,
  556. 'order' => $order
  557. );
  558. $the_query = new WP_Query( $args );
  559. while ( $the_query->have_posts() ) {
  560. $the_query->the_post();
  561. return $the_query->post->ID;
  562. }
  563. wp_reset_query();
  564. return false;
  565. }
  566. /**
  567. * Get sliders. Returns a nicely formatted array of currently
  568. * published sliders.
  569. *
  570. * @param string $sort_key
  571. * @return array all published sliders
  572. */
  573. private function all_meta_sliders( $sort_key = 'date' ) {
  574. $sliders = false;
  575. // list the tabs
  576. $args = array(
  577. 'post_type' => 'ml-slider',
  578. 'post_status' => 'publish',
  579. 'orderby' => $sort_key,
  580. 'suppress_filters' => 1, // wpml, ignore language filter
  581. 'order' => 'ASC',
  582. 'posts_per_page' => -1
  583. );
  584. $args = apply_filters( 'metaslider_all_meta_sliders_args', $args );
  585. // WP_Query causes issues with other plugins using admin_footer to insert scripts
  586. // use get_posts instead
  587. $all_sliders = get_posts( $args );
  588. foreach( $all_sliders as $slideshow ) {
  589. $active = $this->slider && ( $this->slider->id == $slideshow->ID ) ? true : false;
  590. $sliders[] = array(
  591. 'active' => $active,
  592. 'title' => $slideshow->post_title,
  593. 'id' => $slideshow->ID
  594. );
  595. }
  596. return $sliders;
  597. }
  598. /**
  599. * Compare array values
  600. *
  601. * @param array $elem1
  602. * @param array $elem2
  603. * @return bool
  604. */
  605. private function compare_elems( $elem1, $elem2 ) {
  606. return $elem1['priority'] > $elem2['priority'];
  607. }
  608. /**
  609. *
  610. * @param array $aFields - array of field to render
  611. * @return string
  612. */
  613. public function build_settings_rows( $aFields ) {
  614. // order the fields by priority
  615. uasort( $aFields, array( $this, "compare_elems" ) );
  616. $return = "";
  617. // loop through the array and build the settings HTML
  618. foreach ( $aFields as $id => $row ) {
  619. // checkbox input type
  620. if ( $row['type'] == 'checkbox' ) {
  621. $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']} />";
  622. if ( isset( $row['after'] ) ) {
  623. $return .= "<span class='after'>{$row['after']}</span>";
  624. }
  625. $return .= "</td></tr>";
  626. }
  627. // navigation row
  628. if ( $row['type'] == 'navigation' ) {
  629. $navigation_row = "<tr class='{$row['type']}'><td class='tipsy-tooltip' title=\"{$row['helptext']}\">{$row['label']}</td><td><ul>";
  630. foreach ( $row['options'] as $k => $v ) {
  631. if ( $row['value'] === true && $k === 'true' ) {
  632. $checked = checked( true, true, false );
  633. } else if ( $row['value'] === false && $k === 'false' ) {
  634. $checked = checked( true, true, false );
  635. } else {
  636. $checked = checked( $k, $row['value'], false );
  637. }
  638. $disabled = $k == 'thumbnails' ? 'disabled' : '';
  639. $navigation_row .= "<li><label><input type='radio' name='settings[{$id}]' value='{$k}' {$checked} {$disabled}/>{$v['label']}</label></li>";
  640. }
  641. $navigation_row .= "</ul></td></tr>";
  642. $return .= apply_filters( 'metaslider_navigation_options', $navigation_row, $this->slider );
  643. }
  644. // navigation row
  645. if ( $row['type'] == 'radio' ) {
  646. $navigation_row = "<tr class='{$row['type']}'><td class='tipsy-tooltip' title=\"{$row['helptext']}\">{$row['label']}</td><td><ul>";
  647. foreach ( $row['options'] as $k => $v ) {
  648. $checked = checked( $k, $row['value'], false );
  649. $class = isset( $v['class'] ) ? $v['class'] : "";
  650. $navigation_row .= "<li><label><input type='radio' name='settings[{$id}]' value='{$k}' {$checked} class='radio {$class}'/>{$v['label']}</label></li>";
  651. }
  652. $navigation_row .= "</ul></td></tr>";
  653. $return .= apply_filters( 'metaslider_navigation_options', $navigation_row, $this->slider );
  654. }
  655. // header/divider row
  656. if ( $row['type'] == 'divider' ) {
  657. $return .= "<tr class='{$row['type']}'><td colspan='2' class='divider'><b>{$row['value']}</b></td></tr>";
  658. }
  659. // slideshow select row
  660. if ( $row['type'] == 'slider-lib' ) {
  661. $return .= "<tr class='{$row['type']}'><td colspan='2' class='slider-lib-row'>";
  662. foreach ( $row['options'] as $k => $v ) {
  663. $checked = checked( $k, $row['value'], false );
  664. $return .= "<input class='select-slider' id='{$k}' rel='{$k}' type='radio' name='settings[type]' value='{$k}' {$checked} />
  665. <label for='{$k}'>{$v['label']}</label>";
  666. }
  667. $return .= "</td></tr>";
  668. }
  669. // number input type
  670. if ( $row['type'] == 'number' ) {
  671. $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='" . absint( $row['value'] ) . "' /><span class='after'>{$row['after']}</span></td></tr>";
  672. }
  673. // select drop down
  674. if ( $row['type'] == 'select' ) {
  675. $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}]'>";
  676. foreach ( $row['options'] as $k => $v ) {
  677. $selected = selected( $k, $row['value'], false );
  678. $return .= "<option class='{$v['class']}' value='{$k}' {$selected}>{$v['label']}</option>";
  679. }
  680. $return .= "</select></td></tr>";
  681. }
  682. // theme drop down
  683. if ( $row['type'] == 'theme' ) {
  684. $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}]'>";
  685. $themes = "";
  686. foreach ( $row['options'] as $k => $v ) {
  687. $selected = selected( $k, $row['value'], false );
  688. $themes .= "<option class='{$v['class']}' value='{$k}' {$selected}>{$v['label']}</option>";
  689. }
  690. $return .= apply_filters( 'metaslider_get_available_themes', $themes, $this->slider->get_setting( 'theme' ) );
  691. $return .= "</select></td></tr>";
  692. }
  693. // text input type
  694. if ( $row['type'] == 'text' ) {
  695. $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='" . esc_attr( $row['value'] ) . "' /></td></tr>";
  696. }
  697. // text input type
  698. if ( $row['type'] == 'textarea' ) {
  699. $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>";
  700. }
  701. // text input type
  702. if ( $row['type'] == 'title' ) {
  703. $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='" . esc_attr( $row['value'] ) . "' /></td></tr>";
  704. }
  705. }
  706. return $return;
  707. }
  708. /**
  709. * Return an indexed array of all easing options
  710. *
  711. * @return array
  712. */
  713. private function get_easing_options() {
  714. $options = array(
  715. 'linear', 'swing', 'jswing', 'easeInQuad', 'easeOutQuad', 'easeInOutQuad',
  716. 'easeInCubic', 'easeOutCubic', 'easeInOutCubic', 'easeInQuart',
  717. 'easeOutQuart', 'easeInOutQuart', 'easeInQuint', 'easeOutQuint',
  718. 'easeInOutQuint', 'easeInSine', 'easeOutSine', 'easeInOutSine',
  719. 'easeInExpo', 'easeOutExpo', 'easeInOutExpo', 'easeInCirc', 'easeOutCirc',
  720. 'easeInOutCirc', 'easeInElastic', 'easeOutElastic', 'easeInOutElastic',
  721. 'easeInBack', 'easeOutBack', 'easeInOutBack', 'easeInBounce', 'easeOutBounce',
  722. 'easeInOutBounce'
  723. );
  724. foreach ( $options as $option ) {
  725. $return[$option] = array(
  726. 'label' => ucfirst( preg_replace( '/(\w+)([A-Z])/U', '\\1 \\2', $option ) ),
  727. 'class' => ''
  728. );
  729. }
  730. return $return;
  731. }
  732. /**
  733. * Output the slideshow selector.
  734. *
  735. * Show tabs or a dropdown list depending on the users saved preference.
  736. */
  737. public function print_slideshow_selector() {
  738. global $user_ID;
  739. $add_url = wp_nonce_url( "?page=metaslider&amp;add=true", "metaslider_add_slider" );
  740. if ( $tabs = $this->all_meta_sliders() ) {
  741. if ( $this->get_view() == 'tabs' ) {
  742. echo "<div style='display: none;' id='screen-options-switch-view-wrap'>
  743. <a class='switchview dashicons-before dashicons-randomize tipsy-tooltip' title='" . __("Switch to Dropdown view", "metaslider") . "' href='" . admin_url( "admin-post.php?action=metaslider_switch_view&view=dropdown") . "'>" . __("Dropdown", "metaslider") . "</a></div>";
  744. echo "<h3 class='nav-tab-wrapper'>";
  745. foreach ( $tabs as $tab ) {
  746. if ( $tab['active'] ) {
  747. echo "<div class='nav-tab nav-tab-active'><input type='text' name='title' value='" . esc_attr( $tab['title'] ) . "' onfocus='this.style.width = ((this.value.length + 1) * 9) + \"px\"' /></div>";
  748. } else {
  749. echo "<a href='?page=metaslider&amp;id={$tab['id']}' class='nav-tab'>" . esc_html( $tab['title'] ) . "</a>";
  750. }
  751. }
  752. echo "<a href='{$add_url}' id='create_new_tab' class='nav-tab'>+</a>";
  753. echo "</h3>";
  754. } else {
  755. if ( isset( $_GET['add'] ) && $_GET['add'] == 'true' ) {
  756. echo "<div id='message' class='updated'><p>" . __( "New slideshow created. Click 'Add Slide' to get started!", "metaslider" ) . "</p></div>";
  757. }
  758. echo "<div style='display: none;' id='screen-options-switch-view-wrap'><a class='switchview dashicons-before dashicons-randomize tipsy-tooltip' title='" . __("Switch to Tab view", "metaslider") . "' href='" . admin_url( "admin-post.php?action=metaslider_switch_view&view=tabs") . "'>" . __("Tabs", "metaslider") . "</a></div>";
  759. echo "<div class='dropdown_container'><label for='select-slider'>" . __("Select Slider", "metaslider") . ": </label>";
  760. echo "<select name='select-slider' onchange='if (this.value) window.location.href=this.value'>";
  761. $tabs = $this->all_meta_sliders( 'title' );
  762. foreach ( $tabs as $tab ) {
  763. $selected = $tab['active'] ? " selected" : "";
  764. if ( $tab['active'] ) {
  765. $title = $tab['title'];
  766. }
  767. echo "<option value='?page=metaslider&amp;id={$tab['id']}'{$selected}>{$tab['title']}</option>";
  768. }
  769. echo "</select> " . __( 'or', "metaslider" ) . " ";
  770. echo "<a href='{$add_url}'>" . __( 'Add New Slideshow', "metaslider" ) . "</a></div>";
  771. }
  772. } else {
  773. echo "<h3 class='nav-tab-wrapper'>";
  774. echo "<a href='{$add_url}' id='create_new_tab' class='nav-tab'>+</a>";
  775. echo "<div class='bubble'>" . __( "Create your first slideshow", "metaslider" ) . "</div>";
  776. echo "</h3>";
  777. }
  778. }
  779. /**
  780. * Return the users saved view preference.
  781. */
  782. public function get_view() {
  783. global $user_ID;
  784. if ( get_user_meta( $user_ID, "metaslider_view", true ) ) {
  785. return get_user_meta( $user_ID, "metaslider_view", true );
  786. }
  787. return 'tabs';
  788. }
  789. /**
  790. * Render the admin page (tabs, slides, settings)
  791. */
  792. public function render_admin_page() {
  793. $this->admin_process();
  794. $this->upgrade_to_pro_cta();
  795. $this->do_system_check();
  796. $slider_id = $this->slider ? $this->slider->id : 0;
  797. ?>
  798. <script type='text/javascript'>
  799. var metaslider_slider_id = <?php echo $slider_id; ?>;
  800. </script>
  801. <div class="wrap metaslider">
  802. <form accept-charset="UTF-8" action="?page=metaslider&amp;id=<?php echo $slider_id ?>" method="post">
  803. <?php
  804. if ( $this->slider ) {
  805. wp_nonce_field( 'metaslider_save_' . $this->slider->id );
  806. }
  807. $this->print_slideshow_selector();
  808. if ( ! $this->slider ) {
  809. return;
  810. }
  811. ?>
  812. <div id='poststuff'>
  813. <div id='post-body' class='metabox-holder columns-2'>
  814. <div id='post-body-content'>
  815. <div class="left">
  816. <?php do_action( "metaslider_admin_table_before", $this->slider->id ); ?>
  817. <table class="widefat sortable">
  818. <thead>
  819. <tr>
  820. <th style="width: 100px;">
  821. <h3><?php _e( "Slides", "metaslider" ) ?></h3>
  822. <?php do_action( "metaslider_admin_table_header_left", $this->slider->id ); ?>
  823. </th>
  824. <th>
  825. <a href='#' class='button alignright add-slide' data-editor='content' title='<?php _e( "Add Slide", "metaslider" ) ?>'>
  826. <span class='wp-media-buttons-icon'></span> <?php _e( "Add Slide", "metaslider" ) ?>
  827. </a>
  828. <?php do_action( "metaslider_admin_table_header_right", $this->slider->id ); ?>
  829. </th>
  830. </tr>
  831. </thead>
  832. <tbody>
  833. <?php
  834. $this->slider->render_admin_slides();
  835. ?>
  836. </tbody>
  837. </table>
  838. <?php do_action( "metaslider_admin_table_after", $this->slider->id ); ?>
  839. </div>
  840. </div>
  841. <div id="postbox-container-1" class="postbox-container">
  842. <div class='right'>
  843. <div class="ms-postbox" id="metaslider_configuration">
  844. <h3 class='configuration'>
  845. <?php _e( "Settings", "metaslider" ) ?>
  846. <input class='alignright button button-primary' type='submit' name='save' id='ms-save' value='<?php _e( "Save", "metaslider" ) ?>' />
  847. <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' ) ?>' />
  848. <span class="spinner"></span>
  849. </h3>
  850. <div class="inside">
  851. <table class="settings">
  852. <tbody>
  853. <?php
  854. $aFields = array(
  855. 'type' => array(
  856. 'priority' => 0,
  857. 'type' => 'slider-lib',
  858. 'value' => $this->slider->get_setting( 'type' ),
  859. 'options' => array(
  860. 'flex' => array( 'label' => __( "Flex Slider", "metaslider" ) ),
  861. 'responsive' => array( 'label' => __( "R. Slides", "metaslider" ) ),
  862. 'nivo' => array( 'label' => __( "Nivo Slider", "metaslider" ) ),
  863. 'coin' => array( 'label' => __( "Coin Slider", "metaslider" ) )
  864. )
  865. ),
  866. 'width' => array(
  867. 'priority' => 10,
  868. 'type' => 'number',
  869. 'size' => 3,
  870. 'min' => 0,
  871. 'max' => 9999,
  872. 'step' => 1,
  873. 'value' => $this->slider->get_setting( 'width' ),
  874. 'label' => __( "Width", "metaslider" ),
  875. 'class' => 'coin flex responsive nivo',
  876. 'helptext' => __( "Slideshow width", "metaslider" ),
  877. 'after' => __( "px", "metaslider" )
  878. ),
  879. 'height' => array(
  880. 'priority' => 20,
  881. 'type' => 'number',
  882. 'size' => 3,
  883. 'min' => 0,
  884. 'max' => 9999,
  885. 'step' => 1,
  886. 'value' => $this->slider->get_setting( 'height' ),
  887. 'label' => __( "Height", "metaslider" ),
  888. 'class' => 'coin flex responsive nivo',
  889. 'helptext' => __( "Slideshow height", "metaslider" ),
  890. 'after' => __( "px", "metaslider" )
  891. ),
  892. 'effect' => array(
  893. 'priority' => 30,
  894. 'type' => 'select',
  895. 'value' => $this->slider->get_setting( 'effect' ),
  896. 'label' => __( "Effect", "metaslider" ),
  897. 'class' => 'effect coin flex responsive nivo',
  898. 'helptext' => __( "Slide transition effect", "metaslider" ),
  899. 'options' => array(
  900. 'random' => array( 'class' => 'option coin nivo' , 'label' => __( "Random", "metaslider" ) ),
  901. 'swirl' => array( 'class' => 'option coin', 'label' => __( "Swirl", "metaslider" ) ),
  902. 'rain' => array( 'class' => 'option coin', 'label' => __( "Rain", "metaslider" ) ),
  903. 'straight' => array( 'class' => 'option coin', 'label' => __( "Straight", "metaslider" ) ),
  904. 'sliceDown' => array( 'class' => 'option nivo', 'label' => __( "Slide Down", "metaslider" ) ),
  905. 'sliceUp' => array( 'class' => 'option nivo', 'label' => __( "Slice Up", "metaslider" ) ),
  906. 'sliceUpLeft' => array( 'class' => 'option nivo', 'label' => __( "Slide Up Left", "metaslider" ) ),
  907. 'sliceUpDown' => array( 'class' => 'option nivo', 'label' => __( "Slice Up Down", "metaslider" ) ),
  908. 'slideUpDownLeft' => array( 'class' => 'option nivo', 'label' => __( "Slide Up Down Left", "metaslider" ) ),
  909. 'fold' => array( 'class' => 'option nivo', 'label' => __( "Fold", "metaslider" ) ),
  910. 'fade' => array( 'class' => 'option nivo flex responsive', 'label' => __( "Fade", "metaslider" ) ),
  911. 'slideInRight' => array( 'class' => 'option nivo', 'label' => __( "Slide In Right", "metaslider" ) ),
  912. 'slideInLeft' => array( 'class' => 'option nivo', 'label' => __( "Slide In Left", "metaslider" ) ),
  913. 'boxRandom' => array( 'class' => 'option nivo', 'label' => __( "Box Random", "metaslider" ) ),
  914. 'boxRain' => array( 'class' => 'option nivo', 'label' => __( "Box Rain", "metaslider" ) ),
  915. 'boxRainReverse' => array( 'class' => 'option nivo', 'label' => __( "Box Rain Reverse", "metaslider" ) ),
  916. 'boxRainGrowReverse' => array( 'class' => 'option nivo', 'label' => __( "Box Rain Grow Reverse", "metaslider" ) ),
  917. 'slide' => array( 'class' => 'option flex', 'label' => __( "Slide", "metaslider" ) )
  918. ),
  919. ),
  920. 'theme' => array(
  921. 'priority' => 40,
  922. 'type' => 'theme',
  923. 'value' => $this->slider->get_setting( 'theme' ),
  924. 'label' => __( "Theme", "metaslider" ),
  925. 'class' => 'effect coin flex responsive nivo',
  926. 'helptext' => __( "Slideshow theme", "metaslider" ),
  927. 'options' => array(
  928. 'default' => array( 'class' => 'option nivo flex coin responsive' , 'label' => __( "Default", "metaslider" ) ),
  929. 'dark' => array( 'class' => 'option nivo', 'label' => __( "Dark (Nivo)", "metaslider" ) ),
  930. 'light' => array( 'class' => 'option nivo', 'label' => __( "Light (Nivo)", "metaslider" ) ),
  931. 'bar' => array( 'class' => 'option nivo', 'label' => __( "Bar (Nivo)", "metaslider" ) ),
  932. ),
  933. ),
  934. 'links' => array(
  935. 'priority' => 50,
  936. 'type' => 'checkbox',
  937. 'label' => __( "Arrows", "metaslider" ),
  938. 'class' => 'option coin flex nivo responsive',
  939. 'checked' => $this->slider->get_setting( 'links' ) == 'true' ? 'checked' : '',