khaihihi
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* WPSEO interface file.
|
||||
*
|
||||
* @package WPSEO\Indexables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface WPSEO_Endpoint_Validator.
|
||||
*/
|
||||
interface WPSEO_Endpoint_Validator {
|
||||
|
||||
/**
|
||||
* Validates the passed request data.
|
||||
*
|
||||
* @param array $request_data The request data to validate.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function validate( $request_data );
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* WPSEO plugin file.
|
||||
*
|
||||
* @package WPSEO\Indexables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class WPSEO_Keyword_Validator.
|
||||
*/
|
||||
class WPSEO_Keyword_Validator implements WPSEO_Endpoint_Validator {
|
||||
|
||||
/**
|
||||
* Validates the keyword-related data.
|
||||
*
|
||||
* @param array $request_data The request data to validate.
|
||||
*
|
||||
* @throws WPSEO_Invalid_Argument_Exception Thrown if the keyword or the score is of an invalid value type.
|
||||
*/
|
||||
public function validate( $request_data ) {
|
||||
if ( WPSEO_Validator::key_exists( $request_data, 'keyword' ) && ! WPSEO_Validator::is_string( $request_data['keyword'] ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_string_parameter( $request_data['keyword'], 'keyword' );
|
||||
}
|
||||
|
||||
if ( WPSEO_Validator::key_exists( $request_data, 'score' ) && ! WPSEO_Validator::is_integer( $request_data['score'] ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_integer_parameter( $request_data['score'], 'score' );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* WPSEO plugin file.
|
||||
*
|
||||
* @package WPSEO\Indexables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class WPSEO_Link_Validator.
|
||||
*/
|
||||
class WPSEO_Link_Validator implements WPSEO_Endpoint_Validator {
|
||||
|
||||
/**
|
||||
* Validates the link-related data.
|
||||
*
|
||||
* @param array $request_data The request data to validate.
|
||||
*
|
||||
* @throws WPSEO_Invalid_Argument_Exception Thrown if the link-data count or incoming count is of an invalid value type.
|
||||
*/
|
||||
public function validate( $request_data ) {
|
||||
if ( WPSEO_Validator::key_exists( $request_data, 'count' ) && ! WPSEO_Validator::is_integer( $request_data['count'] ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_integer_parameter( $request_data['count'], 'count' );
|
||||
}
|
||||
|
||||
if ( WPSEO_Validator::key_exists( $request_data, 'incoming_count' ) && ! WPSEO_Validator::is_integer( $request_data['incoming_count'] ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_integer_parameter( $request_data['incoming_count'], 'incoming_count' );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* WPSEO plugin file.
|
||||
*
|
||||
* @package WPSEO\Indexables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class WPSEO_Meta_Values_Validator.
|
||||
*/
|
||||
class WPSEO_Meta_Values_Validator implements WPSEO_Endpoint_Validator {
|
||||
|
||||
/**
|
||||
* Validates the meta values data.
|
||||
*
|
||||
* @param array $request_data The request data to validate.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws WPSEO_Invalid_Argument_Exception Thrown if a field from the request data is of an invalid value type.
|
||||
*/
|
||||
public function validate( $request_data ) {
|
||||
if ( WPSEO_Validator::key_exists( $request_data, 'title' ) && ! WPSEO_Validator::is_string( $request_data['title'] ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_string_parameter( $request_data['title'], 'title' );
|
||||
}
|
||||
|
||||
if ( WPSEO_Validator::key_exists( $request_data, 'metadesc' ) && ! WPSEO_Validator::is_string( $request_data['metadesc'] ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_string_parameter( $request_data['metadesc'], 'metadesc' );
|
||||
}
|
||||
|
||||
if ( WPSEO_Validator::key_exists( $request_data, 'permalink' ) && ! WPSEO_Validator::is_string( $request_data['permalink'] ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_string_parameter( $request_data['permalink'], 'permalink' );
|
||||
}
|
||||
|
||||
if ( WPSEO_Validator::key_exists( $request_data, 'readability_score' ) && ! WPSEO_Validator::is_integer( $request_data['readability_score'] ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_integer_parameter( $request_data['readability_score'], 'readability_score' );
|
||||
}
|
||||
|
||||
if ( WPSEO_Validator::key_exists( $request_data, 'is_cornerstone' ) && ! WPSEO_Validator::is_boolean( $request_data['is_cornerstone'] ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_boolean_parameter( $request_data['is_cornerstone'], 'is_cornerstone' );
|
||||
}
|
||||
|
||||
if ( WPSEO_Validator::key_exists( $request_data, 'canonical' ) && ! WPSEO_Validator::is_string( $request_data['canonical'] ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_string_parameter( $request_data['canonical'], 'canonical' );
|
||||
}
|
||||
|
||||
if ( WPSEO_Validator::key_exists( $request_data, 'breadcrumb_title' ) && ! WPSEO_Validator::is_string( $request_data['breadcrumb_title'] ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_string_parameter( $request_data['breadcrumb_title'], 'breadcrumb_title' );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* WPSEO plugin file.
|
||||
*
|
||||
* @package WPSEO\Indexables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class WPSEO_Object_Type_Validator.
|
||||
*/
|
||||
class WPSEO_Object_Type_Validator implements WPSEO_Endpoint_Validator {
|
||||
|
||||
/**
|
||||
* Validates the object_type parameter.
|
||||
*
|
||||
* @param string $object_type The object type to validate.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws WPSEO_Invalid_Argument_Exception Thrown is the object type is invalid.
|
||||
*/
|
||||
private static function validate_type( $object_type ) {
|
||||
if ( ! in_array( $object_type, [ 'post', 'term' ], true ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_type( $object_type );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates whether the passed subtype is valid or not.
|
||||
*
|
||||
* @param string $type The type to validate.
|
||||
* @param string $subtype The subtype to validate.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws WPSEO_Invalid_Argument_Exception Thrown if the subtype doesn't exist for the given type.
|
||||
*/
|
||||
private static function validate_subtype( $type, $subtype ) {
|
||||
if ( $type === 'post' && ! post_type_exists( $subtype ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_subtype( $subtype, $type );
|
||||
}
|
||||
|
||||
if ( $type === 'term' && ! taxonomy_exists( $subtype ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_subtype( $subtype, $type );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the object type-related data.
|
||||
*
|
||||
* @param array $request_data The request data to validate.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws WPSEO_Invalid_Argument_Exception Thrown if the type or subtype are invalid.
|
||||
*/
|
||||
public function validate( $request_data ) {
|
||||
if ( WPSEO_Validator::key_exists( $request_data, 'object_type' ) ) {
|
||||
self::validate_type( $request_data['object_type'] );
|
||||
}
|
||||
|
||||
if ( WPSEO_Validator::key_exists( $request_data, 'object_subtype' ) ) {
|
||||
self::validate_subtype( $request_data['object_type'], $request_data['object_subtype'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* WPSEO plugin file.
|
||||
*
|
||||
* @package WPSEO\Indexables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class WPSEO_OpenGraph_Validator.
|
||||
*/
|
||||
class WPSEO_OpenGraph_Validator implements WPSEO_Endpoint_Validator {
|
||||
|
||||
/**
|
||||
* Validates the OpenGraph-related data.
|
||||
*
|
||||
* @param array $request_data The request data to validate.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws WPSEO_Invalid_Argument_Exception Thrown if one of the OpenGraph properties is of an invalid value type.
|
||||
*/
|
||||
public function validate( $request_data ) {
|
||||
if ( WPSEO_Validator::key_exists( $request_data, 'og_title' ) && ! WPSEO_Validator::is_string( $request_data['og_title'] ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_string_parameter( $request_data['og_title'], 'og_title' );
|
||||
}
|
||||
|
||||
if ( WPSEO_Validator::key_exists( $request_data, 'og_description' ) && ! WPSEO_Validator::is_string( $request_data['og_description'] ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_string_parameter( $request_data['og_description'], 'og_description' );
|
||||
}
|
||||
|
||||
if ( WPSEO_Validator::key_exists( $request_data, 'og_image' ) && ! WPSEO_Validator::is_string( $request_data['og_image'] ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_string_parameter( $request_data['og_image'], 'og_image' );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* WPSEO plugin file.
|
||||
*
|
||||
* @package WPSEO\Indexables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class WPSEO_Robots_Validator.
|
||||
*/
|
||||
class WPSEO_Robots_Validator implements WPSEO_Endpoint_Validator {
|
||||
|
||||
/**
|
||||
* The robots keys to validate.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $robots_to_validate = [
|
||||
'is_robots_nofollow',
|
||||
'is_robots_noarchive',
|
||||
'is_robots_noimageindex',
|
||||
'is_robots_nosnippet',
|
||||
'is_robots_noindex',
|
||||
];
|
||||
|
||||
/**
|
||||
* Validates the passed request data.
|
||||
*
|
||||
* @param array $request_data The request data to validate.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws WPSEO_Invalid_Argument_Exception Thrown if the robots values are not a boolean type.
|
||||
*/
|
||||
public function validate( $request_data ) {
|
||||
foreach ( $this->robots_to_validate as $item ) {
|
||||
if ( ! WPSEO_Validator::key_exists( $request_data, $item ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! is_null( $request_data[ $item ] ) && ! WPSEO_Validator::is_boolean( $request_data[ $item ] ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_boolean_parameter( $request_data[ $item ], $item );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* WPSEO plugin file.
|
||||
*
|
||||
* @package WPSEO\Indexables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class WPSEO_Twitter_Validator.
|
||||
*/
|
||||
class WPSEO_Twitter_Validator implements WPSEO_Endpoint_Validator {
|
||||
|
||||
/**
|
||||
* Validates the Twitter-related data.
|
||||
*
|
||||
* @param array $request_data The request data to validate.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws WPSEO_Invalid_Argument_Exception Thrown if one of the Twitter properties is of an invalid value type.
|
||||
*/
|
||||
public function validate( $request_data ) {
|
||||
if ( WPSEO_Validator::key_exists( $request_data, 'twitter_title' ) && ! WPSEO_Validator::is_string( $request_data['twitter_title'] ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_string_parameter( $request_data['twitter_title'], 'twitter_title' );
|
||||
}
|
||||
|
||||
if ( WPSEO_Validator::key_exists( $request_data, 'twitter_description' ) && ! WPSEO_Validator::is_string( $request_data['twitter_description'] ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_string_parameter( $request_data['twitter_description'], 'twitter_description' );
|
||||
}
|
||||
|
||||
if ( WPSEO_Validator::key_exists( $request_data, 'twitter_image' ) && ! WPSEO_Validator::is_string( $request_data['twitter_image'] ) ) {
|
||||
throw WPSEO_Invalid_Argument_Exception::invalid_string_parameter( $request_data['twitter_image'], 'twitter_image' );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user