Habari\Post::status PHP Метод

status() публичный статический Метод

returns the integer value of the specified post status, or false
public static status ( string | integer $name ) : integer | boolean
$name string | integer a post status name or value
Результат integer | boolean an integer or boolean false
    public static function status($name)
    {
        $statuses = Post::list_post_statuses();
        if (is_numeric($name) && false !== in_array($name, $statuses)) {
            return $name;
        }
        if (isset($statuses[MultiByte::strtolower($name)])) {
            return $statuses[MultiByte::strtolower($name)];
        }
        return false;
    }

Usage Example

Пример #1
0
 /**
  * Accepts an Atom entry for insertion as a new post.
  */
 public function post_collection()
 {
     if ($this->is_auth(true)) {
         $bxml = file_get_contents('php://input');
     }
     $xml = new SimpleXMLElement($bxml);
     $post = new Post();
     Plugins::act('atom_post_collection', $xml, $post, $this->handler_vars);
     if ((string) $xml->title != '') {
         $post->title = $xml->title;
     }
     if ((string) $xml->id != '') {
         $post->guid = $xml->id;
     }
     if ((string) $xml->content != '') {
         $post->content = (string) $xml->content;
     }
     if ((string) $xml->pubdate != '') {
         $post->pubdate = (string) $xml->pubdate;
     }
     // Save categories as tags
     $atom_ns = $xml->children('http://www.w3.org/2005/Atom');
     $categories = $atom_ns->category;
     if (!empty($categories)) {
         $terms = array();
         foreach ($categories as $category) {
             $category_attrs = $category->attributes();
             $terms[] = (string) $category_attrs['term'];
         }
         $post->tags = $terms;
     }
     if (isset($_SERVER['HTTP_SLUG'])) {
         $post->slug = $_SERVER['HTTP_SLUG'];
     }
     // Check if it's a draft (using XPath because Namespaces are easier than with SimpleXML)
     $xml->registerXPathNamespace('app', 'http://www.w3.org/2007/app');
     $draft = $xml->xpath('//app:control/app:draft');
     if (is_array($draft) && (string) $draft[0] == 'yes') {
         $post->status = Post::status('draft');
     } else {
         $post->status = Post::status('published');
     }
     $post->user_id = $this->user->id;
     $post->insert();
     header('HTTP/1.1 201 Created', true, 201);
     header('Status: 201 Created');
     header('Location: ' . URL::get('atom_entry', array('slug' => $post->slug)));
     $this->get_entry($post->slug);
 }