Completed
Push — master ( 72613d...069c91 )
by Michael
02:16
created

assets/js/ml-slider/ml-slider.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/*
3
 * Plugin Name: Meta Slider
4
 * Plugin URI: http://www.metaslider.com
5
 * Description: Easy to use slideshow plugin. Create SEO optimised responsive slideshows with Nivo Slider, Flex Slider, Coin Slider and Responsive Slides.
6
 * Version: 2.6.3
7
 * Author: Matcha Labs
8
 * Author URI: http://www.matchalabs.com
9
 * License: GPLv2 or later
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 */
16
17
// disable direct access
18
if (!defined('ABSPATH')) {
19
    exit;
20
}
21
22
define('METASLIDER_VERSION', '2.6.3');
23
define('METASLIDER_BASE_URL', plugins_url('ml-slider') . '/'); //plugin_dir_url(__FILE__)
24
define('METASLIDER_ASSETS_URL', METASLIDER_BASE_URL . 'assets/');
25
define('METASLIDER_BASE_DIR_LONG', __DIR__);
26
define('METASLIDER_INC_DIR', METASLIDER_BASE_DIR_LONG . '/inc/');
27
28
// include slider classes
29
require_once(METASLIDER_INC_DIR . 'slider/metaslider.class.php');
30
require_once(METASLIDER_INC_DIR . 'slider/metaslider.coin.class.php');
31
require_once(METASLIDER_INC_DIR . 'slider/metaslider.flex.class.php');
32
require_once(METASLIDER_INC_DIR . 'slider/metaslider.nivo.class.php');
33
require_once(METASLIDER_INC_DIR . 'slider/metaslider.responsive.class.php');
34
35
// include slide classes
36
require_once(METASLIDER_INC_DIR . 'slide/metaslide.class.php');
37
require_once(METASLIDER_INC_DIR . 'slide/metaslide.image.class.php');
38
39
// include image helper
40
require_once(METASLIDER_INC_DIR . 'metaslider.imagehelper.class.php');
41
42
// include widget
43
require_once(METASLIDER_INC_DIR . 'metaslider.widget.class.php');
44
45
// include system check
46
require_once(METASLIDER_INC_DIR . 'metaslider.systemcheck.class.php');
47
48
/**
49
 * Register the plugin.
50
 *
51
 * Display the administration panel, insert JavaScript etc.
52
 */
