Beispiel #1
0
 public function add($path)
 {
     if (!IO_FS::exists($path)) {
         throw new IO_Arc_FileNotFound_Exception("File not found: {$path}");
     } elseif (is_dir($path)) {
         $this->add_dir($path);
     } else {
         $this->add_file($path);
     }
     return $this;
 }
Beispiel #2
0
 static function with_images_cb($m)
 {
     $src = '.' . $m[2];
     if (IO_FS::exists($src)) {
         self::$multipart = 'related';
         $id = md5($src);
         self::$attaches[$id] = Mail_Message::Part()->file($src)->content_id("<{$id}>")->content_disposition('inline');
         return $m[1] . "=\"cid:{$id}\"";
     } else {
         return $m[0];
     }
 }
Beispiel #3
0
 protected function get_lang_file($data)
 {
     $lang_file = false;
     $lang_file = $data['lang_file'];
     $lang = $this->get_lang($data);
     $path = "jquery/lang/{$lang}.js";
     if ($data['lang_file']) {
         $lang_file = $data['lang_file'];
     } elseif (IO_FS::exists('scripts/' . $path)) {
         $lang_file = $path;
     } elseif (IO_FS::exists(CMS::stdfile('scripts/' . $path))) {
         $lang_file = CMS::stdfile_url('scripts/' . $path);
     }
     return $lang_file;
 }
Beispiel #4
0
 /**
  * @param int    $page
  * @param int    $numpages
  * @param string $url_template
  *
  * @return string
  */
 static function run($page, $numpages, $tpl)
 {
     if ($numpages < 2) {
         return '';
     }
     self::$url_template = $tpl;
     self::$current = $page;
     ob_start();
     if (IO_FS::exists(self::$template)) {
         include self::$template;
     } else {
         include CMS::view('page-navigator.phtml');
     }
     $out = ob_get_clean();
     return $out;
 }
Beispiel #5
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 #6
0
 public function __construct($file)
 {
     $this->zip_path = $file;
     $this->zip = new ZipArchive();
     if (IO_FS::exists($file)) {
         $res = $this->zip->open($file);
         if ($res === true) {
             return $this;
         }
         if ($res === ZIPARCHIVE::ER_NOZIP) {
             throw new IO_Arc_InvalidArchive_Exception("{$file} is not ZIP archive");
         }
         throw new IO_Arc_Exception("Error opening ZIP archive {$file}. Error code: {$res}");
     } else {
         $res = $this->zip->open($file, ZIPARCHIVE::CREATE);
     }
     return $this;
 }
Beispiel #7
0
 /**
  */
 public function generate()
 {
     foreach (new Dev_Source_LibraryDirIterator($this->path_to_library) as $module_name => $module) {
         if (Core_Strings::contains($module_name, '.')) {
             $file_place = $this->path_to_html . "/" . Core_Regexps::replace('{/\\w+$}', '', Core_Strings::replace($module_name, '.', '/'));
             if (!IO_FS::exists($file_place)) {
                 IO_FS::mkdir($file_place, 0775, true);
             }
         }
         try {
             $module_generator = new Dev_Source_Doc_ModuleGenerator($module, $this->path_to_html . "/" . Core_Strings::replace($module_name, '.', '/'));
             $module_generator->write();
             $module_generator->write_diagram();
             $this->add_to_toc($module_generator);
         } catch (Dev_Source_InvalidSourceException $e) {
         }
     }
     $this->write_css();
     $this->write_toc();
     $this->write_index();
 }
Beispiel #8
0
 public function page_navigator($view, $pagenum, $numpages, $url)
 {
     $app = CMS::app_path('views/helpers');
     $lib = CMS::tao_view('helpers');
     $templates = array();
     if (CMS::admin()) {
         $templates[] = "{$app}/page-navigator-admin.phtml";
         $templates[] = "{$lib}/page-navigator-admin.phtml";
     } else {
         $templates[] = "{$app}/page-navigator-site.phtml";
         $templates[] = "{$app}/page-navigator.phtml";
     }
     $templates[] = "{$lib}/page-navigator.phtml";
     foreach ($templates as $template) {
         if (IO_FS::exists($template)) {
             break;
         }
     }
     self::$pn_url = $url;
     self::$pn_current = $pagenum;
     return $view->partial($template, array('tpl' => $url, 'page' => $pagenum, 'numpages' => $numpages));
 }
