Example #1
0
 public function handle($stanza, $parent = false)
 {
     $pd = new \modl\PostnDAO();
     $pd->delete($this->_id);
     $td = new \Modl\TagDAO();
     $td->delete($this->_id);
     $this->pack(['server' => $this->_to, 'node' => $this->_node, 'id' => $this->_id]);
     $this->deliver();
 }
Example #2
0
 public function set($item, $from, $delay = false, $node = false)
 {
     if ($item->item) {
         $entry = $item->item;
     } else {
         $entry = $item;
     }
     if ($from != '') {
         $this->__set('origin', $from);
     }
     if ($node) {
         $this->__set('node', $node);
     } else {
         $this->__set('node', (string) $item->attributes()->node);
     }
     $this->__set('nodeid', (string) $entry->attributes()->id);
     if ($entry->entry->id) {
         $this->__set('nodeid', (string) $entry->entry->id);
     }
     // Get some informations on the author
     if ($entry->entry->author->name) {
         $this->__set('aname', (string) $entry->entry->author->name);
     }
     if ($entry->entry->author->uri) {
         $this->__set('aid', substr((string) $entry->entry->author->uri, 5));
     }
     if ($entry->entry->author->email) {
         $this->__set('aemail', (string) $entry->entry->author->email);
     }
     // Non standard support
     if ($entry->entry->source && $entry->entry->source->author->name) {
         $this->__set('aname', (string) $entry->entry->source->author->name);
     }
     if ($entry->entry->source && $entry->entry->source->author->uri) {
         $this->__set('aid', substr((string) $entry->entry->source->author->uri, 5));
     }
     $this->__set('title', $this->getTitle($entry->entry->title));
     // Content
     if ($entry->entry->summary && (string) $entry->entry->summary != '') {
         $summary = '<p class="summary">' . (string) $entry->entry->summary . '</p>';
     } else {
         $summary = '';
     }
     if ($entry->entry && $entry->entry->content) {
         $content = $this->getContent($entry->entry->content);
     } elseif ($summary == '') {
         $content = __('');
     } else {
         $content = '';
     }
     $content = $summary . $content;
     if ($entry->entry->updated) {
         $this->__set('updated', (string) $entry->entry->updated);
     } else {
         $this->__set('updated', gmdate(DATE_ISO8601));
     }
     if ($entry->entry->published) {
         $this->__set('published', (string) $entry->entry->published);
     } elseif ($entry->entry->updated) {
         $this->__set('published', (string) $entry->entry->updated);
     } else {
         $this->__set('published', gmdate(DATE_ISO8601));
     }
     if ($delay) {
         $this->__set('delay', $delay);
     }
     // Tags parsing
     if ($entry->entry->category) {
         $td = new \Modl\TagDAO();
         $td->delete($this->__get('nodeid'));
         if ($entry->entry->category->count() == 1 && isset($entry->entry->category->attributes()->term)) {
             $tag = new \Modl\Tag();
             $tag->nodeid = $this->__get('nodeid');
             $tag->tag = strtolower((string) $entry->entry->category->attributes()->term);
             $td->set($tag);
         } else {
             foreach ($entry->entry->category as $cat) {
                 $tag = new \Modl\Tag();
                 $tag->nodeid = $this->__get('nodeid');
                 $tag->tag = strtolower((string) $cat->attributes()->term);
                 $td->set($tag);
             }
         }
     }
     if (!isset($this->commentorigin)) {
         $this->__set('commentorigin', $this->origin);
     }
     $this->__set('content', trim($content));
     $this->contentcleaned = purifyHTML(html_entity_decode($this->content));
     $extra = false;
     // We try to extract a picture
     $xml = \simplexml_load_string('<div>' . $this->contentcleaned . '</div>');
     if ($xml) {
         $results = $xml->xpath('//img/@src');
         if (is_array($results) && !empty($results)) {
             $extra = (string) $results[0];
             if (isSmallPicture($extra)) {
                 $this->picture = $extra;
             }
         }
         $results = $xml->xpath('//video/@poster');
         if (is_array($results) && !empty($results)) {
             $extra = (string) $results[0];
             if (isSmallPicture($extra)) {
                 $this->picture = $extra;
             }
         }
     }
     $this->setAttachments($entry->entry->link, $extra);
     if ($entry->entry->geoloc) {
         if ($entry->entry->geoloc->lat != 0) {
             $this->__set('lat', (string) $entry->entry->geoloc->lat);
         }
         if ($entry->entry->geoloc->lon != 0) {
             $this->__set('lon', (string) $entry->entry->geoloc->lon);
         }
     }
     // We fill empty aid
     if ($this->isMicroblog() && empty($this->aid)) {
         $this->__set('aid', $this->origin);
     }
     // We check if this is a reply
     if ($entry->entry->{'in-reply-to'}) {
         $href = (string) $entry->entry->{'in-reply-to'}->attributes()->href;
         $arr = explode(';', $href);
         $reply = ['origin' => substr($arr[0], 5, -1), 'node' => substr($arr[1], 5), 'nodeid' => substr($arr[2], 5)];
         $this->__set('reply', serialize($reply));
     }
 }