Beispiel #1
0
 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;
 }
Beispiel #2
0
 /**
  * Конструктор
  *
  * @param string $dsn
  * @param int    $mode
  */
 public function __construct($dsn = 'sphinx://localhost:3312', $mode = SPH_MATCH_EXTENDED)
 {
     if (!($m = Core_Regexps::match_with_results('{^sphinx://([a-zA-Z./]+)(:?:(\\d+))?}', (string) $dsn))) {
         throw new Search_Sphinx_Exception("Bad DSN {$dsn}");
     }
     $this->client = new SphinxClient();
     $this->catch_errors($this->client->SetServer($m[1], (int) Core::if_not($m[3], 3312)) !== false && $this->client->setMatchMode($mode) !== false && $this->client->setArrayResult(true) !== false);
 }
Beispiel #3
0
 /**
  * Производит парсинг строки подключения и возвращает соответственный объект
  *
  * @param  $DSN
  *
  * @return Cache_Backend
  */
 public static function connect($dsn, $timeout = Cache::DEFAULT_TIMEOUT)
 {
     if (($m = Core_Regexps::match_with_results('{^([a-zA-Z]+)://}', (string) $dsn)) && isset(self::$backends[$m[1]])) {
         $module = self::$backends[$m[1]];
         // Core::load($module = 'Cache.Backend.'.self::$backends[$m[1]]);
         return Core::make($module, $dsn, $timeout);
     } else {
         throw new Cache_BadDSNException($dsn);
     }
 }
Beispiel #4
0
 protected function get_var_value($name)
 {
     $site = false;
     if ($m = Core_Regexps::match_with_results('{^(.+)/([^/]+)$}', $name)) {
         $name = trim($m[1]);
         $site = trim($m[2]);
         if ($site == '*') {
             $site = CMS_Admin::site();
         }
     }
     return CMS::vars()->get($name, $site);
 }
Beispiel #5
0
 /**
  * Конструктор
  *
  * @param string $dsn
  * @param int    $timeout
  */
 public function __construct($dsn, $timeout = Cache_Backend_FS::DEFAULT_TIMEOUT)
 {
     $m1 = Core_Regexps::match_with_results("|^{$this->prefix}://(.*)|", $dsn);
     if (!$m1) {
         throw new Cache_BadDSNException($dsn);
     }
     $this->path = rtrim($m1[1], DIRECTORY_SEPARATOR);
     if (!IO_FS::exists($this->path)) {
         IO_FS::mkdir($this->path, null, true);
     }
     $this->timeout = $timeout;
 }
Beispiel #6
0
 /**
  * Конструктор
  *
  * @param string $dsn
  * @param int    $timeout
  */
 public function __construct($dsn, $timeout = Cache_Backend_MemCache::DEFAULT_TIMEOUT)
 {
     $m1 = Core_Regexps::match_with_results('{^memcache://([^:]+):?(\\d+)?}', $dsn);
     if (!$m1) {
         throw new Cache_BadDSNException($dsn);
     }
     $this->memcache = new Memcache();
     if (!$this->memcache->connect($m1[1], Core::if_null($m1[2], 11211))) {
         throw new Cache_Exception('Could not connect');
     }
     $this->timeout = $timeout;
 }
