/** * Pingback function * * @access public */ function Pingback() { if ($this->gadget->registry->fetch('pingback') == 'true') { $pback = Jaws_Pingback::getInstance(); $response = $pback->listen(); if (is_array($response)) { //Load model $model = $this->gadget->model->load('Posts'); //We need to parse the target URI to get the post ID $GLOBALS['app']->Map->Parse($response['targetURI']); //pingbacks come from POST but JawsURL maps everything on get (that how Maps work) $postID = jaws()->request->fetch('id', 'get'); if (empty($postID)) { return; } $entry = $model->GetEntry($postID, true); if (!Jaws_Error::IsError($entry)) { $title = ''; $content = ''; $response['title'] = strip_tags($response['title']); if (empty($response['title'])) { if (empty($entry['title'])) { $title = _t('GLOBAL_RE') . _t('BLOG_PINGBACK_TITLE', $entry['title']); $content = _t('BLOG_PINGBACK_DEFAULT_COMMENT', $entry['sourceURI']); } } else { $comesFrom = '<a href="' . $response['sourceURI'] . '">' . $response['title'] . '</a>'; $content = _t('BLOG_PINGBACK_COMMENT', $comesFrom); $title = _t('GLOBAL_RE') . _t('BLOG_PINGBACK_TITLE', $response['title']); } $model->SavePingback($postID, $response['sourceURI'], $response['targetURI'], $title, $content); } } } }
/** * Updates an entry * * @access public * @param int $post_id Post ID * @param int $categories Categories array * @param string $title Title of the Entry * @param string $summary entry summary * @param string $content Content of the Entry * @param string $image Image file name * @param string $fast_url FastURL * @param string $meta_keywords Meta keywords * @param string $meta_desc Meta description * @param string $tags Tags * @param bool $allow_comments If entry should allow comments * @param bool $trackbacks * @param bool $publish If entry should be published * @param string $timestamp Entry timestamp (optional) * @param bool $autodraft Does it comes from an autodraft action? * @return mixed Returns the ID of the post or Jaws_Error on failure */ function UpdateEntry($post_id, $categories, $title, $summary, $content, $image, $fast_url, $meta_keywords, $meta_desc, $tags, $allow_comments, $trackbacks, $publish, $timestamp = null, $autoDraft = false) { $fast_url = empty($fast_url) ? $title : $fast_url; $fast_url = $this->GetRealFastUrl($fast_url, 'blog', false); $params['title'] = $title; $params['text'] = $content; $params['summary'] = $summary; $params['trackbacks'] = $trackbacks; $params['published'] = $publish; $params['allow_comments'] = $allow_comments; $params['categories'] = implode(',', $categories); $params['fast_url'] = $fast_url; $params['meta_keywords'] = $meta_keywords; $params['meta_description'] = $meta_desc; $params['updatetime'] = Jaws_DB::getInstance()->date(); if (!is_null($image)) { $params['image'] = empty($image) ? null : $image; } if (!is_bool($params['published'])) { $params['published'] = $params['published'] == '1' ? true : false; } if (!is_bool($params['allow_comments'])) { $params['allow_comments'] = $params['allow_comments'] == '1' ? true : false; } $model = $this->gadget->model->load('Posts'); $e = $model->GetEntry($post_id); if (Jaws_Error::IsError($e)) { $GLOBALS['app']->Session->PushLastResponse(_t('BLOG_ERROR_ENTRY_NOT_UPDATED'), RESPONSE_ERROR); return new Jaws_Error(_t('BLOG_ERROR_ENTRY_NOT_UPDATED')); } if ($e['published'] && !$this->gadget->GetPermission('ModifyPublishedEntries')) { $GLOBALS['app']->Session->PushLastResponse(_t('BLOG_ERROR_ENTRY_NOT_UPDATED'), RESPONSE_ERROR); return new Jaws_Error(_t('BLOG_ERROR_ENTRY_NOT_UPDATED')); } if ($GLOBALS['app']->Session->GetAttribute('user') != $e['user_id']) { if (!$this->gadget->GetPermission('ModifyOthersEntries')) { $GLOBALS['app']->Session->PushLastResponse(_t('BLOG_ERROR_ENTRY_NOT_UPDATED'), RESPONSE_ERROR); return new Jaws_Error(_t('BLOG_ERROR_ENTRY_NOT_UPDATED')); } } if (!$this->gadget->GetPermission('PublishEntries')) { $params['published'] = $e['published']; } //Current fast url changes? if ($e['fast_url'] != $fast_url && $autoDraft === false) { $fast_url = $this->GetRealFastUrl($fast_url, 'blog'); $params['fast_url'] = $fast_url; } // Switch out for the MDB2 way if (!is_bool($params['allow_comments'])) { $params['allow_comments'] = $params['allow_comments'] === 1 ? true : false; } if (!is_bool($params['published'])) { $params['published'] = $params['published'] === 1 ? true : false; } $date = Jaws_Date::getInstance(); if (!is_null($timestamp)) { // Maybe we need to not allow crazy dates, e.g. 100 years ago $timestamp = $date->ToBaseDate(preg_split('/[- :]/', $timestamp), 'Y-m-d H:i:s'); $params['publishtime'] = $GLOBALS['app']->UserTime2UTC($timestamp, 'Y-m-d H:i:s'); } $blogTable = Jaws_ORM::getInstance()->table('blog'); //Start Transaction $blogTable->beginTransaction(); $result = $blogTable->update($params)->where('id', $post_id)->exec(); if (Jaws_Error::IsError($result)) { $GLOBALS['app']->Session->PushLastResponse(_t('BLOG_ERROR_ENTRY_NOT_UPDATED'), RESPONSE_ERROR); return new Jaws_Error(_t('BLOG_ERROR_ENTRY_NOT_UPDATED')); } if ($this->gadget->registry->fetch('generate_xml') == 'true') { $model = $this->gadget->model->load('Feeds'); $model->MakeAtom(true); $model->MakeRSS(true); } if (!is_array($categories)) { $categories = array(); } $catAux = array(); foreach ($e['categories'] as $cat) { $catAux[] = $cat['id']; } $feedModel = $this->gadget->model->load('Feeds'); foreach ($categories as $category) { if (!in_array($category, $catAux)) { $this->AddCategoryToEntry($post_id, $category); } else { if ($this->gadget->registry->fetch('generate_category_xml') == 'true') { $model = $this->gadget->model->load('Feeds'); $catAtom = $model->GetCategoryAtomStruct($category); $feedModel->MakeCategoryAtom($category, $catAtom, true); $feedModel->MakeCategoryRSS($category, $catAtom, true); } } } foreach ($e['categories'] as $k => $v) { if (!in_array($v['id'], $categories)) { $this->DeleteCategoryInEntry($post_id, $v['id']); } } //Commit Transaction $blogTable->commit(); if ($this->gadget->registry->fetch('pingback') == 'true') { $pback = Jaws_Pingback::getInstance(); $pback->sendFromString($this->gadget->urlMap('SingleView', array('id' => $post_id), true), $params['text']); } if (Jaws_Gadget::IsGadgetInstalled('Tags') && !empty($tags)) { $model = Jaws_Gadget::getInstance('Tags')->model->loadAdmin('Tags'); $res = $model->UpdateReferenceTags('Blog', 'post', $post_id, $params['published'], isset($params['publishtime']) ? strtotime($params['publishtime']) : time(), $tags); if (Jaws_Error::IsError($res)) { $GLOBALS['app']->Session->PushLastResponse(_t('BLOG_ERROR_TAGS_NOT_UPDATED'), RESPONSE_ERROR); } } //FIXME: add shoutAll method in core for increase performance // shout subscriptions event // generate a key for reference - shout subscription $key = crc32('Post' . $post_id); if (is_array($categories) && count($categories) > 0) { foreach ($categories as $category) { // [Category] action $subscriptionParams = array('action' => 'Category', 'reference' => $category, 'key' => $key, 'summary' => $title, 'publish_time' => isset($params['publishtime']) ? strtotime($params['publishtime']) : time(), 'description' => $content, 'url' => $this->gadget->urlMap('SingleView', array('id' => $post_id), true)); $this->gadget->event->shout('Subscription', $subscriptionParams); } } $GLOBALS['app']->Session->PushLastResponse(_t('BLOG_ENTRY_UPDATED'), RESPONSE_NOTICE); return $post_id; }
/** * Displays a given blog entry * * @access public * @param int $id Post id (optional, null by default) * @return string XHTML template content */ function SingleView($id = null) { $g_id = jaws()->request->fetch('id', 'get'); $g_id = Jaws_XSS::defilter($g_id); $model = $this->gadget->model->load('Posts'); if (is_null($id)) { $entry = $model->GetEntry($g_id, true); } else { $entry = $model->GetEntry($id, true); } if (!Jaws_Error::IsError($entry) && !empty($entry)) { foreach ($entry['categories'] as $cat) { if (!$this->gadget->GetPermission('CategoryAccess', $cat['id'])) { return Jaws_HTTPError::Get(403); } } //increase entry's visits counter $model->ViewEntry($entry['id']); $entry['clicks']++; if ($this->gadget->registry->fetch('pingback') == 'true') { $pback = Jaws_Pingback::getInstance(); $pback->showHeaders($this->gadget->urlMap('Pingback', array(), true)); } $this->SetTitle($entry['title']); $this->AddToMetaKeywords($entry['meta_keywords']); $this->SetDescription($entry['meta_description']); $tpl = $this->gadget->template->load('Post.html'); $tpl->SetBlock('single_view'); $this->ShowEntry($tpl, 'single_view', $entry, false); $trbkHTML = $this->gadget->action->load('Trackbacks'); if (!Jaws_Error::IsError($trbkHTML)) { $tpl->SetVariable('trackbacks', $trbkHTML->ShowTrackbacks($entry['id'])); } $allow_comments_config = $this->gadget->registry->fetch('allow_comments', 'Comments'); switch ($allow_comments_config) { case 'restricted': $allow_comments_config = $GLOBALS['app']->Session->Logged(); $restricted = !$allow_comments_config; break; default: $restricted = false; $allow_comments_config = $allow_comments_config == 'true'; } if (Jaws_Gadget::IsGadgetInstalled('Comments')) { $allow_comments = $entry['allow_comments'] === true && $this->gadget->registry->fetch('allow_comments') == 'true' && $allow_comments_config; $cHTML = Jaws_Gadget::getInstance('Comments')->action->load('Comments'); $tpl->SetVariable('comments', $cHTML->ShowComments('Blog', 'Post', $entry['id'], array('action' => 'SingleView', 'params' => array('id' => empty($entry['fast_url']) ? $entry['id'] : $entry['fast_url'])))); if ($allow_comments) { $redirect_to = $this->gadget->urlMap('SingleView', array('id' => empty($entry['fast_url']) ? $entry['id'] : $entry['fast_url'])); $tpl->SetVariable('comment-form', $cHTML->ShowCommentsForm('Blog', 'Post', $entry['id'], $redirect_to)); } elseif ($restricted) { $login_url = $GLOBALS['app']->Map->GetURLFor('Users', 'LoginBox'); $register_url = $GLOBALS['app']->Map->GetURLFor('Users', 'Registration'); $tpl->SetVariable('comment-form', _t('COMMENTS_COMMENTS_RESTRICTED', $login_url, $register_url)); } } if ($tpl->VariableExists('navigation')) { $navtpl = $this->gadget->template->load('PostNavigation.html'); if ($prev = $model->GetNOPEntry($entry['id'], 'previous')) { $navtpl->SetBlock('entry-navigation/previous'); $navtpl->SetVariable('url', $this->gadget->urlMap('SingleView', array('id' => empty($prev['fast_url']) ? $prev['id'] : $prev['fast_url']))); $navtpl->SetVariable('title', $prev['title']); $navtpl->SetVariable('previous', _t('GLOBAL_PREVIOUS')); $navtpl->ParseBlock('entry-navigation/previous'); } if ($next = $model->GetNOPEntry($entry['id'], 'next')) { $navtpl->SetBlock('entry-navigation/next'); $navtpl->SetVariable('url', $this->gadget->urlMap('SingleView', array('id' => empty($next['fast_url']) ? $next['id'] : $next['fast_url']))); $navtpl->SetVariable('title', $next['title']); $navtpl->SetVariable('next', _t('GLOBAL_NEXT')); $navtpl->ParseBlock('entry-navigation/next'); } $navtpl->ParseBlock('entry-navigation'); $tpl->SetVariable('navigation', $navtpl->Get()); } $tpl->ParseBlock('single_view'); return $tpl->Get(); } else { return Jaws_HTTPError::Get(404); } }