*/ class Scrollsequence_Admin { /** * The ID of this plugin. * * @since 0.7.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name ; /** * The version of this plugin. * * @since 0.7.0 * @access private * @var string $version The current version of this plugin. */ private $version ; /** * Initialize the class and set its properties. * * @since 0.7.0 * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; $this->version = $version; add_shortcode( 'scrollsequence', array( $this, 'scrollsequence_shortcode' ) ); } /** * Register the stylesheets for the admin area. * * @since 0.7.0 */ public function enqueue_styles() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Scrollsequence_Loader as all of the hooks are defined * in that particular class. * * The Scrollsequence_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ // Ak: I want to add an IF statement to enqueue scripts only to my CPT global $post_type ; if ( 'scrollsequence' == $post_type ) { wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/scrollsequence-admin.css', array(), $this->version, 'all' ); } // Ak: end } /** * Register the JavaScript for the admin area. * * @since 0.7.0 */ public function enqueue_scripts() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Scrollsequence_Loader as all of the hooks are defined * in that particular class. * * The Scrollsequence_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ // Ak: I want to add an IF statement to enqueue scripts only to my CPT global $post_type ; global $pagenow ; if ( 'scrollsequence' == $post_type && ('post-new.php' === $pagenow || 'post.php' === $pagenow) ) { // Free wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/scrollsequence-admin.js', array( 'jquery' ), $this->version, true ); } // Ak: end } /** * Register Scrollsequence CPT . * * @since 0.7.0 */ public function scrollsequence_cpt() { require_once "create-cpt.php"; } /** * Register Scrollsequence CPT . * * @since 0.7.3 */ public function scrollsequence_cpt_submenu() { add_submenu_page( 'edit.php?post_type=scrollsequence', /*parent_slug*/ 'Dashboard Scrollsequence', /*page title*/ 'Dashboard', /*menu title*/ 'edit_posts', /*roles and capability needed*/ // Update 0.9.93 'dashboard', /*menu slug*/ 'scrollsequence_cpt_dashboard_callback' ); function scrollsequence_cpt_dashboard_callback() { //include_once 'dashboard.php'; - results on parse error require_once "partials/scrollsequence-admin-display.php"; } } /** * Single file custom template for scrollsequence. I am following this: * https://code.tutsplus.com/tutorials/a-guide-to-wordpress-custom-post-types-creation-display-and-meta-boxes--wp-27645 * ref "tutsplus" in class-scrollsequence add action thing * @since 0.7.0 * @uses i dont know * Step 1 https://blog.wplauncher.com/add-meta-box-wordpress-custom-post-type/ */ public function scrollsequence_template( $template_path ) { if ( get_post_type() == 'scrollsequence' ) { if ( is_single() ) { // checks if the file exists in the theme first, // otherwise serve the file from the plugin if ( $theme_file = locate_template( array( 'single-scrollsequence.php' ) ) ) { $template_path = $theme_file; } else { $template_path = plugin_dir_path( __DIR__ ) . 'public/partials/single-scrollsequence.php'; } } } return $template_path; } /** * Carbon Fields Boot function. This function boots up carbon fields. * * @since 0.9.8 */ public function scrollsequence_carbon_fields_load() { require_once __DIR__ . '/../includes/carbonfields/autoload.php'; \Carbon_Fields\Carbon_Fields::boot(); } /** * Carbon Fields Main Function (Scrollsequence CPT) * * @since 0.9.8 */ public function scrollsequence_carbon_fields_cpt() { $scrollsequence_advert_html = '

Full animation settings are available in Scrollsequence PRO.

NEW: We offer 14 days FREE trial - no card required, no risk. '; $scrollsequence_left_center_right = '
Left
Right
'; $scrollsequence_bottom_center_top = '
Top
Bottom
'; $scrollsequence_aglignmentadv = '

More Scale and Alignment settings are available in Scrollsequence PRO.

NEW: We offer 14 days FREE trial - no card required, no risk.

'; $scrollsequence_condition_need_images = array( 'relation' => 'AND', array( 'field' => 'scrollsequence_p_images', 'value' => '', 'compare' => '!=', ), ); // FREE VERSION 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( 'plural_name' => 'Pages', 'singular_name' => 'Page', ) )->set_layout( 'tabbed-horizontal' )->set_required( true )->set_max( 3 )->add_fields( array( Field::make( 'rich_text', 'scrollsequence_p_wysiwyg', __( 'Page Content' ) )->set_conditional_logic( $scrollsequence_condition_need_images )->set_default_value( '

Another day on Earth.

' ), 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' ), Field::make( 'complex', 'ssqnce_anim', 'Content Animation' )->set_conditional_logic( $scrollsequence_condition_need_images )->set_layout( 'tabbed-vertical' )->setup_labels( array( 'plural_name' => 'Animations', 'singular_name' => 'Animation', ) )->add_fields( 'ssqnce_anim_io', 'Animate From/To', array( Field::make( 'text', 'ssqnce_anim_io_id', 'Selector' )->set_width( 20 )->set_required( true )->set_help_text( 'Enter #id or .class selector' ), 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' ), 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' ), // Free advert Field::make( 'separator', 'scrollsequence_advert', 'Animation Settings Not Available in Free Version' )->set_help_text( $scrollsequence_advert_html ), ) )->set_header_template( ' Animate <% if (ssqnce_anim_io_id) { %> - <%- ssqnce_anim_io_id %> <% } %> ' ), // PRO ONLY END1 // Field::make( 'text', 'scrollsequence_p_duration', __( 'Page Height (vh)' ) ) // ->set_conditional_logic($scrollsequence_condition_need_images) // ->set_attribute( 'type', 'number' ) // ->set_required( true ) // ->set_default_value('200') // ->set_attribute( 'min', '20' ) // ->set_attribute( 'max', '2000' ) // ->set_attribute( 'step', '1' ) // ->help_text('This sets the amount of scroll needed to get past this page.'), 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.' ), // PANORAMA (MOBILE) Field::make( 'html', 'scrollsequence_info_html_panorama' )->set_conditional_logic( $scrollsequence_condition_need_images )->set_html( '

Image Scale and Alignment

' ), 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( 'fill' => ' Scale to fill', 'fit' => 'Scale to fit 100%', '0.5' => 'Scale to fit 50%', ) ), 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' ), // ROADM 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' ), // ROADM // LANDSCAPE (DESKTOP) 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( 'fill' => ' Scale to fill', 'fit' => 'Scale to fit 100%', '0.5' => 'Scale to fit 50%', ) ), 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' ), // ROADM 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' ), // ROADM Field::make( 'html', 'scrollsequence_info_html_freealignadv' )->set_conditional_logic( $scrollsequence_condition_need_images )->set_html( $scrollsequence_aglignmentadv ), ) )->set_header_template( 'Page <%- $_index %>' ) ) ); // FREE $scrub_field = Field::make( 'html', 'scrollsequence_hidden', '' )->set_html( '
Scroll Delay