53
class MetaSliderPlugin
54
{
55
    /** Current Slider **/
56
    public $slider = null;
57
58
    /**
59
     * Constructor
60
     */
61
    public function __construct()
62
    {
63
        // create the admin menu/page
64
        add_action('admin_menu', array($this, 'register_admin_menu'), 9553);
65
66
        // register slider post type and taxonomy
67
        add_action('init', array($this, 'register_post_type'));
68
        add_action('init', array($this, 'register_taxonomy'));
69
        add_action('init', array($this, 'load_plugin_textdomain'));
70
71
        // register shortcodes
72
        add_shortcode('metaslider', array($this, 'register_shortcode'));
73
        add_shortcode('ml-slider', array($this, 'register_shortcode')); // backwards compatibility
74
75
        add_filter('media_upload_tabs', array($this, 'custom_media_upload_tab_name'), 998);
76
        add_filter('media_view_strings', array($this, 'custom_media_uploader_tabs'), 5);
77
        add_action('media_upload_vimeo', array($this, 'metaslider_pro_tab'));
78
        add_action('media_upload_youtube', array($this, 'metaslider_pro_tab'));
79
        add_action('media_upload_post_feed', array($this, 'metaslider_pro_tab'));
80
        add_action('media_upload_layer', array($this, 'metaslider_pro_tab'));
81
82
        add_filter('media_buttons_context', array($this, 'insert_metaslider_button'));
83
        add_action('admin_footer', array($this, 'admin_footer'));
84
85
        // add 'go pro' link to plugin options
86
        $plugin = plugin_basename(__FILE__);
87
        add_filter("plugin_action_links_{$plugin}", array($this, 'upgrade_to_pro'));
88
89
        $this->register_slide_types();
90
    }
91
92
    /**
93
     * Check our WordPress installation is compatible with Meta Slider
94
     */
95
    public function system_check()
96
    {
97
        $systemCheck = new MetaSliderSystemCheck();
98
        $systemCheck->check();
99
    }
100
101
    /**
102
     * Add settings link on plugin page
103
     * @param $links
104
     * @return array
105
     */
106
    public function upgrade_to_pro($links)
107
    {
108
        if (function_exists('is_plugin_active') && !is_plugin_active('ml-slider-pro/ml-slider-pro.php')) {
109
            $links[] = '<a href="http://www.metaslider.com/upgrade" target="_blank">' . __('Go Pro', 'metaslider') . '</a>';
110
        }
111
112
        return $links;
113
    }
114
115
    /**
116
     * Return the meta slider pro upgrade iFrame
117
     */
118
    public function metaslider_pro_tab()
119
    {
120
        if (function_exists('is_plugin_active') && !is_plugin_active('ml-slider-pro/ml-slider-pro.php')) {
121
            return wp_iframe(array($this, 'iframe'));
122
        }
123
    }
124
125
    /**
126
     * Media Manager iframe HTML
127
     */
128
    public function iframe()
129
    {
130
        wp_enqueue_style('metaslider-admin-styles', METASLIDER_ASSETS_URL . 'metaslider/admin.css', false, METASLIDER_VERSION);
131
        wp_enqueue_script('google-font-api', 'http://fonts.googleapis.com/css?family=PT+Sans:400,700');
132
133
        $link = apply_filters('metaslider_hoplink', 'http://www.metaslider.com/upgrade/');
134
        $link .= '?utm_source=lite&amp;utm_medium=more-slide-types&amp;utm_campaign=pro';
135
136
        echo "<div class='metaslider'>";
137
        echo "<p style='text-align: center; font-size: 1.2em; margin-top: 50px;'>Get the Pro Addon pack to add support for: <b>Post Feed</b> Slides, <b>YouTube</b> Slides, <b>HTML</b> Slides & <b>Vimeo</b> Slides</p>";
138
        echo "<p style='text-align: center; font-size: 1.2em;'><b>NEW: </b> Animated HTML <b>Layer</b> Slides (with an awesome Drag & Drop editor!)</p>";
139
        echo "<p style='text-align: center; font-size: 1.2em;'><b></b> Live Theme Editor!</p>";
140
        echo "<p style='text-align: center; font-size: 1.2em;'><b>NEW:</b> Thumbnail Navigation for Flex & Nivo Slider!</p>";
141
        echo "<a class='probutton' href='{$link}' target='_blank'>Get <span class='logo'><strong>Meta</strong>Slider</span><span class='super'>Pro</span></a>";
142
        echo "<span class='subtext'>Opens in a new window</span>";
143
        echo '</div>';
144
    }
145
146
    /**
147
     * Register our slide types
148
     */
149
    private function register_slide_types()
150
    {
151
        $image = new MetaImageSlide();
152
    }
153
154
    /**
155
     * Initialise translations
156
     */
157
    public function load_plugin_textdomain()
158
    {
159
        load_plugin_textdomain('metaslider', false, dirname(plugin_basename(__FILE__)) . '/languages/');
160
    }
161
162
    /**
163
     * Update the tab options in the media manager
164
     * @param $strings
165
     * @return mixed
166
     */
167
    public function custom_media_uploader_tabs($strings)
168
    {
169
        //update strings
170
        if (isset($_GET['page']) && 'metaslider' == $_GET['page']) {
171
            $strings['insertMediaTitle'] = __('Image', 'metaslider');
172
            $strings['insertIntoPost']   = __('Add to slider', 'metaslider');
173
            // remove options
174
            if (isset($strings['createGalleryTitle'])) {
175
                unset($strings['createGalleryTitle']);
176
            }
177
            if (isset($strings['insertFromUrlTitle'])) {
178
                unset($strings['insertFromUrlTitle']);
179
            }
180
        }
181
182
        return $strings;
183
    }
184
185
    /**
186
     * Add extra tabs to the default wordpress Media Manager iframe
187
     *
188
     * @var array existing media manager tabs
189
     * @return array
190
     */
191
    public function custom_media_upload_tab_name($tabs)
192
    {
193
        $metaslider_tabs = array('post_feed', 'layer', 'youtube', 'vimeo');
194
195
        // restrict our tab changes to the meta slider plugin page
196
        if ((isset($_GET['page']) && 'metaslider' === $_GET['page']) || (isset($_GET['tab']) && in_array($_GET['tab'], $metaslider_tabs))) {
197
            $newtabs = array();
198
199
            if (function_exists('is_plugin_active') && !is_plugin_active('ml-slider-pro/ml-slider-pro.php')) {
200
                $newtabs = array(
201
                    'post_feed' => __('Post Feed', 'metaslider'),
202
                    'vimeo'     => __('Vimeo', 'metaslider'),
203
                    'youtube'   => __('YouTube', 'metaslider'),
204
                    'layer'     => __('Layer Slide', 'metaslider')
205
                );
206
            }
207
208
            if (isset($tabs['nextgen'])) {
209
                unset($tabs['nextgen']);
210
            }
211
212
            return array_merge($tabs, $newtabs);
213
        }
214
215
        return $tabs;
216
    }
217
218
    /**
219
     * Rehister admin styles
220
     */
221
    public function register_admin_styles()
222
    {
223
        wp_enqueue_style('metaslider-admin-styles', METASLIDER_ASSETS_URL . 'metaslider/admin.css', false, METASLIDER_VERSION);
224
        wp_enqueue_style('metaslider-colorbox-styles', METASLIDER_ASSETS_URL . 'colorbox/colorbox.css', false, METASLIDER_VERSION);
225
        wp_enqueue_style('metaslider-tipsy-styles', METASLIDER_ASSETS_URL . 'tipsy/tipsy.css', false, METASLIDER_VERSION);
226
227
        do_action('metaslider_register_admin_styles');
228
    }
229
230
    /**
231
     * Register admin JavaScript
232
     */
233
    public function register_admin_scripts()
234
    {
235
        if (wp_script_is('wp-auth-check', 'queue')) {
236
            // meta slider checks for active AJAX requests in order to show the spinner
237
            // .. but the auth-check runs an AJAX request every 15 seconds
238
            // deregister the script that displays the login panel if the user becomes logged
239
            // out at some point
240
            // todo: implement some more intelligent request checking
241
            wp_deregister_script('wp-auth-check');
242
            wp_register_script('wp-auth-check', null); // fix php notice
243
        }
244
245
        // media library dependencies
246
        wp_enqueue_media();
247
248
        // plugin dependencies
249
        wp_enqueue_script('jquery-ui-core', array('jquery'));
250
        wp_enqueue_script('jquery-ui-sortable', array('jquery', 'jquery-ui-core'));
251
        wp_enqueue_script('metaslider-colorbox', METASLIDER_ASSETS_URL . 'colorbox/jquery.colorbox-min.js', array('jquery'), METASLIDER_VERSION);
252
        wp_enqueue_script('metaslider-tipsy', METASLIDER_ASSETS_URL . 'tipsy/jquery.tipsy.js', array('jquery'), METASLIDER_VERSION);
253
        wp_enqueue_script('metaslider-admin-script', METASLIDER_ASSETS_URL . 'metaslider/admin.js', array('jquery', 'metaslider-tipsy', 'media-upload'), METASLIDER_VERSION);
254
        wp_enqueue_script('metaslider-admin-addslide', METASLIDER_ASSETS_URL . 'metaslider/image/image.js', array('metaslider-admin-script'), METASLIDER_VERSION);
255
256
        // localise the JS
257
        wp_localize_script('metaslider-admin-addslide', 'metaslider_image', array(
258
            'addslide_nonce' => wp_create_nonce('metaslider_addslide')
259
        ));
260
261
        // localise the JS
262
        wp_localize_script('metaslider-admin-script', 'metaslider', array(
263
            'url'            => __('URL', 'metaslider'),
264
            'caption'        => __('Caption', 'metaslider'),
265
            'new_window'     => __('New Window', 'metaslider'),
266
            'confirm'        => __('Are you sure?', 'metaslider'),
267
            'ajaxurl'        => admin_url('admin-ajax.php'),
268
            'resize_nonce'   => wp_create_nonce('metaslider_resize'),
269
            'iframeurl'      => METASLIDER_BASE_URL . 'preview.php',
270
            'useWithCaution' => __("Caution: This setting is for advanced developers only. If you're unsure, leave it checked.", 'metaslider')
271
        ));
272
273
        do_action('metaslider_register_admin_scripts');
274
    }
275
276
    /**
277
     * Add the menu page
278
     */
279
    public function register_admin_menu()
280
    {
281
        $title = apply_filters('metaslider_menu_title', 'Meta Slider');
282
283
        $page = add_menu_page($title, $title, 'edit_others_posts', 'metaslider', array(
284
            $this,
285
            'render_admin_page'
286
        ), METASLIDER_ASSETS_URL . 'metaslider/matchalabs.png', 9501);
287
288
        // ensure our JavaScript is only loaded on the Meta Slider admin page
289
        add_action('admin_print_scripts-' . $page, array($this, 'register_admin_scripts'));
290
        add_action('admin_print_styles-' . $page, array($this, 'register_admin_styles'));
291
        add_action('load-' . $page, array($this, 'help_tab'));
292
    }
293
294
    /**
295
     * Upgrade CTA.
296
     */
297
    public function go_pro_cta()
298
    {
299
        if (function_exists('is_plugin_active') && !is_plugin_active('ml-slider-pro/ml-slider-pro.php')) {
300
            $link = apply_filters('metaslider_hoplink', 'http://www.metaslider.com/upgrade/');
301
302
            $link .= '?utm_source=lite&amp;utm_medium=nag&amp;utm_campaign=pro';
303
304
            $goPro = "<div style='display: none;' id='screen-options-link-wrap'><a target='_blank' class='show-settings' href='{$link}'>Meta Slider v" . METASLIDER_VERSION . ' - ' . __('Upgrade to Pro $19', 'metaslider') . '</a></div>';
305
306
            echo $goPro;
307
        }
308
    }
309
310
    /**
311
     *
312
     */
313
    public function help_tab()
314
    {
315
        $screen = get_current_screen();
316
317
        // documentation tab
318
        $screen->add_help_tab(array(
319
                                  'id'      => 'documentation',
320
                                  'title'   => __('Documentation'),
321
                                  'content' => "<p><a href='http://www.metaslider.com/documentation/' target='blank'>Meta Slider Documentation</a></p>"
322
                              ));
323
    }
324
325
    /**
326
     * Register ML Slider post type
327
     */
328
    public function register_post_type()
329
    {
330
        register_post_type('ml-slider', array(
331
            'query_var' => false,
332
            'rewrite'   => false,
333
            'public'    => true,
334
            'show_ui'   => false,
335
            'labels'    => array(
336
                'name' => 'Meta Slider'
337
            )
338
        ));
339
    }
340
341
    /**
342
     * Register taxonomy to store slider => slides relationship
343
     */
344
    public function register_taxonomy()
345
    {
346
        register_taxonomy('ml-slider', 'attachment', array(
347
            'hierarchical' => true,
348
            'public'       => false,
349
            'query_var'    => false,
350
            'rewrite'      => false
351
        ));
352
    }
353
354
    /**
355
     * Shortcode used to display slideshow
356
     *
357
     * @param $atts
358
     * @return string HTML output of the shortcode
359
     */
360
    public function register_shortcode($atts)
361
    {
362
        if (!isset($atts['id'])) {
363
            return false;
364
        }
365
366
        // we have an ID to work with
367
        $slider = get_post($atts['id']);
368
369
        // check the slider is published
370
        if ('publish' !== $slider->post_status) {
371
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type documented by MetaSliderPlugin::register_shortcode of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
372
        }
373
374
        // lets go
375
        $this->set_slider($atts['id'], $atts);
376
        $this->slider->enqueue_scripts();
377
378
        return $this->slider->render_public_slides();
379
    }
380
381
    /**
382
     * Set the current slider
383
     * @param       $id
384
     * @param array $shortcode_settings
385
     */
386
    public function set_slider($id, $shortcode_settings = array())
387
    {
388
        $type = 'flex';
389
390
        $settings = array_merge(get_post_meta($id, 'ml-slider_settings', true), $shortcode_settings);
391
392
        if (isset($settings['type']) && in_array($settings['type'], array('flex', 'coin', 'nivo', 'responsive'))) {
393
            $type = $settings['type'];
394
        }
395
396
        $this->slider = $this->create_slider($type, $id, $shortcode_settings);
397
    }
398
399
    /**
400
     * Create a new slider based on the sliders type setting
401
     * @param $type
402
     * @param $id
403
     * @param $shortcode_settings
404
     * @return MetaFlexSlider|MetaNivoSlider|MetaResponsiveSlider
405
     */
406
    private function create_slider($type, $id, $shortcode_settings)
407
    {
408
        switch ($type) {
409
            case('coin'):
410
                return new MetaCoinSlider($id, $shortcode_settings);
411
            case('flex'):
412
                return new MetaFlexSlider($id, $shortcode_settings);
413
            case('nivo'):
414
                return new MetaNivoSlider($id, $shortcode_settings);
415
            case('responsive'):
416
                return new MetaResponsiveSlider($id, $shortcode_settings);
417
            default:
418
                return new MetaFlexSlider($id, $shortcode_settings);
419
        }
420
    }
421
422
    /**
423
     * Handle slide uploads/changes.
424
     */
425
    public function admin_process()
426
    {
427
        // this function should only ever be called from the Meta Slider admin page.
428
        if (!is_admin()) {
429
            return;
430
        }
431
432
        // default to the latest slider
433
        $slider_id = $this->find_slider('modified', 'DESC');
434
435
        // delete a slider
436
        if (isset($_GET['delete'])) {
437
            $slider_id = $this->delete_slider((int)$_GET['delete']);
438
        }
439
440
        // create a new slider
441
        if (isset($_GET['add'])) {
442
            $slider_id = $this->add_slider();
443
        }
444
445
        // load a slider by ID
446
        if (isset($_REQUEST['id'])) {
447
            $temp_id = (int)$_REQUEST['id'];
448
449
            // check valid post ID
450
            if (get_post($temp_id)) {
451
                $slider_id = $temp_id;
452
            }
453
        }
454
455
        if ($slider_id > 0) {
456
            $this->set_slider($slider_id);
457
        }
458
    }
459
460
    /**
461
     * Create a new slider
462
     */
463
    private function add_slider()
464
    {
465
        // check nonce
466
        check_admin_referer('metaslider_add_slider');
467
468
        $defaults = array();
469
470
        // if possible, take a copy of the last edited slider settings in place of default settings
471
        if ($last_modified = $this->find_slider('modified', 'DESC')) {
472
            $defaults = get_post_meta($last_modified, 'ml-slider_settings', true);
473
        }
474
475
        // use the default settings if we can't find anything more suitable.
476
        if (empty($defaults)) {
477
            $slider   = new MetaSlider($id, array());
478
            $defaults = $slider->get_default_parameters();
479
        }
480
481
        // insert the post
482
        $id = wp_insert_post(array(
483
                                 'post_title'  => __('New Slider', 'metaslider'),
484
                                 'post_status' => 'publish',
485
                                 'post_type'   => 'ml-slider'
486
                             ));
487
488
        // insert the post meta
489
        add_post_meta($id, 'ml-slider_settings', $defaults, true);
490
491
        // create the taxonomy term, the term is the ID of the slider itself
492
        wp_insert_term($id, 'ml-slider');
493
494
        return $id;
495
    }
496
497
    /**
498
     * Delete a slider (send it to trash)
499
     *
500
     * @param int $id
501
     * @return int
502
     */
503
    private function delete_slider($id)
504
    {
505
        // check nonce
506
        check_admin_referer('metaslider_delete_slider');
507
508
        // send the post to trash
509
        wp_update_post(array(
510
                           'ID'          => $id,
511
                           'post_status' => 'trash'
512
                       ));
513
514
        return $this->find_slider('date', 'DESC');
515
    }
516
517
    /**
518
     * Find a single slider ID. For example, last edited, or first published.
519
     *
520
     * @param  string $orderby field to order.
521
     * @param  string $order   direction (ASC or DESC).
522
     * @return int    slider ID.
523
     */
524
    private function find_slider($orderby, $order)
525
    {
526
        $args = array(
527
            'force_no_custom_order' => true,
528
            'post_type'             => 'ml-slider',
529
            'num_posts'             => 1,
530
            'post_status'           => 'publish',
531
            'suppress_filters'      => 1, // wpml, ignore language filter
532
            'orderby'               => $orderby,
533
            'order'                 => $order
534
        );
535
536
        $the_query = new WP_Query($args);
537
538
        while ($the_query->have_posts()) {
539
            $the_query->the_post();
540
541
            return $the_query->post->ID;
542
        }
543
544
        wp_reset_query();
545
546
        return false;
547
    }
548
549
    /**
550
     * Get sliders. Returns a nicely formatted array of currently
551
     * published sliders.
552
     *
553
     * @param  string $sort_key
554
     * @return array  all published sliders
555
     */
556
    private function all_meta_sliders($sort_key = 'date')
557
    {
558
        $sliders = false;
559
560
        // list the tabs
561
        $args = array(
562
            'post_type'        => 'ml-slider',
563
            'post_status'      => 'publish',
564
            'orderby'          => $sort_key,
565
            'suppress_filters' => 1, // wpml, ignore language filter
566
            'order'            => 'ASC',
567
            'posts_per_page'   => -1
568
        );
569
570
        $args = apply_filters('metaslider_all_meta_sliders_args', $args);
571
572
        $the_query = new WP_Query($args);
573
574
        while ($the_query->have_posts()) {
575
            $the_query->the_post();
576
            $active = $this->slider && ($this->slider->id == $the_query->post->ID) ? true : false;
577
578
            $sliders[] = array(
579
                'active' => $active,
580
                'title'  => get_the_title(),
581
                'id'     => $the_query->post->ID
582
            );
583
        }
584
585
        wp_reset_query();
586
587
        return $sliders;
588
    }
589
590
    /**
591
     * Compare array values
592
     *
593
     * @param  array $elem1
594
     * @param  array $elem2
595
     * @return bool
596
     */
597
    private function compare_elems($elem1, $elem2)
598
    {
599
        return $elem1['priority'] > $elem2['priority'];
600
    }
601
602
    /**
603
     *
604
     * @param  array $aFields - array of field to render
605
     * @return string
606
     */
607
    public function build_settings_rows($aFields)
608
    {
609
        // order the fields by priority
610
        uasort($aFields, array($this, 'compare_elems'));
611
612
        $return = '';
613
614
        // loop through the array and build the settings HTML
615
        foreach ($aFields as $id => $row) {
616
            // checkbox input type
617
            if ('checkbox' === $row['type']) {
618
                $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']} >";
619
620
                if (isset($row['after'])) {
621
                    $return .= "<span class='after'>{$row['after']}</span>";
622
                }
623
624
                $return .= '</td></tr>';
625
            }
626
627
            // navigation row
628
            if ('navigation' === $row['type']) {
629
                $navigation_row = "<tr class='{$row['type']}'><td class='tipsy-tooltip' title=\"{$row['helptext']}\">{$row['label']}</td><td><ul>";
630
631
                foreach ($row['options'] as $k => $v) {
632
                    $checked        = checked($k, $row['value'], false);
633
                    $disabled       = 'thumbnails' === $k ? 'disabled' : '';
634
                    $navigation_row .= "<li><label><input type='radio' name='settings[{$id}]' value='{$k}' {$checked} {$disabled}>{$v['label']}</label></li>";
635
                }
636
637
                $navigation_row .= '</ul></td></tr>';
638
639
                $return .= apply_filters('metaslider_navigation_options', $navigation_row, $this->slider);
640
            }
641
642
            // navigation row
643 View Code Duplication
            if ('radio' === $row['type']) {
644
                $navigation_row = "<tr class='{$row['type']}'><td class='tipsy-tooltip' title=\"{$row['helptext']}\">{$row['label']}</td><td><ul>";
645
646
                foreach ($row['options'] as $k => $v) {
647
                    $checked        = checked($k, $row['value'], false);
648
                    $class          = isset($v['class']) ? $v['class'] : '';
649
                    $navigation_row .= "<li><label><input type='radio' name='settings[{$id}]' value='{$k}' {$checked} class='radio {$class}'>{$v['label']}</label></li>";
650
                }
651
652
                $navigation_row .= '</ul></td></tr>';
653
654
                $return .= apply_filters('metaslider_navigation_options', $navigation_row, $this->slider);
655
            }
656
657
            // header/divider row
658
            if ('divider' === $row['type']) {
659
                $return .= "<tr class='{$row['type']}'><td colspan='2' class='divider'><b>{$row['value']}</b></td></tr>";
660
            }
661
662
            // slideshow select row
663
            if ('slider-lib' === $row['type']) {
664
                $return .= "<tr class='{$row['type']}'><td colspan='2' class='slider-lib-row'>";
665
666
                foreach ($row['options'] as $k => $v) {
667
                    $checked = checked($k, $row['value'], false);
668
                    $return  .= "<input class='select-slider' id='{$k}' rel='{$k}' type='radio' name='settings[type]' value='{$k}' {$checked} >
669
                    <label for='{$k}'>{$v['label']}</label>";
670
                }
671
672
                $return .= '</td></tr>';
673
            }
674
675
            // number input type
676
            if ('number' === $row['type']) {
677
                $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>";
678
            }
679
680
            // select drop down
681
            if ('select' === $row['type']) {
682
                $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}]'>";
683
                foreach ($row['options'] as $k => $v) {
684
                    $selected = selected($k, $row['value'], false);
685
                    $return   .= "<option class='{$v['class']}' value='{$k}' {$selected}>{$v['label']}</option>";
686
                }
687
                $return .= '</select></td></tr>';
688
            }
689
690
            // theme drop down
691 View Code Duplication
            if ('theme' === $row['type']) {
692
                $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}]'>";
