protected function preprocess($template, $name, $data) { parent::preprocess($template, $name, $data); $class_name = $this->css_class_name($name, $data); $parms = $template->parms; if (empty($parms['tagparms']['class']) || !Core_Strings::contains('mce', $parms['tagparms']['class'])) { $template->update_parm('tagparms', array('class' => (isset($parms['tagparms']['class']) ? $parms['tagparms']['class'] : '') . ' ' . $class_name)); } $template->update_parm('tagparms', array('id' => $name . '-' . $this->url_class())); }
/** * Возвращает объект адаптера соответствующего DSN * * @params DB_DSN $dsn объект строки DSN * * @throws DB_Exception Если отсутствует параметр type в строке DSN * * @return object */ public static function instantiate(DB_DSN $dsn) { $adapters = self::option('adapters'); if (isset($adapters[$dsn->type])) { $module = $adapters[$dsn->type]; $module = Core_Strings::contains('.', $module) ? $module : 'DB.Adapter.' . $module; Core::load($module); return Core::make($module . '.Connection', $dsn); } else { throw new DB_Exception("Missing adapter for type {$module}"); } }
/** * Запускает приложение * * @param array $argv * * @return int */ public function run(array $argv) { $cache = Cache::connect($this->config->dsn); if ($this->config->modules != null) { foreach (Core_Strings::split_by(',', $this->config->modules) as $v) { Core::load($v); } } foreach ($argv as $v) { IO::stdout()->write_line($v)->write_line(var_export($cache[$v], true)); } return 0; }
public function preprocess($file) { //TODO: to options $suffix = '.less'; if (Core_Strings::ends_with($file, $suffix)) { $file = Templates_HTML::css_path($file, false); $css_file = md5($file) . '.css'; $css_file = Templates_HTML_Preprocess::option('less_output_dir') . '/' . $css_file; //TODO: errors $this->compile('./' . $file, $css_file); return '/' . ltrim($css_file, '\\/.'); } return $file; }
/** * @param WS_Environment $env * * @return mixed */ public function run(WS_Environment $env) { $env->auth = Core::object(array('user' => null, 'module' => $this->auth_module)); $this->set_user($env); $uri = $env->request->url; try { $response = $this->application->run($env); } catch (WS_Auth_UnauthenticatedException $e) { $response = Net_HTTP::Response(Net_HTTP::UNAUTHORIZED); } catch (WS_Auth_ForbiddenException $e) { $response = Net_HTTP::Response(Net_HTTP::FORBIDDEN); } if ($response->status->code == Net_HTTP::UNAUTHORIZED) { return Net_HTTP::redirect_to(Core_Strings::replace($this->auth_url, '{url}', $uri)); } else { return $response; } }
public function use_file(array $file, $type = null) { $path = $file['name']; if (!Templates_HTML::path($type, $path)) { if (!is_null($type)) { $paths = Templates_HTML::option('paths'); $prefix = $paths[$type]; if (!Core_Strings::starts_with($path, $prefix)) { $path = $prefix . '/' . ltrim($path, '/'); } } $component = false; if ($file['component']) { $component = $file['component']; } $component_url = CMS::component_static_path($path, $component); $component_path = str_replace('file://', '', $component_url); if (is_file($component_path)) { $file['name'] = $component_url; } } return parent::use_file($file, $type); }
public function render_urls() { $res = array(); $base_path = realpath($_SERVER['DOCUMENT_ROOT']); foreach ($this->filelist($dir) as $file) { $real_path = realpath($file); $name = basename($file); if ($base_path && $real_path && Core_Strings::starts_with($real_path, $base_path)) { $res[$name] = '/' . trim($file, '\\/.'); } else { $res[$name] = '#'; } } return $res; }
/** * @abstract * * @param Net_HTTP_Request $request * @param OpenId_Client $client */ public function retrieve(Net_HTTP_Request $request, OpenId_Client $client) { $values = array(); $sreg_to_ax = array_flip(self::$ax_to_sreg); $schema_to_name = array_flip(array_merge($client->optional, $client->required)); $prefix = 'openid.sreg.'; foreach ($request->parameters as $k => $v) { if (Core_Strings::starts_with($k, $prefix) && ($name = substr($k, strlen($prefix))) && isset($sreg_to_ax[$name])) { $ax = $sreg_to_ax[$name]; $alias = $schema_to_name[$ax]; $values[$alias] = trim($this->is_date($ax, $v) ? Time::DateTime($v) : urldecode($v)); } } return $values; }
public static function flip_column($type) { $map = self::get_flip_columns_type_map(); $type = Core_Strings::upcase($type); $res = array(null, null); if (isset($map[$type])) { $res = explode(':', $map[$type]); } return $res; }
/** * Преобразует значение полученное из БД в нужный формат, для работы с ним в php * * @param DB_ColumnMeta $metadata * @param $value * * @return mixed */ public function cast_column(DB_ColumnMeta $metadata, $value) { switch (true) { case $metadata->type == 'date': return is_null($value) ? null : Time::parse($value); case $metadata->type == 'timestamp': return is_null($value) ? null : Time::parse($value); case Core_Strings::starts_with($metadata->type, '_'): $arr = array(); foreach (explode(',', Core_Strings::substr($value, 1, strlen($value) - 2)) as $element) { $arr[] = $this->cast_column(new DB_ColumnMeta($metadata->name, Core_Strings::substr($metadata->type, 1), $metadata->length, $metadata->precision), ltrim(rtrim($element, '"'), '"')); } return $arr; case Core_Strings::starts_with($metadata->type, 'int'): return (int) $value; case in_array($metadata->type, array('varchar', 'text')): return (string) $value; case in_array($metadata->type, array('numeric', 'double', 'float')): return (double) $value; default: return $value; } }
/** * Подгружает модуль * * @param string $module * * @return Core_ModuleLoader */ public function load($module) { if (!$this->is_loaded($module)) { $real_module_name = Core_Types::real_class_name_for($module); $this->mark_as_loaded($module); $cached_path = Core::cached_modules($module); if ($cached_path) { $loaded = true; //FIXME: if (!Core_Strings::starts_with($cached_path, '.') && !Core_Strings::starts_with($cached_path, '/')) { $cached_path = $this->paths['*'] . '/' . $cached_path; } include_once $cached_path; } else { $loaded = $this->load_module_file($file = $this->file_path_for($module, false), $real_module_name, $module); if ($file && $loaded) { Core::cached_modules($module, $file); } } if (Core::option('spl_autoload') && !$loaded) { return false; } if ($this->is_module($real_module_name)) { if (method_exists($real_module_name, 'initialize')) { call_user_func(array($real_module_name, 'initialize'), isset($this->configs[$module]) ? $this->configs[$module] : array()); } } else { throw new Core_InvalidModuleException($module); } } return Core::option('spl_autoload') ? true : $this; }
/** * Обработка вызовов методов установки значений опций * * @param string $method * @param array $args * * @return mixed */ public function __call($method, $args) { switch ($method) { case 'classname': return $this->option($method, (string) $args[0]); case 'column': $this->array_option('columns', (string) $args[0]); if (isset($args[1])) { $this->array_option('defaults', $args[1], $args[0]); } return $this; case 'validator': return $this->use_validator($args[0]); case 'table': return $this->option($method, explode(' ', (string) $args[0])); case 'columns': case 'exclude': case 'only': case 'key': foreach ((array) $args[0] as $v) { $this->array_option($method, (string) $v); } return $this; case 'defaults': foreach ((array) $args[0] as $k => $v) { $this->array_option($method, $v, $k); } return $this; case 'lookup_by': case 'search_by': return $this->option($method, (string) $args[0]); case 'explicit_key': return $this->option($method, (bool) $args[0]); case 'calculate': foreach ((array) $args[0] as $k => $v) { $alias = (string) $k; if (is_int($k)) { switch (true) { case Core_Strings::contains($v, ' '): $v = preg_replace('!\\sas\\s!i', ' ', $v); $parts = explode(' ', $v); $alias = array_pop($parts); $v = implode(' ', $parts) . ' as '; break; case preg_match('{[0-9a-zA-Z_]+\\.([0-9a-zA-Z_]+)}', $v, $m): $alias = $m[1]; break; default: $alias = $v; } } $this->array_option($method, $v, $alias, false); } return $this; case 'having': case 'where': return $this->array_option($method, (string) $args[0]); case 'order_by': case 'group_by': return $this->option($method, (string) $args[0]); case 'join': return $this->array_option('join', array((string) $args[0], (string) $args[1], (array) $args[2])); case 'range': return $this->option('range', array((int) $args[0], isset($args[1]) ? (int) $args[1] : 0)); case 'index': return $this->option('index', (string) $args[0]); case 'union': return $this->array_option($method, $args[0], $args[1]); default: return $this->option($method, $args[0]); } }
public function preprocess($file, $data) { $suffix = '.scss'; $content = null; if (Core_Strings::ends_with($file, $suffix)) { $this->load(); if (!$this->server) { return array($file, $content); } // TODO: move to function $file = Templates_HTML::css_path($file, false); $file_name = ltrim($file, '/\\.'); $scss_file = './' . ltrim($file, '/'); $css_file = str_replace('.scss', '.css', $file_name); $css_file = str_replace('styles/', '', $css_file); $css_file = './' . self::option('scss_output_dir') . '/' . $css_file; $css_file = str_replace('//', '/', $css_file); $dir = dirname($css_file); if (!IO_FS::exists($dir)) { IO_FS::mkdir($dir); } if ($this->server->needsCompile($scss_file, $css_file, $etag = '')) { $this->server->compile($scss_file, $css_file); } return array('/' . ltrim($css_file, '\\/.'), $content); } return array($file, $content); }
/** * @param Dev_Source_Module $module * @param Dev_Source_Check_Result $result */ public function run(Dev_Source_Module $module, Dev_Source_Check_Result $result) { $this->result = $result; $this->module = $module; try { $xml = Dev_Source::Library($module->name)->xml; set_error_handler(array($this, 'error_handler'), E_WARNING); $xml->relaxNGValidate('etc/tao-doc.rng'); restore_error_handler(); } catch (Dev_Source_InvalidSourceException $e) { foreach ($e->errors as $error) { $result->add_error($this, $module, Core_Strings::format("%s: %d : %s", $module->name, $error->line, $error->message)); } } }
/** * Проверяет установку значения свойства * * @param string $property * * @return boolean */ public function __isset($property) { switch ($property) { case 'link': case 'title': case 'description': case 'published_at': $m = $property . '_for'; return $this->protocol->{$m}($this->element) !== null; default: return isset($this->{$property}) || $this->get(Core_Strings::to_camel_case($property, true)) !== null; } }
protected function tag_attrs_filter($attr) { return Core_Strings::starts_with($attr, 'data-') || Core_Strings::starts_with($attr, 'on') || in_array($attr, $this->tag_attrs()); }
/** */ protected function output($result) { switch ($application = $this->config->application) { case 'dot': case 'neato': case 'fdp': case 'circo': case 'twopi': Proc::Pipe(Core_Strings::format('%s -T%s %s', $application, $this->config->format, $this->config->output ? ' -o ' . $this->config->output : ''), 'w')->write($result)->close(); break; default: throw new Dev_Diagram_Exception(Core_Strings::format('Unknown application (%s)', $application)); } }
public function action_url($action, $p = false, $args = false, $extra = false) { $res = parent::action_url($action, $p, $args, $extra); if ($this->default_action($action, $args) !== 'tree') { return $res; } $res = preg_replace('!/list!', '', $res); if (preg_match('!/page-(\\d+)!', $res, $m)) { $page = $m[1]; $res = str_replace('/page-' . $page, '', $res); $res .= (Core_Strings::contains($res, '?') ? '&' : '?') . "page={$page}"; } return $res; }
/** * @param $body * * @return string */ protected function format_body($body) { switch (true) { case is_array($body) && Core_Strings::contains($body[0], '%'): return vsprintf($body[0], array_slice($body, 1)); case is_object($body) && !method_exists($body, '__toString'): case is_array($body): return var_export($body, true); default: return (string) $body; } }
/** * Выполняет развертывание имени компонента * * @param string $name * * @return string */ protected function complete_name($name) { if (Core_Strings::ends_with($name, '.')) { $name = $name . WS_DSL::SUFFIX; } if (Core_Strings::starts_with($name, '.')) { $name = WS_DSL::PREFIX . $name; } return $name; }
public function filter() { foreach (Core::normalize_args(func_get_args()) as $arg) { $this->filters[str_replace('!', '', $arg)] = !Core_Strings::starts_with($arg, '!'); } return $this; }
/** * @param string $name * @param int $http_mask * @param string $path * @param string $formats * * @return WS_REST_DSL_Resource */ public function method($name, $http_mask = Net_HTTP::ANY, $path = null, $formats = null, $defaults = array()) { $formats = $formats === null ? isset($this->scope->formats) ? $this->scope->formats : array() : $formats; $path = $path === null ? isset($this->scope->path) ? $this->scope->path : 'index' : $path; $name = $name ? $name : $path; $http_mask = $http_mask === null ? isset($this->scope->http_methods) ? $this->scope->http_methods : Net_HTTP::ANY : $http_mask; $this->object->method(Core::with(new WS_Services_REST_Method($name))->path($path)->http($http_mask)->defaults($defaults)->produces(is_array($formats) ? $formats : Core_Strings::split_by(',', (string) $formats))); return $this; }
public function __call($method, $args) { switch ($method) { case 'columns': $this->set_columns($args); break; case 'offset': $this->{$method} = $args[0]; break; case 'from': case 'where': case 'having': case 'order_by': case 'group_by': foreach (Core_Arrays::flatten($args) as $arg) { $target =& $this->{$method}; $target[] = $arg; } break; case 'left_join': case 'right_join': case 'inner_join': case 'outer_join': $this->joins[] = array(Core_Strings::upcase(Core_Strings::replace($method, '_join', '')), Core_Arrays::shift($args), $args); break; } return $this; }
/** * @return mixed */ protected function get_classes() { if ($this->classes != null) { return $this->classes; } $this->classes = array(); foreach ($this->module->xml->getElementsByTagName('class') as $k => $v) { $name = $v->getAttribute('name'); $this->classes[$name] = $this->ref . '#c-' . Core_Strings::replace($name, '.', '-'); } return $this->classes; }
public function __call($method, $args) { if (Core_Strings::ends_with($method, '_cache')) { $method = str_replace('_cache', '', $method); //TODO: to Core::call if (version_compare(PHP_VERSION, '5.3.0') >= 0) { $call = array('parent', '__call'); } else { $call = array($this, 'parent::__call'); } return $this->cached_call($this->helper_cache_key($method, $args), $call, array($method, $args)); } return parent::__call($method, $args); }
/** * @param string $path * * @return string */ protected function module_name($path) { return Core_Strings::replace(Core_Strings::replace(Core_Strings::replace($path, $this->path . "/", ''), '.php', ''), '/', '.'); }
/** * @param string $method * @param array $parms * * @return mixed */ public function __call($method, $args) { try { return $this->delay()->soap->__call(ucfirst(Core_Strings::to_camel_case($method)), $args); } catch (SoapException $e) { if (Service_Yandex_Direct::supress_exceptions()) { $this->last_error = $e; return null; } else { throw $e; } } }
protected function entity_reflection() { if ($this->entity_reflection) { return $this->entity_reflection; } $this->entity_reflection = Core_Types::reflection_for(Core_Strings::replace($this->entity, '.', '_')); return $this->entity_reflection; }
/** * @param string $type * @param string $url * @param array $options * * @return string */ public function auto_discovery_link_tag($t, $type, $url, array $options = array()) { return $t->tags->tag('link', array('rel' => $options['rel'] ? $options['rel'] : 'alternate', 'type' => $options['type'] ? $options['type'] : "application/{$type}+xml", 'title' => $options['title'] ? $options['title'] : Core_Strings::upcase($type), 'href' => $url)) . "\n"; }
public function get($url = '', $parms = null) { $encoded = $this->encode_parameters($parms); return $this->url($url . ($encoded ? (Core_Strings::contains($url, '?') ? '&' : '?') . $encoded : ''))->exec_with_options(array(CURLOPT_HTTPGET => 1)); }