protected function component_class($name) { $name = trim($name); $name = strtolower($name); if (isset(self::$components_classes[$name])) { return self::$components_classes[$name]; } if (CMS::component_exists($name) || $name[0] == '_') { $lang = CMS::site_lang(); $lang = ucfirst($lang); if ($m = Core_Regexps::match_with_results('{^_(.+)$}', $name)) { $name = trim($m[1]); $module = 'CMS.Lang.' . ucfirst($name) . '.' . $lang; } else { $module = CMS::$component_module_prefix[$name] . ".Lang.{$lang}"; } $class = str_replace('.', '_', $module); try { @Core::load($module); } catch (Core_ModuleNotFoundException $e) { return false; } if (!class_exists($class)) { return false; } $object = new $class(); self::$components_classes[$name] = $object; return $object; } return false; }
/** $schema -- массив или лубой другой итерируемый объект * Ключи являются именами таблиц. * Значения -- массивы , которые могут содержать следующие ключи: * - 'description': описание таблицы, пока не поддерживается * - 'mysql_engine', 'mysql_engine': параметры специфичные для MySQL * - 'columns': массив массив, каждый из которых описывает колонку. * Колонка: * - 'description': описание * - 'name': имя колонки, * - 'mysql_definition', 'pgsql_definition' ... : строка определени колонки, если задано, то все последющие опции игнорируются * - 'type': Тип: 'char', 'varchar', 'text', 'blob', 'int', 'timestamp', 'datetime', 'date', 'time' * 'float', 'numeric', or 'serial'. Используйте 'serial' для auto incrementing * колонок, для MySQL это аналогично 'INT auto_increment'. * - 'mysql_type', 'pgsql_type', 'sqlite_type', etc.: тип специфичный для конкретной БД. * - 'size': Размер: 'tiny', 'small', 'medium', 'normal', * 'big'. Аналогично TINYINT TINYTEXT и т.д. в MySQL * - 'not null': По умолчанию false * - 'default': Значение по умолчанию для колонки * - 'default_quote': помещать ли значение по умоляанию в кавычки. По умолчанию, если * default строка, то true. * - 'length': Длина для таких типов как 'char', 'varchar' or 'text' * - 'unsigned': По умолчанию false * - 'precision', 'scale': Для типа 'numeric' * Обязательные параметры name и type * - 'indexes' массив массивов описывающие индексы. * Каждый индекс может содержать * - 'name': имя индекса * - 'type': тип: null, primary key, unique, fulltext * - 'columns': массив колонок входящих в индекс, * каждая может быть строкой с именем колонки или массивом, первый элемент которого имя, а второй длина * * DB_Schema::process( * array( * 'test2' => array( * 'mysql_engine' => 'MyISAM', * 'columns' => array( * array('name' => 'id', 'type' => 'serial'), * array('name' => 'title', 'type' => 'varchar', 'length' => 255, 'default' => '', 'not null' => true), * array('name' => 'body', 'type' => 'text', 'size' => 'big', 'default' => '', 'not null' => true), * ), * 'indexes' => array( * array('type' => 'primary key', 'columns' => array('id')), * array('name' => 'title', 'columns' => array('title')) * ) * ) * ), * $db * ); */ public static function process($schema, $connection = null, $force_update = false, $cache = null) { if (is_null($connection)) { Core::load('WS'); } $rc = true; foreach ($schema as $table_name => $table_data) { $conn = !is_null($connection) ? $connection : WS::env()->orm->session->connection_for($table_name); if (!$conn) { return false; } $table = self::table($conn)->for_table($table_name)->for_data($table_data); if ($cache) { $key = 'schema:' . $table_name; $value = md5(serialize($table_data)); if ($cache->get($key) != $value) { $rc = $table->execute($force_update) && $rc; $cache->set($key, $value, 0); } } else { $rc = $table->execute($force_update) && $rc; } } return $rc; }
static function load($filename) { self::$stream = IO_FS::FileStream($filename); while ($line = self::get()) { $line = trim($line); if ($m = Core_Regexps::match_with_results('{^!DUMP\\s+([^\\s]+)(.*)$}', $line)) { $module = trim($m[1]); $parms = trim($m[2]); $dumper = trim(self::$dumpers[$module]); if ($dumper == '') { throw new CMS_Dumps_UnknownDumperException("Unknown dumper: {$module}"); } $dumper_class_name = str_replace('.', '_', $dumper); if (!class_exists($dumper_class_name)) { Core::load($dumper); } $class = new ReflectionClass($dumper_class_name); $class->setStaticPropertyValue('stream', self::$stream); $method = $class->getMethod('load'); $rc = $method->invokeArgs(null, array($parms)); if (trim($rc) != '') { return $rc; } } } return true; }
public function dump($parms) { $component = trim($parms['component']); Core::load('CMS.Dumps.Vars'); CMS_Dumps_Vars::dump($component); die; }
public function action($name, $data, $action, $item = false) { $c = CMS::$current_controller; $item_id = $item ? $item->id() : 0; if (isset($_GET['filename'])) { $filename = $_GET['filename']; $filename = str_replace('..', '', $filename); $path = CMS::temp_dir() . '/' . $filename; } if ($action == 'temp') { if (!IO_FS::exists($path)) { return false; } Core::load('Net.HTTP'); return Net_HTTP::Download($path, false); } if ($action == 'delete') { if (IO_FS::exists($path)) { IO_FS::rm($path); } return 'ok'; } if ($action == 'info') { if ($filename == 'none') { return 'ok'; } return $this->render($name, $data, 'info-ajax.phtml', array('file_path' => $path, 'file_url' => $c->field_action_url($name, 'temp', $item, array('filename' => str_replace('/', '', $filename))), 'name' => $name)); } if ($action == 'upload') { return $this->action_upload($name, $data, $action, $item); } return false; }
/** * Устанавливает локаль * * @param string $lang * * @return L10N_LocaleInterface */ public static function locale($lang = null) { if ($lang !== null) { Core::load($module = 'L10N.' . strtoupper($lang)); self::$locale = Core::make("{$module}.Locale"); } return self::$locale; }
public function preview() { CMS::layout_view()->use_scripts('/tao/scripts/admin/vars/image.js'); Core::load('CMS.Images'); $url = CMS_Images::modified_image('./' . $this['image'], '150x150'); $id = 'container-' . md5($this['image']); return "<span class='var-image-preview' data-image='{$url}' data-container='{$id}'>[Image]</span>"; }
/** * Запускает CLI-приложение * * @param array $argv */ public static function run_module(array $argv) { Core::load($argv[0]); if (Core_Types::reflection_for($module = Core_Types::real_class_name_for($argv[0]))->implementsInterface('CLI_RunInterface')) { return call_user_func(array($module, 'main'), $argv); } else { throw new CLI_NotRunnableModuleException($argv[0]); } }
/** * put your comment there... * * @param string $tpl * @param string $class * @return BaseLayout */ static function layout($tpl = null, $class = 'Layout') { if ($tpl !== null) { Core::load($class, Core::kFTLayout); // include kFWCorePath.'/layouts/'.$class.kPhpExt; self::$_layout = new $class($tpl, App::config()); } return self::$_layout; }
/** * Запускает приложение * * @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; }
protected function process_format($code, $value, $format) { if (empty($format['output'])) { return $value; } if (Core_Types::is_callable($format['output'])) { return Core::invoke($format['output'], array($value)); } if (is_string($format['output']) || is_array($format['output'])) { Core::load('Text.Process'); return Text_Process::process($value, $format['output']); } return $value; }
static function format($css) { if (preg_match('|^' . preg_quote(CSS_PATCHED_FLAG, '|') . '|', $css)) { return $css; } $mini = Config::get('page.css_minify'); Core::load(THIRD_BASE, 'cssp', 'system'); if (class_exists('CSSP', false)) { $mode = CSSP::FORMAT_NOCOMMENTS; if ($mini) { $mode |= CSSP::FORMAT_MINIFY; } return CSS_PATCHED_FLAG . "\n" . CSSP::fragment($css)->format($mode); } }
/** * @param array $config */ static function initialize($config = array()) { self::$files_dir = './' . Core::option('files_name') . '/vars'; foreach ($config as $key => $value) { self::${$key} = $value; } Core::load('CMS.Vars.Types'); if (self::$type == 'orm') { Core::load('CMS.Vars.ORM'); WS::env()->orm->submapper('vars', 'CMS.Vars.ORM.Mapper'); } if (self::$type == 'storage') { Core::load('Storage'); Storage::manager()->add('vars', 'CMS.Vars.Storage'); } CMS::cached_run('CMS.Vars.Schema'); self::register_type('CMS.Vars.Types.Dir', 'CMS.Vars.Types.Integer', 'CMS.Vars.Types.String', 'CMS.Vars.Types.Text', 'CMS.Vars.Types.Html', 'CMS.Vars.Types.Array', 'CMS.Vars.Types.Mail', 'CMS.Vars.Types.HtmlP', 'CMS.Vars.Types.File'); CMS_Dumps::dumper('VARS', 'CMS.Dumps.Vars'); }
<?php /** * @package Storage\File\Export */ Core::load('Storage.File'); class Storage_File_Export implements COre_ModuleInterface { const VERSION = '0.0.0'; public static function storage($path = null) { if (is_null($path)) { return new Storage_File_Export_Type(); } return new Storage_File_Export_Type($path); } } class Storage_File_Export_Type extends Storage_File_Type { public function read($file) { if (is_file($file)) { $res = (include $file); return $res; } return null; } public function write($file, $data) { $res = var_export($data, true); $res = "<?php\n/**\n * @package Storage\\File\\Export\n */\n return \n {$res} ;";
<?php /** * Service.Yandex.Direct * * @package Service\Yandex\Direct * @version 0.3.0 */ Core::load('SOAP'); /** * @package Service\Yandex\Direct */ class Service_Yandex_Direct implements Core_ModuleInterface { const VERSION = '0.3.0'; protected static $options = array('delay' => 5, 'default_wsdl' => 'https://api.direct.yandex.ru/wsdl/v4/', 'wsdl' => 'https://api.direct.yandex.ru/wsdl/v4/'); private static $api; private static $supress_exceptions = false; /** * Выполняет инициализацию модуля * * @param array $options */ public static function initialize(array $options = array()) { return self::options($options); } /** * Устанавливает значения списка опций, возвращает список значений всех опций * * @param array $options
<?php /** * @package CMS\Fields\Types\TreeSelect */ Core::load('CMS.Fields.Types.Select'); class CMS_Fields_Types_TreeSelect extends CMS_Fields_AbstractField implements Core_ModuleInterface { const VERSION = '0.0.0'; public function view_value($value, $name, $data) { $value = parent::view_value($value, $name, $data); if (isset($data['items'])) { $items = CMS::items_for_select($data['items']); $outs = $this->process_items($items, $data); $value = $outs[1][$value]; } return $value; } protected function stdunset($data) { $res = parent::stdunset($data); return $this->punset($res, 'text-wrap', 'flat', 'level_up', 'create_tree', 'container_style', 'empty_value'); } protected function layout_preprocess($l, $name, $data) { $id = $this->url_class(); $code = "; \$(function() { \$('.{$id} div.tree_select').filter('.name_{$name}').each(\n\t\t\t\t\tfunction() {\n\t \t\t\t\t\tTAO.fields.tree_select(\$(this));\n\t\t\t\t\t\t}\n\t\t)});"; $l->append_to('js', $code); $l->with('url_class', $id); $l->use_scripts(CMS::stdfile_url('scripts/fields/tree-select.js'));
<?php /** * OpenId * * @package OpenId * @version 0.1.0 */ Core::load('Net.HTTP', 'XML'); /** * @package OpenId */ class OpenId implements Core_ModuleInterface { const VERSION = '0.1.0'; /** * @param Net_HTTP_Request $request * @param mixed $agent * * @return OpenId_Client */ static function Client($request = null, $agent = null) { return new OpenId_Client($request, $agent); } /** */ static function Version1() { return new OpenId_Version1(); }
/** * Фабричный метод, возвращает объект класса Templates.JSON.Template * * @param string $name * * @return Templates_JSON_Template */ public static function JSON($name) { Core::load('Templates.JSON'); return new Templates_JSON_Template($name); }
<?php /** * @package CMS\Fields\Types\Wiki */ Core::load('CMS.Fields.Types.HTML', 'CMS.Redactor'); class CMS_Fields_Types_Wiki extends CMS_Fields_Types_HTML implements Core_ModuleInterface { protected $default_editor = 'epic'; protected $fallback_editor = 'textarea'; protected function get_editor($name, $data) { if (isset($data['redactor'])) { return CMS_Redactor::get_editor($data['redactor']); } $main = CMS_Redactor::get_editor($this->default_editor); return $main->is_installed() ? $main : CMS_Redactor::get_editor($this->fallback_editor); } }
<?php /** * @package DB\ORM\Mappers */ Core::load('DB.ORM'); class DB_ORM_Mappers implements Core_ModuleInterface { const VERSION = '0.1.0'; protected static $set; public static function set() { return !empty(self::$set) ? self::$set : (self::$set = new DB_ORM_Mappers_Set()); } } class DB_ORM_Mappers_Set extends DB_ORM_ConnectionMapper { protected function setup() { return $this->submappers(array('information' => 'Information.*'), 'DB.ORM.Mappers.'); } }
public function action($name, $data, $action, $item = false) { $code = $this->request('code'); $dir = $this->dir_path($item, $code, $name, $data); if ($action == 'delete') { return $this->action_delete($name, $data, $action, $item); } if ($action == 'download') { $file = $this->request('file'); $path = "{$dir}/{$file}"; if (!IO_FS::exists($path)) { return false; } Core::load('Net.HTTP'); return Net_HTTP::Download($path, false); } if ($action == 'reload') { $t = $this->create_template($name, $data, 'files'); return $t->with(array('type_object' => $this, 'c' => CMS::$current_controller, 'name' => $name, 'data' => $data, 'item' => $item))->render(); } if ($action == 'upload') { return $this->action_upload($name, $data, $action, $item); } return false; }
<?php /** * WebKit.Helpers.Helpers.Assets * * @package Templates\HTML\Assets * @version 1.0.2 */ Core::load('Templates.HTML', 'Templates.HTML.Helpers.Tags'); /** * @package Templates\HTML\Helpers\Assets */ class Templates_HTML_Helpers_Assets implements Core_ModuleInterface, Templates_HelperInterface { const VERSION = '1.0.2'; /** */ public static function initialize() { Templates_HTML::use_helper('tags', 'Templates.HTML.Helpers.Tags'); Templates_HTML::use_helper('assets', 'Templates.HTML.Helpers.Assets'); } /** * @param string $url * @param array $attributes * * @return string */ public function image_tag($t, $url, array $attributes = array()) { return $t->tags->tag('img', Core_Arrays::merge($attributes, array('src' => $this->image_path_for($url))));
protected function admin_preview_path($data) { //if (!isset($this->value())) return false; $value = trim($this->value()); if ($value == '') { return false; } $dir = $this->cache_dir($name, $data, $item); $size = 200; if (isset($data['admin_preview_size'])) { $size = $data['admin_preview_size']; } $url = $this->get_preview_url(); $path = $this->original_preview_path(); if (!IO_FS::exists($path)) { return false; } $preview_path = "{$dir}/{$this->name}-admin-preview.jpg"; $create = false; if (IO_FS::exists($preview_path)) { if (filemtime($path) > filemtime($preview_path)) { $create = true; } } else { $create = true; } if ($create) { CMS::mkdirs($dir); Core::load('CMS.Images'); CMS_Images::Image($path)->fit($size, $size)->save($preview_path); } return $preview_path; }
protected static function adapter_module($fallback = false) { if (!$fallback) { $adapter = self::$options['default_adapter']; } else { $adapter = self::$options['fallback_adapter']; } if (!isset(self::$options['adapter_module'][$adapter])) { throw new WS_Exception("Adapter '{$adapter}' module not found"); } $module = self::$options['adapter_module'][$adapter]; Core::load($module); return Core_Types::real_class_name_for($module); }
<?php /** * WS.Adapters.Apache * * @package WS\Adapters\Apache * @version 0.2.0 */ Core::load('WS', 'Net.HTTP'); /** * @package WS\Adapters\Apache */ class WS_Adapters_Apache implements Core_ModuleInterface { const VERSION = '0.2.1'; /** * @return WS_Adapters_Apache_Adapter */ public static function Adapter() { return new WS_Adapters_Apache_Adapter(); } } /** * @package WS\Adapters\Apache */ class WS_Adapters_Apache_Adapter extends WS_AdapterAbstract { protected function headers() { return apache_request_headers();
<?php /** * L10N.EN * * Содержит описание месяцов и дней недели для EN локали * * @package L10N\EN * @version 0.2.0 */ Core::load('L10N'); /** * @package L10N\EN */ class L10N_EN implements Core_ModuleInterface { const VERSION = '0.2.0'; } /** * @package L10N\EN */ class L10N_EN_Locale extends L10N_Locale { /** * Контруктор * */ public function __construct() { return parent::__construct(array('months' => array(L10N::FULL => array(1 => 'january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'), L10N::ABBREVIATED => array(1 => 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec')), 'weekdays' => array(L10N::FULL => array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'), L10N::ABBREVIATED => array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun')))); }
<?php /// <module name="Config.File" maintainer="*****@*****.**" version="1.0.0"> Core::load('Config', 'IO.FS'); /// <class name="Config.File" stereotype="module"> /// <implements interface="Core.ModuleInterface" /> /// <depends supplier="Config.File.IniParser" stereotype="uses" /> /// <depends supplier="Config.File.PHPParser" stereotype="uses" /> /// <depends supplier="Config.File.UnknownFormatException" stereotype="throws" /> class Config_File implements Core_ModuleInterface { /// <constants> const MODULE = 'Config'; const VERSION = '1.0.0'; /// </constants> protected static $parsers = array('php' => 'PHPParser', 'ini' => 'IniParser'); /// <protocol name="building"> /// <method name="load" returns="Config.Tree"> /// <args> /// <arg name="path" type="string" /> /// <arg name="defaults" type="Config.Tree" default="null" /> /// </args> /// <body> public static function load($path, Config_Tree $defaults = null) { $extension = IO_FS::Path($path)->extension; if (isset(self::$parsers[$extension])) { $class_name = 'Config_File_' . self::$parsers[$extension]; $parser = new $class_name($path); return $parser->parse($defaults); } else {
<?php /** * @package CMS\Fields\Helper */ Core::load('CMS.Fields'); class CMS_Fields_Helper implements Core_ModuleInterface, Templates_HelperInterface { const MODULE = 'CMS.Fields.Helper'; const VERSION = '0.0.0'; public function draw($view, $fields, $layout = false) { if (!is_array($fields)) { return ''; } if (count($fields) < 1) { return ''; } $out = ''; foreach ($fields as $name => $data) { $out .= $this->field_in_layout($view, $name, $data, $layout); } return $out; } public function field($view, $name, $data) { $type = CMS_Fields::type($data); $type->view = $view; return $type->render($name, $data); } public function field_in_layout($view, $name, $data, $layout = false)
<?php /** * @package Text\Parser\Translit */ Core::load('Text.Process'); class Text_Parser_Translit implements Core_ModuleInterface, Text_Process_ProcessInterface { const VERSION = '0.1.0'; static $letters = array('А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D', 'Е' => 'E', 'Ё' => 'Yo', 'Ж' => 'Zh', 'З' => 'Z', 'И' => 'I', 'Й' => 'I', 'К' => 'K', 'Л' => 'L', 'М' => 'M', 'Н' => 'N', 'О' => 'O', 'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T', 'У' => 'U', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'Ts', 'Ч' => 'Ch', 'Ш' => 'Sh', 'Щ' => 'Sch', 'Ъ' => '', 'Ы' => 'Y', 'Ь' => '', 'Э' => 'E', 'Ю' => 'Yu', 'Я' => 'Ya'); function configure($config) { } function process($s) { return self::run($s); } static function run($s) { foreach (self::$letters as $rus => $lat) { $s = str_replace($rus, $lat, $s); // TODO: encoding to config $s = str_replace(mb_strtolower($rus, 'UTF-8'), mb_strtolower($lat, 'UTF-8'), $s); } return $s; } }
<?php /** * CLI.Application * * Простейшая структура CLI-приложения * * @package CLI\Application * @version 0.3.0 */ Core::load('CLI', 'CLI.GetOpt', 'IO', 'Log', 'Config.DSL'); /** * Класс модуля * * @package CLI\Application */ class CLI_Application implements Core_ModuleInterface { const MODULE = 'CLI.Application'; const VERSION = '0.3.0'; } /** * Базовый класс исключений * * @package CLI\Application */ class CLI_Application_Exception extends CLI_Exception { } /** * Базовый класс CLI-приложения