Beispiel #1
0
function parseItem($blog, $item, $ts)
{
    if ($ts != 0 && $item->pubdate <= $ts) {
        logmsg('Zatrzymanie na wpisie: %s', StringUtils::removeAccents($item->title));
        return false;
    }
    logmsg('  - Parsowanie wpisu: %s', StringUtils::removeAccents($item->title));
    $post = new Post();
    $post->setBlog($blog);
    foreach ($item->tags as $name) {
        $tag = TagPeer::retriveByName($name, true);
        if ($post->addTag($tag)) {
            logmsg('    - Znaleziono tag: %s', $name);
        }
    }
    if ($post->hasTags()) {
        $shortened = $post->setFullContent($item->content);
        $post->setLink(htmlspecialchars($item->link));
        $post->setTitle($item->title);
        $post->setCreatedAt($item->pubdate);
        $post->setShortened($shortened);
        $post->save();
    } else {
        logmsg('    - Nie znaleziono tagow');
    }
    return true;
}
Beispiel #2
0
 public function executeRefresh()
 {
     $post = PostPeer::retrieveByPK($this->getRequestParameter('id'));
     $blog = $post->getBlog();
     $this->forward404Unless($blog->getId() == $this->getUser()->getId());
     if ($post) {
         try {
             $items = FeedParser::parse($blog->getFeed());
             foreach ($items as $item) {
                 if ($item->link == $post->getLink()) {
                     $post->removeTags();
                     foreach ($item->tags as $name) {
                         $tag = TagPeer::retriveByName($name, true);
                         $post->addTag($tag);
                     }
                     if ($post->hasTags()) {
                         $shortened = $post->setFullContent($item->content);
                         $post->setLink($item->link);
                         $post->setTitle($item->title);
                         $post->setCreatedAt($item->pubdate);
                         $post->setShortened($shortened);
                         $post->save();
                     }
                     break;
                 }
             }
             $this->setFlash('updated', 'Wpis został odświeżony.');
         } catch (Exception $e) {
             $this->setFlash('updated', 'Odswieżanie wpisu nie powiodło się.');
         }
     }
     $this->redirect('ucp/index');
 }