Beispiel #7
0
 public function route($request)
 {
     $uri = trim(strtolower($this->clean_url($request->uri)));
     if (CMS_FSPages::$with_htm_extension) {
         $uri = preg_replace('{\\.htm$}', '/', $uri);
     }
     $path = '';
     if ($uri == '/') {
         $path = '/';
     } elseif ($m = Core_Regexps::match_with_results('{^/(.+)/$}', $uri)) {
         foreach (explode('/', $m[1]) as $chunk) {
             if (Core_Regexps::match('{[a-z0-9_-]+}', $chunk)) {
                 $path .= "/{$chunk}";
             }
         }
     }
     if ($path != '') {
         $dirs = array(CMS::$taopath . '/views/pages', CMS::app_path('views/pages'));
         /**
          * @event cms.fspages.dirs
          * @arg $dirs Список каталогов
          * Событие генерируется механизмом статических страниц (CMS.FSPages) для уточнения списка каталогов, в которых ищутся шаблоны. При необходимости в список можно добавить свой каталог.
          */
         Events::call('cms.fspages.dirs', $dirs);
         if (count($dirs) > 0) {
             for ($i = count($dirs) - 1; $i >= 0; $i--) {
                 $dir = $dirs[$i];
                 $page = false;
                 $page_path = "{$dir}{$path}/index.phtml";
                 if (IO_FS::exists($page_path)) {
                     $page = $page_path;
                 } else {
                     $page_path = "{$dir}/{$path}.phtml";
                     if (IO_FS::exists($page_path)) {
                         $page = $page_path;
                     }
                 }
                 if ($page) {
                     return array('controller' => 'CMS.Controller.FSPages', 'action' => 'index', $page);
                 }
             }
         }
     }
     return false;
 }
Beispiel #8
0
 /**
  * @param WebKit_HTTP_Request $request
  *
  * @return WebKit_Controller_Route
  */
 public function route($request)
 {
     if ($this->is_not_match_for($request->urn)) {
         return null;
     }
     if ($route = $this->route_index($request)) {
         return $route;
     }
     $uri = $this->clean_url($request->urn);
     foreach ($this->rules as $rule) {
         if ($match = Core_Regexps::match_with_results($rule[0], $uri)) {
             $route = WebKit_Controller::Route();
             foreach ($rule[1] as $k => $v) {
                 $route[$v] = isset($match[$k + 1]) ? $match[$k + 1] : $rule[2][$v];
             }
             $route->merge($rule[2]);
             break;
         }
     }
     return $route ? $route->merge($this->defaults)->add_controller_prefix($this->options['prefix']) : null;
 }
Beispiel #9
0
 public function filename()
 {
     if ($m = Core_Regexps::match_with_results('{/([^/]+)$}', $this->name)) {
         return $m[1];
     }
     return $this->name;
 }
Beispiel #10
0
 /**
  */
 protected function parse_dl()
 {
     while (!$this->eof()) {
         $line = $this->get();
         if ($m = Core_Regexps::match_with_results('{^;(.+?):(.+)$}', $line)) {
             $this->html .= self::$tag_dt_start;
             $this->html .= trim($m[1]);
             $this->html .= self::$tag_dt_end;
             $this->html .= self::$tag_dd_start;
             $this->html .= trim($m[2]);
             $this->html .= self::$tag_dd_end;
         } else {
             $this->unget();
             return;
         }
     }
 }
Beispiel #11
0
 public function after_all_uploads($name, $parms, $filename, $uploaded, $old = '')
 {
     $from = isset($parms['thumb_from']) ? trim($parms['thumb_from']) : '';
     if ($from != '') {
         if (isset($parms['not_recreate_thumb']) && $parms['not_recreate_thumb'] && $old != '') {
             return;
         }
         if (!isset($uploaded[$name]) && isset($uploaded[$from])) {
             $src = $uploaded[$from];
             $ext = false;
             if ($m = Core_Regexps::match_with_results('{\\.(jpg|gif|png|jpeg|bmp)$}i', $src)) {
                 $ext = strtolower($m[1]);
                 if ($ext == 'jpeg') {
                     $ext = 'jpg';
                 }
             }
             if ($ext) {
                 $filename = str_replace('$$$', $ext, $filename);
                 copy($src, $filename);
                 $this->resize_image($filename, $parms);
                 return $filename;
             }
         }
     }
 }
