/**
 * Archive articles (cron task function).
 *
 * @param vivvo_lite_site	$sm
 */
function auto_update_article_stats($sm)
{
    $db = $sm->get_db();
    //get statistics
    $res = $db->query("SELECT * FROM " . VIVVO_DB_PREFIX . "articles_stats WHERE updated=1");
    while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
        // update articles table
        $db->exec("UPDATE " . VIVVO_DB_PREFIX . "articles\n\t\t\t\t\t\tSET last_read='{$row['last_read']}', times_read={$row['times_read']}, today_read={$row['today_read']}\n\t\t\t\t\t\tWHERE id={$row['article_id']}");
        // reset updated flag if no new reads in mean time
        $db->exec("UPDATE " . VIVVO_DB_PREFIX . "articles_stats\n\t\t\t\t\t\tSET updated=0\n\t\t\t\t\t\tWHERE article_id={$row['article_id']} AND times_read={$row['times_read']}");
    }
    if (defined('VIVVO_CRONJOB_MODE')) {
        echo 'auto_update_article_stats: Finished.' . PHP_EOL;
    }
}
 function _default_view()
 {
     $template = vivvo_lite_site::get_instance()->get_template();
     $template->assign_template('content', $this->load_template($this->_template_root . 'content.xml'));
     $template->assign_template('left', $this->load_template($this->_template_root . 'tabs.xml'));
     return $template;
 }
Ejemplo n.º 3
0
 function check_token()
 {
     if (!vivvo_lite_site::get_instance()->check_token()) {
         //TODO: error number
         $this->set_error_code(2121);
         return false;
     }
     return true;
 }
 function _list_output()
 {
     $um = vivvo_lite_site::get_instance()->get_url_manager();
     $template = $this->load_template($this->_template_root . 'list.xml');
     foreach (array('search_article_id', 'search_author_name') as $filter) {
         if ($um->isset_param($filter)) {
             $template->assign($filter, $um->get_param($filter));
         }
     }
     return $template;
 }
Ejemplo n.º 5
0
 function num_tagged_articles($tag_id, $topic_id)
 {
     $tag_id = (int) $tag_id;
     $topic_id = (int) $topic_id;
     $sql = 'SELECT COUNT(*) FROM ' . VIVVO_DB_PREFIX . "ArticlesTags WHERE tag_id = {$tag_id} AND tags_group_id = {$topic_id}";
     $res = vivvo_lite_site::get_instance()->get_db()->query($sql);
     if (!PEAR::isError($sql) && ($total = $res->fetchOne())) {
         return $total;
     }
     return 0;
 }
Ejemplo n.º 6
0
/**
 * Import articles (cron task function).
 *
 * @param vivvo_lite_site	$sm
 */
function auto_import_feeds($sm)
{
    require_once dirname(__FILE__) . '/../core/Feeds.class.php';
    require_once VIVVO_FS_FRAMEWORK . 'vivvo_post.php';
    $db = $sm->get_db();
    if (VIVVO_PLUGIN_FEED_IMPORTER_AUTO_DELETE > 0) {
        $datetime = date('Y-m-d H:i:59', VIVVO_START_TIME - VIVVO_PLUGIN_FEED_IMPORTER_AUTO_DELETE * 86400);
        if (VIVVO_PLUGIN_FEED_IMPORTER_TRASH) {
            $db->exec('UPDATE ' . VIVVO_DB_PREFIX . "articles SET status = -2 WHERE created < '{$datetime}' AND feed_item_id IS NOT NULL AND status > -2");
        } else {
            $db->exec('DELETE FROM ' . VIVVO_DB_PREFIX . "articles WHERE created < '{$datetime}' AND feed_item_id IS NOT NULL");
        }
    }
    if (VIVVO_PLUGIN_FEED_IMPORTER_AUTO_ARCHIVE > 0) {
        $datetime = date('Y-m-d H:i:59', VIVVO_START_TIME - VIVVO_PLUGIN_FEED_IMPORTER_AUTO_ARCHIVE * 86400);
        $db->exec('UPDATE ' . VIVVO_DB_PREFIX . "articles SET status = -1 WHERE created < '{$datetime}' AND feed_item_id IS NOT NULL");
    }
    $feed_list = Feeds_list::factory();
    $feed_list->search(array());
    $post_master = new vivvo_post_master($sm);
    $total_added = 0;
    $total_updated = 0;
    foreach ($feed_list->list as $feed) {
        $counts = $feed->import_articles();
        $total_added += $counts[0];
        $total_updated += $counts[1];
        $post_master->set_data_object($feed);
        $post_master->sql_update();
    }
    if (defined('VIVVO_CRONJOB_MODE')) {
        $feed_count = count($feed_list->list);
        echo "auto_import_feeds: Imported {$total_added} and updated {$total_updated} article(s) from {$feed_count} feed(s)." . PHP_EOL;
    } elseif (defined('VIVVO_FEED_IMPORTER_ADMIN_VIEW')) {
        echo json_encode(array('feeds' => count($feed_list->list), 'added' => $total_added, 'updated' => $total_updated));
    }
}
Ejemplo n.º 7
0
 /**
  * Load configuration data from database
  */
 function load_configuration($force = false)
 {
     if (!$force and ($data = vivvo_cache::get_instance()->get('configuration')) !== false) {
         if (!empty($data)) {
             $this->_config_data = $data;
             return;
         }
     }
     $db = vivvo_lite_site::get_instance()->get_db();
     $res = $db->query('SELECT * FROM ' . VIVVO_DB_PREFIX . 'configuration');
     $this->_config_data = array();
     if (!PEAR::isError($res)) {
         while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
             $this->_config_data[] = $row;
         }
         $res->free();
     }
     vivvo_cache::get_instance()->put('configuration', $this->_config_data);
 }
