Example #1
1
 /**
  * Read menu file. Parse xml and initializate menu.
  *
  * @param	menu		string 		Configuration file
  * @param	cacheFile	string		Name of file where parsed config will be stored for faster loading
  * @return	void
  */
 public function parseFile(RM_Account_iUser $obUser)
 {
     PROFILER_IN('Menu');
     $cacheFile = $this->_filepath . '.' . L(NULL) . '.cached';
     if ($this->_cache_enabled and file_exists($cacheFile) and filemtime($cacheFile) > filemtime($this->_filepath)) {
         $this->_rootArray = unserialize(file_get_contents($cacheFile));
     } else {
         #
         # Initializing PEAR config engine...
         #
         $old = error_reporting();
         error_reporting($old & ~E_STRICT);
         require_once 'Config.php';
         $conf = new Config();
         $this->_root = $conf->parseConfig($this->_filepath, 'XML');
         if (PEAR::isError($this->_root)) {
             error_reporting($old);
             throw new Exception(__METHOD__ . '(): Error while reading menu configuration: ' . $this->_root->getMessage());
         }
         $this->_rootArray = $this->_root->toArray();
         if ($this->_cache_enabled) {
             file_put_contents($cacheFile, serialize($this->_rootArray));
         }
     }
     $arr = array_shift($this->_rootArray);
     $arr = $arr['menu'];
     $this->_menuData['index'] = array();
     // index for branches
     $this->_menuData['default'] = array();
     // default selected block of menu
     $this->_menuData['tree'] = $this->formMenuArray($obUser, $arr['node']);
     $this->_menuData['branches'] = array();
     // tmp array, dont cached
     PROFILER_OUT('Menu');
 }
Example #2
0
 /**
  * Returns XML as string
  *
  * @return string
  */
 public function getXML()
 {
     PROFILER_IN('ajaxGetXML');
     $tmp = $this->_header->_createXml()->saveXML();
     PROFILER_OUT('ajaxGetXML');
     return $tmp;
 }
Example #3
0
function __autoload($class)
{
    PROFILER_IN('__autoload');
    #PROFILER_CNT('class',PROFILER_CNT('class',NULL)."; $class");
    @($GLOBALS["mem_req"] -= memory_get_usage());
    require_once rm_class2file($class);
    $GLOBALS["mem_req"] += memory_get_usage();
    PROFILER_OUT('__autoload');
}
Example #4
0
 public function download(RM_Map_iEngine $engine, $fp)
 {
     PROFILER_IN('download');
     $this->_initCurl(M('Map')->getUrl());
     $this->addGetParams($engine);
     $this->_curl->outputToFile($fp);
     $this->_curl->execute();
     PROFILER_OUT('download');
     return TRUE;
 }
Example #5
0
/**
 *	Shortcut for:
 *		RM_Url_Facade::getURL()
 *
 *	@param		string		$urlCode	Url code
 * 	@param 		mixed		$data		Url data (object, hash, scalar, ..)
 * 	@param 		hash|string	$args		Extra URL parameters (to add to query - second arg to Tools.web.makeUrl
 * 	@param		string		$extra		Options for Tools.web.makeUrl
 *  @param 		bool		$full
 *	@return		string
 */
function U($urlCode, $data = NULL, $args = NULL, $extra = NULL, $full = TRUE)
{
    static $u = NULL, $w = NULL;
    if (!$u) {
        $u = M('Url');
        $w = M('Tools')->web();
    }
    PROFILER_IN('U');
    $url = $u->getURL($urlCode, $data, $args, $full);
    if ($args) {
        $url = $w->makeUrl($url, $args, $extra);
    }
    PROFILER_OUT('U');
    return $url;
}
Example #6
0
 public function download(RM_Map_iEngine $engine, $fp)
 {
     $xml = $this->_initXml($engine);
     PROFILER_IN('download');
     PROFILER_IN('Download url request');
     $url = $this->_firstStep($xml);
     PROFILER_OUT('Download url request');
     if (!$url) {
         return M('Base')->null();
     }
     PROFILER_IN('Map request');
     $res = $this->_secondStep($url, $fp);
     PROFILER_OUT('Map request');
     PROFILER_OUT('download');
     return $res;
 }