Beispiel #9
0
 /**
  * @param string $access
  *
  * @return string
  */
 static function admin_menu($access = 'full')
 {
     if (!CMS::$globals[$access]) {
         return '';
     }
     ob_start();
     $tpl = self::$admin_menu_tpl . '.phtml';
     if (IO_FS::exists("../app/views/{$tpl}")) {
         include "../app/views/{$tpl}";
     } else {
         include CMS::view("{$tpl}");
     }
     $content = ob_get_clean();
     return $content;
 }
Beispiel #10
0
 /**
  * @return Log_FileHandler
  */
 public function init()
 {
     if (!IO_FS::exists($dir = IO_FS::File($this->path)->dir_name)) {
         IO_FS::mkdir($dir, null, true);
     }
     $this->stream = IO_FS::FileStream($this->path, 'a');
     return $this;
 }
Beispiel #11
0
 public function draw($template = 'simple', $parms = array())
 {
     //var_dump($this);
     $this->links = $this->sub();
     if (!$this->links) {
         $this->links = new ArrayObject();
     }
     ob_start();
     $filename1 = CMS_Navigation2::$tpl_path . "/{$template}.phtml";
     $filename2 = CMS::view("navigation/{$template}.phtml");
     if (IO_FS::exists($filename1)) {
         include $filename1;
     } else {
         if (IO_FS::exists($filename2)) {
             include $filename2;
         }
     }
     return ob_get_clean();
 }
Beispiel #12
0
 public function template($data = array(), $name = 'template')
 {
     static $template = array();
     if (Templates::is_absolute_path($name)) {
         return $name;
     }
     if (isset($data['template'])) {
         $data_templates = is_string($data['template']) ? array('template' => $data['template']) : $data['template'];
         if (isset($data_templates[$name]) && IO_FS::exists($data_templates[$name])) {
             return $data_templates[$name];
         }
     }
     $type = isset($data['type']) ? $data['type'] : 'input';
     $key = $type . '_' . $name;
     if (isset($template[$key])) {
         return $template[$key];
     }
     /*if ($name == 'template' && isset($data['template name']))
       $name = $data['template name'];*/
     $file = $this->dir() . "/{$name}.phtml";
     if (IO_FS::exists($file)) {
         return $template[$key] = $file;
     }
     $types = array($type);
     $parents = Core_Types::class_hierarchy_for($this);
     if (count($parents) >= 3) {
         foreach (array_slice($parents, 1, count($parents) - 2) as $p) {
             $type = CMS_Fields::type_by_class($p);
             if (empty($type)) {
                 $type = CMS_Fields::type_by_class(Core_Types::module_name_for($p));
             }
             $types[] = $type;
         }
     }
     foreach ($types as $t) {
         if (empty($t)) {
             continue;
         }
         $view = Templates_HTML::Template('fields/' . $t . '/' . $name);
         if ($view->exists()) {
             return $template[$key] = $view->path;
         }
     }
     $view = Templates_HTML::Template('fields/' . $name);
     if ($view->exists()) {
         return $template[$key] = $view->path;
     }
     return $template[$key] = $name;
 }
Beispiel #13
0
 /**
  * Подгружает файл конфигурации в формате Config.DSL
  *
  * @param string $path
  *
  * @return CLI_Application_Base
  */
 protected function load_config($path)
 {
     if (IO_FS::exists($path)) {
         $this->log->debug('Using config: %s', $path);
         Config_DSL::Builder($this->config)->load($path);
     } else {
         throw new CLI_ApplicationException("Missing config file: {$path}");
     }
     return $this;
 }