Ejemplo n.º 8
0
 function get_view()
 {
     $sm = vivvo_lite_site::get_instance();
     $template = $sm->get_template();
     $um = $sm->get_url_manager();
     $pm = $sm->get_plugin_manager();
     $dm = $sm->get_dump_manager();
     $template->assign('DUMP_MESSAGES', $dm->_dump_pool);
     $this->_default_assignments();
     $um_keys = array_keys($um->list);
     $views = array_intersect($this->views, $um_keys);
     $default_view = false;
     if (!empty($views)) {
         $view = current($views);
         if (method_exists($this, '_' . $view)) {
             $tpl = call_user_func(array($this, '_' . $view));
         } elseif (file_exists($this->_template_root . $view . '.xml')) {
             $tpl = $this->load_template($this->_template_root . $view . '.xml');
         } else {
             die('No such view');
         }
         echo $tpl->get_output();
     } else {
         if ($this->_default_view) {
             $tpl =& call_user_func(array($this, $this->_default_view));
             echo $tpl->get_output();
         } else {
             $tpl = $this->_default_view();
             echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . "\n";
             echo $sm->get_output();
         }
     }
     if ($sm->user && $sm->user->is_admin()) {
         $sm->fb_debug_output();
     }
 }
 public function _force_import()
 {
     require_once dirname(__FILE__) . '/tasks/auto_import_feeds.php';
     define('VIVVO_FEED_IMPORTER_ADMIN_VIEW', true);
     auto_import_feeds(vivvo_lite_site::get_instance());
     header('Content-Type: application/json');
     exit;
 }
Ejemplo n.º 10
0
 function set__file_manager()
 {
     $this->_file_manager = vivvo_lite_site::get_instance()->get_file_manager();
 }
Ejemplo n.º 11
0
 function group_edit($group_id, $in_group)
 {
     if (!$this->check_token()) {
         return false;
     }
     if (!vivvo_hooks_manager::call('vivvoCore_groupEdit', array(&$group_id, &$in_group))) {
         return vivvo_hooks_manager::get_status();
     }
     if ($this->_user && $this->_user->is_admin()) {
         $sm = vivvo_lite_site::get_instance();
         $user_manager = $sm->get_user_manager();
         $group = $user_manager->get_group_by_id($group_id);
         if ($group) {
             if (VIVVO_USER_SOURCE == 'vivvo@localhost') {
                 $group->name = $in_group['name'];
                 $this->_post_master->set_data_object($group);
                 if (!$this->_post_master->sql_update()) {
                     $this->set_error_code(5115);
                     return false;
                 }
             }
             if ($user_manager->save_group_privileges($group, $in_group['privileges'])) {
                 admin_log($sm->user->get_username(), 'Edited group #' . $group_id);
                 return true;
             } else {
                 $this->set_error_code(5116);
                 return false;
             }
         } else {
             $this->set_error_code(5117);
             return false;
         }
     } else {
         $this->set_error_code(5118);
         return false;
     }
 }
