public function load() { if (!isset($this->_data)) { $this->_data = array(); if (isset($this->value)) { $test_data_dir = config('test_data_dir'); if (!$test_data_dir) { $test_data_dir = config('test_dir'); $test_data_dir = path_join($test_data_dir[0], 'data'); } else { $test_data_dir = $test_data_dir[0]; } if (!is_array($this->value)) { $this->value = array($this->value); } foreach ($this->value as $config) { $p = path_join($test_data_dir, $config . '.yml'); $p = \Clips\try_path($p); if ($p) { $content = file_get_contents($p); $args = context('test_args'); if (!$args) { $args = array(); } $this->_data[$config] = parse_yaml(str_template($content, $args)); } } } } return $this->_data; }
public function contents($uri) { $file = str_replace('app://', '', $uri); $path = \Clips\try_path(\Clips\path_join('application', $file)); if ($path) { return file_get_contents($path); } return null; }
public function execute($args) { $csv = \Clips\try_path('tests/data/places.csv'); $f = fopen($csv, 'r'); while ($data = fgetcsv($f)) { $this->place->insert(array('id' => $data[0], 'parent_id' => $data[1], 'name' => $data[2], 'type' => $data[3])); } $this->output('done'); }
public function contents($uri) { $uri = str_replace('src://', '', $uri); $path = \Clips\try_path($uri); if ($path) { return file_get_contents($path); } return null; }
public function execute($args) { if ($args) { if (!is_array($args)) { $args = array($args); } foreach ($args as $file) { $file = \Clips\try_path($file); if ($file) { $c = file_get_contents($file); $o = unserialize($c); print_r($o); } } } }
public function readFile($file) { if (strpos($file, "://") !== false) { $r = new \Clips\Resource($file); return $r->contents(); } // Try the absolute path first if (file_exists($file)) { return file_get_contents($file); } foreach (\Clips\clips_config('sass_folders', array()) as $folder) { $r = \Clips\try_path(\Clips\path_join($folder, $file)); if ($r) { return file_get_contents($r); } } foreach ($this->includePathes as $path) { $filepath = $path . '/' . $file; if (file_exists($filepath) && is_file($filepath) && is_readable($filepath)) { return file_get_contents($filepath); } } return ''; }
public function testZipContents() { $path = Clips\try_path('test.zip'); if ($path) { $this->assertNotNull(Clips\zip_contents($path, 'config.yml')); } }
public function mkdir($folder) { $cache = $this->cacheDir(); $f = \Clips\path_join($cache, $folder); if (!file_exists($f)) { // If no folder exists, make it mkdir($f, 0777, true); } return \Clips\try_path($f); }
public function size() { if (func_num_args() < 2) { $this->error('Argument is too little for responsive!', 'responsive'); return; } $args = array_map(function ($item) { return urldecode($item); }, func_get_args()); $size = array_shift($args); $file = implode('/', $args); $size = preg_replace('/[^0-9\\.]/', '', $size); if (!is_numeric($size) || $size <= 0) { $this->error('Size [' . $size . '] must be positive number!', 'responsive'); return; } foreach (\Clips\config('image_dir') as $dir) { $path = \Clips\try_path(\Clips\path_join($dir, $file)); if ($path) { break; } } $n = array_pop($args); if ($args) { // If we still have args, make it as the folder $folder = implode('/', $args); } else { $folder = ''; } $cache = $this->filecache->cacheDir(); $folder = \Clips\path_join($cache, 'img', $folder, $size); if (!file_exists($folder)) { // If no folder exists, make it mkdir($folder, 0777, true); } if (!$path) { foreach (\Clips\config('image_url_base') as $base) { $url = $base . '/' . $file; $f = \Clips\path_join($cache, 'img', implode('/', $args)); $local_file = $this->filecache->fileName($n, $f); $path = \Clips\try_path($local_file); if ($path) { break; } $this->curl->setOpt(CURLOPT_SSL_VERIFYHOST, false); $this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, false); $this->curl->setOpt(CURLOPT_HEADER, false); $this->curl->setOpt(CURLOPT_FOLLOWLOCATION, true); if ($this->curl->get($url) == 0) { file_put_contents($local_file, $this->curl->response); $path = \Clips\try_path($local_file); } break; } if (!$path) { $this->error('Can\'t find image file [' . $file . '] !', 'responsive'); return; } } $name = $this->filecache->fileName($n, $folder); if ($this->filecache->shouldUpdate($n, $path, $folder)) { $this->imageutils->thumbnail($path, $name, $size); } return $this->image($name); }
public function download_file() { $file_url = $this->get('file_url'); $file_url = \Clips\try_path($file_url); if (file_exists($file_url)) { $download = new Download(); $download->download_file($file_url); } }
function smarty_function_js($params, $template) { $tool = \Clips\get_clips_tool(); //Processing jquery init $init = \Clips\clips_context('jquery_init'); if ($init) { if (!is_array($init)) { $init = array($init); } $init[] = "if(typeof initialize === 'function') initialize();"; \Clips\add_init_js("//====================================\n// The jQuery initialize function \n//====================================\n\n" . 'jQuery(function($){' . "\n\t" . implode("\n\t", $init) . "\n" . '});'); } // Processing js $scripts = \Clips\context('js'); if ($scripts) { if (!is_array($scripts)) { $scripts = array($scripts); } $output = array(); $init = array(); foreach ($scripts as $item) { if (is_array($item)) { $js = explode("\n", $item['script']); $ret = array(); foreach ($js as $line) { $ret[] = "\t" . $line; } $init[] = implode("\n\t\t", $ret); } else { if (is_object($item)) { $js = explode("\n", $item->script); $ret = array(); foreach ($js as $line) { $ret[] = "\t" . trim($line); } $init[] = implode("\n\t\t", $ret); } else { $path = \Clips\safe_add_extension($item, 'js'); if (strpos($path, 'http:') === false) { $path = \Clips\static_url($path); } $output[] = '<script type="text/javascript" src="' . $path . '"></script>'; } } } $output[] = '<script type="text/javascript">' . "\n\t\t" . implode("\n\t\t", $init) . "\n\t\t" . '</script>'; // Added the jsx support for ReactJs $jsx = \Clips\context('jsx'); if ($jsx) { if (\Clips\config('babel')) { // TODO: This is a little bit ugly, needs refactor.... $babel = $tool->library('babel'); foreach ($jsx as $item) { $path = Clips\try_path(Clips\safe_add_extension($item, 'jsx')); if ($path) { $output[] = '<script type="text/javascript" src="' . Clips\static_url($babel->compile($path)) . '"></script>'; } } } else { foreach ($jsx as $item) { $output[] = '<script type="text/babel" src="' . Clips\static_url(Clips\safe_add_extension($item, 'jsx')) . '"></script>'; } } } $jsx = \Clips\context('jsx_script'); if ($jsx) { if (\Clips\config('babel')) { $babel = $tool->library('babel'); $cache = $tool->library('fileCache'); $c = \Clips\context('controller'); $cm = \Clips\context('controller_method'); $name = $c . '_' . $cm . '.jsx'; $cache_file = $cache->cacheDir() . '/js/cache/' . $c . '_' . $cm . '.js'; if (\Clips\try_path($cache_file) && !\Clips\config('debug_jsx')) { $output[] = '<script type="text/javascript" src="' . Clips\static_url($cache_file) . '"></script>'; } else { $cache->save($name, $jsx, \Clips\path_join($cache->cacheDir(), 'js')); $output[] = '<script type="text/javascript" src="' . Clips\static_url($babel->compile($cache->cacheDir() . '/js/' . $name)) . '"></script>'; } } else { $output[] = '<script type="text/babel">' . implode("\n\t\t", $jsx) . '</script>'; } } return implode("\n\t\t", $output); } else { return ''; } }
public function widget() { $config = \Clips\interactive('interactive/widget', $this); $config->date = strftime("%a %b %e %H:%M:%S %Y"); $config->widget = ucfirst($config->widget); $namespace = \Clips\config('namespace'); if ($namespace) { $config->namespace = $namespace[0]; } else { $config->namespace = 'Clips\\'; } $widget_dir = \Clips\clips_config('widget_dir'); foreach ($widget_dir as $p) { $path = \Clips\try_path($p); if ($path) { break; } } if (!$path) { $this->output('Can\'t find any widget directory, generation failed!'); return -1; } $dir = \Clips\path_join($path, $config->widget); if (\file_exists($dir)) { $this->output('Widget %s exists!', $config->widget); return -1; } // Make the widget dir first mkdir($dir, 0755, true); // Write the widget configuration \file_put_contents(\Clips\path_join($dir, 'widget.yml'), \Clips\clips_out('widget', $config, false)); // Write the widget class \file_put_contents(\Clips\path_join($dir, 'Widget.php'), \Clips\clips_out('widget_class', $config, false)); $this->output('Done!'); }