Beispiel #14
0
 static function modified_image($path, $mods)
 {
     if (is_string($mods)) {
         $mods = self::parse_modifiers($mods);
     }
     $ext = false;
     $name = false;
     if ($m = Core_Regexps::match_with_results('{(.+)\\.(jpe?g|gif|png|bmp)$}i', $path)) {
         $name = $m[1];
         $ext = strtolower($m[2]);
     }
     if (!$ext || !IO_FS::exists($path)) {
         $path = '../tao/files/images/admin.gif';
         $ext = 'gif';
         $name = 'error';
     }
     $name = preg_replace('{^\\.\\./}', 'up/', $name);
     $name = ltrim($name, '.');
     $name = ltrim($name, '/');
     $stat = IO_FS::Stat($path);
     $mtime = $stat->mtime->timestamp;
     $name .= "-{$stat->size}-{$mtime}-";
     $name .= md5(serialize($mods));
     $cache = self::$cache_dir . "/{$name}.{$ext}";
     if (IO_FS::exists('./' . $cache)) {
         return '/' . $cache;
     }
     $dir = preg_replace('{/([^/]+)$}', '', $cache);
     if (!IO_FS::exists($dir)) {
         IO_FS::mkdir($dir);
     }
     $image = self::Image($path);
     $image->modify($mods);
     $image->save('./' . $cache);
     CMS::chmod_file('./' . $cache);
     return '/' . $cache;
 }
Beispiel #15
0
 public function load_mods_info($dir)
 {
     $path = $dir . '/' . $this->mods_file_name;
     if (IO_FS::exists($path)) {
         return json_decode(IO_FS::File($path)->load(), true);
     }
     return array();
 }
Beispiel #16
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);
 }
Beispiel #17
0
 /**
  * @param string $index
  *
  * @return boolean
  */
 public function offsetExists($index)
 {
     return IO_FS::exists($this->full_path_for($index));
 }
Beispiel #18
0
 public function draw($template = 'simple', $parms = array())
 {
     ob_start();
     $filename1 = CMS_Navigation3::$tpl_path . "/{$template}.phtml";
     $filename2 = CMS::view("navigation/{$template}.phtml");
     if (IO_FS::exists($filename1)) {
         include $filename1;
     } else {
         if (IO_FS::exists($filename2)) {
             include $filename2;
         }
     }
     return ob_get_clean();
 }
Beispiel #19
0
 public function template_path($template)
 {
     $component_dir = $this->dir();
     $variants = array('/app/views/', '/views/');
     foreach ($variants as $v) {
         $path = $component_dir . $v . trim($template, '/');
         if (IO_FS::exists($path)) {
             return $path;
         }
     }
     return false;
 }
Beispiel #20
0
 /**
  * Инклюдит шаблон, создавая необходимые переменные
  * 
  * @param  $__path
  * @return Templates_JSON_Template
  */
 protected function load($__path)
 {
     foreach ($this->parms as $__k => $__v) {
         ${$__k} = $__v;
     }
     $parms = $this->parms;
     $json = array();
     if (IO_FS::exists($__path)) {
         ob_start();
         include $__path;
         return Core::if_not(ob_get_clean(), json_encode((array) $json));
     } else {
         throw new Templates_MissingTemplateException($__path);
     }
 }
Beispiel #21
0
 /**
  * Инклюдит шаблон, создавая необходимые переменные
  * 
  * @param string $__path
  * @return Templates_Text_Template
  */
 protected function load($__path)
 {
     foreach ($this->parms as $__k => $__v) {
         ${$__k} = $__v;
     }
     $parms = $this->parms;
     $text = $this->text;
     if (IO_FS::exists($__path)) {
         include $__path;
         return $this;
     } else {
         throw new Templates_MissingTemplateException($__path);
     }
 }
Beispiel #22
0
 public function attaches($parms)
 {
     $id = (int) $parms['id'];
     $attaches = 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;
             $attaches[$fp] = array('name' => $fp, 'path' => $f->path);
         }
     }
     return $this->render('attaches', array('id' => $id, 'attaches' => $attaches));
 }
