Habari\Plugins::act PHP Метод

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

Call to execute a plugin action
public static act ( string $hookname, mixed $param = null )
$hookname string The name of the action to execute
$param mixed Optional arguments needed for action
    public static function act($hookname, $param = null)
    {
        $args = func_get_args();
        $hookname = array_shift($args);
        if (isset(self::$hooks['action'][$hookname])) {
            foreach (self::$hooks['action'][$hookname] as $priority) {
                foreach ($priority as $action) {
                    // $action is an array of object reference
                    // and method name
                    call_user_func_array($action, $args);
                }
            }
        }
    }

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);
 }