Example #7
0
 protected function _exec($sth, $binds)
 {
     PROFILER_IN('db-exec');
     $time = microtime(true);
     $res = @$sth->execute($binds);
     $time = sprintf('%.5f', microtime(true) - $time);
     $slow = false;
     $slow_limit = floatval(@C('database.slow-query'));
     if ($slow_limit) {
         $slow = floatval($time) > $slow_limit;
     }
     $this->trace("({$time} sec) " . preg_replace('/\\s+/', ' ', $sth->queryString), $binds);
     if ($slow) {
         $this->trace("SLOW QUERY!({$time} sec) " . preg_replace('/\\s+/', ' ', $sth->queryString), $binds, true);
     }
     PROFILER_CNT('sql', PROFILER_CNT('sql', NULL) . "\n" . str_repeat("*", 100) . "\n[" . ($slow ? "SLOW][" : "") . $time . "]\n{$sth->queryString} \n" . print_r($binds, true) . "\n");
     PROFILER_OUT('db-exec');
     if (!$res) {
         $this->_throw($sth->errorInfo(), $sth->queryString, $binds);
     }
 }
Example #8
0
 /**
  * Puts data into cache.
  *
  * @param	string	$ns			Key namespace (read from config)
  * @param	string	$key		Key name
  * @param	mixed	$value		Value to put
  * @param	int		$expire		Expire in seconds. Default is detected from namespace (1 hour unless specified)
  * @return	bool				TRUE on success or FALSE on failure
  */
 public function put($ns, $key, $value, $expire = NULL)
 {
     PROFILER_IN('Cache-put');
     $this->_checkNs($ns);
     if (NULL === $expire) {
         $expire = lor($this->_keyNs[$ns]['expire'], $this->_defaultExpire);
     }
     if ($expire <= 0) {
         $this->clear($ns, $key);
         PROFILER_OUT('Cache-put');
         return TRUE;
     }
     $key = $this->_keyNs[$ns]['value'] . ':' . $key;
     $retval = memcache_set($this->_conn($ns), $key, $value, 0, $expire);
     PROFILER_OUT('Cache-put');
     return $retval;
 }
Example #9
0
function _prepareTemplate($template, array $params = array(), array $keys = NULL, $fetch = FALSE, $item = 'design')
{
    static $_templates;
    $ext = "phtml";
    $template = preg_replace('/\\.(php|phtml)$/i', '', $template);
    PROFILER_IN('template');
    PROFILER_IN("template-" . $template . "." . $ext);
    if (!isset($_templates)) {
        foreach (M('Config')->getList('cache.template') as $ar) {
            $_templates[$ar['name']]['time'] = $ar['time'];
            if (isset($ar['dep'])) {
                $arDep = explode(",", $ar['dep']);
                if (count($arDep) > 0) {
                    foreach ($arDep as $dep) {
                        $_templates[$ar['name']]['keys'][] = $dep;
                    }
                }
            }
        }
    }
    if (isset($_templates[$template]['keys'])) {
        foreach ($_templates[$template]['keys'] as $key) {
            if ($keys) {
                $ar =& $keys;
            } else {
                $ar =& $params;
            }
            switch ($key) {
                case 'perm':
                    // template is depended on permissions of current user
                    $ar['current_user_id'] = me()->id();
                    break;
                case 'lang':
                    // template is depended on current language
                    $ar['current_lang'] = L(NULL);
                    break;
                case 'host':
                    // template is depended on current host
                    $ar['current_host'] = $_SERVER['HTTP_HOST'];
                    break;
                case 'tz':
                    // template is depended on timezone
                    if (me()->id()) {
                        $tz = me()->getTimezoneOffset();
                    }
                    $ar['timezone'] = @$tz ? $tz : @C('timezone.default_offset');
                    break;
            }
        }
    }
    $cacheTime = intval(@$_templates[$template]['time']);
    $arPath = pathinfo($template . "." . $ext);
    if (!$cacheTime || C('cache.enable') == 0) {
        //echo '[NO CACHE] '.$template;
        $obj = M('Template');
    } else {
        //echo '[CACHE] '.$template;
        $obj = M('Cache')->memoize(M('Template'), array('cacheTime' => intval($cacheTime), 'dir' => M('Tools')->file()->prepareFilePath("/" . $arPath["dirname"] . "/" . $arPath["basename"] . "/"), 'keys' => $keys, 'methods' => array('fetch' => 'return', 'display' => 'output')));
    }
    $method = $fetch ? 'fetch' : 'display';
    $result = $obj->{$method}($template . "." . $ext, $item, $params);
    PROFILER_OUT("template-" . $template . "." . $ext);
    PROFILER_OUT('template');
    if ($method == "fetch") {
        return $result;
    }
}