Exemplo n.º 1
0
 /**
  * Create ATOM struct of a given category
  *
  * @access  public
  * @param   int     $category   Category ID
  * @param   string  $feed_type  OPTIONAL feed type
  * @return  mixed   Can return the Atom Object or Jaws_Error on error
  */
 function GetCategoryAtomStruct($category, $feed_type = 'atom')
 {
     $model = $this->gadget->model->load('Categories');
     $catInfo = $model->GetCategory($category);
     if (Jaws_Error::IsError($catInfo)) {
         return new Jaws_Error(_t('BLOG_ERROR_GETTING_CATEGORIES_ATOMSTRUCT'));
     }
     $now = Jaws_DB::getInstance()->date();
     $blogTable = Jaws_ORM::getInstance()->table('blog');
     $blogTable->select('blog.id:integer', 'user_id:integer', 'blog_entrycat.category_id:integer', 'username', 'email', 'nickname', 'title', 'fast_url', 'summary', 'text', 'blog.publishtime', 'blog.updatetime', 'clicks:integer', 'comments:integer', 'allow_comments:boolean', 'published:boolean')->join('users', 'blog.user_id', 'users.id')->join('blog_entrycat', 'blog.id', 'blog_entrycat.entry_id');
     $blogTable->where('published', true)->and()->where('blog.publishtime', $now, '<=');
     $blogTable->and()->where('blog_entrycat.category_id', $catInfo['id']);
     $result = $blogTable->orderby('blog.publishtime desc')->fetchAll();
     if (Jaws_Error::IsError($result)) {
         return new Jaws_Error(_t('BLOG_ERROR_GETTING_CATEGORIES_ATOMSTRUCT'));
     }
     $cid = empty($catInfo['fast_url']) ? $catInfo['id'] : Jaws_XSS::filter($catInfo['fast_url']);
     $categoryAtom = new Jaws_AtomFeed();
     $siteURL = $GLOBALS['app']->GetSiteURL('/');
     $url = $this->gadget->urlMap($feed_type == 'atom' ? 'ShowAtomCategory' : 'ShowRSSCategory', array('id' => $cid), true);
     $categoryAtom->SetTitle($this->gadget->registry->fetch('site_name', 'Settings'));
     $categoryAtom->SetLink($url);
     $categoryAtom->SetId($siteURL);
     $categoryAtom->SetTagLine($catInfo['name']);
     $categoryAtom->SetAuthor($this->gadget->registry->fetch('site_author', 'Settings'), $siteURL, $this->gadget->registry->fetch('gate_email', 'Settings'));
     $categoryAtom->SetGenerator('JAWS ' . $GLOBALS['app']->Registry->fetch('version'));
     $categoryAtom->SetCopyright($this->gadget->registry->fetch('site_copyright', 'Settings'));
     $objDate = Jaws_Date::getInstance();
     foreach ($result as $r) {
         $entry = new AtomEntry();
         $entry->SetTitle($r['title']);
         $post_id = empty($r['fast_url']) ? $r['id'] : $r['fast_url'];
         $url = $this->gadget->urlMap('SingleView', array('id' => $post_id), true);
         $entry->SetLink($url);
         $entry->SetId($url);
         $summary = $r['summary'];
         $text = $r['text'];
         // for compatibility with old versions
         $more_pos = Jaws_UTF8::strpos($text, '[more]');
         if ($more_pos !== false) {
             $summary = Jaws_UTF8::substr($text, 0, $more_pos);
             $text = Jaws_UTF8::str_replace('[more]', '', $text);
             // Update this entry to split summary and body of post
             $model = $this->gadget->model->load('Posts');
             $model->SplitEntry($r['id'], $summary, $text);
         }
         $summary = empty($summary) ? $text : $summary;
         $summary = $this->gadget->ParseText($summary);
         $text = $this->gadget->ParseText($text);
         $entry->SetSummary($summary, 'html');
         $entry->SetContent($text, 'html');
         $email = $r['email'];
         $entry->SetAuthor($r['nickname'], $categoryAtom->Link->HRef, $email);
         $entry->SetPublished($objDate->ToISO($r['publishtime']));
         $entry->SetUpdated($objDate->ToISO($r['updatetime']));
         $categoryAtom->AddEntry($entry);
         if (!isset($last_modified)) {
             $last_modified = $r['updatetime'];
         }
     }
     if (isset($last_modified)) {
         $categoryAtom->SetUpdated($objDate->ToISO($last_modified));
     } else {
         $categoryAtom->SetUpdated($objDate->ToISO(date('Y-m-d H:i:s')));
     }
     return $categoryAtom;
 }