Beispiel #12
0
 static function NAVIGATION($parms)
 {
     $parms = trim($parms);
     if ($parms == '') {
         return CMS::$navigation->draw();
     }
     if (Core_Regexps::match('/^[0-9a-z_]+$/i', $parms)) {
         return CMS::$navigation->linkset_by_id($parms)->draw();
     }
     if ($m = Core_Regexps::match_with_results('/^([^:]+):([^:]+)$/', $parms)) {
         return CMS::$navigation->linkset_by_id($m[2])->draw($m[1]);
     }
     if ($m = Core_Regexps::match_with_results('/^([^:]+):([^:]+):([^:]+)$/', $parms)) {
         return CMS::$navigation[$m[2]]->linkset_by_id($m[3])->draw($m[1]);
     }
     return "%NAVIGATION{{$parms}}";
 }
Beispiel #13
0
 protected function get_file_format($file)
 {
     $ext = $this->get_file_format_exif($file);
     if ($ext) {
         return $ext;
     }
     if ($m = Core_Regexps::match_with_results('{\\.(jpg|gif|png|jpeg|bmp)$}i', $file)) {
         $ext = strtolower($m[1]);
         if ($ext == 'jpeg') {
             $ext = 'jpg';
         }
     }
     return $ext;
 }
Beispiel #14
0
 public function split($s, $lang = 'default')
 {
     $s = trim($s);
     if ($s == '') {
         return $s;
     }
     if (strpos($s, '%LANG{') === false) {
         return $s;
     }
     if ($m = Core_Regexps::match_with_results('/^(.*?)%LANG\\{([a-z]+)\\}(.*)$/ism', $s)) {
         $langs = array();
         $langs[$lang] = trim($m[1]);
         $next = trim($m[2]);
         $_langs = $this->split($m[3], $next);
         if (is_string($_langs)) {
             $langs[$next] = $_langs;
         } else {
             $langs = array_merge($langs, $_langs);
         }
         return $langs;
     }
     return $s;
 }
Beispiel #15
0
 /**
  * Выполняет разбор переменной окружения TAO_PATH
  *
  * @return array
  */
 private static function parse_environment_paths()
 {
     $result = array();
     if (($path_var = getenv(self::PATH_VARIABLE)) !== false) {
         foreach (Core_Strings::split_by(';', $path_var) as $rule) {
             if ($m = Core_Regexps::match_with_results('{^([-A-Za-z0-9*][A-Za-z0-9_.]*):(.+)$}', $rule)) {
                 $result[$m[1]] = $m[2];
             }
         }
     }
     return $result;
 }
Beispiel #16
0
 /**
  * @param Dev_Source_Module       $module
  * @param Dev_Source_Check_Result $result
  */
 public function run(Dev_Source_Module $module, Dev_Source_Check_Result $result)
 {
     $comment_name = false;
     $code_name = false;
     foreach ($module->file as $line_number => $line) {
         if (!$comment_name) {
             $m1 = Core_Regexps::match_with_results('{/' . '//\\s+<(class|interface|method).*name="([^"\']+)"}', $line);
             if ($m1) {
                 $comment_name = $m1[2];
                 $code_name = false;
             }
         }
         if (!$code_name && $comment_name) {
             $m2 = Core_Regexps::match_with_results('{^[a-zA-Z\\s]*(class|interface|function)\\s+([a-zA-Z_0-9]+)}', $line);
             if ($m2) {
                 $code_name = $m2[2];
                 if ($m2[1] != 'function') {
                     $code_name = Core_Strings::replace($code_name, '_', '.');
                 }
                 if ($code_name != $comment_name) {
                     $result->add_error($this, $module, "names no equal {$code_name}, {$comment_name} in line {$line_number}");
                 }
                 $comment_name = false;
             }
         }
     }
     $module->file->close();
 }
