/**
  * 
  * Clears the config cache and loads it
  * @return boolean
  */
 public function reload_config()
 {
     // Clears cached data
     Core::cache('config_db', NULL, 0);
     //load config
     return $this->load_config();
 }
示例#2
0
 /**
  * Execute the current query on the given database. Edited to use the cache instance.
  *
  * @param   mixed    $db  Database instance or name of instance
  * @param   string   result object classname, TRUE for stdClass or FALSE for array
  * @param   array    result object constructor arguments
  * @return  object   Database_Result for SELECT queries
  * @return  mixed    the insert id for INSERT queries
  * @return  integer  number of affected rows for all other queries
  */
 public function execute($db = NULL, $as_object = NULL, $object_params = NULL)
 {
     if (!is_object($db)) {
         // Get the database instance
         $db = Database::instance($db);
     }
     if ($as_object === NULL) {
         $as_object = $this->_as_object;
     }
     if ($object_params === NULL) {
         $object_params = $this->_object_params;
     }
     // Compile the SQL query
     $sql = $this->compile($db);
     if ($this->_lifetime !== NULL and $this->_type === Database::SELECT) {
         // Set the cache key based on the database instance name and SQL
         $cache_key = 'Database::query("' . $db . '", "' . $sql . '")';
         // Read the cache first to delete a possible hit with lifetime <= 0
         if (($result = Core::cache($cache_key, NULL, $this->_lifetime)) !== NULL and !$this->_force_execute) {
             // Return a cached result
             return new Database_Result_Cached($result, $sql, $as_object, $object_params);
         }
     }
     // Execute the query
     $result = $db->query($this->_type, $sql, $as_object, $object_params);
     if (isset($cache_key) and $this->_lifetime > 0) {
         // Cache the result array
         Core::cache($cache_key, $result->as_array(), $this->_lifetime);
     }
     return $result;
 }
示例#3
0
 /**
  * Automatically executed before the widget action. Can be used to set
  * class properties, do authorization checks, and execute other custom code.
  *
  * @return  void
  */
 public function before()
 {
     //try to get the Info from the cache
     $info = Core::cache(Route::url('sitejson'));
     //not cached :(
     if ($info === NULL) {
         $info = json_decode(Core::curl_get_contents(Route::url('sitejson')));
         Core::cache(Route::url('sitejson'), $info);
     }
     $this->info = $info;
 }
示例#4
0
 /**
  * Automatically executed before the widget action. Can be used to set
  * class properties, do authorization checks, and execute other custom code.
  *
  * @return  void
  */
 public function before()
 {
     //try to get the RSS from the cache
     $rss = Core::cache($this->rss_url, NULL, $this->rss_expire);
     //not cached :(
     if ($rss === NULL) {
         $rss = Feed::parse($this->rss_url, $this->rss_limit);
         Core::cache($this->rss_url, $rss, $this->rss_expire);
     }
     $this->rss_items = $rss;
 }
示例#5
0
 /**
  * Parses a remote feed into an array.
  *
  * @param   string  $feed   remote feed URL
  * @param   integer $limit  item limit to fetch
  * @param   integer $cache_expire_time in seconds when cache expires
  * @return  array
  */
 public static function parse($feed, $limit = 0, $cache_expire_time = NULL)
 {
     //in case theres no expire time set to 24h
     if ($cache_expire_time === NULL) {
         $cache_expire_time = 24 * 60 * 60;
     }
     // Check if SimpleXML is installed
     if (!function_exists('simplexml_load_file')) {
         throw new Kohana_Exception('SimpleXML must be installed!');
     }
     // Make limit an integer
     $limit = (int) $limit;
     // Disable error reporting while opening the feed
     $error_level = error_reporting(0);
     // Allow loading by filename or raw XML string
     if (Valid::url($feed)) {
         //mod! force usage of curl with timeout and cached!
         $feed_result = Core::cache($feed, NULL, $cache_expire_time);
         //not cached :(
         if ($feed_result === NULL) {
             $feed_result = Core::curl_get_contents($feed, 5);
             Core::cache($feed, $feed_result, $cache_expire_time);
         }
         $feed = $feed_result;
     } elseif (is_file($feed)) {
         // Get file contents
         $feed = file_get_contents($feed);
     }
     // Load the feed
     $feed = simplexml_load_string($feed, 'SimpleXMLElement', LIBXML_NOCDATA);
     // Restore error reporting
     error_reporting($error_level);
     // Feed could not be loaded
     if ($feed === FALSE) {
         return array();
     }
     $namespaces = $feed->getNamespaces(TRUE);
     // Detect the feed type. RSS 1.0/2.0 and Atom 1.0 are supported.
     $feed = isset($feed->channel) ? $feed->xpath('//item') : $feed->entry;
     $i = 0;
     $items = array();
     foreach ($feed as $item) {
         if ($limit > 0 and $i++ === $limit) {
             break;
         }
         $item_fields = (array) $item;
         // get namespaced tags
         foreach ($namespaces as $ns) {
             $item_fields += (array) $item->children($ns);
         }
         $items[] = $item_fields;
     }
     return $items;
 }