Scroll Delay Settings available only in Premium version.

' ); $debug_multi_options_array = array( 'debug' => 'General Debug', 'preloaddebug' => 'Image Preload Debug', ); // END OF FREE Container::make( 'post_meta', 'Scrollsequence Settings' )->where( 'post_type', '=', 'scrollsequence' )->set_context( 'side' )->set_priority( 'low' )->add_fields( array( $scrub_field, Field::make( 'select', 'scrollsequence_image_full_width', 'Image Width' )->add_options( array( false => 'Content Width (default)', true => 'Force Full Width', ) )->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.' ), 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' ), // THIS IS QUITE COMPLEX - ACTIVATE LATER ??? // Field::make( 'text', 'scrollsequence_image_zindex', __( 'Image z-index (optional)' ) ) // //->set_help_text( '' ) // ->set_attribute( 'type', 'number' ) // ->set_attribute( 'min', '-9999' ) // ->set_attribute( 'max', '9999' ) // ->set_attribute( 'step', '1' ), // Field::make( 'select', 'scrollsequence_content_spacer', 'Classic Content Position' ) // LEGACY // ->add_options( array( // LEGACY // 'after100' => 'End of Document (default)', // LEGACY // 'after' => 'End of Document (with overlap) ', // LEGACY // 'during' => 'Start of Document', // ) ), Field::make( 'textarea', 'scrollsequence_custom_css', __( 'Custom CSS' ) )->set_default_value( '.ssq-center-center{ position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); text-shadow: 0 0 8px white; text-align: center; } ' )->help_text( 'Enter custom CSS here.' ), Field::make( "multiselect", "scrollsequence_debug_multi", "Show Development Information" )->add_options( $debug_multi_options_array ), ) ); /* * SIDE CONTEXT - ADVANCED SETTINGS */ Container::make( 'post_meta', 'Custom Post Settings' )->where( 'post_type', '=', 'scrollsequence' )->set_context( 'side' )->set_priority( 'low' )->add_fields( array( Field::make( 'color', 'scrollsequence_bodybgcolor', __( 'Body Background Color' ) )->help_text( 'Set CSS attribute background-color of body.single-scrollsequence class.' ), // Field::make( 'color', 'scrollsequence_classic_content_after_bgcolor', __( 'Background Color - After Scrollsequence' ) ) // ->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. ') // , Field::make( 'checkbox', 'scrollsequence_show_sidebar', __( 'Show Sidebar' ) )->set_option_value( 'yes' )->help_text( 'Experimental, take care' ), Field::make( 'checkbox', 'scrollsequence_show_footer', __( 'Show Footer' ) )->set_option_value( 'yes' )->help_text( 'Experimental, take care.
(This setting displays footer element and changes z-index to 9999)' ), ) ); } // END OF CARBON FIELD MAIN FUNCTION (CPT) /** * ROADM Alert Too Many Pages and Images * * @since 0.7.4 */ public function scrollsequence_admin_notice() { // Ak: I want to add an IF statement to add admin notice only to scrollsequence post php global $post_type ; global $pagenow ; if ( $pagenow == 'post.php' && 'scrollsequence' == $post_type ) { echo '' ; echo '' ; } // Ak: end } /** * Classic Content Editor Heading * * @since 0.9.94 */ public function scrollsequence_classic_content_html() { // Ak: I want to add an IF statement to add admin notice only to scrollsequence post php global $post_type ; global $pagenow ; if ( $pagenow == 'post.php' && 'scrollsequence' == $post_type ) { echo '

