/** * Set page description for current execution. * * @param array $tag_params * @param array $children */ private function setDescription($tag_params, $children) { global $language; // set from language constant if (isset($tag_params['constant'])) { $language_handler = MainLanguageHandler::getInstance(); $constant = fix_chars($tag_params['constant']); $this->page_description = $language_handler->getText($constant); // set from article } else { if (isset($tag_params['article']) && class_exists('articles')) { $manager = ArticleManager::getInstance(); $text_id = fix_chars($tag_params['article']); // get article from database $item = $manager->getSingleItem(array('content'), array('text_id' => $text_id)); if (is_object($item)) { $content = strip_tags(Markdown($item->content[$language])); $data = explode("\n", utf8_wordwrap($content, 150, "\n", true)); if (count($data) > 0) { $this->page_description = $data[0]; } } } } }
/** * Function to record vote from AJAX call */ private function json_Vote() { $id = fix_id($_REQUEST['id']); $value = $_REQUEST['value']; $manager = ArticleManager::getInstance(); $vote_manager = ArticleVoteManager::getInstance(); $vote = $vote_manager->getSingleItem(array('id'), array('article' => $id, 'address' => $_SERVER['REMOTE_ADDR'])); $result = array('error' => false, 'error_message' => ''); if (is_object($vote)) { // that address already voted $result['error'] = true; $result['error_message'] = $this->getLanguageConstant('message_vote_already'); } else { // stupid but we need to make sure article exists $article = $manager->getSingleItem(array('id', 'votes_up', 'votes_down'), array('id' => $id)); if (is_object($article)) { $vote_manager->insertData(array('article' => $article->id, 'address' => $_SERVER['REMOTE_ADDR'])); if (is_numeric($value)) { $data = array('votes_up' => $article->votes_up, 'votes_down' => $article->votes_down); if ($value == -1) { $data['votes_down']++; } if ($value == 1) { $data['votes_up']++; } $manager->updateData($data, array('id' => $article->id)); } $article = $manager->getSingleItem(array('id', 'votes_up', 'votes_down'), array('id' => $id)); $result['rating'] = $this->getArticleRating($article, 10); } else { $result['error'] = true; $result['error_message'] = $this->getLanguageConstant('message_vote_error'); } } print json_encode($result); }