plugin updates
This commit is contained in:
@@ -1,151 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Values;
|
||||
|
||||
use Yoast\WP\SEO\Helpers\Image_Helper;
|
||||
use Yoast\WP\SEO\Helpers\Url_Helper;
|
||||
|
||||
/**
|
||||
* Class Images
|
||||
*
|
||||
* Value object for the Images.
|
||||
*/
|
||||
class Images {
|
||||
|
||||
/**
|
||||
* The image size.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $image_size = 'full';
|
||||
|
||||
/**
|
||||
* Holds the images that have been put out as image.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $images = [];
|
||||
|
||||
/**
|
||||
* The image helper.
|
||||
*
|
||||
* @var Image_Helper
|
||||
*/
|
||||
protected $image;
|
||||
|
||||
/**
|
||||
* The URL helper.
|
||||
*
|
||||
* @var Url_Helper
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* Images constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param Image_Helper $image The image helper.
|
||||
* @param Url_Helper $url The url helper.
|
||||
*/
|
||||
public function __construct( Image_Helper $image, Url_Helper $url ) {
|
||||
$this->image = $image;
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an image to the list by image ID.
|
||||
*
|
||||
* @param int $image_id The image ID to add.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_image_by_id( $image_id ) {
|
||||
$image = $this->image->get_attachment_image_source( $image_id, $this->image_size );
|
||||
if ( $image ) {
|
||||
$this->add_image( $image );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an image to the list by image ID.
|
||||
*
|
||||
* @param string $image_meta JSON encoded image meta.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_image_by_meta( $image_meta ) {
|
||||
$this->add_image( (array) \json_decode( $image_meta ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the images array.
|
||||
*
|
||||
* @return array The images.
|
||||
*/
|
||||
public function get_images() {
|
||||
return $this->images;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether we have images or not.
|
||||
*
|
||||
* @return bool True if we have images, false if we don't.
|
||||
*/
|
||||
public function has_images() {
|
||||
return ! empty( $this->images );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an image based on a given URL.
|
||||
*
|
||||
* @param string $url The given URL.
|
||||
*
|
||||
* @return number|null Returns the found image ID if it exists. Otherwise -1.
|
||||
* If the URL is empty we return null.
|
||||
*/
|
||||
public function add_image_by_url( $url ) {
|
||||
if ( empty( $url ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$image_id = $this->image->get_attachment_by_url( $url );
|
||||
|
||||
if ( $image_id ) {
|
||||
$this->add_image_by_id( $image_id );
|
||||
|
||||
return $image_id;
|
||||
}
|
||||
|
||||
$this->add_image( $url );
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an image to the list of images.
|
||||
*
|
||||
* @param string|array $image Image array.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_image( $image ) {
|
||||
if ( \is_string( $image ) ) {
|
||||
$image = [ 'url' => $image ];
|
||||
}
|
||||
|
||||
if ( ! \is_array( $image ) || empty( $image['url'] ) || ! \is_string( $image['url'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( $this->url->is_relative( $image['url'] ) && $image['url'][0] === '/' ) {
|
||||
$image['url'] = $this->url->build_absolute_url( $image['url'] );
|
||||
}
|
||||
|
||||
if ( \array_key_exists( $image['url'], $this->images ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->images[ $image['url'] ] = $image;
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Values\Indexables;
|
||||
|
||||
/**
|
||||
* Class Indexable_Builder_Versions
|
||||
*/
|
||||
class Indexable_Builder_Versions {
|
||||
|
||||
public const DEFAULT_INDEXABLE_BUILDER_VERSION = 1;
|
||||
|
||||
/**
|
||||
* The list of indexable builder versions defined by Yoast SEO Free.
|
||||
* If the key is not in this list, the indexable type will not be managed.
|
||||
* These numbers should be increased if one of the builders implements a new feature.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $indexable_builder_versions_by_type = [
|
||||
'date-archive' => self::DEFAULT_INDEXABLE_BUILDER_VERSION,
|
||||
'general' => self::DEFAULT_INDEXABLE_BUILDER_VERSION,
|
||||
'home-page' => 2,
|
||||
'post' => 2,
|
||||
'post-type-archive' => 2,
|
||||
'term' => 2,
|
||||
'user' => 2,
|
||||
'system-page' => self::DEFAULT_INDEXABLE_BUILDER_VERSION,
|
||||
];
|
||||
|
||||
/**
|
||||
* Provides the most recent version number for an Indexable's object type.
|
||||
*
|
||||
* @param string $object_type The Indexable type for which you want to know the most recent version.
|
||||
*
|
||||
* @return int The most recent version number for the type, or 1 if the version doesn't exist.
|
||||
*/
|
||||
public function get_latest_version_for_type( $object_type ) {
|
||||
if ( ! \array_key_exists( $object_type, $this->indexable_builder_versions_by_type ) ) {
|
||||
return self::DEFAULT_INDEXABLE_BUILDER_VERSION;
|
||||
}
|
||||
|
||||
return $this->indexable_builder_versions_by_type[ $object_type ];
|
||||
}
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Values\OAuth;
|
||||
|
||||
use Yoast\WP\SEO\Exceptions\OAuth\Tokens\Empty_Property_Exception;
|
||||
use YoastSEO_Vendor\League\OAuth2\Client\Token\AccessTokenInterface;
|
||||
|
||||
/**
|
||||
* Class OAuth_Token
|
||||
*/
|
||||
class OAuth_Token {
|
||||
|
||||
/**
|
||||
* The access token.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $access_token;
|
||||
|
||||
/**
|
||||
* The refresh token.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $refresh_token;
|
||||
|
||||
/**
|
||||
* The expiration date.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $expires;
|
||||
|
||||
/**
|
||||
* Whether or not the token has expired.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $has_expired;
|
||||
|
||||
/**
|
||||
* The timestamp at which the token was created.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $created_at;
|
||||
|
||||
/**
|
||||
* The number of times we've gotten an error trying to refresh this token.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $error_count;
|
||||
|
||||
/**
|
||||
* OAuth_Token constructor.
|
||||
*
|
||||
* @param string $access_token The access token.
|
||||
* @param string $refresh_token The refresh token.
|
||||
* @param int $expires The date and time at which the token will expire.
|
||||
* @param bool $has_expired Whether or not the token has expired.
|
||||
* @param int $created_at The timestamp of when the token was created.
|
||||
* @param int $error_count The number of times we've gotten an error trying to refresh this token.
|
||||
*
|
||||
* @throws Empty_Property_Exception Exception thrown if a token property is empty.
|
||||
*/
|
||||
public function __construct( $access_token, $refresh_token, $expires, $has_expired, $created_at, $error_count = 0 ) {
|
||||
|
||||
if ( empty( $access_token ) ) {
|
||||
throw new Empty_Property_Exception( 'access_token' );
|
||||
}
|
||||
|
||||
$this->access_token = $access_token;
|
||||
|
||||
if ( empty( $refresh_token ) ) {
|
||||
throw new Empty_Property_Exception( 'refresh_token' );
|
||||
}
|
||||
|
||||
$this->refresh_token = $refresh_token;
|
||||
|
||||
if ( empty( $expires ) ) {
|
||||
throw new Empty_Property_Exception( 'expires' );
|
||||
}
|
||||
|
||||
$this->expires = $expires;
|
||||
|
||||
if ( \is_null( $has_expired ) ) {
|
||||
throw new Empty_Property_Exception( 'has_expired' );
|
||||
}
|
||||
|
||||
$this->has_expired = $has_expired;
|
||||
$this->created_at = $created_at;
|
||||
$this->error_count = $error_count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance based on the passed response.
|
||||
*
|
||||
* @param AccessTokenInterface $response The response object to create a new instance from.
|
||||
*
|
||||
* @return OAuth_Token The token object.
|
||||
*
|
||||
* @throws Empty_Property_Exception Exception thrown if a token property is empty.
|
||||
*/
|
||||
public static function from_response( AccessTokenInterface $response ) {
|
||||
return new self(
|
||||
$response->getToken(),
|
||||
$response->getRefreshToken(),
|
||||
$response->getExpires(),
|
||||
$response->hasExpired(),
|
||||
\time()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not the token has expired.
|
||||
*
|
||||
* @return bool Whether or not the token has expired.
|
||||
*/
|
||||
public function has_expired() {
|
||||
return ( \time() >= $this->expires ) || $this->has_expired === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the object to an array.
|
||||
*
|
||||
* @return array The converted object.
|
||||
*/
|
||||
public function to_array() {
|
||||
return [
|
||||
'access_token' => $this->access_token,
|
||||
'refresh_token' => $this->refresh_token,
|
||||
'expires' => $this->expires,
|
||||
'has_expired' => $this->has_expired(),
|
||||
'created_at' => $this->created_at,
|
||||
'error_count' => $this->error_count,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Values\Open_Graph;
|
||||
|
||||
use Yoast\WP\SEO\Helpers\Open_Graph\Image_Helper as Open_Graph_Image_Helper;
|
||||
use Yoast\WP\SEO\Values\Images as Base_Images;
|
||||
|
||||
/**
|
||||
* Value object for the Open Graph Images.
|
||||
*/
|
||||
class Images extends Base_Images {
|
||||
|
||||
/**
|
||||
* The Open Graph image helper.
|
||||
*
|
||||
* @var Open_Graph_Image_Helper
|
||||
*/
|
||||
protected $open_graph_image;
|
||||
|
||||
/**
|
||||
* Sets the helpers.
|
||||
*
|
||||
* @required
|
||||
*
|
||||
* @codeCoverageIgnore - Is handled by DI-container.
|
||||
*
|
||||
* @param Open_Graph_Image_Helper $open_graph_image Image helper for Open Graph.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set_helpers( Open_Graph_Image_Helper $open_graph_image ) {
|
||||
$this->open_graph_image = $open_graph_image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the images.
|
||||
*
|
||||
* @codeCoverageIgnore - The method is empty, nothing to test.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function show() {}
|
||||
|
||||
/**
|
||||
* Adds an image to the list by image ID.
|
||||
*
|
||||
* @param int $image_id The image ID to add.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_image_by_id( $image_id ) {
|
||||
$attachment = $this->open_graph_image->get_image_by_id( $image_id );
|
||||
|
||||
if ( $attachment ) {
|
||||
$this->add_image( $attachment );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Values\Robots;
|
||||
|
||||
/**
|
||||
* Class Directive
|
||||
*/
|
||||
class Directive {
|
||||
|
||||
/**
|
||||
* Paths list.
|
||||
*
|
||||
* @var array All paths affected by this directive.
|
||||
*/
|
||||
private $paths;
|
||||
|
||||
/**
|
||||
* Sets up the path array
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->paths = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a path to the directive path list.
|
||||
*
|
||||
* @param string $path A path to add in the path list.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_path( $path ) {
|
||||
if ( ! \in_array( $path, $this->paths, true ) ) {
|
||||
$this->paths[] = $path;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all paths.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_paths() {
|
||||
return $this->paths;
|
||||
}
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Values\Robots;
|
||||
|
||||
/**
|
||||
* Class User_Agent_List
|
||||
*/
|
||||
class User_Agent_List {
|
||||
|
||||
/**
|
||||
* The list of user agents.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $user_agent_list;
|
||||
|
||||
/**
|
||||
* User Agent list constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->user_agent_list = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if given user_agent is already registered.
|
||||
*
|
||||
* @param string $user_agent The user agent identifier.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has_user_agent( $user_agent ) {
|
||||
return \array_key_exists( $user_agent, $this->user_agent_list );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user agent object. If it is not yet registered it creates it.
|
||||
*
|
||||
* @param string $user_agent The user agent identifier.
|
||||
*
|
||||
* @return User_Agent
|
||||
*/
|
||||
public function get_user_agent( $user_agent ) {
|
||||
if ( $this->has_user_agent( $user_agent ) ) {
|
||||
return $this->user_agent_list[ $user_agent ];
|
||||
}
|
||||
|
||||
$this->user_agent_list[ $user_agent ] = new User_Agent( $user_agent );
|
||||
|
||||
return $this->user_agent_list[ $user_agent ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of user agents.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_user_agents() {
|
||||
return $this->user_agent_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all disallow directives by user agent.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_disallow_directives() {
|
||||
$directives = [];
|
||||
foreach ( $this->user_agent_list as $user_agent ) {
|
||||
$directives[ $user_agent->get_user_agent() ] = $user_agent->get_disallow_paths();
|
||||
}
|
||||
|
||||
return $directives;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all sallow directives by user agent.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_allow_directives() {
|
||||
$directives = [];
|
||||
foreach ( $this->user_agent_list as $user_agent ) {
|
||||
$directives[ $user_agent->get_user_agent() ] = $user_agent->get_allow_paths();
|
||||
}
|
||||
|
||||
return $directives;
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Values\Robots;
|
||||
|
||||
/**
|
||||
* Class Directive
|
||||
*/
|
||||
class User_Agent {
|
||||
|
||||
/**
|
||||
* The user agent identifier.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $user_agent;
|
||||
|
||||
/**
|
||||
* All directives that are allowed for this user agent.
|
||||
*
|
||||
* @var Directive
|
||||
*/
|
||||
private $allow_directive;
|
||||
|
||||
/**
|
||||
* All directives that are disallowed for this user agent.
|
||||
*
|
||||
* @var Directive
|
||||
*/
|
||||
private $disallow_directive;
|
||||
|
||||
/**
|
||||
* Constructor of the user agent value object.
|
||||
*
|
||||
* @param string $user_agent The user agent identifier.
|
||||
*/
|
||||
public function __construct( $user_agent ) {
|
||||
$this->user_agent = $user_agent;
|
||||
$this->allow_directive = new Directive();
|
||||
$this->disallow_directive = new Directive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user agent identifier.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_user_agent() {
|
||||
return $this->user_agent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a path to the directive object.
|
||||
*
|
||||
* @param string $path The path to add to the disallow directive.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_disallow_directive( $path ) {
|
||||
$this->disallow_directive->add_path( $path );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a path to the directive object.
|
||||
*
|
||||
* @param string $path The path to add to the allow directive.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_allow_directive( $path ) {
|
||||
$this->allow_directive->add_path( $path );
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all disallow paths for this user agent.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_disallow_paths() {
|
||||
return $this->disallow_directive->get_paths();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all sallow paths for this user agent.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_allow_paths() {
|
||||
return $this->allow_directive->get_paths();
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Yoast\WP\SEO\Values\Twitter;
|
||||
|
||||
use Yoast\WP\SEO\Helpers\Twitter\Image_Helper as Twitter_Image_Helper;
|
||||
use Yoast\WP\SEO\Values\Images as Base_Images;
|
||||
|
||||
/**
|
||||
* Value object for the twitter Images.
|
||||
*/
|
||||
class Images extends Base_Images {
|
||||
|
||||
/**
|
||||
* The twitter image helper.
|
||||
*
|
||||
* @var Twitter_Image_Helper
|
||||
*/
|
||||
protected $twitter_image;
|
||||
|
||||
/**
|
||||
* Sets the helpers.
|
||||
*
|
||||
* @required
|
||||
*
|
||||
* @codeCoverageIgnore - Is handled by DI-container.
|
||||
*
|
||||
* @param Twitter_Image_Helper $twitter_image Image helper for twitter.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set_helpers( Twitter_Image_Helper $twitter_image ) {
|
||||
$this->twitter_image = $twitter_image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an image to the list by image ID.
|
||||
*
|
||||
* @param int $image_id The image ID to add.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function add_image_by_id( $image_id ) {
|
||||
$attachment = $this->twitter_image->get_by_id( $image_id );
|
||||
|
||||
if ( $attachment ) {
|
||||
$this->add_image( $attachment );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user