Beispiel #17
0
 public function validator_tagparms($name, $data, &$tagparms)
 {
     $rc = false;
     if (isset($data['validate_ajax'])) {
         $rc = true;
         $tagparms['data-validate-ajax'] = trim($data['validate_ajax']);
     }
     if (isset($data['validate_presence'])) {
         $rc = true;
         $tagparms['data-validate-presence'] = htmlspecialchars($data['validate_presence']);
     }
     if (isset($data['validate_email'])) {
         $rc = true;
         $tagparms['data-validate-match'] = $this->email_regexp();
         $tagparms['data-validate-match-message'] = $data['validate_email'];
         $tagparms['data-validate-match-mods'] = '';
     }
     if (isset($data['validate_match']) && isset($data['validate_match_message'])) {
         $rc = true;
         $match = trim($data['validate_match']);
         $mods = '';
         if ($match[0] == '/' || $match[0] == '{') {
             $mods = '';
             if ($m = Core_Regexps::match_with_results('!^(?:{|/)(.+)(?:}|/)([a-z]*)$!', $match)) {
                 $match = $m[1];
                 $mods = $m[2];
             }
         }
         $tagparms['data-validate-match'] = $match;
         $tagparms['data-validate-match-mods'] = $mods;
         $tagparms['data-validate-match-message'] = htmlspecialchars($data['validate_match_message']);
     }
     if ($rc) {
         $class = isset($tagparms['class']) ? $tagparms['class'] : '';
         $class = trim("{$class} validable");
         $tagparms['class'] = $class;
     }
     return $rc;
 }
Beispiel #18
0
 public function assign($data)
 {
     if (!empty($data)) {
         foreach ($data as $name => $value) {
             $name = trim($name);
             $this->{$name} = $value;
             if ($value) {
                 if ($m = Core_Regexps::match_with_results('{^group_(.+)$}', $name)) {
                     $group = $m[1];
                     $this->groups[$group] = $group;
                 }
             }
         }
     }
     return $this;
 }
Beispiel #19
0
 public function load_info()
 {
     if (!$this->installed_version) {
         if ($content = $this->load_info_file()) {
             foreach (explode("\n", $content) as $line) {
                 $line = trim($line);
                 if ($m = Core_Regexps::match_with_results('{^version(.+)$}', $line)) {
                     $this->installed_version = trim($m[1]);
                 } elseif ($m = Core_Regexps::match_with_results('{^hash\\s+([^\\s]+)\\s+(.+)$}', $line)) {
                     $hash = trim($m[1]);
                     $file = trim($m[2]);
                     $this->hashes[$file] = $hash;
                 }
             }
         }
     }
 }
Beispiel #20
0
 protected function multilink_load($table, $kname, $fname, $mask = false, $afield = false)
 {
     if ($this->id() > 0) {
         if (!$afield) {
             $afield = $table;
         }
         if (!$mask) {
             $mask = "{$fname}%";
             $regexp = "/^{$fname}(\\d+)\$/";
         }
         foreach ($this->attributes as $key => $value) {
             if ($m = Core_Regexps::match_with_results($regexp, $key)) {
                 unset($this->attributes[$key]);
             }
         }
         $query = DB_SQL::db()->{$table}->select->where("{$kname}=:{$kname}");
         $rows = $query->run($this->id());
         $arr = array();
         foreach ($rows as $row) {
             $arr[] = $row->{$fname};
             $p = str_replace('%', $row->{$fname}, $mask);
             $this->attributes[$p] = 1;
         }
         $this->attributes[$afield] = $arr;
     }
 }
Beispiel #21
0
 /**
  * @param Net_HTTP_Response $res
  * @param string            $name
  *
  * @return string|null
  */
 protected function get_value(Net_HTTP_Response $res, $name)
 {
     return ($m = Core_Regexps::match_with_results('{' . $name . '=([^\\n]*)}i', $res->body)) ? $m[1] : null;
 }
Beispiel #22
0
 public function process($data)
 {
     foreach ($data as $title => $item) {
         if (is_string($item) && trim($item) == '' && ($m = Core_Regexps::match_with_results('{^\\%(.+)$}', trim($title)))) {
             $_component = trim($m[1]);
             $_parms = false;
             if ($m = Core_Regexps::match_with_results('{^([^\\s]+)\\s+(.+)$}', $_component)) {
                 $_component = $m[1];
                 $_parms = trim($m[2]);
             }
             if (CMS::component_exists($_component)) {
                 $_class = CMS::$component_names[$_component];
                 $_classref = Core_Types::reflection_for($_class);
                 $links = $_classref->hasMethod('navigation_tree') ? $_classref->getMethod('navigation_tree')->invokeArgs(NULL, array($_parms)) : array();
                 foreach ($links as $k => $v) {
                     if (is_string($v)) {
                         $v = array('url' => $v);
                     }
                     $v["from-{$_component}"] = 1;
                     $links[$k] = $v;
                 }
                 $this->process($links);
             }
         } else {
             $this->add($title, $item);
         }
     }
 }
