Beispiel #1
0
 /**
  * Performs sql query with error reporting and logging.
  * 
  * @todo Debug debug backtrace
  * @access public
  * @param  string $sSql query string
  * @return int query result handle
  */
 public function query($sSql, &$hLink = '')
 {
     if (!$hLink) {
         $hLink =& $this->_hMaster;
     }
     PHPFOX_DEBUG ? Phpfox_Debug::start('sql') : '';
     $hRes = sqlite_query($sSql, $hLink);
     if (!$hRes) {
         Phpfox_Error::trigger('Query Error:' . $this->_sqlError(), PHPFOX_DEBUG ? E_USER_ERROR : E_USER_WARNING);
     }
     PHPFOX_DEBUG ? Phpfox_Debug::end('sql', array('sql' => $sSql, 'slave' => $this->_sIsSlave, 'rows' => is_bool($hRes) ? '-' : sqlite_num_rows($hRes))) : '';
     $this->_sIsSlave = '';
     return $hRes;
 }
Beispiel #2
0
 /**
  * Performs sql query with error reporting and logging.
  * 
  * @access public
  * @param  string $sSql query string
  * @return int query result handle
  */
 public function query($sSql, &$hLink = '')
 {
     if (!$hLink) {
         $hLink =& $this->_hMaster;
     }
     PHPFOX_DEBUG ? Phpfox_Debug::start('sql') : '';
     $this->_sLastQuery = $sSql;
     $this->_hQuery = @pg_query($hLink, $sSql);
     if (!$this->_hQuery) {
         Phpfox_Error::trigger('Query Error: ' . $this->_sqlError() . ' <br /> Query: ' . $sSql . '', PHPFOX_DEBUG ? E_USER_ERROR : E_USER_WARNING);
     }
     PHPFOX_DEBUG ? Phpfox_Debug::end('sql', array('sql' => $sSql, 'slave' => $this->_sIsSlave, 'rows' => is_bool($this->_hQuery) ? '-' : pg_num_rows($this->_hQuery))) : '';
     $this->_sIsSlave = '';
     return $this->_hQuery;
 }
Beispiel #3
0
 /**
  * Performs sql query with error reporting and logging.
  * 
  * @todo Debug debug backtrace
  * @access public
  * @param  string $sSql query string
  * @return int query result handle
  */
 public function query($sSql, &$hLink = '')
 {
     if (!$hLink) {
         $hLink =& $this->_hMaster;
     }
     PHPFOX_DEBUG ? Phpfox_Debug::start('sql') : '';
     $this->_sLastQuery = $sSql;
     $hRes = @ociparse($hLink, $sSql);
     if (!$hRes) {
         Phpfox_Error::trigger('Query Error:' . $this->_sqlError(), PHPFOX_DEBUG ? E_USER_ERROR : E_USER_WARNING);
     }
     ociexecute($hRes);
     PHPFOX_DEBUG ? Phpfox_Debug::end('sql', array('sql' => $sSql, 'slave' => $this->_sIsSlave, 'rows' => is_bool($hRes) ? '-' : ocirowcount($hRes))) : '';
     $this->_sIsSlave = '';
     return $hRes;
 }
Beispiel #4
0
 public function get($sId, $iTime = 0)
 {
     $oCache = parent::getInstance();
     if (class_exists('Phpfox_Cache_Storage_File') && Phpfox::getParam('core.cache_storage') == 'file') {
         return $oCache->get($sId, $iTime);
     }
     if (class_exists('Phpfox_Cache_Storage_Memcache') && Phpfox::getParam('core.cache_storage') == 'memcache') {
         if (defined('PHPFOX_INSTALLER')) {
             return false;
         }
         if ($this->_bFromMemoryYN) {
             $this->_bFromMemoryYN = false;
             return false;
         }
         PHPFOX_DEBUG ? Phpfox_Debug::start('cache') : false;
         if (Phpfox::getParam('core.cache_skip')) {
             return false;
         }
         $oMemcache = $this->getMemcache();
         $sName = $sId;
         if (!($sContent = $oMemcache->get($sName))) {
             return false;
         }
         $aContent = unserialize($sContent);
         if (is_array($aContent) && isset($aContent['data'])) {
             $aContent = $aContent['data'];
             if (isset($aContent['time_stamp']) && (int) $iTime > 0) {
                 if (PHPFOX_TIME - $iTime * 60 > $aContent['time_stamp']) {
                     $oMemcache->delete($sName);
                     return false;
                 }
             }
         }
         PHPFOX_DEBUG ? Phpfox_Debug::end('cache', array('namefile' => $sName)) : false;
         if (!isset($aContent)) {
             return false;
         }
         if (!is_array($aContent) && empty($aContent)) {
             return true;
         }
         if (is_array($aContent) && !count($aContent)) {
             return true;
         }
         return $aContent;
     }
 }