Content Editor

Place shortcode [scrollsequence] anywhere in the classic content to control image sequence position.
If not specified [scrollsequence] shortcode will be placed at the start of content automatically, rendering the image sequence at the begining of the page.
' ; } if ( $pagenow == 'post-new.php' && 'scrollsequence' == $post_type ) { echo '

Content Editor

Place shortcode [scrollsequence] anywhere in the classic content to control image sequence position.
If not specified [scrollsequence] shortcode will be placed at the start of content automatically, rendering the image sequence at the begining of the page.
' ; } // Ak: end } /** * Function that makes the scrollsequence shortcode happen.. * * Shortcode: [scrollsequence id="###"] * * * @since 0.9.95 */ public function scrollsequence_shortcode( $atts ) { // Extract atts extract( shortcode_atts( array( 'id' => get_the_id(), 'margintop' => 0, 'marginbottom' => 0, ), $atts ) ); // Get info from database $ssqInputZeroObject = array( 'debug' => carbon_get_post_meta( $id, 'scrollsequence_debug_multi' ), 'show_footer' => carbon_get_post_meta( $id, 'scrollsequence_show_footer' ), 'show_sidebar' => carbon_get_post_meta( $id, 'scrollsequence_show_sidebar' ), 'preloadPercentage' => '0.12', 'ssqFyiId' => $id, ); $ssqInputObject = array( 'ssqId' => $id, 'bodyBgColor' => carbon_get_post_meta( $id, 'scrollsequence_bodybgcolor' ), 'imageOpacity' => carbon_get_post_meta( $id, 'scrollsequence_image_opacity' ), 'scrub' => (double) carbon_get_post_meta( $id, 'scrollsequence_scrub' ), 'forceFullWidth' => carbon_get_post_meta( $id, 'scrollsequence_image_full_width' ), 'zIndex' => carbon_get_post_meta( $id, 'scrollsequence_image_zindex' ), ); // Rename info from database in JS format $ssqInputObject['page'] = array(); $ssqPageFromUI = carbon_get_post_meta( $id, 'scrollsequence_page' ); foreach ( $ssqPageFromUI as $x => $val ) { $ssqInputObject['page'][$x]['alignX']['desktop'] = $ssqPageFromUI[$x]['scrollsequence_p_alignx_desktop']; $ssqInputObject['page'][$x]['alignX']['mobile'] = $ssqPageFromUI[$x]['scrollsequence_p_alignx_mobile']; $ssqInputObject['page'][$x]['alignY']['desktop'] = $ssqPageFromUI[$x]['scrollsequence_p_aligny_desktop']; $ssqInputObject['page'][$x]['alignY']['mobile'] = $ssqPageFromUI[$x]['scrollsequence_p_aligny_mobile']; // $ssqInputObject['page'][$x]['pageDuration']= (float)$ssqPageFromUI[$x]['scrollsequence_p_duration']; $ssqInputObject['page'][$x]['imgDur'] = (double) $ssqPageFromUI[$x]['scrollsequence_p_imgdur']; $ssqInputObject['page'][$x]['scaleTo']['desktop'] = $ssqPageFromUI[$x]['scrollsequence_p_scaleto_desktop']; $ssqInputObject['page'][$x]['scaleTo']['mobile'] = $ssqPageFromUI[$x]['scrollsequence_p_scaleto_mobile']; // Loop Through Anim $ssqInputObject['page'][$x]['animEl'] = array(); // in case of empty foreach ( $ssqPageFromUI[$x]['ssqnce_anim'] as $z => $animvar ) { $ssqInputObject['page'][$x]['animEl'][$z] = $ssqPageFromUI[$x]['ssqnce_anim'][$z]; } } // FREE foreach ( $ssqPageFromUI as $x => $val ) { // Loop Through IMAGES $ssqInputObject['page'][$x]['imagesFull'] = array( plugin_dir_url( __DIR__ ) . 'public/img/noimg.jpg' ); //if empty foreach ( $ssqPageFromUI[$x]['scrollsequence_p_images'] as $y => $imgvar ) { $ssqInputObject['page'][$x]['imagesFull'][$y] = wp_get_attachment_url( $ssqPageFromUI[$x]['scrollsequence_p_images'][$y] ); } $ssqInputObject['page'][$x]['imagesFull'] = array_splice( $ssqInputObject['page'][$x]['imagesFull'], 0, 100 ); } // Calculate lengths, spacers and absSpacers (SC is calculated in JS) $ssqInputObject['pageLength'] = count( $ssqInputObject['page'] ); $ssqInputObject['scSpacer'] = 0; $pageAbsSpacerTotal = 0; foreach ( $ssqPageFromUI as $x => $val ) { $ssqInputObject['page'][$x]['imagesLength'] = count( $ssqInputObject['page'][$x]['imagesFull'] ); $ssqInputObject['page'][$x]['animElLength'] = count( $ssqInputObject['page'][$x]['animEl'] ); $ssqInputObject['page'][$x]['pageSpacer'] = $ssqInputObject['page'][$x]['imagesLength'] * $ssqInputObject['page'][$x]['imgDur']; $ssqInputObject['scSpacer'] = $ssqInputObject['scSpacer'] + $ssqInputObject['page'][$x]['pageSpacer']; $ssqInputObject['page'][$x]['pageAbsBegin'] = $pageAbsSpacerTotal; $pageAbsSpacerTotal = $pageAbsSpacerTotal + $ssqInputObject['page'][$x]['pageSpacer']; $ssqInputObject['page'][$x]['pageAbsEnd'] = $pageAbsSpacerTotal; } // Localize/Inline Script static $ssqScCount = 0 ; if ( !$ssqScCount ) { // First run we need to declare variable and input $inlineData = 'var ssqInput={}; ssqInput=' . json_encode( $ssqInputZeroObject ) . '; ssqInput.sc=[]; ssqInput.sc[' . $ssqScCount . ']=' . json_encode( $ssqInputObject ) . ';'; } else { // All other runs just input $inlineData = 'ssqInput.sc[' . $ssqScCount . ']=' . json_encode( $ssqInputObject ) . ';'; } wp_enqueue_script( 'scrollsequence-lib' ); if ( $ssqScCount < 1 ) { wp_add_inline_script( $this->plugin_name . '-lib', $inlineData, 'before' ); } // Prepare for returning onlyonece HTML if ( !$ssqScCount ) { // First run $onlyonceHtml = '
'; } else { $onlyonceHtml = ''; } //all other runs // JUNK START // #ssq-is-stuck-wrap > .scrollsequence-sticky { position: fixed; top: 0px;} // JUNK END // Style for each SC $customCssVar = ''; if ( !empty(carbon_get_post_meta( $id, 'scrollsequence_custom_css' )) ) { $customCssVar = ' '; } // end of if not empty // Prepare for returning pages html $pagesHtml = array(); foreach ( $ssqPageFromUI as $p => $pagevar ) { $pagesHtml[$p] = '
' . apply_filters( 'the_content', $ssqPageFromUI[$p]['scrollsequence_p_wysiwyg'] ) . '
'; } // return $returnvar = $onlyonceHtml . $customCssVar . '
' . implode( " ", $pagesHtml ) . '
'; // Free $ssqScCount++; if ( $ssqScCount <= 1 ) { return $returnvar; } else { return '
For performance reasons only one shortcode is allowed in Scrollsequence FREE. To to place unlimited shortcodes on single page Upgrade to PRO version.
'; } // end of else count other than zero // end of free // NO ROADM // $ssqScCount++; // return $returnvar; } // end of scrollsequence_shortcode function // function scrollsequence_admin_columns( $columns ) { // $columns = array( // 'cb' => $columns['cb'], // 'title' => __( 'Title' ), // 'date' => __( 'Date' ), // 'author' => __( 'Author' ), // 'ssq_shortcode' => __( 'Shortcode' ), // //'price' => __( 'Price', 'smashing' ), // //'area' => __( 'Area', 'smashing' ), // ); // return $columns; // } // function scrollsequence_admin_column_content( $column, $id ) { // if( 'ssq_shortcode' == $column ) { // echo 'tohleje'.$id; // } // } function scrollsequence_admin_columns( $columns ) { $columns = array( 'cb' => $columns['cb'], 'title' => __( 'Title' ), 'ssq_shortcode' => __( 'Shortcode' ), 'date' => __( 'Date' ), 'author' => __( 'Author' ), ); return $columns; } function scrollsequence_admin_column_content( $column, $id ) { if ( 'ssq_shortcode' == $column ) { echo '[scrollsequence id="' . $id . '"]' ; } } } // end of class Scrollsequence_Admin