Ejemplo n.º 12
0
 /**
  * Generate box output
  *
  * @param array $params Parameters
  */
 function generate_output($params)
 {
     $this->set_template($params);
     if (isset($params['max_page'])) {
         $max_page = (int) $params['max_page'];
     } else {
         $max_page = 10;
     }
     if (isset($params['list']) && is_a($params['list'], 'vivvo_db_list')) {
         $paging_params = $params['list']->get_pagination();
         $this->pagination = new pagination($paging_params['pg_records_per_page'], $max_page, $paging_params['pg_href']);
         $this->pagination->set_template($this->_template);
         $this->pagination->generate_pagelist($paging_params['pg_total'], $paging_params['pg_current']);
     } elseif (isset($params['list']) && is_a($params['list'], 'vivvo_file_paged_list')) {
         $paging_params = $params['list']->get_pagination();
         $this->pagination = new pagination($paging_params['pg_records_per_page'], $max_page, $paging_params['pg_href']);
         $this->pagination->set_template($this->_template);
         $this->pagination->generate_pagelist($paging_params['pg_total'], $paging_params['pg_current']);
     } else {
         $um = vivvo_lite_site::get_instance()->get_url_manager();
         $this->pagination = new pagination($um->get_param('pg_records_per_page'), $max_page, $um->get_param('pg_href'));
         $this->pagination->set_template($this->_template);
         $this->pagination->generate_pagelist($um->get_param('pg_total'), $um->get_param('pg_current'));
     }
     if (isset($params['title'])) {
         $this->_template->assign('title', $params['title']);
     }
     $this->_template->assign('box_id', $params['box_id']);
 }
 /**
  * Autocomplete box feed
  */
 public function _autocomplete_links()
 {
     $sm = vivvo_lite_site::get_instance();
     $template = $sm->get_template();
     $um = $sm->get_url_manager();
     $pm = $sm->get_plugin_manager();
     $content_template = new template(null, $template);
     $content_template->set_template_file($this->_template_root . 'autocomplete_links.xml');
     $hrefs = array();
     $db = $sm->get_db();
     $name = secure_sql($um->get_param('name'));
     $sql = "(SELECT id, category_name AS title, sefriendly, '' AS category_id,  'Categories' AS type FROM " . VIVVO_DB_PREFIX . "categories WHERE category_name LIKE '{$name}%')\n\t\t\t\t\t UNION\n\t\t\t\t    (SELECT id, title, sefriendly, category_id, 'Articles' AS type FROM " . VIVVO_DB_PREFIX . "articles WHERE title LIKE '{$name}%')";
     if ($pm->is_installed('pages')) {
         $sql .= "UNION (SELECT id, title, sefriendly, '' AS category_id, 'Pages' AS type FROM " . VIVVO_DB_PREFIX . "pages WHERE title LIKE '{$name}%')";
     }
     $sql .= "UNION (SELECT t.id, CONCAT(tg.name,': ',t.name) AS title, t.sefriendly AS sefriendly, tg.url AS category_id, 'Tags' AS type FROM " . VIVVO_DB_PREFIX . "tags AS t INNER JOIN " . VIVVO_DB_PREFIX . "tags_to_tags_groups AS ttg ON ttg.tag_id = t.id INNER JOIN " . VIVVO_DB_PREFIX . "tags_groups AS tg ON ttg.tags_group_id = tg.id WHERE t.name LIKE '{$name}%' GROUP BY t.id, tg.id) " . "UNION (SELECT id, name AS title, url AS sefriendly, '' AS category_id,  'Topics' AS type FROM " . VIVVO_DB_PREFIX . "tags_groups WHERE name LIKE '{$name}%')";
     $res = $db->query($sql);
     if (!PEAR::isError($res)) {
         $i = 0;
         while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
             $hrefs[$i] = array();
             $hrefs[$i]['title'] = $row['title'];
             $hrefs[$i]['id'] = $row['id'];
             $hrefs[$i]['type'] = $row['type'];
             switch ($row['type']) {
                 case 'Articles':
                     if (!$article) {
                         require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Articles.class.php';
                         $article = new Articles();
                     }
                     $article->id = $row['id'];
                     $article->title = $row['title'];
                     $article->sefriendly = $row['sefriendly'];
                     $article->category_id = $row['category_id'];
                     $hrefs[$i]['href'] = $article->get_href();
                     break;
                 case 'Categories':
                     if (!$cat) {
                         $cat = $sm->get_categories();
                     }
                     $hrefs[$i]['href'] = $cat->list[$row['id']]->get_href();
                     break;
                 case 'Pages':
                     if (!$page) {
                         require_once VIVVO_FS_PLUGIN_ROOT . 'plugins/pages/Pages.class.php';
                         $page = new Pages();
                     }
                     $page->id = $row['id'];
                     $page->title = $row['title'];
                     $page->sefriendly = $row['sefriendly'];
                     $hrefs[$i]['href'] = $page->get_href();
                     break;
                 case 'Tags':
                     if (!$tag) {
                         require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/Tags.class.php';
                         $tag = new Tags();
                     }
                     $tag->id = $row['id'];
                     $tag->name = $row['title'];
                     $tag->sefriendly = $row['sefriendly'];
                     $tag->group_url = $row['category_id'] . '/';
                     $hrefs[$i]['href'] = $tag->get_href();
                     break;
                 case 'Topics':
                     if (!$topic) {
                         require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/core/TagsGroups.class.php';
                         $topic = new TagsGroups();
                     }
                     $topic->id = $row['id'];
                     $topic->name = $row['title'];
                     $topic->url = $row['sefriendly'];
                     $hrefs[$i]['href'] = rtrim($topic->get_href(), '/');
                     break;
             }
             $i++;
         }
     }
     $content_template->assign('link_list', $hrefs);
     return $content_template;
 }
Ejemplo n.º 14
0
/**
 * Box def move service function
 *
 * @param vivvo_lite_site $sm
 * @return xmlrpcresp
 */
function vivvo_core_service(&$sm, $action, $command)
{
    require_once dirname(__FILE__) . '/vivvo_core.service.php';
    $um = $sm->get_url_manager();
    $dm = $sm->get_dump_manager();
    $lang = $sm->get_lang();
    $vivvo_core_service = new vivvo_core_service($sm);
    if ($command == 'preferences') {
        $success = true;
        if (is_array($um->list) && !empty($um->list)) {
            foreach ($um->list as $key => $value) {
                if (preg_match('/^(VIVVO_|PLUGIN_)/', $key)) {
                    if (is_array($um->list[$key])) {
                        $value = implode(',', $um->list[$key]);
                        $response = $vivvo_core_service->edit_preferences($key, $value);
                        if (!$response) {
                            $success = false;
                        }
                    } else {
                        $response = $vivvo_core_service->edit_preferences($key, $um->list[$key]);
                        if (!$response) {
                            $success = false;
                        }
                    }
                }
            }
        }
        if ($success) {
            $dm->add_dump('info', 0, $lang->get_value('LNG_INFO_PREFERENCES_SAVE_SUCCESS'));
            vivvo_hooks_manager::call('vivvoCore_preferences_postaction');
            header('X-Vivvo-Action-Status: 1');
            return true;
        } else {
            header('X-Vivvo-Action-Status: 0');
            header('X-Vivvo-Action-Error: ' . json_encode($vivvo_core_service->get_error_info()));
            return false;
        }
    } else {
        if ($command == 'cronTask') {
            $success = true;
            if (is_array($um->list) && !empty($um->list)) {
                foreach ($um->list as $key => $value) {
                    if (preg_match('/^(VIVVO_|PLUGIN_)/', $key)) {
                        if (is_array($um->list[$key])) {
                            $value = implode(',', $um->list[$key]);
                            $response = $vivvo_core_service->edit_preferences($key, $value);
                            if (!$response) {
                                $success = false;
                            }
                        } else {
                            $response = $vivvo_core_service->edit_preferences($key, $um->list[$key]);
                            if (!$response) {
                                $success = false;
                            }
                        }
                    }
                }
            }
            $in_task = $um->get_param_regexp('/^TASK_/');
            $success = $success && $vivvo_core_service->edit_cron_task($in_task);
            if ($success) {
                $dm->add_dump('info', 0, $lang->get_value('LNG_INFO_TASK_SAVE_SUCCESS'));
                vivvo_hooks_manager::call('vivvoCore_cronTask_postaction');
                header('X-Vivvo-Action-Status: 1');
                return true;
            } else {
                header('X-Vivvo-Action-Status: 0');
                header('X-Vivvo-Action-Error: ' . json_encode($vivvo_core_service->get_error_info()));
                return false;
            }
        } else {
            if ($command == 'groupAdd') {
                $in_group = $um->get_param_regexp('/^GROUP_/');
                $success = $vivvo_core_service->group_add($in_group);
                if ($success) {
                    $dm->add_dump('info', 0, $lang->get_value('LNG_INFO_GROUP_SAVE_SUCCESS'));
                    vivvo_hooks_manager::call('vivvoCore_groupAdd_postaction');
                    header('X-Vivvo-Action-Status: 1');
                    return true;
                } else {
                    header('X-Vivvo-Action-Status: 0');
                    header('X-Vivvo-Action-Error: ' . json_encode($vivvo_core_service->get_error_info()));
                    return false;
                }
            } else {
                if ($command == 'groupEdit') {
                    $group_id = $um->get_param('GROUP_id');
                    $in_group = $um->get_param_regexp('/^GROUP_/');
                    $success = $vivvo_core_service->group_edit($group_id, $in_group);
                    if ($success) {
                        $dm->add_dump('info', 0, $lang->get_value('LNG_INFO_GROUP_EDIT_SUCCESS'));
                        vivvo_hooks_manager::call('vivvoCore_groupEdit_postaction');
                        header('X-Vivvo-Action-Status: 1');
                        return true;
                    } else {
                        header('X-Vivvo-Action-Status: 0');
                        header('X-Vivvo-Action-Error: ' . json_encode($vivvo_core_service->get_error_info()));
                        return false;
                    }
                } else {
                    if ($command == 'groupDelete') {
                        $group_id = $um->get_param('GROUP_id');
                        $success = $vivvo_core_service->group_delete($group_id);
                        if ($success) {
                            $dm->add_dump('info', 0, $lang->get_value('LNG_INFO_GROUP_DELETE_SUCCESS'));
                            vivvo_hooks_manager::call('vivvoCore_groupDelete_postaction');
                            header('X-Vivvo-Action-Status: 1');
                            return true;
                        } else {
                            header('X-Vivvo-Action-Status: 0');
                            header('X-Vivvo-Action-Error: ' . json_encode($vivvo_core_service->get_error_info()));
                            return false;
                        }
                    }
                }
            }
        }
    }
}
Ejemplo n.º 15
0
/**
 * Handles cronjob.php --touch
 */
