Passed
Push — master ( 8d8e58...047d50 )
by Michael
02:21
created

MetaSliderPlugin   F

Complexity

Total Complexity 123

Size/Duplication

Total Lines 1339
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1339
rs 0.6314
c 0
b 0
f 0
wmc 123

30 Methods

Rating   Name   Duplication   Size   Complexity  
B get_easing_options() 0 46 2
A insert_metaslider_button() 0 15 2
A system_check() 0 4 1
B admin_footer() 0 34 4
B custom_media_uploader_tabs() 0 16 5
A upgrade_to_pro() 0 7 3
A compare_elems() 0 3 1
A help_tab() 0 9 1
B register_admin_scripts() 0 41 2
A find_slider() 0 23 2
A register_post_type() 0 9 1
A register_taxonomy() 0 7 1
A register_admin_menu() 0 13 1
B all_meta_sliders() 0 32 4
B create_slider() 0 13 5
C custom_media_upload_tab_name() 0 25 8
F render_admin_page() 0 548 32
A iframe() 0 16 1
A load_plugin_textdomain() 0 3 1
B add_slider() 0 32 3
A set_slider() 0 11 3
C admin_process() 0 32 7
A delete_slider() 0 12 1
A register_slide_types() 0 3 1
A metaslider_pro_tab() 0 4 3
B __construct() 0 29 1
F build_settings_rows() 0 110 20
A go_pro_cta() 0 10 3
A register_admin_styles() 0 7 1
A register_shortcode() 0 19 3

How to fix   Complexity   

Complex Class

Complex classes like MetaSliderPlugin often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use MetaSliderPlugin, and based on these observations, apply Extract Interface, too.

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 22 and the first side effect is on line 19.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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__)
0 ignored issues
show
Bug introduced by
The function plugins_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
define('METASLIDER_BASE_URL', /** @scrutinizer ignore-call */ plugins_url('ml-slider') . '/'); //plugin_dir_url(__FILE__)
Loading history...
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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);
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
        /** @scrutinizer ignore-call */ 
65
        add_action('admin_menu', array($this, 'register_admin_menu'), 9553);
Loading history...
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'));
0 ignored issues
show
Bug introduced by
The function add_shortcode was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

72
        /** @scrutinizer ignore-call */ 
73
        add_shortcode('metaslider', array($this, 'register_shortcode'));
Loading history...
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);
0 ignored issues
show
Bug introduced by
The function add_filter was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

75
        /** @scrutinizer ignore-call */ 
76
        add_filter('media_upload_tabs', array($this, 'custom_media_upload_tab_name'), 998);
Loading history...
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__);
0 ignored issues
show
Bug introduced by
The function plugin_basename was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

86
        $plugin = /** @scrutinizer ignore-call */ plugin_basename(__FILE__);
Loading history...
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>';
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

109
            $links[] = '<a href="http://www.metaslider.com/upgrade" target="_blank">' . /** @scrutinizer ignore-call */ __('Go Pro', 'metaslider') . '</a>';
Loading history...
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'));
0 ignored issues
show
Bug introduced by
The function wp_iframe was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

121
            return /** @scrutinizer ignore-call */ wp_iframe(array($this, 'iframe'));
Loading history...
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);
0 ignored issues
show
Bug introduced by
The function wp_enqueue_style was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

130
        /** @scrutinizer ignore-call */ 
131
        wp_enqueue_style('metaslider-admin-styles', METASLIDER_ASSETS_URL . 'metaslider/admin.css', false, METASLIDER_VERSION);
Loading history...
131
        wp_enqueue_script('google-font-api', 'http://fonts.googleapis.com/css?family=PT+Sans:400,700');
0 ignored issues
show
Bug introduced by
The function wp_enqueue_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

131
        /** @scrutinizer ignore-call */ 
132
        wp_enqueue_script('google-font-api', 'http://fonts.googleapis.com/css?family=PT+Sans:400,700');
Loading history...
132
133
        $link = apply_filters('metaslider_hoplink', 'http://www.metaslider.com/upgrade/');
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

133
        $link = /** @scrutinizer ignore-call */ apply_filters('metaslider_hoplink', 'http://www.metaslider.com/upgrade/');
Loading history...
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();
0 ignored issues
show
Unused Code introduced by
The assignment to $image is dead and can be removed.
Loading history...
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/');
0 ignored issues
show
Bug introduced by
The function plugin_basename was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

159
        load_plugin_textdomain('metaslider', false, dirname(/** @scrutinizer ignore-call */ plugin_basename(__FILE__)) . '/languages/');
Loading history...
Bug introduced by
The function load_plugin_textdomain was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

159
        /** @scrutinizer ignore-call */ 
