function full_page_cache_load() { list($url) = explode('?', CACHE_URL, 2); if (substr($url, -16) == '/cron_image.html' or substr($url, -15) == '/imagecode.html' or !defined('VIVVO_DB_HOST')) { return array('', array()); } $connection = @mysql_connect(VIVVO_DB_HOST, VIVVO_DB_USER, VIVVO_DB_PASSWORD) or die("Can't connect! " . mysql_error()); if (!mysql_select_db(VIVVO_DB_DATABASE, $connection)) { die("Error while connection to database. " . mysql_error()); } $res = mysql_query('SELECT * FROM ' . VIVVO_DB_PREFIX . "configuration WHERE variable_name LIKE 'VIVVO_CACHE_%'"); while ($row = mysql_fetch_assoc($res)) { @define($row['variable_name'], $row['variable_value']); } $kill_cache = isset($_GET['kill_cache']); if (!$kill_cache && isset($_COOKIE['kill_cache']) && $_COOKIE['kill_cache'] == '1') { $kill_cache = true; setcookie("kill_cache", false, 1, VIVVO_COOKIE_PATH, VIVVO_COOKIE_DOMAIN); } $output = ''; $uncached_boxes = array(); if (VIVVO_CACHE_ENABLE > 1 && !$kill_cache && !isset($_REQUEST['template_output']) && !isset($_REQUEST['action']) && !isset($_REQUEST['search_options']) && !preg_match('/\\?print$/', $_SERVER['REQUEST_URI'])) { class_exists('vivvo_cache') or (require VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/framework/vivvo_cache.php'); $cache_manager = vivvo_cache::get_instance(); if (!$cache_manager->exists(CACHE_URL)) { return array($output, $uncached_boxes); } $output = $cache_manager->get(CACHE_URL); echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n"; //<!--NoCache box/login.tpl--> if (VIVVO_CACHE_ENABLE == 2) { preg_match_all('/<!--NoCache ([a-zA-Z0-9_\\/\\.]+)-->/', $output, $arr); $uncached_boxes = array_unique($arr[1]); } else { $output = str_replace('$generation_time$', '0s', $output); if (preg_match('!^' . preg_quote(VIVVO_URL, '!') . '.+?/(\\d+)(-.+)?\\.html!', CACHE_URL, $match)) { $id = (int) $match[1]; if ($article = mysql_fetch_assoc($result = mysql_query('SELECT times_read,today_read,last_read,created FROM ' . VIVVO_DB_PREFIX . "articles_stats WHERE `article_id`={$id}"))) { mysql_free_result($result); $today = date('Y-m-d'); $last_read = date('Y-m-d H:i:s'); $times_read = (int) $article['times_read']; $today_read = (int) $article['today_read']; if (strtotime($article['last_read']) < strtotime($today)) { $today_read = 1; } else { $today_read++; } $times_read++; mysql_query('INSERT INTO ' . VIVVO_DB_PREFIX . "articles_stats\n\t\t\t\t\t\t\t(`article_id`, `last_read`, `times_read`, `today_read`, `updated`, `created`)\n\t\t\t\t\t\t\tVALUES ({$id}, '{$last_read}', {$times_read}, {$today_read}, 1, '{$article['created']}')\n\t\t\t\t\t\t\tON DUPLICATE KEY UPDATE\n\t\t\t\t\t\t\t\t`today_read`=IF(`last_read`<'{$today}', 1, `today_read`+1),\n\t\t\t\t\t\t\t\t`last_read`='{$last_read}',\n\t\t\t\t\t\t\t\t`times_read`=`times_read`+1,\n\t\t\t\t\t\t\t\t`updated`=1,\n\t\t\t\t\t\t\t\t`created`='{$article['created']}'"); } } echo $output; exit; } } $result = array($output, $uncached_boxes); return $result; }
$queries_no++; if (!mysql_query($queries)) { if ($debug_mode) { $messages[] = array('message' => mysql_error() . "({$queries})", 'type' => 'error'); } } else { $success_no++; } $queries = ''; $break_point = $read_line; } } } while (!feof($file) && microtime() - $start_time < 20 * 59 * 1000); if ($queries_no > 1 or $success_no > 1) { $messages[] = array('message' => $lang->get_value('LNG_ADMIN_BACKUP_RESTORED') . ' - ' . $success_no . ' / ' . $queries_no . ' ' . $lang->get_value('LNG_ADMIN_INSTRUCTIONS'), 'type' => 'action', 'result' => 'success'); vivvo_cache::get_instance()->delete_all(); } else { $messages[] = array('message' => $lang->get_value('LNG_ADMIN_NOTHING_TO_DO'), 'type' => 'action', 'result' => 'success'); } } } elseif (isset($_REQUEST['relate_articles'])) { $action = 'relate_articles'; if (!VIVVO_ARTICLE_RELATED_CATEGORY and !VIVVO_ARTICLE_RELATED_TAGS and !VIVVO_ARTICLE_RELATED_TOPIC) { $messages[] = array('message' => $lang->get_value('LNG_ADMIN_NOTHING_TO_DO'), 'type' => 'action', 'result' => 'success'); } else { $start = empty($_GET['restart']) ? 0 : (int) $_GET['restart']; $datetime = empty($_GET['dt']) ? date('Y-m-d 23:59:00') : $_GET['dt']; $count = empty($_GET['cnt']) ? -1 : (int) $_GET['cnt']; $db = $sm->get_db(); do { if ($count < 0) {
function set_list() { if (($list = vivvo_cache::get_instance()->get('categories')) !== false) { $this->list = $list; } else { $sql = 'SELECT * FROM ' . VIVVO_DB_PREFIX . 'categories ORDER BY order_num ASC'; $res = vivvo_lite_site::get_instance()->get_db()->query($sql); while ($row = $res->fetchRow(MDB2_FETCHMODE_ASSOC)) { $this->list[$row['id']] = new Categories(null, $row); $this->list[$row['id']]->set__category_list($this); } $res->free(); $this->list[0] = new Categories(); $this->list[0]->set__category_list($this); $this->list[0]->id = 0; $this->sort_subcategories(0); vivvo_cache::get_instance()->put('categories', $this->list); } $current_url = preg_replace('|/index(\\.\\d+)?\\.html$|', '/', CURRENT_URL); foreach ($this->list[0]->subcategories as $category) { $this->set_selected($category, $current_url); } }
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); }
function on_update($post_master = null) { vivvo_cache::get_instance()->delete('configuration'); }
/** * Creates new instance of Hybrid cache driver * * @param string $slow (optional) Name of "slow" driver, if null the best available driver will be choosen * @param string $fast (optional) Name of "fast" driver, if null the best available driver will be choosen * @param array $slow_params (optional) Initialization parameters for slow driver * @param array $fast_params (optional) Initialization parameters for fast driver * @return vivvo_cache_Hybrid */ public static function factory($slow = null, $fast = null, array $slow_params = array(), array $fast_params = array()) { if ($slow == null) { if (defined('VIVVO_SYSTEM_CACHE_DRIVER_SLOW')) { $slow = VIVVO_SYSTEM_CACHE_DRIVER_SLOW; } else { $priorities = array_keys(self::$slow_drivers); rsort($priorities); foreach ($priorities as $priority) { if (vivvo_cache::is_supported(self::$slow_drivers[$priority])) { $slow = self::$slow_drivers[$priority]; break; } } } } if ($fast == null) { if (defined('VIVVO_SYSTEM_CACHE_DRIVER_FAST')) { $fast = VIVVO_SYSTEM_CACHE_DRIVER_FAST; } else { $priorities = array_keys(self::$fast_drivers); rsort($priorities); foreach ($priorities as $priority) { if (vivvo_cache::is_supported(self::$fast_drivers[$priority])) { $fast = self::$fast_drivers[$priority]; break; } } } } return new self(array('slow' => vivvo_cache::get_instance($slow, $slow_params), 'fast' => vivvo_cache::get_instance($fast, $fast_params))); }
function sql_delete_list($sql_table, $where, $from = false, $commit = true) { if ($from) { $sql = 'DELETE FROM ' . $from . ' WHERE ' . $where; $sql_table = preg_replace('/^' . VIVVO_DB_PREFIX . '/', '', $from); } else { $sql = 'DELETE FROM `' . VIVVO_DB_PREFIX . $sql_table . '` WHERE ' . $where; } $db = vivvo_lite_site::get_instance()->get_db(); if ($commit == true || !$db->supports('transactions')) { $hook = 'db_' . $sql_table . '_delete_list'; if (vivvo_hooks_manager::call($hook . '_pre', array(&$this)) !== false) { $res = $db->query($sql); if (PEAR::isError($res)) { vivvo_lite_site::get_instance()->debug_push("sql:", $res->getMessage(), 1); return false; } vivvo_hooks_manager::call($hook . '_post', array(&$this)); } elseif (!vivvo_hooks_manager::get_status()) { return false; } } else { $this->stack[] = $sql; } vivvo_cache::get_instance()->cleanup(); return true; }
/** * Method to invoke on object data sql insert * * @param vivvo_post_master $post_master */ function on_insert($post_master) { vivvo_cache::get_instance()->cleanup(); }
/** * vivvo_lite_site class constructor. * * @return void */ public function __construct() { self::$instance = $this; vivvo_cache::get_instance(); if (!defined('VIVVO_INSTALLER')) { $this->set_db(); $this->start_session(); $this->define_global_param(); vivvo_hooks_manager::load(); //load a list of registered hook handlers $this->set_user_manager(); $this->set_modules(); $this->set_url_modules(); $this->set_user(); if (!$this->user) { $this->set_guest_group(); } if (isset($_GET['kill_cache']) && $this->user && $this->user->is_admin()) { vivvo_cache::get_instance()->delete_all(); } } if (defined('VIVVO_FRIENDY_URL') && VIVVO_FRIENDY_URL == 0) { if (!defined('VIVVO_SYSTEM_PROXY_URL')) { define('VIVVO_SYSTEM_PROXY_URL', VIVVO_URL . 'index.php/'); } } $this->set_url_manager(); if (!defined('VIVVO_INSTALLER')) { $this->set_header_manager(); $this->set_dump_manager(); $this->set_plugin_manager(); if (defined('VIVVO_ROOT_CATEGORY')) { $this->set_categories(VIVVO_ROOT_CATEGORY); } $this->define_global_param(); vivvo_chart::init(); $this->_url_manager->parse_url(); $this->set_lang(); $this->_plugin_manager->load_lang(); $this->set_template_dir(); $this->load_action_handlers(); } $this->define_proxy_url(); if (!defined('VIVVO_FS_THEME_ROOT')) { define('VIVVO_FS_THEME_ROOT', VIVVO_FS_TEMPLATE_ROOT); } }
function category_service(&$sm, $action, $command) { require_once dirname(__FILE__) . '/Categories.service.php'; $category_service = new category_service($sm); $um = $sm->get_url_manager(); $dm = $sm->get_dump_manager(); $lang = $sm->get_lang(); $category_id = $um->get_param('CATEGORY_id'); if ($command == 'add') { $in_category = $um->get_param_regexp('/^CATEGORY_/'); $response = $category_service->add_category($in_category); if ($response) { $dm->add_dump('info', 0, $lang->get_value($um->get_param('CATEGORY_redirect') ? 'LNG_INFO_LINK_ADD_SUCCESS' : 'LNG_INFO_CATEGORY_ADD_SUCCESS')); vivvo_cache::get_instance()->delete('categories'); vivvo_hooks_manager::call('category_add_postaction'); header('X-Vivvo-Action-Status: 1'); return true; } else { header('X-Vivvo-Action-Status: 0'); header('X-Vivvo-Action-Error: ' . json_encode($category_service->get_error_info())); return false; } } elseif ($command == 'delete') { $response = $category_service->delete_category($category_id); if ($response) { $dm->add_dump('info', 0, $lang->get_value($um->get_param('CATEGORY_redirect') ? 'LNG_INFO_LINK_DELETE_SUCCESS' : 'LNG_INFO_CATEGORY_DELETE_SUCCESS')); vivvo_cache::get_instance()->delete('categories'); vivvo_hooks_manager::call('category_delete_postaction'); header('X-Vivvo-Action-Status: 1'); return true; } else { header('X-Vivvo-Action-Status: 0'); header('X-Vivvo-Action-Error: ' . json_encode($category_service->get_error_info())); return false; } } elseif ($command == 'edit') { $category_id = $um->get_param('CATEGORY_id'); $in_category = $um->get_param_regexp('/^CATEGORY_/'); $response = $category_service->edit_category($category_id, $in_category); if ($response) { $dm->add_dump('info', 0, $lang->get_value($um->get_param('CATEGORY_redirect') ? 'LNG_INFO_LINK_EDIT_SUCCESS' : 'LNG_INFO_CATEGORY_EDIT_SUCCESS')); vivvo_cache::get_instance()->delete('categories'); vivvo_hooks_manager::call('category_edit_postaction'); header('X-Vivvo-Action-Status: 1'); return true; } else { header('X-Vivvo-Action-Status: 0'); header('X-Vivvo-Action-Error: ' . json_encode($category_service->get_error_info())); return false; } } elseif ($command == 'reorder') { $in_category = $um->get_param('category_list'); $in_category = json_decode($in_category, true); $response = $category_service->reorder_category(0, $in_category); if ($response !== false) { $dm->add_dump('info', 0, $lang->get_value('LNG_INFO_CATEGORY_REORDER_SUCCESS')); vivvo_cache::get_instance()->delete('categories'); vivvo_hooks_manager::call('category_reorder_postaction'); header('X-Vivvo-Action-Status: 1'); return true; } else { header('X-Vivvo-Action-Status: 0'); header('X-Vivvo-Action-Error: ' . json_encode($category_service->get_error_info())); return false; } } elseif ($command == 'deleteImage') { $category_id = $um->get_param('CATEGORY_id'); $response = $category_service->delete_image($category_id); if ($response) { $dm->add_dump('info', 0, $lang->get_value('LNG_INFO_CATEGORY_DELETE_IMAGE_SUCCESS')); vivvo_cache::get_instance()->delete('categories'); vivvo_hooks_manager::call('category_deleteImage_postaction'); header('X-Vivvo-Action-Status: 1'); return true; } else { header('X-Vivvo-Action-Status: 0'); header('X-Vivvo-Action-Error: ' . json_encode($category_service->get_error_info())); return false; } } return true; }
/** * Constructor creates cache driver by name. Parameters for * the specific driver may be deployed by the second argument. * * @param string|false The name of the driver * @return void * * TODO normalize case-sensitive names */ private function __construct($name = null, array $params = null) { // load configuration if (self::$conf === null) { // default configuration self::$conf = array('Cache_Lite' => array('cacheDir' => VIVVO_FS_INSTALL_ROOT . 'cache/', 'lifeTime' => null, 'automaticSerialization' => true, 'errorHandlingAPIBreak' => true, 'group' => 'vivvo_cache'), 'SQLite' => array('file' => VIVVO_FS_INSTALL_ROOT . 'cache/sqlite.db', 'schema' => 'CREATE TABLE cache( id VARCHAR(100) PRIMARY KEY, tags VARCHAR(255), lifetime INTEGER, data TEXT);'), 'MySQL' => array('host' => VIVVO_DB_HOST, 'username' => VIVVO_DB_USER, 'password' => VIVVO_DB_PASSWORD, 'database' => VIVVO_DB_DATABASE, 'data_table' => VIVVO_DB_PREFIX . 'cache', 'tags_table' => VIVVO_DB_PREFIX . 'cache_tags')); if (defined('VIVVO_SYSTEM_CACHE_DRIVER_PARAMS')) { self::$conf = array_merge(self::$conf, json_decode(VIVVO_SYSTEM_CACHE_DRIVER_PARAMS, true)); } } $name = $name === null ? VIVVO_SYSTEM_CACHE_DRIVER : trim($name); $driver = 'vivvo_cache_' . $name; $file = VIVVO_FS_CACHE_DRIVER . $name . '.php'; if (!file_exists($file)) { throw new CacheDriverException($driver, 'Driver file could not be found.'); } require_once $file; // Passed params overwrites those in conf.cache.php since they are on-demand $params = $params !== null ? array_merge(self::$conf[$name], $params) : self::$conf[$name]; is_array($params) or $params = array(); // Create our cache driver self::$drivers[$name] = new $driver($params); if (!self::$drivers[$name] instanceof vivvo_cache_driver) { throw new CacheDriverException($driver, 'Driver class does not implement vivvo_cache_driver interface.'); } }
/** * Reutrn module template output * * @return string */ function get_output() { if ($this->cache && $this->cache_output) { return $this->cache_output; } else { if ($this->_template instanceof template) { $output = $this->_template->get_output(); } else { $output = $this->output; } if ($this->cache) { $class = get_class($this); vivvo_cache::get_instance()->put($this->_cache_id . '!' . $class, $output, array($class), VIVVO_MODULE_CACHE_TIME); vivvo_lite_site::get_instance()->debug_push('Box cache:', 'Save ' . $class); } return $output; } }
/** * Set configuration data * * @param string $name Variable name * @param string $property Variable property name * @param string $value Variable value * @param string $module Module name * @param string $reg_exp Variable value restriction * @param string $doamin_id Doamin restriction * * @return boolean True on success, false on fail */ function set_conf($name, $property = '', $value, $module = '', $reg_exp = '', $domain_id = 1) { require_once VIVVO_FS_FRAMEWORK . 'vivvo_preference.php'; if (!$this->_post_master) { $this->set__post_master(); } $config_list = new preferences_list(); $conf = $config_list->get_preference_by_all_variable($name, '', '', ''); if ($conf) { if ($property != '') { $conf->set_variable_property($property); } $conf->set_variable_value($value); if ($module != '') { $conf->set_module($module); } if ($reg_exp != '') { $conf->set_reg_exp($reg_exp); } $conf->set_domain_id($domain_id); $this->_post_master->set_data_object($conf); $this->_post_master->sql_update(); vivvo_cache::get_instance()->delete('configuration'); } else { $this->add_conf($name, $property, $value, $module, $reg_exp, $domain_id); } }