Beispiel #5
0
 /**
  * Performs sql query with error reporting and logging.
  * 
  * @see mysql_query()
  * @param  string $sSql MySQL query to perform
  * @param resource $hLink MySQL resource. If nothing is passed we load the default master server.
  * @return resource Returns the MYSQL resource from the function mysql_query()
  */
 public function query($sSql, &$hLink = '')
 {
     if (!$hLink) {
         $hLink =& $this->_hMaster;
     }
     PHPFOX_DEBUG ? Phpfox_Debug::start('sql') : '';
     $hRes = @($this->_aCmd['mysql_query'] == 'mysqli_query' ? $this->_aCmd['mysql_query']($hLink, $sSql) : $this->_aCmd['mysql_query']($sSql, $hLink));
     if (defined('PHPFOX_LOG_SQL') && Phpfox::getLib('file')->isWritable(PHPFOX_DIR_FILE . 'log' . PHPFOX_DS)) {
         $hFile = fopen(PHPFOX_DIR_FILE . 'log' . PHPFOX_DS . 'phpfox_query_' . date('d.m.y', PHPFOX_TIME) . '_' . md5(Phpfox::getVersion()) . '.php', 'a');
         fwrite($hFile, '<?php defined(\'PHPFOX\') or exit(\'NO DICE!\');  ?>' . "##\n{$sSql}##\n");
         fclose($hFile);
     }
     if (!$hRes) {
         Phpfox_Error::trigger('Query Error:' . $this->_sqlError(), PHPFOX_DEBUG ? E_USER_ERROR : E_USER_WARNING);
     }
     PHPFOX_DEBUG ? Phpfox_Debug::end('sql', array('sql' => $sSql, 'slave' => $this->_bIsSlave, 'rows' => is_bool($hRes) ? '-' : @$this->_aCmd['mysql_num_rows']($hRes))) : '';
     $this->_bIsSlave = false;
     return $hRes;
 }
Beispiel #6
0
 /**
  * Gets and creates an object for a class.
  *
  * @param string $sClass Class name.
  * @param array $aParams Params to pass to the class.
  * @return object Object created will be returned.
  */
 public static function &getObject($sClass, $aParams = array())
 {
     $sHash = md5($sClass . serialize($aParams));
     if (isset(self::$_aObject[$sHash])) {
         return self::$_aObject[$sHash];
     }
     PHPFOX_DEBUG ? Phpfox_Debug::start('object') : false;
     $sClass = str_replace(array('.', '-'), '_', $sClass);
     if (!class_exists($sClass)) {
         Phpfox_Error::trigger('Unable to call class: ' . $sClass, E_USER_ERROR);
     }
     if ($aParams) {
         self::$_aObject[$sHash] = new $sClass($aParams);
     } else {
         self::$_aObject[$sHash] = new $sClass();
     }
     PHPFOX_DEBUG ? Phpfox_Debug::end('object', array('name' => $sClass)) : false;
     if (method_exists(self::$_aObject[$sHash], 'getInstance')) {
         return self::$_aObject[$sHash]->getInstance();
     }
     return self::$_aObject[$sHash];
 }
