function smarty_block_dl($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } $items = Clips\get_default($params, 'items', array()); if ($items) { unset($params['items']); $level = Clips\context('indent_level'); if ($level === null) { $level = 0; } else { $level = count($level); } $indent = ''; for ($i = 0; $i < $level; $i++) { $indent .= "\t"; } if (!trim($content)) { $content = '{dt}{$key}{/dt}' . "\n{$indent}" . '{dd}{$value}{/dd}'; } $output = array(); $t = 'string:' . $content; foreach ($items as $key => $value) { $output[] = trim($template->fetch($t, array('key' => $key, 'value' => $value))); } $content = implode("\n{$indent}", $output); } Clips\context_pop('indent_level'); return Clips\create_tag_with_content('dl', $content, $params); }
function smarty_block_navigation($params, $content = '', $template, &$repeat) { if ($repeat) { // Start the navigation ul Clips\clips_context('indent_level', 1, true); return; } $default = array('class' => array('nav')); $f = true; $actions = Clips\get_default($params, 'actions'); if ($actions) { unset($params['actions']); $content = ''; $level = Clips\context('indent_level'); if ($level === null) { $level = 0; } else { $level = count($level); } $indent = ''; for ($i = 0; $i < $level; $i++) { $indent .= "\t"; } foreach ($actions as $action) { // Only if the object is the valid action if (Clips\valid_obj($action, 'Clips\\Interfaces\\Action')) { $content .= _smarty_block_navigation_tree_node($action, $indent, $template, $repeat, Clips\get_default($params, 'item-class', array())); } } } Clips\context_pop('indent_level'); return Clips\create_tag_with_content('ul', $content, $params, $default); }
function smarty_block_button($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } $value = Clips\get_default($params, 'caption'); if ($value) { // We did have value, so the content is the JavaScript $id = Clips\get_default($params, 'id', 'clips_button_' . Clips\sequence('button')); $js = "\$(\"#{$id}\").click(function(){\n\t\t" . trim($content) . "\n\t});"; $content = $value; unset($params['caption']); $params['id'] = $id; Clips\context('jquery_init', $js, true); } // For i18n $bundle_name = Clips\context('current_bundle'); $bundle = Clips\get_default($params, 'bundle', $bundle_name); if ($bundle !== null) { $bundle = Clips\bundle($bundle); $content = $bundle->message($content); } Clips\context_pop('indent_level'); return Clips\create_tag_with_content('button', $content, $params); }
function smarty_block_form($params, $content = '', $template, &$repeat) { if ($repeat) { // Set the current form to the context Clips\clips_context('indent_level', 1, true); $name = Clips\get_default($params, 'name', Clips\default_form_name()); $data = Clips\context('form_' . $name); if ($data) { Clips\context('current_form_data', $data); } Clips\clips_context('current_form', $name); return; } $content .= "\t" . Clips\create_tag('input', array('type' => 'hidden', 'name' => Clips\Form::FORM_FIELD, 'value' => Clips\get_default($params, 'name', 'form'))); $action = Clips\get_default($params, 'action'); if ($action) { if (strpos($action, 'http') !== 0) { $params['action'] = Clips\site_url($action); } } if (Clips\get_default($params, 'upload')) { unset($params['upload']); $params['enctype'] = 'multipart/form-data'; } Clips\context_pop('current_form'); Clips\context_pop('current_form_data'); Clips\context_pop('indent_level'); return Clips\create_tag_with_content('form', $content, $params, array('action' => '#', 'method' => 'post', 'class' => ['clips-form', 'default-form'])); }
function smarty_function_cancel($params, $template) { Clips\require_widget_smarty_plugin('html', 'a'); $bundle_name = Clips\context('current_bundle'); $bundle = Clips\get_default($params, 'bundle', $bundle_name); $cancel = Clips\get_default($params, 'label', 'Cancel'); if ($bundle !== null) { $bundle = Clips\bundle($bundle); $cancel = $bundle->message($cancel); } $request = Clips\context('request'); $bs = $request->breadscrumb(); if (count($bs) > 1) { array_pop($bs); // Pop current $params['href'] = Clips\site_url(array_pop($bs)); $params['title'] = $cancel; $f = true; // Open the link smarty_block_a($params, '', $template, $f); $f = false; return smarty_block_a($params, $cancel, $template, $f); } return ''; }
protected function etag($args = array(), $callback = null) { $lastModified = \Clips\get_default($args, 'last-modified', time()); $etagFile = \Clips\get_default($args, 'etag', 'nothing'); $expires = \Clips\get_default($args, 'expires', '2 weeks'); $contentLengh = \Clips\get_default($args, 'content-length'); //get the HTTP_IF_MODIFIED_SINCE header if set $ifModifiedSince = $this->server('HTTP_IF_MODIFIED_SINCE', false); //get the HTTP_IF_NONE_MATCH header if set (etag: unique file hash) $etagHeader = trim($this->server('HTTP_IF_NONE_MATCH')); $headers = array(); //set last-modified header $headers['Last-Modified'] = gmdate("D, d M Y H:i:s", $lastModified) . " GMT"; //set etag-header $headers['Etag'] = $etagFile; if (is_string($expires)) { $expires = gmdate("D, d M Y H:i:s", strtotime($expires)); } if ($contentLengh) { $headers['Content-Length'] = $contentLengh; } $headers['Expires'] = $expires; //make sure caching is turned on $headers['Cache-Control'] = 'public'; //check if page has changed. If not, send 304 and exit if ($ifModifiedSince && @strtotime($ifModifiedSince) == $lastModified && $etagHeader == $etagFile) { return $this->not_modified($headers); } if ($callback) { return $callback($this, $headers, $args); } return false; }
function smarty_function_img($params, $template) { $uri = Clips\get_default($params, 'uri'); if ($uri) { unset($params['uri']); $params['src'] = Clips\static_url($uri); } return Clips\create_tag('img', $params); }
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); }
function smarty_block_uri($params, $content = '', $template, &$repeat) { if ($repeat) { return; } if (Clips\get_default($params, 'static')) { return Clips\static_url($content); } return Clips\base_url($content); }
function smarty_function_video($params, $template) { $src = Clips\get_default($params, 'src', null); if (!$src) { Clips\error("No src found for this video tag."); return ''; } $src = Clips\create_tag('source', array('src' => $src, 'type' => "application/x-mpegURL")); return Clips\create_tag_with_content('video', $src, $params, array('class' => array('video-js', 'vjs-default-skin'), 'id' => 'video', 'controls')); }
function smarty_block_html($params, $content = '', $template, &$repeat) { $version = Clips\get_default($params, 'version', '5'); Clips\clips_context('html_version', $version); if ($repeat) { Clips\clips_context('indent_level', 1, true); // Enstack indent level return; } $default = array(); switch ($version) { case '4': case '4t': $default['lang'] = 'en'; $pre = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'; break; case '4s': $default['lang'] = 'en'; $pre = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'; break; case '4f': $default['lang'] = 'en'; $pre = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'; break; case 'xhtml': $default['xmlns'] = 'http://www.w3.org/1999/xhtml'; $default['xml:lang'] = 'en'; $pre = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'; break; case 'xhtmlt': $default['xmlns'] = 'http://www.w3.org/1999/xhtml'; $default['xml:lang'] = 'en'; $pre = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'; break; case 'xhtmlf': $default['xmlns'] = 'http://www.w3.org/1999/xhtml'; $default['xml:lang'] = 'en'; $pre = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">'; break; case 'xhtml1.1': $default['xmlns'] = 'http://www.w3.org/1999/xhtml'; $default['xml:lang'] = 'en'; $pre = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'; break; case '5': $default['lang'] = 'en'; $pre = '<!DOCTYPE html>'; break; } if (isset($params['version'])) { unset($params['version']); } Clips\context_pop('indent_level'); return $pre . "\n" . Clips\create_tag_with_content('html', $content, $params, $default); }
public function filter($sql, $config) { if (is_array($sql)) { $this->tables = array(); $this->aliases = array(); $this->scan($sql); $prefix = \Clips\get_default($config, 'table_prefix', ''); return $this->prefix($sql, $prefix); } return $sql; }
public function publicDecrypt($message) { $key = \Clips\get_default($this, 'publicKey'); if ($key) { $ret = ''; if (openssl_public_decrypt(base64_decode($message), $ret, $key)) { return $ret; } } return false; }
function smarty_block_head($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); // Enstack indent level return; } $encoding = Clips\get_default($params, 'encoding', 'UTF-8'); $version = Clips\context('html_version'); $title = Clips\get_default($params, 'title', null); if (!$title) { // If didn't found title on the parameter, try find it in context $title = Clips\context('html_title'); } // Adding metas if (!$version) { $version = 5; } $meta = Clips\context('html_meta'); if (!$meta) { $meta = array(); } switch ($version) { case '4': case '4t': case '4s': case '4f': case 'xhtml': case 'xhtmlt': case 'xhtmlf': case 'xhtml1.1': array_unshift($meta, array('http-equiv' => 'Content-Type', 'content' => 'text/html;charset=' . $encoding)); break; case '5': array_unshift($meta, array('charset' => $encoding)); break; } $pre = array(); foreach ($meta as $m) { $pre[] = Clips\create_tag('meta', $m); } // Adding the title if ($title) { $pre[] = Clips\create_tag_with_content('title', $title); } $pre = "\t" . implode("\n\t\t", $pre); if (isset($params['title'])) { unset($params['title']); } Clips\context_pop('indent_level'); // Pop the stack before output return Clips\create_tag_with_content('head', $pre . $content, $params); }
function smarty_block_jsx($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\context('indent_level', 1, true); return; } // The element tag name that holds the virtual dom $tag = Clips\get_default($params, 'tag', 'div'); $id = Clips\render_jsx($content, Clips\get_default($params, 'id')); Clips\context_pop('indent_level'); return Clips\create_tag_with_content($tag, '', array('id' => $id, 'class' => array('jsx', 'jsx_holder'))); }
function smarty_function_context($params, $template) { $key = Clips\get_default($params, 'key', null); if ($key) { $formatter = Clips\get_default($params, 'formatter', null); $obj = Clips\clips_context($key); if ($formatter) { return Clips\format($obj, $formatter); } return $obj; } return ''; }
function smarty_block_state($params, $content = '', $template, &$repeat) { $name = Clips\get_default($params, 'name'); $state = Clips\context_peek('state'); if ($repeat) { return; } if ($name && ($name == 'default' && !Clips\context('matched_state')) || $state && $name == $state) { Clips\context('matched_state', $name); return trim($content); } return ''; }
function smarty_block_markup($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\context('indent_level', 1, true); return; } $tool =& Clips\get_clips_tool(); $flavor = Clips\get_default($params, 'flavor', 'github'); $markup = $tool->library('markup'); $content = $markup->render($content, $flavor); Clips\context_pop('indent_level'); return Clips\create_tag_with_content('div', $content, $params, array('class' => 'markup')); }
function smarty_function_submit($params, $template) { $bundle_name = Clips\context('current_bundle'); $bundle = Clips\get_default($params, 'bundle', $bundle_name); $submit = Clips\get_default($params, 'value', 'Submit'); if ($bundle !== null) { $bundle = Clips\bundle($bundle); $submit = $bundle->message($submit); } if (isset($params['value'])) { $params['value'] = $submit; } return Clips\create_tag('input', $params, array('type' => 'submit', 'value' => $submit, 'class' => array('btn', 'btn-primary'))); }
function smarty_block_lang($params, $content = '', $template, &$repeat) { if ($repeat) { return; } // Get the format from parameters, if no format parameter, use content instead $format = Clips\get_default($params, 'format', $content); $bundle_name = Clips\context('current_bundle'); if (!$bundle_name) { $bundle_name = ''; } $bundle = Clips\bundle(Clips\get_default($params, 'bundle', $bundle_name)); return $bundle->message($format, $content); }
function smarty_block_a($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } $uri = Clips\get_default($params, 'uri'); if ($uri) { unset($params['uri']); $params['href'] = Clips\site_url($uri); } Clips\context_pop('indent_level'); return Clips\create_tag_with_content('a', $content, $params); }
function smarty_block_container($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } $fluid = Clips\get_default($params, 'fluid', false); $class = 'container'; if ($fluid) { $class = 'container-fluid'; unset($params['fluid']); } Clips\context_pop('indent_level'); return Clips\create_tag_with_content('div', $content, $params, array('class' => $class)); }
function smarty_block_label($params, $content = '', $template, &$repeat) { if ($repeat) { Clips\clips_context('indent_level', 1, true); return; } Clips\context_pop('indent_level'); $bundle_name = Clips\context('current_bundle'); $bundle = Clips\get_default($params, 'bundle', $bundle_name); if ($bundle !== null) { $bundle = Clips\bundle($bundle); $content = $bundle->message($content); } return Clips\create_tag_with_content('label', $content, $params); }
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.'); } }
public function init() { $sling_config = \CLips\config('sling'); if ($sling_config) { $sling_config = $sling_config[0]; // Use the first configuration $this->host = \Clips\get_default($sling_config, 'host'); $this->port = \Clips\get_default($sling_config, 'port'); $this->username = \Clips\get_default($sling_config, 'username'); $this->password = \Clips\get_default($sling_config, 'password'); $this->base = \Clips\get_default($sling_config, 'base', ''); $this->curl->setBasicAuthentication($this->username, $this->password); } else { throw new \Clips\Exception('There is no sling configuration!'); } }
function smarty_block_states($params, $content = '', $template, &$repeat) { $state = Clips\get_default($params, 'state'); if ($repeat) { if ($state) { Clips\context('state', $state, true); } // Append the state into the state stack return; } if ($state) { Clips\context_pop('state'); } Clips\context_pop('matched_state'); return trim($content); }
public function up($migration, $config) { foreach ($config as $name => $options) { $table = $migration->table($name); $keys = array(); $foreign_keys = array(); // Add the columns foreach ($options as $colname => $colopts) { if (array_search($colname, array('form', 'pagination', 'view', 'model', 'controller')) !== false) { if ($colopts === false) { continue; } } if (!is_array($colopts)) { $colopts = (array) $colopts; } $type = \Clips\get_default($colopts, 'type', 'integer'); $opts = \Clips\get_default($colopts, 'options', array()); if (isset($colopts['key']) && $colopts['key']) { $keys[] = $colname; } if (isset($colopts['foreign_key'])) { switch (count($colopts['foreign_key'])) { case 1: // Only the table name, using id as the reference field $foreign_keys[] = array($colname, $colopts['foreign_key'], "id"); break; case 2: $foreign_keys[] = array($colname, $colopts['foreign_key'][0], $colopts['foreign_key'][1]); break; } } $table->addColumn($colname, $type, (array) $opts); } foreach ($keys as $key) { $table->addIndex($key); } foreach ($foreign_keys as $fk) { $table->addForeignKey($fk[0], $fk[1], $fk[2]); } $table->create(); } }
function smarty_function_input($params, $template) { $default = array('class' => array('form-input', 'form-control')); $f = Clips\clips_context('current_field'); if ($f) { $default = $f->getDefault($default); } $data = Clips\context_pop('current_form_field_data'); if ($data) { $default['value'] = $data; } $state = Clips\context('current_form_field_state'); if ($state && $state == 'readonly') { $value = Clips\get_default($default, 'value'); if ($value) { return "<span>{$value}</span>"; } return "<span>" . Clips\get_default($params, 'value', '') . "</span>"; } return Clips\create_tag('input', $params, $default); }
protected function init($config) { foreach ($config as $k => $v) { $this->{$k} = $v; } $table_prefix = \Clips\get_default($config, 'table_prefix'); $context = \Clips\get_default($config, 'context'); if ($table_prefix !== null && $context) { $this->context = $table_prefix . $context; } $this->db = new \mysqli($this->host, $this->username, $this->password, $this->database, $this->port); $this->db->set_charset($this->encoding); if ($this->db->connect_error) { throw new \Clips\DataSourceException($this->db->connect_error); } $this->sql = new \Clips\Libraries\Sql(); // Should we have a better idea? if ($table_prefix !== null) { $this->sql->table_prefix = $table_prefix; $this->table_prefix = $table_prefix; } }
function smarty_block_swiper__slide($params, $content = '', $template, &$repeat) { if ($repeat) { \Clips\clips_context('indent_level', 1, true); return; } $default = array('class' => 'swiper-slide'); $dataImage = \Clips\get_default($params, 'data-image', null); $paginationImage = \Clips\get_default($params, 'data-pagination-image', null); $responsive = \Clips\get_default($params, 'responsive', false); $image = ''; if ($dataImage) { if ($responsive == "true") { $image = smarty_function_resimg(array('data-image' => $dataImage, 'data-pagination-src' => $paginationImage), $template); } else { $image = smarty_function_img(array('src' => $dataImage, 'data-pagination-src' => $dataImage), $template); } unset($params['data-image']); unset($params['data-pagination-image']); unset($params['responsive']); } \Clips\context_pop('indent_level'); return \Clips\create_tag('div', $params, $default, $image . $content); }