function action_touch($options)
{
    defined('VIVVO_START_TIME') or define('VIVVO_START_TIME', time());
    $cron_flag = VIVVO_FS_ROOT . 'cache/.cron.lock';
    // call cron only if it's been at least a minute since the last
    if (file_exists($cron_flag) and VIVVO_START_TIME - filemtime($cron_flag) < 60) {
        cronjob_error('Cron manager has already been called less than a minute ago.');
    }
    // reset flag
    @unlink($cron_flag);
    touch($cron_flag);
    require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/vivvo_lite_site.php';
    require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/framework/vivvo_cron.php';
    error_reporting(E_ERROR);
    define('VIVVO_SKIP_URL_PARSING', true);
    $sm = vivvo_lite_site::get_instance();
    $cm = new vivvo_cron_manager($sm);
    $cm->execute();
    echo 'Cron manager executed successfully.' . PHP_EOL;
}
Ejemplo n.º 16
0
 /**
  * Confirmation procedure
  *
  * @param	string	$ack
  * @return	boolean	true on success or false on fail
  */
 function confirm($ack)
 {
     if (!vivvo_hooks_manager::call('login_confirm', array(&$ack))) {
         return vivvo_hooks_manager::get_status();
     }
     $user_list = new Users_list();
     $user = $user_list->get_user_by_md5($ack);
     if ($user === false) {
         $this->set_error_code(2710);
         return false;
     } else {
         $user->set_activated('1');
         vivvo_lite_site::get_instance()->get_template()->assign('CONFIRMED', 1);
         $this->_post_master->set_data_object($user);
         if ($this->_post_master->sql_update()) {
             return true;
         } else {
             $this->set_error_code(2711);
             return false;
         }
     }
 }
 function _autocomplete_tags()
 {
     $sm = vivvo_lite_site::get_instance();
     $um = $sm->get_url_manager();
     $output = '';
     if ($um->isset_param('name')) {
         $name = escape_sql_like(secure_sql($um->get_param('name')));
         $res = $sm->get_db()->query('SELECT name FROM ' . VIVVO_DB_PREFIX . "tags WHERE name LIKE '{$name}%'");
         if (!PEAR::isError($res)) {
             $attributes[] = ENT_QUOTES;
             $attributes[] = 'UTF-8';
             $tags = array_map('html_entity_decode', $res->fetchCol(), $attributes);
             $res->free();
             $output = '<ul><li>' . implode('</li><li>', $tags) . '</li></ul>';
         }
     }
     echo $output;
     exit;
 }
