示例#1
0
 function addQuery($sql)
 {
     if (!\Radical\Core\Server::isProduction() && $this->explain) {
         $this->queries[] = $sql;
         $this->backtraces[] = debug_backtrace(false);
     }
 }
 /**
  * Handle GET request
  *
  * @throws \Exception
  */
 function GET()
 {
     $key = static::EXTENSION . '_' . $this->name . '_' . $this->version;
     $files = $this->getFiles();
     $this->sendHeaders($files);
     $cache = PooledCache::Get(get_called_class(), 'Memory');
     $ret = $cache->get($key);
     if (!$ret || !\Radical\Core\Server::isProduction()) {
         $data = array();
         foreach ($files as $f) {
             if (is_file($f)) {
                 //Ignore folders
                 $fn = basename($f);
                 $data[$fn] = Individual::get_file($f);
             }
         }
         $ret = '';
         foreach ($data as $f => $d) {
             if (!\Radical\Core\Server::isProduction()) {
                 $ret .= "\r\n/* Including: " . $f . " */\r\n";
             }
             $ret .= $d;
         }
         if (\Radical\Core\Server::isProduction()) {
             $ret = $this->optimize($ret);
             $cache->set($key, $ret);
         }
     }
     echo $ret;
     $headers = \Radical\Web\Page\Handler::top()->headers;
     $headers->setContentLength(strlen($ret));
     $headers['Vary'] = 'Accept-Encoding';
 }
 static function HTML($name)
 {
     $path = Server::getSiteRoot();
     if (ResourceConfig::$addCachePrefixJs && static::PATH == 'js' || ResourceConfig::$addCachePrefixCss && static::PATH == 'css') {
         $path .= ResourceConfig::$addCachePrefix . '/';
     }
     $path .= $name . '.' . static::FileTime($name) . '.' . static::PATH;
     return static::_HTML($path);
 }
 function __construct($is_cli = null)
 {
     if ($is_cli === null) {
         $is_cli = \Radical\Core\Server::isCLI();
     }
     if ($is_cli) {
         $c = self::CLI_HANDLER;
     } else {
         $c = self::WEB_HANDLER;
     }
     $this->handler = new $c();
 }
 function __construct(\Bugsnag_Client $client, $is_cli = null)
 {
     if ($is_cli === null) {
         $is_cli = \Radical\Core\Server::isCLI();
     }
     if ($is_cli) {
         $c = self::CLI_HANDLER;
     } else {
         $c = self::WEB_HANDLER;
     }
     $this->client = $client;
     $this->handler = new $c($this);
 }
示例#6
0
 /**
  * @param string $sql
  * @return Table\CacheableTableSet|Table\TableSet|static[]
  */
 static function getAll($sql = '')
 {
     if (\Radical\Core\Server::isCLI()) {
         return parent::getAll($sql);
     }
     $obj = static::_getAll($sql);
     $cached = Table\TableCache::Get($obj);
     if ($cached) {
         return $cached;
     } else {
         return new Table\CacheableTableSet($obj, get_called_class());
     }
 }
示例#7
0
 /**
  * Get the users IP
  * 
  * @return \Radical\Utility\Net\IP
  */
 static function IP()
 {
     if (\Radical\Core\Server::isCLI()) {
         return new IP(static::DEFAULT_IP);
     }
     if (isset($_SERVER['HTTP_X_REAL_IP'])) {
         return new IP($_SERVER['HTTP_X_REAL_IP']);
     }
     if (isset($_SERVER['REMOTE_ADDR'])) {
         return new IP($_SERVER['REMOTE_ADDR']);
     }
     return new IP(static::DEFAULT_IP);
 }
 static function handler($errno, $msg_text, $errfile, $errline)
 {
     if (!(error_reporting() & $errno)) {
         return true;
     }
     if (!($errno & E_STRICT)) {
         //E_STRICT, well we would like it but not PEAR
         if ($errno & E_WARNING && preg_match('/^Declaration of .+ should be compatible with/', $msg_text)) {
             return true;
         }
         new static($errno, $msg_text, new Structs\LocationReference($errfile, $errline));
         return Server::isProduction();
     }
     return true;
 }
 function __construct(\Exception $ex, $fatal = true)
 {
     $this->ex = $ex;
     //Build Error page
     if (!\Radical\Core\Server::isCLI() && \Radical\Core\Server::isProduction()) {
         $message = 'An exception has occurred in the script.';
         global $_ADMIN_EMAIL;
         if (isset($_ADMIN_EMAIL)) {
             $message .= ' Please report this to an administrator at ' . $_ADMIN_EMAIL . '.';
         }
     } else {
         $message = 'An exception occurred at ' . $ex->getFile() . '@' . $ex->getLine() . ': ' . $ex->getMessage();
     }
     $header = sprintf(static::HEADER, ltrim(get_class($ex), '\\'));
     parent::__construct($message, $header, $fatal, $ex);
 }