693
                $themes = '';
694
695
                foreach ($row['options'] as $k => $v) {
696
                    $selected = selected($k, $row['value'], false);
697
                    $themes   .= "<option class='{$v['class']}' value='{$k}' {$selected}>{$v['label']}</option>";
698
                }
699
700
                $return .= apply_filters('metaslider_get_available_themes', $themes, $this->slider->get_setting('theme'));
701
702
                $return .= '</select></td></tr>';
703
            }
704
705
            // text input type
706 View Code Duplication
            if ('text' === $row['type']) {
707
                $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>";
708
            }
709
710
            // text input type
711 View Code Duplication
            if ('title' === $row['type']) {
712
                $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>";
713
            }
714
        }
715
716
        return $return;
717
    }
718
719
    /**
720
     * Return an indexed array of all easing options
721
     *
722
     * @return array
723
     */
724
    private function get_easing_options()
725
    {
726
        $options = array(
727
            'linear',
728
            'swing',
729
            'jswing',
730
            'easeInQuad',
731
            'easeOutQuad',
732
            'easeInOutQuad',
733
            'easeInCubic',
734
            'easeOutCubic',
735
            'easeInOutCubic',
736
            'easeInQuart',
737
            'easeOutQuart',
738
            'easeInOutQuart',
739
            'easeInQuint',
740
            'easeOutQuint',
741
            'easeInOutQuint',
742
            'easeInSine',
743
            'easeOutSine',
744
            'easeInOutSine',
745
            'easeInExpo',
746
            'easeOutExpo',
747
            'easeInOutExpo',
748
            'easeInCirc',
749
            'easeOutCirc',
750
            'easeInOutCirc',
751
            'easeInElastic',
752
            'easeOutElastic',
753
            'easeInOutElastic',
754
            'easeInBack',
755
            'easeOutBack',
756
            'easeInOutBack',
757
            'easeInBounce',
758
            'easeOutBounce',
759
            'easeInOutBounce'
760
        );
761
762
        foreach ($options as $option) {
763
            $return[$option] = array(
764
                'label' => ucfirst(preg_replace('/(\w+)([A-Z])/U', '\\1 \\2', $option)),
765
                'class' => ''
766
            );
767
        }
768
769
        return $return;
770
    }