Beispiel #23
0
 protected function write($path, $content)
 {
     $os_path = './' . ltrim($path, '\\/.');
     $os_dir = dirname($os_path);
     if (!IO_FS::exists($dir)) {
         IO_FS::mkdir($os_dir);
     }
     IO_FS::File($os_path)->update($content);
     //IO_FS::chmod($path, IO_FS::option('file_mod'));
     return $this;
 }
Beispiel #24
0
 /**
  * @param WS_Environment $env
  *
  * @return Net_HTTP_Response
  */
 public function run(WS_Environment $env)
 {
     //if ($this->disabled) return $this->application->run($env);
     $error = null;
     try {
         $body = $this->application->run($env);
         $response = Net_HTTP::merge_response($body, $env->response);
     } catch (Exception $e) {
         $error = $e;
         if ($this->disabled) {
             throw $e;
         }
         $response = Net_HTTP::Response(Net_HTTP::INTERNAL_SERVER_ERROR);
     }
     if (!$response->body && ($template = $this->find_template_name_for($response->status))) {
         if (isset($env->not_found->static_file)) {
             $response->body(IO_FS::File($env->not_found->static_file));
         } else {
             $layout = isset($env->not_found->layout) ? $env->not_found->layout : 'work';
             $view = Templates::HTML($template);
             if ($layout) {
                 $view->within_layout($layout);
             }
             $view->root->with(array('env' => $env, 'response' => $response, 'error' => $error));
             if ($view->exists()) {
                 $response->body($view);
             } else {
                 if (IO_FS::exists($static_name = $template . '.html')) {
                     $response->body(IO_FS::File($static_name));
                 }
             }
         }
     }
     Events::call('ws.status', $response);
     return $response;
 }
Beispiel #25
0
 protected function before_render()
 {
     parent::before_render();
     $path = $this->cached_path();
     if (!IO_FS::exists($path)) {
         return '';
     }
     if ($this->get_parm('width') === null || $this->get_parm('height') === null) {
         $sz = getImageSize($path);
         if ($this->get_parm('width') === null) {
             $this->set_parm('width', $sz[0]);
         }
         if ($this->get_parm('height') === null) {
             $this->set_parm('height', $sz[1]);
         }
     }
 }
Beispiel #26
0
 public function action_aimages($id)
 {
     if ($this->image_list_from_gallery) {
         return $this->action_gimages($id);
     }
     if (!$this->attaches_dir) {
         die;
     }
     $id = (int) $id;
     $dir = "./{$this->attaches_dir}/" . $this->iddir($id);
     $ar = array();
     if (IO_FS::exists($dir)) {
         foreach (IO_FS::Dir($dir) as $f) {
             $fp = $f->path;
             if ($m = Core_Regexps::match_with_results('{/([^/]+)$}', $fp)) {
                 $fp = $m[1];
             }
             $ar[] = '["' . $fp . '","' . $this->file_url($f->path) . '"]';
         }
     }
     echo 'var tinyMCEImageList = new Array(' . implode(',', $ar) . ');';
     die;
 }
Beispiel #27
0
 public function exists()
 {
     return IO_FS::exists($this->get_path());
 }
Beispiel #28
0
 public function get_existed_hash($file)
 {
     $path = "../{$file}";
     if (!IO_FS::exists($path)) {
         return false;
     }
     return md5_file($path);
 }
Beispiel #29
0
 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;
 }
Beispiel #30
0
 protected function create_module_file($module, $content)
 {
     list($file, $dir) = $this->module_paths($module);
     if (!IO_FS::exists($dir)) {
         CMS::mkdirs($dir);
         CMS::chmod_dir($dir);
     }
     if (IO_FS::exists($file)) {
         //return "{$file} уже существует!";
     }
     $content = preg_replace('{^&lt;}', '<', $content);
     file_put_contents($file, $content);
     CMS::chmod_file($file);
     return false;
 }