Σ(゚Д゚;≡;゚д゚)Σ(゚Д゚;≡;゚д゚)Σ(゚Д゚;≡;゚д゚)始,故人唐宰相鲁公,🆚开府南服,余以布衣从戎。明年,别公漳水湄。后明年,公以事过张睢阳庙及颜杲卿所尝往来处,悲歌慷慨,卒不负其言而从之游。今其诗具在,可考也。😭
oauth/oauth-token.php 0000644 00000006223 15233532006 0010635 0 ustar 00 <?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,
];
}
}
open-graph/images.php 0000644 00000002205 15233532006 0010560 0 ustar 00 <?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.
*/
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 );
}
}
}
images.php 0000644 00000005420 15233532006 0006522 0 ustar 00 <?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;
}
}
indexables/indexable-builder-versions.php 0000644 00000002577 15233532006 0014632 0 ustar 00 <?php
namespace Yoast\WP\SEO\Values\Indexables;
/**
* Class Indexable_Builder_Versions
*/
class Indexable_Builder_Versions {
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 ];
}
}