本文整理汇总了PHP中Parse类的典型用法代码示例。如果您正苦于以下问题:PHP Parse类的具体用法?PHP Parse怎么用?PHP Parse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Parse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public static function run($line)
{
if (preg_match_all('/(?<start>.*)(?<statement>{{\\s*endif\\s*;\\s*}})(?<end>.*)/', $line, $matches)) {
return Parse::run($matches);
}
return false;
}
示例2: render
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);
}
示例3: render
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);
}
示例4: getContent
/**
* 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);
}
示例5: __call
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);
}
示例6: execute
/**
* 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;
}
示例7: __call
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;
}
示例8: display
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);
}
示例9: listing
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);
}
}
示例10: run
public static function run($line)
{
if (preg_match('/(?<start>.*){{\\s*endforeach;\\s*}}(?<end>.*)/', $line, $match)) {
return Parse::run($match);
}
return false;
}
示例11: run
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;
}
示例12: index
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);
}
示例13: index
/**
* 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);
}
示例14: execute
/**
* (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();
}
示例15: setTemplates
/**
* 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);
}