Gleez Core class
Class declared in MODPATH/gleez/classes/gleez.php on line 3.
string(7) "0.9.9.1"string(15) "Turdus obscurus"boolean $installedGleez installed?
bool TRUE
string $themeDefault theme name
string(5) "fluid"boolean $_ginitHas Gleez::_ginit been called?
bool TRUE
Check to see if an IP address has been blocked and deny access to blocked IP addresses
public static function block_ips()
{
$blocked_ips = Kohana::$config->load('site.blocked_ips', NULL);
$ip = Request::$client_ip;
if (!empty($blocked_ips) AND in_array($ip, preg_split("/[\s,]+/",$blocked_ips)))
{
Kohana::$log->add(LOG::INFO, 'Sorry, your ip address (:ip) has been banned.', array(':ip' => $ip));
throw new HTTP_Exception_403('Sorry, your ip address (:ip) has been banned.', array(':ip' => $ip));
}
}
APC cache
Provides an opcode based cache.
string
$name
required - Name of the cachemixed
$data
= NULL - Data to cache [Optional]integer
$lifetime
= integer 3600 - Number of seconds the cache is valid for [Optional]mixed - For gettingboolean - For settingpublic static function cache($name, $data = NULL, $lifetime = 3600)
{
// Enable cache only in production environment
if (Kohana::$environment !== Kohana::PRODUCTION)
{
Kohana::$log->add(LOG::DEBUG, 'Gleez Caching only available in production');
return FALSE;
}
// Check for existence of the APC extension
if ( ! extension_loaded('apc'))
{
Kohana::$log->add(LOG::INFO, 'PHP APC extension is not available');
return FALSE;
}
if (isset($_SERVER['HTTP_HOST']))
{
$name .= $_SERVER['HTTP_HOST'];
}
if (is_null($data))
{
try
{
// Return the cache
return apc_fetch(self::_sanitize_id($name));
}
catch (Exception $e)
{
// Cache is corrupt, let return happen normally
Kohana::$log->add(LOG::ERROR, "Cache name: `:name` is corrupt", array(
':name' => $name
));
}
// Cache not found
return FALSE;
}
else
{
try
{
return apc_store(self::_sanitize_id($name), $data, $lifetime);
}
catch (Exception $e)
{
// Failed to write cache
return FALSE;
}
}
}
Delete all known cache's we set
public static function cache_delete()
{
// Clear any cache for sure
Cache::instance('modules')->delete_all();
Cache::instance('menus')->delete_all();
Cache::instance('widgets')->delete_all();
Cache::instance('feeds')->delete_all();
Cache::instance('page')->delete_all();
Cache::instance('blog')->delete_all();
// For each cache instance
foreach (Cache::$instances as $group => $instance)
{
$instance->delete_all();
}
}
Check the supplied integer in given range
integer
$min
required - $mininteger
$max
required - $maxinteger
$from_user
required - Supplied intigerbooleanpublic static function check_in_range($min, $max, $from_user)
{
// Convert to int
$start = (int) $min;
$end = (int) $max;
$user = (int) $from_user;
// Check that user data is between start & end
return (($user > $start) AND ($user < $end));
}
Check for maintenance_mode
If Gleez is in maintenance mode, then force all non-admins to get routed to a "This site is down for maintenance" page.
public static function maintenance_mode()
{
$maintenance_mode = Kohana::$config->load('site.maintenance_mode', false);
$request = Request::initial();
if ($maintenance_mode AND ($request instanceof Request) AND ($request->controller() != 'user' AND $request->action() != 'login') AND !ACL::check('administer site') AND $request->controller() != 'media')
{
Kohana::$log->add(LOG::INFO, 'Site running in Maintenance Mode');
throw new HTTP_Exception_503('Site running in Maintenance Mode');
}
}
Runs the Gleez environment
public static function ready()
{
if (self::$_ginit)
{
// Do not allow execution twice
return;
}
/**
* Gleez is now initialized?
* @var boolean
*/
self::$_ginit = TRUE;
/**
* Default cookie salt
* @var string
*/
Cookie::$salt = Kohana::$config->load('cookie.salt');
/**
* Default cookie lifetime
* @var string
*/
Cookie::$expiration = Kohana::$config->load('cookie.lifetime');
/**
* Check database config file exist or not
* @var boolean
*/
Gleez::$installed = file_exists(APPPATH.'config/database.php');
if (Gleez::$installed)
{
// Database config reader and writer
Kohana::$config->attach(new Config_Database);
}
// I18n settings
self::_set_locale();
if (Kohana::$environment !== Kohana::DEVELOPMENT)
{
Kohana_Exception::$error_view = 'errors/stack';
}
/**
* Disable the kohana powered headers
* @var boolean
*/
Kohana::$expose = FALSE;
/**
* If database.php doesn't exist, then we assume that the Gleez is not
* properly installed and send to the installer.
*/
if ( ! Gleez::$installed)
{
Session::$default = 'cookie';
Kohana_Exception::$error_view = 'kohana/error';
// Static file serving (CSS, JS, images)
Route::set('install/media', 'media(/<file>)', array(
'file' => '.+'
))
->defaults(array(
'controller' => 'install',
'action' => 'media',
'file' => NULL,
'directory' => 'install'
));
Route::set('install', '(install(/<action>))', array(
'action' => 'index|systemcheck|database|install|finalize'
))
->defaults(array(
'controller' => 'install',
'directory' => 'install'
));
return;
}
// Set the default session type
Session::$default = Kohana::$config->load('site.session_type');
// Initialize Gleez modules
Module::load_modules(FALSE);
// Load the active theme(s)
Theme::load_themes();
}
List of route types
Route name used for creating alias and term/tag routes
array - Typespublic static function types()
{
$states = array(
'post' => __('Post'),
'page' => __('Page'),
'blog' => __('Blog'),
'forum' => __('Forum'),
'book' => __('Book'),
'user' => __('User')
);
$values = Module::action('gleez_types', $states);
return $values;
}
Replaces troublesome characters with underscores.
// Sanitize a cache id $id = $this->_sanitize_id($id);
string
$id
required - Id of cache to sanitizestringprotected static function _sanitize_id($id)
{
// Change slashes and spaces to underscores
return str_replace(array(
'/',
'\\',
' '
), '_', $id);
}
I18n settings
By default - English
protected static function _set_locale()
{
// First check cookies
$locale = Cookie::get('locale');
// If cookies are empty read accept_language
if (empty($locale) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
{
$locale = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
}
//Check if the locale is available or not
$installed_locales = in_array($locale, Kohana::$config->load('site.installed_locales'));
if ( ! $installed_locales)
{
// By default - English
$locale = 'en';
}
// Setting lang
I18n::$lang = $locale;
Cookie::set('locale', $locale);
}
This function searches for the file that first matches the specified file name and returns its path.
string
$file
required - The file namestring - The file pathprotected static function find_file_custom($file)
{
if (file_exists($file))
{
return $file;
}
$uri = THEMEPATH . $file;
if (file_exists($uri))
{
return $uri;
}
$uri = APPPATH . $file;
if (file_exists($uri))
{
return $uri;
}
$modules = Kohana::modules();
foreach ($modules as $module)
{
$uri = $module . $file;
if (file_exists($uri))
{
return $uri;
}
}
$uri = SYSPATH . $file;
if (file_exists($uri))
{
return $uri;
}
throw new Kohana_Exception('Unable to locate file `:file`. No file exists with the specified file name.', array(
':file' => $file
));
}