public static function profiler() { static $profiler = null; if (is_null($profiler)) { $profiler = new Profiler(); self::debug()->onStop(function () use($profiler) { if ($profiler->hasData()) { fx::log('%raw%' . $profiler->show(), $profiler->getSortedTags(), $profiler); } }); } return $profiler; }
public function save($target_path = false, $params = null) { if (isset($params)) { $params = $this->readConfig($params); } else { $params = $this->config; } $params = array_merge(array('quality' => 90), $params); $type_props = null; if (isset($params['type'])) { $type_props = self::imageTypeByPath('pic.' . $params['type']); } elseif ($target_path) { $type_props = self::imageTypeByPath($target_path); } if ($type_props && $type_props['type'] !== $this->info['imagetype']) { $image_type = $type_props['type']; $save_function = $type_props['save_func']; } else { $image_type = $this->info['imagetype']; $save_function = $this->info['save_func']; } $quality = $params['quality']; if ($image_type == IMAGETYPE_PNG) { //$quality = 10 - round($quality / 10); // this is not 'quality', but a compression level, the more is value the less is filesize // png compression is always lossles $quality = 9; } $output = isset($this->config['output']); if ($target_path === false) { $target_path = $this->source_path; } elseif ($target_path === null || $output) { header("Content-type: " . $this->info['mime']); ob_end_clean(); } else { fx::files()->mkdir(dirname($target_path)); } if (!$this->image) { $this->loadImage(); } if ($save_function === 'imagejpeg') { imageinterlace($this->image, true); } // Save to file call_user_func($save_function, $this->image, $target_path, $quality); // Output to browser if ($output && $target_path !== null) { fx::log('sending'); call_user_func($save_function, $this->image, null, $quality); } }
<?php ini_set('display_errors', 'off'); try { require_once 'boot.php'; $result = fx::router()->route(); if (fx::env('ajax')) { $result = fx::page()->ajaxResponse($result); } echo $result; fx::complete(); } catch (\Exception $e) { fx::log($e, $e->getTraceAsString()); if (!fx::env('ajax') || fx::env('console')) { fx::debug($e, $e->getTraceAsString()); } }
public function query($statement) { self::$q_count++; $start_time = microtime(true); $statement = $this->prepareQuery($statement); // determine the type of request // but what for??? /* preg_match("/^([a-z]+)\s+/i", $statement, $match); $this->query_type = strtolower($match[1]); * */ $this->last_result = parent::query($statement); $this->num_queries++; $this->last_query = $statement; if (!$this->last_result) { $this->last_error = $this->errorInfo(); fx::log('sql error', $this->last_error, microtime(true), $statement, debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)); throw new \Exception("Query: " . $statement . "\n" . "Error: " . $this->last_error[2]); } $trace_rex = fx::config('dev.log_sql_backtrace'); if ($trace_rex) { if ($trace_rex[0] === '~' && preg_match($trace_rex, $statement)) { fx::log($trace_rex, debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)); } elseif (strstr($statement, $trace_rex)) { fx::log($trace_rex, debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)); } } if (!fx::config('dev.log_sql')) { return $this->last_result; } $end_time = microtime(true); $q_time = $end_time - $start_time; self::$q_time += $q_time; fx::log('#' . self::$q_count, 'q_time: ' . $q_time, 'q_total: ' . self::$q_time, microtime(true), $statement); return $this->last_result; }
/** * Load options from DB */ public function loadFromDb() { try { $options = fx::data('option')->all(); foreach ($options as $option) { $this->set($option['keyword'], $option['value']); } } catch (\Exception $e) { fx::log('Error while loading options: ', $e); } }
public function addCssBundle($files, $params = array()) { if (!isset($params['name'])) { $params['name'] = md5(join($files)); } $params['name'] .= '.css.gz'; $http_path = fx::path()->http('@files/asset_cache/' . $params['name']); $full_path = fx::path()->abs($http_path); $last_modified = 0; $less_flag = false; $files = array_unique($files); foreach ($files as $file) { if (preg_match("~\\.less\$~", $file)) { $less_flag = true; } if (!preg_match("~^http://~i", $file)) { $file_path = fx::path()->abs($file); if (file_exists($file_path)) { $c_modified = filemtime($file_path); if ($c_modified > $last_modified) { $last_modified = $c_modified; } } } } if (!file_exists($full_path) || filemtime($full_path) < $last_modified) { $file_content = ''; foreach ($files as $file) { if (preg_match("~^http://~i", $file)) { $file_contents = file_get_contents($file); } else { $http_base = fx::path()->http($file); $http_base = preg_replace("~[^/]+\$~", '', $http_base); $c_abs = fx::path()->abs($file); if (file_exists($c_abs)) { $file_contents = file_get_contents($c_abs); $file_contents = $this->cssUrlReplace($file_contents, $http_base); $file_contents = $this->lessImportUrlReplace($file_contents, $http_base); } } $file_content .= $file_contents . "\n"; } if ($less_flag) { $less = $this->getLessCompiler(); $less->setImportDir(DOCUMENT_ROOT); try { $file_content = $less->compile($file_content); } catch (\Exception $e) { fx::log('Less error while adding bundle', $e->getMessage(), $file_content, $files); $file_content = ''; } } $plain_path = preg_replace("~\\.css\\.gz\$~", ".css", $full_path); // directory should be created here: fx::files()->writefile($plain_path, $file_content); $fh = gzopen($full_path, 'wb5'); gzwrite($fh, $file_content); gzclose($fh); } if (!$this->acceptGzip()) { $http_path = preg_replace("~\\.css\\.gz\$~", ".css", $http_path); } $this->files_css[] = $http_path; }