Skip to content

Commit

Permalink
Closes #64, closes #231
Browse files Browse the repository at this point in the history
  • Loading branch information
sybrew committed Feb 23, 2018
1 parent 9caddcd commit 60609cb
Show file tree
Hide file tree
Showing 23 changed files with 739 additions and 122 deletions.
2 changes: 1 addition & 1 deletion autodescription.php
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: The SEO Framework
* Plugin URI: https://theseoframework.com/
* Description: An automated, advanced, accessible, unbranded and extremely fast SEO solution for any WordPress website.
* Version: 3.0.4-dev2018.2.23.0
* Version: 3.0.4-dev2018.2.23.1
* Author: Sybre Waaijer
* Author URI: https://theseoframework.com/
* License: GPLv3
Expand Down
3 changes: 2 additions & 1 deletion inc/classes/admin-init.class.php
Expand Up @@ -212,6 +212,7 @@ public function _localize_admin_javascript() {
* 3. Removed unused caching.
* 4. Added dynamic output control.
* @since 2.9.0 Added boolean $returnValue['states']['isSettingsPage']
* @since 3.0.4 `descPixelGuideline` has been increased from "920 and 820" to "1820 and 1720" respectively.
*
* @return array $strings The l10n strings.
*/
Expand Down Expand Up @@ -369,7 +370,7 @@ protected function get_javascript_l10n() {
'descriptionSeparator' => $description_separator,
'titleLocation' => $title_location,
'titlePixelGuideline' => 600,
'descPixelGuideline' => $is_post_edit ? ( $this->is_page() ? 920 : 820 ) : 920,
'descPixelGuideline' => $is_post_edit ? ( $this->is_page() ? 1820 : 1720 ) : 1820,
),
'other' => $this->additional_js_l10n( null, array(), true ),
);
Expand Down
18 changes: 15 additions & 3 deletions inc/classes/admin-pages.class.php
Expand Up @@ -871,18 +871,30 @@ public function get_logo_uploader_form( $input_id ) {
}

