| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Plugin Name: Slideshow Gallery |
|---|
| 4 | Plugin URI: https://tribulant.com/plugins/view/13/ |
|---|
| 5 | Author: Tribulant |
|---|
| 6 | Author URI: https://tribulant.com |
|---|
| 7 | Description: Feature content in a JavaScript powered slideshow gallery showcase on your WordPress website. The slideshow is flexible and all aspects can easily be configured. Embedding or hardcoding the slideshow gallery is a breeze. See the <a href="https://tribulant.com/docs/wordpress-slideshow-gallery/1758/" target="_blank">online documentation</a> for instructions on using and embedding slideshow galleries. Upgrade to the premium version to remove all limitations. |
|---|
| 8 | Version: 1.8.4 |
|---|
| 9 | License: GNU General Public License v2 or later |
|---|
| 10 | License URI: https://www.gnu.org/licenses/gpl-2.0.html |
|---|
| 11 | Tags: slideshow gallery, slideshow, gallery, slider, jquery, bfithumb, galleries, photos, images |
|---|
| 12 | Text Domain: slideshow-gallery |
|---|
| 13 | Domain Path: /languages |
|---|
| 14 | */ |
|---|
| 15 | |
|---|
| 16 | if (!defined('ABSPATH')) exit; // Exit if accessed directly |
|---|
| 17 | |
|---|
| 18 | if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } |
|---|
| 19 | |
|---|
| 20 | $path = dirname(__FILE__) . DS . 'slideshow-gallery-plugin.php'; |
|---|
| 21 | if (file_exists($path)) { |
|---|
| 22 | require_once(dirname(__FILE__) . DS . 'includes' . DS . 'checkinit.php'); |
|---|
| 23 | require_once(dirname(__FILE__) . DS . 'includes' . DS . 'constants.php'); |
|---|
| 24 | require_once($path); |
|---|
| 25 | require_once(dirname(__FILE__) . DS . 'includes' . DS . 'errorhandler.php'); |
|---|
| 26 | require_once(dirname(__FILE__) . DS . 'vendors' . DS . 'otf_regen_thumbs.php'); |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | if (!class_exists('SlideshowGallery')) { |
|---|
| 32 | class SlideshowGallery extends GalleryPlugin { |
|---|
| 33 | public $url; |
|---|
| 34 | public $referer; |
|---|
| 35 | public $plugin_file; |
|---|
| 36 | public $Db; |
|---|
| 37 | public $Html; |
|---|
| 38 | public $Form; |
|---|
| 39 | public $errorhandler; |
|---|
| 40 | |
|---|
| 41 | function __construct() { |
|---|
| 42 | $url = explode("&", $_SERVER['REQUEST_URI']); |
|---|
| 43 | $this -> url = $url[0]; |
|---|
| 44 | $this -> referer = (empty($_SERVER['HTTP_REFERER'])) ? $this -> url : $_SERVER['HTTP_REFERER']; |
|---|
| 45 | $this -> plugin_name = basename(dirname(__FILE__)); |
|---|
| 46 | $this -> plugin_file = plugin_basename(__FILE__); |
|---|
| 47 | $this -> register_plugin($this -> plugin_name, __FILE__); |
|---|
| 48 | $this -> errorhandler = new SlideshowErrorHandler(); |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | //WordPress action hooks |
|---|
| 52 | $this -> add_action('plugins_loaded'); |
|---|
| 53 | $this -> add_action('wp_head'); |
|---|
| 54 | $this -> add_action('wp_footer'); |
|---|
| 55 | $this -> add_action('admin_menu'); |
|---|
| 56 | $this -> add_action('admin_head'); |
|---|
| 57 | $this -> add_action('admin_notices'); |
|---|
| 58 | $this -> add_action('wp_print_styles', 'print_styles'); |
|---|
| 59 | $this -> add_action('admin_print_styles', 'print_styles'); |
|---|
| 60 | $this -> add_action('wp_print_scripts', 'print_scripts'); |
|---|
| 61 | $this -> add_action('admin_print_scripts', 'print_scripts'); |
|---|
| 62 | $this -> add_action('init', 'init_textdomain', 10, 1); |
|---|
| 63 | $this -> add_action('admin_init', 'custom_redirect', 1, 1); |
|---|
| 64 | |
|---|
| 65 | //WordPress Ajax hooks |
|---|
| 66 | $this -> add_action('wp_ajax_slideshow_slides_order', 'ajax_slides_order', 10, 1); |
|---|
| 67 | $this -> add_action('wp_ajax_slideshow_tinymce', 'ajax_tinymce', 10, 1); |
|---|
| 68 | |
|---|
| 69 | //WordPress filter hooks |
|---|
| 70 | $this -> add_filter('mce_buttons'); |
|---|
| 71 | $this -> add_filter('mce_external_plugins'); |
|---|
| 72 | $this -> add_filter("plugin_action_links_" . $this -> plugin_file, 'plugin_action_links', 10, 4); |
|---|
| 73 | |
|---|
| 74 | $this -> add_action('slideshow_ratereviewhook', 'ratereview_hook'); |
|---|
| 75 | $this ->add_action( 'wp_ajax_slideshow_dismiss_smart_rating', 'dismiss_slideshow_smart_rating' ); |
|---|
| 76 | |
|---|
| 77 | if (!is_admin() || wp_doing_ajax()) { |
|---|
| 78 | add_shortcode('slideshow', array($this, 'embed')); |
|---|
| 79 | add_shortcode('tribulant_slideshow', array($this, 'embed')); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | $this -> updating_plugin(); |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | function excerpt_more($more = null) { |
|---|
| 86 | global $slideshow_post; |
|---|
| 87 | $excerptsettings = $this -> get_option('excerptsettings'); |
|---|
| 88 | if (!empty($excerptsettings)) { |
|---|
| 89 | $excerpt_readmore = $this -> get_option('excerpt_readmore'); |
|---|
| 90 | if (!empty($excerpt_readmore)) { |
|---|
| 91 | $more = ' <a href="' . get_permalink($slideshow_post -> ID) . '">' . esc_html($excerpt_readmore) . '</a>'; |
|---|
| 92 | } |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | return $more; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | function excerpt_length($length = null) { |
|---|
| 99 | $excerptsettings = $this -> get_option('excerptsettings'); |
|---|
| 100 | if (!empty($excerptsettings)) { |
|---|
| 101 | $excerpt_length = $this -> get_option('excerpt_length'); |
|---|
| 102 | if (!empty($excerpt_length)) { |
|---|
| 103 | $length = $excerpt_length; |
|---|
| 104 | } |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | return $length; |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | function plugin_action_links($actions = null, $plugin_file = null, $plugin_data = null, $context = null) { |
|---|
| 111 | $this_plugin = plugin_basename(__FILE__); |
|---|
| 112 | |
|---|
| 113 | if (!empty($plugin_file) && $plugin_file == $this_plugin) { |
|---|
| 114 | $actions[] = '<a href="" onclick="jQuery.colorbox({href:ajaxurl + \'?action=slideshow_serialkey&security=' . wp_create_nonce('serialkey') . '\'}); return false;" id="slideshow_submitseriallink"><i class="fa fa-key fa-fw"></i> ' . __('Serial Key', 'slideshow-gallery') . '</a>'; |
|---|
| 115 | $actions[] = '<a href="' . admin_url('admin.php?page=' . $this -> sections -> settings) . '"><i class="fa fa-cog fa-fw"></i> ' . __('Settings', 'slideshow-gallery') . '</a>'; |
|---|
| 116 | |
|---|
| 117 | /*if ($update = $this -> vendor('update')) { |
|---|
| 118 | $version_info = $update -> get_version_info(); |
|---|
| 119 | if (!empty($version_info['dtype']) && $version_info['dtype'] == "single") { |
|---|
| 120 | $actions[] = '<a href="https://tribulant.com/items/upgrade/' . $version_info['item_id'] . '" target="_blank"><i class="fa fa-level-up fa-fw"></i> ' . __('Upgrade', 'slideshow-gallery') . '</a>'; |
|---|
| 121 | } |
|---|
| 122 | }*/ |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | return $actions; |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | function init() { |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | function init_textdomain() { |
|---|
| 132 | $locale = get_locale(); |
|---|
| 133 | |
|---|
| 134 | if (!empty($locale)) { |
|---|
| 135 | if ($locale == "ja" || $locale == "ja_JP") { setlocale(LC_ALL, "ja_JP.UTF8"); } |
|---|
| 136 | } else { |
|---|
| 137 | setlocale(LC_ALL, apply_filters('slideshow_setlocale', $locale)); |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | $mo_file = $this -> plugin_name . '-' . $locale . '.mo'; |
|---|
| 141 | $language_external = $this -> get_option('language_external'); |
|---|
| 142 | |
|---|
| 143 | if (!empty($language_external)) { |
|---|
| 144 | if (function_exists('load_textdomain')) { |
|---|
| 145 | load_textdomain($this -> plugin_name, WP_LANG_DIR . DS . $this -> plugin_name . DS . $mo_file); |
|---|
| 146 | } |
|---|
| 147 | } else { |
|---|
| 148 | if (function_exists('load_plugin_textdomain')) { |
|---|
| 149 | load_plugin_textdomain($this -> plugin_name, false, dirname(plugin_basename(__FILE__)) . DS . 'languages' . DS); |
|---|
| 150 | } |
|---|
| 151 | } |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | function plugins_loaded() { |
|---|
| 155 | $this -> ci_initialize(); |
|---|
| 156 | |
|---|
| 157 | if ($this -> language_do()) { |
|---|
| 158 | add_filter('gettext', array($this, 'language_useordefault'), 0); |
|---|
| 159 | } |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | function wp_head() { |
|---|
| 163 | global $slideshow_javascript, $slideshow_css; |
|---|
| 164 | $slideshow_javascript = array(); |
|---|
| 165 | $slideshow_css = array(); |
|---|
| 166 | |
|---|
| 167 | $this -> render('head', false, true, 'default'); |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | function wp_footer() { |
|---|
| 171 | global $slideshow_javascript, $slideshow_css; |
|---|
| 172 | $jsoutput = $this -> get_option('jsoutput'); |
|---|
| 173 | |
|---|
| 174 | if (!empty($slideshow_javascript)) { |
|---|
| 175 | if (!empty($jsoutput) && $jsoutput == "footerglobal") { |
|---|
| 176 | ?><!-- Slideshow Gallery Javascript BEG --><?php |
|---|
| 177 | |
|---|
| 178 | foreach ($slideshow_javascript as $javascript) { |
|---|
| 179 | //echo wp_unslash($javascript); |
|---|
| 180 | echo html_entity_decode(str_replace("\'", "'", str_replace('\n', '', esc_js($javascript)))); |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | ?><!-- Slideshow Gallery Javascript END --><?php |
|---|
| 184 | } |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | if (!empty($slideshow_css)) { |
|---|
| 188 | if (!empty($jsoutput) && $jsoutput == "footerglobal") { |
|---|
| 189 | ?><!-- Slideshow Gallery CSS BEG --><?php |
|---|
| 190 | |
|---|
| 191 | foreach ($slideshow_css as $css) { |
|---|
| 192 | //echo wp_unslash($css); |
|---|
| 193 | echo html_entity_decode(esc_html($css)); |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | ?><!-- Slideshow Gallery CSS END --><?php |
|---|
| 197 | } |
|---|
| 198 | } |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | function admin_menu() { |
|---|
| 202 | //$update_icon = ($this -> has_update()) ? ' <span class="update-plugins count-1"><span class="update-count">1</span></span>' : ''; |
|---|
| 203 | $update_icon = ''; |
|---|
| 204 | $this -> check_roles(); |
|---|
| 205 | |
|---|
| 206 | add_menu_page(__('Slideshow', 'slideshow-gallery'), __('Slideshow', 'slideshow-gallery') . $update_icon, 'slideshow_slides', $this -> sections -> slides, array($this, 'admin_slides'), false, "26.113"); |
|---|
| 207 | $this -> menus['slideshow-slides'] = add_submenu_page($this -> sections -> slides, __('Manage Slides', 'slideshow-gallery'), __('Manage Slides', 'slideshow-gallery'), 'slideshow_slides', $this -> sections -> slides, array($this, 'admin_slides')); |
|---|
| 208 | $this -> menus['slideshow-galleries'] = add_submenu_page($this -> sections -> slides, __('Manage Galleries', 'slideshow-gallery'), __('Manage Galleries', 'slideshow-gallery'), 'slideshow_galleries', $this -> sections -> galleries, array($this, 'admin_galleries')); |
|---|
| 209 | $this -> menus['slideshow-settings'] = add_submenu_page($this -> sections -> slides, __('Settings', 'slideshow-gallery'), __('Settings', 'slideshow-gallery'), 'slideshow_settings', $this -> sections -> settings, array($this, 'admin_settings')); |
|---|
| 210 | //$this -> menus['slideshow-settings-updates'] = add_submenu_page($this -> sections -> slides, __('Updates', 'slideshow-gallery'), __('Updates', 'slideshow-gallery') . $update_icon, 'slideshow_settings_updates', $this -> sections -> settings_updates, array($this, 'admin_settings_updates')); |
|---|
| 211 | |
|---|
| 212 | if (!$this -> ci_serial_valid()) { |
|---|
| 213 | //$this -> menus['slideshow-submitserial'] = add_submenu_page($this -> sections -> slides, __('Submit Serial Key', 'slideshow-gallery'), __('Submit Serial Key', 'slideshow-gallery'), 'slideshow_submitserial', $this -> sections -> submitserial, array($this, 'admin_submitserial')); |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | add_action("load-" . $this -> menus['slideshow-slides'], array($this, 'screen_options_slides')); |
|---|
| 217 | add_action("load-" . $this -> menus['slideshow-galleries'], array($this, 'screen_options_galleries')); |
|---|
| 218 | |
|---|
| 219 | do_action('slideshow_admin_menu', $this -> menus); |
|---|
| 220 | |
|---|
| 221 | add_action('admin_head-' . $this -> menus['slideshow-settings'], array($this, 'admin_head_gallery_settings')); |
|---|
| 222 | |
|---|
| 223 | add_dashboard_page( |
|---|
| 224 | sprintf('Slideshow Gallery %s', $this -> version), |
|---|
| 225 | sprintf('Slideshow Gallery %s', $this -> version), |
|---|
| 226 | 'read', |
|---|
| 227 | $this -> sections -> about, |
|---|
| 228 | array($this, 'slideshow_gallery_about') |
|---|
| 229 | ); |
|---|
| 230 | |
|---|
| 231 | remove_submenu_page('index.php', $this -> sections -> about); |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | function set_screen_option($status = null, $option = null, $value = null) { |
|---|
| 235 | return $value; |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | function removable_query_args($removable_query_args = array()) { |
|---|
| 239 | |
|---|
| 240 | $removable_query_args[] = 'Galleryupdated'; |
|---|
| 241 | $removable_query_args[] = 'Gallerymessage'; |
|---|
| 242 | |
|---|
| 243 | return $removable_query_args; |
|---|
| 244 | } |
|---|
| 245 | |
|---|
| 246 | function screen_options_slides() { |
|---|
| 247 | $screen = get_current_screen(); |
|---|
| 248 | |
|---|
| 249 | // get out of here if we are not on our settings page |
|---|
| 250 | if (!is_object($screen) || $screen -> id != $this -> menus['slideshow-slides']) { |
|---|
| 251 | return; |
|---|
| 252 | } |
|---|
| 253 | |
|---|
| 254 | $args = array( |
|---|
| 255 | 'label' => __('Slides per page', 'slideshow-gallery'), |
|---|
| 256 | 'default' => 15, |
|---|
| 257 | 'option' => 'slideshow_slides_perpage' |
|---|
| 258 | ); |
|---|
| 259 | |
|---|
| 260 | add_screen_option('per_page', $args); |
|---|
| 261 | |
|---|
| 262 | require_once $this -> plugin_base() . DS . 'includes' . DS . 'class.slide-list-table.php'; |
|---|
| 263 | $Slide_List_Table = new Slide_List_Table; |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | function screen_options_galleries() { |
|---|
| 267 | $screen = get_current_screen(); |
|---|
| 268 | |
|---|
| 269 | // get out of here if we are not on our settings page |
|---|
| 270 | if (!is_object($screen) || $screen -> id != $this -> menus['slideshow-galleries']) { |
|---|
| 271 | return; |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | $args = array( |
|---|
| 275 | 'label' => __('Galleries per page', 'slideshow-gallery'), |
|---|
| 276 | 'default' => 15, |
|---|
| 277 | 'option' => 'slideshow_galleries_perpage' |
|---|
| 278 | ); |
|---|
| 279 | |
|---|
| 280 | add_screen_option('per_page', $args); |
|---|
| 281 | |
|---|
| 282 | require_once $this -> plugin_base() . DS . 'includes' . DS . 'class.gallery-list-table.php'; |
|---|
| 283 | $Gallery_List_Table = new Gallery_List_Table; |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | function default_hidden_columns($hidden = null, $screen = null) { |
|---|
| 287 | if ($current_screen = get_current_screen()) { |
|---|
| 288 | if (($current_screen -> id == $this -> menus['slideshow-slides']) || ($current_screen -> id == $this -> menus['slideshow-galleries'])) { |
|---|
| 289 | switch ($screen -> id) { |
|---|
| 290 | case $this -> menus['slideshow-slides'] : |
|---|
| 291 | $hidden = array( |
|---|
| 292 | 'id', |
|---|
| 293 | 'link', |
|---|
| 294 | 'expiry', |
|---|
| 295 | 'order', |
|---|
| 296 | ); |
|---|
| 297 | break; |
|---|
| 298 | case $this -> menus['slideshow-galleries'] : |
|---|
| 299 | $hidden = array( |
|---|
| 300 | 'id', |
|---|
| 301 | ); |
|---|
| 302 | break; |
|---|
| 303 | } |
|---|
| 304 | } |
|---|
| 305 | } |
|---|
| 306 | |
|---|
| 307 | return $hidden; |
|---|
| 308 | } |
|---|
| 309 | |
|---|
| 310 | function slideshow_gallery_about() { |
|---|
| 311 | $this -> render('about', false, true, 'admin'); |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | function admin_head() { |
|---|
| 315 | $this -> render('head', false, true, 'admin'); |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | function admin_head_gallery_settings() { |
|---|
| 319 | add_meta_box('submitdiv', __('Save Settings', 'slideshow-gallery'), array($this -> Metabox, "settings_submit"), $this -> menus['slideshow-settings'], 'side', 'core'); |
|---|
| 320 | add_meta_box('pluginsdiv', __('Recommended Plugin', 'slideshow-gallery'), array($this -> Metabox, "settings_plugins"), $this -> menus['slideshow-settings'], 'side', 'core'); |
|---|
| 321 | add_meta_box('aboutdiv', __('About This Plugin', 'slideshow-gallery') . $this -> Html -> help(__('More about this plugin and the creators of it', 'slideshow-gallery')), array($this -> Metabox, "settings_about"), $this -> menus['slideshow-settings'], 'side', 'core'); |
|---|
| 322 | add_meta_box('generaldiv', __('General Settings', 'slideshow-gallery') . $this -> Html -> help(__('General settings for the inner workings and some default behaviours', 'slideshow-gallery')), array($this -> Metabox, "settings_general"), $this -> menus['slideshow-settings'], 'normal', 'core'); |
|---|
| 323 | add_meta_box('postsdiv', __('Posts/Pages Settings', 'slideshow-gallery'), array($this -> Metabox, "settings_postspages"), $this -> menus['slideshow-settings'], 'normal', 'core'); |
|---|
| 324 | add_meta_box('linksimagesdiv', __('Links & Images Overlay', 'slideshow-gallery') . $this -> Html -> help(__('Configure the way that slides with links are opened', 'slideshow-gallery')), array($this -> Metabox, "settings_linksimages"), $this -> menus['slideshow-settings'], 'normal', 'core'); |
|---|
| 325 | add_meta_box('stylesdiv', __('Appearance & Styles', 'slideshow-gallery') . $this -> Html -> help(__('Change the way the slideshows look so that it suits your needs', 'slideshow-gallery')), array($this -> Metabox, "settings_styles"), $this -> menus['slideshow-settings'], 'normal', 'core'); |
|---|
| 326 | add_meta_box('techdiv', __('Technical Settings', 'slideshow-gallery'), array($this -> Metabox, "settings_tech"), $this -> menus['slideshow-settings'], 'normal', 'core'); |
|---|
| 327 | add_meta_box('wprelateddiv', __('WordPress Related', 'slideshow-gallery') . $this -> Html -> help(__('Settings specifically related to WordPress', 'slideshow-gallery')), array($this -> Metabox, "settings_wprelated"), $this -> menus['slideshow-settings'], 'normal', 'core'); |
|---|
| 328 | |
|---|
| 329 | global $post; |
|---|
| 330 | do_action('do_meta_boxes', $this -> menus['slideshow-settings'], 'normal', $post); |
|---|
| 331 | do_action('do_meta_boxes', $this -> menus['slideshow-settings'], 'side', $post); |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | function admin_submitserial() { |
|---|
| 335 | $success = false; |
|---|
| 336 | |
|---|
| 337 | if (!empty($_POST)) { |
|---|
| 338 | check_admin_referer($this -> sections -> submitserial); |
|---|
| 339 | |
|---|
| 340 | $serial = sanitize_text_field($_REQUEST['serial']); |
|---|
| 341 | |
|---|
| 342 | if (empty($serial)) { $errors[] = __('Please fill in a serial key.', 'slideshow-gallery'); } |
|---|
| 343 | else { |
|---|
| 344 | $this -> update_option('serialkey', $serial); //update the DB option |
|---|
| 345 | $this -> delete_all_cache('all'); |
|---|
| 346 | |
|---|
| 347 | if (!$this -> ci_serial_valid()) { $errors[] = __('Serial key is invalid, please try again.', 'slideshow-gallery'); } |
|---|
| 348 | else { |
|---|
| 349 | delete_transient($this -> pre . 'update_info'); |
|---|
| 350 | $success = true; |
|---|
| 351 | $this -> redirect(admin_url('admin.php?page=' . $this -> sections -> welcome)); |
|---|
| 352 | } |
|---|
| 353 | } |
|---|
| 354 | } |
|---|
| 355 | |
|---|
| 356 | $this -> render('settings-submitserial', array('success' => $success, 'errors' => $errors), true, 'admin'); |
|---|
| 357 | } |
|---|
| 358 | |
|---|
| 359 | function dismiss_slideshow_smart_rating() { |
|---|
| 360 | $nonce = isset($_POST['nonce']) ? $_POST['nonce'] : ''; |
|---|
| 361 | $action = 'slideshow_feedback_notification_bar_nonce'; |
|---|
| 362 | |
|---|
| 363 | if (!wp_verify_nonce($nonce, $action)) { |
|---|
| 364 | wp_send_json_error(); |
|---|
| 365 | } |
|---|
| 366 | |
|---|
| 367 | if ( false === get_option( 'slideshow_smart_rating_dismissed' ) && false === update_option( 'slideshow_smart_rating_dismissed', false ) ) { |
|---|
| 368 | add_option( 'slideshow_smart_rating_dismissed', true ); |
|---|
| 369 | } |
|---|
| 370 | wp_send_json_success(); |
|---|
| 371 | } |
|---|
| 372 | |
|---|
| 373 | function admin_notices() { |
|---|
| 374 | if ( get_option( 'slideshow_smart_rating_dismissed', false ) ) { |
|---|
| 375 | return; |
|---|
| 376 | } |
|---|
| 377 | |
|---|
| 378 | if (is_admin()) { |
|---|
| 379 | $this -> check_uploaddir(); |
|---|
| 380 | |
|---|
| 381 | $message = (!empty($_GET[$this -> pre . 'message'])) ? wp_kses_html_error($_GET[$this -> pre . 'message']) : false; |
|---|
| 382 | if (!empty($message)) { |
|---|
| 383 | $msg_type = (!empty($_GET[$this -> pre . 'updated'])) ? 'msg' : 'err'; |
|---|
| 384 | call_user_func(array($this, 'render_' . $msg_type), $message); |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | $showmessage_ratereview = $this -> get_option('showmessage_ratereview'); |
|---|
| 388 | |
|---|
| 389 | if (!empty($showmessage_ratereview)) { |
|---|
| 390 | $nonce = wp_create_nonce( 'slideshow_feedback_notification_bar_nonce' ); |
|---|
| 391 | |
|---|
| 392 | $message = sprintf(esc_html__('You have been using the %s for %s days or more. Please consider to %s it or say it %s on %s. %s', 'slideshow-gallery'), |
|---|
| 393 | '<a href="https://wordpress.org/plugins/slideshow-gallery/" target="_blank">Tribulant Slideshow Gallery plugin</a>', |
|---|
| 394 | $showmessage_ratereview, |
|---|
| 395 | '<a class="button" href="https://wordpress.org/support/plugin/slideshow-gallery/reviews/?rate=5#new-post" target="_blank"><i class="fa fa-star"></i> Rate</a>', |
|---|
| 396 | '<a class="button" href="https://wordpress.org/plugins/slideshow-gallery/?compatibility[version]=' . get_bloginfo('version') . '&compatibility[topic_version]=' . $this -> version . '&compatibility[compatible]=1" target="_blank"><i class="fa fa-check"></i> Works</a>', |
|---|
| 397 | '<a href="https://wordpress.org/plugins/slideshow-gallery/" target="_blank">WordPress.org</a>', |
|---|
| 398 | '<button type="button" class="button slideshow-my-custom-dismiss-button" data-nonce="' . $nonce .'">' . __('Dismiss forever', 'slideshow-gallery') . '</button>'); |
|---|
| 399 | |
|---|
| 400 | $dismissable = admin_url('admin.php?page=' . $this -> sections -> settings . '&slideshow_method=hidemessage&message=ratereview'); |
|---|
| 401 | $this -> render_msg($message, $dismissable, false); |
|---|
| 402 | ?> |
|---|
| 403 | <script type="text/javascript"> |
|---|
| 404 | jQuery('.slideshow-my-custom-dismiss-button').on('click', function(e) { |
|---|
| 405 | e.preventDefault(); |
|---|
| 406 | var nonce =jQuery(this).attr('data-nonce'); |
|---|
| 407 | jQuery.post(ajaxurl,{action:'slideshow_dismiss_smart_rating',nonce:nonce}) |
|---|
| 408 | jQuery('.slideshow.notice').hide(); |
|---|
| 409 | }); |
|---|
| 410 | </script> |
|---|
| 411 | <?php |
|---|
| 412 | } |
|---|
| 413 | |
|---|
| 414 | /* Serial key submission message */ |
|---|
| 415 | if (isset($_GET['page'])) { |
|---|
| 416 | $page = sanitize_text_field($_GET['page']); |
|---|
| 417 | } else { |
|---|
| 418 | $page = ""; |
|---|
| 419 | } |
|---|
| 420 | |
|---|
| 421 | if (!$this -> ci_serial_valid() && (empty($page) || $page != $this -> sections -> submitserial)) { |
|---|
| 422 | $hidemessage_upgradetopro = $this -> get_option('hidemessage_upgradetopro'); |
|---|
| 423 | |
|---|
| 424 | if (empty($hidemessage_upgradetopro)) { |
|---|
| 425 | $message = sprintf(esc_html__('You are using Slideshow Gallery LITE. Take your slideshows to the next level with %s. Already purchased? %s.', 'slideshow-gallery'), '<a href="' . admin_url('admin.php?page=' . $this -> sections -> lite_upgrade) . '">Slideshow Gallery PRO</a>', '<a href="https://tribulant.com/docs/wordpress-slideshow-gallery/1758" target="_blank">See instructions to install PRO</a>'); |
|---|
| 426 | $message .= ' <a class="button button-primary" href="' . admin_url('admin.php?page=' . $this -> sections -> lite_upgrade) . '"><i class="fa fa-check"></i> ' . __('Upgrade to PRO', 'slideshow-gallery') . '</a>'; |
|---|
| 427 | $message .= ' <a class="button button-secondary" href="' . admin_url('admin.php?page=' . $this -> sections -> welcome . '&slideshow_method=hidemessage&message=upgradetopro') . '"><i class="fa fa-times"></i> ' . __('Hide this message', 'slideshow-gallery') . '</a>'; |
|---|
| 428 | $dismissable = admin_url('admin.php?page=' . $this -> sections -> welcome . '&slideshow_method=hidemessage&message=upgradetopro'); |
|---|
| 429 | $this -> render_msg($message, $dismissable, false); |
|---|
| 430 | |
|---|
| 431 | ?> |
|---|
| 432 | |
|---|
| 433 | <script type="text/javascript"> |
|---|
| 434 | jQuery(document).ready(function(e) { |
|---|
| 435 | jQuery('#<?php echo esc_attr($this -> pre); ?>submitseriallink').click(function() { |
|---|
| 436 | jQuery.colorbox({href:ajaxurl + "?action=slideshow_serialkey&security=<?php echo wp_create_nonce('serialkey'); ?>"}); |
|---|
| 437 | return false; |
|---|
| 438 | }); |
|---|
| 439 | }); |
|---|
| 440 | </script> |
|---|
| 441 | |
|---|
| 442 | <?php |
|---|
| 443 | } |
|---|
| 444 | } |
|---|
| 445 | |
|---|
| 446 | // Is an Update Available? |
|---|
| 447 | /*if (!empty($page) && in_array($page, (array) $this -> sections)) { |
|---|
| 448 | if (apply_filters('slideshow_updates', true)) { |
|---|
| 449 | if (current_user_can('edit_plugins') && $this -> has_update() && (empty($page) || (!empty($page) && $page != $this -> sections -> settings_updates))) { |
|---|
| 450 | $hideupdate = $this -> get_option('hideupdate'); |
|---|
| 451 | if (empty($hideupdate) || (!empty($hideupdate) && version_compare($this -> version, $hideupdate, '>'))) { |
|---|
| 452 | $update = $this -> vendor('update'); |
|---|
| 453 | $update_info = $update -> get_version_info(); |
|---|
| 454 | $this -> render('update', array('update_info' => $update_info), true, 'admin'); |
|---|
| 455 | } |
|---|
| 456 | } |
|---|
| 457 | } |
|---|
| 458 | }*/ |
|---|
| 459 | } |
|---|
| 460 | |
|---|
| 461 | } |
|---|
| 462 | |
|---|
| 463 | function mce_buttons($buttons) { |
|---|
| 464 | array_push($buttons, "separator", "gallery"); |
|---|
| 465 | return $buttons; |
|---|
| 466 | } |
|---|
| 467 | |
|---|
| 468 | function mce_external_plugins($plugins) { |
|---|
| 469 | $plugins['gallery'] = $this -> url() . '/js/tinymce/editor_plugin.js'; |
|---|
| 470 | return $plugins; |
|---|
| 471 | } |
|---|
| 472 | |
|---|
| 473 | function slideshow($output = true, $post_id = null, $exclude = null) { |
|---|
| 474 | $params['post_id'] = $post_id; |
|---|
| 475 | $params['exclude'] = $exclude; |
|---|
| 476 | |
|---|
| 477 | $content = $this -> embed($params, false); |
|---|
| 478 | |
|---|
| 479 | if ($output == true) { |
|---|
| 480 | echo wp_kses_post($content); |
|---|
| 481 | } else { |
|---|
| 482 | return $content; |
|---|
| 483 | } |
|---|
| 484 | } |
|---|
| 485 | |
|---|
| 486 | function embed($atts = array(), $content = null) { |
|---|
| 487 | //global variables |
|---|
| 488 | global $wpdb; |
|---|
| 489 | $styles = $this -> get_option('styles'); |
|---|
| 490 | |
|---|
| 491 | $effect = $this -> get_option('effect'); |
|---|
| 492 | $slide_direction = $this -> get_option('slide_direction'); |
|---|
| 493 | $easing = $this -> get_option('easing'); |
|---|
| 494 | $autoheight = $this -> get_option('autoheight'); |
|---|
| 495 | |
|---|
| 496 | $this -> add_filter('excerpt_more', 'excerpt_more', 999, 1); |
|---|
| 497 | $this -> add_filter('excerpt_length', 'excerpt_length', 999, 1); |
|---|
| 498 | |
|---|
| 499 | // default shortcode parameters |
|---|
| 500 | $defaults = array( |
|---|
| 501 | 'source' => "slides", |
|---|
| 502 | 'products' => false, |
|---|
| 503 | 'productsnumber' => 10, |
|---|
| 504 | 'featured' => false, |
|---|
| 505 | 'featurednumber' => 10, |
|---|
| 506 | 'featuredtype' => "post", |
|---|
| 507 | 'gallery_id' => false, |
|---|
| 508 | 'orderby' => array('order', "ASC"), |
|---|
| 509 | 'orderf' => false, // order field |
|---|
| 510 | 'orderd' => false, // order direction (ASC/DESC) |
|---|
| 511 | 'resizeimages' => (($styles['resizeimages'] == "Y") ? "true" : "false"), |
|---|
| 512 | 'imagesoverlay' => (($this -> get_option('imagesthickbox') == "Y") ? "true" : "false"), |
|---|
| 513 | 'layout' => ($styles['layout']), |
|---|
| 514 | 'width' => ($styles['width']), |
|---|
| 515 | 'height' => ((empty($autoheight)) ? $styles['height'] : false), |
|---|
| 516 | 'autoheight' => ((!empty($autoheight)) ? "true" : "false"), |
|---|
| 517 | 'autoheight_max' => ($this -> get_option('autoheight_max')), |
|---|
| 518 | 'resheight' => ($styles['resheight']), |
|---|
| 519 | 'resheighttype' => ($styles['resheighttype']), |
|---|
| 520 | 'auto' => (($this -> get_option('autoslide') == "Y") ? "true" : "false"), |
|---|
| 521 | 'effect' => ((empty($effect) || (!empty($effect) && $effect == "fade")) ? 'fade' : $effect), |
|---|
| 522 | 'slide_direction' => ((empty($slide_direction) || (!empty($slide_direction) && $slide_direction == "lr")) ? 'lr' : 'tb'), |
|---|
| 523 | 'easing' => ((empty($easing)) ? 'swing' : $easing), |
|---|
| 524 | 'autospeed' => ($this -> get_option('autospeed')), |
|---|
| 525 | 'alwaysauto' => ($this -> get_option('alwaysauto')), |
|---|
| 526 | 'fadespeed' => ($this -> get_option('fadespeed')), |
|---|
| 527 | 'shownav' => (($this -> get_option('shownav') == "Y") ? "true" : "false"), |
|---|
| 528 | 'navopacity' => ($this -> get_option('navopacity')), |
|---|
| 529 | 'navhoveropacity' => ($this -> get_option('navhover')), |
|---|
| 530 | 'showinfo' => (($this -> get_option('information') == "Y") ? "true" : "false"), |
|---|
| 531 | 'infoheadingcontent' => "title", |
|---|
| 532 | 'infoposition' => ($this -> get_option('infoposition')), |
|---|
| 533 | 'infoonhover' => ($this -> get_option('infoonhover')), |
|---|
| 534 | 'infospeed' => ($this -> get_option('infospeed')), |
|---|
| 535 | 'infodelay' => ($this -> get_option('infodelay')), |
|---|
| 536 | 'infofade' => ($this -> get_option ('infofade')), |
|---|
| 537 | 'infofadedelay' => ($this -> get_option ('infofadedelay')), |
|---|
| 538 | 'showthumbs' => (($this -> get_option('thumbnails') == "Y") ? "true" : "false"), |
|---|
| 539 | 'thumbsposition' => ($this -> get_option('thumbposition')), |
|---|
| 540 | 'thumbsborder' => (isset($styles['thumbactive']) ? (empty($styles['thumbactive'] ) ? "#ffffff" : $styles['thumbactive'] ) : "#ffffff" ), |
|---|
| 541 | 'thumbsspeed' => ($this -> get_option('thumbscrollspeed')), |
|---|
| 542 | 'thumbsspacing' => ($this -> get_option('thumbspacing')), |
|---|
| 543 | 'post_id' => null, |
|---|
| 544 | 'numberposts' => "-1", |
|---|
| 545 | 'exclude' => null, |
|---|
| 546 | 'custom' => null, |
|---|
| 547 | ); |
|---|
| 548 | |
|---|
| 549 | $s = shortcode_atts($defaults, $atts); |
|---|
| 550 | |
|---|
| 551 | |
|---|
| 552 | // Sanitize each element in the $s array |
|---|
| 553 | foreach ($s as $key => $value) { |
|---|
| 554 | if (is_numeric($value)) { |
|---|
| 555 | $s[$key] = intval($value); // For integers |
|---|
| 556 | } elseif (is_array($value)) { |
|---|
| 557 | $s[$key] = array_map('sanitize_text_field', $value); // For arrays |
|---|
| 558 | } else { |
|---|
| 559 | $s[$key] = sanitize_text_field($value); // For strings |
|---|
| 560 | } |
|---|
| 561 | } |
|---|
| 562 | |
|---|
| 563 | if (!in_array($s['orderby'], ['id', 'date', 'name', 'type', 'created' , 'order' , 'random'], true)) { |
|---|
| 564 | $s['orderby'] = array('order', "ASC"); // Default fallback |
|---|
| 565 | } |
|---|
| 566 | |
|---|
| 567 | // Additional validation based on the context |
|---|
| 568 | if (!in_array($s['orderf'], ['id', 'date', 'name', 'type', 'created', 'order'], true)) { |
|---|
| 569 | $s['orderf'] = 'order'; // Default fallback |
|---|
| 570 | } |
|---|
| 571 | |
|---|
| 572 | if (!in_array(strtoupper($s['orderd']), ['ASC', 'DESC'], true)) { |
|---|
| 573 | $s['orderd'] = 'ASC'; // Default fallback |
|---|
| 574 | } |
|---|
| 575 | |
|---|
| 576 | |
|---|
| 577 | extract($s); |
|---|
| 578 | |
|---|
| 579 | $slideshowtype = false; |
|---|
| 580 | |
|---|
| 581 | if (!empty($products)) { |
|---|
| 582 | include_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|---|
| 583 | if (is_plugin_active('wp-checkout' . DS . 'wp-checkout.php')) { |
|---|
| 584 | $slides = array(); |
|---|
| 585 | |
|---|
| 586 | if (empty($orderf) && empty($orderd)) { |
|---|
| 587 | $orderf = "order"; |
|---|
| 588 | $orderd = "ASC"; |
|---|
| 589 | } |
|---|
| 590 | |
|---|
| 591 | if (class_exists('wpCheckout')) { |
|---|
| 592 | if ($wpCheckout = new wpCheckout()) { |
|---|
| 593 | global $wpcoDb, $Product; |
|---|
| 594 | $wpcoDb -> model = $Product -> model; |
|---|
| 595 | $productstype = $products; |
|---|
| 596 | |
|---|
| 597 | switch ($productstype) { |
|---|
| 598 | case 'latest' : |
|---|
| 599 | $products = $wpcoDb -> find_all(false, false, array($orderf, $orderd), $productsnumber); |
|---|
| 600 | break; |
|---|
| 601 | case 'featured' : |
|---|
| 602 | $products = $wpcoDb -> find_all(array('featured' => "1"), false, array($orderf, $orderd), $productsnumber); |
|---|
| 603 | break; |
|---|
| 604 | } |
|---|
| 605 | } |
|---|
| 606 | } |
|---|
| 607 | |
|---|
| 608 | if (!empty($products)) { |
|---|
| 609 | $slides = $products; |
|---|
| 610 | $slideshowtype = "products"; |
|---|
| 611 | $content = $this -> render('gallery', array('slides' => $slides, 'unique' => 'products' . $productstype . $productsnumber, 'products' => true, 'options' => $s, 'frompost' => false), false, 'default'); |
|---|
| 612 | } else { |
|---|
| 613 | $error = __('No products are available', 'slideshow-gallery'); |
|---|
| 614 | } |
|---|
| 615 | } else { |
|---|
| 616 | $error = sprintf(__('You need the %sShopping Cart plugin%s to display products slides.', 'slideshow-gallery'), '<a href="https://tribulant.com/plugins/view/10/wordpress-shopping-cart-plugin" target="_blank">', '</a>'); |
|---|
| 617 | } |
|---|
| 618 | // Featured images |
|---|
| 619 | } elseif (!empty($featured)) { |
|---|
| 620 | global $post; |
|---|
| 621 | |
|---|
| 622 | if (empty($orderf) && empty($orderd)) { |
|---|
| 623 | $orderf = "order"; |
|---|
| 624 | $orderd = "ASC"; |
|---|
| 625 | } |
|---|
| 626 | |
|---|
| 627 | $args = array( |
|---|
| 628 | 'numberposts' => $featurednumber, // should show 5 but only shows 3 |
|---|
| 629 | 'post_type' => $featuredtype, // posts only |
|---|
| 630 | 'meta_key' => '_thumbnail_id', // with thumbnail |
|---|
| 631 | 'exclude' => $post -> ID, // exclude current post |
|---|
| 632 | 'orderby' => $orderf, |
|---|
| 633 | 'order' => $orderd, |
|---|
| 634 | ); |
|---|
| 635 | |
|---|
| 636 | if ($posts = get_posts($args)) { |
|---|
| 637 | $slides = $posts; |
|---|
| 638 | $slideshowtype = "featured"; |
|---|
| 639 | $content = $this -> render('gallery', array('slides' => $slides, 'unique' => 'featured' . $featuredtype . $featurednumber, 'featured' => true, 'options' => $s, 'frompost' => false), false, 'default'); |
|---|
| 640 | } else { |
|---|
| 641 | $error = sprintf(__('No posts with featured images are available. Ensure your theme includes %s support.', 'slideshow-gallery'), '<code>add_theme_support("post-thumbnails");</code>'); |
|---|
| 642 | } |
|---|
| 643 | // Slides of a gallery |
|---|
| 644 | } elseif (!empty($gallery_id)) { |
|---|
| 645 | if (!is_array($orderby) && !empty($orderby) && $orderby == "random") { |
|---|
| 646 | $orderbystring = "ORDER BY RAND()"; |
|---|
| 647 | } else if (!is_array($orderby) && !empty($orderby) && $orderby != "random" ) { |
|---|
| 648 | $orderbystring = "ORDER BY " . $orderby ; |
|---|
| 649 | } |
|---|
| 650 | else { |
|---|
| 651 | |
|---|
| 652 | if (empty($orderf) && empty($orderd)) { |
|---|
| 653 | list($orderf, $orderd) = $orderby; |
|---|
| 654 | } |
|---|
| 655 | |
|---|
| 656 | if ($orderf == "order") { |
|---|
| 657 | $orderbystring = "ORDER BY " . $this -> GallerySlides() -> table . ".order " . esc_sql($orderd) . ""; |
|---|
| 658 | } else { |
|---|
| 659 | $orderbystring = "ORDER BY " . $this -> Slide() -> table . "." . esc_sql($orderf) . " " . esc_sql($orderd) . ""; |
|---|
| 660 | } |
|---|
| 661 | } |
|---|
| 662 | |
|---|
| 663 | $slidesquery = "SELECT * FROM " . $this -> Slide() -> table . " LEFT JOIN " . $this -> GallerySlides() -> table . |
|---|
| 664 | " ON " . $this -> Slide() -> table . ".id = " . $this -> GallerySlides() -> table . ".slide_id WHERE " . |
|---|
| 665 | $this -> GallerySlides() -> table . ".gallery_id = '" . esc_sql($gallery_id) . "' AND (" . $this -> Slide() -> table . ".expiry = NULL OR " . $this -> Slide() -> table . ".expiry > CURDATE() OR " . $this -> Slide() -> table . ".expiry = '0000-00-00') " . $orderbystring; |
|---|
| 666 | |
|---|
| 667 | $query_hash = md5($slidesquery); |
|---|
| 668 | if ($oc_slides = wp_cache_get($query_hash, 'slideshowgallery')) { |
|---|
| 669 | $slides = $oc_slides; |
|---|
| 670 | } else { |
|---|
| 671 | $slides = $wpdb -> get_results($slidesquery); |
|---|
| 672 | wp_cache_set($query_hash, $slides, 'slideshowgallery', 0); |
|---|
| 673 | } |
|---|
| 674 | |
|---|
| 675 | if (!empty($slides)) { |
|---|
| 676 | $imagespath = $this -> get_option('imagespath'); |
|---|
| 677 | |
|---|
| 678 | foreach ($slides as $skey => $slide) { |
|---|
| 679 | $slides[$skey] = $this -> init_class($this -> Slide() -> model, $slide); |
|---|
| 680 | //$slides[$skey] -> image_path = $this -> Html -> image_path($slide); |
|---|
| 681 | } |
|---|
| 682 | |
|---|
| 683 | if ($orderby == "random") { shuffle($slides); } |
|---|
| 684 | $slideshowtype = "gallery"; |
|---|
| 685 | $content = $this -> render('gallery', array('slides' => $slides, 'unique' => 'gallery' . $gallery_id . rand(1, 999), 'options' => $s, 'frompost' => false), false, 'default'); |
|---|
| 686 | } else { |
|---|
| 687 | $error = __('No slides are available in this gallery', 'slideshow-gallery'); |
|---|
| 688 | } |
|---|
| 689 | // All slides |
|---|
| 690 | } elseif (!empty($custom) || empty($post_id)) { |
|---|
| 691 | if (!empty($orderf) && !empty($orderd)) { |
|---|
| 692 | $orderby = array($orderf, $orderd); |
|---|
| 693 | } |
|---|
| 694 | |
|---|
| 695 | $slides = $this -> Slide() -> find_all(null, null, $orderby); |
|---|
| 696 | |
|---|
| 697 | if (!empty($slides)) { |
|---|
| 698 | foreach ($slides as $slide_key => $slide) { |
|---|
| 699 | |
|---|
| 700 | // Check exclude |
|---|
| 701 | if (!empty($exclude)) { |
|---|
| 702 | $exclude = array_map('trim', explode(',', $exclude)); |
|---|
| 703 | if (in_array($slide -> id, $exclude)) { |
|---|
| 704 | unset($slides[$slide_key]); |
|---|
| 705 | } |
|---|
| 706 | } |
|---|
| 707 | |
|---|
| 708 | // Check slide expiration |
|---|
| 709 | if (!empty($slide -> expiry)) { |
|---|
| 710 | if (strtotime($slide -> expiry) <= time()) { |
|---|
| 711 | unset($slides[$slide_key]); |
|---|
| 712 | } |
|---|
| 713 | } |
|---|
| 714 | } |
|---|
| 715 | } |
|---|
| 716 | |
|---|
| 717 | if ($orderby == "random") { shuffle($slides); } |
|---|
| 718 | $slideshowtype = "slides"; |
|---|
| 719 | |
|---|
| 720 | if (!empty($slides)) { |
|---|
| 721 | $content = $this -> render('gallery', array('slides' => $slides, 'unique' => "custom" . rand(1, 999), 'options' => $s, 'frompost' => false), false, 'default'); |
|---|
| 722 | } else { |
|---|
| 723 | $error = __('No slides are available', 'slideshow-gallery'); |
|---|
| 724 | } |
|---|
| 725 | // Images of a post/page |
|---|
| 726 | } else { |
|---|
| 727 | global $post; |
|---|
| 728 | $pid = (empty($post_id)) ? $post -> ID : $post_id; |
|---|
| 729 | |
|---|
| 730 | if (!is_numeric($post_id)) { |
|---|
| 731 | $pid = $post -> ID; |
|---|
| 732 | } |
|---|
| 733 | |
|---|
| 734 | if (!empty($pid) && $post = get_post($pid)) { |
|---|
| 735 | $children_attributes = array( |
|---|
| 736 | 'numberposts' => $numberposts, |
|---|
| 737 | 'post_parent' => $post -> ID, |
|---|
| 738 | 'post_type' => "attachment", |
|---|
| 739 | 'post_status' => "any", |
|---|
| 740 | 'post_mime_type' => "image", |
|---|
| 741 | 'orderby' => ((!empty($orderf)) ? $orderf : "menu_order"), |
|---|
| 742 | 'order' => ((!empty($orderd)) ? $orderd : "ASC"), |
|---|
| 743 | ); |
|---|
| 744 | |
|---|
| 745 | if ($attachments = get_children($children_attributes)) { |
|---|
| 746 | if (!empty($exclude)) { |
|---|
| 747 | $exclude = array_map('trim', explode(',', $exclude)); |
|---|
| 748 | |
|---|
| 749 | $a = 0; |
|---|
| 750 | foreach ($attachments as $id => $attachment) { |
|---|
| 751 | //$attachments[$id] = (object) array_map('esc_attr', (array) $attachment); |
|---|
| 752 | |
|---|
| 753 | $a++; |
|---|
| 754 | if (in_array($a, $exclude)) { |
|---|
| 755 | unset($attachments[$id]); |
|---|
| 756 | } |
|---|
| 757 | } |
|---|
| 758 | } |
|---|
| 759 | |
|---|
| 760 | if ($orderby == "random") { shuffle($attachments); } |
|---|
| 761 | $slides = $attachments; |
|---|
| 762 | |
|---|
| 763 | $slideshowtype = "post"; |
|---|
| 764 | $content = $this -> render('gallery', array('slides' => $slides, 'unique' => $pid, 'options' => $s, 'frompost' => true), false, 'default'); |
|---|
| 765 | } else { |
|---|
| 766 | $error = __('No attachments on this post/page', 'slideshow-gallery'); |
|---|
| 767 | } |
|---|
| 768 | } else { |
|---|
| 769 | $error = __('No post/page ID was specified', 'slideshow-gallery'); |
|---|
| 770 | } |
|---|
| 771 | } |
|---|
| 772 | |
|---|
| 773 | // Check if this is an RSS Feed? |
|---|
| 774 | if (is_feed()) { |
|---|
| 775 | $content = ''; |
|---|
| 776 | ob_start(); |
|---|
| 777 | |
|---|
| 778 | $width = $this -> get_option('thumbwidth'); |
|---|
| 779 | $height = $this -> get_option('thumbheight'); |
|---|
| 780 | |
|---|
| 781 | if (!empty($slides)) { |
|---|
| 782 | switch ($slideshowtype) { |
|---|
| 783 | case 'products' : |
|---|
| 784 | foreach ($slides as $slide) { |
|---|
| 785 | ?> |
|---|
| 786 | |
|---|
| 787 | <a href="<?php echo get_permalink($slide -> post_id); ?>" title="<?php echo esc_attr($slide -> title); ?>"> |
|---|
| 788 | <img align="left" hspace="15" src="<?php echo esc_url($this -> Html() -> otf_image_src($slide, $this -> get_option('thumbwidth'), $this -> get_option('thumbheight'), 100)); ?>" /> |
|---|
| 789 | </a> |
|---|
| 790 | |
|---|
| 791 | <?php |
|---|
| 792 | } |
|---|
| 793 | break; |
|---|
| 794 | case 'gallery' : |
|---|
| 795 | foreach ($slides as $slide) { |
|---|
| 796 | ?> |
|---|
| 797 | |
|---|
| 798 | <a href="<?php echo esc_url($slide -> image_path); ?>" title="<?php echo esc_attr($slide -> title); ?>"> |
|---|
| 799 | <img align="left" hspace="15" src="<?php echo esc_url($this -> Html() -> otf_image_src($slide, $this -> get_option('thumbwidth'), $this -> get_option('thumbheight'), 100)); ?>" alt="<?php echo esc_attr($this -> Html -> sanitize($slide -> title)); ?>" /> |
|---|
| 800 | </a> |
|---|
| 801 | |
|---|
| 802 | <?php |
|---|
| 803 | } |
|---|
| 804 | break; |
|---|
| 805 | case 'featured' : |
|---|
| 806 | foreach ($slides as $slide) { |
|---|
| 807 | ?> |
|---|
| 808 | |
|---|
| 809 | <a href="<?php echo esc_url($slide -> guid); ?>" title="<?php echo esc_attr($slide -> post_title); ?>"> |
|---|
| 810 | <img align="left" hspace="15" src="<?php echo esc_url($this -> Html() -> otf_image_src($slide, $this -> get_option('thumbwidth'), $this -> get_option('thumbheight'), 100)); ?>" alt="<?php echo esc_attr($this -> Html -> sanitize($slide -> post_title)); ?>" /> |
|---|
| 811 | </a> |
|---|
| 812 | |
|---|
| 813 | <?php |
|---|
| 814 | } |
|---|
| 815 | break; |
|---|
| 816 | case 'post' : |
|---|
| 817 | default : |
|---|
| 818 | foreach ($slides as $slide) { |
|---|
| 819 | $full_image_href = wp_get_attachment_image_src($slide -> ID, 'full', false); |
|---|
| 820 | $full_image_url = wp_get_attachment_url($slide -> ID); |
|---|
| 821 | |
|---|
| 822 | ?> |
|---|
| 823 | |
|---|
| 824 | <a href="<?php echo esc_url($full_image_url); ?>" title="<?php echo esc_attr($slide -> post_title); ?>"> |
|---|
| 825 | <img align="left" hspace="15" src="<?php echo esc_url($this -> Html() -> otf_image_src($slide, $this -> get_option('thumbwidth'), $this -> get_option('thumbheight'), 100)); ?>" alt="<?php echo $this -> Html -> sanitize($slide -> post_title); ?>" /> |
|---|
| 826 | </a> |
|---|
| 827 | |
|---|
| 828 | <?php |
|---|
| 829 | } |
|---|
| 830 | break; |
|---|
| 831 | } |
|---|
| 832 | |
|---|
| 833 | ?><hr style="visibility:hidden; height:1px; width:100%; display:block;" /><?php |
|---|
| 834 | } |
|---|
| 835 | |
|---|
| 836 | $content = ob_get_clean(); |
|---|
| 837 | } |
|---|
| 838 | |
|---|
| 839 | // Check for error messages |
|---|
| 840 | if (!empty($error)) { |
|---|
| 841 | $content = ''; |
|---|
| 842 | $content .= '<p class="slideshow_error slideshow-gallery-error">'; |
|---|
| 843 | $content .= wp_unslash($error); |
|---|
| 844 | $content .= '</p>'; |
|---|
| 845 | } |
|---|
| 846 | |
|---|
| 847 | remove_filter('excerpt_more', array($this, 'excerpt_more')); |
|---|
| 848 | remove_filter('excerpt_length', array($this, 'excerpt_length')); |
|---|
| 849 | |
|---|
| 850 | return $content; |
|---|
| 851 | } |
|---|
| 852 | |
|---|
| 853 | function admin_slides() { |
|---|
| 854 | global $wpdb; |
|---|
| 855 | $method = (!empty($_GET['method'])) ? sanitize_text_field($_GET['method']) : false; |
|---|
| 856 | $errors = array(); |
|---|
| 857 | switch ($method) { |
|---|
| 858 | case 'delete' : |
|---|
| 859 | check_admin_referer($this -> sections -> slides . '_delete'); |
|---|
| 860 | $id = sanitize_text_field($_GET['id']); |
|---|
| 861 | if (!empty($id)) { |
|---|
| 862 | if ($this -> Slide() -> delete($id)) { |
|---|
| 863 | $msg_type = 'message'; |
|---|
| 864 | $message = __('Slide has been removed', 'slideshow-gallery'); |
|---|
| 865 | } else { |
|---|
| 866 | $msg_type = 'error'; |
|---|
| 867 | $message = __('Slide cannot be removed', 'slideshow-gallery'); |
|---|
| 868 | } |
|---|
| 869 | } else { |
|---|
| 870 | $msg_type = 'error'; |
|---|
| 871 | $message = __('No slide was specified', 'slideshow-gallery'); |
|---|
| 872 | } |
|---|
| 873 | |
|---|
| 874 | $this -> redirect($this -> referer, $msg_type, $message); |
|---|
| 875 | break; |
|---|
| 876 | case 'save' : |
|---|
| 877 | if (!empty($_POST)) { |
|---|
| 878 | check_admin_referer($this -> sections -> slides . '_save'); |
|---|
| 879 | |
|---|
| 880 | if ($this -> Slide() -> save($_POST, true)) { |
|---|
| 881 | $message = __('Slide item has been saved', 'slideshow-gallery'); |
|---|
| 882 | |
|---|
| 883 | if (!empty($_POST['continueediting'])) { |
|---|
| 884 | $this -> redirect(admin_url('admin.php?page=' . $this -> sections -> slides . '&method=save&id=' . $this -> Slide() -> insertid . '&continueediting=1'), 'message', $message); |
|---|
| 885 | } else { |
|---|
| 886 | $this -> redirect($this -> url, "message", $message); |
|---|
| 887 | } |
|---|
| 888 | } else { |
|---|
| 889 | $this -> render_err(__('Slide could not be saved', 'slideshow-gallery')); |
|---|
| 890 | $this -> render('slides' . DS . 'save', false, true, 'admin'); |
|---|
| 891 | } |
|---|
| 892 | } else { |
|---|
| 893 | $this -> Db -> model = $this -> Slide() -> model; |
|---|
| 894 | $slideId = (isset($_GET['id'])) ? sanitize_text_field($_GET['id']) : 0; |
|---|
| 895 | $this -> Slide() -> find(array('id' => $slideId)); |
|---|
| 896 | $this -> render('slides' . DS . 'save', false, true, 'admin'); |
|---|
| 897 | } |
|---|
| 898 | break; |
|---|
| 899 | case 'save-multiple' : |
|---|
| 900 | if (!empty($_POST)) { |
|---|
| 901 | check_admin_referer($this -> sections -> slides . '_save-multiple'); |
|---|
| 902 | |
|---|
| 903 | |
|---|
| 904 | |
|---|
| 905 | if (!empty($_POST['Slide']['slides'])) { |
|---|
| 906 | $slides = map_deep($_POST['Slide']['slides'], 'sanitize_text_field'); |
|---|
| 907 | $galleries = map_deep((empty($_POST['Slide']['galleries']) ? array() : $_POST['Slide']['galleries']) , 'sanitize_text_field'); |
|---|
| 908 | |
|---|
| 909 | $s = 0; |
|---|
| 910 | |
|---|
| 911 | foreach ($slides as $attachment_id => $slide) { |
|---|
| 912 | $slide_data = array( |
|---|
| 913 | 'Slide' => array( |
|---|
| 914 | 'title' => $slide['title'], |
|---|
| 915 | 'description' => $slide['description'], |
|---|
| 916 | 'image' => basename($slide['url']), |
|---|
| 917 | 'attachment_id' => $attachment_id, |
|---|
| 918 | 'type' => 'media', |
|---|
| 919 | 'image_url' => $slide['url'], |
|---|
| 920 | 'media_file' => $slide['url'], |
|---|
| 921 | 'galleries' => $galleries, |
|---|
| 922 | ) |
|---|
| 923 | ); |
|---|
| 924 | |
|---|
| 925 | if (!$this -> Slide() -> save($slide_data)) { |
|---|
| 926 | //$errors = array_merge($errors, $this -> Slide() -> errors); |
|---|
| 927 | $errors[$s] = $this -> Slide() -> errors; |
|---|
| 928 | } |
|---|
| 929 | |
|---|
| 930 | $s++; |
|---|
| 931 | } |
|---|
| 932 | |
|---|
| 933 | if (empty($errors)) { |
|---|
| 934 | $message = __('Slides have been saved', 'slideshow-gallery'); |
|---|
| 935 | $this -> redirect(admin_url('admin.php?page=' . $this -> sections -> slides), 'message', $message); |
|---|
| 936 | } |
|---|
| 937 | } else { |
|---|
| 938 | $errors[] = __('No slides were selected', 'slideshow-gallery'); |
|---|
| 939 | } |
|---|
| 940 | } |
|---|
| 941 | |
|---|
| 942 | $this -> render('slides' . DS . 'save-multiple', array('errors' => $errors), true, 'admin'); |
|---|
| 943 | break; |
|---|
| 944 | case 'order' : |
|---|
| 945 | if (isset($_GET['gallery_id'])) { |
|---|
| 946 | $gallery_id = sanitize_text_field($_GET['gallery_id']); |
|---|
| 947 | } else { |
|---|
| 948 | $gallery_id = ""; |
|---|
| 949 | } |
|---|
| 950 | |
|---|
| 951 | if (!empty($gallery_id)) { |
|---|
| 952 | $gallery = $this -> Gallery() -> find(array('id' => $gallery_id)); |
|---|
| 953 | |
|---|
| 954 | $slides = array(); |
|---|
| 955 | $gsquery = "SELECT gs.slide_id FROM `" . $this -> GallerySlides() -> table . "` gs WHERE `gallery_id` = '" . esc_sql($gallery -> id) . "' ORDER BY gs.order ASC"; |
|---|
| 956 | |
|---|
| 957 | $query_hash = md5($gsquery); |
|---|
| 958 | if ($oc_gs = wp_cache_get($query_hash, 'slideshowgallery')) { |
|---|
| 959 | $gs = $oc_gs; |
|---|
| 960 | } else { |
|---|
| 961 | $gs = $wpdb -> get_results($gsquery); |
|---|
| 962 | wp_cache_set($query_hash, $gs, 'slideshowgallery', 0); |
|---|
| 963 | } |
|---|
| 964 | |
|---|
| 965 | if (!empty($gs)) { |
|---|
| 966 | foreach ($gs as $galleryslide) { |
|---|
| 967 | $slides[] = $this -> Slide() -> find(array('id' => $galleryslide -> slide_id)); |
|---|
| 968 | } |
|---|
| 969 | } |
|---|
| 970 | |
|---|
| 971 | $this -> render('slides' . DS . 'order-gallery', array('gallery' => $gallery, 'slides' => $slides), true, 'admin'); |
|---|
| 972 | } else { |
|---|
| 973 | $slides = $this -> Slide() -> find_all(null, null, array('order', "ASC")); |
|---|
| 974 | $this -> render('slides' . DS . 'order', array('slides' => $slides), true, 'admin'); |
|---|
| 975 | } |
|---|
| 976 | break; |
|---|
| 977 | default : |
|---|
| 978 | $this -> render('slides' . DS . 'index', false, true, 'admin'); |
|---|
| 979 | break; |
|---|
| 980 | } |
|---|
| 981 | } |
|---|
| 982 | |
|---|
| 983 | function admin_galleries() { |
|---|
| 984 | |
|---|
| 985 | $method = (!empty($_GET['method'])) ? sanitize_text_field($_GET['method']) : false; |
|---|
| 986 | switch ($method) { |
|---|
| 987 | case 'save' : |
|---|
| 988 | if (!empty($_POST)) { |
|---|
| 989 | check_admin_referer($this -> sections -> galleries . '_save'); |
|---|
| 990 | |
|---|
| 991 | if ($this -> Gallery() -> save($_POST, true)) { |
|---|
| 992 | $message = __('Gallery item has been saved', 'slideshow-gallery'); |
|---|
| 993 | |
|---|
| 994 | if (!empty($_POST['continueediting'])) { |
|---|
| 995 | $this -> redirect(admin_url('admin.php?page=' . $this -> sections -> galleries . '&method=save&id=' . $this -> Gallery() -> insertid . '&continueediting=1'), 'message', $message); |
|---|
| 996 | } else { |
|---|
| 997 | $this -> redirect($this -> url, "message", $message); |
|---|
| 998 | } |
|---|
| 999 | } else { |
|---|
| 1000 | $this -> render('galleries' . DS . 'save', false, true, 'admin'); |
|---|
| 1001 | } |
|---|
| 1002 | } else { |
|---|
| 1003 | $this -> Db -> model = $this -> Gallery() -> model; |
|---|
| 1004 | $galleryId = (isset($_GET['id'])) ? sanitize_text_field($_GET['id']) : 0; |
|---|
| 1005 | $this -> Gallery() -> find(array('id' => $galleryId)); |
|---|
| 1006 | $this -> render('galleries' . DS . 'save', false, true, 'admin'); |
|---|
| 1007 | } |
|---|
| 1008 | break; |
|---|
| 1009 | case 'view' : |
|---|
| 1010 | $this -> Db -> model = $this -> Gallery() -> model; |
|---|
| 1011 | $gallery = $this -> Gallery() -> find(array('id' => sanitize_text_field($_GET['id']))); |
|---|
| 1012 | $perpage = (isset($_COOKIE[$this -> pre . 'slidesperpage'])) ? sanitize_text_field($_COOKIE[$this -> pre . 'slidesperpage']) : 25; |
|---|
| 1013 | $orderfield = (empty($_GET['orderby'])) ? 'modified' : sanitize_text_field($_GET['orderby']); |
|---|
| 1014 | $orderdirection = (empty($_GET['order'])) ? 'DESC' : strtoupper(sanitize_text_field($_GET['order'])); |
|---|
| 1015 | $order = array($orderfield, $orderdirection); |
|---|
| 1016 | $data = $this -> paginate('GallerySlides', "*", $this -> sections -> galleries . '&method=view&id=' . $gallery -> id, array('gallery_id' => $gallery -> id), false, $perpage, $order); |
|---|
| 1017 | |
|---|
| 1018 | if ( ! is_array( $data ) ) { |
|---|
| 1019 | $data = []; |
|---|
| 1020 | } |
|---|
| 1021 | |
|---|
| 1022 | $data['Slide'] = array(); |
|---|
| 1023 | if (!empty($data[$this -> GallerySlides() -> model])) { |
|---|
| 1024 | foreach ($data[$this -> GallerySlides() -> model] as $galleryslide) { |
|---|
| 1025 | $this -> Db -> model = $this -> Slide() -> model; |
|---|
| 1026 | $data['Slide'][] = $this -> Slide() -> find(array('id' => $galleryslide -> slide_id)); |
|---|
| 1027 | } |
|---|
| 1028 | } |
|---|
| 1029 | |
|---|
| 1030 | $data_paginate = isset( $data['Paginate'] ) ? $data['Paginate'] : false; |
|---|
| 1031 | |
|---|
| 1032 | $this -> render('galleries' . DS . 'view', array('gallery' => $gallery, 'slides' => $data[$this -> Slide() -> model], 'paginate' => $data_paginate), true, 'admin'); |
|---|
| 1033 | break; |
|---|
| 1034 | case 'hardcode' : |
|---|
| 1035 | $this -> Db -> model = $this -> Gallery() -> model; |
|---|
| 1036 | $gallery = $this -> Gallery() -> find(array('id' => sanitize_text_field($_GET['id']))); |
|---|
| 1037 | $this -> render('galleries' . DS . 'hardcode', array('gallery' => $gallery), true, 'admin'); |
|---|
| 1038 | break; |
|---|
| 1039 | case 'delete' : |
|---|
| 1040 | check_admin_referer($this -> sections -> galleries . '_delete'); |
|---|
| 1041 | |
|---|
| 1042 | $id = sanitize_text_field($_GET['id']); |
|---|
| 1043 | if (!empty($id)) { |
|---|
| 1044 | if ($this -> Gallery() -> delete($id)) { |
|---|
| 1045 | $msg_type = 'message'; |
|---|
| 1046 | $message = __('Gallery has been removed', 'slideshow-gallery'); |
|---|
| 1047 | } else { |
|---|
| 1048 | $msg_type = 'error'; |
|---|
| 1049 | $message = __('Gallery cannot be removed', 'slideshow-gallery'); |
|---|
| 1050 | } |
|---|
| 1051 | } else { |
|---|
| 1052 | $msg_type = 'error'; |
|---|
| 1053 | $message = __('No gallery was specified', 'slideshow-gallery'); |
|---|
| 1054 | } |
|---|
| 1055 | |
|---|
| 1056 | $this -> redirect($this -> referer, $msg_type, $message); |
|---|
| 1057 | break; |
|---|
| 1058 | default : |
|---|
| 1059 | $this -> render('galleries' . DS . 'index', false, true, 'admin'); |
|---|
| 1060 | break; |
|---|
| 1061 | } |
|---|
| 1062 | } |
|---|
| 1063 | |
|---|
| 1064 | function admin_settings() { |
|---|
| 1065 | global $wpdb; |
|---|
| 1066 | $method = (!empty($_GET['method'])) ? sanitize_text_field($_GET['method']) : false; |
|---|
| 1067 | |
|---|
| 1068 | switch ($method) { |
|---|
| 1069 | case 'clearlog' : |
|---|
| 1070 | |
|---|
| 1071 | check_admin_referer($this -> sections -> settings . '_clearlog'); |
|---|
| 1072 | |
|---|
| 1073 | @unlink(SLIDESHOW_LOG_FILE); |
|---|
| 1074 | |
|---|
| 1075 | $fh = fopen(SLIDESHOW_LOG_FILE, "w"); |
|---|
| 1076 | fwrite($fh, "*** Slideshow Log File *** \r\n\r\n"); |
|---|
| 1077 | fclose($fh); |
|---|
| 1078 | chmod(SLIDESHOW_LOG_FILE, 0777); |
|---|
| 1079 | |
|---|
| 1080 | $msgtype = 'message'; |
|---|
| 1081 | $message = __('Log file has been cleared', 'slideshow-gallery'); |
|---|
| 1082 | $this -> redirect($this -> referer, $msgtype, $message); |
|---|
| 1083 | |
|---|
| 1084 | break; |
|---|
| 1085 | case 'dismiss' : |
|---|
| 1086 | if (!empty($_GET['dismiss'])) { |
|---|
| 1087 | $this -> update_option('dismiss_' . sanitize_text_field($_GET['dismiss']), 1); |
|---|
| 1088 | } |
|---|
| 1089 | |
|---|
| 1090 | $this -> redirect($this -> referer); |
|---|
| 1091 | break; |
|---|
| 1092 | case 'checkdb' : |
|---|
| 1093 | check_admin_referer($this -> sections -> settings . '_checkdb'); |
|---|
| 1094 | $this -> check_tables(); |
|---|
| 1095 | |
|---|
| 1096 | if (!empty($this -> models)) { |
|---|
| 1097 | foreach ($this -> models as $model) { |
|---|
| 1098 | $query = "OPTIMIZE TABLE `" . $this -> {$model}() -> table . "`"; |
|---|
| 1099 | $wpdb -> query($query); |
|---|
| 1100 | } |
|---|
| 1101 | } |
|---|
| 1102 | |
|---|
| 1103 | $this -> redirect($this -> referer, 'message', __('Database tables have been checked and optimized', 'slideshow-gallery')); |
|---|
| 1104 | break; |
|---|
| 1105 | case 'reset' : |
|---|
| 1106 | check_admin_referer($this -> sections -> settings . '_reset'); |
|---|
| 1107 | global $wpdb; |
|---|
| 1108 | $query = "DELETE FROM `" . $wpdb -> prefix . "options` WHERE `option_name` LIKE '" . esc_sql($this -> pre) . "%';"; |
|---|
| 1109 | |
|---|
| 1110 | if ($wpdb -> query($query)) { |
|---|
| 1111 | $this -> initialize_options(); |
|---|
| 1112 | |
|---|
| 1113 | $message = __('All settings have been reset to their defaults', 'slideshow-gallery'); |
|---|
| 1114 | $msg_type = 'message'; |
|---|
| 1115 | $this -> render_msg($message); |
|---|
| 1116 | } else { |
|---|
| 1117 | $message = __('Settings could not be reset', 'slideshow-gallery'); |
|---|
| 1118 | $msg_type = 'error'; |
|---|
| 1119 | $this -> render_err($message); |
|---|
| 1120 | } |
|---|
| 1121 | |
|---|
| 1122 | $this -> redirect($this -> url, $msg_type, $message); |
|---|
| 1123 | break; |
|---|
| 1124 | default : |
|---|
| 1125 | if (!empty($_POST)) { |
|---|
| 1126 | check_admin_referer($this -> sections -> settings); |
|---|
| 1127 | |
|---|
| 1128 | delete_option('tridebugging'); |
|---|
| 1129 | $this -> delete_option('infohideonmobile'); |
|---|
| 1130 | $this -> delete_option('autoheight'); |
|---|
| 1131 | $this -> delete_option('language_external'); |
|---|
| 1132 | $this -> delete_option('excerptsettings'); |
|---|
| 1133 | $this -> delete_option('infofade'); |
|---|
| 1134 | $this -> delete_option('fadedelay'); |
|---|
| 1135 | $this -> delete_option('infoonhover'); |
|---|
| 1136 | $this -> delete_option('thumbhideonmobile'); |
|---|
| 1137 | |
|---|
| 1138 | foreach ($_POST as $pkey => $pval) { |
|---|
| 1139 | switch ($pkey) { |
|---|
| 1140 | case 'styles' : |
|---|
| 1141 | $styles = array(); |
|---|
| 1142 | foreach ($pval as $pvalkey => $pvalval) { |
|---|
| 1143 | switch ($pvalkey) { |
|---|
| 1144 | case 'layout' : |
|---|
| 1145 | if (!$this -> ci_serial_valid()) { |
|---|
| 1146 | $styles[$pvalkey] = "specific"; |
|---|
| 1147 | } else { |
|---|
| 1148 | $styles[$pvalkey] = $pvalval; |
|---|
| 1149 | } |
|---|
| 1150 | break; |
|---|
| 1151 | default : |
|---|
| 1152 | $styles[$pvalkey] = $pvalval; |
|---|
| 1153 | break; |
|---|
| 1154 | } |
|---|
| 1155 | } |
|---|
| 1156 | |
|---|
| 1157 | $this -> update_option('styles', $styles); |
|---|
| 1158 | break; |
|---|
| 1159 | case 'debugging' : |
|---|
| 1160 | if (!empty($pval)) { |
|---|
| 1161 | update_option('tridebugging', 1); |
|---|
| 1162 | } |
|---|
| 1163 | break; |
|---|
| 1164 | case 'excerpt_readmore' : |
|---|
| 1165 | if ($this -> language_do()) { |
|---|
| 1166 | $this -> update_option($pkey, $this -> language_join($pval)); |
|---|
| 1167 | } else { |
|---|
| 1168 | $this -> update_option($pkey, $pval); |
|---|
| 1169 | } |
|---|
| 1170 | break; |
|---|
| 1171 | case 'permissions' : |
|---|
| 1172 | global $wp_roles; |
|---|
| 1173 | $role_names = $wp_roles -> get_names(); |
|---|
| 1174 | |
|---|
| 1175 | if (!empty($_POST['permissions'])) { |
|---|
| 1176 | $permissions = map_deep($_POST['permissions'], 'sanitize_text_field'); |
|---|
| 1177 | |
|---|
| 1178 | foreach ($role_names as $role_key => $role_name) { |
|---|
| 1179 | foreach ($this -> sections as $section_key => $section_name) { |
|---|
| 1180 | $wp_roles -> remove_cap($role_key, 'slideshow_' . $section_key); |
|---|
| 1181 | |
|---|
| 1182 | if (!empty($permissions[$role_key]) && in_array($section_key, $permissions[$role_key])) { |
|---|
| 1183 | $wp_roles -> add_cap($role_key, 'slideshow_' . $section_key); |
|---|
| 1184 | } |
|---|
| 1185 | |
|---|
| 1186 | if ($role_key == "administrator") { |
|---|
| 1187 | $wp_roles -> add_cap("administrator", 'slideshow_' . $section_key); |
|---|
| 1188 | $permissions[$role_key][] = $section_key; |
|---|
| 1189 | } |
|---|
| 1190 | } |
|---|
| 1191 | } |
|---|
| 1192 | } |
|---|
| 1193 | |
|---|
| 1194 | $this -> update_option('permissions', $permissions); |
|---|
| 1195 | break; |
|---|
| 1196 | default : |
|---|
| 1197 | $this -> update_option($pkey, $pval); |
|---|
| 1198 | break; |
|---|
| 1199 | } |
|---|
| 1200 | } |
|---|
| 1201 | |
|---|
| 1202 | if (!$this -> ci_serial_valid()) { |
|---|
| 1203 | $this -> update_option('effect', "slide"); |
|---|
| 1204 | $this -> update_option('easing', "swing"); |
|---|
| 1205 | $this -> update_option('infodelay', "0"); |
|---|
| 1206 | $this -> delete_option('infohideonmobile'); |
|---|
| 1207 | $this -> delete_option('excerptsettings'); |
|---|
| 1208 | $this -> update_option('imagesthickbox', "N"); |
|---|
| 1209 | $this -> delete_option('thumbhideonmobile'); |
|---|
| 1210 | } |
|---|
| 1211 | |
|---|
| 1212 | $message = __('Settings has been saved', 'slideshow-gallery'); |
|---|
| 1213 | $this -> render_msg($message); |
|---|
| 1214 | } |
|---|
| 1215 | |
|---|
| 1216 | $this -> render('settings', false, true, 'admin'); |
|---|
| 1217 | break; |
|---|
| 1218 | } |
|---|
| 1219 | } |
|---|
| 1220 | |
|---|
| 1221 | function admin_settings_updates() { |
|---|
| 1222 | $method = (!empty($_GET['method'])) ? sanitize_text_field($_GET['method']) : false; |
|---|
| 1223 | switch ($method) { |
|---|
| 1224 | case 'check' : |
|---|
| 1225 | delete_transient('slideshow_update_info'); |
|---|
| 1226 | $this -> redirect($this -> referer); |
|---|
| 1227 | break; |
|---|
| 1228 | } |
|---|
| 1229 | |
|---|
| 1230 | $this -> render('settings-updates', false, true, 'admin'); |
|---|
| 1231 | } |
|---|
| 1232 | |
|---|
| 1233 | public function secureSlideshowGalleryLiteLog() { |
|---|
| 1234 | // Define the path to the .htaccess file |
|---|
| 1235 | $htaccessPath = ABSPATH . '.htaccess'; // ABSPATH is the WordPress root directory |
|---|
| 1236 | // Directive to add for restricting access to newsletters.log |
|---|
| 1237 | $restrictionDirective = "\n<FilesMatch \"^slideshow\\.log$\">\nOrder Allow,Deny\nDeny from all\n</FilesMatch>\n"; |
|---|
| 1238 | // Check if the .htaccess file exists |
|---|
| 1239 | if (file_exists($htaccessPath)) { |
|---|
| 1240 | $contents = file_get_contents($htaccessPath); |
|---|
| 1241 | |
|---|
| 1242 | // Check if the directive is already present |
|---|
| 1243 | if (strpos($contents, trim($restrictionDirective)) === false) { |
|---|
| 1244 | // Directive not found, append it |
|---|
| 1245 | file_put_contents($htaccessPath, $restrictionDirective, FILE_APPEND); |
|---|
| 1246 | echo "Directive added to existing .htaccess file."; |
|---|
| 1247 | } else { |
|---|
| 1248 | // Directive already exists |
|---|
| 1249 | echo "Directive already exists in .htaccess file."; |
|---|
| 1250 | } |
|---|
| 1251 | } else { |
|---|
| 1252 | // .htaccess file does not exist, create it and add the directive |
|---|
| 1253 | file_put_contents($htaccessPath, $restrictionDirective); |
|---|
| 1254 | echo "No .htaccess file found. New file created with directive."; |
|---|
| 1255 | } |
|---|
| 1256 | } |
|---|
| 1257 | |
|---|
| 1258 | |
|---|
| 1259 | function activation_hook() { |
|---|
| 1260 | $this->secureSlideshowGalleryLiteLog(); |
|---|
| 1261 | $this -> add_option('activation_redirect', true); |
|---|
| 1262 | } |
|---|
| 1263 | |
|---|
| 1264 | function custom_redirect() { |
|---|
| 1265 | |
|---|
| 1266 | $method = (!empty($_GET['slideshow_method'])) ? sanitize_text_field($_GET['slideshow_method']) : false; |
|---|
| 1267 | if (!empty($method)) { |
|---|
| 1268 | switch ($method) { |
|---|
| 1269 | case 'hidemessage' : |
|---|
| 1270 | if (!empty($_GET['message'])) { |
|---|
| 1271 | switch ($_GET['message']) { |
|---|
| 1272 | case 'upgradetopro' : |
|---|
| 1273 | $this -> update_option('hidemessage_upgradetopro', true); |
|---|
| 1274 | break; |
|---|
| 1275 | case 'ratereview' : |
|---|
| 1276 | $this -> delete_option('showmessage_ratereview'); |
|---|
| 1277 | $this -> redirect($this -> referer); |
|---|
| 1278 | break; |
|---|
| 1279 | } |
|---|
| 1280 | } |
|---|
| 1281 | break; |
|---|
| 1282 | case 'hideupdate' : |
|---|
| 1283 | if (!empty($_GET['version'])) { |
|---|
| 1284 | $this -> update_option('hideupdate', sanitize_text_field($_GET['version'])); |
|---|
| 1285 | $this -> redirect($this -> referer); |
|---|
| 1286 | } |
|---|
| 1287 | break; |
|---|
| 1288 | } |
|---|
| 1289 | } |
|---|
| 1290 | |
|---|
| 1291 | $activation_redirect = $this -> get_option('activation_redirect'); |
|---|
| 1292 | if (is_admin() && !empty($activation_redirect)) { |
|---|
| 1293 | $this -> delete_option('activation_redirect'); |
|---|
| 1294 | wp_cache_flush(); |
|---|
| 1295 | wp_redirect(admin_url('index.php?page=' . $this -> sections -> about)); |
|---|
| 1296 | } |
|---|
| 1297 | } |
|---|
| 1298 | } |
|---|
| 1299 | } |
|---|
| 1300 | |
|---|
| 1301 | if (!function_exists('SG')) { |
|---|
| 1302 | function SG($param = null) { |
|---|
| 1303 | return new SlideshowGallery($param); |
|---|
| 1304 | } |
|---|
| 1305 | } |
|---|
| 1306 | |
|---|
| 1307 | //initialize a Gallery object |
|---|
| 1308 | global $Gallery; |
|---|
| 1309 | $Gallery = new SlideshowGallery(); |
|---|
| 1310 | register_activation_hook(plugin_basename(__FILE__), array($Gallery, 'initialize_options')); |
|---|
| 1311 | register_activation_hook(plugin_basename(__FILE__), array($Gallery, 'activation_hook')); |
|---|
| 1312 | |
|---|
| 1313 | if (!function_exists('slideshow')) { |
|---|
| 1314 | function slideshow($output = true, $gallery_id = null, $post_id = null, $params = array()) { |
|---|
| 1315 | $params['gallery_id'] = $gallery_id; |
|---|
| 1316 | $params['post_id'] = $post_id; |
|---|
| 1317 | |
|---|
| 1318 | $Gallery = new SlideshowGallery(); |
|---|
| 1319 | $content = $Gallery -> embed($params, false); |
|---|
| 1320 | |
|---|
| 1321 | if ($output == true) { |
|---|
| 1322 | echo wp_kses_post($content); |
|---|
| 1323 | } else { |
|---|
| 1324 | return $content; |
|---|
| 1325 | } |
|---|
| 1326 | } |
|---|
| 1327 | } |
|---|
| 1328 | |
|---|
| 1329 | ?> |
|---|