public function __construct($source_http_path, $config = '') { if (empty($source_http_path)) { throw new \Exception('Empty path'); } $this->config = $this->readConfig($config); if (!isset($this->config['async'])) { $this->config['async'] = true; } $source_path = fx::path()->abs($source_http_path); if (!file_exists($source_path) || !is_file($source_path)) { throw new \Exception('File not found: ' . $source_path); } $this->source_http_path = $source_http_path; $source_path = realpath($source_path); $this->source_path = $source_path; $info = getimagesize($source_path); $info['width'] = $info[0]; $info['height'] = $info[1]; $info['imagetype'] = $info[2]; unset($info[0]); unset($info[1]); unset($info[2]); unset($info[3]); $this->info = $info; if (!isset(self::$_types[$info['imagetype']])) { // incorrect/unknown type pictures throw new \Exception('Wrong image type'); } $max_filesize = fx::config('image.max_filesize'); if ($max_filesize && filesize($source_path) > $max_filesize) { throw new \Exception('Image is too big (limit is ' . $max_filesize . ')'); } $this->info += self::$_types[$info['imagetype']]; }
public function __construct($params = null, $data = array()) { $this->data = $data; $this->mailer = new \PHPMailer(); $this->mailer->CharSet = 'utf-8'; if (!is_array($params)) { $params = array(); } if (!isset($params['from'])) { $from = fx::config('mail.from'); if (!$from) { $from = 'noreply@' . fx::env('host'); } $params['from'] = $from; } foreach (array('host', 'password', 'user', 'port') as $smtp_prop) { if (!isset($params['smtp_' . $smtp_prop]) && ($conf_prop = fx::config('mail.smtp_' . $smtp_prop))) { $params['smtp_' . $smtp_prop] = $conf_prop; } } $this->setParams($params); }
public function unsetServiceSession($item) { $key = fx::config()->SESSION_KEY; $data = $_SESSION[$key]; unset($data[$item]); $_SESSION[$key] = $data; }
public function offsetSet($offset, $value) { $offset_exists = array_key_exists($offset, $this->data); $offsets = $this->getAvailableOffsets(); $offset_type = null; if (isset($offsets[$offset])) { $offset_meta = $offsets[$offset]; $offset_type = $offset_meta['type']; } switch ($offset_type) { case self::OFFSET_LANG: $offset = $offset . '_' . fx::config('lang.admin'); break; case self::OFFSET_RELATION: $relation = $offset_meta['relation']; if ($relation[0] === Finder::BELONGS_TO && $value instanceof Entity) { $c_rel_field = $relation[2]; $value_id = $value['id']; if ($c_rel_field && $value_id) { $this[$c_rel_field] = $value_id; } } break; } if (!$this->is_loaded && $this->is_saved) { $this->data[$offset] = $value; return; } // use non-strict '==' because int values from db becomes strings - should be fixed if ($offset_exists && $this->data[$offset] == $value) { return; } if (!isset($this->modified_data[$offset])) { $this->modified_data[$offset] = isset($this->data[$offset]) ? $this->data[$offset] : null; $this->modified[] = $offset; } $this->data[$offset] = $value; }
public static function console($command) { ob_start(); $manager = new \Floxim\Floxim\System\Console\Manager(); $manager->addCommands(fx::config('console.commands')); $manager->addPath(fx::path()->abs('/vendor/Floxim/Floxim/System/Console/Command')); $manager->run($command); return ob_get_clean(); }
protected function acceptGzip() { if (!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { return false; } if (!fx::config('cache.gzip_bundles')) { return false; } return in_array('gzip', explode(",", $_SERVER['HTTP_ACCEPT_ENCODING'])); }
public function dump($params) { $dump_path = fx::config('dev.mysqldump_path'); if (!$dump_path) { return; } if (is_string($params)) { $params = array('file' => $params); } if (!$params['file']) { return; } $target_file = fx::path($params['file']); $params = array_merge(array('data' => true, 'schema' => true, 'add' => false, 'where' => false, 'tables' => array()), $params); $command = $dump_path . ' -u' . fx::config('db.user') . ' -p' . fx::config('db.password') . ' --host=' . fx::config('db.host'); $command .= ' ' . fx::config('db.name'); if (!$params['schema']) { $command .= ' --no-create-info'; } if (!$params['data']) { $command .= ' --no-data'; } $command .= ' --skip-comments'; if ($params['where']) { $command .= ' --where="' . $params['where'] . '"'; } foreach ($params['tables'] as $t) { $command .= ' ' . $this->replacePrefix('{{' . $t . '}}'); } $do_gzip = isset($params['gzip']) && $params['gzip'] || preg_match("~\\.gz\$~", $target_file); if ($do_gzip) { $target_file = preg_replace("~\\.gz\$~", '', $target_file); } $command .= ($params['add'] ? ' >> ' : ' > ') . $target_file; exec($command); if ($do_gzip && file_exists($target_file)) { $gzipped_file = $target_file . '.gz'; $gzipped = gzopen($gzipped_file, 'w'); $raw = fopen($target_file, 'r'); while (!feof($raw)) { $s = fgets($raw, 4096); gzputs($gzipped, $s, 4096); } fclose($raw); gzclose($gzipped); unlink($target_file); return $gzipped_file; } }
protected function entry() { $c_time = microtime(true); $memory = memory_get_usage(true); $backtrace = array_slice(debug_backtrace(), 4, 2); $meta = array('time' => $c_time - $this->start_time, 'passed' => $c_time - $this->last_time, 'memory' => $memory); $this->last_time = $c_time; if (isset($backtrace[0]['file'])) { $meta['file'] = $backtrace[0]['file']; $meta['line'] = $backtrace[0]['line']; } $caller = ''; if (isset($backtrace[1])) { if (isset($backtrace[1]['class'])) { $caller = $backtrace[1]['class']; $caller .= $backtrace[1]['type']; } if (isset($backtrace[1]['function'])) { $caller .= $backtrace[1]['function']; } } $meta['caller'] = $caller; $args = func_get_args(); $items = array(); $light_mode = fx::config('dev.debug_light'); foreach ($args as $a) { $type = gettype($a); if ($type == 'array' || $type == 'object') { if ($light_mode) { $a = '[' . ($type === 'object' ? get_class($a) : $type) . ']'; } else { $a = print_r($a, 1); } } $items[] = array($type, $a); } return array($meta, $items); }
function unzip($file, $dir) { $dir = trim($dir, '/') . '/'; $dir = fx::config()->DOCUMENT_ROOT . fx::config()->HTTP_FILES_PATH . $dir; $this->zipMkdir($dir); $zip_handle = zip_open($file); if (!is_resource($zip_handle)) { die("Problems while reading zip archive"); } while ($zip_entry = zip_read($zip_handle)) { $zip_name = zip_entry_name($zip_entry); $zip_dir = dirname(zip_entry_name($zip_entry)); $zip_size = zip_entry_filesize($zip_entry); if (preg_match("~/\$~", $zip_name)) { $new_dir_name = preg_replace("~/\$~", '', $dir . $zip_name); $this->zipMkdir($new_dir_name); chmod($new_dir_name, 0777); } else { zip_entry_open($zip_handle, $zip_entry, 'r'); if (is_writable($dir . $zip_dir)) { $fp = @fopen($dir . $zip_name, 'w'); if (is_resource($fp)) { @fwrite($fp, zip_entry_read($zip_entry, $zip_size)); @fclose($fp); chmod($dir . $zip_name, 0666); } } zip_entry_close($zip_entry); } } zip_close($zip_handle); return true; }