function article1_url_handler(&$sm, $url_array) { $um = $sm->get_url_manager(); $params = array('url_module' => 'article'); $last_chunk = end($url_array); if (preg_match('/^(\\d+)-?/', $last_chunk, $article_url)) { if (isset($article_url[1])) { require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Articles.class.php'; $article = Articles_list::factory()->get_article_by_id($article_url[1], $um->list['search_cid']); if ($article) { $params['search_id'] = $article->id; } else { return false; } } } else { return false; } return $params; }
function _stats() { $sm = vivvo_lite_site::get_instance(); $um = $sm->get_url_manager(); $template = $this->load_template($this->_template_root . 'stats_modal.xml'); if ($um->isset_param('article_id')) { $article = Articles_list::factory()->get_article_by_id($um->get_param('article_id')); if ($article) { $template->assign('article', $article); } } return $template; }
function article_content_handler(&$sm) { $template = $sm->get_template(); $template->set_template_file(VIVVO_FS_TEMPLATE_ROOT . VIVVO_TEMPLATE_DIR . 'frame/default.tpl'); $header = $sm->get_header_manager(); $um = $sm->get_url_manager(); if ($um->get_param('search_id')) { //Article page $id = $um->get_param('search_id'); require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Articles.class.php'; $al = Articles_list::factory(); $sm->article = $al->get_article_by_id($id); if ($sm->article !== false) { $sm->set_categories(); $category = $sm->categories->list[$sm->article->get_category_id()]; if ($um->isset_param('force_template') && $sm->user && $sm->user->is_admin() && file_exists(VIVVO_FS_TEMPLATE_ROOT . VIVVO_TEMPLATE_DIR . 'article/' . $um->get_param('force_template'))) { $template->set_template_file(VIVVO_FS_TEMPLATE_ROOT . VIVVO_TEMPLATE_DIR . 'article/' . $um->get_param('force_template')); } else { $template->set_template_file(VIVVO_FS_TEMPLATE_ROOT . VIVVO_TEMPLATE_DIR . 'article/' . $category->get_article_template()); } // 1. is user and is admin // 2. is user and can read article category // 3. guest and can read article category if ($sm->user && ($sm->user->is_admin() || $sm->user->can('READ', 'Categories', $category->id)) || !$sm->user && $sm->guest_group && $sm->guest_group->can('READ', 'Categories', $category->id)) { if (!defined('VIVVO_ADMIN_MODE')) { if (($sm->article->status == 0 || strtotime($sm->article->created) > VIVVO_START_TIME) && !($sm->user && $sm->user->can('ACCESS_ADMIN'))) { go_404(); } $sm->article->on_display(); } $template->assign('CURRENT_CATEGORY', $category); if (isset($sm->article->author_obj)) { $template->assign('CURRENT_AUTHOR', $sm->article->author_obj); } // revision view: // 1. both 'news' and 'rev' parameters must be passed trough GET // 2. 'news' parameter must be equal to 'search_id' parameter from url_manager // 3. user must have EDITOR privilege for this category, or be an author of article (with WRITE privilege) if (!empty($_GET['news']) and $_GET['news'] == $sm->article->get_id() and !empty($_GET['rev']) and $sm->user and ($sm->user->is('EDITOR', 'Categories', $category->get_id()) or count($sm->user->get_privilege_object_ids('WRITE', 'Categories')) and $sm->user->get_id() == $sm->article->get_user_id())) { class_exists('ArticlesRevisions') or (require VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/ArticlesRevisions.class.php'); $revision = ArticlesRevisions_list::factory()->get_revision_by_article_id_ver($sm->article->get_id(), $_GET['rev'] << 0); if ($revision) { $sm->article->set_title($revision->get_title()); $sm->article->set_abstract($revision->get_abstract()); $sm->article->set_body($revision->get_body()); } } // end revision view // add this article to printed list $sm->printed_articles[] = $sm->article->get_id(); $template->assign('article', $sm->article); if (!defined('VIVVO_ADMIN_MODE')) { if (VIVVO_MODULES_FEED == 1) { $header->add_rss(switch_format('rss', CURRENT_URL), $sm->article->get_title()); if (VIVVO_FRIENDY_URL) { $header->add_rss(switch_format('rss', VIVVO_URL . $category->get_href()), $category->category_name); } else { $header->add_rss(switch_format('rss', $category->get_href()), $category->category_name); } } $sm->page_title = $sm->article->get_title(); if ($um->isset_param('print')) { $sm->set_theme($category->get_css(), true); } else { $sm->set_theme($category->get_css()); } } $sm->_template->assign('PAGE_TITLE', strval($sm->article->title)); $um->set_param('search_cid', $category->id); } else { $template->set_template_file(VIVVO_FS_TEMPLATE_ROOT . VIVVO_TEMPLATE_DIR . 'frame/default.tpl'); $template->assign('PAGE_TITLE', strval($sm->_lang->get_value('LNG_RESTRICTED_ACCESS'))); $content_template = new template($sm, $template); $content_template->set_template_file(VIVVO_FS_TEMPLATE_ROOT . VIVVO_TEMPLATE_DIR . 'system/restricted.tpl'); $template->assign_template('PAGE_CONTENT', $content_template); } } else { go_404(); } } else { go_404(); } }
/** * Add new comment * * @param array $in_article * @param string $captcha * @return boolean true on success or false on fail */ function add_comment($in_comment, $captcha = '') { if (!vivvo_hooks_manager::call('comment_add', array(&$in_comment))) { return vivvo_hooks_manager::get_status(); } $sm = vivvo_lite_site::get_instance(); if (VIVVO_COMMENTS_ENABLE == 1) { if ($this->bad_ip_filter()) { $this->set_error_code(2201); return false; } $is_guest = !$sm->user && $sm->guest_group; if ($is_guest && $sm->guest_group->group_privileges['ARTICLE_COMMENT'] > 0 || $sm->user && $sm->user->privileges['ARTICLE_COMMENT'] > 0) { if ($sm->user) { $in_comment['user_id'] = $sm->user->get_id(); $in_comment['author'] = $sm->user->get_name(); $in_comment['email'] = $sm->user->email_address; $in_comment['www'] = $sm->user->www; } $in_comment['create_dt'] = date('Y-m-d H:i:s'); $in_comment['ip'] = $_SERVER['REMOTE_ADDR']; if ($is_guest && $sm->guest_group->group_privileges['ARTICLE_COMMENT'] == 1 || $sm->user && $sm->user->privileges['ARTICLE_COMMENT'] == 1) { $in_comment['status'] = '1'; } if (VIVVO_COMMENTS_CAPTHA == 0 || is_array($_SESSION['vivvo']['comment_captcha']) && $_SESSION['vivvo']['comment_captcha'][$in_comment['article_id']] == $captcha) { if (isset($_SESSION['vivvo']['comment_time']) && $_SESSION['vivvo']['comment_time'] + VIVVO_COMMENTS_FLOOD_PROTECTION > VIVVO_START_TIME) { $this->set_error_code(2202); return false; } else { array_walk($in_comment, 'array_htmlspecialchars'); $in_comment['description'] = $this->bad_words_filter($in_comment['description']); $in_comment['description'] = trim($in_comment['description']); if ($in_comment['description'] == '') { $this->set_error_code(2221); return false; } if (VIVVO_COMMENTS_ENABLE_BBCODE) { if ($is_guest) { $in_comment['description'] = preg_replace('/\\[url(.+?)?\\]|\\[\\/url\\]/', '', $in_comment['description']); } $in_comment['description_src'] = $in_comment['description']; $in_comment['description'] = Comments::parse_bbcode($in_comment['description']); } if (VIVVO_COMMENTS_ENABLE_THREADED and empty($in_comment['root_comment']) and !empty($in_comment['reply_to'])) { $in_comment['root_comment'] = $in_comment['reply_to']; } $comment = new Comments(null, $in_comment); $this->_post_master->set_data_object($comment); if ($this->_post_master->sql_insert()) { $id = $this->_post_master->get_work_id(); $comment->set_id($id); if (!vivvo_hooks_manager::call('comment_add_postinsert', array(&$comment))) { return vivvo_hooks_manager::get_status(); } if (is_array($_SESSION['vivvo']['comment_captcha'])) { $key = array_search($captcha, $_SESSION['vivvo']['comment_captcha']); unset($_SESSION['vivvo']['comment_captcha'][$key]); class_exists('Articles') or (require VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Articles.class.php'); Articles_list::factory()->get_article_by_id($comment->get_article_id())->generate_captcha(); } $_SESSION['vivvo']['comment_time'] = time(); return true; } else { $this->set_error_code(2203); return false; } } } else { $this->set_error_code(2204); return false; } } else { $this->set_error_code(2205); return false; } } else { $this->set_error_code(2206); return false; } }
public function get_article_count() { if ($this->article_count === false) { class_exists('Articles_list') or (require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Articles.class.php'); $list = Articles_list::factory(); $list->search(array('search_cid' => $this->id), '', '', 0, 0, false); $this->article_count = $list->get_total_count(); } return $this->article_count; }
public function generate_output($params = array()) { static $data_provider = null; static $ga = null; $data_provider != null or $data_provider = new vivvo_ga_chart_provider(); $ga != null or $ga = vivvo_ga::get_instance(array('email' => VIVVO_GA_EMAIL, 'password' => VIVVO_GA_PASSWORD, 'profileId' => VIVVO_GA_PROFILEID, 'no_auth' => true)); $this->set_template($params); unset($params['template_string']); unset($params['template']); $params = $data_provider->filter_box_params($params); $cache_key = 'ga_box_data_' . md5(serialize($params)); if (vivvo_cache::get_instance()->exists($cache_key)) { $report = vivvo_cache::get_instance()->get($cache_key); } else { $report = $ga->getReport($params); empty($params['data_handler']) and $params['data_handler'] = ''; switch ($params['data_handler']) { case 'article_views': class_exists('Articles') or (require VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Articles.class.php'); $article_ids = array(); foreach ($report as $row) { $article_ids[$row['dimensions']['ga:eventLabel']] = 1; } $articles = Articles_list::factory()->get_articles_by_ids(array_keys($article_ids)); for ($i = 0, $count = count($report); $i < $count; $i++) { if (!empty($articles[$report[$i]['dimensions']['ga:eventLabel']])) { $report[$i]['article'] = $articles[$report[$i]['dimensions']['ga:eventLabel']]; $report[$i]['views'] = $report[$i]['metrics']['ga:totalEvents']; } else { unset($report[$i]); } } $report = array_merge($report); default: } vivvo_cache::get_instance()->put($cache_key, $report, null, VIVVO_GA_CACHE_PERIOD); } $this->_template->assign('report', $report); }