示例#6
0
 public function action_index()
 {
     //if not god redirect him to the normal profile page
     if (Auth::instance()->get_user()->id_role != Model_Role::ROLE_ADMIN) {
         Request::current()->redirect(Route::url('oc-panel', array('controller' => 'profile', 'action' => 'index')));
     }
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Welcome')));
     $this->template->title = 'Welcome';
     //try to get the RSS from the cache
     $rss_url = 'http://feeds.feedburner.com/OpenClassifieds';
     $rss = Core::cache($rss_url, NULL, 3 * 24 * 60 * 60);
     //not cached :(
     if ($rss === NULL) {
         $rss = Feed::parse($rss_url, 10);
         Core::cache($rss_url, $rss, 3 * 24 * 60 * 60);
     }
     $this->template->content = View::factory('oc-panel/home', array('rss' => $rss));
 }
示例#7
0
 public function action_info()
 {
     //try to get the info from the cache
     $info = Core::cache('action_info', NULL);
     //not cached :(
     if ($info === NULL) {
         $products = new Model_product();
         $total_products = $products->count_all();
         $last_product = $products->select('created')->order_by('created', 'desc')->limit(1)->find();
         $last_product = $last_product->created;
         $products = new Model_product();
         $first_product = $products->select('created')->order_by('created', 'asc')->limit(1)->find();
         $first_product = $first_product->created;
         $views = new Model_Visit();
         $total_views = $views->count_all();
         $users = new Model_User();
         $total_users = $users->count_all();
         $info = array('site_url' => Core::config('general.base_url'), 'site_name' => Core::config('general.site_name'), 'site_description' => Core::config('general.site_description'), 'created' => $first_product, 'updated' => $last_product, 'email' => Core::config('email.notify_email'), 'version' => Core::VERSION, 'theme' => Core::config('appearance.theme'), 'theme_mobile' => Core::config('appearance.theme_mobile'), 'charset' => Kohana::$charset, 'timezone' => Core::config('i18n.timezone'), 'locale' => Core::config('i18n.locale'), 'currency' => '', 'products' => $total_products, 'views' => $total_views, 'users' => $total_users);
         Core::cache('action_info', $info);
     }
     $this->response->headers('Content-type', 'application/javascript');
     $this->response->body(json_encode($info));
 }
示例#8
0
 /**
  * get geocode lat/lon points for given address from google
  * 
  * @param string $address
  * @return bool|array false if can't be geocoded, array or geocdoes if successful
  */
 public static function address_coords($address)
 {
     $url = 'http://maps.google.com/maps/api/geocode/json?sensor=false&address=' . rawurlencode($address);
     //try to get the json from the cache
     $coords = Core::cache($url);
     //not cached :(
     if ($coords === NULL) {
         $coords = FALSE;
         //get contents from google
         if ($result = core::curl_get_contents($url)) {
             $result = json_decode($result);
             //not found :()
             if ($result->status != "OK") {
                 $coords = FALSE;
             } else {
                 $coords['lat'] = $result->results[0]->geometry->location->lat;
                 $coords['lon'] = $result->results[0]->geometry->location->lng;
             }
         }
         //save the json
         Core::cache($url, $coords, strtotime('+7 day'));
     }
     return $coords;
 }
 /**
  * returns all the parents ids, used to count ads
  * @return array
  */
 public function get_parents_ids()
 {
     if ($this->loaded()) {
         //name used in the cache for storage
         $cache_name = 'get_parents_ids_location_' . $this->id_location;
         if (($ids_parents = Core::cache($cache_name)) === NULL) {
             //array that contains all the parents as keys (1,2,3,4,..)
             $ids_parents = array();
             if ($this->id_location_parent != 1) {
                 //adding the parent only if loaded
                 if ($this->parent->loaded()) {
                     $ids_parents[] = $this->parent->id_location;
                     $ids_parents = array_merge($ids_parents, $this->parent->get_parents_ids());
                     //recursive
                 }
                 //removing repeated values
                 $ids_parents = array_unique($ids_parents);
             }
             //cache the result is expensive!
             Core::cache($cache_name, $ids_parents);
         }
         return $ids_parents;
     }
     //not loaded
     return NULL;
 }
