first commit
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user