Ejemplo n.º 18
0
 /**
  * Edit comment
  *
  * @param	integer		$comment_id
  * @param	array		$data
  * @return	boolean		true on succes, or false on fail
  */
 function vote($comment_id, $vote)
 {
     if (!vivvo_hooks_manager::call('comment_vote', array(&$comment_id, &$vote))) {
         return vivvo_hooks_manager::get_status();
     }
     $sm = vivvo_lite_site::get_instance();
     $dm = $sm->get_dump_manager();
     if (!$sm->user && $sm->guest_group && $sm->guest_group->group_privileges['ARTICLE_COMMENT'] > 0 || $sm->user && $sm->user->privileges['ARTICLE_COMMENT'] > 0) {
         if (!isset($_SESSION['vivvo']['comment'])) {
             $_SESSION['vivvo']['comment'] = array();
         }
         if (in_array($comment_id, $_SESSION['vivvo']['comment'])) {
             $this->set_error_code(2222);
             return false;
         } else {
             if ($vote != 1 and $vote != -1) {
                 $this->set_error_code(2223);
                 return false;
             }
             $comment_list = new Comments_list();
             $comment = $comment_list->get_comments_by_id($comment_id);
             if ($comment !== false) {
                 $vote += $comment->get_vote();
                 $comment->set_vote($vote);
                 $this->_post_master->set_data_object($comment);
                 if ($this->_post_master->sql_update()) {
                     $_SESSION['vivvo']['comment'][] = $comment->id;
                     $dm->add_dump('info', 0, $vote);
                     return true;
                 } else {
                     $this->set_error_code(2224);
                     return false;
                 }
             } else {
                 $this->set_error_code(2225);
                 return false;
             }
         }
     } else {
         $this->set_error_code(2226);
         return false;
     }
 }
Ejemplo n.º 19
0
/**
 * Relate articles (cron task function).
 *
 * @param vivvo_lite_site	$sm
 */
function auto_relate($sm)
{
    if (!VIVVO_ARTICLE_RELATED_CATEGORY and !VIVVO_ARTICLE_RELATED_TAGS and !VIVVO_ARTICLE_RELATED_TOPIC) {
        $result = 'Nothing to do.';
    } else {
        $datetime = date('Y-m-d 23:59:00');
        $db = $sm->get_db();
        do {
            $res = $db->query('SELECT COUNT(*) FROM ' . VIVVO_DB_PREFIX . "articles WHERE created < '{$datetime}' AND status > 0");
            if (!PEAR::isError($res)) {
                $count = $res->fetchOne();
                $res->free();
            } else {
                $result = 'Failed to run.';
                break;
            }
            $db->exec('TRUNCATE TABLE ' . VIVVO_DB_PREFIX . 'related');
            $res = $db->query('SELECT id, category_id FROM ' . VIVVO_DB_PREFIX . "articles WHERE created <= '{$datetime}' AND status > 0");
            if (PEAR::isError($res)) {
                $result = 'Failed to select articles.';
                break;
            }
            $max = VIVVO_ARTICLE_RELATED_CATEGORY + VIVVO_ARTICLE_RELATED_TOPIC + VIVVO_ARTICLE_RELATED_TAGS;
            $rel_category = VIVVO_ARTICLE_RELATED_CATEGORY;
            $rel_parent = VIVVO_ARTICLE_RELATED_CATEGORY / 2;
            $categories = $sm->get_categories()->list;
            while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
                $category_id = $row['category_id'];
                $parent_id = $categories[$category_id]->get_parent_cat();
                $sum = array();
                $join = '';
                if (VIVVO_ARTICLE_RELATED_CATEGORY >= 0) {
                    $sum[] = "IF(a.category_id = {$category_id}, {$rel_category}, IF(a.category_id = {$parent_id}, {$rel_parent}, 0))";
                }
                if (VIVVO_ARTICLE_RELATED_TOPIC >= 0) {
                    $topics_res = $db->query('SELECT DISTINCT tags_groups_id FROM ' . VIVVO_DB_PREFIX . "articles_tags WHERE article_id = {$row['id']}");
                    if (PEAR::isError($topics_res)) {
                        $topics = array();
                    } else {
                        $topics = $topics_res->fetchCol();
                        $topics_res->free();
                    }
                    if (!empty($topics)) {
                        $join .= ' INNER JOIN ' . VIVVO_DB_PREFIX . 'articles_tags AS at1 ON (at1.article_id = a.id AND at1.tags_group_id IN (' . implode(',', $topics) . '))';
                        $sum[] = 'COUNT(DISTINCT at1.tags_groups_id) * ' . VIVVO_ARTICLE_RELATED_TOPIC / count($topics);
                    }
                }
                if (VIVVO_ARTICLE_RELATED_TAGS >= 0) {
                    $tags_res = $db->query('SELECT DISTINCT tag_id FROM ' . VIVVO_DB_PREFIX . "articles_tags WHERE article_id = {$row['id']}");
                    if (PEAR::isError($tags_res)) {
                        $tags = array();
                    } else {
                        $tags = $tags_res->fetchCol();
                        $tags_res->free();
                    }
                    if (!empty($tags)) {
                        $join .= ' INNER JOIN ' . VIVVO_DB_PREFIX . 'articles_tags AS at2 ON (at2.article_id = a.id AND at2.tag_id IN (' . implode(',', $tags) . '))';
                        $sum[] = 'COUNT(DISTINCT at2.tag_id) * ' . VIVVO_ARTICLE_RELATED_TAGS / count($tags);
                    }
                }
                $sql = 'SELECT a.id, (' . implode('+', $sum) . ') AS score
							FROM ' . VIVVO_DB_PREFIX . "articles AS a\r\n\t\t\t\t\t\t\t{$join}\r\n\t\t\t\t\t\t\tWHERE created <= '{$datetime}' AND status > 0 AND a.id != {$row['id']}\r\n\t\t\t\t\t\t\tGROUP BY a.id\r\n\t\t\t\t\t\t\tHAVING score > 0\r\n\t\t\t\t\t\t\tORDER BY score DESC\r\n\t\t\t\t\t\t\tLIMIT 5";
                $related = $db->query($sql);
                if (PEAR::isError($related)) {
                    $result = 'Failed to fetch related articles.';
                    break 2;
                }
                $values = array();
                while ($related_row = $related->fetchRow(MDB2_FETCHMODE_ASSOC)) {
                    $relevance = floor($related_row['score'] / $max * 100);
                    $values[] = "({$row['id']},{$related_row['id']},{$relevance})";
                }
                $related->free();
                $db->exec('INSERT INTO ' . VIVVO_DB_PREFIX . 'related VALUES ' . implode(',', $values));
            }
            $result = 'Executed successfully.';
        } while (0);
    }
    if (defined('VIVVO_CRONJOB_MODE')) {
        echo 'auto_relate: ' . $result . PHP_EOL;
    } else {
        admin_log('(Cron task: Auto Relate)', $result);
    }
}
Ejemplo n.º 20
0
 function get_hrefs($ids)
 {
     $hrefs = array();
     if (is_array($ids)) {
         $ids = implode(',', $ids);
     }
     $sm = vivvo_lite_site::get_instance();
     $sql = 'SELECT id, category_name FROM ' . VIVVO_DB_PREFIX . $this->_sql_table . ' WHERE id IN (' . secure_sql_in($ids) . ')';
     $res = $sm->get_db()->query($sql);
     if (!PEAR::isError($res)) {
         while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) {
             $hrefs[$row['id']] = array();
             $hrefs[$row['id']]['title'] = $row['category_name'];
             $hrefs[$row['id']]['href'] = Categories::format_href($sm, $row['id']);
         }
     }
     return $hrefs;
 }
