Example #1
0
 /**
  * Reset a debug test for a specific routine
  *
  * @param string $sName Unique identifier of the test. If left blank it will reset all tests.
  * @static 
  */
 public static function reset($sName = null)
 {
     if ($sName === null) {
         self::$_aDebug = array();
         return;
     }
     unset(self::$_aDebug[$sName]);
 }
Example #2
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;
 }
Example #3
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;
     }
 }
Example #4
0
 /**
  * Controller
  */
 public function process()
 {
     define('PHPFOX_MEM_END', memory_get_usage());
     $this->template()->assign(array('sDebugInfo' => PHPFOX_DEBUG ? Phpfox_Debug::getDetails() : ''));
 }
Example #5
0
/**
 * Prints error messages. Used with AJAX calls
 */
function e()
{
    $bCliOrAjax = PHP_SAPI == 'cli' || defined('PHPFOX_IS_AJAX') && PHPFOX_IS_AJAX;
    ob_clean();
    if (!$bCliOrAjax) {
        echo '<link rel="stylesheet" type="text/css" href="theme/adminpanel/default/style/default/css/debug.css?v=' . PHPFOX_TIME . '" />';
    }
    define('PHPFOX_MEM_END', memory_get_usage());
    echo Phpfox_Debug::getDetails();
    exit;
}
Example #6
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;
 }
Example #7
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;
 }
Example #8
0
	if (!function_exists('json_decode'))
	{
		function json_decode($mData) 
		{
			$json = new Services_JSON();
			
			return ($json->decode($mData));
		}
	}
}

// Start a session if needed
if (!defined('PHPFOX_NO_SESSION'))
{
	Phpfox::getLib('session.handler')->init();
}

if (!defined('PHPFOX_NO_USER_SESSION'))
{	
	Phpfox::getService('log.session')->setUserSession();
}

// check if user already verified their email
Phpfox::getService('user.auth')->handleStatus();	

(($sPlugin = Phpfox_Plugin::get('init')) ? eval($sPlugin) : false);

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

?>
Example #9
0
 function sqlReport($sQuery)
 {
     $sHtml = '';
     $sExplainQuery = $sQuery;
     if (preg_match('/UPDATE ([a-z0-9_]+).*?WHERE(.*)/s', $sQuery, $m)) {
         $sExplainQuery = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2];
     } elseif (preg_match('/DELETE FROM ([a-z0-9_]+).*?WHERE(.*)/s', $sQuery, $m)) {
         $sExplainQuery = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2];
     }
     if (preg_match('/^SELECT/', $sExplainQuery)) {
         $bTable = false;
         if ($hResult = @pg_query($this->_hMaster, "EXPLAIN {$sExplainQuery}")) {
             while ($aRow = @pg_fetch_assoc($hResult)) {
                 list($bTable, $sData) = Phpfox_Debug::addRow($bTable, $aRow);
                 $sHtml .= $sData;
             }
         }
         @pg_free_result($hResult);
         if ($bTable) {
             $sHtml .= '</table>';
         }
     }
     return $sHtml;
 }
Example #10
0
 public function sqlReport($sQuery)
 {
     if (!preg_match('/^SELECT/', $sQuery)) {
         return '';
     }
     $bTable = false;
     $sHtml = '';
     @mssql_query('SET SHOWPLAN_TEXT ON;', $this->_hMaster);
     if ($hResult = @mssql_query($sQuery, $this->_hMaster)) {
         @mssql_next_result($hResult);
         while ($aRow = @mssql_fetch_row($hResult)) {
             list($bTable, $sData) = Phpfox_Debug::addRow($bTable, $aRow);
             $sHtml .= $sData;
         }
     }
     @mssql_query('SET SHOWPLAN_TEXT OFF;', $this->_hMaster);
     @mssql_free_result($hResult);
     if ($bTable) {
         $sHtml .= '</table>';
     }
     return $sHtml;
 }
Example #11
0
    			$sJs .= '\'' . $aAd['location'] . '\': \'' . str_replace("'", "\'", $aAd['html_code']) . '\',';
    		}
    		$sJs = rtrim($sJs, ',');
    		$sJs .= '}';
    	}
    * 
    */
    if (isset($_GET['js_mobile_version']) && $_GET['js_mobile_version']) {
        if (isset($_GET['req1']) && empty($_GET['req2'])) {
            Phpfox::getLib('ajax')->call('$(\'#mobile_search\').show();');
        } else {
            Phpfox::getLib('ajax')->call('$(\'#mobile_search\').hide();');
        }
    }
    Phpfox::getLib('ajax')->call('$Core.page({' . $sJs . '});');
    if (PHPFOX_DEBUG) {
        Phpfox::getLib('ajax')->call('$(\'#js_main_debug_holder\').html(\'' . Phpfox_Debug::getDetails() . '\');');
    }
    echo Phpfox::getLib('ajax')->getData();
} else {
    $oAjax = Phpfox::getLib('ajax');
    $oAjax->process();
    echo $oAjax->getData();
    if ($oAjax->bIsModeration == true) {
        echo '$(window).trigger("moderation_ended");';
    }
    if (!isset($_REQUEST['height']) && !isset($_REQUEST['width']) && !isset($_REQUEST['no_page_update'])) {
        // echo '$Core.updatePageHistory();';
    }
}
ob_end_flush();
Example #12
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;
 }