示例#10
0
 /**
  * 设置通用魔术方法函数
  */
 public static function setMagicGet($var, $conf)
 {
     static $control_auto_get = array();
     if (isset($control_auto_get[$var])) {
         return $control_auto_get[$var];
     }
     if ($var == 'tpl') {
         $tpl_name = 'Tpl' . ucfirst($conf['template_syntax']);
         $driver_obj = new $tpl_name($conf);
         $control_auto_get[$var] = $driver_obj;
         unset($control_auto_get, $tpl_name);
         return $driver_obj;
     } elseif (substr($var, -3, 3) == '_db') {
         $var_arr = explode("_", $var);
         $dbconf = $conf['db'][$var_arr[0]];
         $driver_obj = Core::db($dbconf);
         $control_auto_get[$var] = $driver_obj;
         unset($control_auto_get, $var_arr, $var, $dbconf);
         return $driver_obj;
     } else {
         if ($var == 'file') {
             return Core::cache($var, $conf);
         }
         $var_arr = explode("_", $var);
         $count = count($var_arr);
         if ($count < 2) {
             throw new Exception("{$var} error !");
         }
         if (in_array($var_arr[0], $conf['support_cache'])) {
             return Core::cache($var_arr[0], $conf, $var_arr[1]);
         }
         $table = substr($var, strlen($var_arr[0] . '_'));
         $driver_obj = Core::model($var_arr[0], $table, $conf);
         $control_auto_get[$var] = $driver_obj;
         unset($control_auto_get, $count, $var_arr, $var);
         return $driver_obj;
     }
 }
示例#11
0
 /**
  * returns all the siblings ids+ the idlocation, used to filter the ads
  * @return array
  */
 public function get_siblings_ids()
 {
     if ($this->loaded()) {
         //name used in the cache for storage
         $cache_name = 'get_siblings_ids_lcoations_' . $this->id_location;
         if (($ids_siblings = Core::cache($cache_name)) === NULL) {
             //array that contains all the siblings as keys (1,2,3,4,..)
             $ids_siblings = array();
             //we add himself as we use the clause IN on the where
             $ids_siblings[] = $this->id_location;
             $locations = new self();
             $locations = $locations->where('id_location_parent', '=', $this->id_location)->cached()->find_all();
             foreach ($locations as $location) {
                 $ids_siblings[] = $location->id_location;
                 //adding his children recursevely if they have any
                 if (count($siblings_locs = $location->get_siblings_ids()) > 1) {
                     $ids_siblings = array_merge($ids_siblings, $siblings_locs);
                 }
             }
             //removing repeated values
             $ids_siblings = array_unique($ids_siblings);
             //cache the result is expensive!
             Core::cache($cache_name, $ids_siblings);
         }
         return $ids_siblings;
     }
     //not loaded
     return NULL;
 }
示例#12
0
 /**
  * deletes from cache a fragment
  * @param  string $name 
  * @return bool       
  */
 public static function delete_fragment($name)
 {
     return Core::cache(self::fragment_name($name), NULL, 0);
 }