160
        load_plugin_textdomain('metaslider', false, dirname(plugin_basename(__FILE__)) . '/languages/');
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

171
            $strings['insertMediaTitle'] = /** @scrutinizer ignore-call */ __('Image', 'metaslider');
Loading history...
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'),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

201
                    'post_feed' => /** @scrutinizer ignore-call */ __('Post Feed', 'metaslider'),
Loading history...
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);
0 ignored issues
show
Bug introduced by
The function wp_enqueue_style was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

223
        /** @scrutinizer ignore-call */ 
224
        wp_enqueue_style('metaslider-admin-styles', METASLIDER_ASSETS_URL . 'metaslider/admin.css', false, METASLIDER_VERSION);
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function do_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

227
        /** @scrutinizer ignore-call */ 
228
        do_action('metaslider_register_admin_styles');
Loading history...
228
    }
229
230
    /**
231
     * Register admin JavaScript
232
     */
233
    public function register_admin_scripts()
234
    {
235
        if (wp_script_is('wp-auth-check', 'queue')) {
0 ignored issues
show
Bug introduced by
The function wp_script_is was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

235
        if (/** @scrutinizer ignore-call */ wp_script_is('wp-auth-check', 'queue')) {
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function wp_deregister_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

241
            /** @scrutinizer ignore-call */ 
242
            wp_deregister_script('wp-auth-check');
Loading history...
242
            wp_register_script('wp-auth-check', null); // fix php notice
0 ignored issues
show
Bug introduced by
The function wp_register_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

242
            /** @scrutinizer ignore-call */ 
243
            wp_register_script('wp-auth-check', null); // fix php notice
Loading history...
243
        }
244
245
        // media library dependencies
246
        wp_enqueue_media();
0 ignored issues
show
Bug introduced by
The function wp_enqueue_media was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

246
        /** @scrutinizer ignore-call */ 
247
        wp_enqueue_media();
Loading history...
247
248
        // plugin dependencies
249
        wp_enqueue_script('jquery-ui-core', array('jquery'));
0 ignored issues
show
Bug introduced by
The function wp_enqueue_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

249
        /** @scrutinizer ignore-call */ 
250
        wp_enqueue_script('jquery-ui-core', array('jquery'));
Loading history...
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(
0 ignored issues
show
Bug introduced by
The function wp_localize_script was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

257
        /** @scrutinizer ignore-call */ 
258
        wp_localize_script('metaslider-admin-addslide', 'metaslider_image', array(
Loading history...
258
            'addslide_nonce' => wp_create_nonce('metaslider_addslide')
0 ignored issues
show
Bug introduced by
The function wp_create_nonce was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

258
            'addslide_nonce' => /** @scrutinizer ignore-call */ wp_create_nonce('metaslider_addslide')
Loading history...
259
        ));
260
261
        // localise the JS
262
        wp_localize_script('metaslider-admin-script', 'metaslider', array(
263
            'url'            => __('URL', 'metaslider'),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

263
            'url'            => /** @scrutinizer ignore-call */ __('URL', 'metaslider'),
Loading history...
264
            'caption'        => __('Caption', 'metaslider'),
265
            'new_window'     => __('New Window', 'metaslider'),
266
            'confirm'        => __('Are you sure?', 'metaslider'),
267
            'ajaxurl'        => admin_url('admin-ajax.php'),
0 ignored issues
show
Bug introduced by
The function admin_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

267
            'ajaxurl'        => /** @scrutinizer ignore-call */ admin_url('admin-ajax.php'),
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function do_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

273
        /** @scrutinizer ignore-call */ 
274
        do_action('metaslider_register_admin_scripts');
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

281
        $title = /** @scrutinizer ignore-call */ apply_filters('metaslider_menu_title', 'Meta Slider');
Loading history...
282
283
        $page = add_menu_page($title, $title, 'edit_others_posts', 'metaslider', array(
0 ignored issues
show
Bug introduced by
The function add_menu_page was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

283
        $page = /** @scrutinizer ignore-call */ add_menu_page($title, $title, 'edit_others_posts', 'metaslider', array(
Loading history...
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'));
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

289
        /** @scrutinizer ignore-call */ 
290
        add_action('admin_print_scripts-' . $page, array($this, 'register_admin_scripts'));
Loading history...
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/');
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

300
            $link = /** @scrutinizer ignore-call */ apply_filters('metaslider_hoplink', 'http://www.metaslider.com/upgrade/');
Loading history...
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>';
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

304
            $goPro = "<div style='display: none;' id='screen-options-link-wrap'><a target='_blank' class='show-settings' href='{$link}'>Meta Slider v" . METASLIDER_VERSION . ' - ' . /** @scrutinizer ignore-call */ __('Upgrade to Pro $19', 'metaslider') . '</a></div>';
Loading history...
305
306
            echo $goPro;
307
        }
308
    }
309
310
    /**
311
     *
312
     */
313
    public function help_tab()
314
    {
315
        $screen = get_current_screen();
0 ignored issues
show
Bug introduced by
The function get_current_screen was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

315
        $screen = /** @scrutinizer ignore-call */ get_current_screen();
Loading history...
316
317
        // documentation tab
318
        $screen->add_help_tab(array(
319
                                  'id'      => 'documentation',
320
                                  'title'   => __('Documentation'),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

320
                                  'title'   => /** @scrutinizer ignore-call */ __('Documentation'),
Loading history...
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(
0 ignored issues
show
Bug introduced by
The function register_post_type was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

330
        /** @scrutinizer ignore-call */ 
331
        register_post_type('ml-slider', array(
Loading history...
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(
0 ignored issues
show
Bug introduced by
The function register_taxonomy was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

346
        /** @scrutinizer ignore-call */ 
347
        register_taxonomy('ml-slider', 'attachment', array(
Loading history...
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;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type string.
Loading history...
364
        }
365
366
        // we have an ID to work with
367
        $slider = get_post($atts['id']);
0 ignored issues
show
Bug introduced by
The function get_post was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

367
        $slider = /** @scrutinizer ignore-call */ get_post($atts['id']);
Loading history...
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 expression return false returns the type false which is incompatible with the documented return type string.
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);
0 ignored issues
show
Bug introduced by
The function get_post_meta was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

390
        $settings = array_merge(/** @scrutinizer ignore-call */ get_post_meta($id, 'ml-slider_settings', true), $shortcode_settings);
Loading history...
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'):
0 ignored issues
show
Coding Style introduced by
As per coding-style, case should be followed by a single space.

As per the PSR-2 coding standard, there must be a space after the case keyword, instead of the test immediately following it.

switch (true) {
    case!isset($a):  //wrong
        doSomething();
        break;
    case !isset($b):  //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
410
                return new MetaCoinSlider($id, $shortcode_settings);
0 ignored issues
show
Bug Best Practice introduced by
The expression return new MetaCoinSlide...d, $shortcode_settings) returns the type MetaCoinSlider which is incompatible with the documented return type MetaNivoSlider|MetaResponsiveSlider|MetaFlexSlider.
Loading history...
411
            case('flex'):
0 ignored issues
show
Coding Style introduced by
As per coding-style, case should be followed by a single space.

As per the PSR-2 coding standard, there must be a space after the case keyword, instead of the test immediately following it.

switch (true) {
    case!isset($a):  //wrong
        doSomething();
        break;
    case !isset($b):  //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
412
                return new MetaFlexSlider($id, $shortcode_settings);
413
            case('nivo'):
0 ignored issues
show
Coding Style introduced by
As per coding-style, case should be followed by a single space.

As per the PSR-2 coding standard, there must be a space after the case keyword, instead of the test immediately following it.

switch (true) {
    case!isset($a):  //wrong
        doSomething();
        break;
    case !isset($b):  //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
414
                return new MetaNivoSlider($id, $shortcode_settings);
415
            case('responsive'):
0 ignored issues
show
Coding Style introduced by
As per coding-style, case should be followed by a single space.

As per the PSR-2 coding standard, there must be a space after the case keyword, instead of the test immediately following it.

switch (true) {
    case!isset($a):  //wrong
        doSomething();
        break;
    case !isset($b):  //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
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()) {
0 ignored issues
show
Bug introduced by
The function is_admin was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

428
        if (!/** @scrutinizer ignore-call */ is_admin()) {
Loading history...
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)) {
0 ignored issues
show
Bug introduced by
The function get_post was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

450
            if (/** @scrutinizer ignore-call */ get_post($temp_id)) {
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function check_admin_referer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

466
        /** @scrutinizer ignore-call */ 
467
        check_admin_referer('metaslider_add_slider');
Loading history...
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);
0 ignored issues
show
Bug introduced by
The function get_post_meta was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

472
            $defaults = /** @scrutinizer ignore-call */ get_post_meta($last_modified, 'ml-slider_settings', true);
Loading history...
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());
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $id seems to be never defined.
Loading history...
478
            $defaults = $slider->get_default_parameters();
479
        }
480
481
        // insert the post
482
        $id = wp_insert_post(array(
0 ignored issues
show
Bug introduced by
The function wp_insert_post was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

482
        $id = /** @scrutinizer ignore-call */ wp_insert_post(array(
Loading history...
483
                                 'post_title'  => __('New Slider', 'metaslider'),
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

483
                                 'post_title'  => /** @scrutinizer ignore-call */ __('New Slider', 'metaslider'),
Loading history...
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);
0 ignored issues
show
Bug introduced by
The function add_post_meta was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

489
        /** @scrutinizer ignore-call */ 
490
        add_post_meta($id, 'ml-slider_settings', $defaults, true);
Loading history...
490
491
        // create the taxonomy term, the term is the ID of the slider itself
492
        wp_insert_term($id, 'ml-slider');
0 ignored issues
show
Bug introduced by
The function wp_insert_term was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

492
        /** @scrutinizer ignore-call */ 
493
        wp_insert_term($id, 'ml-slider');
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function check_admin_referer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

506
        /** @scrutinizer ignore-call */ 
507
        check_admin_referer('metaslider_delete_slider');
Loading history...
507
508
        // send the post to trash
509
        wp_update_post(array(
0 ignored issues
show
Bug introduced by
The function wp_update_post was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

509
        /** @scrutinizer ignore-call */ 
510
        wp_update_post(array(
Loading history...
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);
0 ignored issues
show
Bug introduced by
The type WP_Query was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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();
0 ignored issues
show
Bug introduced by
The function wp_reset_query was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

544
        /** @scrutinizer ignore-call */ 
545
        wp_reset_query();
Loading history...
545
546
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type integer.
Loading history...
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);
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

570
        $args = /** @scrutinizer ignore-call */ apply_filters('metaslider_all_meta_sliders_args', $args);
Loading history...
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(),
0 ignored issues
show
Bug introduced by
The function get_the_title was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

580
                'title'  => /** @scrutinizer ignore-call */ get_the_title(),
Loading history...
581
                'id'     => $the_query->post->ID
582
            );
583
        }
584
585
        wp_reset_query();
0 ignored issues
show
Bug introduced by
The function wp_reset_query was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

585
        /** @scrutinizer ignore-call */ 
586
        wp_reset_query();
Loading history...
586
587
        return $sliders;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $sliders returns the type false which is incompatible with the documented return type array.
Loading history...
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);
0 ignored issues
show
Bug introduced by
The function checked was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

632
                    $checked        = /** @scrutinizer ignore-call */ checked($k, $row['value'], false);
Loading history...
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);
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

639
                $return .= /** @scrutinizer ignore-call */ apply_filters('metaslider_navigation_options', $navigation_row, $this->slider);
Loading history...
640
            }
641
642
            // navigation row
643
            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);
0 ignored issues
show
Bug introduced by
The function selected was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

684
                    $selected = /** @scrutinizer ignore-call */ selected($k, $row['value'], false);
Loading history...
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
            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
            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
            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;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $return seems to be defined by a foreach iteration on line 762. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
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); ?>
0 ignored issues
show
Bug introduced by
The function apply_filters was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

780
        $max_tabs = /** @scrutinizer ignore-call */ apply_filters('metaslider_max_tabs', 0); ?>
Loading history...
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);
0 ignored issues
show
Bug introduced by
The function wp_nonce_field was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

791
                    /** @scrutinizer ignore-call */ 
792
                    wp_nonce_field('metaslider_save_' . $this->slider->id);
Loading history...
792
                }
793
794
        $title   = '';
795
        $add_url = wp_nonce_url('?page=metaslider&amp;add=true', 'metaslider_add_slider');
0 ignored issues
show
Bug introduced by
The function wp_nonce_url was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

795
        $add_url = /** @scrutinizer ignore-call */ wp_nonce_url('?page=metaslider&amp;add=true', 'metaslider_add_slider');
Loading history...
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>';
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

800
                    echo "<div id='message' class='updated'><p>" . /** @scrutinizer ignore-call */ __("New slideshow created. Click 'Add Slide' to get started!", 'metaslider') . '</p></div>';
Loading history...
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>
0 ignored issues
show
Bug introduced by
The function _e was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

850
                                            <h3><?php /** @scrutinizer ignore-call */ _e('Slides', 'metaslider') ?></h3>
Loading history...
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;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
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')
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1344
                        . /** @scrutinizer ignore-call */ __('Select slideshow to insert into post', 'metaslider')
Loading history...
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;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
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>';
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1380
                        echo "<h3 style='margin-bottom: 20px;'>" . /** @scrutinizer ignore-call */ __('Insert Meta Slider', 'metaslider') . '</h3>';
Loading history...
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');
0 ignored issues
show
Bug introduced by
The function _e was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1389
                        /** @scrutinizer ignore-call */ 
1390
                        _e('No slideshows found', 'metaslider');
Loading history...
1390
                    } ?>
1391
                </div>
1392
            </div>
1393
            <?php
1394
        }
1395
    }
1396
}
1397
1398
$metaslider = new MetaSliderPlugin();
1399
1400
?>
1401