771
772
    /**
773
     * Render the admin page (tabs, slides, settings)
774
     */
775
    public function render_admin_page()
776
    {
777
        $this->admin_process();
778
        $this->go_pro_cta();
779
        $this->system_check();
780
        $max_tabs = apply_filters('metaslider_max_tabs', 0); ?>
781
782
        <script type='text/javascript'>
783
            var metaslider_slider_id = <?php echo $this->slider->id; ?>;
784
            var metaslider_pro_active = <?php echo function_exists('is_plugin_active') && is_plugin_active('ml-slider-pro/ml-slider-pro.php') ? 'true' : 'false' ?>;
785
        </script>
786
787
        <div class="wrap metaslider">
788
            <form accept-charset="UTF-8" action="?page=metaslider&amp;id=<?php echo $this->slider->id ?>" method="post">
789
                <?php
790
                if ($this->slider) {
791
                    wp_nonce_field('metaslider_save_' . $this->slider->id);
792
                }
793
794
        $title   = '';
795
        $add_url = wp_nonce_url('?page=metaslider&amp;add=true', 'metaslider_add_slider');
796
797
        if ($tabs = $this->all_meta_sliders()) {
798
            if ($max_tabs && count($tabs) > $max_tabs) {
799
                if (isset($_GET['add']) && 'true' === $_GET['add']) {
800
                    echo "<div id='message' class='updated'><p>" . __("New slideshow created. Click 'Add Slide' to get started!", 'metaslider') . '</p></div>';
801
                }
802
                echo "<div style='margin-top: 20px;'><label for='select-slider'>Select Slider: </label>";
803
                echo "<select name='select-slider' onchange='if (this.value) window.location.href=this.value'>";
804
805
                $tabs = $this->all_meta_sliders('title');
806
807
                foreach ($tabs as $tab) {
808
                    $selected = $tab['active'] ? ' selected' : '';
809
810
                    if ($tab['active']) {
811
                        $title = $tab['title'];
812
                    }
813
814
                    echo "<option value='?page=metaslider&amp;id={$tab['id']}'{$selected}>{$tab['title']}</option>";
815
                }
816
                echo '</select> ' . __('or', 'metaslider') . ' ';
817
                echo "<a href='{$add_url}'>" . __('Add New Slideshow', 'metaslider') . '</a></div>';
818
            } else {
819
                echo "<h3 class='nav-tab-wrapper'>";
820
                foreach ($tabs as $tab) {
821
                    if ($tab['active']) {
822
                        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>";
823
                    } else {
824
                        echo "<a href='?page=metaslider&amp;id={$tab['id']}' class='nav-tab'>" . $tab['title'] . '</a>';
825
                    }
826
                }
827
                echo "<a href='{$add_url}' id='create_new_tab' class='nav-tab'>+</a>";
828
                echo '</h3>';
829
            }
830
        } else {
831
            echo "<h3 class='nav-tab-wrapper'>";
832
            echo "<a href='{$add_url}' id='create_new_tab' class='nav-tab'>+</a>";
833
            echo "<div class='bubble'>" . __('Create your first slideshow') . '</div>';
834
            echo '</h3>';
835
        } ?>
836
837
                <?php
838
                if (!$this->slider) {
839
                    return;
840
                } ?>
841
                <div id='poststuff'>
842
                    <div id='post-body' class='metabox-holder columns-2'>
843
844
                        <div id='post-body-content'>
845
                            <div class="left">
846
                                <table class="widefat sortable">
847
                                    <thead>
848
                                    <tr>
849
                                        <th style="width: 100px;">
850
                                            <h3><?php _e('Slides', 'metaslider') ?></h3>
851
                                        </th>
852
                                        <th>
853
                                            <a href='#' class='button alignright add-slide' data-editor='content' title='<?php _e('Add Slide', 'metaslider') ?>'>
854
                                                <span class='wp-media-buttons-icon'></span> <?php _e('Add Slide', 'metaslider') ?>
855
                                            </a>
856
                                        </th>
857
                                    </tr>
858
                                    </thead>
859
860
                                    <tbody>
861
                                    <?php
862
                                    $this->slider->render_admin_slides(); ?>
863
                                    </tbody>
864
                                </table>
865
                            </div>
866
                        </div>
867
868
                        <div id='postbox-container-1' class='postbox-container'>
869
                            <div id="side-sortables" class="meta-box-sortables">
870
                                <div class='right'>
871
                                    <div class="postbox">
872
                                        <h3 class='configuration'>
873
                                            <?php _e('Settings', 'metaslider') ?>
874
                                            <input class='alignright button button-primary' type='submit' name='save' id='ms-save' value='<?php _e('Save', 'metaslider') ?>'>
875
                                            <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 ?>'
876
                                                   data-slider_width='<?php echo $this->slider->get_setting('width') ?>' data-slider_height='<?php echo $this->slider->get_setting('height') ?>'>
877
                                            <span class="spinner"></span>
878
                                        </h3>
879
                                        <div class="inside">
880
                                            <table class="widefat settings">
881
                                                <tbody>
882
                                                <?php
883
                                                $aFields = array(
884
                                                    'type'       => array(
885
                                                        'priority' => 0,
886
                                                        'type'     => 'slider-lib',
887
                                                        'value'    => $this->slider->get_setting('type'),
888
                                                        'options'  => array(
889
                                                            'flex'       => array('label' => __('Flex Slider', 'metaslider')),
890
                                                            'responsive' => array('label' => __('Responsive', 'metaslider')),
891
                                                            'nivo'       => array('label' => __('Nivo Slider', 'metaslider')),
892
                                                            'coin'       => array('label' => __('Coin Slider', 'metaslider'))
893
                                                        )
894
                                                    ),
895
                                                    'width'      => array(
896
                                                        'priority' => 10,
897
                                                        'type'     => 'number',
898
                                                        'size'     => 3,
899
                                                        'min'      => 0,
900
                                                        'max'      => 9999,
901
                                                        'step'     => 1,
902
                                                        'value'    => $this->slider->get_setting('width'),
903
                                                        'label'    => __('Width', 'metaslider'),
904
                                                        'class'    => 'coin flex responsive nivo',
905
                                                        'helptext' => __('Slideshow width', 'metaslider'),
906
                                                        'after'    => __('px', 'metaslider')
907
                                                    ),
908
                                                    'height'     => array(
909
                                                        'priority' => 20,
910
                                                        'type'     => 'number',
911
                                                        'size'     => 3,
912
                                                        'min'      => 0,
913
                                                        'max'      => 9999,
914
                                                        'step'     => 1,
915
                                                        'value'    => $this->slider->get_setting('height'),
916
                                                        'label'    => __('Height', 'metaslider'),
917
                                                        'class'    => 'coin flex responsive nivo',
918
                                                        'helptext' => __('Slideshow height', 'metaslider'),
919
                                                        'after'    => __('px', 'metaslider')
920
                                                    ),
921
                                                    'effect'     => array(
922
                                                        'priority' => 30,
923
                                                        'type'     => 'select',
924
                                                        'value'    => $this->slider->get_setting('effect'),
925
                                                        'label'    => __('Effect', 'metaslider'),
926
                                                        'class'    => 'effect coin flex responsive nivo',
927
                                                        'helptext' => __('Slide transition effect', 'metaslider'),
928
                                                        'options'  => array(
929
                                                            'random'             => array('class' => 'option coin nivo', 'label' => __('Random', 'metaslider')),
930
                                                            'swirl'              => array('class' => 'option coin', 'label' => __('Swirl', 'metaslider')),
931
                                                            'rain'               => array('class' => 'option coin', 'label' => __('Rain', 'metaslider')),
932
                                                            'straight'           => array('class' => 'option coin', 'label' => __('Straight', 'metaslider')),
933
                                                            'sliceDown'          => array('class' => 'option nivo', 'label' => __('Slide Down', 'metaslider')),
934
                                                            'sliceUp'            => array('class' => 'option nivo', 'label' => __('Slice Up', 'metaslider')),
935
                                                            'sliceUpLeft'        => array('class' => 'option nivo', 'label' => __('Slide Up Left', 'metaslider')),
936
                                                            'sliceUpDown'        => array('class' => 'option nivo', 'label' => __('Slice Up Down', 'metaslider')),
937
                                                            'slideUpDownLeft'    => array('class' => 'option nivo', 'label' => __('Slide Up Down Left', 'metaslider')),
938
                                                            'fold'               => array('class' => 'option nivo', 'label' => __('Fold', 'metaslider')),
939
                                                            'fade'               => array('class' => 'option nivo flex responsive', 'label' => __('Fade', 'metaslider')),
940
                                                            'slideInRight'       => array('class' => 'option nivo', 'label' => __('Slide In Right', 'metaslider')),
941
                                                            'slideInLeft'        => array('class' => 'option nivo', 'label' => __('Slide In Left', 'metaslider')),
942
                                                            'boxRandom'          => array('class' => 'option nivo', 'label' => __('Box Random', 'metaslider')),
943
                                                            'boxRain'            => array('class' => 'option nivo', 'label' => __('Box Rain', 'metaslider')),
944
                                                            'boxRainReverse'     => array('class' => 'option nivo', 'label' => __('Box Rain Reverse', 'metaslider')),
945
                                                            'boxRainGrowReverse' => array('class' => 'option nivo', 'label' => __('Box Rain Grow Reverse', 'metaslider')),
946
                                                            'slide'              => array('class' => 'option flex', 'label' => __('Slide', 'metaslider'))
947
                                                        )
948
                                                    ),
949
                                                    'theme'      => array(
950
                                                        'priority' => 40,
951
                                                        'type'     => 'theme',
952
                                                        'value'    => $this->slider->get_setting('theme'),
953
                                                        'label'    => __('Theme', 'metaslider'),
954
                                                        'class'    => 'effect coin flex responsive nivo',
955
                                                        'helptext' => __('Slideshow theme', 'metaslider'),
956
                                                        'options'  => array(
957
                                                            'default' => array('class' => 'option nivo flex coin responsive', 'label' => __('Default', 'metaslider')),
958
                                                            'dark'    => array('class' => 'option nivo', 'label' => __('Dark (Nivo)', 'metaslider')),
959
                                                            'light'   => array('class' => 'option nivo', 'label' => __('Light (Nivo)', 'metaslider')),
960
                                                            'bar'     => array('class' => 'option nivo', 'label' => __('Bar (Nivo)', 'metaslider'))
961
                                                        )
962
                                                    ),
963
                                                    'links'      => array(
964
                                                        'priority' => 50,
965
                                                        'type'     => 'checkbox',
966
                                                        'label'    => __('Arrows', 'metaslider'),
967
                                                        'class'    => 'option coin flex nivo responsive',
968
                                                        'checked'  => 'true' === $this->slider->get_setting('links') ? 'checked' : '',
969
                                                        'helptext' => __('Show the previous/next arrows', 'metaslider')
970
                                                    ),
971
                                                    'navigation' => array(
972
                                                        'priority' => 60,
973
                                                        'type'     => 'navigation',
974
                                                        'label'    => __('Navigation', 'metaslider'),
975
                                                        'class'    => 'option coin flex nivo responsive',
976
                                                        'value'    => $this->slider->get_setting('navigation'),
977
                                                        'helptext' => __('Show the slide navigation bullets', 'metaslider'),
978
                                                        'options'  => array(
979
                                                            'false'      => array('label' => __('Hidden', 'metaslider')),
980
                                                            'true'       => array('label' => __('Dots', 'metaslider')),
981
                                                            'thumbnails' => array('label' => __('Thumbnails (Pro)', 'metaslider'))
982
                                                        )
983
                                                    )
984
                                                );
985
986
        if ($max_tabs && count($this->all_meta_sliders()) > $max_tabs) {
987
            $aFields['title'] = array(
988
                                                        'type'     => 'title',
989
                                                        'priority' => 5,
990
                                                        'class'    => 'option flex nivo responsive coin',
991
                                                        'value'    => $title,
992
                                                        'label'    => __('Title', 'metaslider'),
993
                                                        'helptext' => __('Slideshow title', 'metaslider')
994
                                                    );
995
        }
996
997
        $aFields = apply_filters('metaslider_basic_settings', $aFields, $this->slider);
998
999
        echo $this->build_settings_rows($aFields); ?>
1000
                                                </tbody>
1001
                                            </table>
1002
                                        </div>
1003
                                    </div>
1004
1005
                                    <div class="postbox ms-toggle closed">
1006
                                        <div class="handlediv" title="Click to toggle"><br></div>
1007
                                        <h3 class="hndle"><span><?php _e('Advanced Settings', 'metaslider') ?></span></h3>
1008
                                        <div class="inside">
1009
                                            <table>
1010
                                                <tbody>
1011
                                                <?php
1012
                                                $aFields = array(
1013
                                                    'fullWidth'        => array(
1014
                                                        'priority' => 5,
1015
                                                        'type'     => 'checkbox',
1016
                                                        'label'    => __('Stretch', 'metaslider'),
1017
                                                        'class'    => 'option flex nivo responsive',
1018
                                                        'after'    => __('100% wide output', 'metaslider'),
1019
                                                        'checked'  => 'true' === $this->slider->get_setting('fullWidth') ? 'checked' : '',
1020
                                                        'helptext' => __("Stretch the slideshow output to fill it's parent container", 'metaslider')
1021
                                                    ),
1022
                                                    'center'           => array(
1023
                                                        'priority' => 10,
1024
                                                        'type'     => 'checkbox',
1025
                                                        'label'    => __('Center align', 'metaslider'),
1026
                                                        'class'    => 'option coin flex nivo responsive',
1027
                                                        'checked'  => 'true' === $this->slider->get_setting('center') ? 'checked' : '',
1028
                                                        'helptext' => __('Center align the slideshow', 'metaslider')
1029
                                                    ),
1030
                                                    'autoPlay'         => array(
1031
                                                        'priority' => 20,
1032
                                                        'type'     => 'checkbox',
1033
                                                        'label'    => __('Auto play', 'metaslider'),
1034
                                                        'class'    => 'option flex nivo responsive',
1035
                                                        'checked'  => 'true' === $this->slider->get_setting('autoPlay') ? 'checked' : '',
1036
                                                        'helptext' => __('Transition between slides automatically', 'metaslider')
1037
                                                    ),
1038
                                                    'smartCrop'        => array(
1039
                                                        'priority' => 30,
1040
                                                        'type'     => 'checkbox',
1041
                                                        'label'    => __('Smart crop', 'metaslider'),
1042
                                                        'class'    => 'option coin flex nivo responsive',
1043
                                                        'checked'  => 'true' === $this->slider->get_setting('smartCrop') ? 'checked' : '',
1044
                                                        'helptext' => __('Smart Crop ensures your responsive slides are cropped to a ratio that results in a consistent slideshow size', 'metaslider')
1045
                                                    ),
1046
                                                    'carouselMode'     => array(
1047
                                                        'priority' => 40,
1048
                                                        'type'     => 'checkbox',
1049
                                                        'label'    => __('Carousel mode', 'metaslider'),
1050
                                                        'class'    => 'option flex',
1051
                                                        'checked'  => 'true' === $this->slider->get_setting('carouselMode') ? 'checked' : '',
1052
                                                        'helptext' => __('Display multiple slides at once. Slideshow output will be 100% wide.', 'metaslider')
1053
                                                    ),
1054
                                                    'random'           => array(
1055
                                                        'priority' => 50,
1056
                                                        'type'     => 'checkbox',
1057
                                                        'label'    => __('Random', 'metaslider'),
1058
                                                        'class'    => 'option coin flex nivo responsive',
1059
                                                        'checked'  => 'true' === $this->slider->get_setting('random') ? 'checked' : '',
1060
                                                        'helptext' => __('Randomise the order of the slides', 'metaslider')
1061
                                                    ),
1062
                                                    'hoverPause'       => array(
1063
                                                        'priority' => 60,
1064
                                                        'type'     => 'checkbox',
1065
                                                        'label'    => __('Hover pause', 'metaslider'),
1066
                                                        'class'    => 'option coin flex nivo responsive',
1067
                                                        'checked'  => 'true' === $this->slider->get_setting('hoverPause') ? 'checked' : '',
1068
                                                        'helptext' => __('Pause the slideshow when hovering over slider, then resume when no longer hovering.', 'metaslider')
1069
                                                    ),
1070
                                                    'reverse'          => array(
1071
                                                        'priority' => 70,
1072
                                                        'type'     => 'checkbox',
1073
                                                        'label'    => __('Reverse', 'metaslider'),
1074
                                                        'class'    => 'option flex',
1075
                                                        'checked'  => 'true' === $this->slider->get_setting('reverse') ? 'checked' : '',
1076
                                                        'helptext' => __('Reverse the animation direction', 'metaslider')
1077
                                                    ),
1078
                                                    'delay'            => array(
1079
                                                        'priority' => 80,
1080
                                                        'type'     => 'number',
1081
                                                        'size'     => 3,
1082
                                                        'min'      => 500,
1083
                                                        'max'      => 10000,
1084
                                                        'step'     => 100,
1085
                                                        'value'    => $this->slider->get_setting('delay'),
1086
                                                        'label'    => __('Slide delay', 'metaslider'),
1087
                                                        'class'    => 'option coin flex responsive nivo',
1088
                                                        'helptext' => __('How long to display each slide, in milliseconds', 'metaslider'),
1089
                                                        'after'    => __('ms', 'metaslider')
1090
                                                    ),
1091
                                                    'animationSpeed'   => array(
1092
                                                        'priority' => 90,
1093
                                                        'type'     => 'number',
1094
                                                        'size'     => 3,
1095
                                                        'min'      => 0,
1096
                                                        'max'      => 2000,
1097
                                                        'step'     => 100,
1098
                                                        'value'    => $this->slider->get_setting('animationSpeed'),
1099
                                                        'label'    => __('Animation speed', 'metaslider'),
1100
                                                        'class'    => 'option flex responsive nivo',
1101
                                                        'helptext' => __('Set the speed of animations, in milliseconds', 'metaslider'),
1102
                                                        'after'    => __('ms', 'metaslider')
1103
                                                    ),
1104
                                                    'slices'           => array(
1105
                                                        'priority' => 100,
1106
                                                        'type'     => 'number',
1107
                                                        'size'     => 3,
1108
                                                        'min'      => 0,
1109
                                                        'max'      => 20,
1110
                                                        'step'     => 1,
1111
                                                        'value'    => $this->slider->get_setting('slices'),
1112
                                                        'label'    => __('Number of slices', 'metaslider'),
1113
                                                        'class'    => 'option nivo',
1114
                                                        'helptext' => __('Number of slices', 'metaslider'),
1115
                                                        'after'    => __('ms', 'metaslider')
1116
                                                    ),
1117
                                                    'spw'              => array(
1118
                                                        'priority' => 110,
1119
                                                        'type'     => 'number',
1120
                                                        'size'     => 3,
1121
                                                        'min'      => 0,
1122
                                                        'max'      => 20,
1123
                                                        'step'     => 1,
1124
                                                        'value'    => $this->slider->get_setting('spw'),
1125
                                                        'label'    => __('Number of squares', 'metaslider') . ' (' . __('Width', 'metaslider') . ')',
1126
                                                        'class'    => 'option nivo',
1127
                                                        'helptext' => __('Number of squares', 'metaslider'),
1128
                                                        'after'    => ''
1129
                                                    ),
1130
                                                    'sph'              => array(
1131
                                                        'priority' => 120,
1132
                                                        'type'     => 'number',
1133
                                                        'size'     => 3,
1134
                                                        'min'      => 0,
1135
                                                        'max'      => 20,
1136
                                                        'step'     => 1,
1137
                                                        'value'    => $this->slider->get_setting('sph'),
1138
                                                        'label'    => __('Number of squares', 'metaslider') . ' (' . __('Height', 'metaslider') . ')',
1139
                                                        'class'    => 'option nivo',
1140
                                                        'helptext' => __('Number of squares', 'metaslider'),
1141
                                                        'after'    => ''
1142
                                                    ),
1143
                                                    'direction'        => array(
1144
                                                        'priority' => 130,
1145
                                                        'type'     => 'select',
1146
                                                        'label'    => __('Slide direction', 'metaslider'),
1147
                                                        'class'    => 'option flex',
1148
                                                        'helptext' => __('Select the sliding direction', 'metaslider'),
1149
                                                        'value'    => $this->slider->get_setting('direction'),
1150
                                                        'options'  => array(
1151
                                                            'horizontal' => array('label' => __('Horizontal', 'metaslider'), 'class' => ''),
1152
                                                            'vertical'   => array('label' => __('Vertical', 'metaslider'), 'class' => '')
1153
                                                        )
1154
                                                    ),
1155
                                                    'easing'           => array(
1156
                                                        'priority' => 140,
1157
                                                        'type'     => 'select',
1158
                                                        'label'    => __('Easing', 'metaslider'),
1159
                                                        'class'    => 'option flex',
1160
                                                        'helptext' => __('Animation easing effect', 'metaslider'),
1161
                                                        'value'    => $this->slider->get_setting('easing'),
1162
                                                        'options'  => $this->get_easing_options()
1163
                                                    ),
1164
                                                    'prevText'         => array(
1165
                                                        'priority' => 150,
1166
                                                        'type'     => 'text',
1167
                                                        'label'    => __('Previous text', 'metaslider'),
1168
                                                        'class'    => 'option coin flex responsive nivo',
1169
                                                        'helptext' => __("Set the text for the 'previous' direction item", 'metaslider'),
1170
                                                        'value'    => 'false' === $this->slider->get_setting('prevText') ? '' : $this->slider->get_setting('prevText')
1171
                                                    ),
1172
                                                    'nextText'         => array(
1173
                                                        'priority' => 160,
1174
                                                        'type'     => 'text',
1175
                                                        'label'    => __('Next text', 'metaslider'),
1176
                                                        'class'    => 'option coin flex responsive nivo',
1177
                                                        'helptext' => __("Set the text for the 'next' direction item", 'metaslider'),
1178
                                                        'value'    => 'false' === $this->slider->get_setting('nextText') ? '' : $this->slider->get_setting('nextText')
1179
                                                    ),
1180
                                                    'sDelay'           => array(
1181
                                                        'priority' => 170,
1182
                                                        'type'     => 'number',
1183
                                                        'size'     => 3,
1184
                                                        'min'      => 0,
1185
                                                        'max'      => 500,
1186
                                                        'step'     => 10,
1187
                                                        'value'    => $this->slider->get_setting('sDelay'),
1188
                                                        'label'    => __('Square delay', 'metaslider'),
1189
                                                        'class'    => 'option coin',
1190
                                                        'helptext' => __('Delay between squares in ms', 'metaslider'),
1191
                                                        'after'    => __('ms', 'metaslider')
1192
                                                    ),
1193
                                                    'opacity'          => array(
1194
                                                        'priority' => 180,
1195
                                                        'type'     => 'number',
1196
                                                        'size'     => 3,
1197
                                                        'min'      => 0,
1198
                                                        'max'      => 1,
1199
                                                        'step'     => 0.1,
1200
                                                        'value'    => $this->slider->get_setting('opacity'),
1201
                                                        'label'    => __('Opacity', 'metaslider'),
1202
                                                        'class'    => 'option coin',
1203
                                                        'helptext' => __('Opacity of title and navigation', 'metaslider'),
1204
                                                        'after'    => ''
1205
                                                    ),
1206
                                                    'titleSpeed'       => array(
1207
                                                        'priority' => 190,
1208
                                                        'type'     => 'number',
1209
                                                        'size'     => 3,
1210
                                                        'min'      => 0,
1211
                                                        'max'      => 10000,
1212
                                                        'step'     => 100,
1213
                                                        'value'    => $this->slider->get_setting('titleSpeed'),
1214
                                                        'label'    => __('Caption speed', 'metaslider'),
1215
                                                        'class'    => 'option coin',
1216
                                                        'helptext' => __('Set the fade in speed of the caption', 'metaslider'),
1217
                                                        'after'    => __('ms', 'metaslider')
1218
                                                    ),
1219
                                                    'developerOptions' => array(
1220
                                                        'priority' => 195,
1221
                                                        'type'     => 'divider',
1222
                                                        'class'    => 'option coin flex responsive nivo',
1223
                                                        'value'    => __('Developer options', 'metaslider')
1224
                                                    ),
1225
                                                    'cssClass'         => array(
1226
                                                        'priority' => 200,
1227
                                                        'type'     => 'text',
1228
                                                        'label'    => __('CSS classes', 'metaslider'),
1229
                                                        'class'    => 'option coin flex responsive nivo',
1230
                                                        'helptext' => __('Specify any custom CSS Classes you would like to be added to the slider wrapper', 'metaslider'),
1231
                                                        'value'    => 'false' === $this->slider->get_setting('cssClass') ? '' : $this->slider->get_setting('cssClass')
1232
                                                    ),
1233
                                                    'printCss'         => array(
1234
                                                        'priority' => 210,
1235
                                                        'type'     => 'checkbox',
1236
                                                        'label'    => __('Print CSS', 'metaslider'),
1237
                                                        'class'    => 'option coin flex responsive nivo useWithCaution',
1238
                                                        'checked'  => 'true' === $this->slider->get_setting('printCss') ? 'checked' : '',
1239
                                                        'helptext' => __('Uncheck this is you would like to include your own CSS', 'metaslider')
1240
                                                    ),
1241
                                                    'printJs'          => array(
1242
                                                        'priority' => 220,
1243
                                                        'type'     => 'checkbox',
1244
                                                        'label'    => __('Print JS', 'metaslider'),
1245
                                                        'class'    => 'option coin flex responsive nivo useWithCaution',
1246
                                                        'checked'  => 'true' === $this->slider->get_setting('printJs') ? 'checked' : '',
1247
                                                        'helptext' => __('Uncheck this is you would like to include your own Javascript', 'metaslider')
1248
                                                    ),
1249
                                                    'noConflict'       => array(
1250
                                                        'priority' => 230,
1251
                                                        'type'     => 'checkbox',
1252
                                                        'label'    => __('No conflict mode', 'metaslider'),
1253
                                                        'class'    => 'option flex',
1254
                                                        'checked'  => 'true' === $this->slider->get_setting('noConflict') ? 'checked' : '',
1255
                                                        'helptext' => __('Delay adding the flexslider class to the slideshow', 'metaslider')
1256
                                                    )
1257
                                                );
1258
1259
        $aFields = apply_filters('metaslider_advanced_settings', $aFields, $this->slider);
1260
1261
        echo $this->build_settings_rows($aFields); ?>
1262
                                                </tbody>
1263
                                            </table>
1264
                                        </div>
1265
                                    </div>
1266
1267
                                    <div class="postbox shortcode ms-toggle">
1268
                                        <div class="handlediv" title="Click to toggle"><br></div>
1269
                                        <h3 class="hndle"><span><?php _e('Usage', 'metaslider') ?></span></h3>
1270
                                        <div class="inside">
1271
                                            <ul class='tabs'>
1272
                                                <li rel='tab-1' class='selected'><?php _e('Shortcode', 'metaslider') ?></li>
1273
                                                <li rel='tab-2'><?php _e('Template Include', 'metaslider') ?></li>
1274
                                            </ul>
1275
                                            <div class='tabs-content'>
1276
                                                <div class='tab tab-1'>
1277
                                                    <p><?php _e('Copy & paste the shortcode directly into any WordPress post or page.', 'metaslider'); ?></p>
1278
                                                    <input readonly='readonly' type='text' value='[metaslider id=<?php echo $this->slider->id ?>]'></div>
1279
                                                <div class='tab tab-2' style='display: none'>
1280
                                                    <p><?php _e('Copy & paste this code into a template file to include the slideshow within your theme.', 'metaslider'); ?></p>
1281
                                                    <textarea readonly='readonly'>&lt;?php &#13;&#10;    echo do_shortcode("[metaslider id=<?php echo $this->slider->id ?>]"); &#13;&#10;?></textarea></div>
1282
                                            </div>
1283
                                        </div>
1284
                                    </div>
1285
1286
                                    <div class="postbox social">
1287
                                        <div class="inside">
1288
                                            <ul class='info'>
1289
                                                <li style='width: 33%;'>
1290
                                                    <a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.metaslider.com" data-text="Check out Meta Slider, an easy to use slideshow plugin for WordPress" data-hashtags="metaslider, wordpress, slideshow">Tweet</a>
1291
                                                    <script>!function (d, s, id) {
1292
                                                            var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/.test(d.location) ? 'http' : 'https';
1293
                                                            if (!d.getElementById(id)) {
1294
                                                                js = d.createElement(s);
1295
                                                                js.id = id;
1296
                                                                js.src = p + '://platform.twitter.com/widgets.js';
1297
                                                                fjs.parentNode.insertBefore(js, fjs);
1298
                                                            }
1299
                                                        }(document, 'script', 'twitter-wjs');</script>
1300
                                                </li>
1301
                                                <li style='width: 34%;'>
1302
                                                    <div class="g-plusone" data-size="medium" data-href="http://www.metaslider.com"></div>
1303
                                                    <script type="text/javascript">
1304
                                                        (function () {
1305
                                                            var po = document.createElement('script');
1306
                                                            po.type = 'text/javascript';
1307
                                                            po.async = true;
1308
                                                            po.src = 'https://apis.google.com/js/plusone.js';
1309
                                                            var s = document.getElementsByTagName('script')[0];
1310
                                                            s.parentNode.insertBefore(po, s);
1311
                                                        })();
1312
                                                    </script>
1313
                                                </li>
1314
                                                <li style='width: 33%;'>
1315
                                                    <iframe style='border:none; overflow:hidden; width:80px; height:21px;'
1316
                                                            src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.metaslider.com&amp;send=false&amp;layout=button_count&amp;width=90&amp;show_faces=false&amp;font&amp;colorscheme=light&amp;action=like&amp;height=21&amp;appId=156668027835524"
1317
                                                            scrolling="no" frameborder="0" allowTransparency="true"></iframe>
1318
                                                </li>
1319
                                            </ul>
1320
                                        </div>
1321
                                    </div>
1322
                                    <a class='delete-slider alignright button-secondary confirm' href='<?php echo wp_nonce_url("?page=metaslider&amp;delete={$this->slider->id}", 'metaslider_delete_slider'); ?>'><?php _e('Delete Slider', 'metaslider') ?></a>
1323
                                </div>
1324
                            </div>
1325
                        </div>
1326
                    </div>
1327
                </div>
1328
            </form>
1329
        </div>
1330
        <?php
1331
    }