Exemplo n.º 2
0
Arquivo: Feeds.php Projeto: uda/jaws
 /**
  * Create ATOM struct of recent comments
  *
  * @access  private
  * @param   string  $gadget     Gadget name
  * @param   string  $action     Action name
  * @param   int     $reference  Reference Id
  * @param   string  $feed_type feed type
  * @return  object  Can return the Atom Object
  */
 function GetRecentCommentsAtomStruct($gadget, $action = null, $reference = null, $feed_type = 'atom')
 {
     $max_title_size = 80;
     $cModel = $this->gadget->model->load('Comments');
     $comments = $cModel->GetComments($gadget, $action, $reference, '', array(Comments_Info::COMMENTS_STATUS_APPROVED));
     if (Jaws_Error::IsError($comments)) {
         return new Jaws_Error(_t('COMMENTS_ERROR_GETTING_COMMENTS_ATOMSTRUCT'));
     }
     $commentAtom = new Jaws_AtomFeed();
     $siteURL = $GLOBALS['app']->GetSiteURL('/');
     $params = array('gadgetname' => $gadget);
     if (!empty($action)) {
         $params['actionname'] = $action;
     }
     if (!empty($reference)) {
         $params['reference'] = $reference;
     }
     $url = $this->gadget->urlMap($feed_type == 'atom' ? 'RecentCommentsAtom' : 'RecentCommentsRSS', $params, true);
     $commentAtom->SetTitle($this->gadget->registry->fetch('site_name', 'Settings'));
     $commentAtom->SetLink($url);
     $commentAtom->SetId($siteURL);
     $commentAtom->SetAuthor($this->gadget->registry->fetch('site_author', 'Settings'), $GLOBALS['app']->GetSiteURL('/'), $this->gadget->registry->fetch('gate_email', 'Settings'));
     $commentAtom->SetGenerator('JAWS ' . $GLOBALS['app']->Registry->fetch('version'));
     $commentAtom->SetCopyright($this->gadget->registry->fetch('site_copyright', 'Settings'));
     $commentAtom->SetTagLine(_t('COMMENTS_RECENT_COMMENTS', _t(strtoupper($gadget) . '_TITLE')));
     $objDate = Jaws_Date::getInstance();
     $site = preg_replace('/(.*)\\/.*/i', '\\1', $commentAtom->Link->HRef);
     foreach ($comments as $c) {
         $entry_id = $c['reference'];
         $entry = new AtomEntry();
         $entry->SetTitle(Jaws_UTF8::strlen($c['msg_txt']) >= $max_title_size ? Jaws_UTF8::substr($c['msg_txt'], 0, $max_title_size) . '...' : $c['msg_txt']);
         $entry->SetId("urn:gadget:{$gadget}:action:{$action}:reference:{$reference}:comment:{$c['id']}");
         switch ($gadget) {
             case 'Blog':
                 // So we can use the UrlMapping feature.
                 $url = $GLOBALS['app']->Map->GetURLFor('Blog', 'SingleView', array('id' => $entry_id), true);
                 $url = $url . htmlentities('#comment' . $c['id']);
                 $entry->SetLink($url);
                 break;
             case 'Phoo':
                 $url = $GLOBALS['app']->Map->GetURLFor('Phoo', 'ViewImage', array('id' => $entry_id), true);
                 $url = $url . htmlentities('#comment' . $c['id']);
                 $entry->SetLink($url);
                 break;
             case 'Shoutbox':
                 $url = $GLOBALS['app']->Map->GetURLFor('Shoutbox', 'Comments', array(), true);
                 $url = $url . htmlentities('#comment' . $c['id']);
                 $entry->SetLink($url);
                 break;
         }
         $content = Jaws_String::AutoParagraph($c['msg_txt']);
         $entry->SetSummary($content, 'html');
         $entry->SetContent($content, 'html');
         $entry->SetAuthor($c['name'], $commentAtom->Link->HRef, $c['email']);
         $entry->SetPublished($objDate->ToISO($c['insert_time']));
         $entry->SetUpdated($objDate->ToISO($c['insert_time']));
         $commentAtom->AddEntry($entry);
         if (!isset($last_modified)) {
             $last_modified = $c['insert_time'];
         }
     }
     if (isset($last_modified)) {
         $commentAtom->SetUpdated($objDate->ToISO($last_modified));
     } else {
         $commentAtom->SetUpdated($objDate->ToISO(date('Y-m-d H:i:s')));
     }
     return $commentAtom;
 }