*/
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 = '
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 '
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. Upgrade to display unlimited images in your Scrollsequence.
' ;
echo '
Warning: Page limit reached. For performance reasons, free version allows maximum of 3 pages. Upgrade to display unlimited pages in your Scrollsequence.
' ;
}
// 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 . '