protected function loadConfig() { parent::loadConfig(); if (\Clips\config('babel')) { $this->config['js']['files'] = array('browser-polyfill.js'); } }
public function filter_after($chain, $controller, $method, $args, $request, $controller_ret) { $scsses = \Clips\context('scss'); if ($scsses) { $cache = $this->filecache->cacheDir(); $forward_method = \Clips\context('forward_method'); if ($forward_method) { $method = $forward_method; } $full_name = \Clips\to_flat(get_class($controller)) . '_' . $method; $uri = \Clips\path_join(\Clips\path_join($cache, 'css'), $full_name); $cache_filename = \Clips\path_join($cache, 'css', \Clips\to_flat(get_class($controller) . '_' . $method) . '.css'); if (file_exists($cache_filename) && !\Clips\config('debug_sass')) { \Clips\add_css(\Clips\static_url($uri)); return; } if (\Clips\config('debug_sass')) { $this->sass->source_map_file = $cache_filename . '.map'; $this->sass->source_comments = true; $this->sass->source_map_embed = true; $this->sass->source_map_contents = true; } // Add the sass_dir into include pathes $result = $this->sass->compile($scsses); if ($result) { $this->filecache->save(\Clips\to_flat(get_class($controller) . '_' . $method) . '.css', $result, \Clips\path_join($cache, 'css'), true); \Clips\add_css(\Clips\static_url($uri)); } } }
/** * Create the git repository support */ public function repo($path) { if (\Clips\config('debug_git')) { return new \Gitonomy\Git\Repository($path, array('logger' => $this->logger)); } else { return new \Gitonomy\Git\Repository($path); } }
/** * Initialize the columns of videos */ public function initColumns() { $columns = \Clips\config('columns'); $columns = $columns[0]; $i = 0; foreach ($columns as $key => $col) { $this->sling->update('/epg/columns/' . $key, array('column_id' => $i, 'column_name' => $col, 'name' => $key, 'type' => 'column', 'time' => \Clips\timestamp(), 'column_type' => $i++, 'rank' => $i, 'status' => 1, 'desc' => $col)); } }
public function getPlayUrl($movie) { $mss = \Clips\config('mss_url'); if ($mss) { $mss = $mss[0]; return $mss . '/api/retrieve/' . $movie->id . '/' . $movie->playlist_name; } return null; }
function smarty_block_figure($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } $src = Clips\get_default($params, 'src'); $path = Clips\get_default($params, 'path', 'responsive/size'); $resolutions = Clips\get_default($params, 'resolutions'); $img_path = Clips\find_image($src); if (!$img_path) { Clips\error('figure', array('Can\'t find image ' . $src . '!')); return ''; } $size = Clips\image_size($img_path); $size = $size['width']; if ($resolutions) { // If we are using auto resizing, skip the resolutions foreach ($resolutions as $res) { $attr['data-media' . $res] = Clips\site_url('responsive/size/' . (double) $res / 2880 * (double) $size . '/' . $src); } } else { $attr = array('path' => Clips\site_url($path)); } foreach ($params as $key => $value) { if ($key == 'path') { continue; } if (strpos($key, 'media') !== false) { $attr['data-' . $key] = Clips\site_url('responsive/size/' . $value . '/' . $src); } else { $attr[$key] = $value; } } $caption = Clips\create_tag_with_content('figcaption', $content); $image_dir = Clips\config('image_dir'); if ($image_dir) { $image_dir = $image_dir[0]; } else { $image_dir = 'application/static/img/'; } $img = Clips\create_tag('img', array('src' => Clips\static_url(Clips\path_join($image_dir, $src)))); $noscript = Clips\create_tag_with_content('noscript', $img); $level = Clips\context('indent_level'); if ($level === null) { $level = 0; } else { $level = count($level); } $indent = ''; for ($i = 0; $i < $level; $i++) { $indent .= "\t"; } Clips\context_pop('indent_level'); return Clips\create_tag_with_content('figure', $noscript . "\n{$indent}" . $caption, $attr); }
public function init() { $name = get_class($this); // Remove the prefixes $name = explode('\\', $name); $name = $name[count($name) - 1]; if (!isset($this->table)) { $this->table = \Clips\to_flat(str_replace('Model', '', $name)) . 's'; // If no table is set for this model, just guess for its table } if (!isset($this->name)) { // If there is no name from the annotation, will use the default table name as the name $this->name = $name; } // Check for models config first $models = \Clips\config('models'); if ($models) { foreach ($models as $mc) { $config = \Clips\get_default($mc, $this->name, null); if ($config) { // If found the model's configuration, try using it to find datasource $ds = \Clips\get_default($config, 'datasource'); if ($ds) { $datasource = $ds; break; } } else { // If not found for model itself, try the common one $ds = \Clips\get_default($mc, 'datasource'); if ($ds) { $datasource = $ds; break; } } } } $ds = $this->tool->library('DataSource'); // Load the datasource library if (!isset($datasource)) { // There is still no datasource information, let's try using first one of the datasource $this->db = $ds->first(); } else { $this->db = $ds->get($datasource); } if (!isset($this->db)) { throw new \Exception('Cant\'t find any datasource for this model.'); } }
/** * @Clips\Library({"fileCache", "qrcode"}) */ public function generate($message) { $message = urldecode(urldecode($message)); // Decode the message first $id = md5($message); $file_name = "clips_qr_{$id}.png"; if ($this->filecache->exists($file_name)) { return $this->image($this->filecache->contents($file_name), 'png'); } $qrcode = $this->qrcode->setText($message); $fontPath = \Clips\config('qr_label_font_path'); if ($fontPath) { $qrcode->setLabelFontPath($fontPath[0]); } foreach ($this->options as $k => $v) { if (is_string($k)) { $name = ucfirst($k); $param = $this->request->param($k); if (!$param || !is_numeric($param)) { continue; } } else { $name = ucfirst($v); $param = $this->request->param($v); if (!$param) { continue; } } $method = 'set' . $name; call_user_func_array(array($this->qrcode, $method), array($param)); } $fcolor = $this->request->param('fcolor'); if ($fcolor) { $qrcode->setForegroundColor(\Clips\hex2rgb($fcolor)); } $bcolor = $this->request->param('bcolor'); if ($bcolor) { $qrcode->setBackgroundColor(\Clips\hex2rgb($bcolor)); } $img = $this->qrcode->show(); $this->filecache->save($file_name, $img); return $this->image($img, 'png'); }
public function compile($file) { $babel = \Clips\config('babel'); if ($babel) { $babel = $babel[0]; $paths = explode('/', $file); $name = str_replace('.jsx', '', array_pop($paths)); // Remove the filename array_pop($paths); // Remove the jsx folder $folder_name = 'js/' . array_pop($paths); $time = filectime($file); $folder = $this->filecache->mkdir($folder_name); if ($this->filecache->shouldUpdate($name . '.js', $time, $folder)) { $this->logger->debug('Trying to compile {0} to path {1} using command {2}', array($file, $folder, $babel)); \Clips\run($babel, array('-o' => \Clips\path_join($folder, $name . '.js'), '-s' => \Clips\path_join($folder, $name . '.js.map'), $file)); } return $this->filecache->cacheDir() . '/' . $folder_name . '/' . $name . '.js'; } return false; }
public function compile() { $args = func_get_args(); if ($args) { foreach ($args as $sass) { if (is_array($sass)) { foreach ($sass as $s) { $this->addSass($s); } continue; } $this->addSass($sass); } } if (\Clips\config('debug_sass')) { $this->logger->debug('Sasses files to compile is ', array($this->sasses)); } $content = $this->precompile(); $this->include_path = implode(PATH_SEPARATOR, $this->includePathes); $ret = sass_compile("data", $content, $this->options, $this->error); if ($ret || !$this->error) { return $ret; } $data = explode(":", $this->error); if (count($data) > 1) { $line = $data[1]; $data = explode("\n", $content); throw new \Exception($this->error . " at line -> [" . $data[$line - 1] . " ]\n"); } else { throw new \Exception($this->error); } }
public function filter_before($chain, $controller, $method, $args, $request) { $widgets = \Clips\clips_context('widgetsv2'); if ($widgets) { if (!is_array($widgets)) { $widgets = array($widgets); } $name = implode(' ', array_map(function ($item) { return get_class($item); }, $widgets)); $name = 'widget_' . md5($name) . '.json'; $smarty = \Clips\context('smarty'); if ($this->filecache->exists($name) && \Clips\config('widget_cache')) { // Let's use this widget cache $cache = unserialize($this->filecache->contents($name)); if (isset($cache['js'])) { $origin = $this->tool->context('js'); if ($origin) { $cache['js'] = array_merge($cache['js'], $origin); } $this->tool->context('js', $cache['js']); } if (isset($cache['jquery'])) { $jquery = $cache['jquery']; if (!is_array($jquery)) { $jquery = array($jquery); } foreach ($jquery as $j) { $this->tool->context('jquery_init', $j, true); } } if (isset($cache['css'])) { $origin = $this->tool->context('css'); if ($origin) { $cache['css'] = array_merge($cache['css'], $origin); } $this->tool->context('css', $cache['css']); } if (isset($cache['scss'])) { $origin = $this->tool->context('scss'); if ($origin) { $cache['scss'] = array_merge($cache['scss'], $origin); } $this->tool->context('scss', $cache['scss']); } if (isset($cache['sass_include'])) { $this->sass->addIncludePath($cache['sass_include']); } if (isset($cache['context'])) { $c = $cache['context']; if (!is_array($c)) { $c = array($c); foreach ($c as $cc) { $this->tool->context($cc, null, true); } } } if (isset($cache['smarty'])) { if ($smarty) { $smarty->setPluginsDir($cache['smarty']); } } } else { $js = $this->tool->context('js'); $css = $this->tool->context('css'); $scss = $this->tool->context('scss'); $jquery_init = $this->tool->context('jquery_init'); $this->tool->context_clear('js'); $this->tool->context_clear('css'); $this->tool->context_clear('scss'); $this->tool->context_clear('jquery_init'); foreach ($widgets as $w) { $w->init_v2(); } // Caching js, css and scss configurations $cache = array(); // Caching smarty's plugins dir if ($smarty) { $cache['smarty'] = $smarty->getPluginsDir(); } $js_widget = \Clips\context('js'); if ($js_widget) { $cache['js'] = $js_widget; } $css_widget = \Clips\context('css'); if ($css_widget) { $cache['css'] = $css_widget; } $jquery = \Clips\context('jquery_init'); if ($jquery) { $cache['jquery'] = $jquery; } $cache['sass_include'] = $this->sass->getIncludePaths(); $scss_widget = \Clips\context('scss'); if ($scss_widget) { $cache['scss'] = $scss_widget; } $context = \Clips\context('widget_context'); if ($context) { if (!is_array($context)) { $context = array($context); } $cache['context'] = array(); foreach ($context as $c) { $cache['context'][] = $c; } } // Save the cache $this->filecache->save($name, serialize($cache)); // Append other js, css and scss to the end if ($js) { if (!is_array($js)) { $js = array($js); } foreach ($js as $j) { $this->tool->context('js', $j, true); } } if ($jquery_init) { foreach ($jquery_init as $j) { $this->tool->context('jquery_init', $j, true); } } if ($css) { if (!is_array($css)) { $css = array($css); } foreach ($css as $j) { $this->tool->context('css', $j, true); } } if ($scss) { if (!is_array($scss)) { $scss = array($scss); } foreach ($scss as $j) { $this->tool->context('scss', $j, true); } } } } }
public function route() { profile_start('route'); profile_start('load_controller'); $request = $this->tool->create('Clips\\HttpRequest'); html_meta('generator', 'clips-tool ' . $this->frameworkmeta->branch . '(' . $this->frameworkmeta->commit . ')'); $this->tool->context(array('request' => $request, 'router' => $this)); // Set the request context to the context // Empty the main envrionment $this->clips->clear(); $this->clips->template("Clips\\RouteResult"); $this->clips->load(clips_config('route_rules', array('/rules/route.rules'))); // Assert the uris $uri = $this->getRequestURI(); // Record the breadscrumb if (\Clips\config('breadscrum')) { if ($request->method == 'get' && $request->getType() != 'ajax' && strpos($uri, 'responsive/size') === false) { $bs = $request->breadscrumb(); if (count($bs) > 1) { if ($bs[count($bs) - 1] != $uri) { $request->breadscrumb($uri); } } else { $request->breadscrumb($uri); } } } context('uri', $uri); $this->clips->assertFacts(array('uri', $uri), array('RequestType', $request->getType()), array('RequestMethod', $request->method)); // Assert the parameters $params = array(); $p = $request->param(); if ($p) { foreach ($request->param() as $k => $v) { $params[] = array('Parameter', $k, $v); } $this->clips->assertFacts($params); } $this->clips->run(); $error = $this->clips->queryFacts("RouteError"); if ($error) { $result = new RouteResult(); $result->controller = $this->tool->controller('error'); $result->method = 'show'; $result->args = $error[0]; $controller_seg = 'error'; //http_response_code(404); //error('RouteError', array($error[0][0])); } else { $result = $this->clips->queryFacts("Clips\\RouteResult"); $controller_seg = $this->clips->queryFacts("controller"); $server_uri = $this->clips->queryFacts("server-uri"); $result = $result[0]; $controller_seg = $controller_seg[0][0]; $server_uri = strtolower(str_replace('\\', '/', $server_uri[0][0])); } if (!isset($server_uri)) { $server_uri = 'error'; } profile_end('load_controller'); profile_start('controller_init'); $cc = $result->controller; $controller = new $cc(); $this->tool->context(array('controller_class' => $result->controller, 'controller_seg' => $controller_seg, 'controller' => $controller, 'controller_method' => $result->method, 'args' => $result->args, 'action' => new SimpleAction(array('type' => Action::SERVER, 'content' => $server_uri, 'params' => $result->args)))); $controller->request = $request; $this->tool->enhance($controller); $this->filterChain = $this->tool->load_class('FilterChain', true); $this->filterChain->addFilter(config('filters')); $re = new \Addendum\ReflectionAnnotatedClass($controller); // Trying to get the definition from class and the method annotation $m = $re->getMethod($result->method); foreach ($m->getAllAnnotations() as $a) { $this->tool->annotationEnhance($a, $controller); } profile_end('controller_init'); profile_start('filter_before'); $ret = null; if ($this->filterChain->filter_before($this->filterChain, $controller, $result->method, $result->args, $request)) { // Let the filter before can prevent the run of the controller method try { profile_end('filter_before'); profile_start('controller'); $ret = call_user_func_array(array($controller, $result->method), $result->args); profile_end('controller'); } catch (\Exception $e) { error(get_class($e), array($e->getMessage()), true); } } // Getting the error from the context $error = context('error'); if ($ret == null && $error) { // If there is no output and we can get the error, show the error $default_view = config('default_view'); if ($default_view) { if (is_array($error)) { $cause = $error[0]; $cause = $cause->cause; } else { $cause = $error->cause; } $r = new Resource('tpl://error/' . $cause); $r = $r->contents(); if (isset($cause) && $r) { $ret = new ViewModel('error/' . $cause, array('error' => $error), $default_view[0]); } else { $ret = new ViewModel('error/error', array('error' => $error), $default_view[0]); } } else { $ret = $error; } } else { if ($error) { // We can get the response, so just log the error $this->logger->error('Getting an error when serving the request.', array('error' => $error)); } } profile_end('route'); // Always run filter after(since the filter after will render the views) $this->filterChain->filter_after($this->filterChain, $controller, $result->method, $result->args, $request, $ret); }
public function sql() { if (isset($this->table_prefix)) { // Honor the prefix in sql $prefix = array($this->table_prefix); } else { $prefix = \Clips\config('table_prefix', null); } if (isset($prefix)) { $this->clips->runWithEnv('SQL', function ($clips, $prefix) { $clips->assertFacts(array('table-prefix', $prefix[0])); }, $prefix); } $result = $this->clips->runWithEnv('SQL', function ($clips, $prefix) { $clips->run(); $clips->assertFacts(array('table-prefix', $prefix[0])); $result = $clips->queryFacts('Clips\\Libraries\\SqlResult'); $clips->reset(); return $result; }, $prefix); if ($result) { if (isset($this->args)) { $args = $this->args; $this->args = null; return array($result[0]->sql, $args); } return array($result[0]->sql); } return null; }
/** * Get all the movies of this column */ public function getMovies($col, $offset = 0, $limit = 10) { $data = $this->sling->data('/epg/columns/' . $col . '.1'); $result = array(); $i = 0; foreach ($data as $k => $v) { if ($i < $offset) { continue; } if ($i >= $offset + $limit) { break; } if (is_object($v) && isset($v->id)) { $video = $this->sling->data('/media/video/' . $v->id); $mss = \Clips\config('mss_url'); $mss = $mss[0]; $video->poster_normal = $v->id . '/' . $video->poster_normal; $video->poster_small = $v->id . '/' . $video->poster_small; $result[] = $video; $i++; } } return $result; }
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!'); }
/** * Render the template using the mustache engine * * @args * template: The template uri for render * args: The args that used for render */ public function render($template, $args = array()) { if (func_num_args() > 2) { // They must using the variable args method $args = func_get_args(); $template = array_shift($args); return $this->render($template, $args); } // Get the cache file name by md5 it $hash = md5($template); $cacheDir = $this->filecache->cacheDir(); if (!file_exists($cacheDir)) { // Create the directory if not exists mkdir($cacheDir, 0755, true); } $phpname = \Clips\path_join($cacheDir, 'tpl_' . $hash . '.php'); $debug = \Clips\config('debug_template'); // Check if we can found the compiled php if (!file_exists($phpname) || $debug) { // Can't found this template in cache, read it from resource $resource = new \Clips\Resource($template); $str = $resource->contents(); $flags = \Clips\context('template_flags'); if (!$flags) { $flags = \Clips\config('template_flags'); if ($flags) { $flags = $flags[0]; } else { $flags = LightnCandy::FLAG_ERROR_EXCEPTION | LightnCandy::FLAG_HANDLEBARS | LightnCandy::FLAG_HANDLEBARSJS; } } $opts = array('flags' => $flags); $partials = \Clips\context('template_partials'); if ($partials) { $opts['partials'] = $partials; } $default_helpers = array('site_url' => '\\Clips\\Libraries\\site_url', 'static_url' => '\\Clips\\Libraries\\static_url', 'php' => '\\Clips\\Libraries\\php_call'); $default_block_helpers = array('times' => '\\Clips\\Libraries\\times', 'randtimes' => '\\Clips\\Libraries\\randtimes'); $helpers = \Clips\context('template_helpers'); if ($helpers) { $opts['helpers'] = array_merge($default_helpers, $helpers); } else { $opts['helpers'] = $default_helpers; } $block_helpers = \Clips\context('template_block_helpers'); if ($block_helpers) { $opts['hbhelpers'] = array_merge($default_block_helpers, $block_helpers); } else { $opts['hbhelpers'] = $default_block_helpers; } if ($str) { $php = "<?php " . PHP_EOL . LightnCandy::compile($str, $opts); // Save it to php file file_put_contents($phpname, $php); } } if (file_exists($phpname)) { $renderer = (include $phpname); return $renderer((array) $args); } return ''; }
/** * Get the datasource by name(name in the configuration) */ public function get($name) { if (isset($this->{$name})) { return $this->{$name}; } $tool = $this->tool; $ds = \Clips\config('datasources'); $config = \Clips\get_default($ds, $name); if (!$config) { // For supporting json configuration foreach ($ds as $d) { $config = \Clips\get_default($d, $name); if ($config) { break; } } } $type = \Clips\get_default($config, 'type'); if ($type) { $tool = $this->tool; $type = $tool->load_class($type, false, new \Clips\LoadConfig($tool->config->datasources_dir, "DataSource", "DataSources\\")); $this->{$name} = new $type($config); $this->tool->enhance($this->{$name}); return $this->{$name}; } else { trigger_error('No datasource config for datasource ' . $name); } return null; }
/** * Get the configured cache directory */ public function cacheDir() { $cache = \Clips\config('cache'); if ($cache) { return $cache[0]; } return 'application/cache'; }
function smarty_function_picture($params, $template) { $src = Clips\get_default($params, 'src'); if ($src) { if (preg_match('/_\\([A-Za-z0-9_]+\\)/', $src)) { $is_template = true; } } if (!isset($is_template)) { $path = Clips\get_default($params, 'path', 'responsive/size'); $resolutions = Clips\get_default($params, 'resolutions'); $medias = Clips\get_default($params, 'medias'); $img_path = Clips\find_image($src); if (!$img_path) { Clips\error('picture', array('Can\'t find image ' . $src . '!')); return ''; } $size = Clips\image_size($img_path); $size = $size['width']; $content = array(); $level = Clips\context('indent_level'); if ($level === null) { $level = 0; } else { $level = count($level); } $indent = ''; for ($i = 0; $i < $level; $i++) { $indent .= "\t"; } if ($resolutions || $medias) { if ($resolutions) { // If we are using auto resizing, skip the resolutions unset($params['resolutions']); foreach ($resolutions as $res) { $content[] = "\t" . Clips\create_tag('source', array('src' => Clips\site_url('responsive/size/' . (double) $res / 2880 * (double) $size . '/' . $src), 'media' => '(min-width:' . $res . 'px)')); } } if ($medias) { unset($params['medias']); foreach ($medias as $media => $res) { $content[] = "\t" . Clips\create_tag('source', array('src' => Clips\site_url('responsive/size/' . $res . '/' . $src), 'media' => '(min-width:' . $media . 'px)')); } } } else { $params['path'] = Clips\site_url($path); } $image_dir = Clips\config('image_dir'); if ($image_dir) { $image_dir = $image_dir[0]; } else { $image_dir = 'application/static/img/'; } Clips\clips_context('indent_level', 1, true); $img = Clips\create_tag('img', array('src' => Clips\static_url(Clips\path_join($image_dir, $src)))); $content[] = "\t" . Clips\create_tag_with_content('noscript', $img); Clips\context_pop('indent_level'); } else { $params['data-role'] = 'item-picture'; $params['path'] = Clips\site_url(Clips\get_default($params, 'path', 'responsive/size')); $indent = ''; $content = array(); } return Clips\create_tag_with_content('picture', implode("\n{$indent}", $content), $params); }
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 addLog($app_id, $info = '') { $request = \Clips\context('request'); $mac = $this->getMac(); $gateway = \Clips\config('gateway'); if ($gateway) { $gateway = $gateway[0]; } else { $gateway = 'none name'; } $gateway_id = $this->gateway->getOrCreate($gateway); if ($mac) { $device = $this->device->getOrCreate($mac, $request->browserMeta()); $device_id = $device->id; } else { $device_id = null; // We don't found any device } $data = array("app_id" => $app_id, "device_id" => $device_id, "gateway_id" => $gateway_id, "info" => $info, "create_date" => date("Y-m-d H:i:s")); $id = $this->insert('downloads', $data); $this->requestSync($app_id); return $id; }
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 ''; } }