<commit_before><?php
/*
 * GetItem.php
 *
 * Copyright 2014 edhelas <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 *
 *
 */

namespace Moxl\Xec\Action\Pubsub;

use Moxl\Xec\Action;
use Moxl\Stanza\Pubsub;
use Moxl\Xec\Action\Pubsub\Errors;

class GetItem extends Errors
{
    private $_to;
    private $_node;
    private $_id;
    private $_askreply;

    public function request()
    {
        $this->store();
        Pubsub::getItem($this->_to, $this->_node, $this->_id);
    }

    public function setTo($to)
    {
        $this->_to = $to;
        return $this;
    }

    public function setNode($node)
    {
        $this->_node = $node;
        return $this;
    }

    public function setId($id)
    {
        $this->_id = $id;
        return $this;
    }

    public function setAskReply($reply)
    {
        $this->_askreply = $reply;
        return $this;
    }

    public function handle($stanza, $parent = false)
    {
        $evt = new \Event();

        $to = current(explode('/',(string)$stanza->attributes()->to));
        $from = $this->_to;
        $node = $this->_node;

        if($stanza->pubsub->items->item) {
            $post = false;

            foreach($stanza->pubsub->items->item as $item) {
                if(isset($item->entry)
                &&(string)$item->entry->attributes()->xmlns == 'http://www.w3.org/2005/Atom') {
                    $p = new \modl\Postn();
                    $p->set($item, $from, false, $node);

                    $pd = new \modl\PostnDAO();
                    $pd->set($p);

                    $post = true;

                    if(is_array($this->_askreply)) {
                        $this->pack([
                            'origin' => $this->_askreply['origin'],
                            'node'   => $this->_askreply['node'],
                            'nodeid' => $this->_askreply['nodeid']]);
                        $this->deliver();
                    }
                }
            }

            //if($post) {
                $this->pack(['server' => $this->_to, 'node' => $this->_node]);
                $this->deliver();
            //}
        } else {
            $pd = new PostDelete;
            $pd->setTo($this->_to)
               ->setNode($this->_node)
               ->setId($this->_id);

            $pd->handle($stanza);
        }
    }
}<commit_msg>Re-add a removed event 'post' feature<commit_after><?php
/*
 * GetItem.php
 *
 * Copyright 2014 edhelas <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 *
 *
 */

namespace Moxl\Xec\Action\Pubsub;

use Moxl\Xec\Action;
use Moxl\Stanza\Pubsub;
use Moxl\Xec\Action\Pubsub\Errors;

class GetItem extends Errors
{
    private $_to;
    private $_node;
    private $_id;
    private $_askreply;

    public function request()
    {
        $this->store();
        Pubsub::getItem($this->_to, $this->_node, $this->_id);
    }

    public function setTo($to)
    {
        $this->_to = $to;
        return $this;
    }

    public function setNode($node)
    {
        $this->_node = $node;
        return $this;
    }

    public function setId($id)
    {
        $this->_id = $id;
        return $this;
    }

    public function setAskReply($reply)
    {
        $this->_askreply = $reply;
        return $this;
    }

    public function handle($stanza, $parent = false)
    {
        $evt = new \Event();

        $to = current(explode('/',(string)$stanza->attributes()->to));
        $from = $this->_to;
        $node = $this->_node;

        if($stanza->pubsub->items->item) {
            $post = false;

            foreach($stanza->pubsub->items->item as $item) {
                if(isset($item->entry)
                &&(string)$item->entry->attributes()->xmlns == 'http://www.w3.org/2005/Atom') {
                    $p = new \modl\Postn();
                    $p->set($item, $from, false, $node);

                    $pd = new \modl\PostnDAO();
                    $pd->set($p);

                    $post = true;

                    if(is_array($this->_askreply)) {
                        $this->pack([
                            'origin' => $this->_askreply['origin'],
                            'node'   => $this->_askreply['node'],
                            'nodeid' => $this->_askreply['nodeid']]);
                        $this->deliver();
                    } else {
                        $this->pack($p);
                        $evt->runEvent('post', $this->packet);
                    }
                }
            }

            //if($post) {
                $this->pack(['server' => $this->_to, 'node' => $this->_node]);
                $this->deliver();
            //}
        } else {
            $pd = new PostDelete;
            $pd->setTo($this->_to)
               ->setNode($this->_node)
               ->setId($this->_id);

            $pd->handle($stanza);
        }
    }
}
{'fraction_non_alphanumeric': 0.1419189492231299, 'fraction_numerical': 0.006727534839019702, 'mean_word_length': 1.6844368013757525, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 102, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6704720', 'n_tokens_mistral': 1862, 'n_tokens_neox': 1772, 'n_words': 475}