self['TITLE'] = 'Accelerate by AMP Publisher'; $this->self['VERSION'] = '1.0.3'; $this->self['DIR'] = $dir . '/'; $dex = count( $splode ) - 1; $this->self['FOLDER'] = $splode[ $dex ]; if ( strstr( $this->self['DIR'], 'wp-content/plugins/' ) || strstr( $this->self['DIR'], 'wp-content\\plugins\\' ) ) { $this->self['PATH'] = plugins_url( $this->self['FOLDER'] ) . '/'; } else { $this->self['PATH'] = esc_url( get_template_directory_uri() ) . '/'; } $this->self['prefix'] = $prefix; $this->self['BAD_CHARS'] = array( '•', '
', '
', '<', '>', '&', '\\', '"', "'", ';' ); $this->self['NEW_CHARS'] = array( '(_BL_)', '(_BR_)', '(_HR_)', '(_LT_)', '(_GT_)', '(_AM_)', '(_BS_)', '(_DQ_)', '(_SQ_)', '(_SC_)' ); $this->self['BAD_CHARS_64'] = array( '•', '
', '
', '<', '>', '&', '\\', '"', "'", ';', '/', '+' ); $this->self['NEW_CHARS_64'] = array( '(_BL_)', '(_BR_)', '(_HR_)', '(_LT_)', '(_GT_)', '(_AM_)', '(_BS_)', '(_DQ_)', '(_SQ_)', '(_SC_)', '(_FS_)', '(_PL_)' ); $this->self['TURNOFFS'] = array(); $this->self['FONT_AWESOME_URL'] = 'https://use.fontawesome.com/releases/v5.5.0/css/all.css'; $this->self['FONT_AWESOME_VERSION'] = '5.5.0'; $datahook = 'wp'; if ( is_admin() ) { global $pagenow; if ( 'post.php' === $pagenow ) { $datahook = 'add_meta_boxes'; } } if ( method_exists( $this, 'extends_construct' ) ) { $this->extends_construct();} } /** * Take registered meta fields and add a Meta Box to the WP post editor. * * @since 1.0 * * @requires : get_value, method_call, echo_post_editor_adv, echo_post_editor_side * @usage : init */ public function add_post_editor() { $how = ''; $screen = get_current_screen(); $type = $screen->post_type; if ( 'post' === $type || 'page' === $type || 'recipe' === $type ) { $how = $type;} global $pagenow; /* FIX 1.0.1 - WPCS whitelist nonce recommendation. */ if ( 'post-new.php' === $pagenow && ! empty( $_GET['post_type'] ) && 'recipe' === $_GET['post_type'] ) {// input var okay; WPCS: CSRF ok. /* No nonce needed, only checking for exact value of "recipe". */ $how = 'recipe'; } $mtitle = $this->get_value( $this->self, 'TITLE' ); $adv = false; $side = false; $arr = $this->self['meta_list']; if ( count( $arr ) > 0 ) { foreach ( $arr as $name => $data ) { $show = $this->get_value( $data, 'show' ); if ( '' !== $show ) { $showit = $this->method_call( $show ); if ( ! $showit ) { continue;} } $types = $this->get_value( $data, 'post_type' ); if ( is_array( $types ) ) { $isit = false; foreach ( $types as $ptype ) { if ( $type === $ptype ) { $isit = true;} } } else { if ( $type === $types ) { $isit = true;} } if ( $isit ) { $mloc = $this->get_value( $data, 'location' ); if ( 'side' === $mloc ) { $side = true; } else { $adv = true; } } } } if ( ! function_exists( 'gutenberg_init' ) && true === $side ) { $adv = true; $side = false;} if ( $adv ) { if ( '' !== $how ) { add_meta_box( $this->self['prefix'] . '_layout_box', $mtitle, array( &$this, 'echo_post_editor_adv' ), $how, 'advanced', 'core' );} } if ( $side ) { if ( '' !== $how ) { add_meta_box( $this->self['prefix'] . '_layout_box_side', $mtitle, array( &$this, 'echo_post_editor_side' ), $how, 'side', 'core' );} } } /** * Allow outside CSS to be added to header through the AMP Custom CSS tag. * * @since 1.0 * * @param string $params . * @requires : get_value, url_get_contents * @usage : stylesheet */ public function add_registered_css( $params = null ) { if ( null === $params ) { if ( isset( $this->self['REGISTEREDCSS'] ) ) { return $this->self['REGISTEREDCSS']; } return ''; } else { $rat = ''; $com = $this->get_value( $params, 'command' ); $pass = $this->get_value( $params, 'pass' ); if ( 'register style' === $com ) { $rat = $pass; } elseif ( 'register stylesheet' === $com ) { $rat = $this->url_get_contents( $pass ); } if ( '' !== $rat ) { if ( isset( $this->self['REGISTEREDCSS'] ) ) { $this->self['REGISTEREDCSS'] = '';} $this->self['REGISTEREDCSS'] .= $rat; } } return ''; } /** * Pull in the stylesheet, process it for shortcodes, then add all custom and object oriented CSS. * * @since 1.0 * * @param string $params . * @requires : stylesheet, get_customizer_setting * @usage : amp_publisher */ public function amp_css( $params = null ) { $rat = ''; $rat .= $this->stylesheet( $params ); $hbgclr = $this->get_customizer_setting( 'header_bgcolor' ); $hbgimg = get_header_image(); if ( '' !== $hbgimg ) { $rat .= '.banner{background:' . $hbgclr . ' url(' . $hbgimg . ') no-repeat top center;background-size:cover;}';} $rat .= '.banner, .banner a{color:#' . get_header_textcolor() . ';}'; return $rat; } /** * Central handler for template function calls. * * @since 1.0 * * @param string $part . * @param string $pass . * @requires : true_pageid, true_pagetype, is_nonamp, display_class, generate_post, get_logo, banner_logo, page_navigation, use_nav_menu, current_page_url, generate_markups, breadcrumbs, true_featured_image, get_customizer_setting, is_homepage, get_customizer_checkbox, is_blog, theme_page_title, amp_css, delimitit, get_value * @usage : wp_body_class */ public function amp_publisher( $part = '', $pass = '' ) { $pageid = $this->true_pageid(); $pagetype = $this->true_pagetype(); if ( 'isamp' === $part ) { return ! $this->is_nonamp(); } if ( 'nonamp' === $part ) { return $this->is_nonamp(); } if ( 'display class' === $part ) { return $this->display_class(); } if ( 'fontawesome' === $part ) { return $this->self['FONT_AWESOME_URL']; } if ( 'post' === $part ) { if ( '' !== $pass ) { $this->generate_post( $pass );} } if ( 'has logo' === $part ) { /* FIX 1.0.2 - Switched to custom-logo support. */ if ( '' !== $this->get_logo( 'id' ) ) { return true;} return false; } if ( 'logo' === $part ) { /* FIX 1.0.2 - Switched to custom-logo support. FIX 1.0.3 - New logo data and banner logo functions. */ $img = $this->get_logo( 'url' ); if ( '' !== $img ) { $this->banner_logo( $pass );} return ''; } if ( 'posts navigation' === $part ) { $this->page_navigation(); } if ( 'use nav menu' === $part ) { return $this->use_nav_menu( $pass ); } if ( 'url' === $part ) { return $this->current_page_url(); } if ( 'head markups' === $part ) { /* No need to escape here, generate_markups() is escaped while compiling the string. */ echo $this->generate_markups();// WPCS: XSS ok. } if ( 'breadcrumbs' === $part ) { $this->breadcrumbs(); } if ( 'hero banner' === $part ) { $thumb = $this->true_featured_image( $pageid, $pagetype ); $defaultimg = $this->get_customizer_setting( 'hero_defaultimage' ); $banner = false; if ( $this->is_homepage() ) { if ( $this->get_customizer_checkbox( 'titlebar_home' ) ) { $show = get_option( 'show_on_front' ); $fpid = get_option( 'page_on_front' ); if ( 'page' === $show && $fpid > 0 && '' !== $fpid ) { $banner = true;} } } elseif ( $this->is_blog() ) { if ( $this->get_customizer_checkbox( 'titlebar_blog' ) ) { $banner = true;} } elseif ( is_page() ) { if ( $this->get_customizer_checkbox( 'titlebar_page' ) ) { $banner = true;} } elseif ( is_single() ) { if ( $this->get_customizer_checkbox( 'titlebar_post' ) ) { $banner = true;} } elseif ( is_category() ) { if ( $this->get_customizer_checkbox( 'titlebar_cats' ) ) { $banner = true;} } $img = ''; $usehero = false; if ( $this->is_homepage() ) { if ( $this->get_customizer_checkbox( 'hero_home' ) ) { $usehero = true;} } elseif ( $this->is_blog() ) { if ( $this->get_customizer_checkbox( 'hero_blog' ) ) { $usehero = true;} } elseif ( is_page() ) { if ( $this->get_customizer_checkbox( 'hero_page' ) ) { $usehero = true;} } elseif ( is_single() ) { if ( $this->get_customizer_checkbox( 'hero_post' ) ) { $usehero = true;} } if ( $usehero ) { if ( $thumb ) { $img = $thumb; } else { $img = $defaultimg; } } if ( $img ) { echo '
'; $maxhit = $this->get_customizer_setting( 'hero_height' ); $sized = 'max-height:' . $maxhit . 'px;'; echo ''; echo '
'; echo '
'; echo '
'; echo '

'; if ( is_archive() ) { $this->theme_page_title(); } else { single_post_title(); } echo '

'; echo '
'; echo '
'; echo '
'; } elseif ( true === $banner ) { echo '
'; echo '
'; echo '

'; if ( is_archive() ) { $this->theme_page_title(); } else { single_post_title(); } echo '

'; echo '
'; echo '
'; } } if ( 'navigatorbar search' === $part ) { $runit = false; if ( $this->is_homepage() ) { if ( true === $this->get_customizer_checkbox( 'navmenu_searchhome' ) ) { $runit = true;} } elseif ( $this->is_blog() ) { if ( true === $this->get_customizer_checkbox( 'navmenu_searchblog' ) ) { $runit = true;} } elseif ( is_category() ) { if ( true === $this->get_customizer_checkbox( 'navmenu_searchcats' ) ) { $runit = true;} } elseif ( is_singular( 'page' ) ) { if ( true === $this->get_customizer_checkbox( 'navmenu_searchpage' ) ) { $runit = true;} } elseif ( is_singular( 'post' ) ) { if ( true === $this->get_customizer_checkbox( 'navmenu_searchpost' ) ) { $runit = true;} } return $runit; } if ( 'stylesheet' === $part ) { return $this->amp_css(); } if ( 'meta description' === $part ) { $metadesc = ''; if ( defined( 'WPSEO_FILE' ) ) { $metadesc = WPSEO_Frontend::get_instance()->metadesc( false );} if ( '' === $metadesc ) { if ( '' === $metadesc ) { if ( $this->is_homepage() ) { $metadesc = get_bloginfo( 'description' );} } if ( '' !== $metadesc ) { echo '';} } } if ( 'meta keywords' === $part ) { $keywords = ''; $list = get_the_tag_list(); $tags = get_tags(); if ( '' !== $tags && count( $tags ) > 0 ) { foreach ( $tags as $tag ) { $tname = $tag->name; $keywords = $this->delimitit( $keywords, ', ', $tname ); } } if ( '' !== $keywords ) { echo '';} } if ( 'copyright' === $part ) { $copyright = $this->get_customizer_setting( 'footer_copyrighttext' ); if ( '' === $copyright ) { $copyright = date( 'Y' ) . ' ' . get_bloginfo( 'name' );} if ( strstr( $copyright, '©' ) ) { str_replace( '©', '', $copyright );} return $copyright; } if ( 'customizer' === $part ) { if ( isset( $this->self['customizer_settings'][ $pass ] ) ) { $type = $this->get_value( $this->self['customizer_settings'][ $pass ], 'type' ); if ( 'checkbox' === $type ) { return $this->get_customizer_checkbox( $pass );} return $this->get_customizer_setting( $pass ); } } if ( 'has sidebar' === $part ) { if ( is_active_sidebar( 'mainsidebar' ) ) { $runit = false; if ( $this->is_homepage() ) { if ( true === $this->get_customizer_checkbox( 'site_sidebarhome' ) ) { $runit = true;} } elseif ( $this->is_blog() ) { if ( true === $this->get_customizer_checkbox( 'site_sidebarblog' ) ) { $runit = true;} } elseif ( is_category() ) { if ( true === $this->get_customizer_checkbox( 'site_sidebarcats' ) ) { $runit = true;} } elseif ( is_singular( 'page' ) ) { if ( true === $this->get_customizer_checkbox( 'site_sidebarpage' ) ) { $runit = true;} } elseif ( is_singular( 'post' ) ) { if ( true === $this->get_customizer_checkbox( 'site_sidebarpost' ) ) { $runit = true;} } if ( $runit ) { return true;} } return false; } if ( 'is homepage' === $part ) { return $this->is_homepage(); } if ( 'is blog' === $part ) { return $this->is_blog(); } if ( 'true pageid' === $part ) { return $this->true_pageid(); } if ( 'true pagetype' === $part ) { return $this->true_pagetype(); } return ''; } /** * Create the logos used in the banner and navigation bar based on site settings. They need to be handled for AMP compatibility and location specifics. * * @since 1.0 * * @param string $how . * @requires : get_logo, get_value, get_customizer_setting * @usage : amp_publisher */ public function banner_logo( $how = '' ) { $sizes = ''; $sized = ''; $imgdata = $this->get_logo(); if ( ! $imgdata ) { return '';} $img = $this->get_value( $imgdata, 'url' ); $imgid = $this->get_value( $imgdata, 'id' ); $wid = $this->get_value( $imgdata, 'width', 100 ); $hit = $this->get_value( $imgdata, 'height', 100 ); if ( '' !== $img ) { $issvg = false; if ( strstr( strtolower( $img ), '.svg' ) ) { $issvg = true;} $resp = 'responsive'; if ( $issvg ) { $sized = 'min-height:' . $hit . 'px;';} if ( 'mnav' === $how || is_integer( $how ) ) { $mhit = $how; if ( 'mnav' === $how ) { $mhit = 48;} if ( is_numeric( $hit ) && is_numeric( $mhit ) ) { if ( $hit > $mhit ) { $nrat = $mhit / $hit; $hit = $mhit; $wid = floor( $wid * $nrat ); $sized = 'max-width:' . $wid . 'px;max-height:' . $hit . 'px;'; } } } else { $mhit = $this->get_customizer_setting( 'header_maxheight' ); if ( 'auto' !== $mhit ) { $bhit = intval( str_replace( 'px', '', $mhit ) ); if ( is_numeric( $hit ) && is_numeric( $bhit ) ) { if ( $hit > $bhit ) { $nrat = $bhit / $hit; $hit = $bhit; $wid = floor( $wid * $nrat ); } } } } if ( ! $issvg ) { $sizes = ' sizes="(max-width: ' . $wid . 'px) calc(100vw - 60px), ' . $wid . 'px"';} } $id = 'logo'; $clss = ''; if ( 'mnav' === $how || is_integer( $how ) ) { $clss .= 'nblogo'; $id = 'navlogo';} if ( '' !== $img ) { $clss .= ' haslogo';} echo ''; } /** * Gather a list of parents to create an escaped breadcrumb. * * @since 1.0 * * @param array $params . * @requires : get_value, taxes, breadcrumb_loop * @usage : breadcrumb_loop, breadcrumbs */ public function breadcrumb_loop( $params = array() ) { $id = $this->get_value( $params, 'id' ); $cat = $this->get_value( $params, 'category' ); if ( '' === $id || null === $id ) { if ( '' === $cat ) { $cat = single_term_title( '', false );} $id = get_cat_ID( $cat ); } $link = $this->taxes( array( 'com' => 'link', 'id' => $id, ) ); $data = $this->taxes( array( 'com' => 'data', 'id' => $id, ) ); $slug = $this->get_value( $data, 'slug' ); $parent = $this->get_value( $data, 'parent' ); $name = $this->get_value( $data, 'name' ); $count = $this->get_value( $data, 'count' ); $strg = $this->get_value( $params, 'text' ); $how = $this->get_value( $params, 'how' ); $href = '' . esc_html( $name ) . ''; $blank = '' . esc_html( $name ) . ''; if ( '' !== $slug ) { $lcsep = ''; if ( '' === $strg ) { $lcsep = 'lcsep';} if ( '' === $strg && '' === $how ) { $strg = $blank; } else { $strg = $href . ' - ' . $strg; } if ( 0 !== $parent ) { $strg = $this->breadcrumb_loop( array( 'id' => $parent, 'text' => $strg, 'how' => $how, ) );} } return $strg; } /** * Generate breadcrumbs. * * @since 1.0 * * @requires : is_homepage, get_page_title, get_post_category_data, taxes, breadcrumb_loop * @usage : amp_publisher */ public function breadcrumbs() { if ( $this->is_homepage() ) { return '';} echo '
'; echo ''; echo ''; $homeurl = home_url(); echo '' . esc_html__( 'Home', 'accelerate-by-amp-publisher' ) . ''; echo ' - '; $args = array( 'com' => 'crumbs' ); if ( ! is_category() ) { $name = $this->get_page_title(); $cat = $this->get_post_category_data( get_the_ID() ); $catid = $this->taxes( array( 'com' => 'id', 'category' => esc_attr( $cat ), ) ); $args['id'] = esc_attr( $catid ); $args['how'] = 'post'; } /* FIX 1.0.1 - WPCS whitelist escape error for safely generated HTML. */ echo $this->breadcrumb_loop( $args );// WPCS: XSS ok. /* No need to escape breadcrumb_loop(), it just escapes each brumb's text and links as it generates the string. */ if ( ! is_category() ) { echo '' . esc_html( $name ) . ''; } echo ''; echo '
'; } /** * Add settings and controls to the Customizer from registered data. * * @since 1.0 * * @param string $id . * @param string $params . * @requires : get_value * @usage : init_customizer_settings */ public function create_customizer_setting( $id, $params ) { global $wp_customize; $type = $this->get_value( $params, 'type' ); $sec = $this->get_value( $params, 'section' ); $title = $this->get_value( $params, 'title' ); $def = $this->get_value( $params, 'default' ); $prio = $this->get_value( $params, 'priority' ); $choices = $this->get_value( $params, 'choices' ); $desc = $this->get_value( $params, 'description' ); $live = $this->get_value( $params, 'live', false ); $theme = $this->self['prefix']; if ( '' !== $id && '' !== $type && '' !== $sec ) { $transport = 'refresh'; if ( true === $live ) { $transport = 'postMessage';} if ( 'color' === $type ) { $wp_customize->add_setting( $id, array( 'default' => $def, 'transport' => $transport, 'sanitize_callback' => 'sanitize_hex_color', ) ); } else { $wp_customize->add_setting( $id, array( 'default' => $def, 'transport' => $transport, 'sanitize_callback' => 'sanitize_text_field', ) ); } $pass = array( 'label' => $title, $theme, 'section' => $sec, 'settings' => $id, ); if ( '' !== $prio ) { $pass['priority'] = $prio;} if ( '' !== $choices ) { $pass['choices'] = $choices;} if ( '' !== $desc ) { $pass['description'] = $desc;} if ( 'color' === $type ) { $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, $id, $pass ) ); } elseif ( 'image' === $type ) { $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, $id, $pass ) ); } else { $pass['type'] = $type; $wp_customize->add_control( $id, $pass ); } } } /** * Get the page URL across a variety of server types. * * @since 1.0 * * @param string $comm . * @usage : amp_publisher, is_homepage */ public function current_page_url( $comm = '' ) { $url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && 'on' === $_SERVER['HTTPS'] ) {// input var okay;. $url .= 's'; } $url .= '://'; if ( isset( $_SERVER['SERVER_NAME'] ) ) { $url .= sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) );// input var okay;. } if ( isset( $_SERVER['REQUEST_URI'] ) ) { $url .= sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) );// input var okay;. } if ( 'base' === $comm ) { $exp = explode( '?', $url ); return $exp[0]; } return $url; } /** * Adds several interval options that only get filtered into WP if they are registered. * * @since 1.0 * * @param string $schedules . * @requires : has_cron * @usage : init */ public function custom_cron_schedules( $schedules ) { $arr = array(); if ( $this->has_cron() ) { foreach ( $this->self['cron_list'] as $fct => $type ) { $arr[ $type ] = true; } } if ( isset( $arr['weekly'] ) ) { $schedules['weekly'] = array( 'interval' => 60480, 'display' => 'Every Week', );} if ( isset( $arr['monthly'] ) ) { $schedules['monthly'] = array( 'interval' => 259200, 'display' => 'Every 30 Days', );} if ( isset( $arr['3hours'] ) ) { $schedules['3hours'] = array( 'interval' => 1080, 'display' => 'Every 3 Hours', );} if ( isset( $arr['6hours'] ) ) { $schedules['6hours'] = array( 'interval' => 2160, 'display' => 'Every 6 Hours', );} return $schedules; } /** * Add a string to a string with a delimiter if it is not blank. * * @since 1.0 * * @param string $str . * @param string $delim . * @param string $val . * @usage : amp_publisher, taxes */ public function delimitit( $str, $delim = '', $val = '' ) { if ( '' === $delim ) { $delim = ',';} if ( '' !== $str ) { $str .= $delim;} $str .= $val; return $str; } /** * Add posts list display mode class to wrapper tag in theme templates. * * @since 1.0 * * @requires : get_customizer_setting * @usage : amp_publisher */ public function display_class() { $display = $this->get_customizer_setting( 'site_postsdisplaymode' ); if ( '' !== $display ) { return ' ' . $display;} return ''; } /** * Second step in adding a Meta Box to the WP post editor, this step fills that box. * * @since 1.0 * * @param string $post . * @param string $pass . * @param string $eloc . * @requires : get_value, get_meta, runit * @usage : echo_post_editor_adv, echo_post_editor_side */ public function echo_post_editor( $post, $pass, $eloc = '' ) { wp_nonce_field( $this->self['prefix'] . '_post_nonce', $this->self['prefix'] . '_nonce_field' ); $atts = array( 'media_buttons' => false ); $arr = $this->self['meta_list']; if ( count( $arr ) > 0 ) { $functs = array(); foreach ( $arr as $name => $data ) { $type = $this->get_value( $data, 'type' ); $title = $this->get_value( $data, 'name' ); $desc = $this->get_value( $data, 'desc' ); $class = $this->get_value( $data, 'class' ); if ( 'adv' === $eloc || 'side' === $eloc ) { $mloc = $this->get_value( $data, 'location', 'adv' ); if ( function_exists( 'gutenberg_init' ) ) { if ( $eloc !== $mloc ) { continue;} } } $classtxt = ''; if ( '' !== $class ) { $classtxt = ' class="' . $class . '"';} if ( 'function' === $type ) { $fct = $this->get_value( $data, 'function' ); if ( '' !== $fct ) { if ( ! in_array( $fct, $functs, true ) ) { $functs[] = $fct;} } } else { echo '
'; $val = $this->get_meta( get_the_ID(), $name ); if ( 'html' === $type ) { echo '' . esc_html( $title ) . ''; wp_editor( $val, $name, $atts ); } else { $fid = $this->get_value( $data, 'id' ); if ( 'checkbox' === $type ) { echo ''; if ( '' !== $val ) { $checked = ' checked="checked"'; } else { $checked = ''; } echo ''; echo ''; echo '' . esc_html( $title ) . ''; echo '
'; } else { if ( 'text' === $type ) { echo ''; } echo '' . esc_html( $title ) . ''; } } if ( '' !== $desc ) { echo '
' . esc_html( $desc ) . '
';} echo '
'; } } if ( count( $functs ) > 0 ) { foreach ( $functs as $dex => $fct ) { $this->runit( $fct ); } } } } /** * Middle step for handling meta boxes in side/inspector. * * @since 1.0 * * @param string $post . * @param string $pass . * @requires : echo_post_editor * @usage : add_post_editor */ public function echo_post_editor_adv( $post, $pass ) { $this->echo_post_editor( $post, $pass, 'adv' ); } /** * Middle step for handling meta boxes in side/inspector. * * @since 1.0 * * @param string $post . * @param string $pass . * @requires : echo_post_editor * @usage : add_post_editor */ public function echo_post_editor_side( $post, $pass ) { $this->echo_post_editor( $post, $pass, 'side' ); } /** * Standard extension class method in our systems, used to hook into the base class init method. * * @since 1.0 * * @requires : filter_handler * @usage : init */ public function extends_init() { $this->self['Title'] = 'Accelerate by AMP Publisher'; $this->filter_handler( 'body_class' );// Add class name for the site's layout to the body tag. } /** * Simplify the process of adding filters by running local methods named for them. * * @since 1.0 * * @param string $pass . * @param string $prio . * @param string $accs . * @requires : wp_ * @usage : extends_init */ public function filter_handler( $pass, $prio = 10, $accs = 1 ) { add_filter( $pass, array( &$this, 'wp_' . $pass ), $prio, $accs ); } /** * Schema markups in JSON script node. * * @since 1.0 * * @requires : is_homepage, extends_markup, get_doc, get_value, true_pageid, true_pagetype, true_featured_image, get_logo * @usage : amp_publisher */ public function generate_markups() { $jsontype = 'WebPage'; if ( $this->is_homepage() ) { $jsontype = 'WebSite'; } elseif ( is_singular( 'post' ) ) { $jsontype = 'BlogPosting'; } $publisher = get_bloginfo( 'name' ); $rat = ''; $rat .= ''; return $rat; } /** * Create the post block DOM used to display posts in archives and post modules. The DOM is modified by CSS for the various display modes. * * @since 1.0 * * @param string $data . * @requires : get_value, get_customizer_setting, get_excerpt_by_id, validate_url, get_customizer_checkbox * @usage : amp_publisher */ public function generate_post( $data ) { $post_id = $this->get_value( $data, 'ID' ); $ttl = $this->get_value( $data, 'post_title' ); $date = $this->get_value( $data, 'post_date' ); $width = $this->get_value( $data, 'width', 'col-6' ); $height = $this->get_value( $data, 'height', 300 ); $twid = $this->get_value( $data, 'thumbwidth', 150 ); $thit = $this->get_value( $data, 'thumbheight', '160px' ); $pnum = $this->get_value( $data, 'pnum' ); $url = esc_url( get_permalink( $post_id ) ); $display = $this->get_customizer_setting( 'site_postsdisplaymode' ); $txt = $this->get_excerpt_by_id( $post_id, true ); $img = $this->self['PATH'] . 'images/no-image-found.jpg'; $imgwid = 260; $imghit = 160; $imgid = ''; if ( has_post_thumbnail( $post_id ) ) { $imgid = get_post_thumbnail_id( $post_id ); $imgurl = wp_get_attachment_url( $imgid ); if ( '' !== $imgurl && $this->validate_url( $imgurl ) ) { $img = $imgurl; $imgdata = wp_get_attachment_metadata( $imgid, true ); $iwid = $this->get_value( $imgdata, 'width' ); $ihit = $this->get_value( $imgdata, 'height' ); } } $timetxt = ''; if ( '' !== $date ) { $timetxt = date( 'M j, Y', strtotime( $date ) );} $author = ''; $authorid = $this->get_value( $data, 'post_author' ); if ( '' !== $authorid ) { $user = get_userdata( $authorid ); $author = $this->get_value( $user, array( 'data', 'display_name' ) ); } $thadd = ''; $theft = ''; $pclass = get_post_class( $post_id ); if ( '' !== $pclass ) { $pclass = ' ' . implode( ' ', $pclass );} if ( '' !== $pnum ) { $pclass .= ' ' . $pnum;} echo '
'; echo '
'; echo '
'; echo ''; $imgadd = ' width="' . esc_attr( $imgwid ) . '" height="' . esc_attr( $imghit ) . '" class="imgborder"'; $clicky = $this->get_customizer_checkbox( 'site_imagelinks' ); if ( $clicky ) { echo '';} echo ''; echo ''; if ( $clicky ) { echo '';} echo ''; echo '
'; echo '

' . esc_html( $ttl ) . ''; $cnum = get_comments_number( $post_id ); if ( $cnum > 0 ) { echo ' ' . esc_html( $cnum ) . ''; } echo '

'; echo ''; echo ''; echo esc_html( $txt ); echo ''; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; } /** * Return the boolean for a customizer setting that is a checkbox by filtering through all possible values. * * @since 1.0 * * @param string $field . * @requires : get_value * @usage : amp_publisher, generate_post, process_stylesheet_code */ public function get_customizer_checkbox( $field ) { $mod = get_theme_mod( $field ); if ( '' === $mod || 'false' === $mod || '0' === $mod ) { return false;} if ( 'true' === $mod || true === $mod || '1' === $mod ) { return true;} $def = $this->get_value( $this->self['customizer_settings'][ $field ], 'default' ); if ( '1' === $def ) { return true;} return false; } /** * Manage the organization of customizer settings to be used in both the WP Customizer and our Live Editor. * * @since 1.0 * * @usage : init_customizer_settings */ public function get_customizer_organization() { $ret = array(); $arr = array(); $arr[] = array( 'site_wrapconstrain' ); $arr[] = array( 'site_wrappad' ); $arr[] = array( 'site_sidebarwidth' ); $arr[] = array( 'site_sidebarhome' ); $arr[] = array( 'site_sidebarblog' ); $arr[] = array( 'site_sidebarpage' ); $arr[] = array( 'site_sidebarpost' ); $arr[] = array( 'site_sidebarcats' ); $arr[] = array( 'site_lineheight' ); $arr[] = array( 'site_fontsize' ); $arr[] = array( 'site_h1fontsize' ); $arr[] = array( 'site_h2fontsize' ); $arr[] = array( 'site_h3fontsize' ); $arr[] = array( 'site_h4fontsize' ); $arr[] = array( 'site_h5fontsize' ); $arr[] = array( 'site_h6fontsize' ); $arr[] = array( 'site_fontcolor' ); $arr[] = array( 'site_linkcolor' ); $arr[] = array( 'site_linkhovercolor' ); $arr[] = array( 'site_accentcolor' ); $ret['basics'] = $arr; $arr = array(); $arr[] = array( 'header_maxheight' ); $arr[] = array( 'header_vpad' ); $arr[] = array( 'header_bgcolor' ); $arr[] = array( 'header_textalign' ); $arr[] = array( 'footer_bgcolor' ); $arr[] = array( 'footer_textcolor' ); $arr[] = array( 'footer_texthovercolor' ); $arr[] = array( 'footer_copyrighttext' ); $ret['headfoot'] = $arr; $arr = array(); $arr[] = array( 'header_displaynavbar' ); $arr[] = array( 'navmenu_searchhome' ); $arr[] = array( 'navmenu_searchblog' ); $arr[] = array( 'navmenu_searchpage' ); $arr[] = array( 'navmenu_searchpost' ); $arr[] = array( 'navmenu_searchcats' ); $arr[] = array( 'navmenu_menufontsize' ); $arr[] = array( 'navmenu_menucase' ); $arr[] = array( 'navmenu_hovereffect' ); $arr[] = array( 'subheader_txtcolor' ); $arr[] = array( 'subheader_menuhovertext' ); $arr[] = array( 'subheader_menuactivecolor' ); $arr[] = array( 'subheader_bgcolor' ); $ret['navbar'] = $arr; $arr = array(); $arr[] = array( 'site_postsdisplaymode' ); $arr[] = array( 'site_postsdisplayheight' ); $arr[] = array( 'site_imagelinks' ); $ret['archives'] = $arr; $arr = array(); $arr[] = array( 'hero_home' ); $arr[] = array( 'hero_blog' ); $arr[] = array( 'hero_page' ); $arr[] = array( 'hero_post' ); $arr[] = array( 'hero_defaultimage' ); $arr[] = array( 'hero_height' ); $arr[] = array( 'hero_color' ); $arr[] = array( 'hero_bgcolor' ); $arr[] = array( 'hero_align' ); $arr[] = array( 'titlebar_home' ); $arr[] = array( 'titlebar_blog' ); $arr[] = array( 'titlebar_page' ); $arr[] = array( 'titlebar_post' ); $arr[] = array( 'titlebar_cats' ); $ret['hero'] = $arr; return $ret; } /** * Pull the Customizer setting (theme mod), then if blank provide registered default value. * * @since 1.0 * * @param string $setting . * @requires : get_value, htmlout * @usage : amp_css, amp_publisher, banner_logo, display_class, generate_post, stylesheet, wp_body_class, process_stylesheet_code */ public function get_customizer_setting( $setting ) { $mod = get_theme_mod( $setting ); if ( isset( $this->self['customizer_settings'][ $setting ] ) ) { $def = $this->get_value( $this->self['customizer_settings'][ $setting ], 'default' ); $type = $this->get_value( $this->self['customizer_settings'][ $setting ], 'type' ); $ismod = false; $mods = get_theme_mods(); if ( isset( $mods[ $setting ] ) ) { $ismod = true;} if ( 'checkbox' === $type && '' === $mod ) { if ( $ismod ) { return ''; } else { return $def; } } if ( 'checkbox' === $type && ( 'false' === $mod || false === $mod || '0' === $mod ) ) { return '';} if ( 'checkbox' === $type && ( 'true' === $mod || true === $mod || '1' === $mod ) ) { return '1';} if ( ! $mod ) { $mod = $def;} } $mod = $this->htmlout( $mod ); $mod = str_replace( '(_PL_)', '+', $mod ); return $mod; } /** * Return an array with registration data for a particular setting. * * @since 1.0 * * @param string $setting . * @requires : has_customizer_settings, get_value * @usage : process_stylesheet_code */ public function get_customizer_settings( $setting = null ) { if ( null === $setting ) { if ( $this->has_customizer_settings() ) { return $this->self['customizer_settings'];} return array(); } else { return $this->get_value( $this->self['customizer_settings'], $setting, array() ); } } /** * Pull the document object regardless of page or post type, convert to and return as array. * * @since 1.0 * * @requires : object_to_array * @usage : generate_markups */ public function get_doc() { $doc = get_queried_object(); global $pagenow; if ( is_customize_preview() || ( is_admin() && 'post.php' === $pagenow ) ) { global $post; $doc = $post; } if ( function_exists( 'wc_get_page_id' ) ) { if ( function_exists( 'is_shop' ) && is_shop() ) { $wooid = wc_get_page_id( 'shop' ); if ( $wooid ) { $doc = get_post( $wooid );} } } $doc = $this->object_to_array( $doc ); return $doc; } /** * Retrieve the excerpt for a post, if it's returned empty it pulls the content and concatenates it by word count. * * @since 1.0 * * @param string $post_id . * @param string $trim . * @usage : generate_post */ public function get_excerpt_by_id( $post_id, $trim = true ) { $the_post = get_post( $post_id ); $the_excerpt = $the_post->post_excerpt; if ( '' === $the_excerpt ) { $trim = true; $the_excerpt = $the_post->post_content; $the_excerpt = strip_shortcodes( $the_excerpt ); $the_excerpt = wp_strip_all_tags( $the_excerpt ); } if ( true === $trim ) { $the_excerpt = wp_trim_words( $the_excerpt, 50, '... ' ); } $link = get_permalink( $post_id ); return $the_excerpt; } /** * Meta fields are registered as a variable name with an object prefix to keep it distinct from fields registerd by other WP products. * * @since 1.0 * * @param string $field . * @param string $over . * @usage : get_meta, update_meta, update_post */ public function get_fieldname( $field, $over = false ) { $pref = $this->self['prefix']; if ( false === $over ) { if ( ! strstr( $field, $pref ) ) { return '_' . $pref . '_' . $field;} } return $field; } /** * Check for custom-logo assignment, and return data for the media object. * * @since 1.0 * * @param string $how . * @requires : get_value * @usage : amp_publisher, banner_logo, stylesheet, generate_markups */ public function get_logo( $how = '' ) { $arr = array(); $logoid = get_theme_mod( 'custom_logo' ); if ( $logoid ) { $arr['id'] = $logoid; if ( 'id' === $how ) { return $logoid;} $img = wp_get_attachment_image_url( $logoid, 'full' ); if ( 'url' === $how ) { return $img;} if ( '' !== $img ) { $arr['url'] = $img; $imgdata = wp_get_attachment_metadata( $logoid, true ); if ( $imgdata ) { $wid = $this->get_value( $imgdata, 'width' ); $hit = $this->get_value( $imgdata, 'height' ); if ( 'width' === $how ) { return $wid;} if ( 'height' === $how ) { return $hit;} $arr['width'] = $wid; $arr['height'] = $hit; } } } if ( '' === $how ) { return $arr;} return ''; } /** * Simplified meta value function that adds the object prefix and weeds out un-registered meta fields. * * @since 1.0 * * @param string $post_id . * @param string $var . * @requires : get_fieldname * @usage : echo_post_editor, update_post */ public function get_meta( $post_id, $var = '' ) { if ( '' === $var ) { return '';} if ( ! isset( $this->self['meta_list'][ $var ] ) ) { return '';} $field = $this->get_fieldname( $var ); return get_post_meta( $post_id, $field, true ); } /** * Return registered data as an array or return a value for a particular registered data point. * * @since 1.0 * * @param string $field . * @param string $var . * @requires : get_value * @usage : update_meta */ public function get_meta_data( $field, $var = '' ) { if ( isset( $this->self['meta_list'][ $field ] ) ) { if ( '' !== $var ) { return $this->get_value( $this->self['meta_list'][ $field ], $var );} return $this->self['meta_list'][ $field ]; } return array(); } /** * Return the page title across different page/post types. This simplifies development with one centralized function call. * * @since 1.0 * * @param string $id . * @requires : taxes * @usage : breadcrumbs */ public function get_page_title( $id = null ) { if ( is_category() || is_tax() ) { return $this->taxes( array( 'com' => 'title' ) );} if ( is_tag() ) { $tag = get_tag( $id ); if ( isset( $tag->name ) ) { return $tag->name; } else { return '';} } return get_the_title( $id ); } /** * Return category data for a post in a number of ways, from full array to a particular variable/value. * * @since 1.0 * * @param string $post_id . * @param string $how . * @param string $what . * @requires : taxes * @usage : breadcrumbs */ public function get_post_category_data( $post_id = null, $how = '', $what = '' ) { if ( null === $post_id ) { $post_id = get_the_ID();} $cats = array(); $cat = ''; $cid = ''; $dep = 0; $ctgy = get_the_category( $post_id ); if ( 'all' === $how ) { $cats = $ctgy; } elseif ( 'base' === $how ) { $dep = 1000; } else { $dep = -1; } foreach ( $ctgy as $rex => $vex ) { $catid = $vex->cat_ID; $ndep = $this->taxes( array( 'com' => 'depth', 'id' => $catid, ) ); if ( $dep !== $ndep ) { if ( 'all' === $how ) { if ( '' !== $cat ) { $cat .= ',';} $cat .= $vex->cat_name; if ( '' !== $cid ) { $cid .= ',';} $cid .= $catid; } else { $isdep = false; if ( 'base' === $how ) { if ( $ndep < $dep ) { $isdep = true; } } else { if ( $ndep > $dep ) { $isdep = true; } } if ( true === $isdep ) { $dep = $ndep; $cat = $vex->cat_name; $cid = $catid; $cats = $vex; } } } } if ( 'array' === $what ) { return $cats; } elseif ( 'id' === $what ) { return $cid; } else { return $cat; } } /** * These two functions consolodate two WP steps into one. * * @since 1.0 * * @usage : taxes */ public function get_site_base_url() { return esc_url( home_url() ); } /** * Return an array with standard size choices available to various objects. * * @since 1.0 * * @param string $how . */ public function get_size_choices( $how = '' ) { $ret = array(); $pre = substr( $how, 0, 5 ); if ( 'auto' === $how || 'thumbhead' === $how ) { $ret ['auto'] = 'Auto';} if ( 'all' === $how ) { $ret['10px'] = '10px'; $ret['20px'] = '20px'; $ret['30px'] = '30px'; $ret['40px'] = '40px'; } if ( 'hero' === $how ) { $pre = 'fifty';} if ( 'thumbhead' === $how || 'all' === $how ) { $ret['50px'] = '50px'; $ret['60px'] = '60px'; $ret['70px'] = '70px'; $ret['80px'] = '80px'; $ret['90px'] = '90px'; } $ret['100px'] = '100px'; if ( 'thumb' === $pre || 'all' === $how ) { $ret['110px'] = '110px'; $ret['120px'] = '120px'; $ret['130px'] = '130px'; $ret['140px'] = '140px'; } $ret['150px'] = '150px'; if ( 'thumb' === $pre || 'all' === $how ) { $ret['160px'] = '160px'; $ret['170px'] = '170px'; $ret['180px'] = '180px'; $ret['190px'] = '190px'; } $ret['200px'] = '200px'; if ( 'fifty' === $pre || 'all' === $how ) { $ret['250px'] = '250px';} $ret['300px'] = '300px'; if ( 'thumb' !== $pre ) { if ( 'fifty' === $pre || 'all' === $how ) { $ret['350px'] = '350px';} $ret['400px'] = '400px'; if ( 'fifty' === $pre || 'all' === $how ) { $ret['450px'] = '450px';} $ret['500px'] = '500px'; if ( 'fifty' === $pre || 'all' === $how ) { $ret['550px'] = '550px';} $ret['600px'] = '600px'; if ( 'fifty' === $pre || 'all' === $how ) { $ret['650px'] = '650px';} $ret['700px'] = '700px'; if ( 'fifty' === $pre || 'all' === $how ) { $ret['750px'] = '750px';} $ret['800px'] = '800px'; if ( 'fifty' === $pre || 'all' === $how ) { $ret['850px'] = '850px';} $ret['900px'] = '900px'; if ( 'fifty' === $pre || 'all' === $how ) { $ret['950px'] = '950px';} $ret['1000px'] = '1000px'; } return $ret; } /** * Get a value from an array or object across nested levels of depth. * * @since 1.0 * * @param string $incoming . * @param string $var . * @param string $def . * @requires : object_to_array * @usage : amp_publisher, banner_logo, breadcrumb_loop, generate_post, is_nonamp, stylesheet, add_post_editor, add_registered_css, create_customizer_setting, echo_post_editor, generate_markups, get_customizer_checkbox, get_customizer_setting, get_customizer_settings, get_logo, get_meta_data, init_customizer_settings, process_stylesheet_code, scrape_between, taxes, update_post, using_meta */ public function get_value( $incoming, $var, $def = '' ) { if ( is_object( $incoming ) && is_array( $var ) ) { $incoming = $this->object_to_array( $incoming );} if ( is_object( $incoming ) ) { if ( isset( $incoming->$var ) ) { return $incoming->$var; } } else { if ( is_array( $var ) ) { if ( count( $var ) > 0 ) { $tar = $incoming; foreach ( $var as $far ) { if ( isset( $tar[ $far ] ) ) { $tar = $tar[ $far ]; } else { return $def; } } return $tar; } } else { if ( isset( $incoming[ $var ] ) ) { return $incoming[ $var ]; } } } return $def; } /** * Check if the class has any cronjobs registered. Used before initiating WP setup script. * * @since 1.0 * * @usage : custom_cron_schedules, init */ public function has_cron() { if ( isset( $this->self['cron_list'] ) ) { if ( count( $this->self['cron_list'] ) > 0 ) { return true; } }return false; } /** * Check if any settings have been registered, used to check if handling is necessary. * * @since 1.0 * * @usage : stylesheet, get_customizer_settings, init, process_stylesheet_code */ public function has_customizer_settings() { if ( isset( $this->self['customizer_settings'] ) ) { if ( count( $this->self['customizer_settings'] ) > 0 ) { return true; } }return false; } /** * Decoding of a string that was encoded with htmlin(). * * @since 1.0 * * @param string $nstr . * @requires : htmlout * @usage : get_customizer_setting, htmlout */ public function htmlout( $nstr ) { if ( is_array( $nstr ) ) { if ( count( $nstr ) > 0 ) { foreach ( $nstr as $dex => $data ) { $nstr[ $dex ] = $this->htmlout( $data ); } } } else { $cnt = count( $this->self['NEW_CHARS'] ); for ( $cc = 0;$cc < $cnt;$cc++ ) { $narr = explode( $this->self['NEW_CHARS'][ $cc ], $nstr ); $nstr = implode( $this->self['BAD_CHARS'][ $cc ], $narr ); } $nstr = stripslashes( $nstr ); } return $nstr; } /** * The main init() function, added as an action in the base level of the functions file. * * @since 1.0 * * @requires : registration, is_child, import_theme_settings, has_customizer_settings, has_cron, using_meta, extends_init, init_customizer_settings, custom_cron_schedules, add_post_editor, update_post */ public function init() { if ( method_exists( $this, 'registration' ) ) { $this->registration();} if ( method_exists( $this, 'is_child' ) && method_exists( $this, 'import_theme_settings' ) ) { if ( $this->is_child() ) { $this->import_theme_settings();} } if ( $this->has_customizer_settings() ) { add_action( 'customize_register', array( &$this, 'init_customizer_settings' ) ); } if ( $this->has_cron() ) { add_filter( 'cron_schedules', array( &$this, 'custom_cron_schedules' ) ); foreach ( $this->self['cron_list'] as $fct => $interval ) { $action = $fct . '_cron'; add_action( $action, $fct ); if ( ! wp_next_scheduled( $action ) ) { wp_schedule_event( time(), $interval, $action ); } } } global $pagenow; if ( $this->using_meta() && ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) ) { add_action( 'edit_form_advanced', array( &$this, 'add_post_editor' ) ); add_action( 'edit_page_form', array( &$this, 'add_post_editor' ) ); add_action( 'edit_post', array( &$this, 'update_post' ), 10, 2 ); } if ( method_exists( $this, 'extends_init' ) ) { $this->extends_init();} } /** * Handle the WP Customizer setup of sections and settings using the registered data. This is added as a WordPress action by the theme's init() function. * * @since 1.0 * * @param string $wp_customize . * @requires : get_value, get_customizer_organization, create_customizer_setting * @usage : init */ public function init_customizer_settings( $wp_customize ) { $secprio = 1; $defsect = ''; foreach ( $this->self['customizer_sections'] as $section => $data ) { if ( '' === $defsect ) { $defsect = $section;} $title = $this->get_value( $data, 'title' ); $prio = $this->get_value( $data, 'priority' ); $desc = $this->get_value( $data, 'description' ); $call = $this->get_value( $data, 'active_callback' ); if ( '' === $prio ) { $prio = $secprio; $secprio ++;} $wp_customize->add_section( $section, array( 'title' => $title, 'priority' => $prio, 'description' => $desc, 'active_callback' => $call, ) ); } if ( method_exists( $this, 'get_customizer_organization' ) ) { $org = $this->get_customizer_organization(); if ( count( $org ) > 0 ) { foreach ( $org as $sect => $sets ) { $dex = 1; foreach ( $sets as $sett ) { $setting = $this->get_value( $sett, 0 ); $com = $this->get_value( $sett, 1 ); $rcom = true; if ( 'label' === $com || 'desc' === $com || 'echo' === $com ) { $rcom = false;} if ( $rcom ) { $data = $this->get_value( $this->self['customizer_settings'], $setting ); if ( '' !== $data ) { $data['section'] = $sect; $data['priority'] = $dex; $dex ++; $this->create_customizer_setting( $setting, $data ); } } } } } foreach ( $this->self['customizer_settings'] as $setting => $data ) { if ( isset( $data['section'] ) ) { $sect = $this->get_value( $data, 'section' ); if ( '' !== $sect ) { $this->create_customizer_setting( $setting, $data ); } } } } else { $bysect = array(); foreach ( $this->self['customizer_settings'] as $setting => $data ) { if ( ! isset( $data['section'] ) ) { $data['section'] = $defsect;} $sect = $this->get_value( $data, 'section' ); if ( '' !== $sect ) { if ( ! isset( $bysect[ $sect ] ) ) { $bysect[ $sect ] = array();} $bysect[ $sect ][ $setting ] = $data; } } if ( count( $bysect ) > 0 ) { foreach ( $bysect as $sect => $sets ) { $dex = 1; foreach ( $sets as $setting => $data ) { $data['priority'] = $dex; $dex ++; $this->create_customizer_setting( $setting, $data ); } } } } } /** * Check if the page is the static page designated as the posts page. * * @since 1.0 * * @requires : is_homepage * @usage : amp_publisher */ public function is_blog() { if ( is_home() && ! $this->is_homepage() ) { return true;} return false; } /** * Check if data from a checkbox is true or false covering a number of possible values. * * @since 1.0 * * @param string $val . * @usage : update_meta */ public function is_checked( $val ) { if ( '1' === $val || 'true' === $val || true === $val ) { return true;} return false; } /** * Check if currently on the actual site root. * * @since 1.0 * * @requires : current_page_url * @usage : amp_publisher, breadcrumbs, generate_markups, is_blog, true_pagetype */ public function is_homepage() { $home = home_url(); $current = $this->current_page_url( 'base' ); if ( $current === $home || $current === $home . '/' ) { return true;} return false; } /** * Check for AMP State, necessary for modifying the DOM in a number of situations to suit the AMP state of the page. * * @since 1.0 * * @requires : true_pageid, get_value * @usage : amp_publisher */ public function is_nonamp() { if ( ! defined( 'AMP__VERSION' ) ) { return true;} $ampt = AMP_Options_Manager::get_option( 'theme_support' ); if ( 'disabled' === $ampt || 'paired' === $ampt ) { /* FIX 1.0.1 - WPCS whitelist nonce recommendation. */ if ( ! isset( $_GET['amp'] ) ) {// input var okay; WPCS: CSRF ok. /* No nonce needed, only checking for variable usage, ignores the input value. */ return true; } } $pageid = $this->true_pageid(); $arr = get_post_meta( $pageid ); if ( ! empty( $arr ) ) { $ampd = $this->get_value( $arr, array( 'amp_status', 0 ) ); if ( 'disabled' === $ampd ) { return true;} } return false; } /** * Check for existence of a method in/by the local class, then run it and return it's value or a confirmation of non-existence. * * @since 1.0 * * @param string $fct . * @param string $pass . * @usage : add_post_editor */ public function method_call( $fct, $pass = '' ) { if ( method_exists( $this, $fct ) ) { if ( '' !== $pass ) { return call_user_func( array( $this, $fct ), $pass ); } else { return call_user_func( array( $this, $fct ) ); } } return 'NA'; } /** * Convert a PHP object to an array. * * @since 1.0 * * @param string $d . * @usage : get_doc, get_value */ public function object_to_array( $d ) { if ( is_object( $d ) ) { $d = get_object_vars( $d ); }if ( is_array( $d ) ) { return array_map( array( $this, 'object_to_array' ), $d ); } else { return $d;} } /** * Create the pagination bar for posts/archives. * * @since 1.0 * * @usage : amp_publisher */ public function page_navigation() { global $wp_query; $bignum = 999999999; if ( $wp_query->max_num_pages <= 1 ) { return;} echo ''; } /** * Handle shortcodes used in the stylesheet. * * @since 1.0 * * @param string $set . * @param string $data . * @requires : has_customizer_settings, get_customizer_settings, get_value, get_customizer_checkbox, get_customizer_setting * @usage : stylesheet */ public function process_stylesheet_code( $set, $data = null ) { if ( null === $data ) { $data = array(); if ( $this->has_customizer_settings() ) { $sets = $this->get_customizer_settings(); $data = $this->get_value( $sets, $set ); } } $type = $this->get_value( $data, 'type' ); if ( 'checkbox' === $type ) { $on = $this->get_customizer_checkbox( $set ); $pos = $this->get_value( $data, 'pos', 'block' ); $neg = $this->get_value( $data, 'neg', 'none' ); if ( true === $on ) { $val = $pos; } else { $val = $neg;} } elseif ( 'color' === $type ) { $val = $this->get_customizer_setting( $set ); if ( 'inherit' === $val && isset( $data['neg'] ) ) { $val = $data['neg']; if ( 'default' === $val ) { $val = $this->get_value( $data, 'default' );} } } else { $val = $this->get_customizer_setting( $set ); } return $val; } /** * Create a section in the customizer, each setting will be assigned to it's section in the order they are registered. * * @since 1.0 * * @param string $sect . * @param array $params . */ public function register_customizer_section( $sect, $params = array() ) { if ( ! isset( $this->self['customizer_sections'] ) ) { $this->self['customizer_sections'] = array();} $this->self['customizer_sections'][ $sect ] = $params; } /** * Add a setting to the Customizer and store the data for use by the framework. Centralizing and storing the data in the class speeds up processing time. * * @since 1.0 * * @param string $setting . * @param array $params . */ public function register_customizer_setting( $setting, $params = array() ) { if ( ! isset( $this->self['customizer_settings'] ) ) { $this->self['customizer_settings'] = array();} $this->self['customizer_settings'][ $setting ] = $params; } /** * Run a function/method by name by first checking if it exists within the class, then if it exists in the base file. * * @since 1.0 * * @param string $fct . * @param string $pass . * @usage : echo_post_editor */ public function runit( $fct, $pass = '' ) { if ( method_exists( $this, $fct ) ) { if ( '' !== $pass ) { call_user_func( array( $this, $fct ), $pass ); } else { call_user_func( array( $this, $fct ) ); } } elseif ( function_exists( $fct ) ) { if ( '' !== $pass ) { call_user_func( $fct, $pass ); } else { call_user_func( $fct ); } } } /** * Find and return a portion of a string that falls between a starting string and an ending string. Used in various places for removing HTML tags and attributes that invalidate Google AMP compliance. * * @since 1.0 * * @param string $txt . * @param string $start . * @param string $end . * @requires : get_value * @usage : stylesheet, true_featured_image */ public function scrape_between( $txt, $start, $end ) { if ( '' === $start ) { $pre = '[START_-_HERE]'; $txt = $pre . $txt; $start = $pre; } if ( '' === $end ) { $pos = '[END_-_HERE]'; $txt = $txt . $pos; $end = $pos; } $splode = explode( $start, $txt ); $part = $this->get_value( $splode, 1 ); $parts = explode( $end, $part ); return $parts[0]; } /** * We must include all CSS in a single tag in the header for AMP compliance, and the entirety of the CSS must not exceed 50KB. We pull in the stylesheet, remove the header, then process the contents for shortcodes and usage checks, handle custom css for various objects, and then remove all comments and minify it. This is all very important to meet the AMP CSS size limit requirements. * * @since 1.0 * * @param string $params . * @requires : url_get_contents, scrape_between, add_registered_css, has_customizer_settings, get_value, process_stylesheet_code, get_logo, get_customizer_setting * @usage : amp_css */ public function stylesheet( $params = null ) { $folder = get_stylesheet_directory_uri(); $sheet = $this->url_get_contents( $folder . '/style.css' ); $sheet = $this->scrape_between( $sheet . '[ENDD]', 'START_STYLEHEET***********************/', '[ENDD]' ); $sheet .= $this->add_registered_css(); if ( $this->has_customizer_settings() ) { $sets = $this->self['customizer_settings']; $codes = array(); foreach ( $sets as $set => $data ) { $code = $this->get_value( $data, 'code' ); if ( '' !== $code ) { $codes[ $code ] = $set; $val = $this->process_stylesheet_code( $set, $data ); $sheet = str_replace( '[[' . $code . ']]', $val, $sheet ); } } $wid = 0; $hit = 0; $logowid = 0; /* FIX 1.0.2 - Switched to custom-logo support. */ if ( '' !== $this->get_logo( 'id' ) ) { $wid = $this->get_logo( 'width' ); $hit = $this->get_logo( 'height' ); if ( '' !== $wid && '' !== $hit ) { $mhit = $this->get_customizer_setting( 'header_maxheight' ); if ( 'auto' !== $mhit ) { $bhit = intval( str_replace( 'px', '', $mhit ) ); if ( $hit > $bhit ) { $nrat = $bhit / $hit; $hit = $bhit; $wid = floor( $wid * $nrat ); } } $logowid = $wid + 20; } } $sheet = str_replace( '[[logo-width]]', $logowid . 'px', $sheet ); $sheet = str_replace( '[[logo-img-width]]', $wid . 'px', $sheet ); $sheet = str_replace( '[[logo-img-height]]', $hit . 'px', $sheet ); $sheet = preg_replace( '/\[[^]]+\]]/', '', $sheet ); $sheet = preg_replace( '/\s*(?!<\")\/\*[^\*]+\*\/(?!\")\s*/', '', $sheet ); $sheet = str_replace( ', ', ',', $sheet ); $sheet = preg_replace( "/\r\n|\r|\n/", '', $sheet ); $sheet = preg_replace( "/\t/", '', $sheet ); } return $sheet; } /** * Return various pieces of category/taxonomy data. This centralized function makes development easier. * * @since 1.0 * * @param string $params . * @requires : get_value, taxes, get_site_base_url, delimitit * @usage : breadcrumb_loop, breadcrumbs, get_page_title, get_post_category_data, taxes */ public function taxes( $params ) { $id = $this->get_value( $params, 'id' ); $com = $this->get_value( $params, 'com' ); $cat = $this->get_value( $params, 'category' ); if ( '' === $id || null === $id ) { if ( '' === $cat ) { $cat = single_term_title( '', false );} $id = get_cat_ID( $cat ); } if ( 'id' === $com ) { return $id; } elseif ( 'title' === $com ) { return get_cat_name( $id ); } elseif ( 'description' === $com ) { return category_description( $id ); } elseif ( 'depth' === $com ) { $dep = 0; $category = get_category( $id ); for ( $i = 1;$i <= 9;$i++ ) { if ( $category->category_parent ) { $category = get_category( $category->category_parent ); $dep = $i; } } return $dep + 1; } elseif ( 'data' === $com ) { $category_data = get_term_by( 'term_id', $id, 'category' ); $var = $this->get_value( $params, 'var' ); if ( '' === $var ) { return $category_data;} if ( is_object( $category_data ) ) { return $category_data->$var; } else { return $this->get_value( $category_data, $var ); } } elseif ( 'link' === $com ) { $catslug = $this->taxes( array( 'com' => 'path', 'id' => $id, ) ); return $this->get_site_base_url() . '/category/' . $catslug; } elseif ( 'path' === $com ) { $data = $this->taxes( array( 'com' => 'data', 'id' => $id, ) ); $pslug = $this->get_value( $data, 'slug' ); $parent = $this->get_value( $data, 'parent', 0 ); $slug = $this->get_value( $params, 'slug' ); if ( '' !== $pslug ) { $slug = $pslug . '/' . $slug; if ( 0 !== $parent ) { $slug = $this->taxes( array( 'com' => 'path', 'id' => $parent, 'slug' => $slug, ) );} } return $slug; } elseif ( 'parents' === $com ) { $data = $this->taxes( array( 'com' => 'data', 'id' => $id, ) ); $parent = $this->get_value( $data, 'parent', 0 ); $ids = $this->get_value( $params, 'ids' ); $ids = $this->delimitit( $ids, ',', $parent ); if ( $parent > 0 ) { $ids = $this->taxes( array( 'com' => 'parents', 'id' => $parent, 'ids' => $ids, ) );} return $ids; } return ''; } /** * Echo the page title across different page/post types. This simplifies development with one centralized function call. * * @since 1.0 * * @param string $post_id . * @usage : amp_publisher */ public function theme_page_title( $post_id = null ) { $format = get_option( 'date_format' ); if ( is_category() ) { single_cat_title();} elseif ( is_tag() ) { single_tag_title();} elseif ( is_author() ) { global $post; $author_id = $post->post_author; the_author_meta( 'display_name', $author_id );} elseif ( is_day() ) { the_time( 'l, F j, Y' );} elseif ( is_month() ) { the_time( $format );} elseif ( is_year() ) { the_time( $format );} elseif ( is_single() || is_page() ) { the_title();} } /** * Retrieve the image assigned as the page, post or category Featured Image. * * @since 1.0 * * @param string $pageid . * @param string $pagetype . * @param string $how . * @requires : scrape_between * @usage : amp_publisher, generate_markups */ public function true_featured_image( $pageid, $pagetype, $how = '' ) { $img = ''; $imgid = ''; if ( $pageid > 0 ) { if ( 'category' === $pagetype || 'product_cat' === $pagetype ) { $imgdata = get_term_meta( $pageid, 'thumbnail_id' ); if ( $imgdata ) { $imgid = $imgdata[0]; $img = wp_get_attachment_url( $imgid ); } } else { if ( has_post_thumbnail( $pageid ) ) { $imgid = get_post_thumbnail_id( $pageid ); $img = wp_get_attachment_url( $imgid ); if ( '' === $img ) { $thumb = get_the_post_thumbnail( null, 'full' ); if ( '' !== $thumb ) { $img = $this->scrape_between( $thumb, 'src="', '"' ); } } } } } if ( 'id' === $how ) { return $imgid;} return $img; } /** * Get the page/post ID, term ID, WooCommerce page ID, or 0 for home page as posts or unassigned. * * @since 1.0 * * @usage : amp_publisher, is_nonamp, generate_markups */ public function true_pageid() { $obj = get_queried_object(); global $pagenow; if ( is_admin() && 'post.php' === $pagenow ) { global $post; $obj = $post; } if ( function_exists( 'wc_get_page_id' ) ) { if ( function_exists( 'is_shop' ) && is_shop() ) { $wooid = wc_get_page_id( 'shop' ); if ( $wooid ) { $obj = get_post( $wooid );} } } if ( $obj ) { if ( isset( $obj->taxonomy ) ) { return $obj->term_id; } if ( isset( $obj->ID ) ) { return $obj->ID; } } return 0; } /** * Get the page type, allows for all iterations of home/posts page assignment, taxonomy, and WooCommmerce page types. * * @since 1.0 * * @requires : is_homepage * @usage : amp_publisher, generate_markups */ public function true_pagetype() { $obj = get_queried_object(); if ( function_exists( 'wc_get_page_id' ) ) { if ( function_exists( 'is_shop' ) && is_shop() ) { return 'shop'; } } if ( $obj ) { if ( isset( $obj->taxonomy ) ) { return $obj->taxonomy; } if ( isset( $obj->post_type ) ) { return $obj->post_type; } } else { if ( $this->is_homepage() ) { return 'home';} } return ''; } /** * Update post meta by adding/editing where appropriate, and deleting when empty. Updating the meta field this way minimizes database weight by not storing empty values and simplifies using meta values in this object. * * @since 1.0 * * @param string $post_id . * @param string $var . * @param string $newval . * @param string $pref . * @requires : get_fieldname, get_meta_data, is_checked * @usage : update_post */ public function update_meta( $post_id, $var, $newval, $pref = false ) { $field = $this->get_fieldname( $var, $pref ); $ftype = $this->get_meta_data( $var, 'type' ); if ( 'checkbox' === $ftype ) { if ( $this->is_checked( $newval ) ) { $newval = '1'; } else { $newval = ''; } } if ( '' === $newval ) { delete_post_meta( $post_id, $field ); } else { add_post_meta( $post_id, $field, $newval, true ) || update_post_meta( $post_id, $field, $newval ); } } /** * Hook into the post editor update functionality to include our registered meta fields. * * @since 1.0 * * @param string $post_id . * @param string $post . * @requires : get_value, get_fieldname, get_meta, update_meta * @usage : init */ public function update_post( $post_id, $post ) { $runit = false; if ( is_single( $post_id ) ) { if ( ! empty( $_POST ) && check_admin_referer( $this->self['prefix'] . '_post_nonce', $this->self['prefix'] . '_nonce_field' ) ) {// input var okay;. $runit = true; } } else { $runit = true; } if ( true === $runit ) { $arr = $this->self['meta_list']; if ( count( $arr ) > 0 ) { foreach ( $arr as $name => $data ) { $type = $this->get_value( $data, 'type' ); if ( 'pass' === $type ) { continue;} $field = $this->get_fieldname( $name ); $oldval = $this->get_meta( $post_id, $field ); if ( 'checkbox' === $type ) { $newval = ''; if ( isset( $_POST[ $field ] ) ) {// input var okay;. $newval = 1; } } else { if ( isset( $_POST[ $field ] ) ) {// input var okay;. $newval = sanitize_text_field( wp_unslash( $_POST[ $field ] ) );// input var okay;. } } if ( $newval !== $oldval || '' === $newval ) { $this->update_meta( $post_id, $field, $newval ); } } } } } /** * Retrieve text/HTML from a URL. This function consolodates the two steps necessary to gather the data and return only the text. This is used to check our API for updates to the Fontawesome version/list. * * @since 1.0 * * @param string $url . * @usage : stylesheet, add_registered_css */ public function url_get_contents( $url ) { if ( function_exists( 'vip_safe_wp_remote_get' ) ) { $response = vip_safe_wp_remote_get( $url ); } else { /* WPCS - Warning : Checking for recommended replacement function if available, then using discouraged function is not available... then show must go on. */ $response = wp_remote_get($url);// phpcs:ignore } if ( is_wp_error( $response ) ) { return '';} return wp_remote_retrieve_body( $response ); } /** * Check if a nav menu is available, assigned, and/or empty. These checks are useful in various situations. * * @since 1.0 * * @param string $location . * @param string $com . * @usage : amp_publisher */ public function use_nav_menu( $location, $com = '' ) { if ( has_nav_menu( $location ) ) { if ( 'assigned' === $com ) { return true;} if ( false !== wp_nav_menu( array( 'theme_location' => $location, 'echo' => false, ) ) ) { return true; } else { if ( 'empty' === $com ) { return true;} } } return false; } /** * Verify that this object has meta field(s) registered, used to check if a process is needed before running it. * * @since 1.0 * * @requires : get_value * @usage : init */ public function using_meta() { if ( isset( $this->self['meta_list'] ) && count( $this->self['meta_list'] ) > 0 ) { foreach ( $this->self['meta_list'] as $var => $arr ) { if ( '' !== $this->get_value( $arr, 'type' ) ) { return true;} } } return false; } /** * Check if a string fits the valid URL structure. * * @since 1.0 * * @param string $string . * @usage : generate_post */ public function validate_url( $string ) { if ( filter_var( $string, FILTER_VALIDATE_URL ) ) { return true;} return false; } /** * Add class name for the site's layout to the body tag. * * @since 1.0 * * @param string $input . * @requires : get_customizer_setting, amp_publisher */ public function wp_body_class( $input ) { $maxed = $this->get_customizer_setting( 'site_wrapconstrain' ); if ( '' === $maxed || '100%' === $maxed ) { $input[] = 'maxed';} if ( $this->amp_publisher( 'has sidebar' ) ) { $input[] = 'has-sidebar';} $input[] = 'tacwpt'; $input[] = 'ampacc'; return $input; } }