/**
* Outputs floating title HTML for JavaScript.
* Outputs floating and reference title HTML elements for JavaScript.
*
* @since 3.0.0
* @since 3.0.4
*/
public function output_floating_title_elements() {
public function output_js_title_elements() {
?>
<span id="tsf-title-reference" style="display:none"></span>
<span id="tsf-title-offset" class="hide-if-no-js"></span>
<span id="tsf-title-placeholder" class="hide-if-no-js"></span>
<span id="tsf-title-placeholder-prefix" class="hide-if-no-js"></span>
<?php
}

/**
* Outputs reference description HTML elements for JavaScript.
*
* @since 3.0.4
*/
public function output_js_description_elements() {
?>
<span id="tsf-description-reference" style="display:none"></span>
<?php
}

/**
* Outputs character counter wrap for both JavaScript and no-Javascript.
*
Expand Down
6 changes: 4 additions & 2 deletions inc/classes/doing-it-right.class.php
Expand Up @@ -1039,6 +1039,8 @@ protected function the_seo_bar_description_notice( $args ) {
* Description Length notices.
*
* @since 2.6.0
* @since 3.0.4 : 1. Threshold "too long" has been increased from 155 to 300.
* 2. Threshold "far too long" has been increased to 330 from 175.
*
* @param int $desc_len The Title length
* @param string $class The current color class.
Expand All @@ -1064,12 +1066,12 @@ protected function get_the_seo_bar_description_length_warning( $desc_len, $class

// Don't make it okay if it's already bad.
$class = $bad === $class ? $class : $okay;
} elseif ( $desc_len > 155 && $desc_len < 175 ) {
} elseif ( $desc_len > 300 && $desc_len < 330 ) {
$notice = $i18n['length_too_long'];

// Don't make it okay if it's already bad.
$class = $bad === $class ? $class : $okay;
} elseif ( $desc_len >= 175 ) {
} elseif ( $desc_len >= 330 ) {
$notice = $i18n['length_far_too_long'];
$class = $bad;
} else {
Expand Down
99 changes: 95 additions & 4 deletions inc/classes/generate-description.class.php
Expand Up @@ -39,6 +39,87 @@ protected function __construct() {
parent::__construct();
}

/**
* Returns the Twitter meta description. Falls back to Open Graph description.
*
* @since 3.0.4
* @uses $this->get_open_graph_description()
*
* @param int|null $id The post or term ID. Falls back to queried ID.
* @param bool $escape Whether to escape the description.
* @return string Twitter Description.
*/
public function get_twitter_description( $id = null, $escape = true ) {

if ( is_null( $id ) )
$id = $this->get_the_real_ID();

$desc = $this->get_custom_field( '_twitter_description', $id )
?: $this->get_open_graph_description( $id, false );

return $escape ? $this->escape_description( $desc ) : $desc;
}

/**
* Returns the Open Graph meta description. Falls back to meta description.
*
* @since 3.0.4
* @uses $this->get_generated_open_graph_description()
*
* @param int|null $id The post or term ID. Falls back to queried ID.
* @param bool $escape Whether to escape the description.
* @return string Open Graph Description.
*/
public function get_open_graph_description( $id = null, $escape = true ) {

if ( is_null( $id ) )
$id = $this->get_the_real_ID();

$desc = $this->get_custom_field( '_open_graph_description', $id )
?: $this->get_generated_open_graph_description( $id, false );

return $escape ? $this->escape_description( $desc ) : $desc;
}

/**
* Returns the autogenerated open graph meta description. Falls back to meta description.
*
* @since 3.0.4
* @uses $this->get_generated_open_graph_description()
*
* @param int|null $id The post or term ID. Falls back to queried ID.
* @param bool $escape Whether to escape the description.
* @return string Autogenerated Twitter Description.
*/
public function get_generated_twitter_description( $id = null, $escape = true ) {
return $this->get_generated_open_graph_description( $id, $escape );
}

/**
* Returns the autogenerated open graph meta description. Falls back to meta description.
*
* @since 3.0.4
* @uses $this->generate_description()
* @staticvar array $cache
*
* @param int|null $id The post or term ID. Falls back to queried ID.
* @param bool $escape Whether to escape the description.
* @return string Autogenerated Open Graph Description.
*/
public function get_generated_open_graph_description( $id = null, $escape = true ) {

if ( is_null( $id ) )
$id = $this->get_the_real_ID();

static $cache = array();

$desc = isset( $cache[ $id ] )
? $cache[ $id ]
: $cache[ $id ] = $this->generate_description( '', array( 'id' => $id, 'social' => true, 'escape' => false ) );

return $escape ? $this->escape_description( $desc ) : $desc;
}

/**
* Creates description. Base function.
*
Expand Down Expand Up @@ -107,7 +188,10 @@ public function generate_description( $description = '', $args = array() ) {
if ( \apply_filters( 'the_seo_framework_do_shortcodes_in_description', false ) )
$description = \do_shortcode( $description );

return $this->escape_description( $description );
if ( $args['escape'] )
$description = $this->escape_description( $description );

return $description;
}

/**
Expand All @@ -130,6 +214,7 @@ public function parse_description_args( $args = array(), $defaults = array(), $g
'is_home' => false,
'get_custom_field' => true,
'social' => false,
'escape' => true,
);

/**
Expand All @@ -139,9 +224,11 @@ public function parse_description_args( $args = array(), $defaults = array(), $g
* @param bool $is_home We're generating for the home page.
* @param bool $get_custom_field Do not fetch custom title when false.
* @param bool $social Generate Social Description when true.
* @param bool $escape Whether to escape the description.
* }
*
* @since 2.5.0
* @since 3.0.4 Added escape parameter.
*
* @param array $defaults The description defaults.
* @param array $args The input args.
Expand All @@ -159,6 +246,7 @@ public function parse_description_args( $args = array(), $defaults = array(), $g
$args['is_home'] = isset( $args['is_home'] ) ? (bool) $args['is_home'] : $defaults['is_home'];
$args['get_custom_field'] = isset( $args['get_custom_field'] ) ? (bool) $args['get_custom_field'] : $defaults['get_custom_field'];
$args['social'] = isset( $args['social'] ) ? (bool) $args['social'] : $defaults['social'];
$args['escape'] = isset( $args['escape'] ) ? (bool) $args['escape'] : $defaults['escape'];

return $args;
}
Expand Down Expand Up @@ -473,6 +561,7 @@ protected function generate_the_description( $args, $escape = true ) {
* Returns the generated description excerpt array for the normal description tag.
*
* @since 2.8.0
* @since 3.0.4 Now uses 300 characters instead of 155.
*
* @param int $id The post/term ID.
* @param bool|object The term object.
Expand Down Expand Up @@ -506,12 +595,13 @@ public function get_description_excerpt_normal( $id = 0, $term = false ) {
* Determine if the title is far too long (72+, rather than 75 in the Title guidelines).
* If this is the case, trim the "title on blogname" part from the description.
* @since 2.8.0
* @since 3.0.4 Increased to basis 300, from 155.
*/
if ( $additions_length > 71 ) {
$max_char_length = 155;
$max_char_length = 300;
$trim = true;
} else {
$max_char_length = 155 - $additions_length;
$max_char_length = 300 - $additions_length;
$trim = false;
}

Expand Down Expand Up @@ -815,6 +905,7 @@ public function generate_description_title( $id = '', $term = '', $page_on_front
*
* @since 2.3.4
* @since 2.8.2 Now no longer escapes excerpt by accident in processing, preventing "too short" output.
* @since 3.0.4 The default $max_char_length has been increased from 155 to 300.
* @staticvar array $excerpt_cache Holds the excerpt
* @staticvar array $excerptlength_cache Holds the excerpt length
*
Expand All @@ -823,7 +914,7 @@ public function generate_description_title( $id = '', $term = '', $page_on_front
* @param int $max_char_length The maximum excerpt char length.
* @return string $excerpt The excerpt, not escaped.
*/
public function generate_excerpt( $page_id, $term = '', $max_char_length = 155 ) {
public function generate_excerpt( $page_id, $term = '', $max_char_length = 300 ) {

static $excerpt_cache = array();
static $excerptlength_cache = array();
Expand Down
81 changes: 81 additions & 0 deletions inc/classes/generate-title.class.php
Expand Up @@ -41,6 +41,87 @@ protected function __construct() {
parent::__construct();
}

/**
* Returns the Twitter meta title. Falls back to Open Graph title.
*
* @since 3.0.4
* @uses $this->get_open_graph_title()
*
* @param int|null $id The post or term ID. Falls back to queried ID.
* @param bool $escape Whether to escape the title.
* @return string Twitter Title.
*/
public function get_twitter_title( $id = null, $escape = true ) {

if ( is_null( $id ) )
$id = $this->get_the_real_ID();

$title = $this->get_custom_field( '_twitter_title', $id )
?: $this->get_open_graph_title( $id, false );

return $escape ? $this->escape_title( $title ) : $title;
}

/**
* Returns the Open Graph meta title. Falls back to meta title.
*
* @since 3.0.4
* @uses $this->get_generated_open_graph_title()
*
* @param int|null $id The post or term ID. Falls back to queried ID.
* @param bool $escape Whether to escape the title.
* @return string Open Graph Title.
*/
public function get_open_graph_title( $id = null, $escape = true ) {

if ( is_null( $id ) )
$id = $this->get_the_real_ID();

$title = $this->get_custom_field( '_open_graph_title', $id )
?: $this->get_generated_open_graph_title( $id, false );

return $escape ? $this->escape_title( $title ) : $title;
}

/**
* Returns the autogenerated open graph meta title. Falls back to meta title.
*
* @since 3.0.4
* @uses $this->get_generated_open_graph_title()
*
* @param int|null $id The post or term ID. Falls back to queried ID.
* @param bool $escape Whether to escape the title.
* @return string Autogenerated Twitter Title.
*/
public function get_generated_twitter_title( $id = null, $escape = true ) {
return $this->get_generated_open_graph_title( $id, $escape );
}

/**
* Returns the autogenerated open graph meta title. Falls back to meta title.
*
* @since 3.0.4
* @uses $this->build_title()
* @staticvar array $cache
*
* @param int|null $id The post or term ID. Falls back to queried ID.
* @param bool $escape Whether to escape the title.
* @return string Autogenerated Open Graph Title.
*/
public function get_generated_open_graph_title( $id = null, $escape = true ) {

if ( is_null( $id ) )
$id = $this->get_the_real_ID();

static $cache = array();

$title = isset( $cache[ $id ] )
? $cache[ $id ]
: $cache[ $id ] = $this->build_title( '', '', array( 'meta' => true, 'term_id' => $id, 'escape' => false ) );

return $escape ? $this->escape_title( $title ) : $title;
}

/**
* Gets the title. Main function.
* Always use this function for the title unless you're absolutely sure what you're doing.
Expand Down
15 changes: 15 additions & 0 deletions inc/classes/inpost.class.php
Expand Up @@ -418,17 +418,30 @@ public function _include_primary_term_selector_template() {
* Do not use. It will take a little too much time to perfect this.
*
* @since 2.9.0
* @since 3.0.4 Added caching.
* @access private
* @staticvar $cache
* @ignore
* @todo Remove and refactor caller.
*
* @param string $tit_len_parsed. Passed by reference.
* @param string $doctitle_placeholder. Passed by reference.
* @param string $desc_len_parsed. Passed by reference.
* @param string $description_placeholder. Passed by reference.
* @return void
*/
public function _get_inpost_general_tab_vars( &$tit_len_parsed, &$doctitle_placeholder, &$desc_len_parsed, &$description_placeholder ) {

static $cache = array();

if ( ! empty( $cache ) ) {
//! Overwrites variables passed by reference via variable variables.
foreach ( $cache as $k => $v ) {
$$k = $v;
}
return;
}

$post_id = $this->get_the_real_ID();
$is_static_frontpage = $this->is_static_frontpage( $post_id );

Expand Down Expand Up @@ -551,5 +564,7 @@ public function _get_inpost_general_tab_vars( &$tit_len_parsed, &$doctitle_place
*/
$doctitle_placeholder = $generated_doctitle;
$description_placeholder = $generated_description;

$cache = compact( 'tit_len_parsed', 'doctitle_placeholder', 'desc_len_parsed', 'description_placeholder' );
}
}

0 comments on commit 60609cb

Please sign in to comment.