| 1 |
<?php |
| 2 |
|
| 3 |
use Carbon_Fields\Container ; |
| 4 |
use Carbon_Fields\Field ; |
| 5 |
//use Carbon_Fields\Block; //not at the moment |
| 6 |
/** |
| 7 |
* The admin-specific functionality of the plugin. |
| 8 |
* |
| 9 |
* @link www.scrollsequence.com |
| 10 |
* @since 0.7.0 |
| 11 |
* |
| 12 |
* @package Scrollsequence |
| 13 |
* @subpackage Scrollsequence/admin |
| 14 |
*/ |
| 15 |
/** |
| 16 |
* The admin-specific functionality of the plugin. |
| 17 |
* |
| 18 |
* Defines the plugin name, version, and two examples hooks for how to |
| 19 |
* enqueue the admin-specific stylesheet and JavaScript. |
| 20 |
* |
| 21 |
* @package Scrollsequence |
| 22 |
* @subpackage Scrollsequence/admin |
| 23 |
* @author Scrollsequence <info@scrollsequence.com> |
| 24 |
*/ |
| 25 |
class Scrollsequence_Admin |
| 26 |
{ |
| 27 |
/** |
| 28 |
* The ID of this plugin. |
| 29 |
* |
| 30 |
* @since 0.7.0 |
| 31 |
* @access private |
| 32 |
* @var string $plugin_name The ID of this plugin. |
| 33 |
*/ |
| 34 |
private $plugin_name ; |
| 35 |
/** |
| 36 |
* The version of this plugin. |
| 37 |
* |
| 38 |
* @since 0.7.0 |
| 39 |
* @access private |
| 40 |
* @var string $version The current version of this plugin. |
| 41 |
*/ |
| 42 |
private $version ; |
| 43 |
/** |
| 44 |
* Initialize the class and set its properties. |
| 45 |
* |
| 46 |
* @since 0.7.0 |
| 47 |
* @param string $plugin_name The name of this plugin. |
| 48 |
* @param string $version The version of this plugin. |
| 49 |
*/ |
| 50 |
public function __construct( $plugin_name, $version ) |
| 51 |
{ |
| 52 |
$this->plugin_name = $plugin_name; |
| 53 |
$this->version = $version; |
| 54 |
add_shortcode( 'scrollsequence', array( $this, 'scrollsequence_shortcode' ) ); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Register the stylesheets for the admin area. |
| 59 |
* |
| 60 |
* @since 0.7.0 |
| 61 |
*/ |
| 62 |
public function enqueue_styles() |
| 63 |
{ |
| 64 |
/** |
| 65 |
* This function is provided for demonstration purposes only. |
| 66 |
* |
| 67 |
* An instance of this class should be passed to the run() function |
| 68 |
* defined in Scrollsequence_Loader as all of the hooks are defined |
| 69 |
* in that particular class. |
| 70 |
* |
| 71 |
* The Scrollsequence_Loader will then create the relationship |
| 72 |
* between the defined hooks and the functions defined in this |
| 73 |
* class. |
| 74 |
*/ |
| 75 |
// Ak: I want to add an IF statement to enqueue scripts only to my CPT |
| 76 |
global $post_type ; |
| 77 |
if ( 'scrollsequence' == $post_type ) { |
| 78 |
wp_enqueue_style( |
| 79 |
$this->plugin_name, |
| 80 |
plugin_dir_url( __FILE__ ) . 'css/scrollsequence-admin.css', |
| 81 |
array(), |
| 82 |
$this->version, |
| 83 |
'all' |
| 84 |
); |
| 85 |
} |
| 86 |
// Ak: end |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Register the JavaScript for the admin area. |
| 91 |
* |
| 92 |
* @since 0.7.0 |
| 93 |
*/ |
| 94 |
public function enqueue_scripts() |
| 95 |
{ |
| 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 |
{ |
| 130 |
require_once "create-cpt.php"; |
| 131 |
} |
| 132 |
|
| 133 |
/** |
| 134 |
* Register Scrollsequence CPT . |
| 135 |
* |
| 136 |
* @since 0.7.3 |
| 137 |
*/ |
| 138 |
public function scrollsequence_cpt_submenu() |
| 139 |
{ |
| 140 |
add_submenu_page( |
| 141 |
'edit.php?post_type=scrollsequence', |
| 142 |
/*parent_slug*/ |
| 143 |
'Dashboard Scrollsequence', |
| 144 |
/*page title*/ |
| 145 |
'Dashboard', |
| 146 |
/*menu title*/ |
| 147 |
'edit_posts', |
| 148 |
/*roles and capability needed*/ |
| 149 |
// Update 0.9.93 |
| 150 |
'dashboard', |
| 151 |
/*menu slug*/ |
| 152 |
'scrollsequence_cpt_dashboard_callback' |
| 153 |
); |
| 154 |
function scrollsequence_cpt_dashboard_callback() |
| 155 |
{ |
| 156 |
//include_once 'dashboard.php'; - results on parse error |
| 157 |
require_once "partials/scrollsequence-admin-display.php"; |
| 158 |
} |
| 159 |
|
| 160 |
} |
| 161 |
|
| 162 |
/** |
| 163 |
* Single file custom template for scrollsequence. I am following this: |
| 164 |
* https://code.tutsplus.com/tutorials/a-guide-to-wordpress-custom-post-types-creation-display-and-meta-boxes--wp-27645 |
| 165 |
* ref "tutsplus" in class-scrollsequence add action thing |
| 166 |
* @since 0.7.0 |
| 167 |
* @uses i dont know |
| 168 |
* Step 1 https://blog.wplauncher.com/add-meta-box-wordpress-custom-post-type/ |
| 169 |
*/ |
| 170 |
public function scrollsequence_template( $template_path ) |
| 171 |
{ |
| 172 |
if ( get_post_type() == 'scrollsequence' ) { |
| 173 |
if ( is_single() ) { |
| 174 |
// checks if the file exists in the theme first, |
| 175 |
// otherwise serve the file from the plugin |
| 176 |
|
| 177 |
if ( $theme_file = locate_template( array( 'single-scrollsequence.php' ) ) ) { |
| 178 |
$template_path = $theme_file; |
| 179 |
} else { |
| 180 |
$template_path = plugin_dir_path( __DIR__ ) . 'public/partials/single-scrollsequence.php'; |
| 181 |
} |
| 182 |
|
| 183 |
} |
| 184 |
} |
| 185 |
return $template_path; |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* Carbon Fields Boot function. This function boots up carbon fields. |
| 190 |
* |
| 191 |
* @since 0.9.8 |
| 192 |
*/ |
| 193 |
public function scrollsequence_carbon_fields_load() |
| 194 |
{ |
| 195 |
require_once __DIR__ . '/../includes/carbonfields/autoload.php'; |
| 196 |
\Carbon_Fields\Carbon_Fields::boot(); |
| 197 |
} |
| 198 |
|
| 199 |
/** |
| 200 |
* Carbon Fields Main Function (Scrollsequence CPT) |
| 201 |
* |
| 202 |
* @since 0.9.8 |
| 203 |
*/ |
| 204 |
public function scrollsequence_carbon_fields_cpt() |
| 205 |
{ |
| 206 |
$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. '; |
| 207 |
$scrollsequence_left_center_right = ' |
| 208 |
<div style="float: left">Left</div> |
| 209 |
<div style="float: right">Right</div> |
| 210 |
<div style="margin: 0 auto; width: 100px;"></div> |
| 211 |
'; |
| 212 |
$scrollsequence_bottom_center_top = ' |
| 213 |
<div style="float: left">Top</div> |
| 214 |
<div style="float: right">Bottom</div> |
| 215 |
<div style="margin: 0 auto; width: 100px;"></div> |
| 216 |
'; |
| 217 |
$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>'; |
| 218 |
$scrollsequence_condition_need_images = array( |
| 219 |
'relation' => 'AND', |
| 220 |
array( |
| 221 |
'field' => 'scrollsequence_p_images', |
| 222 |
'value' => '', |
| 223 |
'compare' => '!=', |
| 224 |
), |
| 225 |
); |
| 226 |
// FREE VERSION |
| 227 |
Container::make( 'post_meta', 'Scrollsequence' )->where( 'post_type', '=', 'scrollsequence' )->set_context( 'carbon_fields_after_title' )->add_fields( array( Field::make( 'complex', 'scrollsequence_page', 'Page' )->setup_labels( array( |
| 228 |
'plural_name' => 'Pages', |
| 229 |
'singular_name' => 'Page', |
| 230 |
) )->set_layout( 'tabbed-horizontal' )->set_required( true )->set_max( 3 )->add_fields( array( |
| 231 |
Field::make( 'rich_text', 'scrollsequence_p_wysiwyg', __( 'Page Content' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_default_value( '<div class="ssq-center-center"><h1 id="on-earth">Another day on Earth. </h1></div> |
| 232 |
' ), |
| 233 |
Field::make( 'media_gallery', 'scrollsequence_p_images', __( 'Image Sequence' ) )->set_type( array( 'image' ) )->set_required( true )->set_duplicates_allowed( true )->set_classes( 'scrollsequence-custom-class' ), |
| 234 |
Field::make( 'complex', 'ssqnce_anim', 'Content Animation' )->set_conditional_logic( $scrollsequence_condition_need_images )->set_layout( 'tabbed-vertical' )->setup_labels( array( |
| 235 |
'plural_name' => 'Animations', |
| 236 |
'singular_name' => 'Animation', |
| 237 |
) )->add_fields( 'ssqnce_anim_io', 'Animate From/To', array( |
| 238 |
Field::make( 'text', 'ssqnce_anim_io_id', 'Selector' )->set_width( 20 )->set_required( true )->set_help_text( 'Enter #id or .class selector' ), |
| 239 |
Field::make( 'text', 'ssqnce_anim_io_start', 'Start' )->set_width( 20 )->set_required( true )->set_help_text( 'Enter image number where element becomes visible' )->set_attribute( 'type', 'number' )->set_attribute( 'min', '0' )->set_attribute( 'step', '1' ), |
| 240 |
Field::make( 'text', 'ssqnce_anim_io_end', 'End' )->set_width( 20 )->set_required( true )->set_help_text( 'Enter image number where element is hidden' )->set_attribute( 'type', 'number' )->set_attribute( 'min', '0' )->set_attribute( 'step', '1' ), |
| 241 |
// Free advert |
| 242 |
Field::make( 'separator', 'scrollsequence_advert', 'Animation Settings Not Available in Free Version' )->set_help_text( $scrollsequence_advert_html ), |
| 243 |
) )->set_header_template( ' Animate |
| 244 |
<% if (ssqnce_anim_io_id) { %> |
| 245 |
- <%- ssqnce_anim_io_id %> |
| 246 |
<% } %> |
| 247 |
' ), |
| 248 |
// PRO ONLY END1 |
| 249 |
// Field::make( 'text', 'scrollsequence_p_duration', __( 'Page Height (vh)' ) ) |
| 250 |
// ->set_conditional_logic($scrollsequence_condition_need_images) |
| 251 |
// ->set_attribute( 'type', 'number' ) |
| 252 |
// ->set_required( true ) |
| 253 |
// ->set_default_value('200') |
| 254 |
// ->set_attribute( 'min', '20' ) |
| 255 |
// ->set_attribute( 'max', '2000' ) |
| 256 |
// ->set_attribute( 'step', '1' ) |
| 257 |
// ->help_text('This sets the amount of scroll needed to get past this page.'), |
| 258 |
Field::make( 'text', 'scrollsequence_p_imgdur', __( 'Image Duration (px)' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_attribute( 'type', 'number' )->set_required( true )->set_default_value( '10' )->set_attribute( 'min', '5' )->set_attribute( 'max', '500' )->set_attribute( 'step', '1' )->help_text( 'This sets how far the images are apart.' ), |
| 259 |
// PANORAMA (MOBILE) |
| 260 |
Field::make( 'html', 'scrollsequence_info_html_panorama' )->set_conditional_logic( $scrollsequence_condition_need_images )->set_html( '<h3>Image Scale and Alignment</h3>' ), |
| 261 |
Field::make( 'select', 'scrollsequence_p_scaleto_mobile', __( 'Panorama (Mobile)' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_width( 30 )->set_default_value( 'fill' )->set_options( array( |
| 262 |
'fill' => ' Scale to fill', |
| 263 |
'fit' => 'Scale to fit 100%', |
| 264 |
'0.5' => 'Scale to fit 50%', |
| 265 |
) ), |
| 266 |
Field::make( 'text', 'scrollsequence_p_alignx_mobile', 'Horizontal Align' )->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' ), |
| 267 |
// ROADM |
| 268 |
Field::make( 'text', 'scrollsequence_p_aligny_mobile', 'Vertical Align' )->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' ), |
| 269 |
// ROADM |
| 270 |
// LANDSCAPE (DESKTOP) |
| 271 |
Field::make( 'select', 'scrollsequence_p_scaleto_desktop', __( 'Landscape (Desktop)' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_width( 30 )->set_default_value( 'fill' )->set_options( array( |
| 272 |
'fill' => ' Scale to fill', |
| 273 |
'fit' => 'Scale to fit 100%', |
| 274 |
'0.5' => 'Scale to fit 50%', |
| 275 |
) ), |
| 276 |
Field::make( 'text', 'scrollsequence_p_alignx_desktop', 'Horizontal Align' )->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' ), |
| 277 |
// ROADM |
| 278 |
Field::make( 'text', 'scrollsequence_p_aligny_desktop', 'Vertical Align' )->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' ), |
| 279 |
// ROADM |
| 280 |
Field::make( 'html', 'scrollsequence_info_html_freealignadv' )->set_conditional_logic( $scrollsequence_condition_need_images )->set_html( $scrollsequence_aglignmentadv ), |
| 281 |
) )->set_header_template( 'Page <%- $_index %>' ) ) ); |
| 282 |
// FREE |
| 283 |
$scrub_field = Field::make( 'html', 'scrollsequence_hidden', '' )->set_html( ' |
| 284 |
<style> |
| 285 |
.nevim{ |
| 286 |
line-height: 1.4; |
| 287 |
font-size: 13px; |
| 288 |
cursor: pointer; |
| 289 |
vertical-align: middle; |
| 290 |
display: block; |
| 291 |
padding-bottom: 5px; |
| 292 |
font-weight: 600; |
| 293 |
color: #23282d; |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
</style> |
| 298 |
<div class="nevim">Scroll Delay</div> |
| 299 |
<select disabled> |
| 300 |
<option value="0">0 seconds (immediate)</option> |
| 301 |
</select> |
| 302 |
<p>Scroll Delay Settings available only in <a href=' . admin_url( "admin.php?page=scrollsequence-pricing" ) . '>Premium</a> version.</p>' ); |
| 303 |
$debug_multi_options_array = array( |
| 304 |
'debug' => 'General Debug', |
| 305 |
'preloaddebug' => 'Image Preload Debug', |
| 306 |
); |
| 307 |
// END OF FREE |
| 308 |
Container::make( 'post_meta', 'Scrollsequence Settings' )->where( 'post_type', '=', 'scrollsequence' )->set_context( 'side' )->set_priority( 'low' )->add_fields( array( |
| 309 |
$scrub_field, |
| 310 |
Field::make( 'select', 'scrollsequence_image_full_width', 'Image Width' )->add_options( array( |
| 311 |
false => 'Content Width (default)', |
| 312 |
true => 'Force Full Width', |
| 313 |
) )->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.' ), |
| 314 |
Field::make( 'text', 'scrollsequence_image_opacity', __( 'Image Opacity' ) )->set_attribute( 'type', 'number' )->set_required( true )->set_default_value( '1' )->set_attribute( 'min', '0' )->set_attribute( 'max', '1' )->set_attribute( 'step', '0.01' ), |
| 315 |
// THIS IS QUITE COMPLEX - ACTIVATE LATER ??? |
| 316 |
// Field::make( 'text', 'scrollsequence_image_zindex', __( 'Image z-index (optional)' ) ) |
| 317 |
// //->set_help_text( '' ) |
| 318 |
// ->set_attribute( 'type', 'number' ) |
| 319 |
// ->set_attribute( 'min', '-9999' ) |
| 320 |
// ->set_attribute( 'max', '9999' ) |
| 321 |
// ->set_attribute( 'step', '1' ), |
| 322 |
// Field::make( 'select', 'scrollsequence_content_spacer', 'Classic Content Position' ) // LEGACY |
| 323 |
// ->add_options( array( // LEGACY |
| 324 |
// 'after100' => 'End of Document (default)', // LEGACY |
| 325 |
// 'after' => 'End of Document (with overlap) ', // LEGACY |
| 326 |
// 'during' => 'Start of Document', |
| 327 |
// ) ), |
| 328 |
Field::make( 'textarea', 'scrollsequence_custom_css', __( 'Custom CSS' ) )->set_default_value( '.ssq-center-center{ |
| 329 |
position: absolute; |
| 330 |
left: 50%; |
| 331 |
top: 50%; |
| 332 |
transform: translate(-50%, -50%); |
| 333 |
text-shadow: 0 0 8px white; |
| 334 |
text-align: center; |
| 335 |
} |
| 336 |
' )->help_text( 'Enter custom CSS here.' ), |
| 337 |
Field::make( "multiselect", "scrollsequence_debug_multi", "Show Development Information" )->add_options( $debug_multi_options_array ), |
| 338 |
) ); |
| 339 |
/* |
| 340 |
* SIDE CONTEXT - ADVANCED SETTINGS |
| 341 |
*/ |
| 342 |
Container::make( 'post_meta', 'Custom Post Settings' )->where( 'post_type', '=', 'scrollsequence' )->set_context( 'side' )->set_priority( 'low' )->add_fields( array( |
| 343 |
Field::make( 'color', 'scrollsequence_bodybgcolor', __( 'Body Background Color' ) )->help_text( 'Set CSS attribute <i><strong>background-color</strong></i> of <i><strong>body.single-scrollsequence</strong></i> class.' ), |
| 344 |
// Field::make( 'color', 'scrollsequence_classic_content_after_bgcolor', __( 'Background Color - After Scrollsequence' ) ) |
| 345 |
// ->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. ') |
| 346 |
// , |
| 347 |
Field::make( 'checkbox', 'scrollsequence_show_sidebar', __( 'Show Sidebar' ) )->set_option_value( 'yes' )->help_text( 'Experimental, take care' ), |
| 348 |
Field::make( 'checkbox', 'scrollsequence_show_footer', __( 'Show Footer' ) )->set_option_value( 'yes' )->help_text( 'Experimental, take care. <br>(This setting displays footer element and changes z-index to 9999)' ), |
| 349 |
) ); |
| 350 |
} |
| 351 |
|
| 352 |
// END OF CARBON FIELD MAIN FUNCTION (CPT) |
| 353 |
/** |
| 354 |
* ROADM Alert Too Many Pages and Images |
| 355 |
* |
| 356 |
* @since 0.7.4 |
| 357 |
*/ |
| 358 |
public function scrollsequence_admin_notice() |
| 359 |
{ |
| 360 |
// Ak: I want to add an IF statement to add admin notice only to scrollsequence post php |
| 361 |
global $post_type ; |
| 362 |
global $pagenow ; |
| 363 |
|
| 364 |
if ( $pagenow == 'post.php' && 'scrollsequence' == $post_type ) { |
| 365 |
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. <a href="' . admin_url( 'admin.php?page=scrollsequence-pricing' ) . '">Upgrade</a> to display unlimited images in your Scrollsequence.</p></div>' ; |
| 366 |
echo '<div class="notice notice-warning" id="scrollsequence_notice_toomanypages" style="display:none" ><p>Warning: Page limit reached. For performance reasons, free version allows maximum of 3 pages. <a href="' . admin_url( 'admin.php?page=scrollsequence-pricing' ) . '">Upgrade</a> to display unlimited pages in your Scrollsequence.</p></div>' ; |
| 367 |
} |
| 368 |
|
| 369 |
// Ak: end |
| 370 |
} |
| 371 |
|
| 372 |
/** |
| 373 |
* Classic Content Editor Heading |
| 374 |
* |
| 375 |
* @since 0.9.94 |
| 376 |
*/ |
| 377 |
public function scrollsequence_classic_content_html() |
| 378 |
{ |
| 379 |
// Ak: I want to add an IF statement to add admin notice only to scrollsequence post php |
| 380 |
global $post_type ; |
| 381 |
global $pagenow ; |
| 382 |
if ( $pagenow == 'post.php' && 'scrollsequence' == $post_type ) { |
| 383 |
echo '<h1>Content Editor </h1> |
| 384 |
<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>' ; |
| 385 |
} |
| 386 |
if ( $pagenow == 'post-new.php' && 'scrollsequence' == $post_type ) { |
| 387 |
echo '<h1>Content Editor </h1> |
| 388 |
<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>' ; |
| 389 |
} |
| 390 |
// Ak: end |
| 391 |
} |
| 392 |
|
| 393 |
/** |
| 394 |
* Function that makes the scrollsequence shortcode happen.. |
| 395 |
* |
| 396 |
* Shortcode: [scrollsequence id="###"] |
| 397 |
* |
| 398 |
* |
| 399 |
* @since 0.9.95 |
| 400 |
*/ |
| 401 |
public function scrollsequence_shortcode( $atts ) |
| 402 |
{ |
| 403 |
// Extract atts |
| 404 |
extract( shortcode_atts( array( |
| 405 |
'id' => get_the_id(), |
| 406 |
'margintop' => 0, |
| 407 |
'marginbottom' => 0, |
| 408 |
), $atts ) ); |
| 409 |
// Get info from database |
| 410 |
$ssqInputZeroObject = array( |
| 411 |
'debug' => carbon_get_post_meta( $id, 'scrollsequence_debug_multi' ), |
| 412 |
'show_footer' => carbon_get_post_meta( $id, 'scrollsequence_show_footer' ), |
| 413 |
'show_sidebar' => carbon_get_post_meta( $id, 'scrollsequence_show_sidebar' ), |
| 414 |
'preloadPercentage' => '0.12', |
| 415 |
'ssqFyiId' => $id, |
| 416 |
); |
| 417 |
$ssqInputObject = array( |
| 418 |
'ssqId' => $id, |
| 419 |
'bodyBgColor' => carbon_get_post_meta( $id, 'scrollsequence_bodybgcolor' ), |
| 420 |
'imageOpacity' => carbon_get_post_meta( $id, 'scrollsequence_image_opacity' ), |
| 421 |
'scrub' => (double) carbon_get_post_meta( $id, 'scrollsequence_scrub' ), |
| 422 |
'forceFullWidth' => carbon_get_post_meta( $id, 'scrollsequence_image_full_width' ), |
| 423 |
'zIndex' => carbon_get_post_meta( $id, 'scrollsequence_image_zindex' ), |
| 424 |
); |
| 425 |
// Rename info from database in JS format |
| 426 |
$ssqInputObject['page'] = array(); |
| 427 |
$ssqPageFromUI = carbon_get_post_meta( $id, 'scrollsequence_page' ); |
| 428 |
foreach ( $ssqPageFromUI as $x => $val ) { |
| 429 |
$ssqInputObject['page'][$x]['alignX']['desktop'] = $ssqPageFromUI[$x]['scrollsequence_p_alignx_desktop']; |
| 430 |
$ssqInputObject['page'][$x]['alignX']['mobile'] = $ssqPageFromUI[$x]['scrollsequence_p_alignx_mobile']; |
| 431 |
$ssqInputObject['page'][$x]['alignY']['desktop'] = $ssqPageFromUI[$x]['scrollsequence_p_aligny_desktop']; |
| 432 |
$ssqInputObject['page'][$x]['alignY']['mobile'] = $ssqPageFromUI[$x]['scrollsequence_p_aligny_mobile']; |
| 433 |
// $ssqInputObject['page'][$x]['pageDuration']= (float)$ssqPageFromUI[$x]['scrollsequence_p_duration']; |
| 434 |
$ssqInputObject['page'][$x]['imgDur'] = (double) $ssqPageFromUI[$x]['scrollsequence_p_imgdur']; |
| 435 |
$ssqInputObject['page'][$x]['scaleTo']['desktop'] = $ssqPageFromUI[$x]['scrollsequence_p_scaleto_desktop']; |
| 436 |
$ssqInputObject['page'][$x]['scaleTo']['mobile'] = $ssqPageFromUI[$x]['scrollsequence_p_scaleto_mobile']; |
| 437 |
// Loop Through Anim |
| 438 |
$ssqInputObject['page'][$x]['animEl'] = array(); |
| 439 |
// in case of empty |
| 440 |
foreach ( $ssqPageFromUI[$x]['ssqnce_anim'] as $z => $animvar ) { |
| 441 |
$ssqInputObject['page'][$x]['animEl'][$z] = $ssqPageFromUI[$x]['ssqnce_anim'][$z]; |
| 442 |
} |
| 443 |
} |
| 444 |
// FREE |
| 445 |
foreach ( $ssqPageFromUI as $x => $val ) { |
| 446 |
// Loop Through IMAGES |
| 447 |
$ssqInputObject['page'][$x]['imagesFull'] = array( plugin_dir_url( __DIR__ ) . 'public/img/noimg.jpg' ); |
| 448 |
//if empty |
| 449 |
foreach ( $ssqPageFromUI[$x]['scrollsequence_p_images'] as $y => $imgvar ) { |
| 450 |
$ssqInputObject['page'][$x]['imagesFull'][$y] = wp_get_attachment_url( $ssqPageFromUI[$x]['scrollsequence_p_images'][$y] ); |
| 451 |
} |
| 452 |
$ssqInputObject['page'][$x]['imagesFull'] = array_splice( $ssqInputObject['page'][$x]['imagesFull'], 0, 100 ); |
| 453 |
} |
| 454 |
// Calculate lengths, spacers and absSpacers (SC is calculated in JS) |
| 455 |
$ssqInputObject['pageLength'] = count( $ssqInputObject['page'] ); |
| 456 |
$ssqInputObject['scSpacer'] = 0; |
| 457 |
$pageAbsSpacerTotal = 0; |
| 458 |
foreach ( $ssqPageFromUI as $x => $val ) { |
| 459 |
$ssqInputObject['page'][$x]['imagesLength'] = count( $ssqInputObject['page'][$x]['imagesFull'] ); |
| 460 |
$ssqInputObject['page'][$x]['animElLength'] = count( $ssqInputObject['page'][$x]['animEl'] ); |
| 461 |
$ssqInputObject['page'][$x]['pageSpacer'] = $ssqInputObject['page'][$x]['imagesLength'] * $ssqInputObject['page'][$x]['imgDur']; |
| 462 |
$ssqInputObject['scSpacer'] = $ssqInputObject['scSpacer'] + $ssqInputObject['page'][$x]['pageSpacer']; |
| 463 |
$ssqInputObject['page'][$x]['pageAbsBegin'] = $pageAbsSpacerTotal; |
| 464 |
$pageAbsSpacerTotal = $pageAbsSpacerTotal + $ssqInputObject['page'][$x]['pageSpacer']; |
| 465 |
$ssqInputObject['page'][$x]['pageAbsEnd'] = $pageAbsSpacerTotal; |
| 466 |
} |
| 467 |
// Localize/Inline Script |
| 468 |
static $ssqScCount = 0 ; |
| 469 |
|
| 470 |
if ( !$ssqScCount ) { |
| 471 |
// First run we need to declare variable and input |
| 472 |
$inlineData = 'var ssqInput={}; |
| 473 |
ssqInput=' . json_encode( $ssqInputZeroObject ) . '; |
| 474 |
ssqInput.sc=[]; |
| 475 |
ssqInput.sc[' . $ssqScCount . ']=' . json_encode( $ssqInputObject ) . ';'; |
| 476 |
} else { |
| 477 |
// All other runs just input |
| 478 |
$inlineData = 'ssqInput.sc[' . $ssqScCount . ']=' . json_encode( $ssqInputObject ) . ';'; |
| 479 |
} |
| 480 |
|
| 481 |
wp_enqueue_script( 'scrollsequence-lib' ); |
| 482 |
if ( $ssqScCount < 1 ) { |
| 483 |
wp_add_inline_script( $this->plugin_name . '-lib', $inlineData, 'before' ); |
| 484 |
} |
| 485 |
// Prepare for returning onlyonece HTML |
| 486 |
|
| 487 |
if ( !$ssqScCount ) { |
| 488 |
// First run |
| 489 |
$onlyonceHtml = ' |
| 490 |
<style> |
| 491 |
.scrollsequence-wrap {visibility:hidden} |
| 492 |
.scrollsequence-pages-wrap {height:100vh} |
| 493 |
.scrollsequence-page {position:absolute;display:none} |
| 494 |
</style> |
| 495 |
<noscript> |
| 496 |
<style> |
| 497 |
.scrollsequence-wrap {visibility:inherit} |
| 498 |
.scrollsequence-spacer{display:none} |
| 499 |
.scrollsequence-pages-wrap {height:initial} |
| 500 |
.scrollsequence-page {position:relative;opacity:initial;display:block ;visibility:initial} |
| 501 |
</style> |
| 502 |
</noscript> |
| 503 |
|
| 504 |
<div style="position: fixed;z-index:99999;bottom:0px;right: 10px;background:red;color:white;" class="ssq-alert-container"> |
| 505 |
<div id="ssqalert"></div> |
| 506 |
</div> |
| 507 |
|
| 508 |
'; |
| 509 |
} else { |
| 510 |
$onlyonceHtml = ''; |
| 511 |
} |
| 512 |
|
| 513 |
//all other runs |
| 514 |
// JUNK START |
| 515 |
// #ssq-is-stuck-wrap > .scrollsequence-sticky { position: fixed; top: 0px;} |
| 516 |
// JUNK END |
| 517 |
// Style for each SC |
| 518 |
$customCssVar = ''; |
| 519 |
if ( !empty(carbon_get_post_meta( $id, 'scrollsequence_custom_css' )) ) { |
| 520 |
$customCssVar = ' |
| 521 |
<style> |
| 522 |
' . carbon_get_post_meta( $id, 'scrollsequence_custom_css' ) . ' |
| 523 |
</style> |
| 524 |
'; |
| 525 |
} |
| 526 |
// end of if not empty |
| 527 |
// Prepare for returning pages html |
| 528 |
$pagesHtml = array(); |
| 529 |
foreach ( $ssqPageFromUI as $p => $pagevar ) { |
| 530 |
$pagesHtml[$p] = ' |
| 531 |
<section class="scrollsequence-page" id="ssq-page-' . $ssqScCount . '-' . $p . '" style="box-sizing: border-box;height:100vh;width:100%;overflow:hidden!important;"> |
| 532 |
' . apply_filters( 'the_content', $ssqPageFromUI[$p]['scrollsequence_p_wysiwyg'] ) . ' |
| 533 |
</section> |
| 534 |
'; |
| 535 |
} |
| 536 |
// return |
| 537 |
$returnvar = $onlyonceHtml . $customCssVar . ' |
| 538 |
<section class="scrollsequence-wrap ssq-wrap-' . $ssqScCount . ' " id="ssq-uid-' . get_the_id() . '-' . $ssqScCount . '-' . $id . '" style="padding:0;margin:0; margin-top:' . $margintop . ';margin-bottom:' . $marginbottom . '; width:100%; max-width:initial;box-sizing: border-box;border:-1px dashed blue;"> |
| 539 |
<div class="scrollsequence-sticky" style="box-sizing: border-box;border:-1px dashed green;"> |
| 540 |
<canvas class="scrollsequence-canvas" style="position:absolute;"></canvas> |
| 541 |
<div class="scrollsequence-pages-wrap" style="position:relative; margin:0; padding:0; box-sizing: border-box;"> |
| 542 |
' . implode( " ", $pagesHtml ) . ' |
| 543 |
</div> |
| 544 |
</div><!-- .scrollsequence-sticky --> |
| 545 |
|
| 546 |
<div class="scrollsequence-spacer" style="height:' . $ssqInputObject['scSpacer'] . 'px; box-sizing: border-box;border:-1px dashed orange;" > |
| 547 |
</div><!-- .scrollsequence-spacer --> |
| 548 |
|
| 549 |
</section><!-- .scrollsequence-wrap --> |
| 550 |
'; |
| 551 |
// Free |
| 552 |
$ssqScCount++; |
| 553 |
|
| 554 |
if ( $ssqScCount <= 1 ) { |
| 555 |
return $returnvar; |
| 556 |
} else { |
| 557 |
return '<section><h5 style="border:2px solid; padding:20px">For performance reasons only one shortcode is allowed in Scrollsequence FREE. To to place unlimited shortcodes on single page <a href="' . admin_url( 'admin.php?page=scrollsequence-pricing' ) . '">Upgrade</a> to PRO version. </h5></section>'; |
| 558 |
} |
| 559 |
|
| 560 |
// end of else count other than zero |
| 561 |
// end of free |
| 562 |
// NO ROADM |
| 563 |
// $ssqScCount++; |
| 564 |
// return $returnvar; |
| 565 |
} |
| 566 |
|
| 567 |
// end of scrollsequence_shortcode function |
| 568 |
// function scrollsequence_admin_columns( $columns ) { |
| 569 |
// $columns = array( |
| 570 |
// 'cb' => $columns['cb'], |
| 571 |
// 'title' => __( 'Title' ), |
| 572 |
// 'date' => __( 'Date' ), |
| 573 |
// 'author' => __( 'Author' ), |
| 574 |
// 'ssq_shortcode' => __( 'Shortcode' ), |
| 575 |
// //'price' => __( 'Price', 'smashing' ), |
| 576 |
// //'area' => __( 'Area', 'smashing' ), |
| 577 |
// ); |
| 578 |
// return $columns; |
| 579 |
// } |
| 580 |
// function scrollsequence_admin_column_content( $column, $id ) { |
| 581 |
// if( 'ssq_shortcode' == $column ) { |
| 582 |
// echo 'tohleje'.$id; |
| 583 |
// } |
| 584 |
// } |
| 585 |
function scrollsequence_admin_columns( $columns ) |
| 586 |
{ |
| 587 |
$columns = array( |
| 588 |
'cb' => $columns['cb'], |
| 589 |
'title' => __( 'Title' ), |
| 590 |
'ssq_shortcode' => __( 'Shortcode' ), |
| 591 |
'date' => __( 'Date' ), |
| 592 |
'author' => __( 'Author' ), |
| 593 |
); |
| 594 |
return $columns; |
| 595 |
} |
| 596 |
|
| 597 |
function scrollsequence_admin_column_content( $column, $id ) |
| 598 |
{ |
| 599 |
if ( 'ssq_shortcode' == $column ) { |
| 600 |
echo '[scrollsequence id="' . $id . '"]' ; |
| 601 |
} |
| 602 |
} |
| 603 |
|
| 604 |
} |
| 605 |
// end of class Scrollsequence_Admin |