Beispiel #7
0
 /**
  * We attempt to get the cache file. Also used within an IF conditional statment
  * to check if the file has already been cached.
  *
  * @see self::set()
  * @param string $sId Unique ID of the file we need to get. This is what is returned from when you use the set() method.
  * @param int $iTime By default this is left blank, however you can identify how long a file should be cached before it needs to be updated in minutes.
  * @return mixed If the file is cached we return the data. If the file is cached but emptry we return a true (bool). if the file has not been cached we return false (bool).
  */
 public function get($sId, $iTime = 0)
 {
     // We don't allow caching during an install or upgrade.
     if (defined('PHPFOX_INSTALLER')) {
         return false;
     }
     if ($this->_bFromMemory) {
         $this->_bFromMemory = false;
         return false;
     }
     PHPFOX_DEBUG ? Phpfox_Debug::start('cache') : false;
     if (!$this->isCached($sId, $iTime)) {
         return false;
     }
     require $this->_getName($this->_aName[$sId]);
     PHPFOX_DEBUG ? Phpfox_Debug::end('cache', array('namefile' => $this->_getName($this->_aName[$sId]))) : false;
     if (!isset($aContent)) {
         return false;
     }
     if ($this->_bSkipClose === false) {
         $this->_bSkipClose = false;
         $this->close($sId);
     }
     /* 
     	Incase the data is not an array and is empty make sure we return it as 'true' 
     	since the data is already cached.		
     */
     if (!is_array($aContent) && empty($aContent)) {
         return true;
     }
     if (is_array($aContent) && !count($aContent)) {
         return true;
     }
     return $aContent;
 }
Beispiel #8
0
 /**
  * Gets a template file from cache. If the file does not exist we re-cache the template.
  *
  * @param string $sFile Full path of the template we are loading.
  */
 private function _getFromCache($sFile, $sTemplate = null)
 {
     if (is_array($sFile)) {
         $sContent = $sFile[0];
         $sFile = $sTemplate;
     }
     if (!$this->_isCached($sFile)) {
         $oTplCache = Phpfox::getLib('template.cache');
         if (!isset($sContent)) {
             $sContent = file_exists($sFile) ? file_get_contents($sFile) : null;
         }
         $mData = $oTplCache->compile($this->_getCachedName($sFile), $sContent);
     }
     // No cache directory so we must
     if (defined('PHPFOX_INSTALLER_NO_TMP')) {
         eval(' ?>' . $mData . '<?php ');
         return;
     }
     PHPFOX_DEBUG ? Phpfox_Debug::start('template') : false;
     $this->_requireFile($sFile);
     PHPFOX_DEBUG ? Phpfox_Debug::end('template', array('name' => $sFile)) : false;
 }
Beispiel #9
0
error_reporting((PHPFOX_DEBUG ? E_ALL | E_STRICT : 0));

require(PHPFOX_DIR_LIB_CORE . 'phpfox' . PHPFOX_DS . 'phpfox.class.php');
require(PHPFOX_DIR_LIB_CORE . 'error' . PHPFOX_DS . 'error.class.php');
require(PHPFOX_DIR_LIB_CORE . 'module' . PHPFOX_DS . 'service.class.php');
require(PHPFOX_DIR_LIB_CORE . 'module' . PHPFOX_DS . 'component.class.php');

// No need to load the debug class if the debug is disabled
if (PHPFOX_DEBUG)
{
	require_once(PHPFOX_DIR_LIB_CORE . 'debug' . PHPFOX_DS . 'debug.class.php');	
}

set_error_handler(array('Phpfox_Error', 'errorHandler'));

(PHPFOX_DEBUG ? Phpfox_Debug::start('init') : false);

// Default time to GMT
if (function_exists('date_default_timezone_set'))
{
	date_default_timezone_set('GMT');
	
	define('PHPFOX_TIME', time());
}
else 
{
	define('PHPFOX_TIME', strtotime(gmdate("M d Y H:i:s", time())));
}

