| 1 |
<?php |
| 2 |
|
| 3 |
use Carbon_Fields\Container; |
| 4 |
use Carbon_Fields\Field; |
| 5 |
//use Carbon_Fields\Block; //not at the moment |
| 6 |
// Make it work on AWS (since 1.5.4) |
| 7 |
define( 'Carbon_Fields\\URL', trailingslashit( plugin_dir_url( __DIR__ ) ) . 'includes/carbonfields/htmlburger/carbon-fields/' ); |
| 8 |
/** |
| 9 |
* The admin-specific functionality of the plugin. |
| 10 |
* |
| 11 |
* @link www.scrollsequence.com |
| 12 |
* @since 0.7.0 |
| 13 |
* |
| 14 |
* @package Scrollsequence |
| 15 |
* @subpackage Scrollsequence/admin |
| 16 |
*/ |
| 17 |
/** |
| 18 |
* The admin-specific functionality of the plugin. |
| 19 |
* |
| 20 |
* Defines the plugin name, version, and two examples hooks for how to |
| 21 |
* enqueue the admin-specific stylesheet and JavaScript. |
| 22 |
* |
| 23 |
* @package Scrollsequence |
| 24 |
* @subpackage Scrollsequence/admin |
| 25 |
* @author Scrollsequence <info@scrollsequence.com> |
| 26 |
*/ |
| 27 |
class Scrollsequence_Admin { |
| 28 |
/** |
| 29 |
* The ID of this plugin. |
| 30 |
* |
| 31 |
* @since 0.7.0 |
| 32 |
* @access private |
| 33 |
* @var string $plugin_name The ID of this plugin. |
| 34 |
*/ |
| 35 |
private $plugin_name; |
| 36 |
|
| 37 |
/** |
| 38 |
* The version of this plugin. |
| 39 |
* |
| 40 |
* @since 0.7.0 |
| 41 |
* @access private |
| 42 |
* @var string $version The current version of this plugin. |
| 43 |
*/ |
| 44 |
private $version; |
| 45 |
|
| 46 |
/** |
| 47 |
* Initialize the class and set its properties. |
| 48 |
* |
| 49 |
* @since 0.7.0 |
| 50 |
* @param string $plugin_name The name of this plugin. |
| 51 |
* @param string $version The version of this plugin. |
| 52 |
*/ |
| 53 |
public function __construct( $plugin_name, $version ) { |
| 54 |
$this->plugin_name = $plugin_name; |
| 55 |
$this->version = $version; |
| 56 |
add_shortcode( 'scrollsequence', array($this, 'scrollsequence_shortcode') ); |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Register the stylesheets for the admin area. |
| 61 |
* |
| 62 |
* @since 0.7.0 |
| 63 |
*/ |
| 64 |
public function enqueue_styles() { |
| 65 |
/** |
| 66 |
* This function is provided for demonstration purposes only. |
| 67 |
* |
| 68 |
* An instance of this class should be passed to the run() function |
| 69 |
* defined in Scrollsequence_Loader as all of the hooks are defined |
| 70 |
* in that particular class. |
| 71 |
* |
| 72 |
* The Scrollsequence_Loader will then create the relationship |
| 73 |
* between the defined hooks and the functions defined in this |
| 74 |
* class. |
| 75 |
*/ |
| 76 |
// Ak: I want to add an IF statement to enqueue scripts only to my CPT |
| 77 |
global $post_type; |
| 78 |
if ( 'scrollsequence' == $post_type ) { |
| 79 |
wp_enqueue_style( |
| 80 |
$this->plugin_name, |
| 81 |
plugin_dir_url( __FILE__ ) . 'css/scrollsequence-admin.css', |
| 82 |
array(), |
| 83 |
$this->version, |
| 84 |
'all' |
| 85 |
); |
| 86 |
} |
| 87 |
// Ak: end |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Register the JavaScript for the admin area. |
| 92 |
* |
| 93 |
* @since 0.7.0 |
| 94 |
*/ |
| 95 |
public function enqueue_scripts() { |
| 96 |
/** |
| 97 |
* This function is provided for demonstration purposes only. |
| 98 |
* |
| 99 |
* An instance of this class should be passed to the run() function |
| 100 |
* defined in Scrollsequence_Loader as all of the hooks are defined |
| 101 |
* in that particular class. |
| 102 |
* |
| 103 |
* The Scrollsequence_Loader will then create the relationship |
| 104 |
* between the defined hooks and the functions defined in this |
| 105 |
* class. |
| 106 |
*/ |
| 107 |
// Ak: I want to add an IF statement to enqueue scripts only to my CPT |
| 108 |
global $post_type; |
| 109 |
global $pagenow; |
| 110 |
if ( 'scrollsequence' == $post_type && ('post-new.php' === $pagenow || 'post.php' === $pagenow) ) { |
| 111 |
// Free |
| 112 |
wp_enqueue_script( |
| 113 |
$this->plugin_name, |
| 114 |
plugin_dir_url( __FILE__ ) . 'js/scrollsequence-admin.js', |
| 115 |
array('jquery'), |
| 116 |
$this->version, |
| 117 |
true |
| 118 |
); |
| 119 |
} |
| 120 |
// Ak: end |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Register Scrollsequence CPT . |
| 125 |
* |
| 126 |
* @since 0.7.0 |
| 127 |
*/ |
| 128 |
public function scrollsequence_cpt() { |
| 129 |
require_once "create-cpt.php"; |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* Register Scrollsequence CPT . |
| 134 |
* |
| 135 |
* @since 0.7.3 |
| 136 |
*/ |
| 137 |
public function scrollsequence_cpt_submenu() { |
| 138 |
add_submenu_page( |
| 139 |
'edit.php?post_type=scrollsequence', |
| 140 |
/*parent_slug*/ |
| 141 |
'Dashboard Scrollsequence', |
| 142 |
/*page title*/ |
| 143 |
'Dashboard', |
| 144 |
/*menu title*/ |
| 145 |
'edit_posts', |
| 146 |
/*roles and capability needed*/ |
| 147 |
// Update 0.9.93 |
| 148 |
'scrollsequence-dashboard', |
| 149 |
/*menu slug*/ |
| 150 |
'scrollsequence_cpt_dashboard_callback' |
| 151 |
); |
| 152 |
function scrollsequence_cpt_dashboard_callback() { |
| 153 |
require_once "partials/scrollsequence-admin-display.php"; |
| 154 |
} |
| 155 |
|
| 156 |
} |
| 157 |
|
| 158 |
public function scrollsequence_preview_media() { |
| 159 |
add_submenu_page( |
| 160 |
'edit.php?post_type=scrollsequence', |
| 161 |
'Preview Scrollsequence', |
| 162 |
/*page title*/ |
| 163 |
'Preview ', |
| 164 |
/*menu title*/ |
| 165 |
'edit_posts', |
| 166 |
/*roles and capability needed*/ |
| 167 |
// Update 0.9.93 |
| 168 |
'scrollsequence-preview', |
| 169 |
/*menu slug*/ |
| 170 |
'scrollsequence_preview_callback' |
| 171 |
); |
| 172 |
function scrollsequence_preview_callback() { |
| 173 |
require_once "partials/scrollsequence-admin-display-media-tools-preview.php"; |
| 174 |
} |
| 175 |
|
| 176 |
// Enqueue script on this specific submenu page |
| 177 |
add_action( 'admin_enqueue_scripts', array($this, 'scrollsequence_preview_enqueue_scripts') ); |
| 178 |
} |
| 179 |
|
| 180 |
function scrollsequence_preview_media_hide_submenu_page() { |
| 181 |
echo '<style> |
| 182 |
#adminmenumain a[href="admin.php?page=scrollsequence-preview"] { |
| 183 |
display: none; |
| 184 |
} |
| 185 |
</style>'; |
| 186 |
} |
| 187 |
|
| 188 |
public function scrollsequence_preview_enqueue_scripts( $hook ) { |
| 189 |
// Check if we're on the 'scrollsequence-preview' page |
| 190 |
if ( 'admin_page_scrollsequence-preview' !== $hook ) { |
| 191 |
return; |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
/** |
| 196 |
* Single file custom template for scrollsequence. I am following this: |
| 197 |
* https://code.tutsplus.com/tutorials/a-guide-to-wordpress-custom-post-types-creation-display-and-meta-boxes--wp-27645 |
| 198 |
* ref "tutsplus" in class-scrollsequence add action thing |
| 199 |
* @since 0.7.0 |
| 200 |
* @uses i dont know |
| 201 |
* Step 1 https://blog.wplauncher.com/add-meta-box-wordpress-custom-post-type/ |
| 202 |
*/ |
| 203 |
public function scrollsequence_template( $template_path ) { |
| 204 |
if ( get_post_type() == 'scrollsequence' ) { |
| 205 |
if ( is_single() ) { |
| 206 |
// checks if the file exists in the theme first, |
| 207 |
// otherwise serve the file from the plugin |
| 208 |
if ( $theme_file = locate_template( array('single-scrollsequence.php') ) ) { |
| 209 |
$template_path = $theme_file; |
| 210 |
} else { |
| 211 |
$template_path = plugin_dir_path( __DIR__ ) . 'public/partials/single-scrollsequence.php'; |
| 212 |
} |
| 213 |
} |
| 214 |
} |
| 215 |
return $template_path; |
| 216 |
} |
| 217 |
|
| 218 |
/** |
| 219 |
* Carbon Fields Boot function. This function boots up carbon fields. |
| 220 |
* |
| 221 |
* @since 0.9.8 |
| 222 |
*/ |
| 223 |
public function scrollsequence_carbon_fields_load() { |
| 224 |
require_once __DIR__ . '/../includes/carbonfields/autoload.php'; |
| 225 |
\Carbon_Fields\Carbon_Fields::boot(); |
| 226 |
} |
| 227 |
|
| 228 |
/** |
| 229 |
* Carbon Fields Main Function (Scrollsequence CPT) |
| 230 |
* |
| 231 |
* @since 0.9.8 |
| 232 |
*/ |
| 233 |
public function scrollsequence_carbon_fields_cpt() { |
| 234 |
/* TRANSLATION IS MISSING FOR STRINGS BELOW */ |
| 235 |
$scrollsequence_advert_html = '<h4>Full animation settings are available in <a href=' . admin_url( "admin.php?page=scrollsequence-pricing" ) . '>Scrollsequence PRO</a>.</h4><strong>NEW: </strong>We offer <a href=' . admin_url( "admin.php?page=scrollsequence-pricing&trial=true" ) . '>14 days FREE trial</a> - no card required, no risk. '; |
| 236 |
$scrollsequence_left_center_right = ' |
| 237 |
<div style="float: left">' . __( 'Left', 'scrollsequence' ) . '</div> |
| 238 |
<div style="float: right">' . __( 'Right', 'scrollsequence' ) . '</div> |
| 239 |
<div style="margin: 0 auto; width: 100px;"></div> |
| 240 |
'; |
| 241 |
$scrollsequence_bottom_center_top = ' |
| 242 |
<div style="float: left">' . __( 'Top', 'scrollsequence' ) . '</div> |
| 243 |
<div style="float: right">' . __( 'Bottom', 'scrollsequence' ) . '</div> |
| 244 |
<div style="margin: 0 auto; width: 100px;"></div> |
| 245 |
'; |
| 246 |
$scrollsequence_trigger_start = ' |
| 247 |
<div style="float: left">' . __( 'Start Sooner', 'scrollsequence' ) . '</div> |
| 248 |
<div style="float: right">' . __( 'Default', 'scrollsequence' ) . '</div> |
| 249 |
<div style="margin: 0 auto; width: 100px;"></div> |
| 250 |
'; |
| 251 |
$scrollsequence_trigger_end = ' |
| 252 |
<div style="float: left">' . __( 'Default', 'scrollsequence' ) . '</div> |
| 253 |
<div style="float: right">' . __( 'End Later', 'scrollsequence' ) . '</div> |
| 254 |
<div style="margin: 0 auto; width: 100px;"></div> |
| 255 |
'; |
| 256 |
/* TRANSLATION IS MISSING FOR STRINGS BELOW */ |
| 257 |
$scrollsequence_aglignmentadv = '<p>More Scale and Alignment settings are available in <a href=' . admin_url( "admin.php?page=scrollsequence-pricing" ) . '>Scrollsequence PRO</a>. </p><p><strong>NEW: </strong>We offer <a href=' . admin_url( "admin.php?page=scrollsequence-pricing&trial=true" ) . '>14 days FREE trial</a> - no card required, no risk.</p>'; |
| 258 |
$scrollsequence_condition_need_images = array( |
| 259 |
'relation' => 'AND', |
| 260 |
array( |
| 261 |
'field' => 'scrollsequence_p_images', |
| 262 |
'value' => '', |
| 263 |
'compare' => '!=', |
| 264 |
), |
| 265 |
); |
| 266 |
// FREE VERSION |
| 267 |
Container::make( 'post_meta', 'Scrollsequence' )->where( 'post_type', '=', 'scrollsequence' )->set_context( 'carbon_fields_after_title' )->add_fields( array(Field::make( 'complex', 'scrollsequence_page', __( 'Scene', 'scrollsequence' ) )->setup_labels( array( |
| 268 |
'plural_name' => __( 'Scenes', 'scrollsequence' ), |
| 269 |
'singular_name' => __( 'Scene', 'scrollsequence' ), |
| 270 |
) )->set_layout( 'tabbed-horizontal' )->set_required( true )->set_max( 3 )->add_fields( array( |
| 271 |
Field::make( 'rich_text', 'scrollsequence_p_wysiwyg', __( 'Fixed Content', 'scrollsequence' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_default_value( '<div class="ssq-center-center"><h1 id="on-earth">' . __( 'Another day on Earth', 'scrollsequence' ) . '</h1></div>' ), |
| 272 |
Field::make( 'media_gallery', 'scrollsequence_p_images', __( 'Image Sequence', 'scrollsequence' ) )->set_type( array('image') )->set_required( true )->set_duplicates_allowed( true )->set_classes( 'scrollsequence-custom-class' ), |
| 273 |
Field::make( 'complex', 'ssqnce_anim', __( 'Fixed Content Animation', 'scrollsequence' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_layout( 'tabbed-vertical' )->setup_labels( array( |
| 274 |
'plural_name' => __( 'Animations', 'scrollsequence' ), |
| 275 |
'singular_name' => __( 'Animation', 'scrollsequence' ), |
| 276 |
) )->add_fields( 'ssqnce_anim_io', 'Animate From/To', array( |
| 277 |
Field::make( 'text', 'ssqnce_anim_io_id', __( 'Selector', 'scrollsequence' ) )->set_width( 20 )->set_required( true )->set_help_text( __( 'Enter #id or .class selector', 'scrollsequence' ) ), |
| 278 |
Field::make( 'text', 'ssqnce_anim_io_start', __( 'Start', 'scrollsequence' ) )->set_width( 20 )->set_required( true )->set_help_text( __( 'Enter image number where element becomes visible', 'scrollsequence' ) )->set_attribute( 'type', 'number' )->set_attribute( 'min', '0' )->set_attribute( 'step', '1' ), |
| 279 |
Field::make( 'text', 'ssqnce_anim_io_end', __( 'End', 'scrollsequence' ) )->set_width( 20 )->set_required( true )->set_help_text( __( 'Enter image number where element is hidden', 'scrollsequence' ) )->set_attribute( 'type', 'number' )->set_attribute( 'min', '0' )->set_attribute( 'step', '1' ), |
| 280 |
// Free advert |
| 281 |
Field::make( 'separator', 'scrollsequence_advert', __( 'Animation Settings Not Available in Free Version', 'scrollsequence' ) )->set_help_text( $scrollsequence_advert_html ), |
| 282 |
) )->set_header_template( __( 'Animation', 'scrollsequence' ) . ' |
| 283 |
<% if (ssqnce_anim_io_id) { %> |
| 284 |
- <%- ssqnce_anim_io_id %> |
| 285 |
<% } %> |
| 286 |
' ), |
| 287 |
// PRO ONLY END1 |
| 288 |
// Field::make( 'text', 'scrollsequence_p_duration', __( 'Page Height (vh)' ) ) |
| 289 |
// ->set_conditional_logic($scrollsequence_condition_need_images) |
| 290 |
// ->set_attribute( 'type', 'number' ) |
| 291 |
// ->set_required( true ) |
| 292 |
// ->set_default_value('200') |
| 293 |
// ->set_attribute( 'min', '20' ) |
| 294 |
// ->set_attribute( 'max', '2000' ) |
| 295 |
// ->set_attribute( 'step', '1' ) |
| 296 |
// ->help_text('This sets the amount of scroll needed to get past this page.'), |
| 297 |
Field::make( 'text', 'scrollsequence_p_imgdur', __( 'Image Duration (px)', 'scrollsequence' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_attribute( 'type', 'number' )->set_required( true )->set_default_value( '25' )->set_attribute( 'min', '5' )->set_attribute( 'max', '500' )->set_attribute( 'step', '1' )->help_text( __( 'This sets how far the images are apart.', 'scrollsequence' ) ), |
| 298 |
// PANORAMA (MOBILE) |
| 299 |
Field::make( 'html', 'scrollsequence_info_html_panorama' )->set_conditional_logic( $scrollsequence_condition_need_images )->set_html( '<h3>' . __( 'Image Scale and Alignment', 'scrollsequence' ) . '</h3>' ), |
| 300 |
Field::make( 'select', 'scrollsequence_p_scaleto_mobile', __( 'Portrait (Mobile)', 'scrollsequence' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_width( 30 )->set_default_value( 'fill' )->set_options( array( |
| 301 |
'fill' => __( 'Scale to fill', 'scrollsequence' ), |
| 302 |
'fit' => __( 'Scale to fit', 'scrollsequence' ) . ' 100%', |
| 303 |
'0.5' => __( 'Scale to fit', 'scrollsequence' ) . ' 50%', |
| 304 |
) ), |
| 305 |
Field::make( 'text', 'scrollsequence_p_alignx_mobile', __( 'Horizontal Align', 'scrollsequence' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_help_text( $scrollsequence_left_center_right )->set_width( 35 )->set_attribute( 'type', 'range' )->set_classes( 'ssq-range-slider' )->set_default_value( '0.5' )->set_attribute( 'min', '0' )->set_attribute( 'max', '1' )->set_attribute( 'step', '0.5' ), |
| 306 |
// ROADM |
| 307 |
Field::make( 'text', 'scrollsequence_p_aligny_mobile', __( 'Vertical Align', 'scrollsequence' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_help_text( $scrollsequence_bottom_center_top )->set_width( 35 )->set_attribute( 'type', 'range' )->set_classes( 'ssq-range-slider' )->set_default_value( '0.5' )->set_attribute( 'min', '0' )->set_attribute( 'max', '1' )->set_attribute( 'step', '0.5' ), |
| 308 |
// ROADM |
| 309 |
// LANDSCAPE (DESKTOP) |
| 310 |
Field::make( 'select', 'scrollsequence_p_scaleto_desktop', __( 'Landscape (Desktop)', 'scrollsequence' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_width( 30 )->set_default_value( 'fill' )->set_options( array( |
| 311 |
'fill' => __( 'Scale to fill', 'scrollsequence' ), |
| 312 |
'fit' => __( 'Scale to fit', 'scrollsequence' ) . ' 100%', |
| 313 |
'0.5' => __( 'Scale to fit', 'scrollsequence' ) . ' 50%', |
| 314 |
) ), |
| 315 |
Field::make( 'text', 'scrollsequence_p_alignx_desktop', __( 'Horizontal Align', 'scrollsequence' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_help_text( $scrollsequence_left_center_right )->set_width( 35 )->set_attribute( 'type', 'range' )->set_classes( 'ssq-range-slider' )->set_default_value( '0.5' )->set_attribute( 'min', '0' )->set_attribute( 'max', '1' )->set_attribute( 'step', '0.5' ), |
| 316 |
// ROADM |
| 317 |
Field::make( 'text', 'scrollsequence_p_aligny_desktop', __( 'Vertical Align', 'scrollsequence' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_help_text( $scrollsequence_bottom_center_top )->set_width( 35 )->set_attribute( 'type', 'range' )->set_classes( 'ssq-range-slider' )->set_default_value( '0.5' )->set_attribute( 'min', '0' )->set_attribute( 'max', '1' )->set_attribute( 'step', '0.5' ), |
| 318 |
// ROADM |
| 319 |
Field::make( 'html', 'scrollsequence_info_html_freealignadv' )->set_conditional_logic( $scrollsequence_condition_need_images )->set_html( $scrollsequence_aglignmentadv ), |
| 320 |
) )->set_header_template( __( 'Scene', 'scrollsequence' ) . ' <%- $_index %>' )) ); |
| 321 |
// FREE |
| 322 |
$scrub_field = Field::make( 'html', 'scrollsequence_hidden', '' )->set_html( ' |
| 323 |
<style> |
| 324 |
.nevim{ |
| 325 |
line-height: 1.4; |
| 326 |
font-size: 13px; |
| 327 |
cursor: pointer; |
| 328 |
vertical-align: middle; |
| 329 |
display: block; |
| 330 |
padding-bottom: 5px; |
| 331 |
font-weight: 600; |
| 332 |
color: #23282d; |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
</style> |
| 337 |
<div class="nevim">' . __( 'Scroll Delay', 'scrollsequence' ) . '</div> |
| 338 |
<select disabled> |
| 339 |
<option value="0">0s (instant)</option> |
| 340 |
</select> |
| 341 |
<p>' . __( 'Scroll Delay Settings available only in', 'scrollsequence' ) . ' <a href=' . admin_url( "admin.php?page=scrollsequence-pricing" ) . '>Scrollsequence PRO</a>.</p>' ); |
| 342 |
$debug_multi_options_array = array( |
| 343 |
'debug' => __( 'General Debug', 'scrollsequence' ), |
| 344 |
'preloaddebug' => __( 'Image Preload Debug', 'scrollsequence' ), |
| 345 |
'detectdebug' => __( 'Device Detect Debug', 'scrollsequence' ), |
| 346 |
); |
| 347 |
$scrollsequence_trigger_start_field = Field::make( 'hidden', 'scrollsequence_trigger_start_hidden', '' )->set_classes( 'schovej-to-policko' ); |
| 348 |
$scrollsequence_trigger_end_field = Field::make( 'hidden', 'scrollsequence_trigger_end_hidden', '' )->set_classes( 'schovej-to-policko' ); |
| 349 |
// END OF FREE __(,'scrollsequence') |
| 350 |
Container::make( 'post_meta', 'Scrollsequence Settings' )->where( 'post_type', '=', 'scrollsequence' )->set_context( 'side' )->set_priority( 'low' )->add_fields( array( |
| 351 |
$scrollsequence_trigger_start_field, |
| 352 |
$scrollsequence_trigger_end_field, |
| 353 |
Field::make( 'select', 'scrollsequence_position', __( 'Position', 'scrollsequence' ) )->help_text( __( 'Sticky position fixes animation to the viewport. Static makes it flow with the rest of the page. Sticky behavior can be controlled via options. See more in documentation.', 'scrollsequence' ) )->add_options( array( |
| 354 |
'sticky' => __( 'Sticky (default)', 'scrollsequence' ), |
| 355 |
'absolute' => __( 'Absolute', 'scrollsequence' ), |
| 356 |
'static' => __( 'Static', 'scrollsequence' ), |
| 357 |
) ), |
| 358 |
$scrub_field, |
| 359 |
Field::make( 'select', 'scrollsequence_image_full_width', __( 'Image Width', 'scrollsequence' ) )->add_options( array( |
| 360 |
false => __( 'Content Width (default)', 'scrollsequence' ), |
| 361 |
true => __( 'Force Full Width', 'scrollsequence' ), |
| 362 |
) )->help_text( __( 'Select "Force Full Width" to overrride your templates default width. If the setting does not work, use full width template included in your Theme.', 'scrollsequence' ) ), |
| 363 |
Field::make( 'text', 'scrollsequence_image_opacity', __( 'Image Opacity', 'scrollsequence' ) )->set_attribute( 'type', 'number' )->set_required( true )->set_default_value( '1' )->set_attribute( 'min', '0' )->set_attribute( 'max', '1' )->set_attribute( 'step', '0.01' ), |
| 364 |
// THIS IS QUITE COMPLEX - ACTIVATE LATER ??? |
| 365 |
// Field::make( 'text', 'scrollsequence_image_zindex', __( 'Image z-index (optional)' ) ) |
| 366 |
// //->set_help_text( '' ) |
| 367 |
// ->set_attribute( 'type', 'number' ) |
| 368 |
// ->set_attribute( 'min', '-9999' ) |
| 369 |
// ->set_attribute( 'max', '9999' ) |
| 370 |
// ->set_attribute( 'step', '1' ), |
| 371 |
// Field::make( 'select', 'scrollsequence_content_spacer', 'Classic Content Position' ) // LEGACY |
| 372 |
// ->add_options( array( // LEGACY |
| 373 |
// 'after100' => 'End of Document (default)', // LEGACY |
| 374 |
// 'after' => 'End of Document (with overlap) ', // LEGACY |
| 375 |
// 'during' => 'Start of Document', |
| 376 |
// ) ), |
| 377 |
Field::make( 'textarea', 'scrollsequence_custom_css', __( 'Custom CSS', 'scrollsequence' ) )->set_default_value( '.ssq-center-center{ |
| 378 |
position: absolute; |
| 379 |
left: 50%; |
| 380 |
top: 50%; |
| 381 |
transform: translate(-50%, -50%); |
| 382 |
text-shadow: 0 0 8px white; |
| 383 |
text-align: center; |
| 384 |
} |
| 385 |
' )->help_text( __( 'Enter custom CSS here.', 'scrollsequence' ) ), |
| 386 |
Field::make( "multiselect", "scrollsequence_debug_multi", __( "Show Development Information", 'scrollsequence' ) )->add_options( $debug_multi_options_array ), |
| 387 |
) ); |
| 388 |
/* |
| 389 |
* SIDE CONTEXT - ADVANCED SETTINGS |
| 390 |
*/ |
| 391 |
Container::make( 'post_meta', 'Custom Post Settings' )->where( 'post_type', '=', 'scrollsequence' )->set_context( 'side' )->set_priority( 'low' )->add_fields( array( |
| 392 |
Field::make( 'color', 'scrollsequence_bodybgcolor', __( 'Body Background Color', 'scrollsequence' ) )->help_text( __( 'Set CSS attribute <i><strong>background-color</strong></i> of <i><strong>body.single-scrollsequence</strong></i> class.', 'scrollsequence' ) ), |
| 393 |
// Field::make( 'color', 'scrollsequence_classic_content_after_bgcolor', __( 'Background Color - After Scrollsequence' ) ) |
| 394 |
// ->help_text('Use in case you want to have different background color after the scrollsequence is finished. Only active when there is content after the image sequence. ') |
| 395 |
// , |
| 396 |
Field::make( 'checkbox', 'scrollsequence_show_sidebar', __( 'Show Sidebar', 'scrollsequence' ) )->set_option_value( 'yes' )->help_text( __( 'Experimental, take care', 'scrollsequence' ) ), |
| 397 |
Field::make( 'checkbox', 'scrollsequence_show_footer', __( 'Show Footer', 'scrollsequence' ) )->set_option_value( 'yes' )->help_text( __( 'Experimental, take care. <br>(This setting displays footer element and changes z-index to 9999)', 'scrollsequence' ) ), |
| 398 |
) ); |
| 399 |
} |
| 400 |
|
| 401 |
// END OF CARBON FIELD MAIN FUNCTION (CPT) |
| 402 |
/** |
| 403 |
* ROADM Alert Too Many Pages and Images |
| 404 |
* |
| 405 |
* @since 0.7.4 |
| 406 |
*/ |
| 407 |
public function scrollsequence_admin_notice() { |
| 408 |
// Ak: I want to add an IF statement to add admin notice only to scrollsequence post php |
| 409 |
global $post_type; |
| 410 |
global $pagenow; |
| 411 |
if ( $pagenow == 'post.php' && 'scrollsequence' == $post_type || $pagenow == 'post-new.php' && 'scrollsequence' == $post_type ) { |
| 412 |
echo '<div class="notice notice-warning" id="scrollsequence_notice_toomanyimg" style="display:none" ><p>' . __( 'Warning: Image limit reached. For performance reasons, free version allows maximum of 100 images on a single page. Images marked with "X" will not be displayed.', 'scrollsequence' ) . ' <a href="' . admin_url( 'admin.php?page=scrollsequence-pricing' ) . '">' . __( 'Upgrade to display unlimited images in your Scrollsequence', 'scrollsequence' ) . '</a>.</p></div>'; |
| 413 |
echo '<div class="notice notice-warning" id="scrollsequence_notice_toomanypages" style="display:none" ><p>' . __( 'Warning: Scene limit reached. For performance reasons, free version allows maximum of 3 scenes.', 'scrollsequence' ) . ' <a href="' . admin_url( 'admin.php?page=scrollsequence-pricing' ) . '">' . __( 'Upgrade to display unlimited scenes in your Scrollsequence', 'scrollsequence' ) . ' </a>.</p></div>'; |
| 414 |
} |
| 415 |
// Ak: end |
| 416 |
} |
| 417 |
|
| 418 |
/** |
| 419 |
* Classic Content Editor Heading |
| 420 |
* |
| 421 |
* @since 0.9.94 |
| 422 |
*/ |
| 423 |
public function scrollsequence_classic_content_html() { |
| 424 |
// Ak: I want to add an IF statement to add admin notice only to scrollsequence post php |
| 425 |
global $post_type; |
| 426 |
global $pagenow; |
| 427 |
if ( $pagenow == 'post.php' && 'scrollsequence' == $post_type || $pagenow == 'post-new.php' && 'scrollsequence' == $post_type ) { |
| 428 |
// IF Condition Changed 1.0.076 |
| 429 |
echo __( '<h1>Content Editor </h1> |
| 430 |
<p><strong>Place shortcode <i>[scrollsequence]</i> anywhere in the classic content to control image sequence position.<br> If not specified <i>[scrollsequence]</i> shortcode will be placed at the start of content automatically, rendering the image sequence at the begining of the page. </strong></p>', 'scrollsequence' ) . ' |
| 431 |
|
| 432 |
'; |
| 433 |
} |
| 434 |
// Ak: end |
| 435 |
} |
| 436 |
|
| 437 |
/** |
| 438 |
* Function that makes the scrollsequence shortcode happen.. |
| 439 |
* |
| 440 |
* Shortcode: [scrollsequence id="###"] |
| 441 |
* |
| 442 |
* |
| 443 |
* @since 0.9.95 |
| 444 |
*/ |
| 445 |
public function scrollsequence_shortcode( $atts ) { |
| 446 |
// Extract atts |
| 447 |
extract( shortcode_atts( array( |
| 448 |
'id' => get_the_id(), |
| 449 |
'margintop' => 0, |
| 450 |
'marginbottom' => 0, |
| 451 |
'hide' => false, |
| 452 |
), $atts ) ); |
| 453 |
// Sanitize atts // since 1.5.5 |
| 454 |
$id = (int) sanitize_text_field( $id ); |
| 455 |
$margintop = sanitize_text_field( $margintop ); |
| 456 |
// uses esc_attr later on |
| 457 |
$marginbottom = sanitize_text_field( $marginbottom ); |
| 458 |
// uses esc_attr later on |
| 459 |
$hide = sanitize_text_field( $hide ); |
| 460 |
// Get info from database |
| 461 |
$ssqInputZeroObject = array( |
| 462 |
'debug' => carbon_get_post_meta( $id, 'scrollsequence_debug_multi' ), |
| 463 |
'show_footer' => carbon_get_post_meta( $id, 'scrollsequence_show_footer' ), |
| 464 |
'show_sidebar' => carbon_get_post_meta( $id, 'scrollsequence_show_sidebar' ), |
| 465 |
'preloadPercentage' => esc_attr( get_option( 'ssq_option_preload_percentage', 0.12 ) ), |
| 466 |
'ssqFyiId' => $id, |
| 467 |
'siteUrl' => esc_attr( get_option( 'siteurl' ) ), |
| 468 |
); |
| 469 |
$ssqInputObject = array( |
| 470 |
'ssqId' => $id, |
| 471 |
'bodyBgColor' => carbon_get_post_meta( $id, 'scrollsequence_bodybgcolor' ), |
| 472 |
'imageOpacity' => carbon_get_post_meta( $id, 'scrollsequence_image_opacity' ), |
| 473 |
'scrub' => (float) carbon_get_post_meta( $id, 'scrollsequence_scrub' ), |
| 474 |
'forceFullWidth' => carbon_get_post_meta( $id, 'scrollsequence_image_full_width' ), |
| 475 |
'zIndex' => carbon_get_post_meta( $id, 'scrollsequence_image_zindex' ), |
| 476 |
'triggerStart' => carbon_get_post_meta( $id, 'scrollsequence_trigger_start' ), |
| 477 |
'triggerEnd' => carbon_get_post_meta( $id, 'scrollsequence_trigger_end' ), |
| 478 |
'canvasDPR' => esc_attr( get_option( 'ssq_option_canvas_dpr', 'quality' ) ), |
| 479 |
); |
| 480 |
// Rename info from database in JS format |
| 481 |
$ssqInputObject['page'] = array(); |
| 482 |
$ssqPageFromUI = carbon_get_post_meta( $id, 'scrollsequence_page' ); |
| 483 |
foreach ( $ssqPageFromUI as $x => $val ) { |
| 484 |
$ssqInputObject['page'][$x]['alignX']['desktop'] = $ssqPageFromUI[$x]['scrollsequence_p_alignx_desktop']; |
| 485 |
$ssqInputObject['page'][$x]['alignX']['mobile'] = $ssqPageFromUI[$x]['scrollsequence_p_alignx_mobile']; |
| 486 |
$ssqInputObject['page'][$x]['alignY']['desktop'] = $ssqPageFromUI[$x]['scrollsequence_p_aligny_desktop']; |
| 487 |
$ssqInputObject['page'][$x]['alignY']['mobile'] = $ssqPageFromUI[$x]['scrollsequence_p_aligny_mobile']; |
| 488 |
// $ssqInputObject['page'][$x]['pageDuration']= (float)$ssqPageFromUI[$x]['scrollsequence_p_duration']; |
| 489 |
$ssqInputObject['page'][$x]['imgDur'] = (float) $ssqPageFromUI[$x]['scrollsequence_p_imgdur']; |
| 490 |
$ssqInputObject['page'][$x]['scaleTo']['desktop'] = $ssqPageFromUI[$x]['scrollsequence_p_scaleto_desktop']; |
| 491 |
$ssqInputObject['page'][$x]['scaleTo']['mobile'] = $ssqPageFromUI[$x]['scrollsequence_p_scaleto_mobile']; |
| 492 |
// Loop Through Anim |
| 493 |
$ssqInputObject['page'][$x]['animEl'] = array(); |
| 494 |
// in case of empty |
| 495 |
foreach ( $ssqPageFromUI[$x]['ssqnce_anim'] as $z => $animvar ) { |
| 496 |
$ssqInputObject['page'][$x]['animEl'][$z] = $ssqPageFromUI[$x]['ssqnce_anim'][$z]; |
| 497 |
} |
| 498 |
} |
| 499 |
// If there is "hide" parameter -> enqueue mobile detect script and act based on parameter values. |
| 500 |
if ( $hide ) { |
| 501 |
$showDetectNotice = in_array( "detectdebug", carbon_get_post_meta( $id, 'scrollsequence_debug_multi' ) ); |
| 502 |
//echo '<!--Scrollsequence - Hide Parameter Exists: -->'; |
| 503 |
require_once 'mobile_detect/mobile_detect.php'; |
| 504 |
$detect = new Mobile_Detect(); |
| 505 |
// var_dump($detect); |
| 506 |
// Any mobile device (phones or tablets). |
| 507 |
if ( $detect->isMobile() && str_contains( strtolower( $hide ), 'ismobile' ) ) { |
| 508 |
return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isMobile </div>'; |
| 509 |
} |
| 510 |
if ( !$detect->isMobile() && str_contains( strtolower( $hide ), 'isnotmobile' ) ) { |
| 511 |
return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isNotMobile </div>'; |
| 512 |
} |
| 513 |
// Any tablet device. |
| 514 |
if ( $detect->isTablet() && str_contains( strtolower( $hide ), 'istablet' ) ) { |
| 515 |
return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isTablet </div>'; |
| 516 |
} |
| 517 |
if ( !$detect->isTablet() && str_contains( strtolower( $hide ), 'isnottablet' ) ) { |
| 518 |
return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isNotTablet </div>'; |
| 519 |
} |
| 520 |
// Exclude tablets. |
| 521 |
if ( $detect->isMobile() && !$detect->isTablet() && str_contains( strtolower( $hide ), 'isphone' ) ) { |
| 522 |
return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isPhone </div>'; |
| 523 |
} |
| 524 |
if ( !($detect->isMobile() && !$detect->isTablet()) && str_contains( strtolower( $hide ), 'isnotphone' ) ) { |
| 525 |
return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isNotPhone </div>'; |
| 526 |
} |
| 527 |
// Check for a specific platform with the help of the magic methods: |
| 528 |
if ( $detect->isiOS() && str_contains( strtolower( $hide ), 'isios' ) ) { |
| 529 |
return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isiOs </div>'; |
| 530 |
} |
| 531 |
if ( !$detect->isiOS() && str_contains( strtolower( $hide ), 'isnotios' ) ) { |
| 532 |
return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isNotiOs </div>'; |
| 533 |
} |
| 534 |
if ( $detect->isAndroidOS() && str_contains( strtolower( $hide ), 'isandroidos' ) ) { |
| 535 |
return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isAndroidOs </div>'; |
| 536 |
} |
| 537 |
if ( !$detect->isAndroidOS() && str_contains( strtolower( $hide ), 'isnotandroidos' ) ) { |
| 538 |
return '<div class="scrollsequence-mobile-detect-message" ' . (( $showDetectNotice ? '' : 'style="display:none' )) . '"> Scrollsequence Debug - MobileDetect: Hide because device isNotAndroidOs </div>'; |
| 539 |
} |
| 540 |
} |
| 541 |
// FREE |
| 542 |
foreach ( $ssqPageFromUI as $x => $val ) { |
| 543 |
// Loop Through IMAGES |
| 544 |
$ssqInputObject['page'][$x]['imagesFull'] = array(plugin_dir_url( __DIR__ ) . 'public/img/noimg.jpg'); |
| 545 |
//if empty |
| 546 |
if ( function_exists( 'get_rocket_cdn_url' ) ) { |
| 547 |
foreach ( $ssqPageFromUI[$x]['scrollsequence_p_images'] as $y => $imgvar ) { |
| 548 |
$ssqInputObject['page'][$x]['imagesFull'][$y] = get_rocket_cdn_url( wp_get_attachment_image_src( $ssqPageFromUI[$x]['scrollsequence_p_images'][$y], 'full' )[0] ); |
| 549 |
} |
| 550 |
} else { |
| 551 |
foreach ( $ssqPageFromUI[$x]['scrollsequence_p_images'] as $y => $imgvar ) { |
| 552 |
$ssqInputObject['page'][$x]['imagesFull'][$y] = wp_get_attachment_image_src( $ssqPageFromUI[$x]['scrollsequence_p_images'][$y], 'full' )[0]; |
| 553 |
} |
| 554 |
} |
| 555 |
$ssqInputObject['page'][$x]['imagesFull'] = array_splice( $ssqInputObject['page'][$x]['imagesFull'], 0, 100 ); |
| 556 |
} |
| 557 |
// Calculate lengths, spacers and absSpacers (SC is calculated in JS) |
| 558 |
$ssqInputObject['pageLength'] = count( $ssqInputObject['page'] ); |
| 559 |
$ssqInputObject['scSpacer'] = 0; |
| 560 |
$pageAbsSpacerTotal = 0; |
| 561 |
foreach ( $ssqPageFromUI as $x => $val ) { |
| 562 |
$ssqInputObject['page'][$x]['imagesLength'] = count( $ssqInputObject['page'][$x]['imagesFull'] ); |
| 563 |
$ssqInputObject['page'][$x]['animElLength'] = count( $ssqInputObject['page'][$x]['animEl'] ); |
| 564 |
$ssqInputObject['page'][$x]['pageSpacer'] = $ssqInputObject['page'][$x]['imagesLength'] * $ssqInputObject['page'][$x]['imgDur']; |
| 565 |
$ssqInputObject['scSpacer'] = $ssqInputObject['scSpacer'] + $ssqInputObject['page'][$x]['pageSpacer']; |
| 566 |
$ssqInputObject['page'][$x]['pageAbsBegin'] = $pageAbsSpacerTotal; |
| 567 |
$pageAbsSpacerTotal = $pageAbsSpacerTotal + $ssqInputObject['page'][$x]['pageSpacer']; |
| 568 |
$ssqInputObject['page'][$x]['pageAbsEnd'] = $pageAbsSpacerTotal; |
| 569 |
} |
| 570 |
// Sticky JS/CSS or Static - Deal with all here early on. - Since 1.3.0 |
| 571 |
$stickyOptionFromSettings = get_option( 'ssq_option_position_sticky', 'sticky-js' ); |
| 572 |
// second argument must be the same as default value, it needs to be here to cover if null |
| 573 |
if ( carbon_get_post_meta( $id, 'scrollsequence_position' ) == 'sticky' && $stickyOptionFromSettings == 'sticky-js' ) { |
| 574 |
// sticky js |
| 575 |
$ssqInputObject['position'] = 'sticky-js'; |
| 576 |
$stickyStyle = 'position:relative;box-sizing: border-box;'; |
| 577 |
$ssqDomSpacer = $ssqInputObject['scSpacer']; |
| 578 |
$ssqWrapStylePosition = ''; |
| 579 |
$absoluteScrollsequenceStyle = ''; |
| 580 |
} else { |
| 581 |
if ( carbon_get_post_meta( $id, 'scrollsequence_position' ) == 'sticky' && $stickyOptionFromSettings == 'sticky-css' ) { |
| 582 |
// sticky css |
| 583 |
$ssqInputObject['position'] = 'sticky-css'; |
| 584 |
$stickyStyle = 'position: -webkit-sticky;position:sticky;top:0;box-sizing: border-box;'; |
| 585 |
$ssqDomSpacer = $ssqInputObject['scSpacer']; |
| 586 |
$ssqWrapStylePosition = ''; |
| 587 |
$absoluteScrollsequenceStyle = ''; |
| 588 |
} else { |
| 589 |
if ( carbon_get_post_meta( $id, 'scrollsequence_position' ) == 'absolute' && $stickyOptionFromSettings == 'sticky-js' ) { |
| 590 |
// sticky js |
| 591 |
$ssqInputObject['position'] = 'sticky-js'; |
| 592 |
$stickyStyle = 'position:relative;box-sizing: border-box;'; |
| 593 |
$ssqDomSpacer = $ssqInputObject['scSpacer']; |
| 594 |
$ssqWrapStylePosition = 'position:absolute;'; |
| 595 |
$absoluteScrollsequenceStyle = 'style="display:block;position:relative;"'; |
| 596 |
} else { |
| 597 |
if ( carbon_get_post_meta( $id, 'scrollsequence_position' ) == 'absolute' && $stickyOptionFromSettings == 'sticky-css' ) { |
| 598 |
// sticky css |
| 599 |
$ssqInputObject['position'] = 'sticky-css'; |
| 600 |
$stickyStyle = 'position: -webkit-sticky;position:sticky;top:0;box-sizing: border-box;'; |
| 601 |
$ssqDomSpacer = $ssqInputObject['scSpacer']; |
| 602 |
$ssqWrapStylePosition = 'position:absolute;'; |
| 603 |
$absoluteScrollsequenceStyle = 'style="display:block;position:relative;"'; |
| 604 |
} else { |
| 605 |
// static |
| 606 |
//$ssqInputObject['carbongetpostmetascrollsequenceposition'] = carbon_get_post_meta( $id, 'scrollsequence_position'); |
| 607 |
//$ssqInputObject['get_optionssqoptionpositionsticky'] =$stickyOptionFromSettings; |
| 608 |
$ssqInputObject['position'] = 'static'; |
| 609 |
$stickyStyle = 'position:relative;box-sizing: border-box; '; |
| 610 |
$ssqDomSpacer = 0; |
| 611 |
$ssqWrapStylePosition = ''; |
| 612 |
$absoluteScrollsequenceStyle = 'style="display:block;position:relative;"'; |
| 613 |
} |
| 614 |
} |
| 615 |
} |
| 616 |
} |
| 617 |
// Localize/Inline Script |
| 618 |
static $ssqScCount = 0; |
| 619 |
if ( !$ssqScCount ) { |
| 620 |
// First run we need to declare variable and input |
| 621 |
$inlineData = 'var ssqInput={}; |
| 622 |
ssqInput=' . json_encode( $ssqInputZeroObject ) . '; |
| 623 |
ssqInput.sc=[]; |
| 624 |
ssqInput.sc[' . $ssqScCount . ']=' . json_encode( $ssqInputObject ) . ';'; |
| 625 |
} else { |
| 626 |
// All other runs just input |
| 627 |
$inlineData = 'ssqInput.sc[' . $ssqScCount . ']=' . json_encode( $ssqInputObject ) . ';'; |
| 628 |
} |
| 629 |
wp_enqueue_script( 'scrollsequence-lib' ); |
| 630 |
// Prepare for returning onlyonece HTML |
| 631 |
if ( !$ssqScCount ) { |
| 632 |
// First run |
| 633 |
$onlyonceHtml = ' |
| 634 |
|
| 635 |
<style> |
| 636 |
.scrollsequence-pages-wrap {height:100vh} |
| 637 |
.scrollsequence-page {position:absolute;display:none} |
| 638 |
|
| 639 |
.gsap-marker-scroller-start {z-index:999999!important;} |
| 640 |
</style> |
| 641 |
<noscript> |
| 642 |
<style> |
| 643 |
.scrollsequence-wrap {height:initial!important;} |
| 644 |
.scrollsequence-pages-wrap {height:initial} |
| 645 |
.scrollsequence-page {position:relative;opacity:initial;display:block ;visibility:initial} |
| 646 |
</style> |
| 647 |
</noscript> |
| 648 |
|
| 649 |
<div style="position: fixed;z-index:99999;bottom:50px;left: 100px;background:#383131b0;color:white; padding: 0.5rem; display:none" class="ssq-alert-container" id="ssqalert" > |
| 650 |
</div> |
| 651 |
|
| 652 |
'; |
| 653 |
} else { |
| 654 |
$onlyonceHtml = ''; |
| 655 |
} |
| 656 |
//all other runs |
| 657 |
// Style for each SC // since 1.5.5 added wp_kses_post() |
| 658 |
$customCssVar = ''; |
| 659 |
if ( !empty( carbon_get_post_meta( $id, 'scrollsequence_custom_css' ) ) ) { |
| 660 |
$customCssVar = ' |
| 661 |
<style> |
| 662 |
' . wp_kses_post( carbon_get_post_meta( $id, 'scrollsequence_custom_css' ) ) . ' |
| 663 |
</style> |
| 664 |
'; |
| 665 |
} |
| 666 |
// end of if not empty |
| 667 |
// Prepare for returning pages html |
| 668 |
$pagesHtml = array(); |
| 669 |
foreach ( $ssqPageFromUI as $p => $pagevar ) { |
| 670 |
/** |
| 671 |
* Filter Stuff |
| 672 |
* Since 1.1.2. |
| 673 |
* Inspired from: https://wordpress.stackexchange.com/questions/134582/apply-filtersthe-content-content-alternative |
| 674 |
* List of standard filters for the_content |
| 675 |
* source: https://core.trac.wordpress.org/browser/tags/5.7.2/src/wp-includes/default-filters.php#L131 |
| 676 |
* search for "the_content" to find what things are applied as standard |
| 677 |
*/ |
| 678 |
$filterSsqPageContent = do_blocks( $ssqPageFromUI[$p]['scrollsequence_p_wysiwyg'] ); |
| 679 |
// priority 9 // Introduced 5.0 |
| 680 |
$filterSsqPageContent = wptexturize( $filterSsqPageContent ); |
| 681 |
// Introduced 0.71 |
| 682 |
$filterSsqPageContent = wpautop( $filterSsqPageContent ); |
| 683 |
// Introduced 0.71 |
| 684 |
$filterSsqPageContent = do_shortcode( $filterSsqPageContent ); |
| 685 |
// Introduced 2.5 |
| 686 |
$filterSsqPageContent = shortcode_unautop( $filterSsqPageContent ); |
| 687 |
// Introduced in 2.9 |
| 688 |
$filterSsqPageContent = prepend_attachment( $filterSsqPageContent ); |
| 689 |
// Introduced in 2.0 |
| 690 |
// $filterSsqPageContent = wp_filter_content_tags($filterSsqPageContent); // Introducted in 5.5 - cannot use (yet) |
| 691 |
// $filterSsqPageContent = wp_replace_insecure_home_url($filterSsqPageContent); // Introducted WP 5.7 - cannot use (yet) |
| 692 |
$filterSsqPageContent = convert_smilies( $filterSsqPageContent ); |
| 693 |
// priority 20? // Introduced longtimeago |
| 694 |
/* |
| 695 |
!!! IMPORTANT: |
| 696 |
Below lines removes script tags and other potentially dangerous content, but may break some existing sites. |
| 697 |
Comment out next line if you want to allow script tags inside Fixed content |
| 698 |
*/ |
| 699 |
//$filterSsqPageContent = wp_kses_post($filterSsqPageContent); // New, security update since 1.5.5 |
| 700 |
// Page HTML |
| 701 |
$pagesHtml[$p] = ' |
| 702 |
<div class="scrollsequence-page" id="ssq-page-' . esc_attr( $ssqScCount ) . '-' . esc_attr( $p ) . '" style="box-sizing: border-box;height:100vh;width:100%;overflow:hidden!important;"> |
| 703 |
' . $filterSsqPageContent . ' |
| 704 |
</div> |
| 705 |
'; |
| 706 |
} |
| 707 |
// return |
| 708 |
$returnvar = ' |
| 709 |
|
| 710 |
<!-- Scrollsequence WP Plugin --> |
| 711 |
<scrollsequence ' . $absoluteScrollsequenceStyle . '> |
| 712 |
' . $onlyonceHtml . $customCssVar . ' |
| 713 |
<section class="scrollsequence-wrap ssq-wrap-' . esc_attr( $ssqScCount ) . ' " id="ssq-uid-' . esc_attr( get_the_id() ) . '-' . esc_attr( $ssqScCount ) . '-' . esc_attr( $id ) . '" style="' . esc_attr( $ssqWrapStylePosition ) . ';height: calc(100vh + ' . esc_attr( $ssqDomSpacer ) . 'px);padding:0;margin:0; margin-top:' . esc_attr( $margintop ) . ';margin-bottom:' . esc_attr( $marginbottom ) . '; width:100%; max-width:initial;box-sizing: border-box;border:-1px dashed blue;"> |
| 714 |
<div class="scrollsequence-sticky" style="' . esc_attr( $stickyStyle ) . '"> |
| 715 |
<canvas class="scrollsequence-canvas" style="position:absolute;"></canvas> |
| 716 |
<div class="scrollsequence-pages-wrap" style="position:relative; margin:0; padding:0; box-sizing: border-box;"> |
| 717 |
' . implode( " ", $pagesHtml ) . ' |
| 718 |
</div> |
| 719 |
</div><!-- .scrollsequence-sticky --> |
| 720 |
|
| 721 |
|
| 722 |
</section><!-- .scrollsequence-wrap --> |
| 723 |
' . '<script class="scrollsequence-input-script"> |
| 724 |
' . $inlineData . ' |
| 725 |
</script> |
| 726 |
</scrollsequence> |
| 727 |
'; |
| 728 |
// Free |
| 729 |
$ssqScCount++; |
| 730 |
if ( $ssqScCount <= 1 ) { |
| 731 |
return $returnvar; |
| 732 |
} else { |
| 733 |
return '<section><h5 style="border:2px solid; padding:20px">' . __( 'For performance reasons only one shortcode is allowed in Scrollsequence FREE.', 'scrollsequence' ) . '<br><br> <a href="' . admin_url( 'admin.php?page=scrollsequence-pricing' ) . '">' . __( 'Upgrade to PRO version for unlimited shortcodes.', 'scrollsequence' ) . '</a> </h5></section>'; |
| 734 |
} |
| 735 |
// end of else count other than zero |
| 736 |
// end of free |
| 737 |
} |
| 738 |
|
| 739 |
// end of scrollsequence_shortcode function |
| 740 |
/** |
| 741 |
* Add Columns to Custom Post Type List |
| 742 |
* |
| 743 |
* |
| 744 |
*/ |
| 745 |
function scrollsequence_admin_columns( $columns ) { |
| 746 |
$columns = array( |
| 747 |
'cb' => $columns['cb'], |
| 748 |
'title' => __( 'Title', 'scrollsequence' ), |
| 749 |
'ssq_shortcode' => __( 'Shortcode', 'scrollsequence' ), |
| 750 |
'date' => __( 'Date', 'scrollsequence' ), |
| 751 |
'author' => __( 'Author', 'scrollsequence' ), |
| 752 |
); |
| 753 |
return $columns; |
| 754 |
} |
| 755 |
|
| 756 |
function scrollsequence_admin_column_content( $column, $id ) { |
| 757 |
if ( 'ssq_shortcode' == $column ) { |
| 758 |
echo '[scrollsequence id="' . esc_attr( (int) $id ) . '"]'; |
| 759 |
} |
| 760 |
} |
| 761 |
|
| 762 |
/** |
| 763 |
* Admin Columns - FEATURED IMAGE |
| 764 |
* |
| 765 |
* Since 1.2.0 |
| 766 |
* |
| 767 |
* |
| 768 |
*/ |
| 769 |
function ssq_add_thumbnail_column( $columns ) { |
| 770 |
$columns['ssq_post_thumb'] = __( 'Featured Image', 'scrollsequence' ); |
| 771 |
return $columns; |
| 772 |
} |
| 773 |
|
| 774 |
function ssq_display_thumbnail_column( $column_name, $post_id ) { |
| 775 |
switch ( $column_name ) { |
| 776 |
case 'ssq_post_thumb': |
| 777 |
$post_thumbnail_id = get_post_thumbnail_id( $post_id ); |
| 778 |
if ( $post_thumbnail_id ) { |
| 779 |
$post_thumbnail_img = wp_get_attachment_image_src( $post_thumbnail_id, 'thumbnail' ); |
| 780 |
echo '<img width="64" src="' . esc_url( $post_thumbnail_img[0] ) . '" />'; |
| 781 |
} else { |
| 782 |
// no thumbnail, try to use something else |
| 783 |
$idOfFirstImage = carbon_get_post_meta( get_the_ID(), 'scrollsequence_page' ); |
| 784 |
//var_dump($idOfFirstImage); |
| 785 |
// Check that is array check that images is array and finally check that count of images is bigger than one. |
| 786 |
if ( is_array( $idOfFirstImage ) && count( $idOfFirstImage ) > 0 && is_array( $idOfFirstImage[0]['scrollsequence_p_images'] ) && count( $idOfFirstImage[0]['scrollsequence_p_images'] ) > 0 ) { |
| 787 |
// first image in sequence exists |
| 788 |
echo '<img width="64" src="' . esc_url( wp_get_attachment_image_src( $idOfFirstImage[0]['scrollsequence_p_images'][0], 'thumbnail' )[0] ) . '" />'; |
| 789 |
} else { |
| 790 |
// there are no images here |
| 791 |
echo 'No Image'; |
| 792 |
} |
| 793 |
} |
| 794 |
break; |
| 795 |
} |
| 796 |
} |
| 797 |
|
| 798 |
/** |
| 799 |
* Register Settings Options in Scrollsequence Options Dashboard |
| 800 |
* |
| 801 |
* @since 1.1.1 |
| 802 |
*/ |
| 803 |
function scrollsequence_register_options_settings() { |
| 804 |
// whitelist options |
| 805 |
register_setting( 'scrollsequence-settings-group', 'ssq_option_preload_percentage', array( |
| 806 |
'default' => 0.12, |
| 807 |
) ); |
| 808 |
register_setting( 'scrollsequence-settings-group', 'ssq_option_position_sticky', array( |
| 809 |
'default' => 'sticky-js', |
| 810 |
) ); |
| 811 |
// since 1.3.0 |
| 812 |
register_setting( 'scrollsequence-settings-group', 'ssq_option_canvas_dpr', array( |
| 813 |
'default' => 'quality', |
| 814 |
) ); |
| 815 |
// since 1.3.3 |
| 816 |
// TODO |
| 817 |
// register_setting( 'scrollsequence-settings-group', 'ssq_option_scroller_proxy' ); // not implemented yet |
| 818 |
// register_setting( 'scrollsequence-settings-group', 'ssq_option_elementor_widget' ); // not implemented yet |
| 819 |
} |
| 820 |
|
| 821 |
/** |
| 822 |
* DUPLICATE SCROLLSEQUENCE |
| 823 |
* @snippet Duplicate posts and pages without plugins |
| 824 |
* @author Misha Rudrastyh |
| 825 |
* @url https://rudrastyh.com/wordpress/duplicate-post.html |
| 826 |
* |
| 827 |
*/ |
| 828 |
// Add the duplicate link to action list for post_row_actions for "post" and custom post types |
| 829 |
function ssq_duplicate_post_link( $actions, $post ) { |
| 830 |
if ( !current_user_can( 'edit_posts' ) ) { |
| 831 |
return $actions; |
| 832 |
} |
| 833 |
if ( $post->post_type !== 'scrollsequence' ) { |
| 834 |
return $actions; |
| 835 |
} |
| 836 |
$url = wp_nonce_url( add_query_arg( array( |
| 837 |
'action' => 'duplicate_scrollsequence_as_draft', |
| 838 |
'post' => $post->ID, |
| 839 |
), 'admin.php' ), basename( __FILE__ ), 'duplicate_ssq_nonce' ); |
| 840 |
$actions['duplicate_ssq'] = '<a href="' . $url . '" title="' . __( 'Duplicate Scrollsequence' ) . '" rel="permalink">' . __( 'Duplicate' ) . '</a>'; |
| 841 |
return $actions; |
| 842 |
} |
| 843 |
|
| 844 |
/* |
| 845 |
* Function creates post duplicate as a draft and redirects then to the edit post screen |
| 846 |
*/ |
| 847 |
function duplicate_scrollsequence_as_draft() { |
| 848 |
// check if post ID has been provided and action |
| 849 |
if ( empty( $_GET['post'] ) ) { |
| 850 |
wp_die( 'No post to duplicate has been provided!' ); |
| 851 |
} |
| 852 |
// Nonce verification |
| 853 |
if ( !isset( $_GET['duplicate_ssq_nonce'] ) || !wp_verify_nonce( $_GET['duplicate_ssq_nonce'], basename( __FILE__ ) ) ) { |
| 854 |
return; |
| 855 |
} |
| 856 |
// Get the original post id |
| 857 |
$post_id = absint( $_GET['post'] ); |
| 858 |
// And all the original post data then |
| 859 |
$post = get_post( $post_id ); |
| 860 |
/* |
| 861 |
* if you don't want current user to be the new post author, |
| 862 |
* then change next couple of lines to this: $new_post_author = $post->post_author; |
| 863 |
*/ |
| 864 |
$current_user = wp_get_current_user(); |
| 865 |
$new_post_author = $current_user->ID; |
| 866 |
// if post data exists (I am sure it is, but just in a case), create the post duplicate |
| 867 |
if ( $post ) { |
| 868 |
// new post data array |
| 869 |
$args = array( |
| 870 |
'comment_status' => $post->comment_status, |
| 871 |
'ping_status' => $post->ping_status, |
| 872 |
'post_author' => $new_post_author, |
| 873 |
'post_content' => $post->post_content, |
| 874 |
'post_excerpt' => $post->post_excerpt, |
| 875 |
'post_name' => $post->post_name, |
| 876 |
'post_parent' => $post->post_parent, |
| 877 |
'post_password' => $post->post_password, |
| 878 |
'post_status' => 'draft', |
| 879 |
'post_title' => $post->post_title . '_duplicate', |
| 880 |
'post_type' => $post->post_type, |
| 881 |
'to_ping' => $post->to_ping, |
| 882 |
'menu_order' => $post->menu_order, |
| 883 |
); |
| 884 |
// insert the post by wp_insert_post() function |
| 885 |
$new_post_id = wp_insert_post( $args ); |
| 886 |
/* |
| 887 |
* get all current post terms ad set them to the new post draft |
| 888 |
*/ |
| 889 |
$taxonomies = get_object_taxonomies( get_post_type( $post ) ); |
| 890 |
// returns array of taxonomy names for post type, ex array("category", "post_tag"); |
| 891 |
if ( $taxonomies ) { |
| 892 |
foreach ( $taxonomies as $taxonomy ) { |
| 893 |
$post_terms = wp_get_object_terms( $post_id, $taxonomy, array( |
| 894 |
'fields' => 'slugs', |
| 895 |
) ); |
| 896 |
wp_set_object_terms( |
| 897 |
$new_post_id, |
| 898 |
$post_terms, |
| 899 |
$taxonomy, |
| 900 |
false |
| 901 |
); |
| 902 |
} |
| 903 |
} |
| 904 |
// duplicate all post meta |
| 905 |
$post_meta = get_post_meta( $post_id ); |
| 906 |
if ( $post_meta ) { |
| 907 |
foreach ( $post_meta as $meta_key => $meta_values ) { |
| 908 |
if ( '_wp_old_slug' == $meta_key ) { |
| 909 |
// do nothing for this meta key |
| 910 |
continue; |
| 911 |
} |
| 912 |
foreach ( $meta_values as $meta_value ) { |
| 913 |
add_post_meta( $new_post_id, $meta_key, $meta_value ); |
| 914 |
} |
| 915 |
} |
| 916 |
} |
| 917 |
// finally, redirect to the edit post screen for the new draft |
| 918 |
// wp_safe_redirect( |
| 919 |
// add_query_arg( |
| 920 |
// array( |
| 921 |
// 'action' => 'edit', |
| 922 |
// 'post' => $new_post_id |
| 923 |
// ), |
| 924 |
// admin_url( 'post.php' ) |
| 925 |
// ) |
| 926 |
// ); |
| 927 |
// exit; |
| 928 |
// or we can redirect to all posts with a message |
| 929 |
wp_safe_redirect( add_query_arg( array( |
| 930 |
'post_type' => ( 'post' !== get_post_type( $post ) ? get_post_type( $post ) : false ), |
| 931 |
'saved' => 'post_duplication_created', |
| 932 |
), admin_url( 'edit.php' ) ) ); |
| 933 |
exit; |
| 934 |
} else { |
| 935 |
wp_die( 'Post creation failed, could not find original post.' ); |
| 936 |
} |
| 937 |
} |
| 938 |
|
| 939 |
/* |
| 940 |
* In case we decided to add admin notices |
| 941 |
*/ |
| 942 |
function ssq_duplication_admin_notice() { |
| 943 |
// Get the current screen |
| 944 |
$screen = get_current_screen(); |
| 945 |
if ( 'edit' !== $screen->base ) { |
| 946 |
return; |
| 947 |
} |
| 948 |
//Checks if settings updated |
| 949 |
if ( isset( $_GET['saved'] ) && 'post_duplication_created' == $_GET['saved'] ) { |
| 950 |
echo '<div class="notice notice-success is-dismissible"><p>' . __( 'Copy created.' ) . '</p></div>'; |
| 951 |
} |
| 952 |
} |
| 953 |
|
| 954 |
// end of duplicate |
| 955 |
/** |
| 956 |
* This function defines helpscout beacon |
| 957 |
* |
| 958 |
* |
| 959 |
*/ |
| 960 |
public function ssq_add_helpscout_beacon() { |
| 961 |
global $post_type; |
| 962 |
//var_dump($post_type); |
| 963 |
global $pagenow; |
| 964 |
//var_dump($pagenow); |
| 965 |
if ( 'scrollsequence' == $post_type && ('post-new.php' === $pagenow || 'post.php' === $pagenow) || 'scrollsequence' == $post_type && 'edit.php' === $pagenow || 'admin.php' === $pagenow && isset( $_GET['page'] ) && $_GET['page'] === 'scrollsequence-dashboard' || 'admin.php' === $pagenow && isset( $_GET['page'] ) && $_GET['page'] === 'scrollsequence-account' || 'admin.php' === $pagenow && isset( $_GET['page'] ) && $_GET['page'] === 'scrollsequence-contact' ) { |
| 966 |
// Inline Script on admin screen - not ready yet, too few articles in the thing. |
| 967 |
?> |
| 968 |
<script type="text/javascript">!function(e,t,n){function a(){var e=t.getElementsByTagName("script")[0],n=t.createElement("script");n.type="text/javascript",n.async=!0,n.src="https://beacon-v2.helpscout.net",e.parentNode.insertBefore(n,e)}if(e.Beacon=n=function(t,n,a){e.Beacon.readyQueue.push({method:t,options:n,data:a})},n.readyQueue=[],"complete"===t.readyState)return a();e.attachEvent?e.attachEvent("onload",a):e.addEventListener("load",a,!1)}(window,document,window.Beacon||function(){});</script> |
| 969 |
<script type="text/javascript">window.Beacon('init', '751bcab8-88ed-4f04-9255-788822978f93')</script> |
| 970 |
<?php |
| 971 |
} |
| 972 |
} |
| 973 |
|
| 974 |
} |
| 975 |
|
| 976 |
// end of class Scrollsequence_Admin |