WPSEO_Sitemap_Cache_Data

Sitemap Cache Data object, manages sitemap data stored in cache.

Defined (1)

The class is defined in the following location(s).

/inc/sitemaps/class-sitemap-cache-data.php  
  1. class WPSEO_Sitemap_Cache_Data implements WPSEO_Sitemap_Cache_Data_Interface, Serializable { 
  2.  
  3. /** @var string Sitemap XML data. */ 
  4. private $sitemap = ''; 
  5.  
  6. /** @var string Status of the sitemap, usable or not. */ 
  7. private $status = self::UNKNOWN; 
  8.  
  9. /** 
  10. * Set the sitemap XML data 
  11. * @param string $sitemap XML Content of the sitemap. 
  12. */ 
  13. public function set_sitemap( $sitemap ) { 
  14.  
  15. if ( ! is_string( $sitemap ) ) { 
  16. $sitemap = ''; 
  17.  
  18. $this->sitemap = $sitemap; 
  19.  
  20. /** 
  21. * Empty sitemap is not usable. 
  22. */ 
  23. if ( ! empty( $sitemap ) ) { 
  24. $this->set_status( self::OK ); 
  25. else { 
  26. $this->set_status( self::ERROR ); 
  27.  
  28. /** 
  29. * Set the status of the sitemap, is it usable. 
  30. * @param bool|string $valid Is the sitemap valid or not. 
  31. * @return void 
  32. */ 
  33. public function set_status( $valid ) { 
  34.  
  35. if ( self::OK === $valid ) { 
  36. $this->status = self::OK; 
  37.  
  38. return; 
  39.  
  40. if ( self::ERROR === $valid ) { 
  41. $this->status = self::ERROR; 
  42. $this->sitemap = ''; 
  43.  
  44. return; 
  45.  
  46. $this->status = self::UNKNOWN; 
  47.  
  48. /** 
  49. * Is the sitemap usable. 
  50. * @return bool True if usable, False if bad or unknown. 
  51. */ 
  52. public function is_usable() { 
  53.  
  54. return self::OK === $this->status; 
  55.  
  56. /** 
  57. * Get the XML content of the sitemap. 
  58. * @return string The content of the sitemap. 
  59. */ 
  60. public function get_sitemap() { 
  61.  
  62. return $this->sitemap; 
  63.  
  64. /** 
  65. * Get the status of the sitemap. 
  66. * @return string Status of the sitemap, 'ok'/'error'/'unknown' 
  67. */ 
  68. public function get_status() { 
  69.  
  70. return $this->status; 
  71.  
  72. /** 
  73. * String representation of object 
  74. * @link http://php.net/manual/en/serializable.serialize.php 
  75. * @return string the string representation of the object or null 
  76. * @since 5.1.0 
  77. */ 
  78. public function serialize() { 
  79.  
  80. $data = array( 
  81. 'status' => $this->status,  
  82. 'xml' => $this->sitemap,  
  83. ); 
  84.  
  85. return serialize( $data ); 
  86.  
  87. /** 
  88. * Constructs the object 
  89. * @link http://php.net/manual/en/serializable.unserialize.php 
  90. * @param string $serialized The string representation of the object. 
  91. * @return void 
  92. * @since 5.1.0 
  93. */ 
  94. public function unserialize( $serialized ) { 
  95.  
  96. $data = unserialize( $serialized ); 
  97. $this->set_sitemap( $data['xml'] ); 
  98. $this->set_status( $data['status'] );