本文整理汇总了PHP中Parse::tagLoop方法的典型用法代码示例。如果您正苦于以下问题:PHP Parse::tagLoop方法的具体用法?PHP Parse::tagLoop怎么用?PHP Parse::tagLoop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parse
的用法示例。
在下文中一共展示了Parse::tagLoop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __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);
}
示例2: 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);
}
}
示例3: 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);
}
示例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: 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);
}
示例6: count
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);
}
}
示例7: index
/**
* Email Form
*
* Allows you to create an email form and parses the posted data.
*/
public function index()
{
// Setup the gazillion options
$options['to'] = $this->fetchParam('to');
$options['cc'] = $this->fetchParam('cc', '');
$options['bcc'] = $this->fetchParam('bcc', '');
$options['from'] = $this->fetchParam('from', '');
$options['msg_header'] = $this->fetchParam('msg_header', 'New Message', false, false, false);
$options['msg_footer'] = $this->fetchParam('msg_footer', '', false, false, false);
$options['subject'] = $this->fetchParam('subject', 'Email Form', false, false, false);
$options['class'] = $this->fetchParam('class', '');
$options['id'] = $this->fetchParam('id', '');
$options['data'] = $this->fetchParam('data', '');
$required = $this->fetchParam('required');
$honeypot = $this->fetchParam('honeypot', false, false, true);
#boolen param
// Set up some default vars.
$output = '';
$vars = array(array());
// If the page has post data process it.
if (isset($_POST) and !empty($_POST)) {
if (!$this->validate($_POST, $required)) {
$vars = array(array('error' => true, 'errors' => $this->validation));
} elseif ($this->send($_POST, $options)) {
$vars = array(array('success' => true));
} else {
$vars = array(array('error' => true, 'errors' => 'Could not send email'));
}
}
// Display the form on the page.
$output .= '<form method="post"';
if ($options['class'] != '') {
$output .= ' class="' . $options['class'] . '"';
}
if ($options['id'] != '') {
$output .= ' id="' . $options['id'] . '"';
}
if ($options['data'] != '') {
$output .= ' data="' . $options['data'] . '"';
}
$output .= '>';
$output .= Parse::tagLoop($this->content, $vars);
//inject the honeypot if true
if ($honeypot) {
$output .= '<input type="text" name="username" value="" style="display:none" />';
}
$output .= '</form>';
return $output;
}
示例8: listing
/**
* Lists entries based on passed parameters
*
* @return array|string
*/
public function listing()
{
$folders = $this->fetchParam('folder', $this->fetchParam('folders', ltrim($this->fetchParam('from', URL::getCurrent()), "/")));
$folders = $folders === "/" ? "" : $folders;
if ($this->fetchParam('taxonomy', false, null, true, null)) {
$taxonomy_parts = Taxonomy::getCriteria(URL::getCurrent());
$taxonomy_type = $taxonomy_parts[0];
$taxonomy_slug = Config::get('_taxonomy_slugify') ? Slug::humanize($taxonomy_parts[1]) : urldecode($taxonomy_parts[1]);
$content_set = ContentService::getContentByTaxonomyValue($taxonomy_type, $taxonomy_slug, $folders);
} else {
$content_set = ContentService::getContentByFolders($folders);
}
// filter
$content_set->filter(array('show_all' => $this->fetchParam('show_hidden', false, null, true, false), 'since' => $this->fetchParam('since'), 'until' => $this->fetchParam('until'), 'show_past' => $this->fetchParam('show_past', true, null, true), 'show_future' => $this->fetchParam('show_future', false, null, true), 'type' => 'entries', 'conditions' => trim($this->fetchParam('conditions', null, false, false, false))));
// sort
$content_set->sort($this->fetchParam('sort_by', 'order_key'), $this->fetchParam('sort_dir'));
// grab total entries for setting later
$total_entries = $content_set->count();
// limit
$limit = $this->fetchParam('limit', null, 'is_numeric');
$offset = $this->fetchParam('offset', 0, 'is_numeric');
$paginate = $this->fetchParam('paginate', true, null, true, false);
if ($limit || $offset) {
if ($limit && $paginate && !$offset) {
// pagination requested, isolate the appropriate page
$content_set->isolatePage($limit, URL::getCurrentPaginationPage());
} else {
// just limit or offset
$content_set->limit($limit, $offset);
}
}
// manually supplement
$content_set->supplement(array('total_found' => $total_entries, 'group_by_date' => $this->fetchParam("group_by_date", null, null, false, false)));
// 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));
}
示例9: listing
public function listing()
{
// grab a taxonomy set from the content service
$taxonomy_set = ContentService::getTaxonomiesByType($this->fetchParam('type', null));
// folders
$folders = $this->fetchParam('folder', $this->fetchParam('folders', ltrim($this->fetchParam('from', URL::getCurrent()), "/")));
// now filter that down to just what we want
$taxonomy_set->filter(array('folders' => $folders, 'show_hidden' => $this->fetchParam('show_hidden', false, null, true, false), 'show_drafts' => $this->fetchParam('show_drafts', false, null, true, false), 'since' => $this->fetchParam('since', null), 'until' => $this->fetchParam('until', null), 'min_count' => $this->fetchParam('min_count', 1, 'is_numeric'), 'show_future' => $this->fetchParam('show_future', false, null, true, false), 'show_past' => $this->fetchParam('show_past', true, null, true, false), 'conditions' => trim($this->fetchParam('conditions', null, false, false, false)), 'where' => trim($this->fetchParam('where', null, false, false, false))));
// sort as needed
$taxonomy_set->sort($this->fetchParam('sort_by', 'name'), $this->fetchParam('sort_dir', 'asc'));
// trim to limit the number of results
$taxonomy_set->limit($this->fetchParam('limit', null, 'is_numeric'));
// contextualize the urls to the given folder
$taxonomy_set->contextualize($this->fetchParam('folder', null));
$output = $taxonomy_set->get();
// no results found, return so
if (!count($output)) {
return array('no_results' => true);
}
// results found, parse the tag loop with our content
return Parse::tagLoop($this->content, $output, true, $this->context);
}
示例10: pagination
/**
* Paginate search results
*
* @return string
*/
public function pagination()
{
// determine configuration
$dataset = $this->fetch('dataset', null, false, false, false);
$parameters = $this->gatherParameters();
$config = $this->tasks->loadDataset($dataset, $parameters);
// short-circuit this if no query
if (!trim($config['query'])) {
return Parse::tagLoop($this->content, array(array('no_query' => true, '_query' => '')));
}
// do search
$output = $this->tasks->lookUp($config['query'], $config);
// get limit
$limit = $config['limit'] ? $config['limit'] : 10;
// get the query variables
$query_var = $config['query_variable'];
$query = urlencode($config['query']);
// count the content available
$count = count($output);
// take page_limit into account
if ($config['page_limit'] && $count > $config['page_limit'] * $limit) {
$count = $config['page_limit'] * $limit;
}
// check for errors
if (isset($output[0]['no_results']) || isset($output[0]['no_query'])) {
return Parse::tagLoop($this->content, $output);
}
$pagination_variable = Config::getPaginationVariable();
$page = Request::get($pagination_variable, 1);
$data = array('total_items' => (int) max(0, $count), 'items_per_page' => (int) max(1, $limit), 'total_pages' => (int) ceil($count / $limit), 'current_page' => (int) min(max(1, $page), max(1, $page)), 'current_first_item' => (int) min(($page - 1) * $limit + 1, $count));
$data['current_last_item'] = (int) min($data['current_first_item'] + $limit - 1, $count);
$data['previous_page'] = $data['current_page'] > 1 ? "?{$pagination_variable}=" . ($data['current_page'] - 1) . "&{$query_var}={$query}" : FALSE;
$data['next_page'] = $data['current_page'] < $data['total_pages'] ? "?{$pagination_variable}=" . ($data['current_page'] + 1) . "&{$query_var}={$query}" : FALSE;
$data['first_page'] = $data['current_page'] === 1 ? FALSE : "?{$pagination_variable}=1&{$query_var}={$query}";
$data['last_page'] = $data['current_page'] >= $data['total_pages'] ? FALSE : "?{$pagination_variable}=" . $data['total_pages'] . "&{$query_var}={$query}";
$data['offset'] = (int) (($data['current_page'] - 1) * $limit);
return Parse::template($this->content, $data);
}
示例11: index
public function index()
{
$from = $this->fetchParam('from', false);
// defaults to null
if (!$from) {
return null;
}
$from = Path::addStartingSlash($from);
$from = strlen($from) > 1 ? rtrim($from, "/") : $from;
$content_set = ContentService::getContentByURL($from);
// filter
$content_set->filter(array('show_all' => $this->fetchParam('show_hidden', 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));
}
示例12: breadcrumbs
public function breadcrumbs()
{
$url = $this->fetchParam('from', URL::getCurrent());
$include_home = $this->fetchParam('include_home', true, false, true);
$reverse = $this->fetchParam('reverse', false, false, true);
$backspace = $this->fetchParam('backspace', false, 'is_numeric', false);
$include_content = $this->fetchParam('include_content', false, null, true);
$trim = $this->fetchParam('trim', true, null, true);
$tag_content = $trim ? trim($this->content) : $this->content;
// add in left-/ if not present
if (substr($url, 0, 1) !== '/') {
$url = '/' . $url;
}
// if this doesn't start with the site root, add the site root
if (!Pattern::startsWith($url, Config::getSiteRoot())) {
$url = Path::tidy(Config::getSiteRoot(), $url);
}
// start crumbs
$crumbs = array();
// we only want to show breadcrumbs when we're not on the homepage
if ($url !== Config::getSiteRoot()) {
$segments = explode('/', ltrim(str_replace(Config::getSiteRoot(), '/', $url), '/'));
$segment_count = count($segments);
$segment_urls = array();
// create crumbs from segments
for ($i = 1; $i <= $segment_count; $i++) {
$segment_urls[] = '/' . join($segments, '/');
array_pop($segments);
}
// should we also include the homepage?
if ($include_home) {
$segment_urls[] = Config::getSiteRoot();
}
// grab data for each
foreach ($segment_urls as $url) {
$this_url = Path::tidy(Config::getSiteRoot() . '/' . $url);
$content = Content::get($this_url, $include_content);
if ($content) {
// standard stuff
$crumbs[$this_url] = $content;
} else {
// no content found? this could be a taxonomy
$crumbs[$this_url] = array('url' => $this_url, 'title' => ucwords(substr($url, strrpos($url, '/') + 1)));
}
$crumbs[$this_url]['is_current'] = URL::getCurrent() == $this_url;
}
// correct order
if (!$reverse) {
$crumbs = array_reverse($crumbs);
}
// add first, last, and index
$i = 1;
$crumb_count = count($crumbs);
foreach ($crumbs as $key => $crumb) {
$crumbs[$key]['first'] = $i === 1;
$crumbs[$key]['last'] = $i === $crumb_count;
$crumbs[$key]['index'] = $i;
$i++;
}
if (!count($crumbs)) {
$output = Parse::template($tag_content, array('no_results' => true));
if ($backspace) {
$output = substr($output, 0, -$backspace);
}
} else {
$output = Parse::tagLoop($tag_content, $crumbs);
if ($backspace) {
$output = substr($output, 0, -$backspace);
}
}
} else {
$output = Parse::template($tag_content, array('no_results' => true));
}
// parse the loop
return $output;
}
示例13: listing
/**
* Lists entries based on passed parameters
*
* @return array|string
*/
public function listing()
{
// grab common parameters
$settings = $this->parseCommonParameters();
// grab content set based on the common parameters
$content_set = $this->getContentSet($settings);
// limit
$limit = $this->fetchParam('limit', null, 'is_numeric');
$offset = $this->fetchParam('offset', 0, 'is_numeric');
$paginate = $this->fetchParam('paginate', true, null, true, false);
if ($limit || $offset) {
if ($limit && $paginate && !$offset) {
// pagination requested, isolate the appropriate page
$content_set->isolatePage($limit, URL::getCurrentPaginationPage());
} else {
// just limit or offset
$content_set->limit($limit, $offset);
}
}
// 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);
}
示例14: listing
public function listing()
{
if (Config::get('disable_member_cache')) {
$this->log->error("Cannot use `member:listing` when `_disable_member_cache` is `true`.");
return Parse::template($this->content, array('no_results' => true));
}
// grab common parameters
$settings = $this->parseCommonParameters();
// grab member set based on the common parameters
$member_set = $this->getMemberSet($settings);
// grab total members for setting later
$total_members = $member_set->count();
// no users found? return no results
if (!$total_members) {
return Parse::template($this->content, array('no_results' => true));
}
// limit
$limit = $this->fetchParam('limit', null, 'is_numeric');
$offset = $this->fetchParam('offset', 0, 'is_numeric');
$paginate = $this->fetchParam('paginate', true, null, true, false);
if ($limit || $offset) {
if ($limit && $paginate && !$offset) {
// pagination requested, isolate the appropriate page
$member_set->isolatePage($limit, URL::getCurrentPaginationPage());
} else {
// just limit or offset
$member_set->limit($limit, $offset);
}
}
// manually supplement
$member_set->supplement(array('total_found' => $total_members));
// check for results
if (!$member_set->count()) {
return Parse::template($this->content, array('no_results' => true));
}
return Parse::tagLoop($this->content, $member_set->get(), true, $this->context);
}
示例15: parse_loop
/**
* Parses through this plugin's content, replacing variables with variables from $data
*
* @deprecated Use Parse::tagLoop() instead
*
* @param string $content Content template to replace variables in
* @param array $data Associated array of data to replace
* @return string
*/
public function parse_loop($content, array $data)
{
$this->log->warn('Use of $this->parse_loop() is deprecated. Use Parse::tagLoop() instead.');
return Parse::tagLoop($content, $data);
}