You've already forked codeigniter_test2
first commit
This commit is contained in:
216
system/libraries/Cache/Cache.php
Normal file
216
system/libraries/Cache/Cache.php
Normal file
@ -0,0 +1,216 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 4.3.2 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 2.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* CodeIgniter Caching Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Core
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link
|
||||
*/
|
||||
class CI_Cache extends CI_Driver_Library {
|
||||
|
||||
protected $valid_drivers = array(
|
||||
'cache_apc', 'cache_file', 'cache_memcached', 'cache_dummy'
|
||||
);
|
||||
|
||||
protected $_cache_path = NULL; // Path of cache files (if file-based cache)
|
||||
protected $_adapter = 'dummy';
|
||||
protected $_backup_driver;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array
|
||||
*/
|
||||
public function __construct($config = array())
|
||||
{
|
||||
if ( ! empty($config))
|
||||
{
|
||||
$this->_initialize($config);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get
|
||||
*
|
||||
* Look for a value in the cache. If it exists, return the data
|
||||
* if not, return FALSE
|
||||
*
|
||||
* @param string
|
||||
* @return mixed value that is stored/FALSE on failure
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
return $this->{$this->_adapter}->get($id);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Cache Save
|
||||
*
|
||||
* @param string Unique Key
|
||||
* @param mixed Data to store
|
||||
* @param int Length of time (in seconds) to cache the data
|
||||
*
|
||||
* @return boolean true on success/false on failure
|
||||
*/
|
||||
public function save($id, $data, $ttl = 60)
|
||||
{
|
||||
return $this->{$this->_adapter}->save($id, $data, $ttl);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete from Cache
|
||||
*
|
||||
* @param mixed unique identifier of the item in the cache
|
||||
* @return boolean true on success/false on failure
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
return $this->{$this->_adapter}->delete($id);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Clean the cache
|
||||
*
|
||||
* @return boolean false on failure/true on success
|
||||
*/
|
||||
public function clean()
|
||||
{
|
||||
return $this->{$this->_adapter}->clean();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Cache Info
|
||||
*
|
||||
* @param string user/filehits
|
||||
* @return mixed array on success, false on failure
|
||||
*/
|
||||
public function cache_info($type = 'user')
|
||||
{
|
||||
return $this->{$this->_adapter}->cache_info($type);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get Cache Metadata
|
||||
*
|
||||
* @param mixed key to get cache metadata on
|
||||
* @return mixed return value from child method
|
||||
*/
|
||||
public function get_metadata($id)
|
||||
{
|
||||
return $this->{$this->_adapter}->get_metadata($id);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Initialize
|
||||
*
|
||||
* Initialize class properties based on the configuration array.
|
||||
*
|
||||
* @param array
|
||||
* @return void
|
||||
*/
|
||||
private function _initialize($config)
|
||||
{
|
||||
$default_config = array(
|
||||
'adapter',
|
||||
'memcached'
|
||||
);
|
||||
|
||||
foreach ($default_config as $key)
|
||||
{
|
||||
if (isset($config[$key]))
|
||||
{
|
||||
$param = '_'.$key;
|
||||
|
||||
$this->{$param} = $config[$key];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($config['backup']))
|
||||
{
|
||||
if (in_array('cache_'.$config['backup'], $this->valid_drivers))
|
||||
{
|
||||
$this->_backup_driver = $config['backup'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Is the requested driver supported in this environment?
|
||||
*
|
||||
* @param string The driver to test.
|
||||
* @return array
|
||||
*/
|
||||
public function is_supported($driver)
|
||||
{
|
||||
static $support = array();
|
||||
|
||||
if ( ! isset($support[$driver]))
|
||||
{
|
||||
$support[$driver] = $this->{$driver}->is_supported();
|
||||
}
|
||||
|
||||
return $support[$driver];
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* __get()
|
||||
*
|
||||
* @param child
|
||||
* @return object
|
||||
*/
|
||||
public function __get($child)
|
||||
{
|
||||
$obj = parent::__get($child);
|
||||
|
||||
if ( ! $this->is_supported($child))
|
||||
{
|
||||
$this->_adapter = $this->_backup_driver;
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
}
|
||||
// End Class
|
||||
|
||||
/* End of file Cache.php */
|
||||
/* Location: ./system/libraries/Cache/Cache.php */
|
151
system/libraries/Cache/drivers/Cache_apc.php
Normal file
151
system/libraries/Cache/drivers/Cache_apc.php
Normal file
@ -0,0 +1,151 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 2.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* CodeIgniter APC Caching Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Core
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link
|
||||
*/
|
||||
|
||||
class CI_Cache_apc extends CI_Driver {
|
||||
|
||||
/**
|
||||
* Get
|
||||
*
|
||||
* Look for a value in the cache. If it exists, return the data
|
||||
* if not, return FALSE
|
||||
*
|
||||
* @param string
|
||||
* @return mixed value that is stored/FALSE on failure
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
$data = apc_fetch($id);
|
||||
|
||||
return (is_array($data)) ? $data[0] : FALSE;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Cache Save
|
||||
*
|
||||
* @param string Unique Key
|
||||
* @param mixed Data to store
|
||||
* @param int Length of time (in seconds) to cache the data
|
||||
*
|
||||
* @return boolean true on success/false on failure
|
||||
*/
|
||||
public function save($id, $data, $ttl = 60)
|
||||
{
|
||||
return apc_store($id, array($data, time(), $ttl), $ttl);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete from Cache
|
||||
*
|
||||
* @param mixed unique identifier of the item in the cache
|
||||
* @param boolean true on success/false on failure
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
return apc_delete($id);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Clean the cache
|
||||
*
|
||||
* @return boolean false on failure/true on success
|
||||
*/
|
||||
public function clean()
|
||||
{
|
||||
return apc_clear_cache('user');
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Cache Info
|
||||
*
|
||||
* @param string user/filehits
|
||||
* @return mixed array on success, false on failure
|
||||
*/
|
||||
public function cache_info($type = NULL)
|
||||
{
|
||||
return apc_cache_info($type);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get Cache Metadata
|
||||
*
|
||||
* @param mixed key to get cache metadata on
|
||||
* @return mixed array on success/false on failure
|
||||
*/
|
||||
public function get_metadata($id)
|
||||
{
|
||||
$stored = apc_fetch($id);
|
||||
|
||||
if (count($stored) !== 3)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
list($data, $time, $ttl) = $stored;
|
||||
|
||||
return array(
|
||||
'expire' => $time + $ttl,
|
||||
'mtime' => $time,
|
||||
'data' => $data
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* is_supported()
|
||||
*
|
||||
* Check to see if APC is available on this system, bail if it isn't.
|
||||
*/
|
||||
public function is_supported()
|
||||
{
|
||||
if ( ! extension_loaded('apc') OR ini_get('apc.enabled') != "1")
|
||||
{
|
||||
log_message('error', 'The APC PHP extension must be loaded to use APC Cache.');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
}
|
||||
// End Class
|
||||
|
||||
/* End of file Cache_apc.php */
|
||||
/* Location: ./system/libraries/Cache/drivers/Cache_apc.php */
|
129
system/libraries/Cache/drivers/Cache_dummy.php
Normal file
129
system/libraries/Cache/drivers/Cache_dummy.php
Normal file
@ -0,0 +1,129 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 4.3.2 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 2.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* CodeIgniter Dummy Caching Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Core
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link
|
||||
*/
|
||||
|
||||
class CI_Cache_dummy extends CI_Driver {
|
||||
|
||||
/**
|
||||
* Get
|
||||
*
|
||||
* Since this is the dummy class, it's always going to return FALSE.
|
||||
*
|
||||
* @param string
|
||||
* @return Boolean FALSE
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Cache Save
|
||||
*
|
||||
* @param string Unique Key
|
||||
* @param mixed Data to store
|
||||
* @param int Length of time (in seconds) to cache the data
|
||||
*
|
||||
* @return boolean TRUE, Simulating success
|
||||
*/
|
||||
public function save($id, $data, $ttl = 60)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete from Cache
|
||||
*
|
||||
* @param mixed unique identifier of the item in the cache
|
||||
* @param boolean TRUE, simulating success
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Clean the cache
|
||||
*
|
||||
* @return boolean TRUE, simulating success
|
||||
*/
|
||||
public function clean()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Cache Info
|
||||
*
|
||||
* @param string user/filehits
|
||||
* @return boolean FALSE
|
||||
*/
|
||||
public function cache_info($type = NULL)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get Cache Metadata
|
||||
*
|
||||
* @param mixed key to get cache metadata on
|
||||
* @return boolean FALSE
|
||||
*/
|
||||
public function get_metadata($id)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Is this caching driver supported on the system?
|
||||
* Of course this one is.
|
||||
*
|
||||
* @return TRUE;
|
||||
*/
|
||||
public function is_supported()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
// End Class
|
||||
|
||||
/* End of file Cache_dummy.php */
|
||||
/* Location: ./system/libraries/Cache/drivers/Cache_dummy.php */
|
195
system/libraries/Cache/drivers/Cache_file.php
Normal file
195
system/libraries/Cache/drivers/Cache_file.php
Normal file
@ -0,0 +1,195 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 4.3.2 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 2.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* CodeIgniter Memcached Caching Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Core
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link
|
||||
*/
|
||||
|
||||
class CI_Cache_file extends CI_Driver {
|
||||
|
||||
protected $_cache_path;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$CI->load->helper('file');
|
||||
|
||||
$path = $CI->config->item('cache_path');
|
||||
|
||||
$this->_cache_path = ($path == '') ? APPPATH.'cache/' : $path;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch from cache
|
||||
*
|
||||
* @param mixed unique key id
|
||||
* @return mixed data on success/false on failure
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
if ( ! file_exists($this->_cache_path.$id))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$data = read_file($this->_cache_path.$id);
|
||||
$data = unserialize($data);
|
||||
|
||||
if (time() > $data['time'] + $data['ttl'])
|
||||
{
|
||||
unlink($this->_cache_path.$id);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return $data['data'];
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Save into cache
|
||||
*
|
||||
* @param string unique key
|
||||
* @param mixed data to store
|
||||
* @param int length of time (in seconds) the cache is valid
|
||||
* - Default is 60 seconds
|
||||
* @return boolean true on success/false on failure
|
||||
*/
|
||||
public function save($id, $data, $ttl = 60)
|
||||
{
|
||||
$contents = array(
|
||||
'time' => time(),
|
||||
'ttl' => $ttl,
|
||||
'data' => $data
|
||||
);
|
||||
|
||||
if (write_file($this->_cache_path.$id, serialize($contents)))
|
||||
{
|
||||
@chmod($this->_cache_path.$id, 0777);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete from Cache
|
||||
*
|
||||
* @param mixed unique identifier of item in cache
|
||||
* @return boolean true on success/false on failure
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
return unlink($this->_cache_path.$id);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Clean the Cache
|
||||
*
|
||||
* @return boolean false on failure/true on success
|
||||
*/
|
||||
public function clean()
|
||||
{
|
||||
return delete_files($this->_cache_path);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Cache Info
|
||||
*
|
||||
* Not supported by file-based caching
|
||||
*
|
||||
* @param string user/filehits
|
||||
* @return mixed FALSE
|
||||
*/
|
||||
public function cache_info($type = NULL)
|
||||
{
|
||||
return get_dir_file_info($this->_cache_path);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get Cache Metadata
|
||||
*
|
||||
* @param mixed key to get cache metadata on
|
||||
* @return mixed FALSE on failure, array on success.
|
||||
*/
|
||||
public function get_metadata($id)
|
||||
{
|
||||
if ( ! file_exists($this->_cache_path.$id))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$data = read_file($this->_cache_path.$id);
|
||||
$data = unserialize($data);
|
||||
|
||||
if (is_array($data))
|
||||
{
|
||||
$mtime = filemtime($this->_cache_path.$id);
|
||||
|
||||
if ( ! isset($data['ttl']))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return array(
|
||||
'expire' => $mtime + $data['ttl'],
|
||||
'mtime' => $mtime
|
||||
);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Is supported
|
||||
*
|
||||
* In the file driver, check to see that the cache directory is indeed writable
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_supported()
|
||||
{
|
||||
return is_really_writable($this->_cache_path);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
}
|
||||
// End Class
|
||||
|
||||
/* End of file Cache_file.php */
|
||||
/* Location: ./system/libraries/Cache/drivers/Cache_file.php */
|
218
system/libraries/Cache/drivers/Cache_memcached.php
Normal file
218
system/libraries/Cache/drivers/Cache_memcached.php
Normal file
@ -0,0 +1,218 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 4.3.2 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2006 - 2012 EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 2.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* CodeIgniter Memcached Caching Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Core
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link
|
||||
*/
|
||||
|
||||
class CI_Cache_memcached extends CI_Driver {
|
||||
|
||||
private $_memcached; // Holds the memcached object
|
||||
|
||||
protected $_memcache_conf = array(
|
||||
'default' => array(
|
||||
'default_host' => '127.0.0.1',
|
||||
'default_port' => 11211,
|
||||
'default_weight' => 1
|
||||
)
|
||||
);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch from cache
|
||||
*
|
||||
* @param mixed unique key id
|
||||
* @return mixed data on success/false on failure
|
||||
*/
|
||||
public function get($id)
|
||||
{
|
||||
$data = $this->_memcached->get($id);
|
||||
|
||||
return (is_array($data)) ? $data[0] : FALSE;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Save
|
||||
*
|
||||
* @param string unique identifier
|
||||
* @param mixed data being cached
|
||||
* @param int time to live
|
||||
* @return boolean true on success, false on failure
|
||||
*/
|
||||
public function save($id, $data, $ttl = 60)
|
||||
{
|
||||
if (get_class($this->_memcached) == 'Memcached')
|
||||
{
|
||||
return $this->_memcached->set($id, array($data, time(), $ttl), $ttl);
|
||||
}
|
||||
else if (get_class($this->_memcached) == 'Memcache')
|
||||
{
|
||||
return $this->_memcached->set($id, array($data, time(), $ttl), 0, $ttl);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete from Cache
|
||||
*
|
||||
* @param mixed key to be deleted.
|
||||
* @return boolean true on success, false on failure
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
return $this->_memcached->delete($id);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Clean the Cache
|
||||
*
|
||||
* @return boolean false on failure/true on success
|
||||
*/
|
||||
public function clean()
|
||||
{
|
||||
return $this->_memcached->flush();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Cache Info
|
||||
*
|
||||
* @param null type not supported in memcached
|
||||
* @return mixed array on success, false on failure
|
||||
*/
|
||||
public function cache_info($type = NULL)
|
||||
{
|
||||
return $this->_memcached->getStats();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get Cache Metadata
|
||||
*
|
||||
* @param mixed key to get cache metadata on
|
||||
* @return mixed FALSE on failure, array on success.
|
||||
*/
|
||||
public function get_metadata($id)
|
||||
{
|
||||
$stored = $this->_memcached->get($id);
|
||||
|
||||
if (count($stored) !== 3)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
list($data, $time, $ttl) = $stored;
|
||||
|
||||
return array(
|
||||
'expire' => $time + $ttl,
|
||||
'mtime' => $time,
|
||||
'data' => $data
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Setup memcached.
|
||||
*/
|
||||
private function _setup_memcached()
|
||||
{
|
||||
// Try to load memcached server info from the config file.
|
||||
$CI =& get_instance();
|
||||
if ($CI->config->load('memcached', TRUE, TRUE))
|
||||
{
|
||||
if (is_array($CI->config->config['memcached']))
|
||||
{
|
||||
$this->_memcache_conf = NULL;
|
||||
|
||||
foreach ($CI->config->config['memcached'] as $name => $conf)
|
||||
{
|
||||
$this->_memcache_conf[$name] = $conf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_memcached = new Memcached();
|
||||
|
||||
foreach ($this->_memcache_conf as $name => $cache_server)
|
||||
{
|
||||
if ( ! array_key_exists('hostname', $cache_server))
|
||||
{
|
||||
$cache_server['hostname'] = $this->_default_options['default_host'];
|
||||
}
|
||||
|
||||
if ( ! array_key_exists('port', $cache_server))
|
||||
{
|
||||
$cache_server['port'] = $this->_default_options['default_port'];
|
||||
}
|
||||
|
||||
if ( ! array_key_exists('weight', $cache_server))
|
||||
{
|
||||
$cache_server['weight'] = $this->_default_options['default_weight'];
|
||||
}
|
||||
|
||||
$this->_memcached->addServer(
|
||||
$cache_server['hostname'], $cache_server['port'], $cache_server['weight']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Is supported
|
||||
*
|
||||
* Returns FALSE if memcached is not supported on the system.
|
||||
* If it is, we setup the memcached object & return TRUE
|
||||
*/
|
||||
public function is_supported()
|
||||
{
|
||||
if ( ! extension_loaded('memcached'))
|
||||
{
|
||||
log_message('error', 'The Memcached Extension must be loaded to use Memcached Cache.');
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$this->_setup_memcached();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
// End Class
|
||||
|
||||
/* End of file Cache_memcached.php */
|
||||
/* Location: ./system/libraries/Cache/drivers/Cache_memcached.php */
|
475
system/libraries/Calendar.php
Normal file
475
system/libraries/Calendar.php
Normal file
@ -0,0 +1,475 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* CodeIgniter Calendar Class
|
||||
*
|
||||
* This class enables the creation of calendars
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Libraries
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link http://codeigniter.com/user_guide/libraries/calendar.html
|
||||
*/
|
||||
class CI_Calendar {
|
||||
|
||||
var $CI;
|
||||
var $lang;
|
||||
var $local_time;
|
||||
var $template = '';
|
||||
var $start_day = 'sunday';
|
||||
var $month_type = 'long';
|
||||
var $day_type = 'abr';
|
||||
var $show_next_prev = FALSE;
|
||||
var $next_prev_url = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Loads the calendar language file and sets the default time reference
|
||||
*/
|
||||
public function __construct($config = array())
|
||||
{
|
||||
$this->CI =& get_instance();
|
||||
|
||||
if ( ! in_array('calendar_lang.php', $this->CI->lang->is_loaded, TRUE))
|
||||
{
|
||||
$this->CI->lang->load('calendar');
|
||||
}
|
||||
|
||||
$this->local_time = time();
|
||||
|
||||
if (count($config) > 0)
|
||||
{
|
||||
$this->initialize($config);
|
||||
}
|
||||
|
||||
log_message('debug', "Calendar Class Initialized");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Initialize the user preferences
|
||||
*
|
||||
* Accepts an associative array as input, containing display preferences
|
||||
*
|
||||
* @access public
|
||||
* @param array config preferences
|
||||
* @return void
|
||||
*/
|
||||
function initialize($config = array())
|
||||
{
|
||||
foreach ($config as $key => $val)
|
||||
{
|
||||
if (isset($this->$key))
|
||||
{
|
||||
$this->$key = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Generate the calendar
|
||||
*
|
||||
* @access public
|
||||
* @param integer the year
|
||||
* @param integer the month
|
||||
* @param array the data to be shown in the calendar cells
|
||||
* @return string
|
||||
*/
|
||||
function generate($year = '', $month = '', $data = array())
|
||||
{
|
||||
// Set and validate the supplied month/year
|
||||
if ($year == '')
|
||||
$year = date("Y", $this->local_time);
|
||||
|
||||
if ($month == '')
|
||||
$month = date("m", $this->local_time);
|
||||
|
||||
if (strlen($year) == 1)
|
||||
$year = '200'.$year;
|
||||
|
||||
if (strlen($year) == 2)
|
||||
$year = '20'.$year;
|
||||
|
||||
if (strlen($month) == 1)
|
||||
$month = '0'.$month;
|
||||
|
||||
$adjusted_date = $this->adjust_date($month, $year);
|
||||
|
||||
$month = $adjusted_date['month'];
|
||||
$year = $adjusted_date['year'];
|
||||
|
||||
// Determine the total days in the month
|
||||
$total_days = $this->get_total_days($month, $year);
|
||||
|
||||
// Set the starting day of the week
|
||||
$start_days = array('sunday' => 0, 'monday' => 1, 'tuesday' => 2, 'wednesday' => 3, 'thursday' => 4, 'friday' => 5, 'saturday' => 6);
|
||||
$start_day = ( ! isset($start_days[$this->start_day])) ? 0 : $start_days[$this->start_day];
|
||||
|
||||
// Set the starting day number
|
||||
$local_date = mktime(12, 0, 0, $month, 1, $year);
|
||||
$date = getdate($local_date);
|
||||
$day = $start_day + 1 - $date["wday"];
|
||||
|
||||
while ($day > 1)
|
||||
{
|
||||
$day -= 7;
|
||||
}
|
||||
|
||||
// Set the current month/year/day
|
||||
// We use this to determine the "today" date
|
||||
$cur_year = date("Y", $this->local_time);
|
||||
$cur_month = date("m", $this->local_time);
|
||||
$cur_day = date("j", $this->local_time);
|
||||
|
||||
$is_current_month = ($cur_year == $year AND $cur_month == $month) ? TRUE : FALSE;
|
||||
|
||||
// Generate the template data array
|
||||
$this->parse_template();
|
||||
|
||||
// Begin building the calendar output
|
||||
$out = $this->temp['table_open'];
|
||||
$out .= "\n";
|
||||
|
||||
$out .= "\n";
|
||||
$out .= $this->temp['heading_row_start'];
|
||||
$out .= "\n";
|
||||
|
||||
// "previous" month link
|
||||
if ($this->show_next_prev == TRUE)
|
||||
{
|
||||
// Add a trailing slash to the URL if needed
|
||||
$this->next_prev_url = preg_replace("/(.+?)\/*$/", "\\1/", $this->next_prev_url);
|
||||
|
||||
$adjusted_date = $this->adjust_date($month - 1, $year);
|
||||
$out .= str_replace('{previous_url}', $this->next_prev_url.$adjusted_date['year'].'/'.$adjusted_date['month'], $this->temp['heading_previous_cell']);
|
||||
$out .= "\n";
|
||||
}
|
||||
|
||||
// Heading containing the month/year
|
||||
$colspan = ($this->show_next_prev == TRUE) ? 5 : 7;
|
||||
|
||||
$this->temp['heading_title_cell'] = str_replace('{colspan}', $colspan, $this->temp['heading_title_cell']);
|
||||
$this->temp['heading_title_cell'] = str_replace('{heading}', $this->get_month_name($month)." ".$year, $this->temp['heading_title_cell']);
|
||||
|
||||
$out .= $this->temp['heading_title_cell'];
|
||||
$out .= "\n";
|
||||
|
||||
// "next" month link
|
||||
if ($this->show_next_prev == TRUE)
|
||||
{
|
||||
$adjusted_date = $this->adjust_date($month + 1, $year);
|
||||
$out .= str_replace('{next_url}', $this->next_prev_url.$adjusted_date['year'].'/'.$adjusted_date['month'], $this->temp['heading_next_cell']);
|
||||
}
|
||||
|
||||
$out .= "\n";
|
||||
$out .= $this->temp['heading_row_end'];
|
||||
$out .= "\n";
|
||||
|
||||
// Write the cells containing the days of the week
|
||||
$out .= "\n";
|
||||
$out .= $this->temp['week_row_start'];
|
||||
$out .= "\n";
|
||||
|
||||
$day_names = $this->get_day_names();
|
||||
|
||||
for ($i = 0; $i < 7; $i ++)
|
||||
{
|
||||
$out .= str_replace('{week_day}', $day_names[($start_day + $i) %7], $this->temp['week_day_cell']);
|
||||
}
|
||||
|
||||
$out .= "\n";
|
||||
$out .= $this->temp['week_row_end'];
|
||||
$out .= "\n";
|
||||
|
||||
// Build the main body of the calendar
|
||||
while ($day <= $total_days)
|
||||
{
|
||||
$out .= "\n";
|
||||
$out .= $this->temp['cal_row_start'];
|
||||
$out .= "\n";
|
||||
|
||||
for ($i = 0; $i < 7; $i++)
|
||||
{
|
||||
$out .= ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_start_today'] : $this->temp['cal_cell_start'];
|
||||
|
||||
if ($day > 0 AND $day <= $total_days)
|
||||
{
|
||||
if (isset($data[$day]))
|
||||
{
|
||||
// Cells with content
|
||||
$temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_content_today'] : $this->temp['cal_cell_content'];
|
||||
$out .= str_replace('{day}', $day, str_replace('{content}', $data[$day], $temp));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cells with no content
|
||||
$temp = ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_no_content_today'] : $this->temp['cal_cell_no_content'];
|
||||
$out .= str_replace('{day}', $day, $temp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Blank cells
|
||||
$out .= $this->temp['cal_cell_blank'];
|
||||
}
|
||||
|
||||
$out .= ($is_current_month == TRUE AND $day == $cur_day) ? $this->temp['cal_cell_end_today'] : $this->temp['cal_cell_end'];
|
||||
$day++;
|
||||
}
|
||||
|
||||
$out .= "\n";
|
||||
$out .= $this->temp['cal_row_end'];
|
||||
$out .= "\n";
|
||||
}
|
||||
|
||||
$out .= "\n";
|
||||
$out .= $this->temp['table_close'];
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get Month Name
|
||||
*
|
||||
* Generates a textual month name based on the numeric
|
||||
* month provided.
|
||||
*
|
||||
* @access public
|
||||
* @param integer the month
|
||||
* @return string
|
||||
*/
|
||||
function get_month_name($month)
|
||||
{
|
||||
if ($this->month_type == 'short')
|
||||
{
|
||||
$month_names = array('01' => 'cal_jan', '02' => 'cal_feb', '03' => 'cal_mar', '04' => 'cal_apr', '05' => 'cal_may', '06' => 'cal_jun', '07' => 'cal_jul', '08' => 'cal_aug', '09' => 'cal_sep', '10' => 'cal_oct', '11' => 'cal_nov', '12' => 'cal_dec');
|
||||
}
|
||||
else
|
||||
{
|
||||
$month_names = array('01' => 'cal_january', '02' => 'cal_february', '03' => 'cal_march', '04' => 'cal_april', '05' => 'cal_mayl', '06' => 'cal_june', '07' => 'cal_july', '08' => 'cal_august', '09' => 'cal_september', '10' => 'cal_october', '11' => 'cal_november', '12' => 'cal_december');
|
||||
}
|
||||
|
||||
$month = $month_names[$month];
|
||||
|
||||
if ($this->CI->lang->line($month) === FALSE)
|
||||
{
|
||||
return ucfirst(str_replace('cal_', '', $month));
|
||||
}
|
||||
|
||||
return $this->CI->lang->line($month);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get Day Names
|
||||
*
|
||||
* Returns an array of day names (Sunday, Monday, etc.) based
|
||||
* on the type. Options: long, short, abrev
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return array
|
||||
*/
|
||||
function get_day_names($day_type = '')
|
||||
{
|
||||
if ($day_type != '')
|
||||
$this->day_type = $day_type;
|
||||
|
||||
if ($this->day_type == 'long')
|
||||
{
|
||||
$day_names = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
|
||||
}
|
||||
elseif ($this->day_type == 'short')
|
||||
{
|
||||
$day_names = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat');
|
||||
}
|
||||
else
|
||||
{
|
||||
$day_names = array('su', 'mo', 'tu', 'we', 'th', 'fr', 'sa');
|
||||
}
|
||||
|
||||
$days = array();
|
||||
foreach ($day_names as $val)
|
||||
{
|
||||
$days[] = ($this->CI->lang->line('cal_'.$val) === FALSE) ? ucfirst($val) : $this->CI->lang->line('cal_'.$val);
|
||||
}
|
||||
|
||||
return $days;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Adjust Date
|
||||
*
|
||||
* This function makes sure that we have a valid month/year.
|
||||
* For example, if you submit 13 as the month, the year will
|
||||
* increment and the month will become January.
|
||||
*
|
||||
* @access public
|
||||
* @param integer the month
|
||||
* @param integer the year
|
||||
* @return array
|
||||
*/
|
||||
function adjust_date($month, $year)
|
||||
{
|
||||
$date = array();
|
||||
|
||||
$date['month'] = $month;
|
||||
$date['year'] = $year;
|
||||
|
||||
while ($date['month'] > 12)
|
||||
{
|
||||
$date['month'] -= 12;
|
||||
$date['year']++;
|
||||
}
|
||||
|
||||
while ($date['month'] <= 0)
|
||||
{
|
||||
$date['month'] += 12;
|
||||
$date['year']--;
|
||||
}
|
||||
|
||||
if (strlen($date['month']) == 1)
|
||||
{
|
||||
$date['month'] = '0'.$date['month'];
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Total days in a given month
|
||||
*
|
||||
* @access public
|
||||
* @param integer the month
|
||||
* @param integer the year
|
||||
* @return integer
|
||||
*/
|
||||
function get_total_days($month, $year)
|
||||
{
|
||||
$days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
|
||||
|
||||
if ($month < 1 OR $month > 12)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Is the year a leap year?
|
||||
if ($month == 2)
|
||||
{
|
||||
if ($year % 400 == 0 OR ($year % 4 == 0 AND $year % 100 != 0))
|
||||
{
|
||||
return 29;
|
||||
}
|
||||
}
|
||||
|
||||
return $days_in_month[$month - 1];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set Default Template Data
|
||||
*
|
||||
* This is used in the event that the user has not created their own template
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
function default_template()
|
||||
{
|
||||
return array (
|
||||
'table_open' => '<table border="0" cellpadding="4" cellspacing="0">',
|
||||
'heading_row_start' => '<tr>',
|
||||
'heading_previous_cell' => '<th><a href="{previous_url}"><<</a></th>',
|
||||
'heading_title_cell' => '<th colspan="{colspan}">{heading}</th>',
|
||||
'heading_next_cell' => '<th><a href="{next_url}">>></a></th>',
|
||||
'heading_row_end' => '</tr>',
|
||||
'week_row_start' => '<tr>',
|
||||
'week_day_cell' => '<td>{week_day}</td>',
|
||||
'week_row_end' => '</tr>',
|
||||
'cal_row_start' => '<tr>',
|
||||
'cal_cell_start' => '<td>',
|
||||
'cal_cell_start_today' => '<td>',
|
||||
'cal_cell_content' => '<a href="{content}">{day}</a>',
|
||||
'cal_cell_content_today' => '<a href="{content}"><strong>{day}</strong></a>',
|
||||
'cal_cell_no_content' => '{day}',
|
||||
'cal_cell_no_content_today' => '<strong>{day}</strong>',
|
||||
'cal_cell_blank' => ' ',
|
||||
'cal_cell_end' => '</td>',
|
||||
'cal_cell_end_today' => '</td>',
|
||||
'cal_row_end' => '</tr>',
|
||||
'table_close' => '</table>'
|
||||
);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Parse Template
|
||||
*
|
||||
* Harvests the data within the template {pseudo-variables}
|
||||
* used to display the calendar
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function parse_template()
|
||||
{
|
||||
$this->temp = $this->default_template();
|
||||
|
||||
if ($this->template == '')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$today = array('cal_cell_start_today', 'cal_cell_content_today', 'cal_cell_no_content_today', 'cal_cell_end_today');
|
||||
|
||||
foreach (array('table_open', 'table_close', 'heading_row_start', 'heading_previous_cell', 'heading_title_cell', 'heading_next_cell', 'heading_row_end', 'week_row_start', 'week_day_cell', 'week_row_end', 'cal_row_start', 'cal_cell_start', 'cal_cell_content', 'cal_cell_no_content', 'cal_cell_blank', 'cal_cell_end', 'cal_row_end', 'cal_cell_start_today', 'cal_cell_content_today', 'cal_cell_no_content_today', 'cal_cell_end_today') as $val)
|
||||
{
|
||||
if (preg_match("/\{".$val."\}(.*?)\{\/".$val."\}/si", $this->template, $match))
|
||||
{
|
||||
$this->temp[$val] = $match['1'];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (in_array($val, $today, TRUE))
|
||||
{
|
||||
$this->temp[$val] = $this->temp[str_replace('_today', '', $val)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// END CI_Calendar class
|
||||
|
||||
/* End of file Calendar.php */
|
||||
/* Location: ./system/libraries/Calendar.php */
|
552
system/libraries/Cart.php
Normal file
552
system/libraries/Cart.php
Normal file
@ -0,0 +1,552 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2006 - 2012, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Shopping Cart Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Shopping Cart
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link http://codeigniter.com/user_guide/libraries/cart.html
|
||||
*/
|
||||
class CI_Cart {
|
||||
|
||||
// These are the regular expression rules that we use to validate the product ID and product name
|
||||
var $product_id_rules = '\.a-z0-9_-'; // alpha-numeric, dashes, underscores, or periods
|
||||
var $product_name_rules = '\.\:\-_ a-z0-9'; // alpha-numeric, dashes, underscores, colons or periods
|
||||
|
||||
// Private variables. Do not change!
|
||||
var $CI;
|
||||
var $_cart_contents = array();
|
||||
|
||||
|
||||
/**
|
||||
* Shopping Class Constructor
|
||||
*
|
||||
* The constructor loads the Session class, used to store the shopping cart contents.
|
||||
*/
|
||||
public function __construct($params = array())
|
||||
{
|
||||
// Set the super object to a local variable for use later
|
||||
$this->CI =& get_instance();
|
||||
|
||||
// Are any config settings being passed manually? If so, set them
|
||||
$config = array();
|
||||
if (count($params) > 0)
|
||||
{
|
||||
foreach ($params as $key => $val)
|
||||
{
|
||||
$config[$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
// Load the Sessions class
|
||||
$this->CI->load->library('session', $config);
|
||||
|
||||
// Grab the shopping cart array from the session table, if it exists
|
||||
if ($this->CI->session->userdata('cart_contents') !== FALSE)
|
||||
{
|
||||
$this->_cart_contents = $this->CI->session->userdata('cart_contents');
|
||||
}
|
||||
else
|
||||
{
|
||||
// No cart exists so we'll set some base values
|
||||
$this->_cart_contents['cart_total'] = 0;
|
||||
$this->_cart_contents['total_items'] = 0;
|
||||
}
|
||||
|
||||
log_message('debug', "Cart Class Initialized");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert items into the cart and save it to the session table
|
||||
*
|
||||
* @access public
|
||||
* @param array
|
||||
* @return bool
|
||||
*/
|
||||
function insert($items = array())
|
||||
{
|
||||
// Was any cart data passed? No? Bah...
|
||||
if ( ! is_array($items) OR count($items) == 0)
|
||||
{
|
||||
log_message('error', 'The insert method must be passed an array containing data.');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// You can either insert a single product using a one-dimensional array,
|
||||
// or multiple products using a multi-dimensional one. The way we
|
||||
// determine the array type is by looking for a required array key named "id"
|
||||
// at the top level. If it's not found, we will assume it's a multi-dimensional array.
|
||||
|
||||
$save_cart = FALSE;
|
||||
if (isset($items['id']))
|
||||
{
|
||||
if (($rowid = $this->_insert($items)))
|
||||
{
|
||||
$save_cart = TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($items as $val)
|
||||
{
|
||||
if (is_array($val) AND isset($val['id']))
|
||||
{
|
||||
if ($this->_insert($val))
|
||||
{
|
||||
$save_cart = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save the cart data if the insert was successful
|
||||
if ($save_cart == TRUE)
|
||||
{
|
||||
$this->_save_cart();
|
||||
return isset($rowid) ? $rowid : TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert
|
||||
*
|
||||
* @access private
|
||||
* @param array
|
||||
* @return bool
|
||||
*/
|
||||
function _insert($items = array())
|
||||
{
|
||||
// Was any cart data passed? No? Bah...
|
||||
if ( ! is_array($items) OR count($items) == 0)
|
||||
{
|
||||
log_message('error', 'The insert method must be passed an array containing data.');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// Does the $items array contain an id, quantity, price, and name? These are required
|
||||
if ( ! isset($items['id']) OR ! isset($items['qty']) OR ! isset($items['price']) OR ! isset($items['name']))
|
||||
{
|
||||
log_message('error', 'The cart array must contain a product ID, quantity, price, and name.');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// Prep the quantity. It can only be a number. Duh...
|
||||
$items['qty'] = trim(preg_replace('/([^0-9])/i', '', $items['qty']));
|
||||
// Trim any leading zeros
|
||||
$items['qty'] = trim(preg_replace('/(^[0]+)/i', '', $items['qty']));
|
||||
|
||||
// If the quantity is zero or blank there's nothing for us to do
|
||||
if ( ! is_numeric($items['qty']) OR $items['qty'] == 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// Validate the product ID. It can only be alpha-numeric, dashes, underscores or periods
|
||||
// Not totally sure we should impose this rule, but it seems prudent to standardize IDs.
|
||||
// Note: These can be user-specified by setting the $this->product_id_rules variable.
|
||||
if ( ! preg_match("/^[".$this->product_id_rules."]+$/i", $items['id']))
|
||||
{
|
||||
log_message('error', 'Invalid product ID. The product ID can only contain alpha-numeric characters, dashes, and underscores');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// Validate the product name. It can only be alpha-numeric, dashes, underscores, colons or periods.
|
||||
// Note: These can be user-specified by setting the $this->product_name_rules variable.
|
||||
if ( ! preg_match("/^[".$this->product_name_rules."]+$/i", $items['name']))
|
||||
{
|
||||
log_message('error', 'An invalid name was submitted as the product name: '.$items['name'].' The name can only contain alpha-numeric characters, dashes, underscores, colons, and spaces');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// Prep the price. Remove anything that isn't a number or decimal point.
|
||||
$items['price'] = trim(preg_replace('/([^0-9\.])/i', '', $items['price']));
|
||||
// Trim any leading zeros
|
||||
$items['price'] = trim(preg_replace('/(^[0]+)/i', '', $items['price']));
|
||||
|
||||
// Is the price a valid number?
|
||||
if ( ! is_numeric($items['price']))
|
||||
{
|
||||
log_message('error', 'An invalid price was submitted for product ID: '.$items['id']);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// We now need to create a unique identifier for the item being inserted into the cart.
|
||||
// Every time something is added to the cart it is stored in the master cart array.
|
||||
// Each row in the cart array, however, must have a unique index that identifies not only
|
||||
// a particular product, but makes it possible to store identical products with different options.
|
||||
// For example, what if someone buys two identical t-shirts (same product ID), but in
|
||||
// different sizes? The product ID (and other attributes, like the name) will be identical for
|
||||
// both sizes because it's the same shirt. The only difference will be the size.
|
||||
// Internally, we need to treat identical submissions, but with different options, as a unique product.
|
||||
// Our solution is to convert the options array to a string and MD5 it along with the product ID.
|
||||
// This becomes the unique "row ID"
|
||||
if (isset($items['options']) AND count($items['options']) > 0)
|
||||
{
|
||||
$rowid = md5($items['id'].implode('', $items['options']));
|
||||
}
|
||||
else
|
||||
{
|
||||
// No options were submitted so we simply MD5 the product ID.
|
||||
// Technically, we don't need to MD5 the ID in this case, but it makes
|
||||
// sense to standardize the format of array indexes for both conditions
|
||||
$rowid = md5($items['id']);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// Now that we have our unique "row ID", we'll add our cart items to the master array
|
||||
|
||||
// let's unset this first, just to make sure our index contains only the data from this submission
|
||||
unset($this->_cart_contents[$rowid]);
|
||||
|
||||
// Create a new index with our new row ID
|
||||
$this->_cart_contents[$rowid]['rowid'] = $rowid;
|
||||
|
||||
// And add the new items to the cart array
|
||||
foreach ($items as $key => $val)
|
||||
{
|
||||
$this->_cart_contents[$rowid][$key] = $val;
|
||||
}
|
||||
|
||||
// Woot!
|
||||
return $rowid;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update the cart
|
||||
*
|
||||
* This function permits the quantity of a given item to be changed.
|
||||
* Typically it is called from the "view cart" page if a user makes
|
||||
* changes to the quantity before checkout. That array must contain the
|
||||
* product ID and quantity for each item.
|
||||
*
|
||||
* @access public
|
||||
* @param array
|
||||
* @param string
|
||||
* @return bool
|
||||
*/
|
||||
function update($items = array())
|
||||
{
|
||||
// Was any cart data passed?
|
||||
if ( ! is_array($items) OR count($items) == 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// You can either update a single product using a one-dimensional array,
|
||||
// or multiple products using a multi-dimensional one. The way we
|
||||
// determine the array type is by looking for a required array key named "id".
|
||||
// If it's not found we assume it's a multi-dimensional array
|
||||
$save_cart = FALSE;
|
||||
if (isset($items['rowid']) AND isset($items['qty']))
|
||||
{
|
||||
if ($this->_update($items) == TRUE)
|
||||
{
|
||||
$save_cart = TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($items as $val)
|
||||
{
|
||||
if (is_array($val) AND isset($val['rowid']) AND isset($val['qty']))
|
||||
{
|
||||
if ($this->_update($val) == TRUE)
|
||||
{
|
||||
$save_cart = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save the cart data if the insert was successful
|
||||
if ($save_cart == TRUE)
|
||||
{
|
||||
$this->_save_cart();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update the cart
|
||||
*
|
||||
* This function permits the quantity of a given item to be changed.
|
||||
* Typically it is called from the "view cart" page if a user makes
|
||||
* changes to the quantity before checkout. That array must contain the
|
||||
* product ID and quantity for each item.
|
||||
*
|
||||
* @access private
|
||||
* @param array
|
||||
* @return bool
|
||||
*/
|
||||
function _update($items = array())
|
||||
{
|
||||
// Without these array indexes there is nothing we can do
|
||||
if ( ! isset($items['qty']) OR ! isset($items['rowid']) OR ! isset($this->_cart_contents[$items['rowid']]))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Prep the quantity
|
||||
$items['qty'] = preg_replace('/([^0-9])/i', '', $items['qty']);
|
||||
|
||||
// Is the quantity a number?
|
||||
if ( ! is_numeric($items['qty']))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Is the new quantity different than what is already saved in the cart?
|
||||
// If it's the same there's nothing to do
|
||||
if ($this->_cart_contents[$items['rowid']]['qty'] == $items['qty'])
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Is the quantity zero? If so we will remove the item from the cart.
|
||||
// If the quantity is greater than zero we are updating
|
||||
if ($items['qty'] == 0)
|
||||
{
|
||||
unset($this->_cart_contents[$items['rowid']]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_cart_contents[$items['rowid']]['qty'] = $items['qty'];
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Save the cart array to the session DB
|
||||
*
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
function _save_cart()
|
||||
{
|
||||
// Unset these so our total can be calculated correctly below
|
||||
unset($this->_cart_contents['total_items']);
|
||||
unset($this->_cart_contents['cart_total']);
|
||||
|
||||
// Lets add up the individual prices and set the cart sub-total
|
||||
$total = 0;
|
||||
$items = 0;
|
||||
foreach ($this->_cart_contents as $key => $val)
|
||||
{
|
||||
// We make sure the array contains the proper indexes
|
||||
if ( ! is_array($val) OR ! isset($val['price']) OR ! isset($val['qty']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$total += ($val['price'] * $val['qty']);
|
||||
$items += $val['qty'];
|
||||
|
||||
// Set the subtotal
|
||||
$this->_cart_contents[$key]['subtotal'] = ($this->_cart_contents[$key]['price'] * $this->_cart_contents[$key]['qty']);
|
||||
}
|
||||
|
||||
// Set the cart total and total items.
|
||||
$this->_cart_contents['total_items'] = $items;
|
||||
$this->_cart_contents['cart_total'] = $total;
|
||||
|
||||
// Is our cart empty? If so we delete it from the session
|
||||
if (count($this->_cart_contents) <= 2)
|
||||
{
|
||||
$this->CI->session->unset_userdata('cart_contents');
|
||||
|
||||
// Nothing more to do... coffee time!
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// If we made it this far it means that our cart has data.
|
||||
// Let's pass it to the Session class so it can be stored
|
||||
$this->CI->session->set_userdata(array('cart_contents' => $this->_cart_contents));
|
||||
|
||||
// Woot!
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Cart Total
|
||||
*
|
||||
* @access public
|
||||
* @return integer
|
||||
*/
|
||||
function total()
|
||||
{
|
||||
return $this->_cart_contents['cart_total'];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Total Items
|
||||
*
|
||||
* Returns the total item count
|
||||
*
|
||||
* @access public
|
||||
* @return integer
|
||||
*/
|
||||
function total_items()
|
||||
{
|
||||
return $this->_cart_contents['total_items'];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Cart Contents
|
||||
*
|
||||
* Returns the entire cart array
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
function contents()
|
||||
{
|
||||
$cart = $this->_cart_contents;
|
||||
|
||||
// Remove these so they don't create a problem when showing the cart table
|
||||
unset($cart['total_items']);
|
||||
unset($cart['cart_total']);
|
||||
|
||||
return $cart;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Has options
|
||||
*
|
||||
* Returns TRUE if the rowid passed to this function correlates to an item
|
||||
* that has options associated with it.
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
function has_options($rowid = '')
|
||||
{
|
||||
if ( ! isset($this->_cart_contents[$rowid]['options']) OR count($this->_cart_contents[$rowid]['options']) === 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Product options
|
||||
*
|
||||
* Returns the an array of options, for a particular product row ID
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
function product_options($rowid = '')
|
||||
{
|
||||
if ( ! isset($this->_cart_contents[$rowid]['options']))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
return $this->_cart_contents[$rowid]['options'];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Format Number
|
||||
*
|
||||
* Returns the supplied number with commas and a decimal point.
|
||||
*
|
||||
* @access public
|
||||
* @return integer
|
||||
*/
|
||||
function format_number($n = '')
|
||||
{
|
||||
if ($n == '')
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
// Remove anything that isn't a number or decimal point.
|
||||
$n = trim(preg_replace('/([^0-9\.])/i', '', $n));
|
||||
|
||||
return number_format($n, 2, '.', ',');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Destroy the cart
|
||||
*
|
||||
* Empties the cart and kills the session
|
||||
*
|
||||
* @access public
|
||||
* @return null
|
||||
*/
|
||||
function destroy()
|
||||
{
|
||||
unset($this->_cart_contents);
|
||||
|
||||
$this->_cart_contents['cart_total'] = 0;
|
||||
$this->_cart_contents['total_items'] = 0;
|
||||
|
||||
$this->CI->session->unset_userdata('cart_contents');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// END Cart Class
|
||||
|
||||
/* End of file Cart.php */
|
||||
/* Location: ./system/libraries/Cart.php */
|
229
system/libraries/Driver.php
Normal file
229
system/libraries/Driver.php
Normal file
@ -0,0 +1,229 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2006 - 2012, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* CodeIgniter Driver Library Class
|
||||
*
|
||||
* This class enables you to create "Driver" libraries that add runtime ability
|
||||
* to extend the capabilities of a class via additional driver objects
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Libraries
|
||||
* @author EllisLab Dev Team
|
||||
* @link
|
||||
*/
|
||||
class CI_Driver_Library {
|
||||
|
||||
protected $valid_drivers = array();
|
||||
protected $lib_name;
|
||||
|
||||
// The first time a child is used it won't exist, so we instantiate it
|
||||
// subsequents calls will go straight to the proper child.
|
||||
function __get($child)
|
||||
{
|
||||
if ( ! isset($this->lib_name))
|
||||
{
|
||||
$this->lib_name = get_class($this);
|
||||
}
|
||||
|
||||
// The class will be prefixed with the parent lib
|
||||
$child_class = $this->lib_name.'_'.$child;
|
||||
|
||||
// Remove the CI_ prefix and lowercase
|
||||
$lib_name = ucfirst(strtolower(str_replace('CI_', '', $this->lib_name)));
|
||||
$driver_name = strtolower(str_replace('CI_', '', $child_class));
|
||||
|
||||
if (in_array($driver_name, array_map('strtolower', $this->valid_drivers)))
|
||||
{
|
||||
// check and see if the driver is in a separate file
|
||||
if ( ! class_exists($child_class))
|
||||
{
|
||||
// check application path first
|
||||
foreach (get_instance()->load->get_package_paths(TRUE) as $path)
|
||||
{
|
||||
// loves me some nesting!
|
||||
foreach (array(ucfirst($driver_name), $driver_name) as $class)
|
||||
{
|
||||
$filepath = $path.'libraries/'.$lib_name.'/drivers/'.$class.'.php';
|
||||
|
||||
if (file_exists($filepath))
|
||||
{
|
||||
include_once $filepath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// it's a valid driver, but the file simply can't be found
|
||||
if ( ! class_exists($child_class))
|
||||
{
|
||||
log_message('error', "Unable to load the requested driver: ".$child_class);
|
||||
show_error("Unable to load the requested driver: ".$child_class);
|
||||
}
|
||||
}
|
||||
|
||||
$obj = new $child_class;
|
||||
$obj->decorate($this);
|
||||
$this->$child = $obj;
|
||||
return $this->$child;
|
||||
}
|
||||
|
||||
// The requested driver isn't valid!
|
||||
log_message('error', "Invalid driver requested: ".$child_class);
|
||||
show_error("Invalid driver requested: ".$child_class);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
}
|
||||
// END CI_Driver_Library CLASS
|
||||
|
||||
|
||||
/**
|
||||
* CodeIgniter Driver Class
|
||||
*
|
||||
* This class enables you to create drivers for a Library based on the Driver Library.
|
||||
* It handles the drivers' access to the parent library
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Libraries
|
||||
* @author EllisLab Dev Team
|
||||
* @link
|
||||
*/
|
||||
class CI_Driver {
|
||||
protected $parent;
|
||||
|
||||
private $methods = array();
|
||||
private $properties = array();
|
||||
|
||||
private static $reflections = array();
|
||||
|
||||
/**
|
||||
* Decorate
|
||||
*
|
||||
* Decorates the child with the parent driver lib's methods and properties
|
||||
*
|
||||
* @param object
|
||||
* @return void
|
||||
*/
|
||||
public function decorate($parent)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
|
||||
// Lock down attributes to what is defined in the class
|
||||
// and speed up references in magic methods
|
||||
|
||||
$class_name = get_class($parent);
|
||||
|
||||
if ( ! isset(self::$reflections[$class_name]))
|
||||
{
|
||||
$r = new ReflectionObject($parent);
|
||||
|
||||
foreach ($r->getMethods() as $method)
|
||||
{
|
||||
if ($method->isPublic())
|
||||
{
|
||||
$this->methods[] = $method->getName();
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($r->getProperties() as $prop)
|
||||
{
|
||||
if ($prop->isPublic())
|
||||
{
|
||||
$this->properties[] = $prop->getName();
|
||||
}
|
||||
}
|
||||
|
||||
self::$reflections[$class_name] = array($this->methods, $this->properties);
|
||||
}
|
||||
else
|
||||
{
|
||||
list($this->methods, $this->properties) = self::$reflections[$class_name];
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* __call magic method
|
||||
*
|
||||
* Handles access to the parent driver library's methods
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @param array
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $args = array())
|
||||
{
|
||||
if (in_array($method, $this->methods))
|
||||
{
|
||||
return call_user_func_array(array($this->parent, $method), $args);
|
||||
}
|
||||
|
||||
$trace = debug_backtrace();
|
||||
_exception_handler(E_ERROR, "No such method '{$method}'", $trace[1]['file'], $trace[1]['line']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* __get magic method
|
||||
*
|
||||
* Handles reading of the parent driver library's properties
|
||||
*
|
||||
* @param string
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($var)
|
||||
{
|
||||
if (in_array($var, $this->properties))
|
||||
{
|
||||
return $this->parent->$var;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* __set magic method
|
||||
*
|
||||
* Handles writing to the parent driver library's properties
|
||||
*
|
||||
* @param string
|
||||
* @param array
|
||||
* @return mixed
|
||||
*/
|
||||
public function __set($var, $val)
|
||||
{
|
||||
if (in_array($var, $this->properties))
|
||||
{
|
||||
$this->parent->$var = $val;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
}
|
||||
// END CI_Driver CLASS
|
||||
|
||||
/* End of file Driver.php */
|
||||
/* Location: ./system/libraries/Driver.php */
|
2092
system/libraries/Email.php
Normal file
2092
system/libraries/Email.php
Normal file
File diff suppressed because it is too large
Load Diff
547
system/libraries/Encrypt.php
Normal file
547
system/libraries/Encrypt.php
Normal file
@ -0,0 +1,547 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* CodeIgniter Encryption Class
|
||||
*
|
||||
* Provides two-way keyed encoding using XOR Hashing and Mcrypt
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Libraries
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link http://codeigniter.com/user_guide/libraries/encryption.html
|
||||
*/
|
||||
class CI_Encrypt {
|
||||
|
||||
var $CI;
|
||||
var $encryption_key = '';
|
||||
var $_hash_type = 'sha1';
|
||||
var $_mcrypt_exists = FALSE;
|
||||
var $_mcrypt_cipher;
|
||||
var $_mcrypt_mode;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Simply determines whether the mcrypt library exists.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->CI =& get_instance();
|
||||
$this->_mcrypt_exists = ( ! function_exists('mcrypt_encrypt')) ? FALSE : TRUE;
|
||||
log_message('debug', "Encrypt Class Initialized");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch the encryption key
|
||||
*
|
||||
* Returns it as MD5 in order to have an exact-length 128 bit key.
|
||||
* Mcrypt is sensitive to keys that are not the correct length
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function get_key($key = '')
|
||||
{
|
||||
if ($key == '')
|
||||
{
|
||||
if ($this->encryption_key != '')
|
||||
{
|
||||
return $this->encryption_key;
|
||||
}
|
||||
|
||||
$CI =& get_instance();
|
||||
$key = $CI->config->item('encryption_key');
|
||||
|
||||
if ($key == FALSE)
|
||||
{
|
||||
show_error('In order to use the encryption class requires that you set an encryption key in your config file.');
|
||||
}
|
||||
}
|
||||
|
||||
return md5($key);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the encryption key
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return void
|
||||
*/
|
||||
function set_key($key = '')
|
||||
{
|
||||
$this->encryption_key = $key;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Encode
|
||||
*
|
||||
* Encodes the message string using bitwise XOR encoding.
|
||||
* The key is combined with a random hash, and then it
|
||||
* too gets converted using XOR. The whole thing is then run
|
||||
* through mcrypt (if supported) using the randomized key.
|
||||
* The end result is a double-encrypted message string
|
||||
* that is randomized with each call to this function,
|
||||
* even if the supplied message and key are the same.
|
||||
*
|
||||
* @access public
|
||||
* @param string the string to encode
|
||||
* @param string the key
|
||||
* @return string
|
||||
*/
|
||||
function encode($string, $key = '')
|
||||
{
|
||||
$key = $this->get_key($key);
|
||||
|
||||
if ($this->_mcrypt_exists === TRUE)
|
||||
{
|
||||
$enc = $this->mcrypt_encode($string, $key);
|
||||
}
|
||||
else
|
||||
{
|
||||
$enc = $this->_xor_encode($string, $key);
|
||||
}
|
||||
|
||||
return base64_encode($enc);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Decode
|
||||
*
|
||||
* Reverses the above process
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function decode($string, $key = '')
|
||||
{
|
||||
$key = $this->get_key($key);
|
||||
|
||||
if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$dec = base64_decode($string);
|
||||
|
||||
if ($this->_mcrypt_exists === TRUE)
|
||||
{
|
||||
if (($dec = $this->mcrypt_decode($dec, $key)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$dec = $this->_xor_decode($dec, $key);
|
||||
}
|
||||
|
||||
return $dec;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Encode from Legacy
|
||||
*
|
||||
* Takes an encoded string from the original Encryption class algorithms and
|
||||
* returns a newly encoded string using the improved method added in 2.0.0
|
||||
* This allows for backwards compatibility and a method to transition to the
|
||||
* new encryption algorithms.
|
||||
*
|
||||
* For more details, see http://codeigniter.com/user_guide/installation/upgrade_200.html#encryption
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @param int (mcrypt mode constant)
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function encode_from_legacy($string, $legacy_mode = MCRYPT_MODE_ECB, $key = '')
|
||||
{
|
||||
if ($this->_mcrypt_exists === FALSE)
|
||||
{
|
||||
log_message('error', 'Encoding from legacy is available only when Mcrypt is in use.');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// decode it first
|
||||
// set mode temporarily to what it was when string was encoded with the legacy
|
||||
// algorithm - typically MCRYPT_MODE_ECB
|
||||
$current_mode = $this->_get_mode();
|
||||
$this->set_mode($legacy_mode);
|
||||
|
||||
$key = $this->get_key($key);
|
||||
|
||||
if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$dec = base64_decode($string);
|
||||
|
||||
if (($dec = $this->mcrypt_decode($dec, $key)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$dec = $this->_xor_decode($dec, $key);
|
||||
|
||||
// set the mcrypt mode back to what it should be, typically MCRYPT_MODE_CBC
|
||||
$this->set_mode($current_mode);
|
||||
|
||||
// and re-encode
|
||||
return base64_encode($this->mcrypt_encode($dec, $key));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* XOR Encode
|
||||
*
|
||||
* Takes a plain-text string and key as input and generates an
|
||||
* encoded bit-string using XOR
|
||||
*
|
||||
* @access private
|
||||
* @param string
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function _xor_encode($string, $key)
|
||||
{
|
||||
$rand = '';
|
||||
while (strlen($rand) < 32)
|
||||
{
|
||||
$rand .= mt_rand(0, mt_getrandmax());
|
||||
}
|
||||
|
||||
$rand = $this->hash($rand);
|
||||
|
||||
$enc = '';
|
||||
for ($i = 0; $i < strlen($string); $i++)
|
||||
{
|
||||
$enc .= substr($rand, ($i % strlen($rand)), 1).(substr($rand, ($i % strlen($rand)), 1) ^ substr($string, $i, 1));
|
||||
}
|
||||
|
||||
return $this->_xor_merge($enc, $key);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* XOR Decode
|
||||
*
|
||||
* Takes an encoded string and key as input and generates the
|
||||
* plain-text original message
|
||||
*
|
||||
* @access private
|
||||
* @param string
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function _xor_decode($string, $key)
|
||||
{
|
||||
$string = $this->_xor_merge($string, $key);
|
||||
|
||||
$dec = '';
|
||||
for ($i = 0; $i < strlen($string); $i++)
|
||||
{
|
||||
$dec .= (substr($string, $i++, 1) ^ substr($string, $i, 1));
|
||||
}
|
||||
|
||||
return $dec;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* XOR key + string Combiner
|
||||
*
|
||||
* Takes a string and key as input and computes the difference using XOR
|
||||
*
|
||||
* @access private
|
||||
* @param string
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function _xor_merge($string, $key)
|
||||
{
|
||||
$hash = $this->hash($key);
|
||||
$str = '';
|
||||
for ($i = 0; $i < strlen($string); $i++)
|
||||
{
|
||||
$str .= substr($string, $i, 1) ^ substr($hash, ($i % strlen($hash)), 1);
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Encrypt using Mcrypt
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function mcrypt_encode($data, $key)
|
||||
{
|
||||
$init_size = mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode());
|
||||
$init_vect = mcrypt_create_iv($init_size, MCRYPT_RAND);
|
||||
return $this->_add_cipher_noise($init_vect.mcrypt_encrypt($this->_get_cipher(), $key, $data, $this->_get_mode(), $init_vect), $key);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Decrypt using Mcrypt
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function mcrypt_decode($data, $key)
|
||||
{
|
||||
$data = $this->_remove_cipher_noise($data, $key);
|
||||
$init_size = mcrypt_get_iv_size($this->_get_cipher(), $this->_get_mode());
|
||||
|
||||
if ($init_size > strlen($data))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$init_vect = substr($data, 0, $init_size);
|
||||
$data = substr($data, $init_size);
|
||||
return rtrim(mcrypt_decrypt($this->_get_cipher(), $key, $data, $this->_get_mode(), $init_vect), "\0");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Adds permuted noise to the IV + encrypted data to protect
|
||||
* against Man-in-the-middle attacks on CBC mode ciphers
|
||||
* http://www.ciphersbyritter.com/GLOSSARY.HTM#IV
|
||||
*
|
||||
* Function description
|
||||
*
|
||||
* @access private
|
||||
* @param string
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function _add_cipher_noise($data, $key)
|
||||
{
|
||||
$keyhash = $this->hash($key);
|
||||
$keylen = strlen($keyhash);
|
||||
$str = '';
|
||||
|
||||
for ($i = 0, $j = 0, $len = strlen($data); $i < $len; ++$i, ++$j)
|
||||
{
|
||||
if ($j >= $keylen)
|
||||
{
|
||||
$j = 0;
|
||||
}
|
||||
|
||||
$str .= chr((ord($data[$i]) + ord($keyhash[$j])) % 256);
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Removes permuted noise from the IV + encrypted data, reversing
|
||||
* _add_cipher_noise()
|
||||
*
|
||||
* Function description
|
||||
*
|
||||
* @access public
|
||||
* @param type
|
||||
* @return type
|
||||
*/
|
||||
function _remove_cipher_noise($data, $key)
|
||||
{
|
||||
$keyhash = $this->hash($key);
|
||||
$keylen = strlen($keyhash);
|
||||
$str = '';
|
||||
|
||||
for ($i = 0, $j = 0, $len = strlen($data); $i < $len; ++$i, ++$j)
|
||||
{
|
||||
if ($j >= $keylen)
|
||||
{
|
||||
$j = 0;
|
||||
}
|
||||
|
||||
$temp = ord($data[$i]) - ord($keyhash[$j]);
|
||||
|
||||
if ($temp < 0)
|
||||
{
|
||||
$temp = $temp + 256;
|
||||
}
|
||||
|
||||
$str .= chr($temp);
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the Mcrypt Cipher
|
||||
*
|
||||
* @access public
|
||||
* @param constant
|
||||
* @return string
|
||||
*/
|
||||
function set_cipher($cipher)
|
||||
{
|
||||
$this->_mcrypt_cipher = $cipher;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the Mcrypt Mode
|
||||
*
|
||||
* @access public
|
||||
* @param constant
|
||||
* @return string
|
||||
*/
|
||||
function set_mode($mode)
|
||||
{
|
||||
$this->_mcrypt_mode = $mode;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get Mcrypt cipher Value
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _get_cipher()
|
||||
{
|
||||
if ($this->_mcrypt_cipher == '')
|
||||
{
|
||||
$this->_mcrypt_cipher = MCRYPT_RIJNDAEL_256;
|
||||
}
|
||||
|
||||
return $this->_mcrypt_cipher;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get Mcrypt Mode Value
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _get_mode()
|
||||
{
|
||||
if ($this->_mcrypt_mode == '')
|
||||
{
|
||||
$this->_mcrypt_mode = MCRYPT_MODE_CBC;
|
||||
}
|
||||
|
||||
return $this->_mcrypt_mode;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the Hash type
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function set_hash($type = 'sha1')
|
||||
{
|
||||
$this->_hash_type = ($type != 'sha1' AND $type != 'md5') ? 'sha1' : $type;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Hash encode a string
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function hash($str)
|
||||
{
|
||||
return ($this->_hash_type == 'sha1') ? $this->sha1($str) : md5($str);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Generate an SHA1 Hash
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function sha1($str)
|
||||
{
|
||||
if ( ! function_exists('sha1'))
|
||||
{
|
||||
if ( ! function_exists('mhash'))
|
||||
{
|
||||
require_once(BASEPATH.'libraries/Sha1.php');
|
||||
$SH = new CI_SHA;
|
||||
return $SH->generate($str);
|
||||
}
|
||||
else
|
||||
{
|
||||
return bin2hex(mhash(MHASH_SHA1, $str));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return sha1($str);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// END CI_Encrypt class
|
||||
|
||||
/* End of file Encrypt.php */
|
||||
/* Location: ./system/libraries/Encrypt.php */
|
1382
system/libraries/Form_validation.php
Normal file
1382
system/libraries/Form_validation.php
Normal file
File diff suppressed because it is too large
Load Diff
660
system/libraries/Ftp.php
Normal file
660
system/libraries/Ftp.php
Normal file
@ -0,0 +1,660 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* FTP Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Libraries
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link http://codeigniter.com/user_guide/libraries/ftp.html
|
||||
*/
|
||||
class CI_FTP {
|
||||
|
||||
var $hostname = '';
|
||||
var $username = '';
|
||||
var $password = '';
|
||||
var $port = 21;
|
||||
var $passive = TRUE;
|
||||
var $debug = FALSE;
|
||||
var $conn_id = FALSE;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor - Sets Preferences
|
||||
*
|
||||
* The constructor can be passed an array of config values
|
||||
*/
|
||||
public function __construct($config = array())
|
||||
{
|
||||
if (count($config) > 0)
|
||||
{
|
||||
$this->initialize($config);
|
||||
}
|
||||
|
||||
log_message('debug', "FTP Class Initialized");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Initialize preferences
|
||||
*
|
||||
* @access public
|
||||
* @param array
|
||||
* @return void
|
||||
*/
|
||||
function initialize($config = array())
|
||||
{
|
||||
foreach ($config as $key => $val)
|
||||
{
|
||||
if (isset($this->$key))
|
||||
{
|
||||
$this->$key = $val;
|
||||
}
|
||||
}
|
||||
|
||||
// Prep the hostname
|
||||
$this->hostname = preg_replace('|.+?://|', '', $this->hostname);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* FTP Connect
|
||||
*
|
||||
* @access public
|
||||
* @param array the connection values
|
||||
* @return bool
|
||||
*/
|
||||
function connect($config = array())
|
||||
{
|
||||
if (count($config) > 0)
|
||||
{
|
||||
$this->initialize($config);
|
||||
}
|
||||
|
||||
if (FALSE === ($this->conn_id = @ftp_connect($this->hostname, $this->port)))
|
||||
{
|
||||
if ($this->debug == TRUE)
|
||||
{
|
||||
$this->_error('ftp_unable_to_connect');
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( ! $this->_login())
|
||||
{
|
||||
if ($this->debug == TRUE)
|
||||
{
|
||||
$this->_error('ftp_unable_to_login');
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Set passive mode if needed
|
||||
if ($this->passive == TRUE)
|
||||
{
|
||||
ftp_pasv($this->conn_id, TRUE);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* FTP Login
|
||||
*
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
function _login()
|
||||
{
|
||||
return @ftp_login($this->conn_id, $this->username, $this->password);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Validates the connection ID
|
||||
*
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
function _is_conn()
|
||||
{
|
||||
if ( ! is_resource($this->conn_id))
|
||||
{
|
||||
if ($this->debug == TRUE)
|
||||
{
|
||||
$this->_error('ftp_no_connection');
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Change directory
|
||||
*
|
||||
* The second parameter lets us momentarily turn off debugging so that
|
||||
* this function can be used to test for the existence of a folder
|
||||
* without throwing an error. There's no FTP equivalent to is_dir()
|
||||
* so we do it by trying to change to a particular directory.
|
||||
* Internally, this parameter is only used by the "mirror" function below.
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @param bool
|
||||
* @return bool
|
||||
*/
|
||||
function changedir($path = '', $supress_debug = FALSE)
|
||||
{
|
||||
if ($path == '' OR ! $this->_is_conn())
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$result = @ftp_chdir($this->conn_id, $path);
|
||||
|
||||
if ($result === FALSE)
|
||||
{
|
||||
if ($this->debug == TRUE AND $supress_debug == FALSE)
|
||||
{
|
||||
$this->_error('ftp_unable_to_changedir');
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create a directory
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return bool
|
||||
*/
|
||||
function mkdir($path = '', $permissions = NULL)
|
||||
{
|
||||
if ($path == '' OR ! $this->_is_conn())
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$result = @ftp_mkdir($this->conn_id, $path);
|
||||
|
||||
if ($result === FALSE)
|
||||
{
|
||||
if ($this->debug == TRUE)
|
||||
{
|
||||
$this->_error('ftp_unable_to_makdir');
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Set file permissions if needed
|
||||
if ( ! is_null($permissions))
|
||||
{
|
||||
$this->chmod($path, (int)$permissions);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Upload a file to the server
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @param string
|
||||
* @param string
|
||||
* @return bool
|
||||
*/
|
||||
function upload($locpath, $rempath, $mode = 'auto', $permissions = NULL)
|
||||
{
|
||||
if ( ! $this->_is_conn())
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( ! file_exists($locpath))
|
||||
{
|
||||
$this->_error('ftp_no_source_file');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Set the mode if not specified
|
||||
if ($mode == 'auto')
|
||||
{
|
||||
// Get the file extension so we can set the upload type
|
||||
$ext = $this->_getext($locpath);
|
||||
$mode = $this->_settype($ext);
|
||||
}
|
||||
|
||||
$mode = ($mode == 'ascii') ? FTP_ASCII : FTP_BINARY;
|
||||
|
||||
$result = @ftp_put($this->conn_id, $rempath, $locpath, $mode);
|
||||
|
||||
if ($result === FALSE)
|
||||
{
|
||||
if ($this->debug == TRUE)
|
||||
{
|
||||
$this->_error('ftp_unable_to_upload');
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Set file permissions if needed
|
||||
if ( ! is_null($permissions))
|
||||
{
|
||||
$this->chmod($rempath, (int)$permissions);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Download a file from a remote server to the local server
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @param string
|
||||
* @param string
|
||||
* @return bool
|
||||
*/
|
||||
function download($rempath, $locpath, $mode = 'auto')
|
||||
{
|
||||
if ( ! $this->_is_conn())
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Set the mode if not specified
|
||||
if ($mode == 'auto')
|
||||
{
|
||||
// Get the file extension so we can set the upload type
|
||||
$ext = $this->_getext($rempath);
|
||||
$mode = $this->_settype($ext);
|
||||
}
|
||||
|
||||
$mode = ($mode == 'ascii') ? FTP_ASCII : FTP_BINARY;
|
||||
|
||||
$result = @ftp_get($this->conn_id, $locpath, $rempath, $mode);
|
||||
|
||||
if ($result === FALSE)
|
||||
{
|
||||
if ($this->debug == TRUE)
|
||||
{
|
||||
$this->_error('ftp_unable_to_download');
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rename (or move) a file
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @param string
|
||||
* @param bool
|
||||
* @return bool
|
||||
*/
|
||||
function rename($old_file, $new_file, $move = FALSE)
|
||||
{
|
||||
if ( ! $this->_is_conn())
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$result = @ftp_rename($this->conn_id, $old_file, $new_file);
|
||||
|
||||
if ($result === FALSE)
|
||||
{
|
||||
if ($this->debug == TRUE)
|
||||
{
|
||||
$msg = ($move == FALSE) ? 'ftp_unable_to_rename' : 'ftp_unable_to_move';
|
||||
|
||||
$this->_error($msg);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Move a file
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @param string
|
||||
* @return bool
|
||||
*/
|
||||
function move($old_file, $new_file)
|
||||
{
|
||||
return $this->rename($old_file, $new_file, TRUE);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rename (or move) a file
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return bool
|
||||
*/
|
||||
function delete_file($filepath)
|
||||
{
|
||||
if ( ! $this->_is_conn())
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$result = @ftp_delete($this->conn_id, $filepath);
|
||||
|
||||
if ($result === FALSE)
|
||||
{
|
||||
if ($this->debug == TRUE)
|
||||
{
|
||||
$this->_error('ftp_unable_to_delete');
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete a folder and recursively delete everything (including sub-folders)
|
||||
* containted within it.
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return bool
|
||||
*/
|
||||
function delete_dir($filepath)
|
||||
{
|
||||
if ( ! $this->_is_conn())
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Add a trailing slash to the file path if needed
|
||||
$filepath = preg_replace("/(.+?)\/*$/", "\\1/", $filepath);
|
||||
|
||||
$list = $this->list_files($filepath);
|
||||
|
||||
if ($list !== FALSE AND count($list) > 0)
|
||||
{
|
||||
foreach ($list as $item)
|
||||
{
|
||||
// If we can't delete the item it's probaly a folder so
|
||||
// we'll recursively call delete_dir()
|
||||
if ( ! @ftp_delete($this->conn_id, $item))
|
||||
{
|
||||
$this->delete_dir($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = @ftp_rmdir($this->conn_id, $filepath);
|
||||
|
||||
if ($result === FALSE)
|
||||
{
|
||||
if ($this->debug == TRUE)
|
||||
{
|
||||
$this->_error('ftp_unable_to_delete');
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set file permissions
|
||||
*
|
||||
* @access public
|
||||
* @param string the file path
|
||||
* @param string the permissions
|
||||
* @return bool
|
||||
*/
|
||||
function chmod($path, $perm)
|
||||
{
|
||||
if ( ! $this->_is_conn())
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Permissions can only be set when running PHP 5
|
||||
if ( ! function_exists('ftp_chmod'))
|
||||
{
|
||||
if ($this->debug == TRUE)
|
||||
{
|
||||
$this->_error('ftp_unable_to_chmod');
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$result = @ftp_chmod($this->conn_id, $perm, $path);
|
||||
|
||||
if ($result === FALSE)
|
||||
{
|
||||
if ($this->debug == TRUE)
|
||||
{
|
||||
$this->_error('ftp_unable_to_chmod');
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* FTP List files in the specified directory
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
function list_files($path = '.')
|
||||
{
|
||||
if ( ! $this->_is_conn())
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return ftp_nlist($this->conn_id, $path);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Read a directory and recreate it remotely
|
||||
*
|
||||
* This function recursively reads a folder and everything it contains (including
|
||||
* sub-folders) and creates a mirror via FTP based on it. Whatever the directory structure
|
||||
* of the original file path will be recreated on the server.
|
||||
*
|
||||
* @access public
|
||||
* @param string path to source with trailing slash
|
||||
* @param string path to destination - include the base folder with trailing slash
|
||||
* @return bool
|
||||
*/
|
||||
function mirror($locpath, $rempath)
|
||||
{
|
||||
if ( ! $this->_is_conn())
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Open the local file path
|
||||
if ($fp = @opendir($locpath))
|
||||
{
|
||||
// Attempt to open the remote file path.
|
||||
if ( ! $this->changedir($rempath, TRUE))
|
||||
{
|
||||
// If it doesn't exist we'll attempt to create the direcotory
|
||||
if ( ! $this->mkdir($rempath) OR ! $this->changedir($rempath))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// Recursively read the local directory
|
||||
while (FALSE !== ($file = readdir($fp)))
|
||||
{
|
||||
if (@is_dir($locpath.$file) && substr($file, 0, 1) != '.')
|
||||
{
|
||||
$this->mirror($locpath.$file."/", $rempath.$file."/");
|
||||
}
|
||||
elseif (substr($file, 0, 1) != ".")
|
||||
{
|
||||
// Get the file extension so we can se the upload type
|
||||
$ext = $this->_getext($file);
|
||||
$mode = $this->_settype($ext);
|
||||
|
||||
$this->upload($locpath.$file, $rempath.$file, $mode);
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Extract the file extension
|
||||
*
|
||||
* @access private
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function _getext($filename)
|
||||
{
|
||||
if (FALSE === strpos($filename, '.'))
|
||||
{
|
||||
return 'txt';
|
||||
}
|
||||
|
||||
$x = explode('.', $filename);
|
||||
return end($x);
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the upload type
|
||||
*
|
||||
* @access private
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function _settype($ext)
|
||||
{
|
||||
$text_types = array(
|
||||
'txt',
|
||||
'text',
|
||||
'php',
|
||||
'phps',
|
||||
'php4',
|
||||
'js',
|
||||
'css',
|
||||
'htm',
|
||||
'html',
|
||||
'phtml',
|
||||
'shtml',
|
||||
'log',
|
||||
'xml'
|
||||
);
|
||||
|
||||
|
||||
return (in_array($ext, $text_types)) ? 'ascii' : 'binary';
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close the connection
|
||||
*
|
||||
* @access public
|
||||
* @param string path to source
|
||||
* @param string path to destination
|
||||
* @return bool
|
||||
*/
|
||||
function close()
|
||||
{
|
||||
if ( ! $this->_is_conn())
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ftp_close($this->conn_id);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Display error message
|
||||
*
|
||||
* @access private
|
||||
* @param string
|
||||
* @return bool
|
||||
*/
|
||||
function _error($line)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$CI->lang->load('ftp');
|
||||
show_error($CI->lang->line($line));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// END FTP Class
|
||||
|
||||
/* End of file Ftp.php */
|
||||
/* Location: ./system/libraries/Ftp.php */
|
1537
system/libraries/Image_lib.php
Normal file
1537
system/libraries/Image_lib.php
Normal file
File diff suppressed because it is too large
Load Diff
871
system/libraries/Javascript.php
Normal file
871
system/libraries/Javascript.php
Normal file
@ -0,0 +1,871 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Javascript Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Javascript
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link http://codeigniter.com/user_guide/libraries/javascript.html
|
||||
*/
|
||||
class CI_Javascript {
|
||||
|
||||
var $_javascript_location = 'js';
|
||||
|
||||
public function __construct($params = array())
|
||||
{
|
||||
$defaults = array('js_library_driver' => 'jquery', 'autoload' => TRUE);
|
||||
|
||||
foreach ($defaults as $key => $val)
|
||||
{
|
||||
if (isset($params[$key]) && $params[$key] !== "")
|
||||
{
|
||||
$defaults[$key] = $params[$key];
|
||||
}
|
||||
}
|
||||
|
||||
extract($defaults);
|
||||
|
||||
$this->CI =& get_instance();
|
||||
|
||||
// load the requested js library
|
||||
$this->CI->load->library('javascript/'.$js_library_driver, array('autoload' => $autoload));
|
||||
// make js to refer to current library
|
||||
$this->js =& $this->CI->$js_library_driver;
|
||||
|
||||
log_message('debug', "Javascript Class Initialized and loaded. Driver used: $js_library_driver");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Event Code
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Blur
|
||||
*
|
||||
* Outputs a javascript library blur event
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @param string The code to execute
|
||||
* @return string
|
||||
*/
|
||||
function blur($element = 'this', $js = '')
|
||||
{
|
||||
return $this->js->_blur($element, $js);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Change
|
||||
*
|
||||
* Outputs a javascript library change event
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @param string The code to execute
|
||||
* @return string
|
||||
*/
|
||||
function change($element = 'this', $js = '')
|
||||
{
|
||||
return $this->js->_change($element, $js);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Click
|
||||
*
|
||||
* Outputs a javascript library click event
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @param string The code to execute
|
||||
* @param boolean whether or not to return false
|
||||
* @return string
|
||||
*/
|
||||
function click($element = 'this', $js = '', $ret_false = TRUE)
|
||||
{
|
||||
return $this->js->_click($element, $js, $ret_false);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Double Click
|
||||
*
|
||||
* Outputs a javascript library dblclick event
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @param string The code to execute
|
||||
* @return string
|
||||
*/
|
||||
function dblclick($element = 'this', $js = '')
|
||||
{
|
||||
return $this->js->_dblclick($element, $js);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Outputs a javascript library error event
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @param string The code to execute
|
||||
* @return string
|
||||
*/
|
||||
function error($element = 'this', $js = '')
|
||||
{
|
||||
return $this->js->_error($element, $js);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Focus
|
||||
*
|
||||
* Outputs a javascript library focus event
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @param string The code to execute
|
||||
* @return string
|
||||
*/
|
||||
function focus($element = 'this', $js = '')
|
||||
{
|
||||
return $this->js->__add_event($focus, $js);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Hover
|
||||
*
|
||||
* Outputs a javascript library hover event
|
||||
*
|
||||
* @access public
|
||||
* @param string - element
|
||||
* @param string - Javascript code for mouse over
|
||||
* @param string - Javascript code for mouse out
|
||||
* @return string
|
||||
*/
|
||||
function hover($element = 'this', $over, $out)
|
||||
{
|
||||
return $this->js->__hover($element, $over, $out);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Keydown
|
||||
*
|
||||
* Outputs a javascript library keydown event
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @param string The code to execute
|
||||
* @return string
|
||||
*/
|
||||
function keydown($element = 'this', $js = '')
|
||||
{
|
||||
return $this->js->_keydown($element, $js);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Keyup
|
||||
*
|
||||
* Outputs a javascript library keydown event
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @param string The code to execute
|
||||
* @return string
|
||||
*/
|
||||
function keyup($element = 'this', $js = '')
|
||||
{
|
||||
return $this->js->_keyup($element, $js);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Load
|
||||
*
|
||||
* Outputs a javascript library load event
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @param string The code to execute
|
||||
* @return string
|
||||
*/
|
||||
function load($element = 'this', $js = '')
|
||||
{
|
||||
return $this->js->_load($element, $js);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Mousedown
|
||||
*
|
||||
* Outputs a javascript library mousedown event
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @param string The code to execute
|
||||
* @return string
|
||||
*/
|
||||
function mousedown($element = 'this', $js = '')
|
||||
{
|
||||
return $this->js->_mousedown($element, $js);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Mouse Out
|
||||
*
|
||||
* Outputs a javascript library mouseout event
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @param string The code to execute
|
||||
* @return string
|
||||
*/
|
||||
function mouseout($element = 'this', $js = '')
|
||||
{
|
||||
return $this->js->_mouseout($element, $js);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Mouse Over
|
||||
*
|
||||
* Outputs a javascript library mouseover event
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @param string The code to execute
|
||||
* @return string
|
||||
*/
|
||||
function mouseover($element = 'this', $js = '')
|
||||
{
|
||||
return $this->js->_mouseover($element, $js);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Mouseup
|
||||
*
|
||||
* Outputs a javascript library mouseup event
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @param string The code to execute
|
||||
* @return string
|
||||
*/
|
||||
function mouseup($element = 'this', $js = '')
|
||||
{
|
||||
return $this->js->_mouseup($element, $js);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Output
|
||||
*
|
||||
* Outputs the called javascript to the screen
|
||||
*
|
||||
* @access public
|
||||
* @param string The code to output
|
||||
* @return string
|
||||
*/
|
||||
function output($js)
|
||||
{
|
||||
return $this->js->_output($js);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Ready
|
||||
*
|
||||
* Outputs a javascript library mouseup event
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @param string The code to execute
|
||||
* @return string
|
||||
*/
|
||||
function ready($js)
|
||||
{
|
||||
return $this->js->_document_ready($js);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Resize
|
||||
*
|
||||
* Outputs a javascript library resize event
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @param string The code to execute
|
||||
* @return string
|
||||
*/
|
||||
function resize($element = 'this', $js = '')
|
||||
{
|
||||
return $this->js->_resize($element, $js);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Scroll
|
||||
*
|
||||
* Outputs a javascript library scroll event
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @param string The code to execute
|
||||
* @return string
|
||||
*/
|
||||
function scroll($element = 'this', $js = '')
|
||||
{
|
||||
return $this->js->_scroll($element, $js);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Unload
|
||||
*
|
||||
* Outputs a javascript library unload event
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @param string The code to execute
|
||||
* @return string
|
||||
*/
|
||||
function unload($element = 'this', $js = '')
|
||||
{
|
||||
return $this->js->_unload($element, $js);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Effects
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* Add Class
|
||||
*
|
||||
* Outputs a javascript library addClass event
|
||||
*
|
||||
* @access public
|
||||
* @param string - element
|
||||
* @param string - Class to add
|
||||
* @return string
|
||||
*/
|
||||
function addClass($element = 'this', $class = '')
|
||||
{
|
||||
return $this->js->_addClass($element, $class);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Animate
|
||||
*
|
||||
* Outputs a javascript library animate event
|
||||
*
|
||||
* @access public
|
||||
* @param string - element
|
||||
* @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
|
||||
* @param string - Javascript callback function
|
||||
* @return string
|
||||
*/
|
||||
function animate($element = 'this', $params = array(), $speed = '', $extra = '')
|
||||
{
|
||||
return $this->js->_animate($element, $params, $speed, $extra);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fade In
|
||||
*
|
||||
* Outputs a javascript library hide event
|
||||
*
|
||||
* @access public
|
||||
* @param string - element
|
||||
* @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
|
||||
* @param string - Javascript callback function
|
||||
* @return string
|
||||
*/
|
||||
function fadeIn($element = 'this', $speed = '', $callback = '')
|
||||
{
|
||||
return $this->js->_fadeIn($element, $speed, $callback);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fade Out
|
||||
*
|
||||
* Outputs a javascript library hide event
|
||||
*
|
||||
* @access public
|
||||
* @param string - element
|
||||
* @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
|
||||
* @param string - Javascript callback function
|
||||
* @return string
|
||||
*/
|
||||
function fadeOut($element = 'this', $speed = '', $callback = '')
|
||||
{
|
||||
return $this->js->_fadeOut($element, $speed, $callback);
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Slide Up
|
||||
*
|
||||
* Outputs a javascript library slideUp event
|
||||
*
|
||||
* @access public
|
||||
* @param string - element
|
||||
* @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
|
||||
* @param string - Javascript callback function
|
||||
* @return string
|
||||
*/
|
||||
function slideUp($element = 'this', $speed = '', $callback = '')
|
||||
{
|
||||
return $this->js->_slideUp($element, $speed, $callback);
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Remove Class
|
||||
*
|
||||
* Outputs a javascript library removeClass event
|
||||
*
|
||||
* @access public
|
||||
* @param string - element
|
||||
* @param string - Class to add
|
||||
* @return string
|
||||
*/
|
||||
function removeClass($element = 'this', $class = '')
|
||||
{
|
||||
return $this->js->_removeClass($element, $class);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Slide Down
|
||||
*
|
||||
* Outputs a javascript library slideDown event
|
||||
*
|
||||
* @access public
|
||||
* @param string - element
|
||||
* @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
|
||||
* @param string - Javascript callback function
|
||||
* @return string
|
||||
*/
|
||||
function slideDown($element = 'this', $speed = '', $callback = '')
|
||||
{
|
||||
return $this->js->_slideDown($element, $speed, $callback);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Slide Toggle
|
||||
*
|
||||
* Outputs a javascript library slideToggle event
|
||||
*
|
||||
* @access public
|
||||
* @param string - element
|
||||
* @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
|
||||
* @param string - Javascript callback function
|
||||
* @return string
|
||||
*/
|
||||
function slideToggle($element = 'this', $speed = '', $callback = '')
|
||||
{
|
||||
return $this->js->_slideToggle($element, $speed, $callback);
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Hide
|
||||
*
|
||||
* Outputs a javascript library hide action
|
||||
*
|
||||
* @access public
|
||||
* @param string - element
|
||||
* @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
|
||||
* @param string - Javascript callback function
|
||||
* @return string
|
||||
*/
|
||||
function hide($element = 'this', $speed = '', $callback = '')
|
||||
{
|
||||
return $this->js->_hide($element, $speed, $callback);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Toggle
|
||||
*
|
||||
* Outputs a javascript library toggle event
|
||||
*
|
||||
* @access public
|
||||
* @param string - element
|
||||
* @return string
|
||||
*/
|
||||
function toggle($element = 'this')
|
||||
{
|
||||
return $this->js->_toggle($element);
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Toggle Class
|
||||
*
|
||||
* Outputs a javascript library toggle class event
|
||||
*
|
||||
* @access public
|
||||
* @param string - element
|
||||
* @return string
|
||||
*/
|
||||
function toggleClass($element = 'this', $class='')
|
||||
{
|
||||
return $this->js->_toggleClass($element, $class);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show
|
||||
*
|
||||
* Outputs a javascript library show event
|
||||
*
|
||||
* @access public
|
||||
* @param string - element
|
||||
* @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
|
||||
* @param string - Javascript callback function
|
||||
* @return string
|
||||
*/
|
||||
function show($element = 'this', $speed = '', $callback = '')
|
||||
{
|
||||
return $this->js->_show($element, $speed, $callback);
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Compile
|
||||
*
|
||||
* gather together all script needing to be output
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @return string
|
||||
*/
|
||||
function compile($view_var = 'script_foot', $script_tags = TRUE)
|
||||
{
|
||||
$this->js->_compile($view_var, $script_tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear Compile
|
||||
*
|
||||
* Clears any previous javascript collected for output
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function clear_compile()
|
||||
{
|
||||
$this->js->_clear_compile();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* External
|
||||
*
|
||||
* Outputs a <script> tag with the source as an external js file
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @return string
|
||||
*/
|
||||
function external($external_file = '', $relative = FALSE)
|
||||
{
|
||||
if ($external_file !== '')
|
||||
{
|
||||
$this->_javascript_location = $external_file;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->CI->config->item('javascript_location') != '')
|
||||
{
|
||||
$this->_javascript_location = $this->CI->config->item('javascript_location');
|
||||
}
|
||||
}
|
||||
|
||||
if ($relative === TRUE OR strncmp($external_file, 'http://', 7) == 0 OR strncmp($external_file, 'https://', 8) == 0)
|
||||
{
|
||||
$str = $this->_open_script($external_file);
|
||||
}
|
||||
elseif (strpos($this->_javascript_location, 'http://') !== FALSE)
|
||||
{
|
||||
$str = $this->_open_script($this->_javascript_location.$external_file);
|
||||
}
|
||||
else
|
||||
{
|
||||
$str = $this->_open_script($this->CI->config->slash_item('base_url').$this->_javascript_location.$external_file);
|
||||
}
|
||||
|
||||
$str .= $this->_close_script();
|
||||
return $str;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Inline
|
||||
*
|
||||
* Outputs a <script> tag
|
||||
*
|
||||
* @access public
|
||||
* @param string The element to attach the event to
|
||||
* @param boolean If a CDATA section should be added
|
||||
* @return string
|
||||
*/
|
||||
function inline($script, $cdata = TRUE)
|
||||
{
|
||||
$str = $this->_open_script();
|
||||
$str .= ($cdata) ? "\n// <![CDATA[\n{$script}\n// ]]>\n" : "\n{$script}\n";
|
||||
$str .= $this->_close_script();
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Open Script
|
||||
*
|
||||
* Outputs an opening <script>
|
||||
*
|
||||
* @access private
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function _open_script($src = '')
|
||||
{
|
||||
$str = '<script type="text/javascript" charset="'.strtolower($this->CI->config->item('charset')).'"';
|
||||
$str .= ($src == '') ? '>' : ' src="'.$src.'">';
|
||||
return $str;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close Script
|
||||
*
|
||||
* Outputs an closing </script>
|
||||
*
|
||||
* @access private
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function _close_script($extra = "\n")
|
||||
{
|
||||
return "</script>$extra";
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// --------------------------------------------------------------------
|
||||
// AJAX-Y STUFF - still a testbed
|
||||
// --------------------------------------------------------------------
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update
|
||||
*
|
||||
* Outputs a javascript library slideDown event
|
||||
*
|
||||
* @access public
|
||||
* @param string - element
|
||||
* @param string - One of 'slow', 'normal', 'fast', or time in milliseconds
|
||||
* @param string - Javascript callback function
|
||||
* @return string
|
||||
*/
|
||||
function update($element = 'this', $speed = '', $callback = '')
|
||||
{
|
||||
return $this->js->_updater($element, $speed, $callback);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Generate JSON
|
||||
*
|
||||
* Can be passed a database result or associative array and returns a JSON formatted string
|
||||
*
|
||||
* @param mixed result set or array
|
||||
* @param bool match array types (defaults to objects)
|
||||
* @return string a json formatted string
|
||||
*/
|
||||
function generate_json($result = NULL, $match_array_type = FALSE)
|
||||
{
|
||||
// JSON data can optionally be passed to this function
|
||||
// either as a database result object or an array, or a user supplied array
|
||||
if ( ! is_null($result))
|
||||
{
|
||||
if (is_object($result))
|
||||
{
|
||||
$json_result = $result->result_array();
|
||||
}
|
||||
elseif (is_array($result))
|
||||
{
|
||||
$json_result = $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->_prep_args($result);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 'null';
|
||||
}
|
||||
|
||||
$json = array();
|
||||
$_is_assoc = TRUE;
|
||||
|
||||
if ( ! is_array($json_result) AND empty($json_result))
|
||||
{
|
||||
show_error("Generate JSON Failed - Illegal key, value pair.");
|
||||
}
|
||||
elseif ($match_array_type)
|
||||
{
|
||||
$_is_assoc = $this->_is_associative_array($json_result);
|
||||
}
|
||||
|
||||
foreach ($json_result as $k => $v)
|
||||
{
|
||||
if ($_is_assoc)
|
||||
{
|
||||
$json[] = $this->_prep_args($k, TRUE).':'.$this->generate_json($v, $match_array_type);
|
||||
}
|
||||
else
|
||||
{
|
||||
$json[] = $this->generate_json($v, $match_array_type);
|
||||
}
|
||||
}
|
||||
|
||||
$json = implode(',', $json);
|
||||
|
||||
return $_is_assoc ? "{".$json."}" : "[".$json."]";
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Is associative array
|
||||
*
|
||||
* Checks for an associative array
|
||||
*
|
||||
* @access public
|
||||
* @param type
|
||||
* @return type
|
||||
*/
|
||||
function _is_associative_array($arr)
|
||||
{
|
||||
foreach (array_keys($arr) as $key => $val)
|
||||
{
|
||||
if ($key !== $val)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Prep Args
|
||||
*
|
||||
* Ensures a standard json value and escapes values
|
||||
*
|
||||
* @access public
|
||||
* @param type
|
||||
* @return type
|
||||
*/
|
||||
function _prep_args($result, $is_key = FALSE)
|
||||
{
|
||||
if (is_null($result))
|
||||
{
|
||||
return 'null';
|
||||
}
|
||||
elseif (is_bool($result))
|
||||
{
|
||||
return ($result === TRUE) ? 'true' : 'false';
|
||||
}
|
||||
elseif (is_string($result) OR $is_key)
|
||||
{
|
||||
return '"'.str_replace(array('\\', "\t", "\n", "\r", '"', '/'), array('\\\\', '\\t', '\\n', "\\r", '\"', '\/'), $result).'"';
|
||||
}
|
||||
elseif (is_scalar($result))
|
||||
{
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
}
|
||||
// END Javascript Class
|
||||
|
||||
/* End of file Javascript.php */
|
||||
/* Location: ./system/libraries/Javascript.php */
|
114
system/libraries/Log.php
Normal file
114
system/libraries/Log.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Logging Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Logging
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link http://codeigniter.com/user_guide/general/errors.html
|
||||
*/
|
||||
class CI_Log {
|
||||
|
||||
protected $_log_path;
|
||||
protected $_threshold = 1;
|
||||
protected $_date_fmt = 'Y-m-d H:i:s';
|
||||
protected $_enabled = TRUE;
|
||||
protected $_levels = array('ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4');
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$config =& get_config();
|
||||
|
||||
$this->_log_path = ($config['log_path'] != '') ? $config['log_path'] : APPPATH.'logs/';
|
||||
|
||||
if ( ! is_dir($this->_log_path) OR ! is_really_writable($this->_log_path))
|
||||
{
|
||||
$this->_enabled = FALSE;
|
||||
}
|
||||
|
||||
if (is_numeric($config['log_threshold']))
|
||||
{
|
||||
$this->_threshold = $config['log_threshold'];
|
||||
}
|
||||
|
||||
if ($config['log_date_format'] != '')
|
||||
{
|
||||
$this->_date_fmt = $config['log_date_format'];
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Write Log File
|
||||
*
|
||||
* Generally this function will be called using the global log_message() function
|
||||
*
|
||||
* @param string the error level
|
||||
* @param string the error message
|
||||
* @param bool whether the error is a native PHP error
|
||||
* @return bool
|
||||
*/
|
||||
public function write_log($level = 'error', $msg, $php_error = FALSE)
|
||||
{
|
||||
if ($this->_enabled === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$level = strtoupper($level);
|
||||
|
||||
if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$filepath = $this->_log_path.'log-'.date('Y-m-d').'.php';
|
||||
$message = '';
|
||||
|
||||
if ( ! file_exists($filepath))
|
||||
{
|
||||
$message .= "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n";
|
||||
}
|
||||
|
||||
if ( ! $fp = @fopen($filepath, FOPEN_WRITE_CREATE))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$message .= $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n";
|
||||
|
||||
flock($fp, LOCK_EX);
|
||||
fwrite($fp, $message);
|
||||
flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
|
||||
@chmod($filepath, FILE_WRITE_MODE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
// END Log Class
|
||||
|
||||
/* End of file Log.php */
|
||||
/* Location: ./system/libraries/Log.php */
|
328
system/libraries/Migration.php
Normal file
328
system/libraries/Migration.php
Normal file
@ -0,0 +1,328 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author EllisLab Dev Team
|
||||
* @copyright Copyright (c) 2006 - 2012, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Migration Class
|
||||
*
|
||||
* All migrations should implement this, forces up() and down() and gives
|
||||
* access to the CI super-global.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Libraries
|
||||
* @author Reactor Engineers
|
||||
* @link
|
||||
*/
|
||||
class CI_Migration {
|
||||
|
||||
protected $_migration_enabled = FALSE;
|
||||
protected $_migration_path = NULL;
|
||||
protected $_migration_version = 0;
|
||||
|
||||
protected $_error_string = '';
|
||||
|
||||
public function __construct($config = array())
|
||||
{
|
||||
# Only run this constructor on main library load
|
||||
if (get_parent_class($this) !== FALSE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($config as $key => $val)
|
||||
{
|
||||
$this->{'_' . $key} = $val;
|
||||
}
|
||||
|
||||
log_message('debug', 'Migrations class initialized');
|
||||
|
||||
// Are they trying to use migrations while it is disabled?
|
||||
if ($this->_migration_enabled !== TRUE)
|
||||
{
|
||||
show_error('Migrations has been loaded but is disabled or set up incorrectly.');
|
||||
}
|
||||
|
||||
// If not set, set it
|
||||
$this->_migration_path == '' AND $this->_migration_path = APPPATH . 'migrations/';
|
||||
|
||||
// Add trailing slash if not set
|
||||
$this->_migration_path = rtrim($this->_migration_path, '/').'/';
|
||||
|
||||
// Load migration language
|
||||
$this->lang->load('migration');
|
||||
|
||||
// They'll probably be using dbforge
|
||||
$this->load->dbforge();
|
||||
|
||||
// If the migrations table is missing, make it
|
||||
if ( ! $this->db->table_exists('migrations'))
|
||||
{
|
||||
$this->dbforge->add_field(array(
|
||||
'version' => array('type' => 'INT', 'constraint' => 3),
|
||||
));
|
||||
|
||||
$this->dbforge->create_table('migrations', TRUE);
|
||||
|
||||
$this->db->insert('migrations', array('version' => 0));
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Migrate to a schema version
|
||||
*
|
||||
* Calls each migration step required to get to the schema version of
|
||||
* choice
|
||||
*
|
||||
* @param int Target schema version
|
||||
* @return mixed TRUE if already latest, FALSE if failed, int if upgraded
|
||||
*/
|
||||
public function version($target_version)
|
||||
{
|
||||
$start = $current_version = $this->_get_version();
|
||||
$stop = $target_version;
|
||||
|
||||
if ($target_version > $current_version)
|
||||
{
|
||||
// Moving Up
|
||||
++$start;
|
||||
++$stop;
|
||||
$step = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Moving Down
|
||||
$step = -1;
|
||||
}
|
||||
|
||||
$method = ($step === 1) ? 'up' : 'down';
|
||||
$migrations = array();
|
||||
|
||||
// We now prepare to actually DO the migrations
|
||||
// But first let's make sure that everything is the way it should be
|
||||
for ($i = $start; $i != $stop; $i += $step)
|
||||
{
|
||||
$f = glob(sprintf($this->_migration_path . '%03d_*.php', $i));
|
||||
|
||||
// Only one migration per step is permitted
|
||||
if (count($f) > 1)
|
||||
{
|
||||
$this->_error_string = sprintf($this->lang->line('migration_multiple_version'), $i);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Migration step not found
|
||||
if (count($f) == 0)
|
||||
{
|
||||
// If trying to migrate up to a version greater than the last
|
||||
// existing one, migrate to the last one.
|
||||
if ($step == 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// If trying to migrate down but we're missing a step,
|
||||
// something must definitely be wrong.
|
||||
$this->_error_string = sprintf($this->lang->line('migration_not_found'), $i);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$file = basename($f[0]);
|
||||
$name = basename($f[0], '.php');
|
||||
|
||||
// Filename validations
|
||||
if (preg_match('/^\d{3}_(\w+)$/', $name, $match))
|
||||
{
|
||||
$match[1] = strtolower($match[1]);
|
||||
|
||||
// Cannot repeat a migration at different steps
|
||||
if (in_array($match[1], $migrations))
|
||||
{
|
||||
$this->_error_string = sprintf($this->lang->line('migration_multiple_version'), $match[1]);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
include $f[0];
|
||||
$class = 'Migration_' . ucfirst($match[1]);
|
||||
|
||||
if ( ! class_exists($class))
|
||||
{
|
||||
$this->_error_string = sprintf($this->lang->line('migration_class_doesnt_exist'), $class);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( ! is_callable(array($class, $method)))
|
||||
{
|
||||
$this->_error_string = sprintf($this->lang->line('migration_missing_'.$method.'_method'), $class);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$migrations[] = $match[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_error_string = sprintf($this->lang->line('migration_invalid_filename'), $file);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
log_message('debug', 'Current migration: ' . $current_version);
|
||||
|
||||
$version = $i + ($step == 1 ? -1 : 0);
|
||||
|
||||
// If there is nothing to do so quit
|
||||
if ($migrations === array())
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
log_message('debug', 'Migrating from ' . $method . ' to version ' . $version);
|
||||
|
||||
// Loop through the migrations
|
||||
foreach ($migrations AS $migration)
|
||||
{
|
||||
// Run the migration class
|
||||
$class = 'Migration_' . ucfirst(strtolower($migration));
|
||||
call_user_func(array(new $class, $method));
|
||||
|
||||
$current_version += $step;
|
||||
$this->_update_version($current_version);
|
||||
}
|
||||
|
||||
log_message('debug', 'Finished migrating to '.$current_version);
|
||||
|
||||
return $current_version;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set's the schema to the latest migration
|
||||
*
|
||||
* @return mixed true if already latest, false if failed, int if upgraded
|
||||
*/
|
||||
public function latest()
|
||||
{
|
||||
if ( ! $migrations = $this->find_migrations())
|
||||
{
|
||||
$this->_error_string = $this->line->lang('migration_none_found');
|
||||
return false;
|
||||
}
|
||||
|
||||
$last_migration = basename(end($migrations));
|
||||
|
||||
// Calculate the last migration step from existing migration
|
||||
// filenames and procceed to the standard version migration
|
||||
return $this->version((int) substr($last_migration, 0, 3));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set's the schema to the migration version set in config
|
||||
*
|
||||
* @return mixed true if already current, false if failed, int if upgraded
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
return $this->version($this->_migration_version);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error string
|
||||
*
|
||||
* @return string Error message returned as a string
|
||||
*/
|
||||
public function error_string()
|
||||
{
|
||||
return $this->_error_string;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set's the schema to the latest migration
|
||||
*
|
||||
* @return mixed true if already latest, false if failed, int if upgraded
|
||||
*/
|
||||
protected function find_migrations()
|
||||
{
|
||||
// Load all *_*.php files in the migrations path
|
||||
$files = glob($this->_migration_path . '*_*.php');
|
||||
$file_count = count($files);
|
||||
|
||||
for ($i = 0; $i < $file_count; $i++)
|
||||
{
|
||||
// Mark wrongly formatted files as false for later filtering
|
||||
$name = basename($files[$i], '.php');
|
||||
if ( ! preg_match('/^\d{3}_(\w+)$/', $name))
|
||||
{
|
||||
$files[$i] = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
sort($files);
|
||||
return $files;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Retrieves current schema version
|
||||
*
|
||||
* @return int Current Migration
|
||||
*/
|
||||
protected function _get_version()
|
||||
{
|
||||
$row = $this->db->get('migrations')->row();
|
||||
return $row ? $row->version : 0;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Stores the current schema version
|
||||
*
|
||||
* @param int Migration reached
|
||||
* @return bool
|
||||
*/
|
||||
protected function _update_version($migrations)
|
||||
{
|
||||
return $this->db->update('migrations', array(
|
||||
'version' => $migrations
|
||||
));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Enable the use of CI super-global
|
||||
*
|
||||
* @param mixed $var
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($var)
|
||||
{
|
||||
return get_instance()->$var;
|
||||
}
|
||||
}
|
||||
|
||||
/* End of file Migration.php */
|
||||
/* Location: ./system/libraries/Migration.php */
|
340
system/libraries/Pagination.php
Normal file
340
system/libraries/Pagination.php
Normal file
@ -0,0 +1,340 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Pagination Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Pagination
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link http://codeigniter.com/user_guide/libraries/pagination.html
|
||||
*/
|
||||
class CI_Pagination {
|
||||
|
||||
var $base_url = ''; // The page we are linking to
|
||||
var $prefix = ''; // A custom prefix added to the path.
|
||||
var $suffix = ''; // A custom suffix added to the path.
|
||||
|
||||
var $total_rows = 0; // Total number of items (database results)
|
||||
var $per_page = 10; // Max number of items you want shown per page
|
||||
var $num_links = 2; // Number of "digit" links to show before/after the currently viewed page
|
||||
var $cur_page = 0; // The current page being viewed
|
||||
var $use_page_numbers = FALSE; // Use page number for segment instead of offset
|
||||
var $first_link = '‹ First';
|
||||
var $next_link = '>';
|
||||
var $prev_link = '<';
|
||||
var $last_link = 'Last ›';
|
||||
var $uri_segment = 3;
|
||||
var $full_tag_open = '';
|
||||
var $full_tag_close = '';
|
||||
var $first_tag_open = '';
|
||||
var $first_tag_close = ' ';
|
||||
var $last_tag_open = ' ';
|
||||
var $last_tag_close = '';
|
||||
var $first_url = ''; // Alternative URL for the First Page.
|
||||
var $cur_tag_open = ' <strong>';
|
||||
var $cur_tag_close = '</strong>';
|
||||
var $next_tag_open = ' ';
|
||||
var $next_tag_close = ' ';
|
||||
var $prev_tag_open = ' ';
|
||||
var $prev_tag_close = '';
|
||||
var $num_tag_open = ' ';
|
||||
var $num_tag_close = '';
|
||||
var $page_query_string = FALSE;
|
||||
var $query_string_segment = 'per_page';
|
||||
var $display_pages = TRUE;
|
||||
var $anchor_class = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
* @param array initialization parameters
|
||||
*/
|
||||
public function __construct($params = array())
|
||||
{
|
||||
if (count($params) > 0)
|
||||
{
|
||||
$this->initialize($params);
|
||||
}
|
||||
|
||||
if ($this->anchor_class != '')
|
||||
{
|
||||
$this->anchor_class = 'class="'.$this->anchor_class.'" ';
|
||||
}
|
||||
|
||||
log_message('debug', "Pagination Class Initialized");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Initialize Preferences
|
||||
*
|
||||
* @access public
|
||||
* @param array initialization parameters
|
||||
* @return void
|
||||
*/
|
||||
function initialize($params = array())
|
||||
{
|
||||
if (count($params) > 0)
|
||||
{
|
||||
foreach ($params as $key => $val)
|
||||
{
|
||||
if (isset($this->$key))
|
||||
{
|
||||
$this->$key = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Generate the pagination links
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function create_links()
|
||||
{
|
||||
// If our item count or per-page total is zero there is no need to continue.
|
||||
if ($this->total_rows == 0 OR $this->per_page == 0)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
// Calculate the total number of pages
|
||||
$num_pages = ceil($this->total_rows / $this->per_page);
|
||||
|
||||
// Is there only one page? Hm... nothing more to do here then.
|
||||
if ($num_pages == 1)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
// Set the base page index for starting page number
|
||||
if ($this->use_page_numbers)
|
||||
{
|
||||
$base_page = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$base_page = 0;
|
||||
}
|
||||
|
||||
// Determine the current page number.
|
||||
$CI =& get_instance();
|
||||
|
||||
if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
|
||||
{
|
||||
if ($CI->input->get($this->query_string_segment) != $base_page)
|
||||
{
|
||||
$this->cur_page = $CI->input->get($this->query_string_segment);
|
||||
|
||||
// Prep the current page - no funny business!
|
||||
$this->cur_page = (int) $this->cur_page;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($CI->uri->segment($this->uri_segment) != $base_page)
|
||||
{
|
||||
$this->cur_page = $CI->uri->segment($this->uri_segment);
|
||||
|
||||
// Prep the current page - no funny business!
|
||||
$this->cur_page = (int) $this->cur_page;
|
||||
}
|
||||
}
|
||||
|
||||
// Set current page to 1 if using page numbers instead of offset
|
||||
if ($this->use_page_numbers AND $this->cur_page == 0)
|
||||
{
|
||||
$this->cur_page = $base_page;
|
||||
}
|
||||
|
||||
$this->num_links = (int)$this->num_links;
|
||||
|
||||
if ($this->num_links < 1)
|
||||
{
|
||||
show_error('Your number of links must be a positive number.');
|
||||
}
|
||||
|
||||
if ( ! is_numeric($this->cur_page))
|
||||
{
|
||||
$this->cur_page = $base_page;
|
||||
}
|
||||
|
||||
// Is the page number beyond the result range?
|
||||
// If so we show the last page
|
||||
if ($this->use_page_numbers)
|
||||
{
|
||||
if ($this->cur_page > $num_pages)
|
||||
{
|
||||
$this->cur_page = $num_pages;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->cur_page > $this->total_rows)
|
||||
{
|
||||
$this->cur_page = ($num_pages - 1) * $this->per_page;
|
||||
}
|
||||
}
|
||||
|
||||
$uri_page_number = $this->cur_page;
|
||||
|
||||
if ( ! $this->use_page_numbers)
|
||||
{
|
||||
$this->cur_page = floor(($this->cur_page/$this->per_page) + 1);
|
||||
}
|
||||
|
||||
// Calculate the start and end numbers. These determine
|
||||
// which number to start and end the digit links with
|
||||
$start = (($this->cur_page - $this->num_links) > 0) ? $this->cur_page - ($this->num_links - 1) : 1;
|
||||
$end = (($this->cur_page + $this->num_links) < $num_pages) ? $this->cur_page + $this->num_links : $num_pages;
|
||||
|
||||
// Is pagination being used over GET or POST? If get, add a per_page query
|
||||
// string. If post, add a trailing slash to the base URL if needed
|
||||
if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE)
|
||||
{
|
||||
$this->base_url = rtrim($this->base_url).'&'.$this->query_string_segment.'=';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->base_url = rtrim($this->base_url, '/') .'/';
|
||||
}
|
||||
|
||||
// And here we go...
|
||||
$output = '';
|
||||
|
||||
// Render the "First" link
|
||||
if ($this->first_link !== FALSE AND $this->cur_page > ($this->num_links + 1))
|
||||
{
|
||||
$first_url = ($this->first_url == '') ? $this->base_url : $this->first_url;
|
||||
$output .= $this->first_tag_open.'<a '.$this->anchor_class.'href="'.$first_url.'">'.$this->first_link.'</a>'.$this->first_tag_close;
|
||||
}
|
||||
|
||||
// Render the "previous" link
|
||||
if ($this->prev_link !== FALSE AND $this->cur_page != 1)
|
||||
{
|
||||
if ($this->use_page_numbers)
|
||||
{
|
||||
$i = $uri_page_number - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$i = $uri_page_number - $this->per_page;
|
||||
}
|
||||
|
||||
if ($i == 0 && $this->first_url != '')
|
||||
{
|
||||
$output .= $this->prev_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;
|
||||
}
|
||||
else
|
||||
{
|
||||
$i = ($i == 0) ? '' : $this->prefix.$i.$this->suffix;
|
||||
$output .= $this->prev_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$i.'">'.$this->prev_link.'</a>'.$this->prev_tag_close;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Render the pages
|
||||
if ($this->display_pages !== FALSE)
|
||||
{
|
||||
// Write the digit links
|
||||
for ($loop = $start -1; $loop <= $end; $loop++)
|
||||
{
|
||||
if ($this->use_page_numbers)
|
||||
{
|
||||
$i = $loop;
|
||||
}
|
||||
else
|
||||
{
|
||||
$i = ($loop * $this->per_page) - $this->per_page;
|
||||
}
|
||||
|
||||
if ($i >= $base_page)
|
||||
{
|
||||
if ($this->cur_page == $loop)
|
||||
{
|
||||
$output .= $this->cur_tag_open.$loop.$this->cur_tag_close; // Current page
|
||||
}
|
||||
else
|
||||
{
|
||||
$n = ($i == $base_page) ? '' : $i;
|
||||
|
||||
if ($n == '' && $this->first_url != '')
|
||||
{
|
||||
$output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'">'.$loop.'</a>'.$this->num_tag_close;
|
||||
}
|
||||
else
|
||||
{
|
||||
$n = ($n == '') ? '' : $this->prefix.$n.$this->suffix;
|
||||
|
||||
$output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$n.'">'.$loop.'</a>'.$this->num_tag_close;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Render the "next" link
|
||||
if ($this->next_link !== FALSE AND $this->cur_page < $num_pages)
|
||||
{
|
||||
if ($this->use_page_numbers)
|
||||
{
|
||||
$i = $this->cur_page + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$i = ($this->cur_page * $this->per_page);
|
||||
}
|
||||
|
||||
$output .= $this->next_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->next_link.'</a>'.$this->next_tag_close;
|
||||
}
|
||||
|
||||
// Render the "Last" link
|
||||
if ($this->last_link !== FALSE AND ($this->cur_page + $this->num_links) < $num_pages)
|
||||
{
|
||||
if ($this->use_page_numbers)
|
||||
{
|
||||
$i = $num_pages;
|
||||
}
|
||||
else
|
||||
{
|
||||
$i = (($num_pages * $this->per_page) - $this->per_page);
|
||||
}
|
||||
$output .= $this->last_tag_open.'<a '.$this->anchor_class.'href="'.$this->base_url.$this->prefix.$i.$this->suffix.'">'.$this->last_link.'</a>'.$this->last_tag_close;
|
||||
}
|
||||
|
||||
// Kill double slashes. Note: Sometimes we can end up with a double slash
|
||||
// in the penultimate link so we'll kill all double slashes.
|
||||
$output = preg_replace("#([^:])//+#", "\\1/", $output);
|
||||
|
||||
// Add the wrapper HTML if exists
|
||||
$output = $this->full_tag_open.$output.$this->full_tag_close;
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
// END Pagination Class
|
||||
|
||||
/* End of file Pagination.php */
|
||||
/* Location: ./system/libraries/Pagination.php */
|
212
system/libraries/Parser.php
Normal file
212
system/libraries/Parser.php
Normal file
@ -0,0 +1,212 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Parser Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Parser
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link http://codeigniter.com/user_guide/libraries/parser.html
|
||||
*/
|
||||
class CI_Parser {
|
||||
|
||||
var $l_delim = '{';
|
||||
var $r_delim = '}';
|
||||
var $object;
|
||||
|
||||
/**
|
||||
* Parse a template
|
||||
*
|
||||
* Parses pseudo-variables contained in the specified template view,
|
||||
* replacing them with the data in the second param
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @param array
|
||||
* @param bool
|
||||
* @return string
|
||||
*/
|
||||
public function parse($template, $data, $return = FALSE)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$template = $CI->load->view($template, $data, TRUE);
|
||||
|
||||
return $this->_parse($template, $data, $return);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Parse a String
|
||||
*
|
||||
* Parses pseudo-variables contained in the specified string,
|
||||
* replacing them with the data in the second param
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @param array
|
||||
* @param bool
|
||||
* @return string
|
||||
*/
|
||||
function parse_string($template, $data, $return = FALSE)
|
||||
{
|
||||
return $this->_parse($template, $data, $return);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Parse a template
|
||||
*
|
||||
* Parses pseudo-variables contained in the specified template,
|
||||
* replacing them with the data in the second param
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @param array
|
||||
* @param bool
|
||||
* @return string
|
||||
*/
|
||||
function _parse($template, $data, $return = FALSE)
|
||||
{
|
||||
if ($template == '')
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
foreach ($data as $key => $val)
|
||||
{
|
||||
if (is_array($val))
|
||||
{
|
||||
$template = $this->_parse_pair($key, $val, $template);
|
||||
}
|
||||
else
|
||||
{
|
||||
$template = $this->_parse_single($key, (string)$val, $template);
|
||||
}
|
||||
}
|
||||
|
||||
if ($return == FALSE)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$CI->output->append_output($template);
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the left/right variable delimiters
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @param string
|
||||
* @return void
|
||||
*/
|
||||
function set_delimiters($l = '{', $r = '}')
|
||||
{
|
||||
$this->l_delim = $l;
|
||||
$this->r_delim = $r;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Parse a single key/value
|
||||
*
|
||||
* @access private
|
||||
* @param string
|
||||
* @param string
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function _parse_single($key, $val, $string)
|
||||
{
|
||||
return str_replace($this->l_delim.$key.$this->r_delim, $val, $string);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Parse a tag pair
|
||||
*
|
||||
* Parses tag pairs: {some_tag} string... {/some_tag}
|
||||
*
|
||||
* @access private
|
||||
* @param string
|
||||
* @param array
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function _parse_pair($variable, $data, $string)
|
||||
{
|
||||
if (FALSE === ($match = $this->_match_pair($string, $variable)))
|
||||
{
|
||||
return $string;
|
||||
}
|
||||
|
||||
$str = '';
|
||||
foreach ($data as $row)
|
||||
{
|
||||
$temp = $match['1'];
|
||||
foreach ($row as $key => $val)
|
||||
{
|
||||
if ( ! is_array($val))
|
||||
{
|
||||
$temp = $this->_parse_single($key, $val, $temp);
|
||||
}
|
||||
else
|
||||
{
|
||||
$temp = $this->_parse_pair($key, $val, $temp);
|
||||
}
|
||||
}
|
||||
|
||||
$str .= $temp;
|
||||
}
|
||||
|
||||
return str_replace($match['0'], $str, $string);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Matches a variable pair
|
||||
*
|
||||
* @access private
|
||||
* @param string
|
||||
* @param string
|
||||
* @return mixed
|
||||
*/
|
||||
function _match_pair($string, $variable)
|
||||
{
|
||||
if ( ! preg_match("|" . preg_quote($this->l_delim) . $variable . preg_quote($this->r_delim) . "(.+?)". preg_quote($this->l_delim) . '/' . $variable . preg_quote($this->r_delim) . "|s", $string, $match))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return $match;
|
||||
}
|
||||
|
||||
}
|
||||
// END Parser Class
|
||||
|
||||
/* End of file Parser.php */
|
||||
/* Location: ./system/libraries/Parser.php */
|
558
system/libraries/Profiler.php
Normal file
558
system/libraries/Profiler.php
Normal file
@ -0,0 +1,558 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* CodeIgniter Profiler Class
|
||||
*
|
||||
* This class enables you to display benchmark, query, and other data
|
||||
* in order to help with debugging and optimization.
|
||||
*
|
||||
* Note: At some point it would be good to move all the HTML in this class
|
||||
* into a set of template files in order to allow customization.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Libraries
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link http://codeigniter.com/user_guide/general/profiling.html
|
||||
*/
|
||||
class CI_Profiler {
|
||||
|
||||
protected $_available_sections = array(
|
||||
'benchmarks',
|
||||
'get',
|
||||
'memory_usage',
|
||||
'post',
|
||||
'uri_string',
|
||||
'controller_info',
|
||||
'queries',
|
||||
'http_headers',
|
||||
'session_data',
|
||||
'config'
|
||||
);
|
||||
|
||||
protected $_query_toggle_count = 25;
|
||||
|
||||
protected $CI;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
public function __construct($config = array())
|
||||
{
|
||||
$this->CI =& get_instance();
|
||||
$this->CI->load->language('profiler');
|
||||
|
||||
if (isset($config['query_toggle_count']))
|
||||
{
|
||||
$this->_query_toggle_count = (int) $config['query_toggle_count'];
|
||||
unset($config['query_toggle_count']);
|
||||
}
|
||||
|
||||
// default all sections to display
|
||||
foreach ($this->_available_sections as $section)
|
||||
{
|
||||
if ( ! isset($config[$section]))
|
||||
{
|
||||
$this->_compile_{$section} = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
$this->set_sections($config);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set Sections
|
||||
*
|
||||
* Sets the private _compile_* properties to enable/disable Profiler sections
|
||||
*
|
||||
* @param mixed
|
||||
* @return void
|
||||
*/
|
||||
public function set_sections($config)
|
||||
{
|
||||
foreach ($config as $method => $enable)
|
||||
{
|
||||
if (in_array($method, $this->_available_sections))
|
||||
{
|
||||
$this->_compile_{$method} = ($enable !== FALSE) ? TRUE : FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Auto Profiler
|
||||
*
|
||||
* This function cycles through the entire array of mark points and
|
||||
* matches any two points that are named identically (ending in "_start"
|
||||
* and "_end" respectively). It then compiles the execution times for
|
||||
* all points and returns it as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _compile_benchmarks()
|
||||
{
|
||||
$profile = array();
|
||||
foreach ($this->CI->benchmark->marker as $key => $val)
|
||||
{
|
||||
// We match the "end" marker so that the list ends
|
||||
// up in the order that it was defined
|
||||
if (preg_match("/(.+?)_end/i", $key, $match))
|
||||
{
|
||||
if (isset($this->CI->benchmark->marker[$match[1].'_end']) AND isset($this->CI->benchmark->marker[$match[1].'_start']))
|
||||
{
|
||||
$profile[$match[1]] = $this->CI->benchmark->elapsed_time($match[1].'_start', $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Build a table containing the profile data.
|
||||
// Note: At some point we should turn this into a template that can
|
||||
// be modified. We also might want to make this data available to be logged
|
||||
|
||||
$output = "\n\n";
|
||||
$output .= '<fieldset id="ci_profiler_benchmarks" style="border:1px solid #900;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
|
||||
$output .= "\n";
|
||||
$output .= '<legend style="color:#900;"> '.$this->CI->lang->line('profiler_benchmarks').' </legend>';
|
||||
$output .= "\n";
|
||||
$output .= "\n\n<table style='width:100%'>\n";
|
||||
|
||||
foreach ($profile as $key => $val)
|
||||
{
|
||||
$key = ucwords(str_replace(array('_', '-'), ' ', $key));
|
||||
$output .= "<tr><td style='padding:5px;width:50%;color:#000;font-weight:bold;background-color:#ddd;'>".$key." </td><td style='padding:5px;width:50%;color:#900;font-weight:normal;background-color:#ddd;'>".$val."</td></tr>\n";
|
||||
}
|
||||
|
||||
$output .= "</table>\n";
|
||||
$output .= "</fieldset>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Compile Queries
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _compile_queries()
|
||||
{
|
||||
$dbs = array();
|
||||
|
||||
// Let's determine which databases are currently connected to
|
||||
foreach (get_object_vars($this->CI) as $CI_object)
|
||||
{
|
||||
if (is_object($CI_object) && is_subclass_of(get_class($CI_object), 'CI_DB') )
|
||||
{
|
||||
$dbs[] = $CI_object;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($dbs) == 0)
|
||||
{
|
||||
$output = "\n\n";
|
||||
$output .= '<fieldset id="ci_profiler_queries" style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
|
||||
$output .= "\n";
|
||||
$output .= '<legend style="color:#0000FF;"> '.$this->CI->lang->line('profiler_queries').' </legend>';
|
||||
$output .= "\n";
|
||||
$output .= "\n\n<table style='border:none; width:100%;'>\n";
|
||||
$output .="<tr><td style='width:100%;color:#0000FF;font-weight:normal;background-color:#eee;padding:5px'>".$this->CI->lang->line('profiler_no_db')."</td></tr>\n";
|
||||
$output .= "</table>\n";
|
||||
$output .= "</fieldset>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
// Load the text helper so we can highlight the SQL
|
||||
$this->CI->load->helper('text');
|
||||
|
||||
// Key words we want bolded
|
||||
$highlight = array('SELECT', 'DISTINCT', 'FROM', 'WHERE', 'AND', 'LEFT JOIN', 'ORDER BY', 'GROUP BY', 'LIMIT', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'OR ', 'HAVING', 'OFFSET', 'NOT IN', 'IN', 'LIKE', 'NOT LIKE', 'COUNT', 'MAX', 'MIN', 'ON', 'AS', 'AVG', 'SUM', '(', ')');
|
||||
|
||||
$output = "\n\n";
|
||||
|
||||
$count = 0;
|
||||
|
||||
foreach ($dbs as $db)
|
||||
{
|
||||
$count++;
|
||||
|
||||
$hide_queries = (count($db->queries) > $this->_query_toggle_count) ? ' display:none' : '';
|
||||
|
||||
$show_hide_js = '(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_queries_db_'.$count.'\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_hide').'\'?\''.$this->CI->lang->line('profiler_section_show').'\':\''.$this->CI->lang->line('profiler_section_hide').'\';">'.$this->CI->lang->line('profiler_section_hide').'</span>)';
|
||||
|
||||
if ($hide_queries != '')
|
||||
{
|
||||
$show_hide_js = '(<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_queries_db_'.$count.'\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show').'</span>)';
|
||||
}
|
||||
|
||||
$output .= '<fieldset style="border:1px solid #0000FF;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
|
||||
$output .= "\n";
|
||||
$output .= '<legend style="color:#0000FF;"> '.$this->CI->lang->line('profiler_database').': '.$db->database.' '.$this->CI->lang->line('profiler_queries').': '.count($db->queries).' '.$show_hide_js.'</legend>';
|
||||
$output .= "\n";
|
||||
$output .= "\n\n<table style='width:100%;{$hide_queries}' id='ci_profiler_queries_db_{$count}'>\n";
|
||||
|
||||
if (count($db->queries) == 0)
|
||||
{
|
||||
$output .= "<tr><td style='width:100%;color:#0000FF;font-weight:normal;background-color:#eee;padding:5px;'>".$this->CI->lang->line('profiler_no_queries')."</td></tr>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($db->queries as $key => $val)
|
||||
{
|
||||
$time = number_format($db->query_times[$key], 4);
|
||||
|
||||
$val = highlight_code($val, ENT_QUOTES);
|
||||
|
||||
foreach ($highlight as $bold)
|
||||
{
|
||||
$val = str_replace($bold, '<strong>'.$bold.'</strong>', $val);
|
||||
}
|
||||
|
||||
$output .= "<tr><td style='padding:5px; vertical-align: top;width:1%;color:#900;font-weight:normal;background-color:#ddd;'>".$time." </td><td style='padding:5px; color:#000;font-weight:normal;background-color:#ddd;'>".$val."</td></tr>\n";
|
||||
}
|
||||
}
|
||||
|
||||
$output .= "</table>\n";
|
||||
$output .= "</fieldset>";
|
||||
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Compile $_GET Data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _compile_get()
|
||||
{
|
||||
$output = "\n\n";
|
||||
$output .= '<fieldset id="ci_profiler_get" style="border:1px solid #cd6e00;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
|
||||
$output .= "\n";
|
||||
$output .= '<legend style="color:#cd6e00;"> '.$this->CI->lang->line('profiler_get_data').' </legend>';
|
||||
$output .= "\n";
|
||||
|
||||
if (count($_GET) == 0)
|
||||
{
|
||||
$output .= "<div style='color:#cd6e00;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_get')."</div>";
|
||||
}
|
||||
else
|
||||
{
|
||||
$output .= "\n\n<table style='width:100%; border:none'>\n";
|
||||
|
||||
foreach ($_GET as $key => $val)
|
||||
{
|
||||
if ( ! is_numeric($key))
|
||||
{
|
||||
$key = "'".$key."'";
|
||||
}
|
||||
|
||||
$output .= "<tr><td style='width:50%;color:#000;background-color:#ddd;padding:5px'>$_GET[".$key."] </td><td style='width:50%;padding:5px;color:#cd6e00;font-weight:normal;background-color:#ddd;'>";
|
||||
if (is_array($val))
|
||||
{
|
||||
$output .= "<pre>" . htmlspecialchars(stripslashes(print_r($val, true))) . "</pre>";
|
||||
}
|
||||
else
|
||||
{
|
||||
$output .= htmlspecialchars(stripslashes($val));
|
||||
}
|
||||
$output .= "</td></tr>\n";
|
||||
}
|
||||
|
||||
$output .= "</table>\n";
|
||||
}
|
||||
$output .= "</fieldset>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Compile $_POST Data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _compile_post()
|
||||
{
|
||||
$output = "\n\n";
|
||||
$output .= '<fieldset id="ci_profiler_post" style="border:1px solid #009900;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
|
||||
$output .= "\n";
|
||||
$output .= '<legend style="color:#009900;"> '.$this->CI->lang->line('profiler_post_data').' </legend>';
|
||||
$output .= "\n";
|
||||
|
||||
if (count($_POST) == 0)
|
||||
{
|
||||
$output .= "<div style='color:#009900;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_post')."</div>";
|
||||
}
|
||||
else
|
||||
{
|
||||
$output .= "\n\n<table style='width:100%'>\n";
|
||||
|
||||
foreach ($_POST as $key => $val)
|
||||
{
|
||||
if ( ! is_numeric($key))
|
||||
{
|
||||
$key = "'".$key."'";
|
||||
}
|
||||
|
||||
$output .= "<tr><td style='width:50%;padding:5px;color:#000;background-color:#ddd;'>$_POST[".$key."] </td><td style='width:50%;padding:5px;color:#009900;font-weight:normal;background-color:#ddd;'>";
|
||||
if (is_array($val))
|
||||
{
|
||||
$output .= "<pre>" . htmlspecialchars(stripslashes(print_r($val, TRUE))) . "</pre>";
|
||||
}
|
||||
else
|
||||
{
|
||||
$output .= htmlspecialchars(stripslashes($val));
|
||||
}
|
||||
$output .= "</td></tr>\n";
|
||||
}
|
||||
|
||||
$output .= "</table>\n";
|
||||
}
|
||||
$output .= "</fieldset>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show query string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _compile_uri_string()
|
||||
{
|
||||
$output = "\n\n";
|
||||
$output .= '<fieldset id="ci_profiler_uri_string" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
|
||||
$output .= "\n";
|
||||
$output .= '<legend style="color:#000;"> '.$this->CI->lang->line('profiler_uri_string').' </legend>';
|
||||
$output .= "\n";
|
||||
|
||||
if ($this->CI->uri->uri_string == '')
|
||||
{
|
||||
$output .= "<div style='color:#000;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_uri')."</div>";
|
||||
}
|
||||
else
|
||||
{
|
||||
$output .= "<div style='color:#000;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->uri->uri_string."</div>";
|
||||
}
|
||||
|
||||
$output .= "</fieldset>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show the controller and function that were called
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _compile_controller_info()
|
||||
{
|
||||
$output = "\n\n";
|
||||
$output .= '<fieldset id="ci_profiler_controller_info" style="border:1px solid #995300;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
|
||||
$output .= "\n";
|
||||
$output .= '<legend style="color:#995300;"> '.$this->CI->lang->line('profiler_controller_info').' </legend>';
|
||||
$output .= "\n";
|
||||
|
||||
$output .= "<div style='color:#995300;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->router->fetch_class()."/".$this->CI->router->fetch_method()."</div>";
|
||||
|
||||
$output .= "</fieldset>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Compile memory usage
|
||||
*
|
||||
* Display total used memory
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _compile_memory_usage()
|
||||
{
|
||||
$output = "\n\n";
|
||||
$output .= '<fieldset id="ci_profiler_memory_usage" style="border:1px solid #5a0099;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
|
||||
$output .= "\n";
|
||||
$output .= '<legend style="color:#5a0099;"> '.$this->CI->lang->line('profiler_memory_usage').' </legend>';
|
||||
$output .= "\n";
|
||||
|
||||
if (function_exists('memory_get_usage') && ($usage = memory_get_usage()) != '')
|
||||
{
|
||||
$output .= "<div style='color:#5a0099;font-weight:normal;padding:4px 0 4px 0'>".number_format($usage).' bytes</div>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$output .= "<div style='color:#5a0099;font-weight:normal;padding:4px 0 4px 0'>".$this->CI->lang->line('profiler_no_memory')."</div>";
|
||||
}
|
||||
|
||||
$output .= "</fieldset>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Compile header information
|
||||
*
|
||||
* Lists HTTP headers
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _compile_http_headers()
|
||||
{
|
||||
$output = "\n\n";
|
||||
$output .= '<fieldset id="ci_profiler_http_headers" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
|
||||
$output .= "\n";
|
||||
$output .= '<legend style="color:#000;"> '.$this->CI->lang->line('profiler_headers').' (<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_httpheaders_table\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show').'</span>)</legend>';
|
||||
$output .= "\n";
|
||||
|
||||
$output .= "\n\n<table style='width:100%;display:none' id='ci_profiler_httpheaders_table'>\n";
|
||||
|
||||
foreach (array('HTTP_ACCEPT', 'HTTP_USER_AGENT', 'HTTP_CONNECTION', 'SERVER_PORT', 'SERVER_NAME', 'REMOTE_ADDR', 'SERVER_SOFTWARE', 'HTTP_ACCEPT_LANGUAGE', 'SCRIPT_NAME', 'REQUEST_METHOD',' HTTP_HOST', 'REMOTE_HOST', 'CONTENT_TYPE', 'SERVER_PROTOCOL', 'QUERY_STRING', 'HTTP_ACCEPT_ENCODING', 'HTTP_X_FORWARDED_FOR') as $header)
|
||||
{
|
||||
$val = (isset($_SERVER[$header])) ? $_SERVER[$header] : '';
|
||||
$output .= "<tr><td style='vertical-align: top;width:50%;padding:5px;color:#900;background-color:#ddd;'>".$header." </td><td style='width:50%;padding:5px;color:#000;background-color:#ddd;'>".$val."</td></tr>\n";
|
||||
}
|
||||
|
||||
$output .= "</table>\n";
|
||||
$output .= "</fieldset>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Compile config information
|
||||
*
|
||||
* Lists developer config variables
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _compile_config()
|
||||
{
|
||||
$output = "\n\n";
|
||||
$output .= '<fieldset id="ci_profiler_config" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
|
||||
$output .= "\n";
|
||||
$output .= '<legend style="color:#000;"> '.$this->CI->lang->line('profiler_config').' (<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_config_table\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show').'</span>)</legend>';
|
||||
$output .= "\n";
|
||||
|
||||
$output .= "\n\n<table style='width:100%; display:none' id='ci_profiler_config_table'>\n";
|
||||
|
||||
foreach ($this->CI->config->config as $config=>$val)
|
||||
{
|
||||
if (is_array($val))
|
||||
{
|
||||
$val = print_r($val, TRUE);
|
||||
}
|
||||
|
||||
$output .= "<tr><td style='padding:5px; vertical-align: top;color:#900;background-color:#ddd;'>".$config." </td><td style='padding:5px; color:#000;background-color:#ddd;'>".htmlspecialchars($val)."</td></tr>\n";
|
||||
}
|
||||
|
||||
$output .= "</table>\n";
|
||||
$output .= "</fieldset>";
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Compile session userdata
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _compile_session_data()
|
||||
{
|
||||
if ( ! isset($this->CI->session))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$output = '<fieldset id="ci_profiler_csession" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
|
||||
$output .= '<legend style="color:#000;"> '.$this->CI->lang->line('profiler_session_data').' (<span style="cursor: pointer;" onclick="var s=document.getElementById(\'ci_profiler_session_data\').style;s.display=s.display==\'none\'?\'\':\'none\';this.innerHTML=this.innerHTML==\''.$this->CI->lang->line('profiler_section_show').'\'?\''.$this->CI->lang->line('profiler_section_hide').'\':\''.$this->CI->lang->line('profiler_section_show').'\';">'.$this->CI->lang->line('profiler_section_show').'</span>)</legend>';
|
||||
$output .= "<table style='width:100%;display:none' id='ci_profiler_session_data'>";
|
||||
|
||||
foreach ($this->CI->session->all_userdata() as $key => $val)
|
||||
{
|
||||
if (is_array($val) OR is_object($val))
|
||||
{
|
||||
$val = print_r($val, TRUE);
|
||||
}
|
||||
|
||||
$output .= "<tr><td style='padding:5px; vertical-align: top;color:#900;background-color:#ddd;'>".$key." </td><td style='padding:5px; color:#000;background-color:#ddd;'>".htmlspecialchars($val)."</td></tr>\n";
|
||||
}
|
||||
|
||||
$output .= '</table>';
|
||||
$output .= "</fieldset>";
|
||||
return $output;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Run the Profiler
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$output = "<div id='codeigniter_profiler' style='clear:both;background-color:#fff;padding:10px;'>";
|
||||
$fields_displayed = 0;
|
||||
|
||||
foreach ($this->_available_sections as $section)
|
||||
{
|
||||
if ($this->_compile_{$section} !== FALSE)
|
||||
{
|
||||
$func = "_compile_{$section}";
|
||||
$output .= $this->{$func}();
|
||||
$fields_displayed++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($fields_displayed == 0)
|
||||
{
|
||||
$output .= '<p style="border:1px solid #5a0099;padding:10px;margin:20px 0;background-color:#eee">'.$this->CI->lang->line('profiler_no_profiles').'</p>';
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
// END CI_Profiler class
|
||||
|
||||
/* End of file Profiler.php */
|
||||
/* Location: ./system/libraries/Profiler.php */
|
780
system/libraries/Session.php
Normal file
780
system/libraries/Session.php
Normal file
@ -0,0 +1,780 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Session Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Sessions
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link http://codeigniter.com/user_guide/libraries/sessions.html
|
||||
*/
|
||||
class CI_Session {
|
||||
|
||||
var $sess_encrypt_cookie = FALSE;
|
||||
var $sess_use_database = FALSE;
|
||||
var $sess_table_name = '';
|
||||
var $sess_expiration = 7200;
|
||||
var $sess_expire_on_close = FALSE;
|
||||
var $sess_match_ip = FALSE;
|
||||
var $sess_match_useragent = TRUE;
|
||||
var $sess_cookie_name = 'ci_session';
|
||||
var $cookie_prefix = '';
|
||||
var $cookie_path = '';
|
||||
var $cookie_domain = '';
|
||||
var $cookie_secure = FALSE;
|
||||
var $sess_time_to_update = 300;
|
||||
var $encryption_key = '';
|
||||
var $flashdata_key = 'flash';
|
||||
var $time_reference = 'time';
|
||||
var $gc_probability = 5;
|
||||
var $userdata = array();
|
||||
var $CI;
|
||||
var $now;
|
||||
|
||||
/**
|
||||
* Session Constructor
|
||||
*
|
||||
* The constructor runs the session routines automatically
|
||||
* whenever the class is instantiated.
|
||||
*/
|
||||
public function __construct($params = array())
|
||||
{
|
||||
log_message('debug', "Session Class Initialized");
|
||||
|
||||
// Set the super object to a local variable for use throughout the class
|
||||
$this->CI =& get_instance();
|
||||
|
||||
// Set all the session preferences, which can either be set
|
||||
// manually via the $params array above or via the config file
|
||||
foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'cookie_secure', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key)
|
||||
{
|
||||
$this->$key = (isset($params[$key])) ? $params[$key] : $this->CI->config->item($key);
|
||||
}
|
||||
|
||||
if ($this->encryption_key == '')
|
||||
{
|
||||
show_error('In order to use the Session class you are required to set an encryption key in your config file.');
|
||||
}
|
||||
|
||||
// Load the string helper so we can use the strip_slashes() function
|
||||
$this->CI->load->helper('string');
|
||||
|
||||
// Do we need encryption? If so, load the encryption class
|
||||
if ($this->sess_encrypt_cookie == TRUE)
|
||||
{
|
||||
$this->CI->load->library('encrypt');
|
||||
}
|
||||
|
||||
// Are we using a database? If so, load it
|
||||
if ($this->sess_use_database === TRUE AND $this->sess_table_name != '')
|
||||
{
|
||||
$this->CI->load->database();
|
||||
}
|
||||
|
||||
// Set the "now" time. Can either be GMT or server time, based on the
|
||||
// config prefs. We use this to set the "last activity" time
|
||||
$this->now = $this->_get_time();
|
||||
|
||||
// Set the session length. If the session expiration is
|
||||
// set to zero we'll set the expiration two years from now.
|
||||
if ($this->sess_expiration == 0)
|
||||
{
|
||||
$this->sess_expiration = (60*60*24*365*2);
|
||||
}
|
||||
|
||||
// Set the cookie name
|
||||
$this->sess_cookie_name = $this->cookie_prefix.$this->sess_cookie_name;
|
||||
|
||||
// Run the Session routine. If a session doesn't exist we'll
|
||||
// create a new one. If it does, we'll update it.
|
||||
if ( ! $this->sess_read())
|
||||
{
|
||||
$this->sess_create();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->sess_update();
|
||||
}
|
||||
|
||||
// Delete 'old' flashdata (from last request)
|
||||
$this->_flashdata_sweep();
|
||||
|
||||
// Mark all new flashdata as old (data will be deleted before next request)
|
||||
$this->_flashdata_mark();
|
||||
|
||||
// Delete expired sessions if necessary
|
||||
$this->_sess_gc();
|
||||
|
||||
log_message('debug', "Session routines successfully run");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch the current session data if it exists
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function sess_read()
|
||||
{
|
||||
// Fetch the cookie
|
||||
$session = $this->CI->input->cookie($this->sess_cookie_name);
|
||||
|
||||
// No cookie? Goodbye cruel world!...
|
||||
if ($session === FALSE)
|
||||
{
|
||||
log_message('debug', 'A session cookie was not found.');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Decrypt the cookie data
|
||||
if ($this->sess_encrypt_cookie == TRUE)
|
||||
{
|
||||
$session = $this->CI->encrypt->decode($session);
|
||||
}
|
||||
else
|
||||
{
|
||||
// encryption was not used, so we need to check the md5 hash
|
||||
$hash = substr($session, strlen($session)-32); // get last 32 chars
|
||||
$session = substr($session, 0, strlen($session)-32);
|
||||
|
||||
// Does the md5 hash match? This is to prevent manipulation of session data in userspace
|
||||
if ($hash !== md5($session.$this->encryption_key))
|
||||
{
|
||||
log_message('error', 'The session cookie data did not match what was expected. This could be a possible hacking attempt.');
|
||||
$this->sess_destroy();
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// Unserialize the session array
|
||||
$session = $this->_unserialize($session);
|
||||
|
||||
// Is the session data we unserialized an array with the correct format?
|
||||
if ( ! is_array($session) OR ! isset($session['session_id']) OR ! isset($session['ip_address']) OR ! isset($session['user_agent']) OR ! isset($session['last_activity']))
|
||||
{
|
||||
$this->sess_destroy();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Is the session current?
|
||||
if (($session['last_activity'] + $this->sess_expiration) < $this->now)
|
||||
{
|
||||
$this->sess_destroy();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Does the IP Match?
|
||||
if ($this->sess_match_ip == TRUE AND $session['ip_address'] != $this->CI->input->ip_address())
|
||||
{
|
||||
$this->sess_destroy();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Does the User Agent Match?
|
||||
if ($this->sess_match_useragent == TRUE AND trim($session['user_agent']) != trim(substr($this->CI->input->user_agent(), 0, 120)))
|
||||
{
|
||||
$this->sess_destroy();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Is there a corresponding session in the DB?
|
||||
if ($this->sess_use_database === TRUE)
|
||||
{
|
||||
$this->CI->db->where('session_id', $session['session_id']);
|
||||
|
||||
if ($this->sess_match_ip == TRUE)
|
||||
{
|
||||
$this->CI->db->where('ip_address', $session['ip_address']);
|
||||
}
|
||||
|
||||
if ($this->sess_match_useragent == TRUE)
|
||||
{
|
||||
$this->CI->db->where('user_agent', $session['user_agent']);
|
||||
}
|
||||
|
||||
$query = $this->CI->db->get($this->sess_table_name);
|
||||
|
||||
// No result? Kill it!
|
||||
if ($query->num_rows() == 0)
|
||||
{
|
||||
$this->sess_destroy();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Is there custom data? If so, add it to the main session array
|
||||
$row = $query->row();
|
||||
if (isset($row->user_data) AND $row->user_data != '')
|
||||
{
|
||||
$custom_data = $this->_unserialize($row->user_data);
|
||||
|
||||
if (is_array($custom_data))
|
||||
{
|
||||
foreach ($custom_data as $key => $val)
|
||||
{
|
||||
$session[$key] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Session is valid!
|
||||
$this->userdata = $session;
|
||||
unset($session);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Write the session data
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function sess_write()
|
||||
{
|
||||
// Are we saving custom data to the DB? If not, all we do is update the cookie
|
||||
if ($this->sess_use_database === FALSE)
|
||||
{
|
||||
$this->_set_cookie();
|
||||
return;
|
||||
}
|
||||
|
||||
// set the custom userdata, the session data we will set in a second
|
||||
$custom_userdata = $this->userdata;
|
||||
$cookie_userdata = array();
|
||||
|
||||
// Before continuing, we need to determine if there is any custom data to deal with.
|
||||
// Let's determine this by removing the default indexes to see if there's anything left in the array
|
||||
// and set the session data while we're at it
|
||||
foreach (array('session_id','ip_address','user_agent','last_activity') as $val)
|
||||
{
|
||||
unset($custom_userdata[$val]);
|
||||
$cookie_userdata[$val] = $this->userdata[$val];
|
||||
}
|
||||
|
||||
// Did we find any custom data? If not, we turn the empty array into a string
|
||||
// since there's no reason to serialize and store an empty array in the DB
|
||||
if (count($custom_userdata) === 0)
|
||||
{
|
||||
$custom_userdata = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
// Serialize the custom data array so we can store it
|
||||
$custom_userdata = $this->_serialize($custom_userdata);
|
||||
}
|
||||
|
||||
// Run the update query
|
||||
$this->CI->db->where('session_id', $this->userdata['session_id']);
|
||||
$this->CI->db->update($this->sess_table_name, array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata));
|
||||
|
||||
// Write the cookie. Notice that we manually pass the cookie data array to the
|
||||
// _set_cookie() function. Normally that function will store $this->userdata, but
|
||||
// in this case that array contains custom data, which we do not want in the cookie.
|
||||
$this->_set_cookie($cookie_userdata);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create a new session
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function sess_create()
|
||||
{
|
||||
$sessid = '';
|
||||
while (strlen($sessid) < 32)
|
||||
{
|
||||
$sessid .= mt_rand(0, mt_getrandmax());
|
||||
}
|
||||
|
||||
// To make the session ID even more secure we'll combine it with the user's IP
|
||||
$sessid .= $this->CI->input->ip_address();
|
||||
|
||||
$this->userdata = array(
|
||||
'session_id' => md5(uniqid($sessid, TRUE)),
|
||||
'ip_address' => $this->CI->input->ip_address(),
|
||||
'user_agent' => substr($this->CI->input->user_agent(), 0, 120),
|
||||
'last_activity' => $this->now,
|
||||
'user_data' => ''
|
||||
);
|
||||
|
||||
|
||||
// Save the data to the DB if needed
|
||||
if ($this->sess_use_database === TRUE)
|
||||
{
|
||||
$this->CI->db->query($this->CI->db->insert_string($this->sess_table_name, $this->userdata));
|
||||
}
|
||||
|
||||
// Write the cookie
|
||||
$this->_set_cookie();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update an existing session
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function sess_update()
|
||||
{
|
||||
// We only update the session every five minutes by default
|
||||
if (($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Save the old session id so we know which record to
|
||||
// update in the database if we need it
|
||||
$old_sessid = $this->userdata['session_id'];
|
||||
$new_sessid = '';
|
||||
while (strlen($new_sessid) < 32)
|
||||
{
|
||||
$new_sessid .= mt_rand(0, mt_getrandmax());
|
||||
}
|
||||
|
||||
// To make the session ID even more secure we'll combine it with the user's IP
|
||||
$new_sessid .= $this->CI->input->ip_address();
|
||||
|
||||
// Turn it into a hash
|
||||
$new_sessid = md5(uniqid($new_sessid, TRUE));
|
||||
|
||||
// Update the session data in the session data array
|
||||
$this->userdata['session_id'] = $new_sessid;
|
||||
$this->userdata['last_activity'] = $this->now;
|
||||
|
||||
// _set_cookie() will handle this for us if we aren't using database sessions
|
||||
// by pushing all userdata to the cookie.
|
||||
$cookie_data = NULL;
|
||||
|
||||
// Update the session ID and last_activity field in the DB if needed
|
||||
if ($this->sess_use_database === TRUE)
|
||||
{
|
||||
// set cookie explicitly to only have our session data
|
||||
$cookie_data = array();
|
||||
foreach (array('session_id','ip_address','user_agent','last_activity') as $val)
|
||||
{
|
||||
$cookie_data[$val] = $this->userdata[$val];
|
||||
}
|
||||
|
||||
$this->CI->db->query($this->CI->db->update_string($this->sess_table_name, array('last_activity' => $this->now, 'session_id' => $new_sessid), array('session_id' => $old_sessid)));
|
||||
}
|
||||
|
||||
// Write the cookie
|
||||
$this->_set_cookie($cookie_data);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Destroy the current session
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function sess_destroy()
|
||||
{
|
||||
// Kill the session DB row
|
||||
if ($this->sess_use_database === TRUE && isset($this->userdata['session_id']))
|
||||
{
|
||||
$this->CI->db->where('session_id', $this->userdata['session_id']);
|
||||
$this->CI->db->delete($this->sess_table_name);
|
||||
}
|
||||
|
||||
// Kill the cookie
|
||||
setcookie(
|
||||
$this->sess_cookie_name,
|
||||
addslashes(serialize(array())),
|
||||
($this->now - 31500000),
|
||||
$this->cookie_path,
|
||||
$this->cookie_domain,
|
||||
0
|
||||
);
|
||||
|
||||
// Kill session data
|
||||
$this->userdata = array();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch a specific item from the session array
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function userdata($item)
|
||||
{
|
||||
return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch all session data
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
function all_userdata()
|
||||
{
|
||||
return $this->userdata;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Add or change data in the "userdata" array
|
||||
*
|
||||
* @access public
|
||||
* @param mixed
|
||||
* @param string
|
||||
* @return void
|
||||
*/
|
||||
function set_userdata($newdata = array(), $newval = '')
|
||||
{
|
||||
if (is_string($newdata))
|
||||
{
|
||||
$newdata = array($newdata => $newval);
|
||||
}
|
||||
|
||||
if (count($newdata) > 0)
|
||||
{
|
||||
foreach ($newdata as $key => $val)
|
||||
{
|
||||
$this->userdata[$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
$this->sess_write();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete a session variable from the "userdata" array
|
||||
*
|
||||
* @access array
|
||||
* @return void
|
||||
*/
|
||||
function unset_userdata($newdata = array())
|
||||
{
|
||||
if (is_string($newdata))
|
||||
{
|
||||
$newdata = array($newdata => '');
|
||||
}
|
||||
|
||||
if (count($newdata) > 0)
|
||||
{
|
||||
foreach ($newdata as $key => $val)
|
||||
{
|
||||
unset($this->userdata[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->sess_write();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Add or change flashdata, only available
|
||||
* until the next request
|
||||
*
|
||||
* @access public
|
||||
* @param mixed
|
||||
* @param string
|
||||
* @return void
|
||||
*/
|
||||
function set_flashdata($newdata = array(), $newval = '')
|
||||
{
|
||||
if (is_string($newdata))
|
||||
{
|
||||
$newdata = array($newdata => $newval);
|
||||
}
|
||||
|
||||
if (count($newdata) > 0)
|
||||
{
|
||||
foreach ($newdata as $key => $val)
|
||||
{
|
||||
$flashdata_key = $this->flashdata_key.':new:'.$key;
|
||||
$this->set_userdata($flashdata_key, $val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Keeps existing flashdata available to next request.
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return void
|
||||
*/
|
||||
function keep_flashdata($key)
|
||||
{
|
||||
// 'old' flashdata gets removed. Here we mark all
|
||||
// flashdata as 'new' to preserve it from _flashdata_sweep()
|
||||
// Note the function will return FALSE if the $key
|
||||
// provided cannot be found
|
||||
$old_flashdata_key = $this->flashdata_key.':old:'.$key;
|
||||
$value = $this->userdata($old_flashdata_key);
|
||||
|
||||
$new_flashdata_key = $this->flashdata_key.':new:'.$key;
|
||||
$this->set_userdata($new_flashdata_key, $value);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch a specific flashdata item from the session array
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function flashdata($key)
|
||||
{
|
||||
$flashdata_key = $this->flashdata_key.':old:'.$key;
|
||||
return $this->userdata($flashdata_key);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Identifies flashdata as 'old' for removal
|
||||
* when _flashdata_sweep() runs.
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _flashdata_mark()
|
||||
{
|
||||
$userdata = $this->all_userdata();
|
||||
foreach ($userdata as $name => $value)
|
||||
{
|
||||
$parts = explode(':new:', $name);
|
||||
if (is_array($parts) && count($parts) === 2)
|
||||
{
|
||||
$new_name = $this->flashdata_key.':old:'.$parts[1];
|
||||
$this->set_userdata($new_name, $value);
|
||||
$this->unset_userdata($name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Removes all flashdata marked as 'old'
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
|
||||
function _flashdata_sweep()
|
||||
{
|
||||
$userdata = $this->all_userdata();
|
||||
foreach ($userdata as $key => $value)
|
||||
{
|
||||
if (strpos($key, ':old:'))
|
||||
{
|
||||
$this->unset_userdata($key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the "now" time
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _get_time()
|
||||
{
|
||||
if (strtolower($this->time_reference) == 'gmt')
|
||||
{
|
||||
$now = time();
|
||||
$time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now));
|
||||
}
|
||||
else
|
||||
{
|
||||
$time = time();
|
||||
}
|
||||
|
||||
return $time;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Write the session cookie
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function _set_cookie($cookie_data = NULL)
|
||||
{
|
||||
if (is_null($cookie_data))
|
||||
{
|
||||
$cookie_data = $this->userdata;
|
||||
}
|
||||
|
||||
// Serialize the userdata for the cookie
|
||||
$cookie_data = $this->_serialize($cookie_data);
|
||||
|
||||
if ($this->sess_encrypt_cookie == TRUE)
|
||||
{
|
||||
$cookie_data = $this->CI->encrypt->encode($cookie_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
// if encryption is not used, we provide an md5 hash to prevent userside tampering
|
||||
$cookie_data = $cookie_data.md5($cookie_data.$this->encryption_key);
|
||||
}
|
||||
|
||||
$expire = ($this->sess_expire_on_close === TRUE) ? 0 : $this->sess_expiration + time();
|
||||
|
||||
// Set the cookie
|
||||
setcookie(
|
||||
$this->sess_cookie_name,
|
||||
$cookie_data,
|
||||
$expire,
|
||||
$this->cookie_path,
|
||||
$this->cookie_domain,
|
||||
$this->cookie_secure
|
||||
);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Serialize an array
|
||||
*
|
||||
* This function first converts any slashes found in the array to a temporary
|
||||
* marker, so when it gets unserialized the slashes will be preserved
|
||||
*
|
||||
* @access private
|
||||
* @param array
|
||||
* @return string
|
||||
*/
|
||||
function _serialize($data)
|
||||
{
|
||||
if (is_array($data))
|
||||
{
|
||||
foreach ($data as $key => $val)
|
||||
{
|
||||
if (is_string($val))
|
||||
{
|
||||
$data[$key] = str_replace('\\', '{{slash}}', $val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_string($data))
|
||||
{
|
||||
$data = str_replace('\\', '{{slash}}', $data);
|
||||
}
|
||||
}
|
||||
|
||||
return serialize($data);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Unserialize
|
||||
*
|
||||
* This function unserializes a data string, then converts any
|
||||
* temporary slash markers back to actual slashes
|
||||
*
|
||||
* @access private
|
||||
* @param array
|
||||
* @return string
|
||||
*/
|
||||
function _unserialize($data)
|
||||
{
|
||||
$data = @unserialize(strip_slashes($data));
|
||||
|
||||
if (is_array($data))
|
||||
{
|
||||
foreach ($data as $key => $val)
|
||||
{
|
||||
if (is_string($val))
|
||||
{
|
||||
$data[$key] = str_replace('{{slash}}', '\\', $val);
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
return (is_string($data)) ? str_replace('{{slash}}', '\\', $data) : $data;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Garbage collection
|
||||
*
|
||||
* This deletes expired session rows from database
|
||||
* if the probability percentage is met
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function _sess_gc()
|
||||
{
|
||||
if ($this->sess_use_database != TRUE)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
srand(time());
|
||||
if ((rand() % 100) < $this->gc_probability)
|
||||
{
|
||||
$expire = $this->now - $this->sess_expiration;
|
||||
|
||||
$this->CI->db->where("last_activity < {$expire}");
|
||||
$this->CI->db->delete($this->sess_table_name);
|
||||
|
||||
log_message('debug', 'Session garbage collection performed.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// END Session Class
|
||||
|
||||
/* End of file Session.php */
|
||||
/* Location: ./system/libraries/Session.php */
|
251
system/libraries/Sha1.php
Normal file
251
system/libraries/Sha1.php
Normal file
@ -0,0 +1,251 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* SHA1 Encoding Class
|
||||
*
|
||||
* Purpose: Provides 160 bit hashing using The Secure Hash Algorithm
|
||||
* developed at the National Institute of Standards and Technology. The 40
|
||||
* character SHA1 message hash is computationally infeasible to crack.
|
||||
*
|
||||
* This class is a fallback for servers that are not running PHP greater than
|
||||
* 4.3, or do not have the MHASH library.
|
||||
*
|
||||
* This class is based on two scripts:
|
||||
*
|
||||
* Marcus Campbell's PHP implementation (GNU license)
|
||||
* http://www.tecknik.net/sha-1/
|
||||
*
|
||||
* ...which is based on Paul Johnston's JavaScript version
|
||||
* (BSD license). http://pajhome.org.uk/
|
||||
*
|
||||
* I encapsulated the functions and wrote one additional method to fix
|
||||
* a hex conversion bug. - Rick Ellis
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Encryption
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link http://codeigniter.com/user_guide/general/encryption.html
|
||||
*/
|
||||
class CI_SHA1 {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
log_message('debug', "SHA1 Class Initialized");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the Hash
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function generate($str)
|
||||
{
|
||||
$n = ((strlen($str) + 8) >> 6) + 1;
|
||||
|
||||
for ($i = 0; $i < $n * 16; $i++)
|
||||
{
|
||||
$x[$i] = 0;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < strlen($str); $i++)
|
||||
{
|
||||
$x[$i >> 2] |= ord(substr($str, $i, 1)) << (24 - ($i % 4) * 8);
|
||||
}
|
||||
|
||||
$x[$i >> 2] |= 0x80 << (24 - ($i % 4) * 8);
|
||||
|
||||
$x[$n * 16 - 1] = strlen($str) * 8;
|
||||
|
||||
$a = 1732584193;
|
||||
$b = -271733879;
|
||||
$c = -1732584194;
|
||||
$d = 271733878;
|
||||
$e = -1009589776;
|
||||
|
||||
for ($i = 0; $i < count($x); $i += 16)
|
||||
{
|
||||
$olda = $a;
|
||||
$oldb = $b;
|
||||
$oldc = $c;
|
||||
$oldd = $d;
|
||||
$olde = $e;
|
||||
|
||||
for ($j = 0; $j < 80; $j++)
|
||||
{
|
||||
if ($j < 16)
|
||||
{
|
||||
$w[$j] = $x[$i + $j];
|
||||
}
|
||||
else
|
||||
{
|
||||
$w[$j] = $this->_rol($w[$j - 3] ^ $w[$j - 8] ^ $w[$j - 14] ^ $w[$j - 16], 1);
|
||||
}
|
||||
|
||||
$t = $this->_safe_add($this->_safe_add($this->_rol($a, 5), $this->_ft($j, $b, $c, $d)), $this->_safe_add($this->_safe_add($e, $w[$j]), $this->_kt($j)));
|
||||
|
||||
$e = $d;
|
||||
$d = $c;
|
||||
$c = $this->_rol($b, 30);
|
||||
$b = $a;
|
||||
$a = $t;
|
||||
}
|
||||
|
||||
$a = $this->_safe_add($a, $olda);
|
||||
$b = $this->_safe_add($b, $oldb);
|
||||
$c = $this->_safe_add($c, $oldc);
|
||||
$d = $this->_safe_add($d, $oldd);
|
||||
$e = $this->_safe_add($e, $olde);
|
||||
}
|
||||
|
||||
return $this->_hex($a).$this->_hex($b).$this->_hex($c).$this->_hex($d).$this->_hex($e);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Convert a decimal to hex
|
||||
*
|
||||
* @access private
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function _hex($str)
|
||||
{
|
||||
$str = dechex($str);
|
||||
|
||||
if (strlen($str) == 7)
|
||||
{
|
||||
$str = '0'.$str;
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return result based on iteration
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _ft($t, $b, $c, $d)
|
||||
{
|
||||
if ($t < 20)
|
||||
return ($b & $c) | ((~$b) & $d);
|
||||
if ($t < 40)
|
||||
return $b ^ $c ^ $d;
|
||||
if ($t < 60)
|
||||
return ($b & $c) | ($b & $d) | ($c & $d);
|
||||
|
||||
return $b ^ $c ^ $d;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Determine the additive constant
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _kt($t)
|
||||
{
|
||||
if ($t < 20)
|
||||
{
|
||||
return 1518500249;
|
||||
}
|
||||
else if ($t < 40)
|
||||
{
|
||||
return 1859775393;
|
||||
}
|
||||
else if ($t < 60)
|
||||
{
|
||||
return -1894007588;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -899497514;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Add integers, wrapping at 2^32
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _safe_add($x, $y)
|
||||
{
|
||||
$lsw = ($x & 0xFFFF) + ($y & 0xFFFF);
|
||||
$msw = ($x >> 16) + ($y >> 16) + ($lsw >> 16);
|
||||
|
||||
return ($msw << 16) | ($lsw & 0xFFFF);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Bitwise rotate a 32-bit number
|
||||
*
|
||||
* @access private
|
||||
* @return integer
|
||||
*/
|
||||
function _rol($num, $cnt)
|
||||
{
|
||||
return ($num << $cnt) | $this->_zero_fill($num, 32 - $cnt);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Pad string with zero
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _zero_fill($a, $b)
|
||||
{
|
||||
$bin = decbin($a);
|
||||
|
||||
if (strlen($bin) < $b)
|
||||
{
|
||||
$bin = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$bin = substr($bin, 0, strlen($bin) - $b);
|
||||
}
|
||||
|
||||
for ($i=0; $i < $b; $i++)
|
||||
{
|
||||
$bin = "0".$bin;
|
||||
}
|
||||
|
||||
return bindec($bin);
|
||||
}
|
||||
}
|
||||
// END CI_SHA
|
||||
|
||||
/* End of file Sha1.php */
|
||||
/* Location: ./system/libraries/Sha1.php */
|
531
system/libraries/Table.php
Normal file
531
system/libraries/Table.php
Normal file
@ -0,0 +1,531 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.3.1
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* HTML Table Generating Class
|
||||
*
|
||||
* Lets you create tables manually or from database result objects, or arrays.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category HTML Tables
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link http://codeigniter.com/user_guide/libraries/uri.html
|
||||
*/
|
||||
class CI_Table {
|
||||
|
||||
var $rows = array();
|
||||
var $heading = array();
|
||||
var $auto_heading = TRUE;
|
||||
var $caption = NULL;
|
||||
var $template = NULL;
|
||||
var $newline = "\n";
|
||||
var $empty_cells = "";
|
||||
var $function = FALSE;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
log_message('debug', "Table Class Initialized");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the template
|
||||
*
|
||||
* @access public
|
||||
* @param array
|
||||
* @return void
|
||||
*/
|
||||
function set_template($template)
|
||||
{
|
||||
if ( ! is_array($template))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$this->template = $template;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the table heading
|
||||
*
|
||||
* Can be passed as an array or discreet params
|
||||
*
|
||||
* @access public
|
||||
* @param mixed
|
||||
* @return void
|
||||
*/
|
||||
function set_heading()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$this->heading = $this->_prep_args($args);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set columns. Takes a one-dimensional array as input and creates
|
||||
* a multi-dimensional array with a depth equal to the number of
|
||||
* columns. This allows a single array with many elements to be
|
||||
* displayed in a table that has a fixed column count.
|
||||
*
|
||||
* @access public
|
||||
* @param array
|
||||
* @param int
|
||||
* @return void
|
||||
*/
|
||||
function make_columns($array = array(), $col_limit = 0)
|
||||
{
|
||||
if ( ! is_array($array) OR count($array) == 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Turn off the auto-heading feature since it's doubtful we
|
||||
// will want headings from a one-dimensional array
|
||||
$this->auto_heading = FALSE;
|
||||
|
||||
if ($col_limit == 0)
|
||||
{
|
||||
return $array;
|
||||
}
|
||||
|
||||
$new = array();
|
||||
while (count($array) > 0)
|
||||
{
|
||||
$temp = array_splice($array, 0, $col_limit);
|
||||
|
||||
if (count($temp) < $col_limit)
|
||||
{
|
||||
for ($i = count($temp); $i < $col_limit; $i++)
|
||||
{
|
||||
$temp[] = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
$new[] = $temp;
|
||||
}
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set "empty" cells
|
||||
*
|
||||
* Can be passed as an array or discreet params
|
||||
*
|
||||
* @access public
|
||||
* @param mixed
|
||||
* @return void
|
||||
*/
|
||||
function set_empty($value)
|
||||
{
|
||||
$this->empty_cells = $value;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Add a table row
|
||||
*
|
||||
* Can be passed as an array or discreet params
|
||||
*
|
||||
* @access public
|
||||
* @param mixed
|
||||
* @return void
|
||||
*/
|
||||
function add_row()
|
||||
{
|
||||
$args = func_get_args();
|
||||
$this->rows[] = $this->_prep_args($args);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Prep Args
|
||||
*
|
||||
* Ensures a standard associative array format for all cell data
|
||||
*
|
||||
* @access public
|
||||
* @param type
|
||||
* @return type
|
||||
*/
|
||||
function _prep_args($args)
|
||||
{
|
||||
// If there is no $args[0], skip this and treat as an associative array
|
||||
// This can happen if there is only a single key, for example this is passed to table->generate
|
||||
// array(array('foo'=>'bar'))
|
||||
if (isset($args[0]) AND (count($args) == 1 && is_array($args[0])))
|
||||
{
|
||||
// args sent as indexed array
|
||||
if ( ! isset($args[0]['data']))
|
||||
{
|
||||
foreach ($args[0] as $key => $val)
|
||||
{
|
||||
if (is_array($val) && isset($val['data']))
|
||||
{
|
||||
$args[$key] = $val;
|
||||
}
|
||||
else
|
||||
{
|
||||
$args[$key] = array('data' => $val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($args as $key => $val)
|
||||
{
|
||||
if ( ! is_array($val))
|
||||
{
|
||||
$args[$key] = array('data' => $val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Add a table caption
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return void
|
||||
*/
|
||||
function set_caption($caption)
|
||||
{
|
||||
$this->caption = $caption;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Generate the table
|
||||
*
|
||||
* @access public
|
||||
* @param mixed
|
||||
* @return string
|
||||
*/
|
||||
function generate($table_data = NULL)
|
||||
{
|
||||
// The table data can optionally be passed to this function
|
||||
// either as a database result object or an array
|
||||
if ( ! is_null($table_data))
|
||||
{
|
||||
if (is_object($table_data))
|
||||
{
|
||||
$this->_set_from_object($table_data);
|
||||
}
|
||||
elseif (is_array($table_data))
|
||||
{
|
||||
$set_heading = (count($this->heading) == 0 AND $this->auto_heading == FALSE) ? FALSE : TRUE;
|
||||
$this->_set_from_array($table_data, $set_heading);
|
||||
}
|
||||
}
|
||||
|
||||
// Is there anything to display? No? Smite them!
|
||||
if (count($this->heading) == 0 AND count($this->rows) == 0)
|
||||
{
|
||||
return 'Undefined table data';
|
||||
}
|
||||
|
||||
// Compile and validate the template date
|
||||
$this->_compile_template();
|
||||
|
||||
// set a custom cell manipulation function to a locally scoped variable so its callable
|
||||
$function = $this->function;
|
||||
|
||||
// Build the table!
|
||||
|
||||
$out = $this->template['table_open'];
|
||||
$out .= $this->newline;
|
||||
|
||||
// Add any caption here
|
||||
if ($this->caption)
|
||||
{
|
||||
$out .= $this->newline;
|
||||
$out .= '<caption>' . $this->caption . '</caption>';
|
||||
$out .= $this->newline;
|
||||
}
|
||||
|
||||
// Is there a table heading to display?
|
||||
if (count($this->heading) > 0)
|
||||
{
|
||||
$out .= $this->template['thead_open'];
|
||||
$out .= $this->newline;
|
||||
$out .= $this->template['heading_row_start'];
|
||||
$out .= $this->newline;
|
||||
|
||||
foreach ($this->heading as $heading)
|
||||
{
|
||||
$temp = $this->template['heading_cell_start'];
|
||||
|
||||
foreach ($heading as $key => $val)
|
||||
{
|
||||
if ($key != 'data')
|
||||
{
|
||||
$temp = str_replace('<th', "<th $key='$val'", $temp);
|
||||
}
|
||||
}
|
||||
|
||||
$out .= $temp;
|
||||
$out .= isset($heading['data']) ? $heading['data'] : '';
|
||||
$out .= $this->template['heading_cell_end'];
|
||||
}
|
||||
|
||||
$out .= $this->template['heading_row_end'];
|
||||
$out .= $this->newline;
|
||||
$out .= $this->template['thead_close'];
|
||||
$out .= $this->newline;
|
||||
}
|
||||
|
||||
// Build the table rows
|
||||
if (count($this->rows) > 0)
|
||||
{
|
||||
$out .= $this->template['tbody_open'];
|
||||
$out .= $this->newline;
|
||||
|
||||
$i = 1;
|
||||
foreach ($this->rows as $row)
|
||||
{
|
||||
if ( ! is_array($row))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// We use modulus to alternate the row colors
|
||||
$name = (fmod($i++, 2)) ? '' : 'alt_';
|
||||
|
||||
$out .= $this->template['row_'.$name.'start'];
|
||||
$out .= $this->newline;
|
||||
|
||||
foreach ($row as $cell)
|
||||
{
|
||||
$temp = $this->template['cell_'.$name.'start'];
|
||||
|
||||
foreach ($cell as $key => $val)
|
||||
{
|
||||
if ($key != 'data')
|
||||
{
|
||||
$temp = str_replace('<td', "<td $key='$val'", $temp);
|
||||
}
|
||||
}
|
||||
|
||||
$cell = isset($cell['data']) ? $cell['data'] : '';
|
||||
$out .= $temp;
|
||||
|
||||
if ($cell === "" OR $cell === NULL)
|
||||
{
|
||||
$out .= $this->empty_cells;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($function !== FALSE && is_callable($function))
|
||||
{
|
||||
$out .= call_user_func($function, $cell);
|
||||
}
|
||||
else
|
||||
{
|
||||
$out .= $cell;
|
||||
}
|
||||
}
|
||||
|
||||
$out .= $this->template['cell_'.$name.'end'];
|
||||
}
|
||||
|
||||
$out .= $this->template['row_'.$name.'end'];
|
||||
$out .= $this->newline;
|
||||
}
|
||||
|
||||
$out .= $this->template['tbody_close'];
|
||||
$out .= $this->newline;
|
||||
}
|
||||
|
||||
$out .= $this->template['table_close'];
|
||||
|
||||
// Clear table class properties before generating the table
|
||||
$this->clear();
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Clears the table arrays. Useful if multiple tables are being generated
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function clear()
|
||||
{
|
||||
$this->rows = array();
|
||||
$this->heading = array();
|
||||
$this->auto_heading = TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set table data from a database result object
|
||||
*
|
||||
* @access public
|
||||
* @param object
|
||||
* @return void
|
||||
*/
|
||||
function _set_from_object($query)
|
||||
{
|
||||
if ( ! is_object($query))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// First generate the headings from the table column names
|
||||
if (count($this->heading) == 0)
|
||||
{
|
||||
if ( ! method_exists($query, 'list_fields'))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$this->heading = $this->_prep_args($query->list_fields());
|
||||
}
|
||||
|
||||
// Next blast through the result array and build out the rows
|
||||
|
||||
if ($query->num_rows() > 0)
|
||||
{
|
||||
foreach ($query->result_array() as $row)
|
||||
{
|
||||
$this->rows[] = $this->_prep_args($row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set table data from an array
|
||||
*
|
||||
* @access public
|
||||
* @param array
|
||||
* @return void
|
||||
*/
|
||||
function _set_from_array($data, $set_heading = TRUE)
|
||||
{
|
||||
if ( ! is_array($data) OR count($data) == 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
foreach ($data as $row)
|
||||
{
|
||||
// If a heading hasn't already been set we'll use the first row of the array as the heading
|
||||
if ($i == 0 AND count($data) > 1 AND count($this->heading) == 0 AND $set_heading == TRUE)
|
||||
{
|
||||
$this->heading = $this->_prep_args($row);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->rows[] = $this->_prep_args($row);
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Compile Template
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _compile_template()
|
||||
{
|
||||
if ($this->template == NULL)
|
||||
{
|
||||
$this->template = $this->_default_template();
|
||||
return;
|
||||
}
|
||||
|
||||
$this->temp = $this->_default_template();
|
||||
foreach (array('table_open', 'thead_open', 'thead_close', 'heading_row_start', 'heading_row_end', 'heading_cell_start', 'heading_cell_end', 'tbody_open', 'tbody_close', 'row_start', 'row_end', 'cell_start', 'cell_end', 'row_alt_start', 'row_alt_end', 'cell_alt_start', 'cell_alt_end', 'table_close') as $val)
|
||||
{
|
||||
if ( ! isset($this->template[$val]))
|
||||
{
|
||||
$this->template[$val] = $this->temp[$val];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Default Template
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _default_template()
|
||||
{
|
||||
return array (
|
||||
'table_open' => '<table border="0" cellpadding="4" cellspacing="0">',
|
||||
|
||||
'thead_open' => '<thead>',
|
||||
'thead_close' => '</thead>',
|
||||
|
||||
'heading_row_start' => '<tr>',
|
||||
'heading_row_end' => '</tr>',
|
||||
'heading_cell_start' => '<th>',
|
||||
'heading_cell_end' => '</th>',
|
||||
|
||||
'tbody_open' => '<tbody>',
|
||||
'tbody_close' => '</tbody>',
|
||||
|
||||
'row_start' => '<tr>',
|
||||
'row_end' => '</tr>',
|
||||
'cell_start' => '<td>',
|
||||
'cell_end' => '</td>',
|
||||
|
||||
'row_alt_start' => '<tr>',
|
||||
'row_alt_end' => '</tr>',
|
||||
'cell_alt_start' => '<td>',
|
||||
'cell_alt_end' => '</td>',
|
||||
|
||||
'table_close' => '</table>'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* End of file Table.php */
|
||||
/* Location: ./system/libraries/Table.php */
|
548
system/libraries/Trackback.php
Normal file
548
system/libraries/Trackback.php
Normal file
@ -0,0 +1,548 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Trackback Class
|
||||
*
|
||||
* Trackback Sending/Receiving Class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Trackbacks
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link http://codeigniter.com/user_guide/libraries/trackback.html
|
||||
*/
|
||||
class CI_Trackback {
|
||||
|
||||
var $time_format = 'local';
|
||||
var $charset = 'UTF-8';
|
||||
var $data = array('url' => '', 'title' => '', 'excerpt' => '', 'blog_name' => '', 'charset' => '');
|
||||
var $convert_ascii = TRUE;
|
||||
var $response = '';
|
||||
var $error_msg = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
log_message('debug', "Trackback Class Initialized");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Send Trackback
|
||||
*
|
||||
* @access public
|
||||
* @param array
|
||||
* @return bool
|
||||
*/
|
||||
function send($tb_data)
|
||||
{
|
||||
if ( ! is_array($tb_data))
|
||||
{
|
||||
$this->set_error('The send() method must be passed an array');
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Pre-process the Trackback Data
|
||||
foreach (array('url', 'title', 'excerpt', 'blog_name', 'ping_url') as $item)
|
||||
{
|
||||
if ( ! isset($tb_data[$item]))
|
||||
{
|
||||
$this->set_error('Required item missing: '.$item);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
switch ($item)
|
||||
{
|
||||
case 'ping_url' : $$item = $this->extract_urls($tb_data[$item]);
|
||||
break;
|
||||
case 'excerpt' : $$item = $this->limit_characters($this->convert_xml(strip_tags(stripslashes($tb_data[$item]))));
|
||||
break;
|
||||
case 'url' : $$item = str_replace('-', '-', $this->convert_xml(strip_tags(stripslashes($tb_data[$item]))));
|
||||
break;
|
||||
default : $$item = $this->convert_xml(strip_tags(stripslashes($tb_data[$item])));
|
||||
break;
|
||||
}
|
||||
|
||||
// Convert High ASCII Characters
|
||||
if ($this->convert_ascii == TRUE)
|
||||
{
|
||||
if ($item == 'excerpt')
|
||||
{
|
||||
$$item = $this->convert_ascii($$item);
|
||||
}
|
||||
elseif ($item == 'title')
|
||||
{
|
||||
$$item = $this->convert_ascii($$item);
|
||||
}
|
||||
elseif ($item == 'blog_name')
|
||||
{
|
||||
$$item = $this->convert_ascii($$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Build the Trackback data string
|
||||
$charset = ( ! isset($tb_data['charset'])) ? $this->charset : $tb_data['charset'];
|
||||
|
||||
$data = "url=".rawurlencode($url)."&title=".rawurlencode($title)."&blog_name=".rawurlencode($blog_name)."&excerpt=".rawurlencode($excerpt)."&charset=".rawurlencode($charset);
|
||||
|
||||
// Send Trackback(s)
|
||||
$return = TRUE;
|
||||
if (count($ping_url) > 0)
|
||||
{
|
||||
foreach ($ping_url as $url)
|
||||
{
|
||||
if ($this->process($url, $data) == FALSE)
|
||||
{
|
||||
$return = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Receive Trackback Data
|
||||
*
|
||||
* This function simply validates the incoming TB data.
|
||||
* It returns FALSE on failure and TRUE on success.
|
||||
* If the data is valid it is set to the $this->data array
|
||||
* so that it can be inserted into a database.
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function receive()
|
||||
{
|
||||
foreach (array('url', 'title', 'blog_name', 'excerpt') as $val)
|
||||
{
|
||||
if ( ! isset($_POST[$val]) OR $_POST[$val] == '')
|
||||
{
|
||||
$this->set_error('The following required POST variable is missing: '.$val);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$this->data['charset'] = ( ! isset($_POST['charset'])) ? 'auto' : strtoupper(trim($_POST['charset']));
|
||||
|
||||
if ($val != 'url' && function_exists('mb_convert_encoding'))
|
||||
{
|
||||
$_POST[$val] = mb_convert_encoding($_POST[$val], $this->charset, $this->data['charset']);
|
||||
}
|
||||
|
||||
$_POST[$val] = ($val != 'url') ? $this->convert_xml(strip_tags($_POST[$val])) : strip_tags($_POST[$val]);
|
||||
|
||||
if ($val == 'excerpt')
|
||||
{
|
||||
$_POST['excerpt'] = $this->limit_characters($_POST['excerpt']);
|
||||
}
|
||||
|
||||
$this->data[$val] = $_POST[$val];
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Send Trackback Error Message
|
||||
*
|
||||
* Allows custom errors to be set. By default it
|
||||
* sends the "incomplete information" error, as that's
|
||||
* the most common one.
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return void
|
||||
*/
|
||||
function send_error($message = 'Incomplete Information')
|
||||
{
|
||||
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?".">\n<response>\n<error>1</error>\n<message>".$message."</message>\n</response>";
|
||||
exit;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Send Trackback Success Message
|
||||
*
|
||||
* This should be called when a trackback has been
|
||||
* successfully received and inserted.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function send_success()
|
||||
{
|
||||
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?".">\n<response>\n<error>0</error>\n</response>";
|
||||
exit;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch a particular item
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function data($item)
|
||||
{
|
||||
return ( ! isset($this->data[$item])) ? '' : $this->data[$item];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process Trackback
|
||||
*
|
||||
* Opens a socket connection and passes the data to
|
||||
* the server. Returns TRUE on success, FALSE on failure
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @param string
|
||||
* @return bool
|
||||
*/
|
||||
function process($url, $data)
|
||||
{
|
||||
$target = parse_url($url);
|
||||
|
||||
// Open the socket
|
||||
if ( ! $fp = @fsockopen($target['host'], 80))
|
||||
{
|
||||
$this->set_error('Invalid Connection: '.$url);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Build the path
|
||||
$ppath = ( ! isset($target['path'])) ? $url : $target['path'];
|
||||
|
||||
$path = (isset($target['query']) && $target['query'] != "") ? $ppath.'?'.$target['query'] : $ppath;
|
||||
|
||||
// Add the Trackback ID to the data string
|
||||
if ($id = $this->get_id($url))
|
||||
{
|
||||
$data = "tb_id=".$id."&".$data;
|
||||
}
|
||||
|
||||
// Transfer the data
|
||||
fputs ($fp, "POST " . $path . " HTTP/1.0\r\n" );
|
||||
fputs ($fp, "Host: " . $target['host'] . "\r\n" );
|
||||
fputs ($fp, "Content-type: application/x-www-form-urlencoded\r\n" );
|
||||
fputs ($fp, "Content-length: " . strlen($data) . "\r\n" );
|
||||
fputs ($fp, "Connection: close\r\n\r\n" );
|
||||
fputs ($fp, $data);
|
||||
|
||||
// Was it successful?
|
||||
$this->response = "";
|
||||
|
||||
while ( ! feof($fp))
|
||||
{
|
||||
$this->response .= fgets($fp, 128);
|
||||
}
|
||||
@fclose($fp);
|
||||
|
||||
|
||||
if (stristr($this->response, '<error>0</error>') === FALSE)
|
||||
{
|
||||
$message = 'An unknown error was encountered';
|
||||
|
||||
if (preg_match("/<message>(.*?)<\/message>/is", $this->response, $match))
|
||||
{
|
||||
$message = trim($match['1']);
|
||||
}
|
||||
|
||||
$this->set_error($message);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Extract Trackback URLs
|
||||
*
|
||||
* This function lets multiple trackbacks be sent.
|
||||
* It takes a string of URLs (separated by comma or
|
||||
* space) and puts each URL into an array
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function extract_urls($urls)
|
||||
{
|
||||
// Remove the pesky white space and replace with a comma.
|
||||
$urls = preg_replace("/\s*(\S+)\s*/", "\\1,", $urls);
|
||||
|
||||
// If they use commas get rid of the doubles.
|
||||
$urls = str_replace(",,", ",", $urls);
|
||||
|
||||
// Remove any comma that might be at the end
|
||||
if (substr($urls, -1) == ",")
|
||||
{
|
||||
$urls = substr($urls, 0, -1);
|
||||
}
|
||||
|
||||
// Break into an array via commas
|
||||
$urls = preg_split('/[,]/', $urls);
|
||||
|
||||
// Removes duplicates
|
||||
$urls = array_unique($urls);
|
||||
|
||||
array_walk($urls, array($this, 'validate_url'));
|
||||
|
||||
return $urls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Validate URL
|
||||
*
|
||||
* Simply adds "http://" if missing
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function validate_url($url)
|
||||
{
|
||||
$url = trim($url);
|
||||
|
||||
if (substr($url, 0, 4) != "http")
|
||||
{
|
||||
$url = "http://".$url;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Find the Trackback URL's ID
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function get_id($url)
|
||||
{
|
||||
$tb_id = "";
|
||||
|
||||
if (strpos($url, '?') !== FALSE)
|
||||
{
|
||||
$tb_array = explode('/', $url);
|
||||
$tb_end = $tb_array[count($tb_array)-1];
|
||||
|
||||
if ( ! is_numeric($tb_end))
|
||||
{
|
||||
$tb_end = $tb_array[count($tb_array)-2];
|
||||
}
|
||||
|
||||
$tb_array = explode('=', $tb_end);
|
||||
$tb_id = $tb_array[count($tb_array)-1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$url = rtrim($url, '/');
|
||||
|
||||
$tb_array = explode('/', $url);
|
||||
$tb_id = $tb_array[count($tb_array)-1];
|
||||
|
||||
if ( ! is_numeric($tb_id))
|
||||
{
|
||||
$tb_id = $tb_array[count($tb_array)-2];
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! preg_match ("/^([0-9]+)$/", $tb_id))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $tb_id;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Convert Reserved XML characters to Entities
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function convert_xml($str)
|
||||
{
|
||||
$temp = '__TEMP_AMPERSANDS__';
|
||||
|
||||
$str = preg_replace("/&#(\d+);/", "$temp\\1;", $str);
|
||||
$str = preg_replace("/&(\w+);/", "$temp\\1;", $str);
|
||||
|
||||
$str = str_replace(array("&","<",">","\"", "'", "-"),
|
||||
array("&", "<", ">", """, "'", "-"),
|
||||
$str);
|
||||
|
||||
$str = preg_replace("/$temp(\d+);/","&#\\1;",$str);
|
||||
$str = preg_replace("/$temp(\w+);/","&\\1;", $str);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Character limiter
|
||||
*
|
||||
* Limits the string based on the character count. Will preserve complete words.
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @param integer
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function limit_characters($str, $n = 500, $end_char = '…')
|
||||
{
|
||||
if (strlen($str) < $n)
|
||||
{
|
||||
return $str;
|
||||
}
|
||||
|
||||
$str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str));
|
||||
|
||||
if (strlen($str) <= $n)
|
||||
{
|
||||
return $str;
|
||||
}
|
||||
|
||||
$out = "";
|
||||
foreach (explode(' ', trim($str)) as $val)
|
||||
{
|
||||
$out .= $val.' ';
|
||||
if (strlen($out) >= $n)
|
||||
{
|
||||
return trim($out).$end_char;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* High ASCII to Entities
|
||||
*
|
||||
* Converts Hight ascii text and MS Word special chars
|
||||
* to character entities
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function convert_ascii($str)
|
||||
{
|
||||
$count = 1;
|
||||
$out = '';
|
||||
$temp = array();
|
||||
|
||||
for ($i = 0, $s = strlen($str); $i < $s; $i++)
|
||||
{
|
||||
$ordinal = ord($str[$i]);
|
||||
|
||||
if ($ordinal < 128)
|
||||
{
|
||||
$out .= $str[$i];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (count($temp) == 0)
|
||||
{
|
||||
$count = ($ordinal < 224) ? 2 : 3;
|
||||
}
|
||||
|
||||
$temp[] = $ordinal;
|
||||
|
||||
if (count($temp) == $count)
|
||||
{
|
||||
$number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64);
|
||||
|
||||
$out .= '&#'.$number.';';
|
||||
$count = 1;
|
||||
$temp = array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set error message
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return void
|
||||
*/
|
||||
function set_error($msg)
|
||||
{
|
||||
log_message('error', $msg);
|
||||
$this->error_msg[] = $msg;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show error messages
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function display_errors($open = '<p>', $close = '</p>')
|
||||
{
|
||||
$str = '';
|
||||
foreach ($this->error_msg as $val)
|
||||
{
|
||||
$str .= $open.$val.$close;
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
}
|
||||
// END Trackback Class
|
||||
|
||||
/* End of file Trackback.php */
|
||||
/* Location: ./system/libraries/Trackback.php */
|
410
system/libraries/Typography.php
Normal file
410
system/libraries/Typography.php
Normal file
@ -0,0 +1,410 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Typography Class
|
||||
*
|
||||
*
|
||||
* @access private
|
||||
* @category Helpers
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link http://codeigniter.com/user_guide/helpers/
|
||||
*/
|
||||
class CI_Typography {
|
||||
|
||||
// Block level elements that should not be wrapped inside <p> tags
|
||||
var $block_elements = 'address|blockquote|div|dl|fieldset|form|h\d|hr|noscript|object|ol|p|pre|script|table|ul';
|
||||
|
||||
// Elements that should not have <p> and <br /> tags within them.
|
||||
var $skip_elements = 'p|pre|ol|ul|dl|object|table|h\d';
|
||||
|
||||
// Tags we want the parser to completely ignore when splitting the string.
|
||||
var $inline_elements = 'a|abbr|acronym|b|bdo|big|br|button|cite|code|del|dfn|em|i|img|ins|input|label|map|kbd|q|samp|select|small|span|strong|sub|sup|textarea|tt|var';
|
||||
|
||||
// array of block level elements that require inner content to be within another block level element
|
||||
var $inner_block_required = array('blockquote');
|
||||
|
||||
// the last block element parsed
|
||||
var $last_block_element = '';
|
||||
|
||||
// whether or not to protect quotes within { curly braces }
|
||||
var $protect_braced_quotes = FALSE;
|
||||
|
||||
/**
|
||||
* Auto Typography
|
||||
*
|
||||
* This function converts text, making it typographically correct:
|
||||
* - Converts double spaces into paragraphs.
|
||||
* - Converts single line breaks into <br /> tags
|
||||
* - Converts single and double quotes into correctly facing curly quote entities.
|
||||
* - Converts three dots into ellipsis.
|
||||
* - Converts double dashes into em-dashes.
|
||||
* - Converts two spaces into entities
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @param bool whether to reduce more then two consecutive newlines to two
|
||||
* @return string
|
||||
*/
|
||||
function auto_typography($str, $reduce_linebreaks = FALSE)
|
||||
{
|
||||
if ($str == '')
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
// Standardize Newlines to make matching easier
|
||||
if (strpos($str, "\r") !== FALSE)
|
||||
{
|
||||
$str = str_replace(array("\r\n", "\r"), "\n", $str);
|
||||
}
|
||||
|
||||
// Reduce line breaks. If there are more than two consecutive linebreaks
|
||||
// we'll compress them down to a maximum of two since there's no benefit to more.
|
||||
if ($reduce_linebreaks === TRUE)
|
||||
{
|
||||
$str = preg_replace("/\n\n+/", "\n\n", $str);
|
||||
}
|
||||
|
||||
// HTML comment tags don't conform to patterns of normal tags, so pull them out separately, only if needed
|
||||
$html_comments = array();
|
||||
if (strpos($str, '<!--') !== FALSE)
|
||||
{
|
||||
if (preg_match_all("#(<!\-\-.*?\-\->)#s", $str, $matches))
|
||||
{
|
||||
for ($i = 0, $total = count($matches[0]); $i < $total; $i++)
|
||||
{
|
||||
$html_comments[] = $matches[0][$i];
|
||||
$str = str_replace($matches[0][$i], '{@HC'.$i.'}', $str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// match and yank <pre> tags if they exist. It's cheaper to do this separately since most content will
|
||||
// not contain <pre> tags, and it keeps the PCRE patterns below simpler and faster
|
||||
if (strpos($str, '<pre') !== FALSE)
|
||||
{
|
||||
$str = preg_replace_callback("#<pre.*?>.*?</pre>#si", array($this, '_protect_characters'), $str);
|
||||
}
|
||||
|
||||
// Convert quotes within tags to temporary markers.
|
||||
$str = preg_replace_callback("#<.+?>#si", array($this, '_protect_characters'), $str);
|
||||
|
||||
// Do the same with braces if necessary
|
||||
if ($this->protect_braced_quotes === TRUE)
|
||||
{
|
||||
$str = preg_replace_callback("#\{.+?\}#si", array($this, '_protect_characters'), $str);
|
||||
}
|
||||
|
||||
// Convert "ignore" tags to temporary marker. The parser splits out the string at every tag
|
||||
// it encounters. Certain inline tags, like image tags, links, span tags, etc. will be
|
||||
// adversely affected if they are split out so we'll convert the opening bracket < temporarily to: {@TAG}
|
||||
$str = preg_replace("#<(/*)(".$this->inline_elements.")([ >])#i", "{@TAG}\\1\\2\\3", $str);
|
||||
|
||||
// Split the string at every tag. This expression creates an array with this prototype:
|
||||
//
|
||||
// [array]
|
||||
// {
|
||||
// [0] = <opening tag>
|
||||
// [1] = Content...
|
||||
// [2] = <closing tag>
|
||||
// Etc...
|
||||
// }
|
||||
$chunks = preg_split('/(<(?:[^<>]+(?:"[^"]*"|\'[^\']*\')?)+>)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
// Build our finalized string. We cycle through the array, skipping tags, and processing the contained text
|
||||
$str = '';
|
||||
$process = TRUE;
|
||||
$paragraph = FALSE;
|
||||
$current_chunk = 0;
|
||||
$total_chunks = count($chunks);
|
||||
|
||||
foreach ($chunks as $chunk)
|
||||
{
|
||||
$current_chunk++;
|
||||
|
||||
// Are we dealing with a tag? If so, we'll skip the processing for this cycle.
|
||||
// Well also set the "process" flag which allows us to skip <pre> tags and a few other things.
|
||||
if (preg_match("#<(/*)(".$this->block_elements.").*?>#", $chunk, $match))
|
||||
{
|
||||
if (preg_match("#".$this->skip_elements."#", $match[2]))
|
||||
{
|
||||
$process = ($match[1] == '/') ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
if ($match[1] == '')
|
||||
{
|
||||
$this->last_block_element = $match[2];
|
||||
}
|
||||
|
||||
$str .= $chunk;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($process == FALSE)
|
||||
{
|
||||
$str .= $chunk;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Force a newline to make sure end tags get processed by _format_newlines()
|
||||
if ($current_chunk == $total_chunks)
|
||||
{
|
||||
$chunk .= "\n";
|
||||
}
|
||||
|
||||
// Convert Newlines into <p> and <br /> tags
|
||||
$str .= $this->_format_newlines($chunk);
|
||||
}
|
||||
|
||||
// No opening block level tag? Add it if needed.
|
||||
if ( ! preg_match("/^\s*<(?:".$this->block_elements.")/i", $str))
|
||||
{
|
||||
$str = preg_replace("/^(.*?)<(".$this->block_elements.")/i", '<p>$1</p><$2', $str);
|
||||
}
|
||||
|
||||
// Convert quotes, elipsis, em-dashes, non-breaking spaces, and ampersands
|
||||
$str = $this->format_characters($str);
|
||||
|
||||
// restore HTML comments
|
||||
for ($i = 0, $total = count($html_comments); $i < $total; $i++)
|
||||
{
|
||||
// remove surrounding paragraph tags, but only if there's an opening paragraph tag
|
||||
// otherwise HTML comments at the ends of paragraphs will have the closing tag removed
|
||||
// if '<p>{@HC1}' then replace <p>{@HC1}</p> with the comment, else replace only {@HC1} with the comment
|
||||
$str = preg_replace('#(?(?=<p>\{@HC'.$i.'\})<p>\{@HC'.$i.'\}(\s*</p>)|\{@HC'.$i.'\})#s', $html_comments[$i], $str);
|
||||
}
|
||||
|
||||
// Final clean up
|
||||
$table = array(
|
||||
|
||||
// If the user submitted their own paragraph tags within the text
|
||||
// we will retain them instead of using our tags.
|
||||
'/(<p[^>*?]>)<p>/' => '$1', // <?php BBEdit syntax coloring bug fix
|
||||
|
||||
// Reduce multiple instances of opening/closing paragraph tags to a single one
|
||||
'#(</p>)+#' => '</p>',
|
||||
'/(<p>\W*<p>)+/' => '<p>',
|
||||
|
||||
// Clean up stray paragraph tags that appear before block level elements
|
||||
'#<p></p><('.$this->block_elements.')#' => '<$1',
|
||||
|
||||
// Clean up stray non-breaking spaces preceeding block elements
|
||||
'#( \s*)+<('.$this->block_elements.')#' => ' <$2',
|
||||
|
||||
// Replace the temporary markers we added earlier
|
||||
'/\{@TAG\}/' => '<',
|
||||
'/\{@DQ\}/' => '"',
|
||||
'/\{@SQ\}/' => "'",
|
||||
'/\{@DD\}/' => '--',
|
||||
'/\{@NBS\}/' => ' ',
|
||||
|
||||
// An unintended consequence of the _format_newlines function is that
|
||||
// some of the newlines get truncated, resulting in <p> tags
|
||||
// starting immediately after <block> tags on the same line.
|
||||
// This forces a newline after such occurrences, which looks much nicer.
|
||||
"/><p>\n/" => ">\n<p>",
|
||||
|
||||
// Similarly, there might be cases where a closing </block> will follow
|
||||
// a closing </p> tag, so we'll correct it by adding a newline in between
|
||||
"#</p></#" => "</p>\n</"
|
||||
);
|
||||
|
||||
// Do we need to reduce empty lines?
|
||||
if ($reduce_linebreaks === TRUE)
|
||||
{
|
||||
$table['#<p>\n*</p>#'] = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
// If we have empty paragraph tags we add a non-breaking space
|
||||
// otherwise most browsers won't treat them as true paragraphs
|
||||
$table['#<p></p>#'] = '<p> </p>';
|
||||
}
|
||||
|
||||
return preg_replace(array_keys($table), $table, $str);
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Format Characters
|
||||
*
|
||||
* This function mainly converts double and single quotes
|
||||
* to curly entities, but it also converts em-dashes,
|
||||
* double spaces, and ampersands
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function format_characters($str)
|
||||
{
|
||||
static $table;
|
||||
|
||||
if ( ! isset($table))
|
||||
{
|
||||
$table = array(
|
||||
// nested smart quotes, opening and closing
|
||||
// note that rules for grammar (English) allow only for two levels deep
|
||||
// and that single quotes are _supposed_ to always be on the outside
|
||||
// but we'll accommodate both
|
||||
// Note that in all cases, whitespace is the primary determining factor
|
||||
// on which direction to curl, with non-word characters like punctuation
|
||||
// being a secondary factor only after whitespace is addressed.
|
||||
'/\'"(\s|$)/' => '’”$1',
|
||||
'/(^|\s|<p>)\'"/' => '$1‘“',
|
||||
'/\'"(\W)/' => '’”$1',
|
||||
'/(\W)\'"/' => '$1‘“',
|
||||
'/"\'(\s|$)/' => '”’$1',
|
||||
'/(^|\s|<p>)"\'/' => '$1“‘',
|
||||
'/"\'(\W)/' => '”’$1',
|
||||
'/(\W)"\'/' => '$1“‘',
|
||||
|
||||
// single quote smart quotes
|
||||
'/\'(\s|$)/' => '’$1',
|
||||
'/(^|\s|<p>)\'/' => '$1‘',
|
||||
'/\'(\W)/' => '’$1',
|
||||
'/(\W)\'/' => '$1‘',
|
||||
|
||||
// double quote smart quotes
|
||||
'/"(\s|$)/' => '”$1',
|
||||
'/(^|\s|<p>)"/' => '$1“',
|
||||
'/"(\W)/' => '”$1',
|
||||
'/(\W)"/' => '$1“',
|
||||
|
||||
// apostrophes
|
||||
"/(\w)'(\w)/" => '$1’$2',
|
||||
|
||||
// Em dash and ellipses dots
|
||||
'/\s?\-\-\s?/' => '—',
|
||||
'/(\w)\.{3}/' => '$1…',
|
||||
|
||||
// double space after sentences
|
||||
'/(\W) /' => '$1 ',
|
||||
|
||||
// ampersands, if not a character entity
|
||||
'/&(?!#?[a-zA-Z0-9]{2,};)/' => '&'
|
||||
);
|
||||
}
|
||||
|
||||
return preg_replace(array_keys($table), $table, $str);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Format Newlines
|
||||
*
|
||||
* Converts newline characters into either <p> tags or <br />
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function _format_newlines($str)
|
||||
{
|
||||
if ($str == '')
|
||||
{
|
||||
return $str;
|
||||
}
|
||||
|
||||
if (strpos($str, "\n") === FALSE && ! in_array($this->last_block_element, $this->inner_block_required))
|
||||
{
|
||||
return $str;
|
||||
}
|
||||
|
||||
// Convert two consecutive newlines to paragraphs
|
||||
$str = str_replace("\n\n", "</p>\n\n<p>", $str);
|
||||
|
||||
// Convert single spaces to <br /> tags
|
||||
$str = preg_replace("/([^\n])(\n)([^\n])/", "\\1<br />\\2\\3", $str);
|
||||
|
||||
// Wrap the whole enchilada in enclosing paragraphs
|
||||
if ($str != "\n")
|
||||
{
|
||||
// We trim off the right-side new line so that the closing </p> tag
|
||||
// will be positioned immediately following the string, matching
|
||||
// the behavior of the opening <p> tag
|
||||
$str = '<p>'.rtrim($str).'</p>';
|
||||
}
|
||||
|
||||
// Remove empty paragraphs if they are on the first line, as this
|
||||
// is a potential unintended consequence of the previous code
|
||||
$str = preg_replace("/<p><\/p>(.*)/", "\\1", $str, 1);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Protect Characters
|
||||
*
|
||||
* Protects special characters from being formatted later
|
||||
* We don't want quotes converted within tags so we'll temporarily convert them to {@DQ} and {@SQ}
|
||||
* and we don't want double dashes converted to emdash entities, so they are marked with {@DD}
|
||||
* likewise double spaces are converted to {@NBS} to prevent entity conversion
|
||||
*
|
||||
* @access public
|
||||
* @param array
|
||||
* @return string
|
||||
*/
|
||||
function _protect_characters($match)
|
||||
{
|
||||
return str_replace(array("'",'"','--',' '), array('{@SQ}', '{@DQ}', '{@DD}', '{@NBS}'), $match[0]);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Convert newlines to HTML line breaks except within PRE tags
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function nl2br_except_pre($str)
|
||||
{
|
||||
$ex = explode("pre>",$str);
|
||||
$ct = count($ex);
|
||||
|
||||
$newstr = "";
|
||||
for ($i = 0; $i < $ct; $i++)
|
||||
{
|
||||
if (($i % 2) == 0)
|
||||
{
|
||||
$newstr .= nl2br($ex[$i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$newstr .= $ex[$i];
|
||||
}
|
||||
|
||||
if ($ct - 1 != $i)
|
||||
$newstr .= "pre>";
|
||||
}
|
||||
|
||||
return $newstr;
|
||||
}
|
||||
|
||||
}
|
||||
// END Typography Class
|
||||
|
||||
/* End of file Typography.php */
|
||||
/* Location: ./system/libraries/Typography.php */
|
383
system/libraries/Unit_test.php
Normal file
383
system/libraries/Unit_test.php
Normal file
@ -0,0 +1,383 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.3.1
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Unit Testing Class
|
||||
*
|
||||
* Simple testing class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category UnitTesting
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link http://codeigniter.com/user_guide/libraries/uri.html
|
||||
*/
|
||||
class CI_Unit_test {
|
||||
|
||||
var $active = TRUE;
|
||||
var $results = array();
|
||||
var $strict = FALSE;
|
||||
var $_template = NULL;
|
||||
var $_template_rows = NULL;
|
||||
var $_test_items_visible = array();
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// These are the default items visible when a test is run.
|
||||
$this->_test_items_visible = array (
|
||||
'test_name',
|
||||
'test_datatype',
|
||||
'res_datatype',
|
||||
'result',
|
||||
'file',
|
||||
'line',
|
||||
'notes'
|
||||
);
|
||||
|
||||
log_message('debug', "Unit Testing Class Initialized");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Run the tests
|
||||
*
|
||||
* Runs the supplied tests
|
||||
*
|
||||
* @access public
|
||||
* @param array
|
||||
* @return void
|
||||
*/
|
||||
function set_test_items($items = array())
|
||||
{
|
||||
if ( ! empty($items) AND is_array($items))
|
||||
{
|
||||
$this->_test_items_visible = $items;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Run the tests
|
||||
*
|
||||
* Runs the supplied tests
|
||||
*
|
||||
* @access public
|
||||
* @param mixed
|
||||
* @param mixed
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
function run($test, $expected = TRUE, $test_name = 'undefined', $notes = '')
|
||||
{
|
||||
if ($this->active == FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (in_array($expected, array('is_object', 'is_string', 'is_bool', 'is_true', 'is_false', 'is_int', 'is_numeric', 'is_float', 'is_double', 'is_array', 'is_null'), TRUE))
|
||||
{
|
||||
$expected = str_replace('is_float', 'is_double', $expected);
|
||||
$result = ($expected($test)) ? TRUE : FALSE;
|
||||
$extype = str_replace(array('true', 'false'), 'bool', str_replace('is_', '', $expected));
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->strict == TRUE)
|
||||
$result = ($test === $expected) ? TRUE : FALSE;
|
||||
else
|
||||
$result = ($test == $expected) ? TRUE : FALSE;
|
||||
|
||||
$extype = gettype($expected);
|
||||
}
|
||||
|
||||
$back = $this->_backtrace();
|
||||
|
||||
$report[] = array (
|
||||
'test_name' => $test_name,
|
||||
'test_datatype' => gettype($test),
|
||||
'res_datatype' => $extype,
|
||||
'result' => ($result === TRUE) ? 'passed' : 'failed',
|
||||
'file' => $back['file'],
|
||||
'line' => $back['line'],
|
||||
'notes' => $notes
|
||||
);
|
||||
|
||||
$this->results[] = $report;
|
||||
|
||||
return($this->report($this->result($report)));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Generate a report
|
||||
*
|
||||
* Displays a table with the test data
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function report($result = array())
|
||||
{
|
||||
if (count($result) == 0)
|
||||
{
|
||||
$result = $this->result();
|
||||
}
|
||||
|
||||
$CI =& get_instance();
|
||||
$CI->load->language('unit_test');
|
||||
|
||||
$this->_parse_template();
|
||||
|
||||
$r = '';
|
||||
foreach ($result as $res)
|
||||
{
|
||||
$table = '';
|
||||
|
||||
foreach ($res as $key => $val)
|
||||
{
|
||||
if ($key == $CI->lang->line('ut_result'))
|
||||
{
|
||||
if ($val == $CI->lang->line('ut_passed'))
|
||||
{
|
||||
$val = '<span style="color: #0C0;">'.$val.'</span>';
|
||||
}
|
||||
elseif ($val == $CI->lang->line('ut_failed'))
|
||||
{
|
||||
$val = '<span style="color: #C00;">'.$val.'</span>';
|
||||
}
|
||||
}
|
||||
|
||||
$temp = $this->_template_rows;
|
||||
$temp = str_replace('{item}', $key, $temp);
|
||||
$temp = str_replace('{result}', $val, $temp);
|
||||
$table .= $temp;
|
||||
}
|
||||
|
||||
$r .= str_replace('{rows}', $table, $this->_template);
|
||||
}
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Use strict comparison
|
||||
*
|
||||
* Causes the evaluation to use === rather than ==
|
||||
*
|
||||
* @access public
|
||||
* @param bool
|
||||
* @return null
|
||||
*/
|
||||
function use_strict($state = TRUE)
|
||||
{
|
||||
$this->strict = ($state == FALSE) ? FALSE : TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Make Unit testing active
|
||||
*
|
||||
* Enables/disables unit testing
|
||||
*
|
||||
* @access public
|
||||
* @param bool
|
||||
* @return null
|
||||
*/
|
||||
function active($state = TRUE)
|
||||
{
|
||||
$this->active = ($state == FALSE) ? FALSE : TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result Array
|
||||
*
|
||||
* Returns the raw result data
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
function result($results = array())
|
||||
{
|
||||
$CI =& get_instance();
|
||||
$CI->load->language('unit_test');
|
||||
|
||||
if (count($results) == 0)
|
||||
{
|
||||
$results = $this->results;
|
||||
}
|
||||
|
||||
$retval = array();
|
||||
foreach ($results as $result)
|
||||
{
|
||||
$temp = array();
|
||||
foreach ($result as $key => $val)
|
||||
{
|
||||
if ( ! in_array($key, $this->_test_items_visible))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_array($val))
|
||||
{
|
||||
foreach ($val as $k => $v)
|
||||
{
|
||||
if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v))))
|
||||
{
|
||||
$v = $line;
|
||||
}
|
||||
$temp[$CI->lang->line('ut_'.$k)] = $v;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$val))))
|
||||
{
|
||||
$val = $line;
|
||||
}
|
||||
$temp[$CI->lang->line('ut_'.$key)] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
$retval[] = $temp;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the template
|
||||
*
|
||||
* This lets us set the template to be used to display results
|
||||
*
|
||||
* @access public
|
||||
* @param string
|
||||
* @return void
|
||||
*/
|
||||
function set_template($template)
|
||||
{
|
||||
$this->_template = $template;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Generate a backtrace
|
||||
*
|
||||
* This lets us show file names and line numbers
|
||||
*
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
function _backtrace()
|
||||
{
|
||||
if (function_exists('debug_backtrace'))
|
||||
{
|
||||
$back = debug_backtrace();
|
||||
|
||||
$file = ( ! isset($back['1']['file'])) ? '' : $back['1']['file'];
|
||||
$line = ( ! isset($back['1']['line'])) ? '' : $back['1']['line'];
|
||||
|
||||
return array('file' => $file, 'line' => $line);
|
||||
}
|
||||
return array('file' => 'Unknown', 'line' => 'Unknown');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get Default Template
|
||||
*
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _default_template()
|
||||
{
|
||||
$this->_template = "\n".'<table style="width:100%; font-size:small; margin:10px 0; border-collapse:collapse; border:1px solid #CCC;">';
|
||||
$this->_template .= '{rows}';
|
||||
$this->_template .= "\n".'</table>';
|
||||
|
||||
$this->_template_rows = "\n\t".'<tr>';
|
||||
$this->_template_rows .= "\n\t\t".'<th style="text-align: left; border-bottom:1px solid #CCC;">{item}</th>';
|
||||
$this->_template_rows .= "\n\t\t".'<td style="border-bottom:1px solid #CCC;">{result}</td>';
|
||||
$this->_template_rows .= "\n\t".'</tr>';
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Parse Template
|
||||
*
|
||||
* Harvests the data within the template {pseudo-variables}
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
function _parse_template()
|
||||
{
|
||||
if ( ! is_null($this->_template_rows))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_null($this->_template))
|
||||
{
|
||||
$this->_default_template();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! preg_match("/\{rows\}(.*?)\{\/rows\}/si", $this->_template, $match))
|
||||
{
|
||||
$this->_default_template();
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_template_rows = $match['1'];
|
||||
$this->_template = str_replace($match['0'], '{rows}', $this->_template);
|
||||
}
|
||||
|
||||
}
|
||||
// END Unit_test Class
|
||||
|
||||
/**
|
||||
* Helper functions to test boolean true/false
|
||||
*
|
||||
*
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
function is_true($test)
|
||||
{
|
||||
return (is_bool($test) AND $test === TRUE) ? TRUE : FALSE;
|
||||
}
|
||||
function is_false($test)
|
||||
{
|
||||
return (is_bool($test) AND $test === FALSE) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
|
||||
/* End of file Unit_test.php */
|
||||
/* Location: ./system/libraries/Unit_test.php */
|
1136
system/libraries/Upload.php
Normal file
1136
system/libraries/Upload.php
Normal file
File diff suppressed because it is too large
Load Diff
549
system/libraries/User_agent.php
Normal file
549
system/libraries/User_agent.php
Normal file
@ -0,0 +1,549 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* User Agent Class
|
||||
*
|
||||
* Identifies the platform, browser, robot, or mobile devise of the browsing agent
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category User Agent
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link http://codeigniter.com/user_guide/libraries/user_agent.html
|
||||
*/
|
||||
class CI_User_agent {
|
||||
|
||||
var $agent = NULL;
|
||||
|
||||
var $is_browser = FALSE;
|
||||
var $is_robot = FALSE;
|
||||
var $is_mobile = FALSE;
|
||||
|
||||
var $languages = array();
|
||||
var $charsets = array();
|
||||
|
||||
var $platforms = array();
|
||||
var $browsers = array();
|
||||
var $mobiles = array();
|
||||
var $robots = array();
|
||||
|
||||
var $platform = '';
|
||||
var $browser = '';
|
||||
var $version = '';
|
||||
var $mobile = '';
|
||||
var $robot = '';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Sets the User Agent and runs the compilation routine
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (isset($_SERVER['HTTP_USER_AGENT']))
|
||||
{
|
||||
$this->agent = trim($_SERVER['HTTP_USER_AGENT']);
|
||||
}
|
||||
|
||||
if ( ! is_null($this->agent))
|
||||
{
|
||||
if ($this->_load_agent_file())
|
||||
{
|
||||
$this->_compile_data();
|
||||
}
|
||||
}
|
||||
|
||||
log_message('debug', "User Agent Class Initialized");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Compile the User Agent Data
|
||||
*
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
private function _load_agent_file()
|
||||
{
|
||||
if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php'))
|
||||
{
|
||||
include(APPPATH.'config/'.ENVIRONMENT.'/user_agents.php');
|
||||
}
|
||||
elseif (is_file(APPPATH.'config/user_agents.php'))
|
||||
{
|
||||
include(APPPATH.'config/user_agents.php');
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$return = FALSE;
|
||||
|
||||
if (isset($platforms))
|
||||
{
|
||||
$this->platforms = $platforms;
|
||||
unset($platforms);
|
||||
$return = TRUE;
|
||||
}
|
||||
|
||||
if (isset($browsers))
|
||||
{
|
||||
$this->browsers = $browsers;
|
||||
unset($browsers);
|
||||
$return = TRUE;
|
||||
}
|
||||
|
||||
if (isset($mobiles))
|
||||
{
|
||||
$this->mobiles = $mobiles;
|
||||
unset($mobiles);
|
||||
$return = TRUE;
|
||||
}
|
||||
|
||||
if (isset($robots))
|
||||
{
|
||||
$this->robots = $robots;
|
||||
unset($robots);
|
||||
$return = TRUE;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Compile the User Agent Data
|
||||
*
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
private function _compile_data()
|
||||
{
|
||||
$this->_set_platform();
|
||||
|
||||
foreach (array('_set_robot', '_set_browser', '_set_mobile') as $function)
|
||||
{
|
||||
if ($this->$function() === TRUE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the Platform
|
||||
*
|
||||
* @access private
|
||||
* @return mixed
|
||||
*/
|
||||
private function _set_platform()
|
||||
{
|
||||
if (is_array($this->platforms) AND count($this->platforms) > 0)
|
||||
{
|
||||
foreach ($this->platforms as $key => $val)
|
||||
{
|
||||
if (preg_match("|".preg_quote($key)."|i", $this->agent))
|
||||
{
|
||||
$this->platform = $val;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->platform = 'Unknown Platform';
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the Browser
|
||||
*
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
private function _set_browser()
|
||||
{
|
||||
if (is_array($this->browsers) AND count($this->browsers) > 0)
|
||||
{
|
||||
foreach ($this->browsers as $key => $val)
|
||||
{
|
||||
if (preg_match("|".preg_quote($key).".*?([0-9\.]+)|i", $this->agent, $match))
|
||||
{
|
||||
$this->is_browser = TRUE;
|
||||
$this->version = $match[1];
|
||||
$this->browser = $val;
|
||||
$this->_set_mobile();
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the Robot
|
||||
*
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
private function _set_robot()
|
||||
{
|
||||
if (is_array($this->robots) AND count($this->robots) > 0)
|
||||
{
|
||||
foreach ($this->robots as $key => $val)
|
||||
{
|
||||
if (preg_match("|".preg_quote($key)."|i", $this->agent))
|
||||
{
|
||||
$this->is_robot = TRUE;
|
||||
$this->robot = $val;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the Mobile Device
|
||||
*
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
private function _set_mobile()
|
||||
{
|
||||
if (is_array($this->mobiles) AND count($this->mobiles) > 0)
|
||||
{
|
||||
foreach ($this->mobiles as $key => $val)
|
||||
{
|
||||
if (FALSE !== (strpos(strtolower($this->agent), $key)))
|
||||
{
|
||||
$this->is_mobile = TRUE;
|
||||
$this->mobile = $val;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the accepted languages
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
private function _set_languages()
|
||||
{
|
||||
if ((count($this->languages) == 0) AND isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) AND $_SERVER['HTTP_ACCEPT_LANGUAGE'] != '')
|
||||
{
|
||||
$languages = preg_replace('/(;q=[0-9\.]+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_LANGUAGE'])));
|
||||
|
||||
$this->languages = explode(',', $languages);
|
||||
}
|
||||
|
||||
if (count($this->languages) == 0)
|
||||
{
|
||||
$this->languages = array('Undefined');
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the accepted character sets
|
||||
*
|
||||
* @access private
|
||||
* @return void
|
||||
*/
|
||||
private function _set_charsets()
|
||||
{
|
||||
if ((count($this->charsets) == 0) AND isset($_SERVER['HTTP_ACCEPT_CHARSET']) AND $_SERVER['HTTP_ACCEPT_CHARSET'] != '')
|
||||
{
|
||||
$charsets = preg_replace('/(;q=.+)/i', '', strtolower(trim($_SERVER['HTTP_ACCEPT_CHARSET'])));
|
||||
|
||||
$this->charsets = explode(',', $charsets);
|
||||
}
|
||||
|
||||
if (count($this->charsets) == 0)
|
||||
{
|
||||
$this->charsets = array('Undefined');
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Is Browser
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function is_browser($key = NULL)
|
||||
{
|
||||
if ( ! $this->is_browser)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// No need to be specific, it's a browser
|
||||
if ($key === NULL)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Check for a specific browser
|
||||
return array_key_exists($key, $this->browsers) AND $this->browser === $this->browsers[$key];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Is Robot
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function is_robot($key = NULL)
|
||||
{
|
||||
if ( ! $this->is_robot)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// No need to be specific, it's a robot
|
||||
if ($key === NULL)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Check for a specific robot
|
||||
return array_key_exists($key, $this->robots) AND $this->robot === $this->robots[$key];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Is Mobile
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function is_mobile($key = NULL)
|
||||
{
|
||||
if ( ! $this->is_mobile)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// No need to be specific, it's a mobile
|
||||
if ($key === NULL)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Check for a specific robot
|
||||
return array_key_exists($key, $this->mobiles) AND $this->mobile === $this->mobiles[$key];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Is this a referral from another site?
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function is_referral()
|
||||
{
|
||||
if ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '')
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Agent String
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function agent_string()
|
||||
{
|
||||
return $this->agent;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get Platform
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function platform()
|
||||
{
|
||||
return $this->platform;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get Browser Name
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function browser()
|
||||
{
|
||||
return $this->browser;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the Browser Version
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get The Robot Name
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function robot()
|
||||
{
|
||||
return $this->robot;
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the Mobile Device
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function mobile()
|
||||
{
|
||||
return $this->mobile;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the referrer
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function referrer()
|
||||
{
|
||||
return ( ! isset($_SERVER['HTTP_REFERER']) OR $_SERVER['HTTP_REFERER'] == '') ? '' : trim($_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the accepted languages
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function languages()
|
||||
{
|
||||
if (count($this->languages) == 0)
|
||||
{
|
||||
$this->_set_languages();
|
||||
}
|
||||
|
||||
return $this->languages;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the accepted Character Sets
|
||||
*
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function charsets()
|
||||
{
|
||||
if (count($this->charsets) == 0)
|
||||
{
|
||||
$this->_set_charsets();
|
||||
}
|
||||
|
||||
return $this->charsets;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Test for a particular language
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function accept_lang($lang = 'en')
|
||||
{
|
||||
return (in_array(strtolower($lang), $this->languages(), TRUE));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Test for a particular character set
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function accept_charset($charset = 'utf-8')
|
||||
{
|
||||
return (in_array(strtolower($charset), $this->charsets(), TRUE));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* End of file User_agent.php */
|
||||
/* Location: ./system/libraries/User_agent.php */
|
1423
system/libraries/Xmlrpc.php
Normal file
1423
system/libraries/Xmlrpc.php
Normal file
File diff suppressed because it is too large
Load Diff
612
system/libraries/Xmlrpcs.php
Normal file
612
system/libraries/Xmlrpcs.php
Normal file
@ -0,0 +1,612 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
if ( ! function_exists('xml_parser_create'))
|
||||
{
|
||||
show_error('Your PHP installation does not support XML');
|
||||
}
|
||||
|
||||
if ( ! class_exists('CI_Xmlrpc'))
|
||||
{
|
||||
show_error('You must load the Xmlrpc class before loading the Xmlrpcs class in order to create a server.');
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* XML-RPC server class
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category XML-RPC
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link http://codeigniter.com/user_guide/libraries/xmlrpc.html
|
||||
*/
|
||||
class CI_Xmlrpcs extends CI_Xmlrpc
|
||||
{
|
||||
var $methods = array(); //array of methods mapped to function names and signatures
|
||||
var $debug_msg = ''; // Debug Message
|
||||
var $system_methods = array(); // XML RPC Server methods
|
||||
var $controller_obj;
|
||||
|
||||
var $object = FALSE;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct($config=array())
|
||||
{
|
||||
parent::__construct();
|
||||
$this->set_system_methods();
|
||||
|
||||
if (isset($config['functions']) && is_array($config['functions']))
|
||||
{
|
||||
$this->methods = array_merge($this->methods, $config['functions']);
|
||||
}
|
||||
|
||||
log_message('debug', "XML-RPC Server Class Initialized");
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Initialize Prefs and Serve
|
||||
*
|
||||
* @access public
|
||||
* @param mixed
|
||||
* @return void
|
||||
*/
|
||||
function initialize($config=array())
|
||||
{
|
||||
if (isset($config['functions']) && is_array($config['functions']))
|
||||
{
|
||||
$this->methods = array_merge($this->methods, $config['functions']);
|
||||
}
|
||||
|
||||
if (isset($config['debug']))
|
||||
{
|
||||
$this->debug = $config['debug'];
|
||||
}
|
||||
|
||||
if (isset($config['object']) && is_object($config['object']))
|
||||
{
|
||||
$this->object = $config['object'];
|
||||
}
|
||||
|
||||
if (isset($config['xss_clean']))
|
||||
{
|
||||
$this->xss_clean = $config['xss_clean'];
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Setting of System Methods
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function set_system_methods()
|
||||
{
|
||||
$this->methods = array(
|
||||
'system.listMethods' => array(
|
||||
'function' => 'this.listMethods',
|
||||
'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString), array($this->xmlrpcArray)),
|
||||
'docstring' => 'Returns an array of available methods on this server'),
|
||||
'system.methodHelp' => array(
|
||||
'function' => 'this.methodHelp',
|
||||
'signature' => array(array($this->xmlrpcString, $this->xmlrpcString)),
|
||||
'docstring' => 'Returns a documentation string for the specified method'),
|
||||
'system.methodSignature' => array(
|
||||
'function' => 'this.methodSignature',
|
||||
'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString)),
|
||||
'docstring' => 'Returns an array describing the return type and required parameters of a method'),
|
||||
'system.multicall' => array(
|
||||
'function' => 'this.multicall',
|
||||
'signature' => array(array($this->xmlrpcArray, $this->xmlrpcArray)),
|
||||
'docstring' => 'Combine multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details')
|
||||
);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Main Server Function
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function serve()
|
||||
{
|
||||
$r = $this->parseRequest();
|
||||
$payload = '<?xml version="1.0" encoding="'.$this->xmlrpc_defencoding.'"?'.'>'."\n";
|
||||
$payload .= $this->debug_msg;
|
||||
$payload .= $r->prepare_response();
|
||||
|
||||
header("Content-Type: text/xml");
|
||||
header("Content-Length: ".strlen($payload));
|
||||
exit($payload);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Add Method to Class
|
||||
*
|
||||
* @access public
|
||||
* @param string method name
|
||||
* @param string function
|
||||
* @param string signature
|
||||
* @param string docstring
|
||||
* @return void
|
||||
*/
|
||||
function add_to_map($methodname, $function, $sig, $doc)
|
||||
{
|
||||
$this->methods[$methodname] = array(
|
||||
'function' => $function,
|
||||
'signature' => $sig,
|
||||
'docstring' => $doc
|
||||
);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Parse Server Request
|
||||
*
|
||||
* @access public
|
||||
* @param string data
|
||||
* @return object xmlrpc response
|
||||
*/
|
||||
function parseRequest($data='')
|
||||
{
|
||||
global $HTTP_RAW_POST_DATA;
|
||||
|
||||
//-------------------------------------
|
||||
// Get Data
|
||||
//-------------------------------------
|
||||
|
||||
if ($data == '')
|
||||
{
|
||||
$data = $HTTP_RAW_POST_DATA;
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
// Set up XML Parser
|
||||
//-------------------------------------
|
||||
|
||||
$parser = xml_parser_create($this->xmlrpc_defencoding);
|
||||
$parser_object = new XML_RPC_Message("filler");
|
||||
|
||||
$parser_object->xh[$parser] = array();
|
||||
$parser_object->xh[$parser]['isf'] = 0;
|
||||
$parser_object->xh[$parser]['isf_reason'] = '';
|
||||
$parser_object->xh[$parser]['params'] = array();
|
||||
$parser_object->xh[$parser]['stack'] = array();
|
||||
$parser_object->xh[$parser]['valuestack'] = array();
|
||||
$parser_object->xh[$parser]['method'] = '';
|
||||
|
||||
xml_set_object($parser, $parser_object);
|
||||
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
|
||||
xml_set_element_handler($parser, 'open_tag', 'closing_tag');
|
||||
xml_set_character_data_handler($parser, 'character_data');
|
||||
//xml_set_default_handler($parser, 'default_handler');
|
||||
|
||||
|
||||
//-------------------------------------
|
||||
// PARSE + PROCESS XML DATA
|
||||
//-------------------------------------
|
||||
|
||||
if ( ! xml_parse($parser, $data, 1))
|
||||
{
|
||||
// return XML error as a faultCode
|
||||
$r = new XML_RPC_Response(0,
|
||||
$this->xmlrpcerrxml + xml_get_error_code($parser),
|
||||
sprintf('XML error: %s at line %d',
|
||||
xml_error_string(xml_get_error_code($parser)),
|
||||
xml_get_current_line_number($parser)));
|
||||
xml_parser_free($parser);
|
||||
}
|
||||
elseif ($parser_object->xh[$parser]['isf'])
|
||||
{
|
||||
return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']);
|
||||
}
|
||||
else
|
||||
{
|
||||
xml_parser_free($parser);
|
||||
|
||||
$m = new XML_RPC_Message($parser_object->xh[$parser]['method']);
|
||||
$plist='';
|
||||
|
||||
for ($i=0; $i < count($parser_object->xh[$parser]['params']); $i++)
|
||||
{
|
||||
if ($this->debug === TRUE)
|
||||
{
|
||||
$plist .= "$i - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE). ";\n";
|
||||
}
|
||||
|
||||
$m->addParam($parser_object->xh[$parser]['params'][$i]);
|
||||
}
|
||||
|
||||
if ($this->debug === TRUE)
|
||||
{
|
||||
echo "<pre>";
|
||||
echo "---PLIST---\n" . $plist . "\n---PLIST END---\n\n";
|
||||
echo "</pre>";
|
||||
}
|
||||
|
||||
$r = $this->_execute($m);
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
// SET DEBUGGING MESSAGE
|
||||
//-------------------------------------
|
||||
|
||||
if ($this->debug === TRUE)
|
||||
{
|
||||
$this->debug_msg = "<!-- DEBUG INFO:\n\n".$plist."\n END DEBUG-->\n";
|
||||
}
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Executes the Method
|
||||
*
|
||||
* @access protected
|
||||
* @param object
|
||||
* @return mixed
|
||||
*/
|
||||
function _execute($m)
|
||||
{
|
||||
$methName = $m->method_name;
|
||||
|
||||
// Check to see if it is a system call
|
||||
$system_call = (strncmp($methName, 'system', 5) == 0) ? TRUE : FALSE;
|
||||
|
||||
if ($this->xss_clean == FALSE)
|
||||
{
|
||||
$m->xss_clean = FALSE;
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
// Valid Method
|
||||
//-------------------------------------
|
||||
|
||||
if ( ! isset($this->methods[$methName]['function']))
|
||||
{
|
||||
return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
// Check for Method (and Object)
|
||||
//-------------------------------------
|
||||
|
||||
$method_parts = explode(".", $this->methods[$methName]['function']);
|
||||
$objectCall = (isset($method_parts['1']) && $method_parts['1'] != "") ? TRUE : FALSE;
|
||||
|
||||
if ($system_call === TRUE)
|
||||
{
|
||||
if ( ! is_callable(array($this,$method_parts['1'])))
|
||||
{
|
||||
return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($objectCall && ! is_callable(array($method_parts['0'],$method_parts['1'])))
|
||||
{
|
||||
return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
|
||||
}
|
||||
elseif ( ! $objectCall && ! is_callable($this->methods[$methName]['function']))
|
||||
{
|
||||
return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
// Checking Methods Signature
|
||||
//-------------------------------------
|
||||
|
||||
if (isset($this->methods[$methName]['signature']))
|
||||
{
|
||||
$sig = $this->methods[$methName]['signature'];
|
||||
for ($i=0; $i<count($sig); $i++)
|
||||
{
|
||||
$current_sig = $sig[$i];
|
||||
|
||||
if (count($current_sig) == count($m->params)+1)
|
||||
{
|
||||
for ($n=0; $n < count($m->params); $n++)
|
||||
{
|
||||
$p = $m->params[$n];
|
||||
$pt = ($p->kindOf() == 'scalar') ? $p->scalarval() : $p->kindOf();
|
||||
|
||||
if ($pt != $current_sig[$n+1])
|
||||
{
|
||||
$pno = $n+1;
|
||||
$wanted = $current_sig[$n+1];
|
||||
|
||||
return new XML_RPC_Response(0,
|
||||
$this->xmlrpcerr['incorrect_params'],
|
||||
$this->xmlrpcstr['incorrect_params'] .
|
||||
": Wanted {$wanted}, got {$pt} at param {$pno})");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
// Calls the Function
|
||||
//-------------------------------------
|
||||
|
||||
if ($objectCall === TRUE)
|
||||
{
|
||||
if ($method_parts[0] == "this" && $system_call == TRUE)
|
||||
{
|
||||
return call_user_func(array($this, $method_parts[1]), $m);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->object === FALSE)
|
||||
{
|
||||
$CI =& get_instance();
|
||||
return $CI->$method_parts['1']($m);
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->object->$method_parts['1']($m);
|
||||
//return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return call_user_func($this->methods[$methName]['function'], $m);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Server Function: List Methods
|
||||
*
|
||||
* @access public
|
||||
* @param mixed
|
||||
* @return object
|
||||
*/
|
||||
function listMethods($m)
|
||||
{
|
||||
$v = new XML_RPC_Values();
|
||||
$output = array();
|
||||
|
||||
foreach ($this->methods as $key => $value)
|
||||
{
|
||||
$output[] = new XML_RPC_Values($key, 'string');
|
||||
}
|
||||
|
||||
foreach ($this->system_methods as $key => $value)
|
||||
{
|
||||
$output[]= new XML_RPC_Values($key, 'string');
|
||||
}
|
||||
|
||||
$v->addArray($output);
|
||||
return new XML_RPC_Response($v);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Server Function: Return Signature for Method
|
||||
*
|
||||
* @access public
|
||||
* @param mixed
|
||||
* @return object
|
||||
*/
|
||||
function methodSignature($m)
|
||||
{
|
||||
$parameters = $m->output_parameters();
|
||||
$method_name = $parameters[0];
|
||||
|
||||
if (isset($this->methods[$method_name]))
|
||||
{
|
||||
if ($this->methods[$method_name]['signature'])
|
||||
{
|
||||
$sigs = array();
|
||||
$signature = $this->methods[$method_name]['signature'];
|
||||
|
||||
for ($i=0; $i < count($signature); $i++)
|
||||
{
|
||||
$cursig = array();
|
||||
$inSig = $signature[$i];
|
||||
for ($j=0; $j<count($inSig); $j++)
|
||||
{
|
||||
$cursig[]= new XML_RPC_Values($inSig[$j], 'string');
|
||||
}
|
||||
$sigs[]= new XML_RPC_Values($cursig, 'array');
|
||||
}
|
||||
$r = new XML_RPC_Response(new XML_RPC_Values($sigs, 'array'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$r = new XML_RPC_Response(new XML_RPC_Values('undef', 'string'));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$r = new XML_RPC_Response(0,$this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']);
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Server Function: Doc String for Method
|
||||
*
|
||||
* @access public
|
||||
* @param mixed
|
||||
* @return object
|
||||
*/
|
||||
function methodHelp($m)
|
||||
{
|
||||
$parameters = $m->output_parameters();
|
||||
$method_name = $parameters[0];
|
||||
|
||||
if (isset($this->methods[$method_name]))
|
||||
{
|
||||
$docstring = isset($this->methods[$method_name]['docstring']) ? $this->methods[$method_name]['docstring'] : '';
|
||||
|
||||
return new XML_RPC_Response(new XML_RPC_Values($docstring, 'string'));
|
||||
}
|
||||
else
|
||||
{
|
||||
return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Server Function: Multi-call
|
||||
*
|
||||
* @access public
|
||||
* @param mixed
|
||||
* @return object
|
||||
*/
|
||||
function multicall($m)
|
||||
{
|
||||
// Disabled
|
||||
return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
|
||||
|
||||
$parameters = $m->output_parameters();
|
||||
$calls = $parameters[0];
|
||||
|
||||
$result = array();
|
||||
|
||||
foreach ($calls as $value)
|
||||
{
|
||||
//$attempt = $this->_execute(new XML_RPC_Message($value[0], $value[1]));
|
||||
|
||||
$m = new XML_RPC_Message($value[0]);
|
||||
$plist='';
|
||||
|
||||
for ($i=0; $i < count($value[1]); $i++)
|
||||
{
|
||||
$m->addParam(new XML_RPC_Values($value[1][$i], 'string'));
|
||||
}
|
||||
|
||||
$attempt = $this->_execute($m);
|
||||
|
||||
if ($attempt->faultCode() != 0)
|
||||
{
|
||||
return $attempt;
|
||||
}
|
||||
|
||||
$result[] = new XML_RPC_Values(array($attempt->value()), 'array');
|
||||
}
|
||||
|
||||
return new XML_RPC_Response(new XML_RPC_Values($result, 'array'));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Multi-call Function: Error Handling
|
||||
*
|
||||
* @access public
|
||||
* @param mixed
|
||||
* @return object
|
||||
*/
|
||||
function multicall_error($err)
|
||||
{
|
||||
$str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString();
|
||||
$code = is_string($err) ? $this->xmlrpcerr["multicall_${err}"] : $err->faultCode();
|
||||
|
||||
$struct['faultCode'] = new XML_RPC_Values($code, 'int');
|
||||
$struct['faultString'] = new XML_RPC_Values($str, 'string');
|
||||
|
||||
return new XML_RPC_Values($struct, 'struct');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Multi-call Function: Processes method
|
||||
*
|
||||
* @access public
|
||||
* @param mixed
|
||||
* @return object
|
||||
*/
|
||||
function do_multicall($call)
|
||||
{
|
||||
if ($call->kindOf() != 'struct')
|
||||
{
|
||||
return $this->multicall_error('notstruct');
|
||||
}
|
||||
elseif ( ! $methName = $call->me['struct']['methodName'])
|
||||
{
|
||||
return $this->multicall_error('nomethod');
|
||||
}
|
||||
|
||||
list($scalar_type,$scalar_value)=each($methName->me);
|
||||
$scalar_type = $scalar_type == $this->xmlrpcI4 ? $this->xmlrpcInt : $scalar_type;
|
||||
|
||||
if ($methName->kindOf() != 'scalar' OR $scalar_type != 'string')
|
||||
{
|
||||
return $this->multicall_error('notstring');
|
||||
}
|
||||
elseif ($scalar_value == 'system.multicall')
|
||||
{
|
||||
return $this->multicall_error('recursion');
|
||||
}
|
||||
elseif ( ! $params = $call->me['struct']['params'])
|
||||
{
|
||||
return $this->multicall_error('noparams');
|
||||
}
|
||||
elseif ($params->kindOf() != 'array')
|
||||
{
|
||||
return $this->multicall_error('notarray');
|
||||
}
|
||||
|
||||
list($a,$b)=each($params->me);
|
||||
$numParams = count($b);
|
||||
|
||||
$msg = new XML_RPC_Message($scalar_value);
|
||||
for ($i = 0; $i < $numParams; $i++)
|
||||
{
|
||||
$msg->params[] = $params->me['array'][$i];
|
||||
}
|
||||
|
||||
$result = $this->_execute($msg);
|
||||
|
||||
if ($result->faultCode() != 0)
|
||||
{
|
||||
return $this->multicall_error($result);
|
||||
}
|
||||
|
||||
return new XML_RPC_Values(array($result->value()), 'array');
|
||||
}
|
||||
|
||||
}
|
||||
// END XML_RPC_Server class
|
||||
|
||||
|
||||
/* End of file Xmlrpcs.php */
|
||||
/* Location: ./system/libraries/Xmlrpcs.php */
|
423
system/libraries/Zip.php
Normal file
423
system/libraries/Zip.php
Normal file
@ -0,0 +1,423 @@
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/**
|
||||
* CodeIgniter
|
||||
*
|
||||
* An open source application development framework for PHP 5.1.6 or newer
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
|
||||
* @license http://codeigniter.com/user_guide/license.html
|
||||
* @link http://codeigniter.com
|
||||
* @since Version 1.0
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Zip Compression Class
|
||||
*
|
||||
* This class is based on a library I found at Zend:
|
||||
* http://www.zend.com/codex.php?id=696&single=1
|
||||
*
|
||||
* The original library is a little rough around the edges so I
|
||||
* refactored it and added several additional methods -- Rick Ellis
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Libraries
|
||||
* @category Encryption
|
||||
* @author ExpressionEngine Dev Team
|
||||
* @link http://codeigniter.com/user_guide/libraries/zip.html
|
||||
*/
|
||||
class CI_Zip {
|
||||
|
||||
var $zipdata = '';
|
||||
var $directory = '';
|
||||
var $entries = 0;
|
||||
var $file_num = 0;
|
||||
var $offset = 0;
|
||||
var $now;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
log_message('debug', "Zip Compression Class Initialized");
|
||||
|
||||
$this->now = time();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Add Directory
|
||||
*
|
||||
* Lets you add a virtual directory into which you can place files.
|
||||
*
|
||||
* @access public
|
||||
* @param mixed the directory name. Can be string or array
|
||||
* @return void
|
||||
*/
|
||||
function add_dir($directory)
|
||||
{
|
||||
foreach ((array)$directory as $dir)
|
||||
{
|
||||
if ( ! preg_match("|.+/$|", $dir))
|
||||
{
|
||||
$dir .= '/';
|
||||
}
|
||||
|
||||
$dir_time = $this->_get_mod_time($dir);
|
||||
|
||||
$this->_add_dir($dir, $dir_time['file_mtime'], $dir_time['file_mdate']);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get file/directory modification time
|
||||
*
|
||||
* If this is a newly created file/dir, we will set the time to 'now'
|
||||
*
|
||||
* @param string path to file
|
||||
* @return array filemtime/filemdate
|
||||
*/
|
||||
function _get_mod_time($dir)
|
||||
{
|
||||
// filemtime() will return false, but it does raise an error.
|
||||
$date = (@filemtime($dir)) ? filemtime($dir) : getdate($this->now);
|
||||
|
||||
$time['file_mtime'] = ($date['hours'] << 11) + ($date['minutes'] << 5) + $date['seconds'] / 2;
|
||||
$time['file_mdate'] = (($date['year'] - 1980) << 9) + ($date['mon'] << 5) + $date['mday'];
|
||||
|
||||
return $time;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Add Directory
|
||||
*
|
||||
* @access private
|
||||
* @param string the directory name
|
||||
* @return void
|
||||
*/
|
||||
function _add_dir($dir, $file_mtime, $file_mdate)
|
||||
{
|
||||
$dir = str_replace("\\", "/", $dir);
|
||||
|
||||
$this->zipdata .=
|
||||
"\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00"
|
||||
.pack('v', $file_mtime)
|
||||
.pack('v', $file_mdate)
|
||||
.pack('V', 0) // crc32
|
||||
.pack('V', 0) // compressed filesize
|
||||
.pack('V', 0) // uncompressed filesize
|
||||
.pack('v', strlen($dir)) // length of pathname
|
||||
.pack('v', 0) // extra field length
|
||||
.$dir
|
||||
// below is "data descriptor" segment
|
||||
.pack('V', 0) // crc32
|
||||
.pack('V', 0) // compressed filesize
|
||||
.pack('V', 0); // uncompressed filesize
|
||||
|
||||
$this->directory .=
|
||||
"\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00"
|
||||
.pack('v', $file_mtime)
|
||||
.pack('v', $file_mdate)
|
||||
.pack('V',0) // crc32
|
||||
.pack('V',0) // compressed filesize
|
||||
.pack('V',0) // uncompressed filesize
|
||||
.pack('v', strlen($dir)) // length of pathname
|
||||
.pack('v', 0) // extra field length
|
||||
.pack('v', 0) // file comment length
|
||||
.pack('v', 0) // disk number start
|
||||
.pack('v', 0) // internal file attributes
|
||||
.pack('V', 16) // external file attributes - 'directory' bit set
|
||||
.pack('V', $this->offset) // relative offset of local header
|
||||
.$dir;
|
||||
|
||||
$this->offset = strlen($this->zipdata);
|
||||
$this->entries++;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Add Data to Zip
|
||||
*
|
||||
* Lets you add files to the archive. If the path is included
|
||||
* in the filename it will be placed within a directory. Make
|
||||
* sure you use add_dir() first to create the folder.
|
||||
*
|
||||
* @access public
|
||||
* @param mixed
|
||||
* @param string
|
||||
* @return void
|
||||
*/
|
||||
function add_data($filepath, $data = NULL)
|
||||
{
|
||||
if (is_array($filepath))
|
||||
{
|
||||
foreach ($filepath as $path => $data)
|
||||
{
|
||||
$file_data = $this->_get_mod_time($path);
|
||||
|
||||
$this->_add_data($path, $data, $file_data['file_mtime'], $file_data['file_mdate']);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$file_data = $this->_get_mod_time($filepath);
|
||||
|
||||
$this->_add_data($filepath, $data, $file_data['file_mtime'], $file_data['file_mdate']);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Add Data to Zip
|
||||
*
|
||||
* @access private
|
||||
* @param string the file name/path
|
||||
* @param string the data to be encoded
|
||||
* @return void
|
||||
*/
|
||||
function _add_data($filepath, $data, $file_mtime, $file_mdate)
|
||||
{
|
||||
$filepath = str_replace("\\", "/", $filepath);
|
||||
|
||||
$uncompressed_size = strlen($data);
|
||||
$crc32 = crc32($data);
|
||||
|
||||
$gzdata = gzcompress($data);
|
||||
$gzdata = substr($gzdata, 2, -4);
|
||||
$compressed_size = strlen($gzdata);
|
||||
|
||||
$this->zipdata .=
|
||||
"\x50\x4b\x03\x04\x14\x00\x00\x00\x08\x00"
|
||||
.pack('v', $file_mtime)
|
||||
.pack('v', $file_mdate)
|
||||
.pack('V', $crc32)
|
||||
.pack('V', $compressed_size)
|
||||
.pack('V', $uncompressed_size)
|
||||
.pack('v', strlen($filepath)) // length of filename
|
||||
.pack('v', 0) // extra field length
|
||||
.$filepath
|
||||
.$gzdata; // "file data" segment
|
||||
|
||||
$this->directory .=
|
||||
"\x50\x4b\x01\x02\x00\x00\x14\x00\x00\x00\x08\x00"
|
||||
.pack('v', $file_mtime)
|
||||
.pack('v', $file_mdate)
|
||||
.pack('V', $crc32)
|
||||
.pack('V', $compressed_size)
|
||||
.pack('V', $uncompressed_size)
|
||||
.pack('v', strlen($filepath)) // length of filename
|
||||
.pack('v', 0) // extra field length
|
||||
.pack('v', 0) // file comment length
|
||||
.pack('v', 0) // disk number start
|
||||
.pack('v', 0) // internal file attributes
|
||||
.pack('V', 32) // external file attributes - 'archive' bit set
|
||||
.pack('V', $this->offset) // relative offset of local header
|
||||
.$filepath;
|
||||
|
||||
$this->offset = strlen($this->zipdata);
|
||||
$this->entries++;
|
||||
$this->file_num++;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Read the contents of a file and add it to the zip
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
function read_file($path, $preserve_filepath = FALSE)
|
||||
{
|
||||
if ( ! file_exists($path))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (FALSE !== ($data = file_get_contents($path)))
|
||||
{
|
||||
$name = str_replace("\\", "/", $path);
|
||||
|
||||
if ($preserve_filepath === FALSE)
|
||||
{
|
||||
$name = preg_replace("|.*/(.+)|", "\\1", $name);
|
||||
}
|
||||
|
||||
$this->add_data($name, $data);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Read a directory and add it to the zip.
|
||||
*
|
||||
* This function recursively reads a folder and everything it contains (including
|
||||
* sub-folders) and creates a zip based on it. Whatever directory structure
|
||||
* is in the original file path will be recreated in the zip file.
|
||||
*
|
||||
* @access public
|
||||
* @param string path to source
|
||||
* @return bool
|
||||
*/
|
||||
function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL)
|
||||
{
|
||||
if ( ! $fp = @opendir($path))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Set the original directory root for child dir's to use as relative
|
||||
if ($root_path === NULL)
|
||||
{
|
||||
$root_path = dirname($path).'/';
|
||||
}
|
||||
|
||||
while (FALSE !== ($file = readdir($fp)))
|
||||
{
|
||||
if (substr($file, 0, 1) == '.')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (@is_dir($path.$file))
|
||||
{
|
||||
$this->read_dir($path.$file."/", $preserve_filepath, $root_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (FALSE !== ($data = file_get_contents($path.$file)))
|
||||
{
|
||||
$name = str_replace("\\", "/", $path);
|
||||
|
||||
if ($preserve_filepath === FALSE)
|
||||
{
|
||||
$name = str_replace($root_path, '', $name);
|
||||
}
|
||||
|
||||
$this->add_data($name.$file, $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get the Zip file
|
||||
*
|
||||
* @access public
|
||||
* @return binary string
|
||||
*/
|
||||
function get_zip()
|
||||
{
|
||||
// Is there any data to return?
|
||||
if ($this->entries == 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$zip_data = $this->zipdata;
|
||||
$zip_data .= $this->directory."\x50\x4b\x05\x06\x00\x00\x00\x00";
|
||||
$zip_data .= pack('v', $this->entries); // total # of entries "on this disk"
|
||||
$zip_data .= pack('v', $this->entries); // total # of entries overall
|
||||
$zip_data .= pack('V', strlen($this->directory)); // size of central dir
|
||||
$zip_data .= pack('V', strlen($this->zipdata)); // offset to start of central dir
|
||||
$zip_data .= "\x00\x00"; // .zip file comment length
|
||||
|
||||
return $zip_data;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Write File to the specified directory
|
||||
*
|
||||
* Lets you write a file
|
||||
*
|
||||
* @access public
|
||||
* @param string the file name
|
||||
* @return bool
|
||||
*/
|
||||
function archive($filepath)
|
||||
{
|
||||
if ( ! ($fp = @fopen($filepath, FOPEN_WRITE_CREATE_DESTRUCTIVE)))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
flock($fp, LOCK_EX);
|
||||
fwrite($fp, $this->get_zip());
|
||||
flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Download
|
||||
*
|
||||
* @access public
|
||||
* @param string the file name
|
||||
* @param string the data to be encoded
|
||||
* @return bool
|
||||
*/
|
||||
function download($filename = 'backup.zip')
|
||||
{
|
||||
if ( ! preg_match("|.+?\.zip$|", $filename))
|
||||
{
|
||||
$filename .= '.zip';
|
||||
}
|
||||
|
||||
$CI =& get_instance();
|
||||
$CI->load->helper('download');
|
||||
|
||||
$get_zip = $this->get_zip();
|
||||
|
||||
$zip_content =& $get_zip;
|
||||
|
||||
force_download($filename, $zip_content);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Initialize Data
|
||||
*
|
||||
* Lets you clear current zip data. Useful if you need to create
|
||||
* multiple zips with different data.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function clear_data()
|
||||
{
|
||||
$this->zipdata = '';
|
||||
$this->directory = '';
|
||||
$this->entries = 0;
|
||||
$this->file_num = 0;
|
||||
$this->offset = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* End of file Zip.php */
|
||||
/* Location: ./system/libraries/Zip.php */
|
10
system/libraries/index.html
Normal file
10
system/libraries/index.html
Normal file
@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
1071
system/libraries/javascript/Jquery.php
Normal file
1071
system/libraries/javascript/Jquery.php
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user