Beispiel #23
0
 /**
  * @param mixed $value
  */
 static function validate_parm($value)
 {
     if (!is_string($value)) {
         return $value;
     }
     while ($m = Core_Regexps::match_with_results('{^var:(.+)$}', trim($value))) {
         $value = CMS_Vars::get($m[1]);
     }
     return $value;
 }
Beispiel #24
0
 /**
  * @dataProvider provider_match_with_results
  */
 public function test_match_with_results($regexp, $string, $result)
 {
     $this->assertEquals(Core_Regexps::match_with_results($regexp, $string), $result);
 }
Beispiel #25
0
 public function imagelist($parms)
 {
     $id = (int) $parms['id'];
     $ar = array();
     if (IO_FS::exists("./" . Core::option('files_name') . "/vars/{$id}")) {
         foreach (IO_FS::Dir("./" . Core::option('files_name') . "/vars/{$id}") as $f) {
             $fp = $f->path;
             if ($m = Core_Regexps::match_with_results('{/([^/]+)$}', $fp)) {
                 $fp = $m[1];
             }
             $ar[] = '["' . $fp . '","' . CMS::file_url($f->path) . '"]';
         }
     }
     echo 'var tinyMCEImageList = new Array(' . implode(',', $ar) . ');';
     die;
 }
Beispiel #26
0
 public function add($title, $item)
 {
     if (!Core_Types::is_iterable($item)) {
         $item = array('uri' => $item, 'url' => $item);
     }
     if (isset($item['title'])) {
         $title = $item['title'];
     }
     $title = CMS::lang($title);
     //Events::dispatch('cms.navigation.add', $ev = Events::Event(array('title' => $title, 'data' => $item, 'url' => $item['url'])));
     //$title = $ev['title'];
     //$item = $ev['data'];
     //$item['url'] = $ev['url'];
     $url = $item['url'];
     Events::call('cms.navigation.add', $title, $item, $url);
     $item['url'] = $url;
     $access = isset($item['access']) ? trim($item['access']) : '';
     if ($access != '' && !CMS::check_globals_or($access)) {
         return $this;
     }
     if (isset($item['disabled'])) {
         if (CMS::check_yes($item['disabled'])) {
             return $this;
         }
     }
     $uri = '';
     if (isset($item['uri'])) {
         $uri = $item['uri'];
     }
     if (isset($item['url'])) {
         $uri = $item['url'];
     }
     $id = isset($item['id']) ? $item['id'] : md5($title . $uri);
     if (isset($item['navigation_id'])) {
         $id = trim($item['navigation_id']);
     }
     $selected = false;
     $disabled = false;
     if (isset($item['match'])) {
         if (preg_match($item['match'], CMS_Navigation3::$uri)) {
             $selected = true;
         }
     }
     if (isset($item['flag'])) {
         if (CMS::$navigation->is_flag($item['flag'])) {
             $selected = true;
         }
     }
     if ($uri == CMS_Navigation3::$uri) {
         $selected = true;
     }
     $item['selected'] = $selected;
     $item['disabled'] = $disabled;
     $sub = isset($item['sub']) ? $item['sub'] : null;
     if (is_string($sub)) {
         $sub = trim($sub);
         $_component = $sub;
         $_parms = $uri;
         if ($m = Core_Regexps::match_with_results('{^([^\\s]+)\\s+(.+)$}', $sub)) {
             $_component = trim($m[1]);
             $_parms = trim($m[2]);
         }
         if (CMS::component_exists($_component)) {
             $_class = CMS::$component_names[$_component];
             $_classref = Core_Types::reflection_for($_class);
             $sub = $_classref->hasMethod('navigation_tree') ? $_classref->getMethod('navigation_tree')->invokeArgs(NULL, array($_parms, $item)) : false;
         }
     }
     if (Core_Types::is_iterable($sub)) {
         $set = new CMS_Navigation3_LinkSet();
         $set->level_num = $this->level_num + 1;
         $set->process($sub);
         $this->link($id, $uri, $title, $item, $set);
     } else {
         $this->link($id, $uri, $title, $item);
     }
     return $this;
 }