示例#10
0
 static function render($file)
 {
     $ext = pathinfo($file, PATHINFO_EXTENSION);
     $bn = basename($file);
     if ($bn[0] == '_') {
         return '';
     }
     // Importable packages
     global $BASEPATH;
     $sass_path = $BASEPATH . '/static/img/sprites/';
     $options = array('style' => 'nested', 'cache' => false, 'syntax' => $ext, 'debug' => false, 'load_paths' => array($sass_path), 'functions' => self::getFunctions(array('Compass', 'Own')), 'extensions' => array('Compass', 'Own'));
     if (\Radical\Core\Server::isProduction()) {
         $options['style'] = 'compressed';
     }
     // Execute the compiler.
     $parser = new \SassParser($options);
     return $parser->toCss($file);
 }
示例#11
0
 public function getColoredString($string, $foreground_color = null, $background_color = null)
 {
     if (\Radical\Core\Server::isWindows()) {
         //TODO: console parsable
         return $string;
     }
     $colored_string = "";
     // Check if given foreground color found
     if (isset($this->foreground_colors[$foreground_color])) {
         $colored_string .= "[" . $this->foreground_colors[$foreground_color] . "m";
     }
     // Check if given background color found
     if (isset($this->background_colors[$background_color])) {
         $colored_string .= "[" . $this->background_colors[$background_color] . "m";
     }
     // Add string and end coloring
     $colored_string .= $string . "";
     return $colored_string;
 }
示例#12
0
 static function init()
 {
     self::$pool = \Radical\Cache\PooledCache::get('radical_orm', 'Memory');
     global $_SQL;
     $cfile = '/tmp/' . $_SQL->getDb();
     if (file_exists($cfile) && filemtime($cfile) >= time() - 30) {
         self::$key = file_get_contents($cfile);
     } else {
         touch($cfile);
         $sql = 'SELECT MAX(UNIX_TIMESTAMP( CREATE_TIME )) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = "' . $_SQL->getDb() . '"';
         self::$key = \Radical\DB::Q($sql)->Fetch(Fetch::FIRST);
         file_put_contents($cfile, self::$key);
     }
     if (Server::isProduction()) {
         self::$data = self::$pool->get($_SQL->getDb() . '_' . self::$key);
         register_shutdown_function(function () {
             Cache::save();
         });
     }
     if (!is_array(self::$data)) {
         self::$data = array();
     }
 }
示例#13
0
 /**
  * Convert an object or string reference to a URL that will work.
  * 
  * @param mixed $object
  * @throws \Exception
  * @return string
  */
 function url($object, $param = null)
 {
     if (is_object($object)) {
         $object = $object->toURL($param);
     }
     if (!is_string($object)) {
         throw new \Exception('Unknown type to URLify: ' . gettype($object));
     }
     //Check for a full 'schemed' URL
     $first_part = substr($object, 0, 6);
     if ($first_part == 'http:/' || $first_part == 'ftp://' || $first_part == 'https:') {
         return $object;
         //URL is full
     }
     //Is relative? Make siterooted
     if ($first_part[0] != '/') {
         $object = \Radical\Core\Server::getSiteRoot() . $object;
     }
     return $object;
 }
示例#14
0
 function __construct()
 {
     $this->is_cli = Server::isCLI();
     parent::__construct();
 }