Ejemplo n.º 21
0
 /**
  * Performs db search based on parameters from url manager
  *
  * @return	array
  */
 public static function search_from_url()
 {
     $sm = vivvo_lite_site::get_instance();
     $params = self::get_search_params_from_url($sm);
     $list = new self($sm);
     return $list->search($params['search_options'], $params['search_sort_by'], $params['search_order'], $params['search_limit'], $params['offset']);
 }
Ejemplo n.º 22
0
 /**
  * Remove tag from tag group
  *
  * @param	int		$tag_id
  * @param	int		$group_id
  */
 public function remove_tag_from_group($tag_id, $group_id)
 {
     if (!vivvo_hooks_manager::call('tag_removeTagFromGroup', array(&$tag_id, &$group_id))) {
         return vivvo_hooks_manager::get_status();
     }
     $user = vivvo_lite_site::get_instance()->user;
     if ($user && $user->can('MANAGE_TAGS')) {
         $tag_group_rel = new TagsToTagsGroups_list();
         $tag_group_rel->get_rel($tag_id, $group_id);
         if ($tag_group_rel->sql_delete_list($this->_post_master)) {
             return true;
         }
         $this->set_error_code(2416);
         return false;
     }
     $this->set_error_code(2410);
     return false;
 }
Ejemplo n.º 23
0
 function _default_view()
 {
     return vivvo_lite_site::get_instance()->get_template();
 }
Ejemplo n.º 24
0
 /**
  * Delete user filter
  *
  * @param	integer	$filter_id
  * @return	boolean	true on success or false on fail
  */
 function delete_UserFilters($filter_id)
 {
     if (!$this->check_token()) {
         return false;
     }
     if (!vivvo_hooks_manager::call('UserFilter_delete', array(&$filter_id))) {
         return vivvo_hooks_manager::get_status();
     }
     $sm = vivvo_lite_site::get_instance();
     if ($sm->user) {
         $filter_list = new UserFilters_list();
         $filter_list->get_UserFilter_by_id($filter_id);
         if ($filter_list->sql_delete_list($this->_post_master)) {
             admin_log($sm->user->get_username(), 'Deleted user filter #' . $filter_id);
             return true;
         } else {
             $this->set_error_code(2503);
             return false;
         }
     } else {
         $this->set_error_code(2504);
         return false;
     }
 }
Ejemplo n.º 25
0
 function on_delete($post_master)
 {
     $poll_answer_list =& new vivvo_poll_answer_list(vivvo_lite_site::get_instance());
     $poll_answer_list->get_answers_by_poll_id($this->id);
     $poll_answer_list->sql_delete_list($post_master);
 }
Ejemplo n.º 26
0
 /**
  * Cascade delete
  */
 function on_delete($post_master)
 {
     $post_master->sql_delete_list('articles_tags', "article_id={$this->id}");
     $post_master->sql_delete_list('articles_schedule', "article_id={$this->id}");
     $post_master->sql_delete_list('articles_revisions', "article_id={$this->id}");
     $post_master->sql_delete_list('articles_stats', "article_id={$this->id}");
     $post_master->sql_delete_list('comments', "article_id={$this->id}");
     $post_master->sql_delete_list('article_attachments', "article_id={$this->id}");
     $post_master->sql_delete_list('article_images', "article_id={$this->id}");
     admin_log(vivvo_lite_site::get_instance()->user->get_username(), 'Deleted article #' . $this->id);
 }
