/** * 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; }
/** * Displays an editor to edit an existing blog entry or preview it before saving changes * * @access public * @param string $action "preview" or empty(optional, empty by default) * @param int $id * @return string XHTML template content */ function EditEntry($action = '', $id = null) { $names = array('id', 'action'); $get = jaws()->request->fetch($names, 'get'); $names = array('allow_comments', 'edit_advanced'); $post = jaws()->request->fetch($names, 'post'); $id = !is_null($id) ? $id : $get['id']; $pModel = $this->gadget->model->load('Posts'); $cModel = $this->gadget->model->load('Categories'); $entry = $pModel->GetEntry($id); if (Jaws_Error::IsError($entry)) { Jaws_Error::Fatal('Post not found', __FILE__, __LINE__); } if ($GLOBALS['app']->Session->GetAttribute('user') != $entry['user_id']) { $this->gadget->CheckPermission('ModifyOthersEntries'); } $this->AjaxMe('script.js'); $tpl = $this->gadget->template->loadAdmin('Entry.html'); $tpl->SetBlock('edit_entry'); $tpl->SetVariable('base_script', BASE_SCRIPT); // Header $action = isset($get['action']) ? $get['action'] : null; $tpl->SetVariable('menubar', $this->MenuBar($action)); // Title $tpl->SetVariable('title', _t('GLOBAL_TITLE')); $tpl->SetVariable('action', 'EditEntry'); $tpl->SetVariable('id', $id); $titleEntry =& Piwi::CreateWidget('Entry', 'title', $entry['title']); $titleEntry->SetStyle('width: 750px'); $tpl->SetVariable('title_field', $titleEntry->Get()); // Image $imageUrl = $GLOBALS['app']->getSiteURL('/gadgets/Blog/Resources/images/no-image.gif'); if (!empty($entry['image'])) { $imageUrl = $GLOBALS['app']->getDataURL() . 'blog/images/' . $entry['image']; } $blogImage =& Piwi::CreateWidget('Image', $imageUrl); $blogImage->SetID('blog_image'); $tpl->SetVariable('blog_image', $blogImage->Get()); $imageFile =& Piwi::CreateWidget('FileEntry', 'image_file', ''); $imageFile->SetID('image_file'); $imageFile->SetSize(1); $imageFile->SetStyle('width:110px; padding:0;'); $imageFile->AddEvent(ON_CHANGE, 'previewImage(this);'); $tpl->SetVariable('upload_image', $imageFile->Get()); $button =& Piwi::CreateWidget('Button', 'btn_upload', '', STOCK_ADD); $tpl->SetVariable('btn_upload', $button->Get()); $button =& Piwi::CreateWidget('Button', 'btn_remove', '', STOCK_DELETE); $button->AddEvent(ON_CLICK, 'removeImage()'); $tpl->SetVariable('btn_remove', $button->Get()); // Category $catChecks =& Piwi::CreateWidget('CheckButtons', 'categories', 'vertical'); $categories = $cModel->GetCategories(); if (!Jaws_Error::IsError($categories)) { foreach ($categories as $a) { if ($this->gadget->GetPermission('CategoryManage', $a['id'])) { $catChecks->AddOption($a['name'], $a['id']); } } } $catDefault = array(); if (!Jaws_Error::isError($entry['categories'])) { foreach ($entry['categories'] as $cat) { if (!$this->gadget->GetPermission('CategoryManage', $cat['id'])) { return Jaws_HTTPError::Get(403); } $catDefault[] = $cat['id']; } } $catChecks->SetDefault($catDefault); $catChecks->SetColumns(3); $tpl->SetVariable('category', _t('GLOBAL_CATEGORY')); $tpl->SetVariable('category_field', $catChecks->Get()); // for compatibility with old versions $more_pos = Jaws_UTF8::strpos($entry['text'], '[more]'); if ($more_pos !== false) { $entry['summary'] = Jaws_UTF8::substr($entry['text'], 0, $more_pos); $entry['text'] = Jaws_UTF8::str_replace('[more]', '', $entry['text']); } // Summary $tpl->SetVariable('lbl_summary', _t('BLOG_ENTRY_SUMMARY')); $summary =& $GLOBALS['app']->LoadEditor('Blog', 'summary_block', $entry['summary'], false); $summary->setId('summary_block'); $summary->TextArea->SetRows(8); $summary->TextArea->SetStyle('width: 750px;'); $summary->SetWidth('96%'); $tpl->SetVariable('summary', $summary->Get()); // Body $tpl->SetVariable('text', _t('BLOG_BODY')); $editor =& $GLOBALS['app']->LoadEditor('Blog', 'text_block', $entry['text'], false); $editor->setId('text_block'); $editor->TextArea->SetRows(12); $editor->TextArea->SetStyle('width: 100%;'); $editor->SetWidth('96%'); $tpl->SetVariable('editor', $editor->Get()); // Allow Comments if (isset($post['allow_comments'])) { $allow = true; } else { if (isset($entry['allow_comments']) && $entry['allow_comments'] === true) { $allow = true; } else { $allow = false; } } $comments =& Piwi::CreateWidget('CheckButtons', 'allow_comments'); $comments->AddOption(_t('BLOG_ALLOW_COMMENTS'), 'comments', 'allow_comments', $allow); $tpl->SetVariable('allow_comments_field', $comments->Get()); // Status $tpl->SetVariable('status', _t('GLOBAL_STATUS')); $entry['published'] = $entry['published'] === true ? 1 : 0; $statData = $entry['published']; $statCombo =& Piwi::CreateWidget('Combo', 'published'); $statCombo->AddOption(_t('BLOG_DRAFT'), '0'); $statCombo->AddOption(_t('BLOG_PUBLISHED'), '1'); $statCombo->SetDefault($statData); if (!$this->gadget->GetPermission('PublishEntries')) { $statCombo->SetEnabled(false); } $tpl->SetVariable('status_field', $statCombo->Get()); // Save $tpl->SetVariable('missing_title', _t('BLOG_MISSING_TITLE')); $saveButton =& Piwi::CreateWidget('Button', 'save', _t('BLOG_UPDATE'), STOCK_SAVE); $saveButton->SetSubmit(); $tpl->SetVariable('save_button', $saveButton->Get()); // Preview // TODO: We need a different stock icon for this. $previewButton =& Piwi::CreateWidget('Button', 'preview', _t('GLOBAL_PREVIEW'), STOCK_PRINT_PREVIEW); $previewButton->SetID('preview_button'); $previewButton->AddEvent(ON_CLICK, "javascript: parseText(this.form);"); $tpl->SetVariable('preview_button', $previewButton->Get()); $tpl->SetBlock('edit_entry/advanced'); $advancedDefault = false; if (isset($post['edit_advanced'])) { $advancedDefault = true; $tpl->SetVariable('advanced_style', 'display: inline;'); } else { $tpl->SetVariable('advanced_style', 'display: none;'); } $editAdvancedchk =& Piwi::CreateWidget('CheckButtons', 'edit_advanced'); $editAdvancedchk->SetID('advanced_toggle'); $editAdvancedchk->AddOption(_t('BLOG_ADVANCED_MODE'), 'advanced', false, $advancedDefault); $editAdvancedchk->AddEvent(ON_CLICK, 'toggleAdvanced(this.checked);'); $tpl->SetVariable('advanced_field', $editAdvancedchk->Get()); $tpl->SetVariable('timestamp_label', _t('BLOG_EDIT_TIMESTAMP')); $tsChk =& Piwi::CreateWidget('CheckButtons', 'edit_timestamp'); $tsChk->AddOption('', 'yes', 'edit_timestamp', false); $tsChk->AddEvent(ON_CLICK, 'toggleUpdate(this.checked);'); $tpl->SetVariable('timestamp_check', $tsChk->Get()); $objDate = Jaws_Date::getInstance(); $pubTime = $objDate->Format($entry['publishtime'], 'Y-m-d H:i:s'); $pubdate =& Piwi::CreateWidget('DatePicker', 'pubdate', $pubTime); $pubdate->SetId('pubdate'); $pubdate->showTimePicker(true); $pubdate->setDateFormat('%Y-%m-%d %H:%M:%S'); $pubdate->setLanguageCode($this->gadget->registry->fetch('admin_language', 'Settings')); $pubdate->setCalType($this->gadget->registry->fetch('calendar', 'Settings')); $tpl->SetVariable('pubdate', $pubdate->Get()); $tpl->SetVariable('fasturl', _t('BLOG_FASTURL')); $fastUrlData = $entry['fast_url']; $fastUrlEntry =& Piwi::CreateWidget('Entry', 'fasturl', $fastUrlData); $fastUrlEntry->SetId('fasturl'); $fastUrlEntry->SetStyle('width: 100%'); $tpl->SetVariable('fasturl_field', $fastUrlEntry->Get()); $tpl->SetVariable('meta_keywords_label', _t('GLOBAL_META_KEYWORDS')); $metaKeywords =& Piwi::CreateWidget('Entry', 'meta_keywords', $entry['meta_keywords']); $metaKeywords->SetStyle('width: 100%;'); $tpl->SetVariable('meta_keywords', $metaKeywords->Get()); $tpl->SetVariable('meta_desc_label', _t('GLOBAL_META_DESCRIPTION')); $metaDesc =& Piwi::CreateWidget('Entry', 'meta_desc', $entry['meta_description']); $metaDesc->SetStyle('width: 100%;'); $tpl->SetVariable('meta_desc', $metaDesc->Get()); if (Jaws_Gadget::IsGadgetInstalled('Tags')) { $tpl->SetBlock('edit_entry/advanced/tags'); $tpl->SetVariable('tags_label', _t('GLOBAL_TAGS')); $postTags = implode(', ', $entry['tags']); $tags =& Piwi::CreateWidget('Entry', 'tags', $postTags); $tags->SetStyle('width: 100%;'); $tpl->SetVariable('tags', $tags->Get()); $tpl->ParseBlock('edit_entry/advanced/tags'); } // Trackback if ($this->gadget->registry->fetch('trackback') == 'true') { $tpl->SetBlock('edit_entry/advanced/trackback'); $tpl->SetVariable('trackback_to', _t('BLOG_TRACKBACK')); $tb =& Piwi::CreateWidget('TextArea', 'trackback_to', $entry['trackbacks']); $tb->SetId('trackback_to'); $tb->SetRows(4); $tb->SetColumns(30); // TODO: Remove this nasty hack, and replace it with some padding in the template. $tb->SetStyle('width: 99%; direction: ltr; white-space: nowrap;'); $tpl->SetVariable('trackbackTextArea', $tb->Get()); $tpl->ParseBlock('edit_entry/advanced/trackback'); } $tpl->ParseBlock('edit_entry/advanced'); $tpl->ParseBlock('edit_entry'); return $tpl->Get(); }
/** * Displays the recent posts of a dynamic category * * @access public * @param int $cat Category ID * @param int $limit * @return string XHTML Template content */ function CategoryEntries($cat = null, $limit = 0) { $cModel = $this->gadget->model->load('Categories'); $pModel = $this->gadget->model->load('Posts'); if (is_null($cat)) { $title = _t('BLOG_RECENT_POSTS'); } else { $category = $cModel->GetCategory($cat); if (Jaws_Error::isError($category)) { return false; } if (array_key_exists('name', $category)) { $cat = $category['id']; $title = _t('BLOG_RECENT_POSTS_BY_CATEGORY', $category['name']); } else { $cat = null; $title = _t('BLOG_RECENT_POSTS_BY_CATEGORY'); } } $entries = $pModel->GetRecentEntries($cat, (int) $limit); if (Jaws_Error::IsError($entries) || empty($entries)) { return false; } $tpl = $this->gadget->template->load('RecentPosts.html'); $tpl->SetBlock('recent_posts'); $tpl->SetVariable('cat', empty($cat) ? '0' : $cat); $tpl->SetVariable('title', $title); $date = Jaws_Date::getInstance(); foreach ($entries as $e) { $tpl->SetBlock('recent_posts/item'); $id = empty($e['fast_url']) ? $e['id'] : $e['fast_url']; $perm_url = $this->gadget->urlMap('SingleView', array('id' => $id)); $summary = $e['summary']; $text = $e['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 $pModel->SplitEntry($e['id'], $summary, $text); } $summary = empty($summary) ? $text : $summary; $summary = $this->gadget->ParseText($summary); $text = $this->gadget->ParseText($text); if (Jaws_UTF8::trim($text) != '') { $tpl->SetBlock('recent_posts/item/read-more'); $tpl->SetVariable('url', $perm_url); $tpl->SetVariable('read_more', _t('BLOG_READ_MORE')); $tpl->ParseBlock('recent_posts/item/read-more'); } $tpl->SetVariable('url', $perm_url); $tpl->SetVariable('title', $e['title']); $tpl->SetVariable('text', $summary); $tpl->SetVariable('username', $e['username']); $tpl->SetVariable('posted_by', _t('BLOG_POSTED_BY')); $tpl->SetVariable('name', $e['nickname']); $tpl->SetVariable('author-url', $this->gadget->urlMap('ViewAuthorPage', array('id' => $e['username']))); $tpl->SetVariable('createtime', $date->Format($e['publishtime'])); $tpl->SetVariable('createtime-monthname', $date->Format($e['publishtime'], 'MN')); $tpl->SetVariable('createtime-month', $date->Format($e['publishtime'], 'm')); $tpl->SetVariable('createtime-day', $date->Format($e['publishtime'], 'd')); $tpl->SetVariable('createtime-year', $date->Format($e['publishtime'], 'Y')); $tpl->SetVariable('createtime-time', $date->Format($e['publishtime'], 'g:ia')); if (empty($e['image'])) { $tpl->SetVariable('image', _t('GLOBAL_NOIMAGE')); $tpl->SetVariable('url_image', 'data:image/png;base64,'); } else { $tpl->SetVariable('image', $e['image']); $tpl->SetVariable('url_image', $GLOBALS['app']->getDataURL() . 'blog/images/' . $e['image']); } $tpl->ParseBlock('recent_posts/item'); } $tpl->ParseBlock('recent_posts'); return $tpl->Get(); }
/** * Displays a given blog entry according to given parameters * * @access public * @param object $tpl Jaws_Template object * @param string $tpl_base_block Template block name * @param int $entry entry id * @param bool $show_summary Show post summary * @return string XHTML template content */ function ShowEntry(&$tpl, $tpl_base_block, $entry, $show_summary = true) { $tpl->SetBlock("{$tpl_base_block}/entry"); $tpl->SetVariablesArray($entry); $tpl->SetVariable('posted_by', _t('BLOG_POSTED_BY')); $tpl->SetVariable('author-url', $this->gadget->urlMap('ViewAuthorPage', array('id' => $entry['username']))); $date = Jaws_Date::getInstance(); $tpl->SetVariable('createtime-iso', $date->ToISO($entry['publishtime'])); $tpl->SetVariable('createtime', $date->Format($entry['publishtime'])); $tpl->SetVariable('createtime-monthname', $date->Format($entry['publishtime'], 'MN')); $tpl->SetVariable('createtime-monthabbr', $date->Format($entry['publishtime'], 'M')); $tpl->SetVariable('createtime-month', $date->Format($entry['publishtime'], 'm')); $tpl->SetVariable('createtime-dayname', $date->Format($entry['publishtime'], 'DN')); $tpl->SetVariable('createtime-dayabbr', $date->Format($entry['publishtime'], 'D')); $tpl->SetVariable('createtime-day', $date->Format($entry['publishtime'], 'd')); $tpl->SetVariable('createtime-year', $date->Format($entry['publishtime'], 'Y')); $tpl->SetVariable('createtime-time', $date->Format($entry['publishtime'], 'g:ia')); $tpl->SetVariable('entry-visits', _t('BLOG_ENTRY_VISITS', $entry['clicks'])); if (empty($entry['image'])) { $tpl->SetVariable('image', _t('GLOBAL_NOIMAGE')); $tpl->SetVariable('url_image', 'data:image/png;base64,'); } else { $tpl->SetVariable('image', $entry['image']); $tpl->SetVariable('url_image', $GLOBALS['app']->getDataURL() . 'blog/images/' . $entry['image']); } $id = empty($entry['fast_url']) ? $entry['id'] : $entry['fast_url']; $perm_url = $this->gadget->urlMap('SingleView', array('id' => $id)); $summary = $entry['summary']; $text = $entry['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($entry['id'], $summary, $text); } $summary = empty($summary) ? $text : $summary; $summary = $this->gadget->ParseText($summary); $text = $this->gadget->ParseText($text); if ($show_summary) { if (Jaws_UTF8::trim($text) != '') { $tpl->SetBlock("{$tpl_base_block}/entry/read-more"); $tpl->SetVariable('url', $perm_url); $tpl->SetVariable('read_more', _t('BLOG_READ_MORE')); $tpl->ParseBlock("{$tpl_base_block}/entry/read-more"); } $tpl->SetVariable('text', $summary); } else { $GLOBALS['app']->Layout->AddHeadLink($this->gadget->urlMap('Atom'), 'alternate', 'application/atom+xml', 'Atom - All'); $GLOBALS['app']->Layout->AddHeadLink($this->gadget->urlMap('RSS'), 'alternate', 'application/rss+xml', 'RSS 2.0 - All'); $tpl->SetVariable('text', empty($text) ? $summary : $text); } $tpl->SetVariable('permanent-link', $perm_url); $pos = 1; $tpl->SetVariable('posted_in', _t('BLOG_POSTED_IN')); foreach ($entry['categories'] as $cat) { $tpl->SetBlock("{$tpl_base_block}/entry/category"); $tpl->SetVariable('id', $cat['id']); $tpl->SetVariable('name', $cat['name']); $cid = empty($cat['fast_url']) ? $cat['id'] : $cat['fast_url']; $tpl->SetVariable('url', $this->gadget->urlMap('ShowCategory', array('id' => $cid))); if ($pos == count($entry['categories'])) { $tpl->SetVariable('separator', ''); } else { $tpl->SetVariable('separator', ','); } $pos++; $tpl->ParseBlock("{$tpl_base_block}/entry/category"); } $commentsCount = 0; $comments = _t('BLOG_NO_COMMENT'); if (Jaws_Gadget::IsGadgetInstalled('Comments')) { $cModel = Jaws_Gadget::getInstance('Comments')->model->load('Comments'); $commentsCount = $cModel->GetCommentsCount('Blog', 'Post', $entry['id'], '', Comments_Info::COMMENTS_STATUS_APPROVED); if (!empty($commentsCount)) { $comments = _t('BLOG_HAS_N_COMMENTS', $commentsCount); } } if ($commentsCount != 0 || $entry['allow_comments'] === true && $this->gadget->registry->fetch('allow_comments') == 'true' && $this->gadget->registry->fetch('allow_comments', 'Comments') != 'false') { $tpl_block = $show_summary ? 'comment-link' : 'comments-statistic'; $tpl->SetBlock("{$tpl_base_block}/entry/{$tpl_block}"); $tpl->SetVariable('url', $perm_url); $tpl->SetVariable('text_comments', $comments); $tpl->SetVariable('num_comments', $commentsCount); $tpl->ParseBlock("{$tpl_base_block}/entry/{$tpl_block}"); } // Show Tags if (Jaws_Gadget::IsGadgetInstalled('Tags')) { $tagsHTML = Jaws_Gadget::getInstance('Tags')->action->load('Tags'); $tagsHTML->loadReferenceTags('Blog', 'post', $entry['id'], $tpl, 'single_view/entry'); } // Show Rating if (Jaws_Gadget::IsGadgetInstalled('Rating')) { $ratingHTML = Jaws_Gadget::getInstance('Rating')->action->load('RatingTypes'); $ratingHTML->loadReferenceRating('Blog', 'post', $entry['id'], 0, $tpl, 'single_view/entry'); } $tpl->ParseBlock("{$tpl_base_block}/entry"); return $tpl->Get(); }