/** * Generate rules for mod rewrite htaccess * @return string */ public static function generate_rewrite_rules() { $dirs = \System\Composer::list_dirs(\System\Loader::DIR_REWRITE); foreach ($dirs as $dir) { $od = opendir($dir); $files = array(); while ($file = readdir($od)) { if (strpos($file, '.') !== 0) { $files[$file] = \System\File::read($dir . '/' . $file); } } ksort($files); } return implode("\n", $files); }
public function val_get() { if ($this->resolved_value) { $val = $this->resolved_value; } else { $val = $this->form()->input_value($this->name); } if (gettype($val) == 'string') { $val = \System\Json::decode($val); } if (is_array($val)) { if ($val['method'] == 'url') { $val = \System\File::fetch($val['url'])->temp()->unload(); $val->temp = false; $val->method = 'keep'; } else { if ($val['method'] == 'upload') { $file = $this->form()->request->post($val['upload']); $file = \System\File::from_tmp($file['tmp_name'], $val['name']); $file->temp(); $file->temp = false; $file->method = 'keep'; $file->mime = $val['mime']; $val = $file; } else { if ($val['method'] == 'save') { $file = \System\File::from_path($val['path']); $file->read_meta(); $val = $file; } else { if ($val['method'] == 'drop') { $val = null; } } } } } $this->resolved_value = $val; return $val; }
/** Force env or read it * @param string $env Environment name * @return void */ public static function set_env($env = null) { if (is_null($env)) { if (file_exists($ef = BASE_DIR . self::DIR_CONF_DIST . '/env')) { self::$env = trim(\System\File::read($ef)); } } else { self::$env = $env; } if (!defined("YACMS_ENV")) { define("YACMS_ENV", self::$env); } }
public function drop() { $this->clear_thumbs(); return parent::drop(); }
private static function resource_list_save($type, &$content) { $content = array_unique($content); $name = self::get_resource_list_name($content); $file = self::get_resource_list_path($type, $name); if (!file_exists($file)) { \System\File::put($file, implode(NL, $content)); } }
private function get_checksum() { if (!$this->md5_sum) { $this->md5_sum = md5(\System\File::read($p = $this->get_file_path())); } return $this->md5_sum; }
public static function save() { \System\File::put(BASE_DIR . self::FILE_ROUTES_CACHE, json_encode(array("routes" => self::$routes, "menu" => self::$menu, "cfg" => self::$cfg))); }
public function get_content() { return \System\File::read(BASE_DIR . $this->get_path()); }
/** * Update htaccess rules * @return bool */ public static function update_rewrite() { if (!\System\File::check($p = BASE_DIR . \System\Loader::FILE_REWRITE)) { $val = \System\File::put($p, \Helper\Htaccess::generate_rewrite_rules()); Status::report('info', "Rewrite rules refreshed"); return $val; } return true; }
/** Put data formatted in JSON to path * @param string $path * @param mixed $json * @return bool */ public static function put($path, $json) { return \System\File::put($path, json_encode($json)); }
/** * Add an asset to the container. * * The extension of the asset source will be used to determine the type of * asset being registered (CSS or JavaScript). If you are using a non-standard * extension, you may use the style or script methods to register assets. * * You may also specify asset dependencies. This will instruct the class to * only link to the registered asset after its dependencies have been linked. * For example, you may wish to make jQuery UI dependent on jQuery. * * @param string $name * @param string $source * @param array $dependencies * @param array $attributes * @return void */ public function add($name, $source, $dependencies = array(), $attributes = array()) { $type = File::extension($source) == 'css' ? 'style' : 'script'; return call_user_func(array($this, $type), $name, $source, $dependencies, $attributes); }
public static function get_schema() { static::check_model(); $attrs = array(); $schema = array(); $cname = get_called_class(); $list = static::get_attr_list(); foreach ($list as $name) { if ($name == static::get_id_col()) { continue; } $attr = static::get_attr($name); $attr['name'] = $name; switch ($attr['type']) { case 'bool': $attr['type'] = 'boolean'; break; case 'varchar': $attr['type'] = 'string'; break; case 'json': $attr['type'] = 'object'; break; case self::REL_HAS_ONE: $nm = $attr['model']; $attr['type'] = 'model'; $attr['subtype'] = 'has_one'; $attr['bound_to'] = static::get_rel_bound_to($name); break; case self::REL_BELONGS_TO: $attr['type'] = 'model'; break; case self::REL_HAS_MANY: $rm = $attr['model']; if (empty($attr['is_bilinear'])) { $attr['bound_to'] = static::get_rel_bound_to($name); $attr['foreign_key'] = $rm::get_belongs_to_id($attr['bound_to']); } else { $attr['foreign_key'] = static::get_id_col(); } $attr['type'] = 'collection'; break; } // Convert attribute model bindings if (isset($attr['model'])) { $attr['model'] = \System\Loader::get_model_from_class($attr['model']); } // Convert attribute value options if (isset($attr['options'])) { if (isset($attr['options'][0]) && $attr['options'][0] == 'callback') { $opts = $attr['options']; array_shift($opts); $opts = call_user_func($opts); } else { $opts = $attr['options']; } $attr['options'] = array(); foreach ($opts as $opt_value => $opt_name) { $attr['options'][] = array('name' => $opt_name, 'value' => $opt_value); } } // Word 'default' is keyword in some browsers, so pwf-models use 'def' instead if (isset($attr['default'])) { $attr['def'] = $attr['default']; unset($attr['default']); if (in_array($attr['type'], array('image'))) { $attr['def'] = \System\Image::from_path($attr['def'])->to_object(); } else { if (in_array($attr['type'], array('file', 'sound'))) { $attr['def'] = \System\File::from_path($attr['def'])->to_object(); } } } if (is_array($attr)) { unset($attr[0]); $attrs[] = $attr; } } if (any($cname::$conversions)) { $schema['conversions'] = $cname::$conversions; } $schema['attrs'] = $attrs; return $schema; }
/** * Get the code surrounding the line where the exception occurred. * * @return array */ public function context() { return File::snapshot($this->exception->getFile(), $this->exception->getLine()); }
public static function build_locales() { $cfg = \System\Settings::get('locales', 'allowed'); $loc = new \System\Locales(); foreach ($cfg as $lang) { $loc->load_messages($lang); \System\File::put(BASE_DIR . \System\Locales::DIR_CACHE . '/' . $lang . '.json', json_encode($loc->get_messages($lang))); } }