1332
1333
    /**
1334
     * Append the 'Add Slider' button to selected admin pages
1335
     * @param $context
1336
     * @return string
1337
     */
1338
    public function insert_metaslider_button($context)
1339
    {
1340
        global $pagenow;
1341
1342
        if (in_array($pagenow, array('post.php', 'page.php', 'post-new.php', 'post-edit.php'))) {
1343
            $context .= '<a href="#TB_inline?&inlineId=choose-meta-slider" class="thickbox button" title="'
1344
                        . __('Select slideshow to insert into post', 'metaslider')
1345
                        . '"><span class="wp-media-buttons-icon" style="background: url('
1346
                        . METASLIDER_ASSETS_URL
1347
                        . '/metaslider/matchalabs.png); background-repeat: no-repeat; background-position: left bottom;"></span> '
1348
                        . __('Add slider', 'metaslider')
1349
                        . '</a>';
1350
        }
1351
1352
        return $context;
1353
    }
1354
1355
    /**
1356
     * Append the 'Choose Meta Slider' thickbox content to the bottom of selected admin pages
1357
     */
1358
    public function admin_footer()
1359
    {
1360
        global $pagenow;
1361
1362
        // Only run in post/page creation and edit screens
1363
        if (in_array($pagenow, array('post.php', 'page.php', 'post-new.php', 'post-edit.php'))) {
1364
            $sliders = $this->all_meta_sliders('title'); ?>
1365
1366
            <script type="text/javascript">
1367
                jQuery(document).ready(function () {
1368
                    jQuery('#insertMetaSlider').on('click', function () {
1369
                        var id = jQuery('#metaslider-select option:selected').val();
1370
                        window.send_to_editor('[metaslider id="' + id + '"]');
1371
                        tb_remove();
1372
                    })
1373
                });
1374
            </script>
1375
1376
            <div id="choose-meta-slider" style="display: none;">
1377
                <div class="wrap">
1378
                    <?php
1379
                    if (count($sliders)) {
1380
                        echo "<h3 style='margin-bottom: 20px;'>" . __('Insert Meta Slider', 'metaslider') . '</h3>';
1381
                        echo "<select id='metaslider-select'>";
1382
                        echo '<option disabled=disabled>' . __('Choose slideshow', 'metaslider') . '</option>';
1383
                        foreach ($sliders as $slider) {
1384
                            echo "<option value='{$slider['id']}'>{$slider['title']}</option>";
1385
                        }
1386
                        echo '</select>';
1387
                        echo "<button class='button primary' id='insertMetaSlider'>Insert Slideshow</button>";
1388
                    } else {
1389
                        _e('No slideshows found', 'metaslider');
1390
                    } ?>
1391
                </div>
1392
            </div>
1393
            <?php
1394
        }
1395
    }
1396
}
1397
1398
$metaslider = new MetaSliderPlugin();
1399
1400
?>
1401