Phpfox::getLib('setting')->set();
Beispiel #10
0
 /**
  * We attempt to get the cache file. Also used within an IF conditional statment
  * to check if the file has already been cached.
  *
  * @see self::set()
  * @param string $sId Unique ID of the file we need to get. This is what is returned from when you use the set() method.
  * @param int $iTime By default this is left blank, however you can identify how long a file should be cached before it needs to be updated in minutes.
  * @return mixed If the file is cached we return the data. If the file is cached but emptry we return a true (bool). if the file has not been cached we return false (bool).
  */
 public function get($sId, $iTime = 0)
 {
     // We don't allow caching during an install or upgrade.
     if (defined('PHPFOX_INSTALLER')) {
         return false;
     }
     PHPFOX_DEBUG ? Phpfox_Debug::start('cache') : false;
     if (!$this->isCached($sId, $iTime)) {
         return false;
     }
     $aContent = (require $this->_getName($this->_aName[$sId]));
     PHPFOX_DEBUG ? Phpfox_Debug::end('cache', array('namefile' => $this->_getName($this->_aName[$sId]))) : false;
     if (!is_array($aContent) && empty($aContent)) {
         return true;
     }
     if (is_array($aContent) && !count($aContent)) {
         return true;
     }
     return $aContent;
 }
Beispiel #11
0
 /**
  * We attempt to get the cache file. Also used within an IF conditional statment
  * to check if the file has already been cached.
  *
  * @see self::set()
  * @param string $sId Unique ID of the file we need to get. This is what is returned from when you use the set() method.
  * @param int $iTime By default this is left blank, however you can identify how long a file should be cached before it needs to be updated in minutes.
  * @return mixed If the file is cached we return the data. If the file is cached but emptry we return a true (bool). if the file has not been cached we return false (bool).
  */
 public function get($sId, $iTime = 0)
 {
     // We don't allow caching during an install or upgrade.
     if (defined('PHPFOX_INSTALLER')) {
         return false;
     }
     if ($this->_bFromMemory) {
         $this->_bFromMemory = false;
         return false;
     }
     PHPFOX_DEBUG ? Phpfox_Debug::start('cache') : false;
     /*
     if (!$this->isCached($sId, $iTime))
     {
     	return false;
     }		
     */
     if (Phpfox::getParam('core.cache_skip')) {
         return false;
     }
     if (!($sContent = $this->_oDb->get($this->_getName($this->_aName[$sId])))) {
         return false;
     }
     $aContent = unserialize($sContent);
     if (is_array($aContent) && isset($aContent['data'])) {
         $aContent = $aContent['data'];
         if (isset($aContent['time_stamp']) && (int) $iTime > 0) {
             if (PHPFOX_TIME - $iTime * 60 > $aContent['time_stamp']) {
                 $this->remove($this->_aName[$sId]);
                 return false;
             }
         }
     }
     PHPFOX_DEBUG ? Phpfox_Debug::end('cache', array('namefile' => $this->_getName($this->_aName[$sId]))) : false;
     if (!isset($aContent)) {
         return false;
     }
     if ($this->_bSkipClose === false) {
         $this->_bSkipClose = false;
         $this->close($sId);
     }
     /* 
     	Incase the data is not an array and is empty make sure we return it as 'true' 
     	since the data is already cached.		
     */
     if (!is_array($aContent) && empty($aContent)) {
         return true;
     }
     if (is_array($aContent) && !count($aContent)) {
         return true;
     }
     return $aContent;
 }
Beispiel #12
0
	/**
	 * Gets a template file from cache. If the file does not exist we re-cache the template.
	 *
	 * @param string $sFile Full path of the template we are loading.
	 */
	private function _getFromCache($sFile)
	{		
		if (!$this->_isCached($sFile))
		{
			$oTplCache = Phpfox::getLib('template.cache');
	
			$sContent = (file_exists($sFile) ? file_get_contents($sFile) : null);
			
			$mData = $oTplCache->compile($this->_getCachedName($sFile), $sContent);
		}		
		
		// No cache directory so we must 
		if (defined('PHPFOX_INSTALLER_NO_TMP'))
		{
			eval(' ?>' . $mData . '<?php ');
			exit;
		}

		(PHPFOX_DEBUG ? Phpfox_Debug::start('template') : false);		
		require($this->_getCachedName($sFile));
		(PHPFOX_DEBUG ? Phpfox_Debug::end('template', array('name' => $sFile)) : false);
	}