Beispiel #27
0
 public function type_mnemocode()
 {
     $name = get_class($this);
     if ($m = Core_Regexps::match_with_results('{_([^_]+)$}', $name)) {
         $name = $m[1];
     }
     return trim(strtolower($name));
 }
Beispiel #28
0
 public function add_item($link, $level, $parent = null)
 {
     $access = isset($link->access) ? trim($link->access) : '';
     if ($access != '' && !CMS::check_globals_or($access)) {
         return $this;
     }
     if (empty($link->url) && empty($link->id) && ($m = Core_Regexps::match_with_results('{^\\%(.+)$}', trim($link->title)))) {
         $_component = trim($m[1]);
         $_parms = false;
         if ($m = Core_Regexps::match_with_results('{^([^\\s]+)\\s+(.+)$}', $_component)) {
             $_component = $m[1];
             $_parms = trim($m[2]);
         }
         if (CMS::component_exists($_component)) {
             $_class = CMS::$component_names[$_component];
             $_classref = Core_Types::reflection_for($_class);
             $links = $_classref->hasMethod('navigation_tree') ? $_classref->getMethod('navigation_tree')->invokeArgs(NULL, array($_parms)) : array();
             foreach ($links as $k => &$v) {
                 $v["from-{$_component}"] = 1;
             }
             return $this->load_data($links, $level, $parent);
         }
         return $this;
     }
     return parent::add_item($link, $level, $parent);
 }
Beispiel #29
0
 /**
  * Возвращает основу слова
  *
  * @param string $word
  *
  * @return string
  */
 public function stem_word($word)
 {
     $word = strtr(mb_strtolower($word), array('ё' => 'е'));
     if ($this->use_cache && isset($this->cache[$word])) {
         return $this->cache[$word];
     }
     list($str, $start, $rv) = Core_Regexps::match_with_results(self::RVRE, $word);
     if (!$rv) {
         return $word;
     }
     // step 1
     if (!Core_Regexps::replace_ref(self::PERFECTIVEGROUND, '', $rv)) {
         $rv = preg_replace(self::REFLEXIVE, '', $rv);
         if (Core_Regexps::replace_ref(self::ADJECTIVE, '', $rv)) {
             $rv = preg_replace(self::PARTICIPLE, '', $rv);
         } else {
             if (!Core_Regexps::replace_ref(self::VERB, '', $rv)) {
                 $rv = preg_replace(self::NOUN, '', $rv);
             }
         }
     }
     // step 2
     $rv = preg_replace('{и$}', '', $rv);
     // step 3
     if (preg_match(self::DERIVATIONAL, $rv)) {
         $rv = preg_replace('{ость?$}', '', $rv);
     }
     // step 4
     if (!Core_Regexps::replace_ref('{ь$}', '', $rv)) {
         $rv = preg_replace(array('{ейше?}', '{нн$}'), array('', 'н'), $rv);
     }
     return $this->use_cache ? $this->cache[$word] = $start . $rv : $start . $rv;
 }
Beispiel #30
0
 protected function tag_url($m)
 {
     $href = trim($m[1]);
     $text = trim($m[2]);
     if ($m = Core_Regexps::match_with_results('{^=(.+)}', $href)) {
         $href = trim($m[1]);
         return "<a href=\"{$href}\" target=\"_blank\">{$text}</a>";
     }
     return $text;
 }