本文整理汇总了PHP中Content::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP Content::parse方法的具体用法?PHP Content::parse怎么用?PHP Content::parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Content
的用法示例。
在下文中一共展示了Content::parse方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepare
/**
* Prepares the data for use in loops
*
* @param bool $parse_content Parse content? This is a performance hit.
* @param bool $override_flag Override `prepared` flag and re-loop?
* @return void
*/
public function prepare($parse_content = true, $override_flag = false)
{
$hash = Debug::markStart('content', 'preparing');
if ($this->prepared && !$override_flag) {
return;
}
$this->prepared = true;
$count = $this->count();
$i = 1;
// loop through the content adding contextual data
foreach ($this->content as $key => $item) {
$this->content[$key]['first'] = $i === 1;
$this->content[$key]['last'] = $i === $count;
$this->content[$key]['count'] = $i;
$this->content[$key]['total_results'] = $count;
// parse full content if that's been requested and is needed
if ($parse_content && isset($item['_file']) && (!$this->content_parsed || $override_flag)) {
// check to see if we know about this content
if (!isset(self::$known_content[$item['url']])) {
// we haven't seen this item before in this page-load
// retrieve this content
$content_file = isset($item['_file']) ? $item['_file'] : null;
$item_content = array('content_raw' => '', 'content' => '');
// content file exists
if ($content_file && File::exists($content_file)) {
// make this
$raw_file = substr(File::get($content_file), 3);
$divide = strpos($raw_file, "\n---");
$item_content['content_raw'] = trim(substr($raw_file, $divide + 4));
$item_content['content'] = Content::parse($item_content['content_raw'], $item);
}
// update the cache
self::$known_content[$item['url']] = $item_content;
}
// pull the content from the known-content cache
$this->content[$key]['content_raw'] = self::$known_content[$item['url']]['content_raw'];
$this->content[$key]['content'] = self::$known_content[$item['url']]['content'];
}
// iterate the counter
$i++;
}
// mark that we've parsed content so that we don't do it again
if ($parse_content) {
$this->content_parsed = true;
}
Debug::markEnd($hash);
}
示例2: map
/**
* Displays entries on a map
*
* @return string
*/
public function map()
{
// check for valid center point
if (!preg_match(Pattern::COORDINATES, $this->fetchParam('center_point'), $matches)) {
print_r($this->fetchParam('center_point'));
$this->log->error("Could not create map, invalid center point coordinates given");
return NULL;
} else {
$latitude = $matches[1];
$longitude = $matches[2];
}
// pop-up template
$pop_up_template = NULL;
// check for a valid pop_up template
if (preg_match_all("/(?:\{\{\s*pop_up\s*\}\})\s*(.*)\s*(?:\{\{\s*\/pop_up\s*\}\})/ism", $this->content, $matches) && is_array($matches[1]) && isset($matches[1][0])) {
$pop_up_template = trim($matches[1][0]);
}
$folders = $this->fetchParam('folder', ltrim($this->fetchParam('from', URL::getCurrent()), "/"));
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_hidden' => $this->fetchParam('show_hidden', false, null, true, false),
'show_drafts' => $this->fetchParam('show_drafts', 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))
));
// prepare if needed
$parse_content = (bool) preg_match(Pattern::USING_CONTENT, $this->content);
if ($parse_content) {
$content_set->prepare();
}
// supplement
$content_set->supplement(array(
'locate_with' => $this->fetchParam('locate_with'),
'center_point' => $this->fetchParam('center_point')
));
// re-filter, we only want entries that have been found
$content_set->filter(array(
'located' => true
));
// sort
$content_set->sort($this->fetchParam('sort_by', 'order_key'), $this->fetchParam('sort_dir'));
// 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
$content_set->limit($limit, $offset);
}
}
// get content
$content_set->prepare(false, true);
$content = $content_set->get($parse_content);
// set variables
$map_id = $this->fetchParam('map_id', Helper::getRandomString());
$zoom = $this->fetchParam('zoom', 12);
// cluster options
$clusters = $this->fetchParam('clusters', TRUE, NULL, TRUE);
$clusters = ($clusters) ? "true" : "false";
$spiderfy_on_max_zoom = $this->fetchParam('spiderfy_on_max_zoom', TRUE, NULL, TRUE);
$spiderfy_on_max_zoom = ($spiderfy_on_max_zoom) ? "true" : "false";
$show_coverage_on_hover = $this->fetchParam('show_coverage_on_hover', TRUE, NULL, TRUE);
//.........这里部分代码省略.........
示例3: parse_content
public static function parse_content($template_data, $data, $type = NULL)
{
Log::warn("Use of Statamic::parse_content() is deprecated. Use Content::parse() instead.", "core", "Statamic");
return Content::parse($template_data, $data, $type);
}
示例4: prepare
/**
* Prepares the member data for use in loops
*
* @param bool $parse_biography Parse content? This is a performance hit.
* @param bool $override_flag Override `prepared` flag and re-loop?
* @return void
*/
public function prepare($parse_biography = true, $override_flag = false)
{
if ($this->prepared && !$override_flag) {
return;
}
$this->prepared = true;
$count = $this->count();
$i = 1;
// loop through the content adding contextual data
foreach ($this->members as $username => $item) {
$this->members[$username]['first'] = $i === 1;
$this->members[$username]['last'] = $i === $count;
$this->members[$username]['count'] = $i;
$this->members[$username]['total_results'] = $count;
$file = sprintf(Config::getConfigPath() . '/users/%s.yaml', $username);
// parse full content if that's been requested
if ($parse_biography && $file) {
$raw_file = substr(File::get($file), 3);
$divide = strpos($raw_file, "\n---");
$this->members[$username]['biography_raw'] = trim(substr($raw_file, $divide + 4));
$this->members[$username]['biography'] = Content::parse($this->members[$username]['biography_raw'], $item);
}
$i++;
}
}
示例5: update
/**
* Updates class variables.
*
* @param string $what set to just update a specific part of the tag
*
* @return void
*/
public function update($what = 'all')
{
/*
* Generate Class array.
*/
if ($what == 'all' || $what == 'classes') {
Generator::updateClasses($this);
}
/*
* Generate Class array.
*/
if ($what == 'all' || $what == 'urls') {
Generator::magicUrls($this);
}
/*
* Parse the content.
*/
if ($what == 'content') {
Content::parse($this);
}
if ($what == 'content' || $what == 'all' || $what == 'inlineInner') {
if ($this->hasOption('inlineInner') || $this->name !== 'blank' && !$this->hasOption('forbidInlineInner') && !$this->isSelfClosing() && !$this->hasOption('start') && strlen($this->content) < Config::get('maxLineWidth') && !preg_match('/\\r\\n|\\n|\\r/', $this->content)) {
$this->inlineInner = true;
} else {
$this->inlineInner = false;
}
}
if ($what == 'all' || $what == 'attributes') {
/*
* Sort Atrributes and Classes.
*/
ksort($this->attributes);
/*
* Parse the attributes to string format.
*/
$this->attributeString = Generator::attsToString($this);
}
}
示例6: supplement
/**
* Supplements the content in the set
*
* @param array $context Context for supplementing
* @return void
*/
public function supplement($context = array())
{
if ($this->supplemented) {
return;
}
$this->supplemented = true;
$context = Helper::ensureArray($context);
// determine context
$given_context = $context;
$context = array('locate_with' => isset($given_context['locate_with']) ? $given_context['locate_with'] : null, 'center_point' => isset($given_context['center_point']) ? $given_context['center_point'] : null, 'pop_up_template' => isset($given_context['pop_up_template']) ? $given_context['pop_up_template'] : null, 'list_helpers' => isset($given_content['list_helpers']) ? $given_context['list_helpers'] : true, 'context_urls' => isset($given_context['context_urls']) ? $given_context['context_urls'] : true, 'total_found' => isset($given_context['total_found']) ? $given_context['total_found'] : null, 'group_by_date' => isset($given_context['group_by_date']) ? $given_context['group_by_date'] : null);
// set up helper variables
$center_point = false;
if ($context['center_point'] && preg_match(Pattern::COORDINATES, $context['center_point'], $matches)) {
$center_point = array($matches[1], $matches[2]);
}
// contextual urls are based on current page, not individual data records
// we can figure this out once and then set it with each one
if ($context['context_urls']) {
$raw_url = Request::getResourceURI();
$page_url = preg_replace(Pattern::ORDER_KEY, '', Request::getResourceURI());
}
// iteration memory
$last_date = null;
// loop through content, supplementing each record with data
foreach ($this->content as $content_key => $data) {
// locate
if ($context['locate_with']) {
$location_data = isset($data[$context['locate_with']]) ? $data[$context['locate_with']] : null;
// check that location data is fully set
if (is_array($location_data) && isset($location_data['latitude']) && $location_data['latitude'] && isset($location_data['longitude']) && $location_data['longitude']) {
$data['latitude'] = $location_data['latitude'];
$data['longitude'] = $location_data['longitude'];
$data['coordinates'] = $location_data['latitude'] . "," . $location_data['longitude'];
// get distance from center
if ($center_point) {
$location = array($data['latitude'], $data['longitude']);
$data['distance_km'] = Math::getDistanceInKilometers($center_point, $location);
$data['distance_mi'] = Math::convertKilometersToMiles($data['distance_km']['distance_km']);
}
}
}
// pop-up template
if ($context['pop_up_template']) {
$data['marker_pop_up_content'] = Content::parse($context['pop_up_template'], $data, "html");
}
// contextual urls
if ($context['context_urls']) {
$data['raw_url'] = $raw_url;
$data['page_url'] = $page_url;
}
// total entries
if ($context['total_found']) {
$data['total_found'] = (int) $context['total_found'];
}
// group by date
if ($context['group_by_date'] && $data['datestamp']) {
$formatted_date = Date::format($context['group_by_date'], $data['datestamp']);
if ($formatted_date !== $last_date) {
$last_date = $formatted_date;
$data['grouped_date'] = $formatted_date;
} else {
$data['grouped_date'] = '';
}
}
// loop through content to add data for variables that are arrays
foreach ($data as $key => $value) {
// Only run on zero indexed arrays/loops
if (is_array($value) && isset($value[0]) && !is_array($value[0])) {
// list helpers
if ($context['list_helpers']) {
// make automagic lists
$data[$key . "_list"] = join(", ", $value);
$data[$key . "_spaced_list"] = join(" ", $value);
$data[$key . "_option_list"] = join("|", $value);
$data[$key . "_ordered_list"] = "<ol><li>" . join("</li><li>", $value) . "</li></ol>";
$data[$key . "_unordered_list"] = "<ul><li>" . join("</li><li>", $value) . "</li></ul>";
$data[$key . "_sentence_list"] = Helper::makeSentenceList($value);
$data[$key . "_ampersand_sentence_list"] = Helper::makeSentenceList($value, "&", false);
// handle taxonomies
if (Taxonomy::isTaxonomy($key)) {
$url_list = array_map(function ($item) use($data, $key, $value) {
return '<a href="' . Taxonomy::getURL($data['_folder'], $key, $item) . '">' . $item . '</a>';
}, $value);
$data[$key . "_url_list"] = join(", ", $url_list);
$data[$key . "_spaced_url_list"] = join(" ", $url_list);
$data[$key . "_ordered_url_list"] = "<ol><li>" . join("</li><li>", $url_list) . "</li></ol>";
$data[$key . "_unordered_url_list"] = "<ul><li>" . join("</li><li>", $url_list) . "</li></ul>";
$data[$key . "_sentence_url_list"] = Helper::makeSentenceList($url_list);
$data[$key . "_ampersand_sentence_url_list"] = Helper::makeSentenceList($url_list, "&", false);
}
}
}
}
// update content with supplemented data merged with global config data
//.........这里部分代码省略.........
示例7: buildScript
private function buildScript($content, $settings)
{
$classes = ($settings['map_class']) ? ' class="' . $settings['map_class'] . '"' : '';
$html = '<div class="map' . $classes . '" id="' . $settings['map_id'] . '"></div>';
$html .= "\n";
$html .= '<script type="text/javascript">';
$html .= "try{_location_maps.length;}catch(e){var _location_maps={};}\n";
$html .= '_location_maps["' . $settings['map_id'] . '"] = { markers: [ ';
$markers = array();
foreach ($content as $item) {
$marker = array(
'latitude' => $item['latitude'],
'longitude' => $item['longitude'],
'marker_content' => Content::parse($this->content, $item, "html")
);
array_push($markers, json_encode($marker));
}
$html .= join(",\n", $markers);
$html .= ' ], ';
$html .= ' clusters: ' . $settings['clusters'] . ',';
// cluster options
$html .= ' spiderfy_on_max_zoom: ' . $settings['spiderfy_on_max_zoom'] . ',';
$html .= ' show_coverage_on_hover: ' . $settings['show_coverage_on_hover'] . ',';
$html .= ' zoom_to_bounds_on_click: ' . $settings['zoom_to_bounds_on_click'] . ',';
$html .= ' single_marker_mode: ' . $settings['single_marker_mode'] . ',';
$html .= ' animate_adding_markers: ' . $settings['animate_adding_markers'] . ',';
$html .= ' disable_clustering_at_zoom: ' . $settings['disable_clustering_at_zoom'] . ',';
$html .= ' max_cluster_radius: ' . $settings['max_cluster_radius'] . ',';
// map settings
$html .= ' starting_latitude: ' . $settings['starting_latitude'] . ',';
$html .= ' starting_longitude: ' . $settings['starting_longitude'] . ',';
$html .= ' starting_zoom: ' . $settings['starting_zoom'] . ',';
$html .= ' mapping_tiles: \'' . $settings['tiles'] . '\',';
$html .= ' mapping_subdomains: \'' . $settings['subdomains'] . '\',';
$html .= ' attribution: \'' . $settings['attribution'] . '\',';
$html .= ' mapping_api_key: \'' . $settings['mapping_service_api_key'] . '\',';
$html .= ' mapping_style: \'' . $settings['mapping_service_style'] . '\',';
$html .= ' min_zoom: ' . $settings['min_zoom'] . ',';
$html .= ' max_zoom: ' . $settings['max_zoom'] . ',';
$html .= ' scroll_wheel_zoom: ' . $settings['interaction_scroll_wheel_zoom'] . ',';
$html .= ' double_click_zoom: ' . $settings['interaction_double_click_zoom'] . ',';
$html .= ' box_zoom: ' . $settings['interaction_box_zoom'] . ',';
$html .= ' touch_zoom: ' . $settings['interaction_touch_zoom'] . ',';
$html .= ' draggable: ' . $settings['interaction_draggable'] . ',';
$html .= ' tap: ' . $settings['interaction_tap'] . ',';
$html .= ' open_popup: ' . $settings['open_popup'] . ',';
$html .= ' auto_center: ' . $settings['auto_center'] . '};';
$html .= '</script>';
// mark that the build script has run, and thus, smart_include should include
$this->blink->set('maps_used', true);
return $html;
}
示例8: retrieveContent
/**
* Grabs content for a given content file, caching it if necessary
*
* @param array $content_item Content item as stored in the system cache
* @return string
*/
public static function retrieveContent($content_item)
{
$content_file = isset($content_item['_file']) ? $content_item['_file'] : null;
$content = array('raw' => '', 'parsed' => '');
// content file doesn't exist
if (!$content_file || !File::exists($content_file)) {
// return nothing
return $content;
}
// make this
$raw_file = substr(File::get($content_file), 3);
$divide = strpos($raw_file, "\n---");
$content['raw'] = trim(substr($raw_file, $divide + 4));
$content['parsed'] = Content::parse($content['raw'], $content_item);
return $content;
}
示例9: parse
public static function parse(&$src)
{
$args = func_get_args();
array_shift($args);
$result = array();
\org\rhaco\Xml::set($x, '<:>' . $src . '</:>');
foreach ($x->in('entry') as $in) {
$o = new self();
$o->id($in->f('id.value()'));
$o->title($in->f('title.value()'));
$o->published($in->f('published.value()'));
$o->updated($in->f('updated.value()'));
$o->issued($in->f('issued.value()'));
$value = $in->value();
$o->content = Content::parse($value);
$o->summary = Summary::parse($value);
$o->link = Link::parse($value);
$o->author = Author::parse($value);
$result[] = $o;
$src = str_replace($in->plain(), '', $src);
}
return $result;
}