Example #13
0
 public function sqlReport($query)
 {
     $sHtml = '';
     $html_table = false;
     // Grab a plan table, any will do
     $sql = "SELECT table_name\n\t\t\t\t\tFROM USER_TABLES\n\t\t\t\t\tWHERE table_name LIKE '%PLAN_TABLE%'";
     $stmt = ociparse($this->_hMaster, $sql);
     ociexecute($stmt);
     $result = array();
     if (ocifetchinto($stmt, $result, OCI_ASSOC + OCI_RETURN_NULLS)) {
         $table = $result['TABLE_NAME'];
         // This is the statement_id that will allow us to track the plan
         $statement_id = substr(md5($query), 0, 30);
         // Remove any stale plans
         $stmt2 = ociparse($this->_hMaster, "DELETE FROM {$table} WHERE statement_id='{$statement_id}'");
         ociexecute($stmt2);
         ocifreestatement($stmt2);
         // Explain the plan
         $sql = "EXPLAIN PLAN\n\t\t\t\t\t\tSET STATEMENT_ID = '{$statement_id}'\n\t\t\t\t\t\tFOR {$query}";
         $stmt2 = ociparse($this->_hMaster, $sql);
         ociexecute($stmt2);
         ocifreestatement($stmt2);
         // Get the data from the plan
         $sql = "SELECT operation, options, object_name, object_type, cardinality, cost\n\t\t\t\t\t\tFROM plan_table\n\t\t\t\t\t\tSTART WITH id = 0 AND statement_id = '{$statement_id}'\n\t\t\t\t\t\tCONNECT BY PRIOR id = parent_id\n\t\t\t\t\t\t\tAND statement_id = '{$statement_id}'";
         $stmt2 = ociparse($this->_hMaster, $sql);
         ociexecute($stmt2);
         $row = array();
         while (ocifetchinto($stmt2, $row, OCI_ASSOC + OCI_RETURN_NULLS)) {
             list($html_table, $sData) = Phpfox_Debug::addRow($html_table, $row);
             $sHtml .= $sData;
         }
         ocifreestatement($stmt2);
         // Remove the plan we just made, we delete them on request anyway
         $stmt2 = ociparse($this->_hMaster, "DELETE FROM {$table} WHERE statement_id='{$statement_id}'");
         ociexecute($stmt2);
         ocifreestatement($stmt2);
     }
     ocifreestatement($stmt);
     if ($html_table) {
         $sHtml .= '</table>';
     }
     return $sHtml;
 }
Example #14
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];
 }
Example #15
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;
 }
Example #16
0
 /**
  * During development you may need to check how your queries are being executed and how long they are taking. This
  * routine uses MySQL's EXPLAIN to return useful information.
  *
  * @param string $sQuery MySQL query to check.
  * @return string HTML output of the information we have found about the query.
  */
 public function sqlReport($sQuery)
 {
     $sHtml = '';
     $sExplainQuery = $sQuery;
     if (preg_match('/UPDATE ([a-z0-9_]+).*?WHERE(.*)/s', $sQuery, $m)) {
         $sExplainQuery = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2];
     } elseif (preg_match('/DELETE FROM ([a-z0-9_]+).*?WHERE(.*)/s', $sQuery, $m)) {
         $sExplainQuery = 'SELECT * FROM ' . $m[1] . ' WHERE ' . $m[2];
     }
     $sExplainQuery = trim($sExplainQuery);
     if (preg_match('/SELECT/se', $sExplainQuery) || preg_match('/^\\(SELECT/', $sExplainQuery)) {
         $bTable = false;
         if ($hResult = @($this->_aCmd['mysql_query'] == 'mysqli_query' ? $this->_aCmd['mysql_query']($this->_hMaster, "EXPLAIN {$sExplainQuery}") : $this->_aCmd['mysql_query']("EXPLAIN {$sExplainQuery}", $this->_hMaster))) {
             while ($aRow = @$this->_aCmd['mysql_fetch_assoc']($hResult)) {
                 list($bTable, $sData) = Phpfox_Debug::addRow($bTable, $aRow);
                 $sHtml .= $sData;
             }
         }
         @$this->_aCmd['mysql_free_result']($hResult);
         if ($bTable) {
             $sHtml .= '</table>';
         }
     }
     return $sHtml;
 }
Example #17
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);
	}