示例#13
0
 /**
  * 设置通用魔术方法函数
  */
 public static function setMagicGet($var, $conf)
 {
     static $control_auto_get = array();
     if (isset($control_auto_get[$var])) {
         return $control_auto_get[$var];
     }
     switch ($var) {
         case 'tpl':
             $tpl_name = 'Tpl' . ucfirst($conf['template_syntax']);
             $driver_obj = new $tpl_name($conf);
             $control_auto_get[$var] = $driver_obj;
             return $driver_obj;
         case 'file':
             return Core::cache($var, $conf);
         default:
             @(list($type, $flag) = explode('_', $var, 2));
             if (empty($type) or empty($flag)) {
                 throw new Exception("{$var} error !");
             }
             if ($flag == 'db') {
                 $dbconf = $conf['db'][$type];
                 $driver_obj = Core::db($dbconf);
                 $control_auto_get[$var] = $driver_obj;
                 return $driver_obj;
             } elseif (in_array($type, $conf['support_cache'])) {
                 return Core::cache($type, $conf, $flag);
             } else {
                 $driver_obj = Core::model($type, $flag, $conf);
                 $control_auto_get[$var] = $driver_obj;
                 return $driver_obj;
             }
     }
 }
示例#14
0
文件: forum.php 项目: demoic/common
 /**
  * we get the forums in an array and a multidimensional array to know the deep
  * @return array 
  */
 public static function get_all()
 {
     $forums = new self();
     $forums = $forums->order_by('order', 'asc')->find_all()->cached()->as_array('id_forum');
     if (($forums_arr = Core::cache('forums_arr')) === NULL) {
         //transform the forums to an array
         $forums_arr = array();
         foreach ($forums as $forum) {
             $forums_arr[$forum->id_forum] = array('name' => $forum->name, 'order' => $forum->order, 'id_forum_parent' => $forum->id_forum_parent, 'parent_deep' => $forum->parent_deep, 'seoname' => $forum->seoname, 'id' => $forum->id_forum);
         }
         Core::cache('forums_arr', $forums_arr);
     }
     if (($forums_m = Core::cache('forums_m')) === NULL) {
         //for each forum we get his siblings
         $forums_s = array();
         foreach ($forums as $forum) {
             $forums_s[$forum->id_forum_parent][] = $forum->id_forum;
         }
         //last build multidimensional array
         if (count($forums_s) > 0) {
             $forums_m = self::multi_forums($forums_s);
         } else {
             $forums_m = array();
         }
         Core::cache('forums_m', $forums_m);
     }
     //array of forum info and array order
     return array($forums_arr, $forums_m);
 }