Ejemplo n.º 27
0
 /**
  * Mail form
  *
  * @param	integer	$form_id
  * @param	array	$data
  * @return	boolean	true on succes, or false on fail
  */
 function mail($form_id, $data)
 {
     $sm = vivvo_lite_site::get_instance();
     if (!vivvo_hooks_manager::call('form_builder_mail', array(&$form_id, &$delete))) {
         return vivvo_hooks_manager::get_status();
     }
     require_once VIVVO_FS_FRAMEWORK . 'PEAR/Mail.php';
     $form_list = new FormBuilderForms_list();
     $form = $form_list->get_form_by_id($form_id);
     $data = array_map('urldecode', $data);
     $attachments = array();
     if ($form !== false) {
         $form_element_list = new FormBuilderFields_list($this->_site_manager);
         $form_element_list->get_elements_by_form_id($form->id);
         $message = '';
         foreach ($form_element_list->list as $field) {
             if ($field->required && !key_exists($field->name, $data) && $data[$field->name] !== '' && $field->type != 'file_upload') {
                 $this->set_error_code(10712);
                 return false;
             } else {
                 if ($field->required && $field->type == 'file_upload' && empty($_FILES['PFB_' . $field->name]['name'])) {
                     $this->set_error_code(10712);
                     return false;
                 }
             }
             if (key_exists($field->name, $data)) {
                 if ($field->reg_exp) {
                     if (!preg_match('/^' . $field->reg_exp . '$/', $data[$field->name])) {
                         $this->set_error_code(10713);
                         return false;
                     }
                 }
                 if ($field->type != 'submit') {
                     if ($field->label != '') {
                         $message .= $field->label . ': ' . $data[$field->name] . "\n";
                     } else {
                         $message .= $field->name . ': ' . $data[$field->name] . "\n";
                     }
                 }
             }
             if ($field->type == 'file_upload' && isset($_FILES['PFB_' . $field->name])) {
                 $attachments[] = 'PFB_' . $field->name;
             }
         }
         if ($form->email) {
             $files = array();
             if (count($attachments)) {
                 foreach ($attachments as $attachment) {
                     if ($_FILES[$attachment]['error'] == 0 && $_FILES[$attachment]['size'] > 0 && $_FILES[$attachment]['size'] <= 2 * 1024 * 1024 && in_array(substr($_FILES[$attachment]['name'], strrpos($_FILES[$attachment]['name'], '.') + 1), array_map('trim', explode(',', VIVVO_ALLOWED_EXTENSIONS))) && is_uploaded_file($_FILES[$attachment]['tmp_name'])) {
                         $filename = VIVVO_FS_INSTALL_ROOT . 'cache/' . md5(uniqid(mt_rand(), true)) . basename($_FILES[$attachment]['name']);
                         if (move_uploaded_file($_FILES[$attachment]['tmp_name'], $filename)) {
                             $files[] = array($filename, basename($_FILES[$attachment]['name']));
                         }
                     }
                 }
             }
             $headers['From'] = VIVVO_ADMINISTRATORS_EMAIL;
             $headers['Subject'] = "=?UTF-8?B?" . base64_encode($form->title) . "?=";
             if (!count($files)) {
                 $headers['Content-Type'] = "text/plain; charset=UTF-8;";
             } else {
                 require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/framework/PEAR/Mail/mime.php';
                 $mime = new Mail_mime();
                 $mime->setTXTBody($message);
                 foreach ($files as $file) {
                     $mime->addAttachment($file[0], 'application/octet-stream', $file[1]);
                 }
                 $message = $mime->get();
                 $headers = $mime->headers($headers);
                 foreach ($files as $file) {
                     @unlink($file[0]);
                 }
             }
             if (VIVVO_EMAIL_SMTP_PHP == 1) {
                 $mail_object = new Mail();
                 $mail_object->send($form->email, $headers, $message);
             } else {
                 $mail_options['driver'] = 'smtp';
                 $mail_options['host'] = VIVVO_EMAIL_SMTP_HOST;
                 $mail_options['port'] = VIVVO_EMAIL_SMTP_PORT;
                 $mail_options['localhost'] = 'localhost';
                 if (VIVVO_EMAIL_SMTP_PASSWORD != '' && VIVVO_EMAIL_SMTP_USERNAME != '') {
                     $mail_options['auth'] = true;
                     $mail_options['username'] = VIVVO_EMAIL_SMTP_USERNAME;
                     $mail_options['password'] = VIVVO_EMAIL_SMTP_PASSWORD;
                 } else {
                     $mail_options['auth'] = false;
                     $mail_options['username'] = '';
                     $mail_options['password'] = '';
                 }
                 $mail_object = Mail::factory('smtp', $mail_options);
                 $mail_object->send($form->email, $headers, $message);
             }
         }
         if ($form->message) {
             return $form->message;
         } else {
             return ' ';
         }
     }
 }
Ejemplo n.º 28
0
 function _list_output($assign_list = true)
 {
     $sm = vivvo_lite_site::get_instance();
     $pm = $sm->get_plugin_manager();
     require_once dirname(__FILE__) . '/poll.class.php';
     $content_template =& $this->load_template($this->_template_root . 'list.xml');
     $content_template->assign('PLUGIN_ROOT', $pm->plugins['poll']['root_dir']);
     $um = $sm->get_url_manager();
     if ($um->isset_param('action') && $um->isset_param('cmd') && $um->get_param('cmd') == 'add' && $sm->action_status === false) {
         $in_poll_question = $um->get_param_regexp('/^PLUGIN_POLL_/');
         $current_poll_question = new vivvo_poll_question(null, $in_poll_question);
         $content_template->assign('poll', $current_poll_question);
     } elseif ($um->isset_param('search_pid') && $um->get_param('search_pid') != '') {
         $poll_list = new vivvo_poll_question_list();
         $poll =& $poll_list->get_question($um->get_param('search_pid'));
         $content_template->assign('poll', $poll);
         $content_template->assign('answer_list', $poll->answer->list);
     } else {
         $poll_list = new vivvo_poll_question_list();
         $poll =& $poll_list->get_question_by_status(1);
         $content_template->assign('poll', $poll);
         $content_template->assign('answer_list', $poll->answer->list);
     }
     if ($um->isset_param('action') && $um->isset_param('cmd') && ($um->get_param('cmd') == 'delete' or $um->get_param('cmd') == 'deactivate' or $um->get_param('cmd') == 'activate')) {
         $content_template->assign('list_output', strval(1));
     }
     return $content_template;
 }
