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); }
/** * Get current user's id from session * * @return user_id * The id of current user, if user is not logged in, the will be false */ public function getCurrentUserId() { $request = \Clips\context('request'); if ($request) { return $request->session('user_id'); } else { \Clips\error('Trying to get user\'s login infor when no request is there.'); } return false; }
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')); }
public function doRender($controller, $method, $args, $request, $template, $data, $controller_ret) { $stream = $controller_ret->template; if ($stream && is_resource($stream)) { $s = fopen('php://output', 'wb'); stream_copy_to_stream($stream, $s); fclose($stream); fclose($s); } else { \Clips\error('No stream to output!'); } }
public function filter_before($chain, $controller, $method, $args, $request) { $action = \Clips\context('action'); if ($action) { $result = $this->securityengine->test($action); if ($result) { // We got an rejects $reasons = array(); $cause = 'security'; foreach ($result as $item) { $reasons[] = $item->reason; if (isset($item->cause)) { $cause = $item->cause; } } \Clips\error($cause, $reasons); $chain->stop(); return false; } } // Default pass return true; }
/** * Reporting the error */ protected function error($message, $cause = null) { if (!\is_array($message)) { $message = array($message); } \Clips\error($cause, $message); }
public function getProductWhenBuy($post) { $id = $post['id']; if (!$id) { \Clips\error('Can\'t find product based on ID' . $id . '!', 'Not Found'); return; } $amount = (int) $post['number']; $product = $this->product->load($id); if ($product->amount < $amount) { return 'Product Amount Not Enough'; } if ($amount < 0) { return 'Product Amount Not Enough'; } $product_photos = $this->productphoto->getProductPhotos($id); $product->path = $product_photos[0]->path; $product->totalPrice = $product->price * $amount; $product->number = $amount; return $product; }
protected function doUpdate($table, $obj) { if (isset($obj->id)) { $orig = $this->db->context; $this->db->context = $table; $ret = false; try { $ret = $this->db->update($obj->id, $obj); } catch (Exception $e) { \Clips\error("database_update", $e->getMessage()); } $this->db->context = $orig; return $ret; } else { \Clips\error("database_update", "No id setting for update table {$table}."); } }
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); }