/** * Create ATOM struct * * @access public * @param string $feed_type OPTIONAL feed type * @return mixed Can return the Atom Object or Jaws_Error on error */ function GetAtomStruct($feed_type = 'atom') { if (isset($this->_Atom) && is_array($this->_Atom->Entries) && count($this->_Atom->Entries) > 0) { return $this->_Atom; } $this->_Atom = new Jaws_AtomFeed(); $now = Jaws_DB::getInstance()->date(); $limit = $this->gadget->registry->fetch('xml_limit'); $blogTable = Jaws_ORM::getInstance()->table('blog'); $blogTable->select('blog.id:integer', 'user_id:integer', 'username', 'email', 'nickname', 'title', 'summary', 'text', 'fast_url', 'blog.publishtime', 'blog.updatetime', 'clicks:integer', 'comments:integer', 'allow_comments:boolean', 'published:boolean', 'categories')->join('users', 'blog.user_id', 'users.id'); $blogTable->where('blog.published', true)->and()->where('blog.publishtime', $now, '<='); $result = $blogTable->orderBy('blog.publishtime desc')->limit($limit)->fetchAll(); if (Jaws_Error::IsError($result)) { return new Jaws_Error(_t('BLOG_ERROR_GETTING_ATOMSTRUCT')); } // Check dynamic ACL foreach ($result as $key => $entry) { foreach (explode(",", $entry['categories']) as $cat) { if (!$this->gadget->GetPermission('CategoryAccess', $cat)) { unset($result[$key]); } } } $siteURL = $GLOBALS['app']->GetSiteURL('/'); $url = $this->gadget->urlMap($feed_type == 'atom' ? 'Atom' : 'RSS', array(), true); $this->_Atom->SetTitle($this->gadget->registry->fetch('site_name', 'Settings')); $this->_Atom->SetLink($url); $this->_Atom->SetId($siteURL); $this->_Atom->SetTagLine($this->gadget->registry->fetch('site_slogan', 'Settings')); $this->_Atom->SetAuthor($this->gadget->registry->fetch('site_author', 'Settings'), $GLOBALS['app']->GetSiteURL(), $this->gadget->registry->fetch('gate_email', 'Settings')); $this->_Atom->SetGenerator('JAWS ' . $GLOBALS['app']->Registry->fetch('version')); $this->_Atom->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'], $this->_Atom->Link->HRef, $email); $entry->SetPublished($objDate->ToISO($r['publishtime'])); $entry->SetUpdated($objDate->ToISO($r['updatetime'])); $model = $this->gadget->model->load('Categories'); $cats = $model->GetCategoriesInEntry($r['id']); foreach ($cats as $c) { $schema = $this->gadget->urlMap('ShowCategory', array('id' => $c['id']), true); $entry->AddCategory($c['id'], $c['name'], $schema); } $this->_Atom->AddEntry($entry); if (!isset($last_modified) || $last_modified < $r['updatetime']) { $last_modified = $r['updatetime']; } } if (isset($last_modified)) { $this->_Atom->SetUpdated($objDate->ToISO($last_modified)); } else { $this->_Atom->SetUpdated($objDate->ToISO(date('Y-m-d H:i:s'))); } return $this->_Atom; }