Ejemplo n.º 29
0
 /**
  * Populate object properties
  *
  * @param	array	$data
  * @param	bool	$dump
  * @return	bool
  */
 public function populate($data, $dump = null)
 {
     if ($status = parent::populate($data, $dump) and $this->user_id) {
         $user = vivvo_lite_site::get_instance()->get_user_manager()->get_user_by_id($this->user_id);
         if ($user) {
             $this->set_author($user->get_name());
             $this->set_www($user->get_www());
             $this->set_email($user->get_email_address());
             $this->author_href = $user->get_href();
             $this->avatar_url = $user->get_picture();
             if ($this->avatar_url and !preg_match('/^[^:\\/\\.\\?]+:/', $this->avatar_url)) {
                 $this->avatar_url = VIVVO_STATIC_URL . 'thumbnail.php?size=avatar&file=' . $this->avatar_url;
             }
         }
     }
     return $status;
 }
Ejemplo n.º 30
0
 /**
  * Returns chart data
  *
  * @param 	array		$params
  * @return	array
  */
 public function get_chart_data(array $params = array())
 {
     $sm = vivvo_lite_site::get_instance();
     if (!$sm->user) {
         return array();
     }
     $cache_key = 'ga_chart_data_' . md5(serialize($params));
     if (vivvo_cache::get_instance()->exists($cache_key)) {
         return vivvo_cache::get_instance()->get($cache_key);
     }
     $ga = vivvo_ga::get_instance(array('email' => VIVVO_GA_EMAIL, 'password' => VIVVO_GA_PASSWORD, 'profileId' => VIVVO_GA_PROFILEID, 'no_auth' => true));
     $report = $ga->getReport($params);
     if (empty($report)) {
         return array(0);
     }
     $data = array();
     empty($params['data_handler']) and $params['data_handler'] = '';
     $min = $max = 0;
     switch ($params['data_handler']) {
         case 'article_views':
             $labels = array();
             foreach ($report as $row) {
                 $labels[$row['dimensions']['ga:eventLabel']] = 1;
             }
             $labels = array_keys($labels);
             foreach ($report as $result) {
                 if (isset($result['dimensions']['ga:date']) && preg_match('/^(\\d{4})(\\d{2})(\\d{2})$/', $result['dimensions']['ga:date'], $part)) {
                     if (isset($result['dimensions']['ga:hour'])) {
                         $hour = $result['dimensions']['ga:hour'] << 0;
                         $format = 'd M Y H\\h';
                         $step = 3600;
                     } else {
                         $hour = 0;
                         $format = 'd M Y';
                         $step = 86400;
                     }
                     $time = mktime($hour, 0, 0, $part[2], $part[3], $part[1]);
                     $time > $max and $max = $time;
                     if ($time < $min or $min == 0) {
                         $min = $time;
                     }
                     $key = format_date(date('Y-m-d H:00:00', $time), $format);
                     if (!isset($data[$key])) {
                         $data[$key] = array_fill(0, count($labels), 0);
                     }
                     $data[$key][array_search($result['dimensions']['ga:eventLabel'], $labels)] = $result['metrics']['ga:totalEvents'];
                 }
             }
             break;
         case 'article_overall_stats':
         case 'article_stats':
             $labels = array();
             foreach ($report as $row) {
                 $labels[$row['dimensions']['ga:eventAction']] = 1;
             }
             $labels = array_keys($labels);
             foreach ($report as $result) {
                 if (isset($result['dimensions']['ga:date']) && preg_match('/^(\\d{4})(\\d{2})(\\d{2})$/', $result['dimensions']['ga:date'], $part)) {
                     if (isset($result['dimensions']['ga:hour'])) {
                         $hour = $result['dimensions']['ga:hour'] << 0;
                         $format = 'd M Y H\\h';
                         $step = 3600;
                     } else {
                         $hour = 0;
                         $format = 'd M Y';
                         $step = 86400;
                     }
                     $time = mktime($hour, 0, 0, $part[2], $part[3], $part[1]);
                     $time > $max and $max = $time;
                     if ($time < $min or $min == 0) {
                         $min = $time;
                     }
                     $key = format_date(date('Y-m-d H:00:00', $time), $format);
                     if (!isset($data[$key])) {
                         $data[$key] = array_fill(0, count($labels), 0);
                     }
                     $data[$key][array_search($result['dimensions']['ga:eventAction'], $labels)] = $result['metrics']['ga:totalEvents'];
                 }
             }
             break;
         default:
             foreach ($report as $result) {
                 if (isset($result['dimensions']['ga:date']) && preg_match('/^(\\d{4})(\\d{2})(\\d{2})$/', $result['dimensions']['ga:date'], $part)) {
                     if (isset($result['dimensions']['ga:hour'])) {
                         $hour = $result['dimensions']['ga:hour'] << 0;
                         $format = 'd M Y H\\h';
                         $step = 3600;
                     } else {
                         $hour = 0;
                         $format = 'd M Y';
                         $step = 86400;
                     }
                     $time = mktime($hour, 0, 0, $part[2], $part[3], $part[1]);
                     $time > $max and $max = $time;
                     if ($time < $min or $min == 0) {
                         $min = $time;
                     }
                     $key = format_date(date('Y-m-d H:00:00', $time), $format);
                     $data[$key] = array();
                     foreach ($result['metrics'] as $metric => $value) {
                         $data[$key][] = $value;
                     }
                 }
             }
     }
     $sample = reset($data);
     if (is_array($sample)) {
         $empty = array_fill(0, count($sample), 0);
     } else {
         $empty = 0;
     }
     for ($i = $min; $i < $max; $i += $step) {
         $key = format_date(date('Y-m-d H:00:00', $i), $format);
         if (!isset($data[$key])) {
             $data[$key] = $empty;
         }
     }
     uksort($data, array(self, 'date_string_compare'));
     $ret = array();
     foreach ($data as $date => $values) {
         array_unshift($values, $date);
         $ret[] = $values;
     }
     vivvo_cache::get_instance()->put($cache_key, $ret, null, VIVVO_GA_CACHE_PERIOD);
     return $ret;
 }