示例#15
0
 /**
  * 
  * generate sitemap
  */
 public static function generate($force = FALSE)
 {
     //start time
     $start_time = microtime(TRUE);
     /**
      * only generate the sitemap if older than XXX
      */
     if (time() >= Core::cache('sitemap_next') or $force == TRUE) {
         $site_url = Core::config('general.base_url');
         // include class
         require Kohana::find_file('vendor/sitemap', 'SitemapGenerator');
         // create object
         $sitemap = new SitemapGenerator($site_url, DOCROOT);
         // will create also compressed (gzipped) sitemap
         $sitemap->createGZipFile = TRUE;
         // determine how many urls should be put into one file
         $sitemap->maxURLsPerSitemap = 10000;
         // sitemap file name
         $sitemap->sitemapFileName = 'sitemap.xml';
         // sitemap index file name
         $sitemap->sitemapIndexFileName = 'sitemap-index.xml';
         // robots file name
         //$sitemap->robotsFileName = 'robots.txt';
         //users
         $users = new Model_User();
         $users = $users->select('seoname')->select('created')->where('status', '=', Model_User::STATUS_ACTIVE)->find_all();
         foreach ($users as $user) {
             $url = Route::url('profile', array('seoname' => $user->seoname));
             $sitemap->addUrl($url, date('c', Date::mysql2unix($user->created)), 'monthly', '0.5');
         }
         //pages CMS
         $pages = new Model_Content();
         $pages = $pages->select('seotitle')->where('type', '=', 'page')->where('status', '=', '1')->find_all();
         foreach ($pages as $page) {
             $url = Route::url('page', array('seotitle' => $page->seotitle));
             $sitemap->addUrl($url, date('c', Date::mysql2unix($page->created)), 'monthly', '0.5');
         }
         //locations
         $locs = new Model_Location();
         $locs = $locs->select('seoname')->where('id_location', '!=', 1)->find_all();
         //categories
         $cats = new Model_Category();
         $cats = $cats->select('seoname')->where('id_category', '!=', 1)->find_all();
         foreach ($cats as $cat) {
             $url = Route::url('list', array('category' => $cat->seoname));
             $sitemap->addUrl($url, date('c'), 'daily', '0.7');
             //adding the categories->locations
             foreach ($locs as $loc) {
                 $url = Route::url('list', array('category' => $cat->seoname, 'location' => $loc->seoname));
                 $sitemap->addUrl($url, date('c'), 'weekly', '0.5');
             }
         }
         //all the ads
         $ads = DB::select('a.seotitle')->select(array('c.seoname', 'category'))->from(array('ads', 'a'))->join(array('categories', 'c'), 'INNER')->on('a.id_category', '=', 'c.id_category')->where('a.status', '=', Model_Ad::STATUS_PUBLISHED)->as_object()->execute();
         foreach ($ads as $a) {
             $url = Route::url('ad', array('category' => $a->category, 'seotitle' => $a->seotitle));
             $sitemap->addUrl($url, date('c'), 'monthly', '0.5');
         }
         //all the blog posts
         $sitemap->addUrl(Route::url('blog'), date('c'), 'daily', '0.7');
         $posts = new Model_Post();
         $posts = $posts->where('status', '=', 1)->order_by('created', 'desc')->find_all();
         foreach ($posts as $post) {
             $url = Route::url('blog', array('seotitle' => $post->seotitle));
             $sitemap->addUrl($url, date('c'), 'monthly', '0.5');
         }
         try {
             // create sitemap
             $sitemap->createSitemap();
             // write sitemap as file
             $sitemap->writeSitemap();
             // update robots.txt file
             //$sitemap->updateRobots();
             // submit sitemaps to search engines
             $result = $sitemap->submitSitemap();
             // shows each search engine submitting status
             // echo '<pre>'.print_r($result,1).'</pre>';
         } catch (Exception $exc) {
             echo $exc->getTraceAsString();
         }
         $ret = 'Memory peak ' . round(memory_get_peak_usage() / (1024 * 1024), 2) . ' MB -';
     } else {
         $ret = __('No sitemap generated');
     }
     //setting the new cache to know when would be next generated
     Core::cache('sitemap_last', time());
     Core::cache('sitemap_next', time() + 24 * 60 * 60);
     //24 hours
     return $ret . ' Time: ' . round(microtime(TRUE) - $start_time, 2) . 's';
 }
示例#16
0
		<h1><?php 
echo __('Sitemap');
?>
</h1>
    <p><?php 
echo __('Last time generated');
?>
 <?php 
echo Date::unix2mysql(Core::cache('sitemap_last'));
?>
</p>
    <p><?php 
echo __('Next sitemap');
?>
 <?php 
echo Date::unix2mysql(Core::cache('sitemap_next'));
?>
</p>
    <a class="btn btn-primary pull-right" href="<?php 
echo Route::url('oc-panel', array('controller' => 'tools', 'action' => 'sitemap'));
?>
?force=1">
      <?php 
echo __('Generate');
?>
</a>
	</div>

	<form class="well form-horizontal"  method="post" action="<?php 
echo Route::url('oc-panel', array('controller' => 'tools', 'action' => 'sitemap'));
?>
示例#17
0
 public function getCache()
 {
     return Core::cache($this->conf['cache_type'], $this->conf);
 }
示例#18
0
文件: core.php 项目: azorpax/common
 /**
  * get market from json hosted currently at our site
  * @param  boolean $reload  
  * @return void
  */
 public static function get_market($reload = FALSE)
 {
     $market_url = Kohana::$environment !== Kohana::DEVELOPMENT ? 'market.' . Core::DOMAIN . '' : 'eshop.lo';
     $market_url = 'http://' . $market_url . '/api/products';
     //try to get the json from the cache
     $market = Core::cache($market_url);
     //not cached :(
     if ($market === NULL or $reload === TRUE) {
         $market = Core::curl_get_contents($market_url . '?r=' . time());
         //save the json
         Core::cache($market_url, $market, strtotime('+1 day'));
     }
     return json_decode($market, TRUE);
 }