public static function run($line) { if (preg_match_all('/(?<start>.*)(?<statement>{{\\s*endif\\s*;\\s*}})(?<end>.*)/', $line, $matches)) { return Parse::run($matches); } return false; }
public function render() { $options = $this->getConfig(); $field_options = array_get($this->field_config, 'options', array()); $options = array_merge($options, $field_options); // File options if ($file_dir = array_get($this->field_config, 'file_dir', false)) { $file_dir = trim(array_get($this->field_config, 'file_dir'), '/') . '/'; $options['fileUpload'] = Config::getSiteRoot() . 'TRIGGER/redactor/upload?path=' . $file_dir; $options['fileManagerJson'] = Config::getSiteRoot() . 'TRIGGER/redactor/fetch_files?path=' . $file_dir; $options['plugins'][] = 'filemanager'; } // Image options if ($image_dir = array_get($this->field_config, 'image_dir', false)) { $image_dir = trim(array_get($this->field_config, 'image_dir'), '/') . '/'; $options['imageUpload'] = Config::getSiteRoot() . 'TRIGGER/redactor/upload?path=' . $image_dir; $options['imageManagerJson'] = Config::getSiteRoot() . 'TRIGGER/redactor/fetch_images?path=' . $image_dir; $options['plugins'][] = 'imagemanager'; if ($resize = array_get($this->field_config, 'resize')) { $options['imageUpload'] .= '&resize=1&' . http_build_query($resize); } } // Enable plugins $supported_plugins = array('table', 'video', 'fullscreen', 'fontcolor', 'fontsize', 'fontfamily'); foreach ($options['buttons'] as $button) { if (in_array($button, $supported_plugins)) { $options['plugins'][] = $button; } } $vars = array('field_id' => $this->field_id, 'field_name' => $this->fieldname, 'tabindex' => $this->tabindex, 'field_data' => $this->field_data, 'field_config' => $this->field_config, 'options' => $options); $template = File::get($this->getAddonLocation() . 'views/fieldtype.html'); return Parse::template($template, $vars); }
public function render() { $data = $this->field_data ? $this->field_data : array(array('cells' => array(''))); $vars = array('field_id' => $this->field_id, 'field_name' => $this->fieldname, 'height' => array_get($this->field_config, 'height'), 'rows' => json_encode($data)); $template = File::get($this->getAddonLocation() . 'views/fieldtype.html'); return Parse::template($template, $vars); }
public static function run($line) { if (preg_match_all('/(?<start>.*){{\\s*foreach\\s*\\((?<array>[\\w|\\.]+)\\s*as\\s*(?<var>\\w+)(\\s*=>\\s*(?<subVar>\\w+))?\\s*\\)\\s*}}(?<end>.*)/', $line, $matches)) { return Parse::run($matches); } return false; }
/** * Lists entries based on passed parameters * * @return array|string */ public function getContent($variable) { $urls = array_get($this->context, $variable); if (!$urls) { return null; } // grab common parameters $settings = $this->parseCommonParameters(); // grab content set based on the common parameters // $content_set = $this->getContentSet($settings); $content_set = ContentService::getContentByURL($urls); $content_set->filter(array('show_hidden' => $this->fetchParam('show_hidden', false, null, true, false), 'show_drafts' => $this->fetchParam('show_drafts', false, null, true, false), 'show_past' => $this->fetchParam('show_past', true, null, true), 'show_future' => $this->fetchParam('show_future', false, null, true), 'type' => 'all', 'conditions' => trim($this->fetchParam('conditions', null, false, false, false)))); // limit $limit = $this->fetchParam('limit', null, 'is_numeric'); $offset = $this->fetchParam('offset', 0, 'is_numeric'); if ($limit || $offset) { $content_set->limit($limit, $offset); } // sort $sort_by = $this->fetchParam('sort_by'); $sort_dir = $this->fetchParam('sort_dir'); if ($sort_by || $sort_dir) { $content_set->sort($sort_by, $sort_dir); } // check for results if (!$content_set->count()) { return Parse::template($this->content, array('no_results' => true)); } return Parse::tagLoop($this->content, $content_set->get(), false, $this->context); }
public function __call($method, $arguments) { // Get all the parameter/filters $filters = $this->attributes; // Default content to context $content = $this->context; // Override content by a specific page if needed if ($from = $this->fetchParam('from')) { $content = current(ContentService::getContentByURL($from)->get()); unset($filters['from']); } // Grab the field data $field_data = array_get($content, $method); // Filter down to what we're looking for $values = array_values(array_filter($field_data, function ($i) use($filters) { foreach ($filters as $key => $val) { $match = array_get($i, $key) == $val; if (!$match) { break; } } return $match; })); // No results? if (empty($values)) { return array('no_results' => true); } // Got something. Yay. Return it. return Parse::tagLoop($this->content, $values, true); }
/** * 初始化函数 * * @access public * @param string $driver 驱动名称 * @param array $option 实例化驱动时需要的参数 * @return void **/ public static function init($driver, $option) { Loader::load('parse.driver.' . ucfirst(strtolower($driver)) . 'Driver'); $class = ucfirst($driver) . 'Driver'; $instance = new ReflectionClass($class); self::$_driver = $instance->newInstanceArgs($option); }
/** * Execute the argument parsing given the input from the command line * in $_SERVER['argv'] * * @param array $args Arguments list from the PHP input * @return array Parsed argument results */ public function execute($args, array $config = array()) { // Strip off the first item, it's the script name array_shift($args); $values = []; // Set any defaults we may have if (isset($config['default'])) { foreach ($config['default'] as $key => $value) { $values[$key] = $value; } } foreach ($args as $argument) { list($name, $value) = Parse::execute($argument); // see if we can find a matching option if ($name !== null) { $values[$name] = $value; } else { $values[] = $value; } } // See if we have ann required params if (isset($config['required'])) { $missing = []; foreach ($config['required'] as $index => $param) { if (!isset($values[$param])) { $missing[] = $param; } } if (!empty($missing)) { throw new Exception\MissingRequiredException('Missing required params: ' . implode(', ', $missing)); } } return $values; }
public function __call($method, $arguments) { $extensions = array(".html", ".md", ".markdown", ".textile"); $html = null; foreach ($extensions as $extension) { $full_src = Path::assemble(BASE_PATH, Config::getCurrentThemePath(), 'partials', ltrim($method . $extension, '/')); if (File::exists($full_src)) { // Merge additional variables passed as parameters Statamic_View::$_dataStore = $arguments + Statamic_View::$_dataStore; if ($this->fetchParam('use_context', false, false, true, false)) { $html = Parse::contextualTemplate(File::get($full_src), Statamic_View::$_dataStore, $this->context, 'Statamic_View::callback'); } else { $html = Parse::template(File::get($full_src), Statamic_View::$_dataStore, 'Statamic_View::callback'); } // parse contents if needed if ($extension == ".md" || $extension == ".markdown") { $html = Parse::markdown($html); } elseif ($extension == ".textile") { $html = Parse::textile($html); } } } if (Config::get('enable_smartypants', TRUE)) { $html = Parse::smartypants($html); } return $html; }
public function display($file) { $this->tpl_file = TPL_DIR . $file . TPL_EXTENDTION; //设置模板文件路径 if (!file_exists($this->tpl_file)) { exit(get_langage_message("template.lang.php", 'TEMPLATE_FILE_NOT_FOUND', array('TEMPLATE_FILE' => $this->tpl_file))); } $this->parse_file = TPL_C_DIR . md5($file) . '.php'; //设置编译文件路径 $parse = new Parse($this->tpl_file); //初始化模板解析类 $parse->compile($this->parse_file, $this->tpl_file); //解析静态模板文件,生成编译文件 //判断是否需要重新生成缓存文件 $this->cache($file); }
public function listing() { $role = $this->fetchParam('role', false); $limit = $this->fetchParam('limit', null, 'is_numeric'); // defaults to none $offset = $this->fetchParam('offset', 0, 'is_numeric'); // defaults to zero $sort_by = $this->fetchParam('sort_by', 'title'); // defaults to date $sort_dir = $this->fetchParam('sort_dir', 'desc'); // defaults to desc $members = Statamic_Auth::get_user_list(false); if (is_array($members) && count($members) > 0) { $members = array_slice($members, $offset, $limit, true); if ($sort_by == 'random') { shuffle($list); } elseif ($sort_by != 'title' || $sort_by != 'username') { # sort by any other field usort($members, function ($a, $b) use($sort_by) { if (isset($a[$sort_by]) && isset($b[$sort_by])) { return strcmp($b[$sort_by], $a[$sort_by]); } }); } // default sort is asc if ($sort_dir == 'desc') { $members = array_reverse($members); } return Parse::tagLoop($this->content, $members); } else { return array('no_results' => true); } }
public static function run($line) { if (preg_match('/(?<start>.*){{\\s*endforeach;\\s*}}(?<end>.*)/', $line, $match)) { return Parse::run($match); } return false; }
public static function run($line) { if (preg_match_all('/(?<start>[^\\{]*)\\s*{{(?<startQuickEsc>{)?\\s*(?<echo>\\w+(\\.\\w+)*)(?<escape>[\\|!](e|escape))?\\s*}}(?<endQuickEsc>})?(?<end>.*)/', $line, $match)) { return Parse::run($match); } return false; }
public function index() { $from = $this->fetchParam('from', false); if (!$from) { return null; } // account for subfolder if (strpos($from, Config::getSiteRoot()) !== 0) { $from = Path::tidy(Config::getSiteRoot() . $from); } $from = Path::addStartingSlash($from); $content_set = ContentService::getContentByURL($from); // filter $content_set->filter(array('show_hidden' => $this->fetchParam('show_hidden', false, null, true, false), 'show_drafts' => $this->fetchParam('show_drafts', false, null, true, false), 'show_past' => $this->fetchParam('show_past', true, null, true), 'show_future' => $this->fetchParam('show_future', false, null, true), 'type' => 'all', 'conditions' => trim($this->fetchParam('conditions', null, false, false, false)))); // limit $limit = $this->fetchParam('limit', 1, 'is_numeric'); $offset = $this->fetchParam('offset', 0, 'is_numeric'); $content_set->limit($limit, $offset); // check for results if (!$content_set->count()) { return Parse::tagLoop($this->content, array(array('no_results' => true))); } // if content is used in this entries loop, parse it $parse_content = (bool) preg_match(Pattern::USING_CONTENT, $this->content); return Parse::tagLoop($this->content, $content_set->get($parse_content), false, $this->context); }
public static function run($line) { if (preg_match_all('/(?<start>.*){{\\s*while\\((?<expr>.*)\\)\\s*}}(?<end>.*)/', $line, $matches)) { return Parse::run($matches); } return false; }
public static function run($line) { if (preg_match_all('/(?<start>.*)?{{\\s*include\\((?<file>[\\w.\\/]+)\\)\\s*}}(?<end>.*)/', $line, $matches)) { return Parse::run($matches); } return false; }
public function __construct($xml, $debug = false) { parent::__construct($debug); $this->xml = $xml; $this->title = $this->xml->channel->title; $this->num_items = count($this->xml->channel->item); }
/** * Get Instagram media * @return array parsed response from a public Instagram feed */ public function index() { $username = $this->fetch('username'); $limit = $this->fetch('limit', false, 'is_numeric'); $offset = $this->fetch('offset', 0, 'is_numeric'); $media = $this->tasks->getMedia($username, $limit, $offset); return Parse::tagLoop($this->content, $media); }
/** * (non-PHPdoc) * @see \DasRed\Translation\Command\Executor\Log\Parse::execute() */ public function execute() { $file = $this->getArguments()[1]; if (file_exists($file) === true) { unlink($file); } $this->write('File', 'LineNumber', 'Key', 'Locale', 'Count of Matches'); return parent::execute(); }
/** * Generate the set templates * * @return string JSON encoded string of templates */ private function setTemplates() { $template = File::get($this->getAddonLocation() . 'views/templates.html'); foreach ($this->set_types as $set) { $set['buttons'] = $this->buttons; $templates[] = array('type' => $set['name'], 'html' => Parse::template($template, $set)); } return json_encode($templates); }
public function file__thumbnail() { if ( ! $path = Request::get('path')) { exit('No path specified'); } $template = "{{ transform src='{ path }' width='125' height='125' action='smart' }}"; exit(Parse::template($template, compact('path'))); }
public function control_panel__add_to_head() { if (URL::getCurrent(false) != '/publish' && URL::getCurrent(false) != '/member') { return; } $config = array('max_files' => 1, 'allowed' => array(), 'destination' => 'UPLOAD_PATH', 'browse' => false); $fieldtype = Fieldtype::render_fieldtype('file', 'markituploader', $config, null, null, 'markituploader', 'markituploader'); $template = File::get($this->getAddonLocation() . 'views/modal.html'); return $this->js->inline('Statamic.markituploader = ' . json_encode(Parse::template($template, compact('fieldtype'))) . ';'); }
public function generateModal($config, $destination) { $vars = array( 'server_files' => $this->getServerFiles($config, $destination), 'destination' => $destination ); $template = File::get($this->getAddonLocation() . 'views/modal.html'); return Parse::template($template, $vars); }
public function map_url() { // parse settings $settings = $this->parseParameters(); // we need to set auto_center to false, here's why: // this tag will only ever place one marker on the map, and because of // the situation, we'll always know its latitude and longitude; by not // setting auto_center to false, starting_zoom no longer works (as the // auto_center function will try to determine the best zoom within the // allowed min_zoom and max_zoom); setting this to false allows users // to start using starting_zoom again without having to worry about any // automagic stuff taking over and wrestling away control $settings['auto_center'] = 'false'; $content_set = ContentService::getContentAsContentSet($settings['url']); // supplement $content_set->supplement(array( 'locate_with' => $settings['locate_with'], 'center_point' => $settings['center_point'], 'pop_up_template' => $this->content )); // re-filter, we only want entries that have been found $content_set->filter(array('located' => true)); $content = $content_set->get(); // no results? no results. if (!count($content)) { return Parse::template($this->content, array('no_results' => true)); } // check for valid center point if (!preg_match(Pattern::COORDINATES, $settings['center_point'], $matches)) { if ( $settings['locate_with'] && isset($content[0][$settings['locate_with']]) && is_array($content[0][$settings['locate_with']]) && isset($content[0][$settings['locate_with']]['latitude']) && isset($content[0][$settings['locate_with']]['longitude']) ) { $settings['starting_latitude'] = $content[0][$settings['locate_with']]['latitude']; $settings['starting_longitude'] = $content[0][$settings['locate_with']]['longitude']; } } else { $settings['starting_latitude'] = $matches[1]; $settings['starting_longitude'] = $matches[2]; } // other overrides $settings['clusters'] = 'false'; return $this->buildScript($content, $settings); }
public static function run($line) { if (preg_match_all('/(?<start>.*){{\\s*(?<beforeInc>\\+\\+|--)?(?<variable>\\w+)(?<afterInc>\\+\\+|--)?\\s*}}(?<end>.*)/', $line, $match)) { if (!empty($match['beforeInc'][0]) || !empty($match['afterInc'][0])) { return Parse::run($match); } else { return false; } } return false; }
public function render() { // Let's make sure they set an upload destination if (array_get($this->field_config, 'destination', false) === false) { throw new Exception("You need to set a destination for your File field."); } // Normalize the destination $this->destination = trim(array_get($this->field_config, 'destination'), '/') . '/'; // Allow a string or an array, but we want an array $has_data = ($this->field_data != ''); $this->field_data = Helper::ensureArray($this->field_data); // Clean up {{ _site_root }} and lack of leading slash existence foreach ($this->field_data as $i => $file) { $this->field_data[$i] = URL::tidy('/' . str_replace('{{ _site_root }}', '', $file)); } // Whether or not to allow the browse existing files functionality $allow_browse = array_get($this->field_config, 'browse', true); // Resizing config if ($resize = array_get($this->field_config, 'resize')) { $resize['resize'] = true; $resize = http_build_query($resize); } // If we're in a subdirectory, prepend it to all the filenames if (($site_root = Config::getSiteRoot()) != '/') { foreach ($this->field_data as $i => $file) { $this->field_data[$i] = URL::assemble($site_root, $file); } } // Send data to the view $vars = array( 'field_id' => $this->field_id, 'field_name' => $this->fieldname, 'tabindex' => $this->tabindex, 'has_data' => $has_data, 'field_data' => $this->field_data, 'field_config' => $this->field_config, 'destination' => $this->destination, 'allow_browse' => $allow_browse, 'server_files' => ($allow_browse) ? json_encode($this->tasks->generateModal($this->field_config, $this->destination)) : null, 'file_thumb' => URL::assemble(Config::getSiteRoot(), Config::get('admin_path'), 'themes', Config::get('admin_theme'), '/img/file.png'), 'resize' => $resize ); $template = File::get($this->getAddonLocation() . 'views/fieldtype.html'); return Parse::template($template, $vars); }
public function count() { $url = $this->fetchParam('from', URL::getCurrent()); $url = Path::resolve($url); $max_depth = $this->fetchParam('max_depth', 1, 'is_numeric'); $tree = Statamic::get_content_tree($url, 1, $max_depth); if ($this->content != '') { return Parse::tagLoop($this->content, $tree); } else { return count($tree); } }
public function partial() { $src = $this->fetchParam('src', null, null, false, false); if ($src) { $src .= ".html"; $partial_path = $this->theme_root . 'partials/' . ltrim($src, '/'); if (File::exists($partial_path)) { Statamic_View::$_dataStore = array_merge(Statamic_View::$_dataStore, $this->attributes); return Parse::template(file_get_contents($partial_path), Statamic_View::$_dataStore, 'Statamic_View::callback'); } } return null; }
public function words() { $limit = $this->fetchParam('limit', NULL); $ending = $this->fetchParam('ending', '...'); $this->content = Parse::template($this->content, Statamic_View::$_dataStore, 'Statamic_View::callback'); $words = preg_split("/[\n\r\t ]+/", $this->content, $limit + 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE); if (count($words) > $limit) { end($words); $last_word = prev($words); $this->content = substr($this->content, 0, $last_word[1] + strlen($last_word[0])) . $ending; } return $this->content; }
public function words() { $limit = $this->fetchParam('limit', NULL); $ending = $this->fetchParam('ending', '...', null, false, false); $this->content = Parse::contextualTemplate($this->content, array(), $this->context); $words = preg_split("/[\n\r\t ]+/", $this->content, $limit + 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_OFFSET_CAPTURE); if (count($words) > $limit) { end($words); $last_word = prev($words); $this->content = substr($this->content, 0, $last_word[1] + strlen($last_word[0])) . $ending; } return $this->content; }