Modules

Gleez
extends Gleez_Core

Gleez Core class

package
Gleez\Core
version
0.9.9.1
author
Sandeep Sangamreddi - Gleez
copyright
© 2011-2013 Gleez Technologies
license
http://gleezcms.org/license Gleez CMS License

Class declared in MODPATH/gleez/classes/gleez.php on line 3.

Constants

VERSION

string(7) "0.9.9.1"

CODENAME

string(15) "Turdus obscurus"

Properties

public static boolean $installed

Gleez installed?

bool TRUE

public static string $theme

Default theme name

string(5) "fluid"

protected static boolean $_ginit

Has Gleez::_ginit been called?

bool TRUE

Methods

public static block_ips( ) (defined in Gleez_Core)

Check to see if an IP address has been blocked and deny access to blocked IP addresses

Tags

Source Code

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));
	}
}

public static cache( string $name [, mixed $data = NULL , integer $lifetime = integer 3600 ] ) (defined in Gleez_Core)

APC cache

Provides an opcode based cache.

Parameters

  • string $name required - Name of the cache
  • mixed $data = NULL - Data to cache [Optional]
  • integer $lifetime = integer 3600 - Number of seconds the cache is valid for [Optional]

Tags

  • Todo - add more support for more cache drivers

Return Values

  • mixed - For getting
  • boolean - For setting

Source Code

public 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;
		}
	}
}

public static cache_delete( ) (defined in Gleez_Core)

Delete all known cache's we set

Source Code

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();
	}
}

public static check_in_range( integer $min , integer $max , integer $from_user ) (defined in Gleez_Core)

Check the supplied integer in given range

Parameters

  • integer $min required - $min
  • integer $max required - $max
  • integer $from_user required - Supplied intiger

Return Values

  • boolean

Source Code

public 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));
}

public static maintenance_mode( ) (defined in Gleez_Core)

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.

Tags

Source Code

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');
	}
}

public static ready( ) (defined in Gleez_Core)

Runs the Gleez environment

Source Code

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();
}

public static types( ) (defined in Gleez_Core)

List of route types

Route name used for creating alias and term/tag routes

Tags

Return Values

  • array - Types

Source Code

public 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;
}

protected static _sanitize_id( string $id ) (defined in Gleez_Core)

Replaces troublesome characters with underscores.

// Sanitize a cache id $id = $this->_sanitize_id($id);

Parameters

  • string $id required - Id of cache to sanitize

Return Values

  • string

Source Code

protected static function _sanitize_id($id)
{
	// Change slashes and spaces to underscores
	return str_replace(array(
		'/',
		'\\',
		' '
	), '_', $id);
}

protected static _set_locale( ) (defined in Gleez_Core)

I18n settings

By default - English

Tags

Source Code

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);
}

protected static find_file_custom( string $file ) (defined in Gleez_Core)

This function searches for the file that first matches the specified file name and returns its path.

Parameters

  • string $file required - The file name

Tags

Return Values

  • string - The file path

Source Code

protected 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
	));
}
Documentation comments powered by Disqus