本文整理汇总了PHP中p_cached_instructions函数的典型用法代码示例。如果您正苦于以下问题:PHP p_cached_instructions函数的具体用法?PHP p_cached_instructions怎么用?PHP p_cached_instructions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了p_cached_instructions函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCleanInstructions
function getCleanInstructions($file)
{
$instructions = p_cached_instructions($file);
$ret = array();
$i = 0;
foreach ($instructions as $ins) {
switch ($ins[0]) {
# Filter out sections and document start/end instructions
case 'document_start':
case 'document_end':
case 'section_open':
case 'section_close':
break;
# Start new block of instructions on paragraph end
# Start new block of instructions on paragraph end
case 'p_close':
$ret[$i++][] = $ins;
break;
# Add the instruction to current block
# Add the instruction to current block
default:
$ret[$i][] = $ins;
break;
}
}
return $ret;
}
示例2: generateODT
/**
* Build a ODT from the articles
*
* @param string $cachefile
* @param string $title
*/
protected function generateODT($cachefile, $title)
{
global $ID;
global $REV;
/** @var renderer_plugin_odt_book $odt */
$odt = plugin_load('renderer', 'odt_book');
// store original pageid
$keep = $ID;
// loop over all pages
$xmlcontent = '';
$cnt = count($this->list);
for ($n = 0; $n < $cnt; $n++) {
$page = $this->list[$n];
// set global pageid to the rendered page
$ID = $page;
$xmlcontent .= p_render('odt_book', p_cached_instructions(wikiFN($page, $REV), false, $page), $info);
}
//restore ID
$ID = $keep;
$odt->doc = $xmlcontent;
$odt->setTitle($title);
$odt->finalize_ODTfile();
// write to cache file
io_savefile($cachefile, $odt->doc);
}
示例3: handle_tpl_act_render
public function handle_tpl_act_render(Doku_Event &$event, $param)
{
global $ID;
global $INFO;
global $DOKUTRANSLATE_EDITFORM;
if (!@file_exists(metaFN($ID, '.translate'))) {
return;
}
# Disable TOC on translated pages
$INFO['prependTOC'] = false;
if (in_array($event->data, array('edit', 'preview'))) {
# Take the event over
$event->preventDefault();
# Save the edit form for later
html_edit();
$DOKUTRANSLATE_EDITFORM = ob_get_clean();
ob_start();
# Render the page (renderer inserts saved edit form
# and preview in the right cell)
echo p_render('xhtml', p_cached_instructions(wikiFN($ID)), $INFO);
}
}
示例4: handle_item_add
/**
* Preprocesses a blog post as its added to the feed. Makes sure to
* remove the first header from the text (otherwise it would be doubled)
* and takes care of presentation as configured via template.
*
* @param $event the event as triggered in feed.php
* @param $param empty
* @return void
*/
function handle_item_add(&$event, $param)
{
$opt = $event->data['opt'];
$ditem = $event->data['ditem'];
if ($opt['feed_mode'] !== 'blogtng') {
return;
}
if ($opt['item_content'] !== 'html') {
return;
}
if ($opt['link_to'] !== 'current') {
return;
}
// don't add drafts to the feed
if (p_get_metadata($ditem['id'], 'type') == 'draft') {
$event->preventDefault();
return;
}
// retrieve first heading from page instructions
$ins = p_cached_instructions(wikiFN($ditem['id']));
$headers = array_filter($ins, array($this, '_filterHeaders'));
$headingIns = array_shift($headers);
$firstheading = $headingIns[1][0];
$this->entryhelper->load_by_row($ditem['entry']);
$output = '';
ob_start();
$this->entryhelper->tpl_content($ditem['entry']['blog'], 'feed');
$output = ob_get_contents();
ob_end_clean();
// make URLs work when canonical is not set, regexp instead of rerendering!
global $conf;
if (!$conf['canonical']) {
$base = preg_quote(DOKU_REL, '/');
$output = preg_replace('/(<a href|<img src)="(' . $base . ')/s', '$1="' . DOKU_URL, $output);
}
// strip first heading and replace item title
$event->data['item']->description = preg_replace('#[^\\n]*?>\\s*?' . preg_quote(hsc($firstheading), '#') . '\\s*?<.*\\n#', '', $output, 1);
$event->data['item']->title = $ditem['entry']['title'];
}
示例5: _render_output
function _render_output($renderer, $addID, $mode)
{
global $ID;
//get data(in instructions format) from $file (dont use cache: false)
$file = wikiFN($addID);
$instr = p_cached_instructions($file, false);
//page was empty
if (empty($instr)) {
return;
}
// Convert Link instructions
$instr = $this->_convertInstructions($instr, $addID, $renderer);
// Section IDs
$check = null;
$addID = sectionID($addID, $check);
//not possible to use a:b:c for id
if ($mode == 'xhtml') {
//--------RENDER
//renderer information(TOC build / Cache used)
$info = array();
$content = p_render($mode, $instr, $info);
//Remove TOC`s, section edit buttons and tags
$content = $this->_cleanXHTML($content);
// embed the included page
$renderer->doc .= '<div class="include">';
//add an anchor to find start of a inserted page
$renderer->doc .= "<a name='{$addID}' id='{$addID}'>";
$renderer->doc .= $content;
$renderer->doc .= '</div>';
} else {
if ($mode == 'odt') {
$renderer->doc .= '<text:bookmark text:name="' . $addID . '"/>';
// Loop through the instructions
foreach ($instr as $instruction) {
// Execute the callback against the Renderer
call_user_func_array(array($renderer, $instruction[0]), $instruction[1]);
}
}
}
}
示例6: _get_instructions
/**
* Returns the converted instructions of a give page/section
*
* @author Michael Klier <chi@chimeric.de>
* @author Michael Hamann <michael@content-space.de>
*/
function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null, $included_pages = array()) {
$key = ($sect) ? $page . '#' . $sect : $page;
$this->includes[$key] = true; // legacy code for keeping compatibility with other plugins
// keep compatibility with other plugins that don't know the $root_id parameter
if (is_null($root_id)) {
global $ID;
$root_id = $ID;
}
if ($flags['linkonly']) {
if (page_exists($page) || $flags['pageexists'] == 0) {
$title = '';
if ($flags['title'])
$title = p_get_first_heading($page);
if($flags['parlink']) {
$ins = array(
array('p_open', array()),
array('internallink', array(':'.$key, $title)),
array('p_close', array()),
);
} else {
$ins = array(array('internallink', array(':'.$key,$title)));
}
}else {
$ins = array();
}
} else {
if (page_exists($page)) {
global $ID;
$backupID = $ID;
$ID = $page; // Change the global $ID as otherwise plugins like the discussion plugin will save data for the wrong page
$ins = p_cached_instructions(wikiFN($page), false, $page);
$ID = $backupID;
} else {
$ins = array();
}
$this->_convert_instructions($ins, $lvl, $page, $sect, $flags, $root_id, $included_pages);
}
return $ins;
}
示例7: gather_data
/**
* Gathers all page and media data for given namespaces.
*
* @namespaces array() of namespaces
* @depth Search depth
* @include_media Determines if media should be regarded, Values: 'ns','all','none'.
* @use_cached_pages Determines if only cached pages should be used. If this option is turned off, the operation will cache all non-cached pages within the namespace.
* @use_first_header Determines if the first header is used for title of the pages.
*
* @return array with pages and media: array('pages'=>pages, 'media'=>media).
*/
function gather_data($namespaces, $depth = 0, $include_media = 'none', $use_cached_pages = true, $use_first_header = false)
{
global $conf;
$transplugin = plugin_load('helper', 'translation');
$pages = array();
$media = array();
// Loop through the namespaces
foreach ($namespaces as $ns) {
// Get the media of the namespace
if ($include_media == 'ns') {
$this->get_media($media, $ns, $depth);
}
// Get the pages of the namespace
$this->get_pages($pages, $ns, $depth, $use_first_header);
}
// Loop through the pages to get links and media
foreach ($pages as $pid => $item) {
// get instructions
$ins = p_cached_instructions(wikiFN($pid), $use_cached_pages, $pid);
// find links and media usage
foreach ($ins as $i) {
$mid = null;
// Internal link?
if ($i[0] == 'internallink') {
$id = $i[1][0];
$exists = true;
resolve_pageid($item['ns'], $id, $exists);
list($id) = explode('#', $id, 2);
if ($id == $pid) {
continue;
}
// skip self references
if ($exists && isset($pages[$id])) {
$pages[$pid]['links'][] = $id;
}
if (is_array($i[1][1]) && $i[1][1]['type'] == 'internalmedia') {
$mid = $i[1][1]['src'];
// image link
} else {
continue;
// we're done here
}
}
if ($i[0] == 'internalmedia') {
$mid = $i[1][0];
}
if (is_null($mid)) {
continue;
}
if ($include_media == 'none') {
continue;
}
// no media wanted
$exists = true;
resolve_mediaid($item['ns'], $mid, $exists);
list($mid) = explode('#', $mid, 2);
$mid = cleanID($mid);
if ($exists) {
if ($include_media == 'all') {
if (!isset($media[$mid])) {
//add node
$media[$mid] = array('size' => filesize(mediaFN($mid)), 'time' => filemtime(mediaFN($mid)), 'ns' => getNS($mid), 'title' => noNS($mid));
}
$pages[$pid]['media'][] = $mid;
} elseif (isset($media[$mid])) {
$pages[$pid]['media'][] = $mid;
}
}
}
// clean up duplicates
$pages[$pid]['links'] = array_unique($pages[$pid]['links']);
$pages[$pid]['media'] = array_unique($pages[$pid]['media']);
}
return array('pages' => $pages, 'media' => $media);
}
示例8: loadlabels
/**
* Initializes the labels, loaded from a defined labelpage
*
* @param array $data all data passed to render()
*/
protected function loadlabels(&$data)
{
global $INFO;
$labelpage = $data['labels'];
$exists = false;
resolve_pageid($INFO['namespace'], $labelpage, $exists);
if (!$exists) {
msg(sprintf($this->getLang('e_labelpage'), html_wikilink($labelpage)), -1);
return;
}
// parse simple list (first level cdata only)
$labels = array();
$instructions = p_cached_instructions(wikiFN($labelpage));
$inli = 0;
$item = '';
foreach ($instructions as $instruction) {
if ($instruction[0] == 'listitem_open') {
$inli++;
continue;
}
if ($inli === 1 && $instruction[0] == 'cdata') {
$item .= $instruction[1][0];
}
if ($instruction[0] == 'listitem_close') {
$inli--;
if ($inli === 0) {
list($k, $v) = explode('=', $item, 2);
$k = trim($k);
$v = trim($v);
if ($k && $v) {
$labels[$k] = $v;
}
$item = '';
}
}
}
// apply labels to all fields
$len = count($data['fields']);
for ($i = 0; $i < $len; $i++) {
if (isset($data['fields'][$i]->depends_on)) {
// translate dependency on fieldsets
$label = $data['fields'][$i]->depends_on[0];
if (isset($labels[$label])) {
$data['fields'][$i]->depends_on[0] = $labels[$label];
}
} else {
if (isset($data['fields'][$i]->opt['label'])) {
// translate field labels
$label = $data['fields'][$i]->opt['label'];
if (isset($labels[$label])) {
$data['fields'][$i]->opt['display'] = $labels[$label];
}
}
}
}
if (isset($data['thanks'])) {
if (isset($labels[$data['thanks']])) {
$data['thanks'] = $labels[$data['thanks']];
}
}
}
示例9: handle_action_act_preprocess_after
/**
* Handler for the ACTION_ACT_PREPROCESS event and AFTER advise.
*
* Sends linkback if previous action was 'save' and new one is show.
*/
function handle_action_act_preprocess_after(&$event, $params)
{
global $ID;
global $ACT;
global $conf;
// only perform linkbacks on save of a wikipage
if ($this->preact != 'save' || $event->data != 'show') {
return;
}
// if guests are not allowed to perform linkbacks, return
if (!$this->getConf('allow_guests') && !$_SERVER['REMOTE_USER']) {
return;
}
// get linkback meta file name
$file = metaFN($ID, '.linkbacks');
$data = array('send' => false, 'receive' => false, 'display' => false, 'sentpings' => array(), 'receivedpings' => array(), 'number' => 0);
if (@file_exists($file)) {
$data = unserialize(io_readFile($file, false));
}
$data['send'] = $_REQUEST['plugin__linkback_toggle'] ? true : false;
if (!$data['send']) {
return;
}
$meta = p_get_metadata($ID);
// prepare linkback info
$linkback_info = array();
$linkback_info['title'] = tpl_pagetitle($ID, true);
$linkback_info['url'] = wl($ID, '', true);
$linkback_info['blog_name'] = $conf['title'];
$linkback_info['excerpt'] = $meta['description']['abstract'];
// get links
$ilist = p_cached_instructions(wikiFN($ID), false, $ID);
if (!is_array($ilist)) {
return;
}
$pages = $this->_parse_instructionlist($ilist);
$sentpings = array();
foreach ($pages as $page) {
if (!$data['sentpings'][$page]) {
// try to ping pages not already pinged
$this->_ping_page($page, $linkback_info);
}
$sentpings[$page] = true;
}
$data['sentpings'] = $sentpings;
// save sent ping info
io_saveFile($file, serialize($data));
return true;
}
示例10: index_media_use
/**
* Index media usage data
*
* @param Doku_Event $event The event object
* @param array $param Optional parameters (unused)
*/
public function index_media_use(Doku_Event $event, $param) {
// From indexer version 6 on the media references are indexed by DokuWiki itself
if (INDEXER_VERSION >= 6) return;
$id = $event->data['page'];
$media_references = array();
$instructions = p_cached_instructions(wikiFn($id), false, $id);
if (is_array($instructions)) {
$this->get_media_references_from_instructions($instructions, $media_references, $id);
}
$media_references = array_unique($media_references);
$event->data['metadata']['relation_media'] = $media_references;
}
示例11: parse
/**
*
*/
private function parse()
{
$text = io_readWikiPage($this->fileName, $this->id);
$call = p_cached_instructions($this->fileName);
$calls = count($call);
for ($c = 0; $c < $calls; $c++) {
if ($call[$c][0] == 'table_open') {
$c = $this->parseTable($call, $calls, $c, $text);
} elseif ($call[$c][0] == 'code') {
$this->parseCode($call[$c]);
} elseif ($call[$c][0] == 'plugin' && $call[$c][1][0] == 'data_entry') {
$this->parseDataEntry($call[$c][1][1]);
}
}
}
示例12: _get_instructions
/**
* Returns the converted instructions of a give page/section
*
* @author Michael Klier <chi@chimeric.de>
* @author Michael Hamann <michael@content-space.de>
*/
function _get_instructions($page, $sect, $mode, $lvl, $flags, $root_id = null)
{
$key = $sect ? $page . '#' . $sect : $page;
$this->includes[$key] = true;
// legacy code for keeping compatibility with other plugins
// keep compatibility with other plugins that don't know the $root_id parameter
if (is_null($root_id)) {
global $ID;
$root_id = $ID;
}
if ($flags['linkonly']) {
$ins = array(array('p_open', array()), array('internallink', array(':' . $key)), array('p_close', array()));
} else {
if (page_exists($page)) {
$ins = p_cached_instructions(wikiFN($page));
} else {
$ins = array();
}
$this->_convert_instructions($ins, $lvl, $page, $sect, $flags, $root_id);
}
return $ins;
}
示例13: get_entrycontent
/**
* FIXME
* @param $readmore
* @param $inc_level
* @param $skipheader
* @return unknown_type
*/
function get_entrycontent($readmore = 'syntax', $inc_level = true, $skipheader = false)
{
static $recursion = array();
$id = $this->entry['page'];
if (in_array($id, $recursion)) {
msg('blogtng: preventing infinite loop', -1);
return false;
// avoid infinite loops
}
$recursion[] = $id;
// FIXME do some caching here!
global $ID, $TOC, $conf;
$info = array();
$ins = p_cached_instructions(wikiFN($id));
$this->_convert_instructions($ins, $inc_level, $readmore, $skipheader);
$backupID = $ID;
$ID = $id;
$handleTOC = $this->renderer !== null;
// the call to p_render below might set the renderer
if ($handleTOC) {
$renderer =& $this->renderer;
// save the renderer before p_render changes it
$backupTOC = $TOC;
// the renderer overwrites the global $TOC
$backupTocminheads = $conf['tocminheads'];
$conf['tocminheads'] = 1;
// let the renderer always generate a toc
}
$content = p_render('xhtml', $ins, $info);
if ($handleTOC) {
if ($TOC && $backupTOC !== $TOC && $info['toc']) {
$renderer->toc = array_merge($renderer->toc, $TOC);
$TOC = null;
// Reset the global toc as it is included in the renderer now
// and if the renderer decides to not to output it the
// global one should be empty
}
$conf['tocminheads'] = $backupTocminheads;
$this->renderer =& $renderer;
}
$ID = $backupID;
array_pop($recursion);
return $content;
}
示例14: setSectionLevels
/**
* Keeps section levels
*/
function setSectionLevels($calls = null)
{
global $ID;
global $conf;
if ($calls === null) {
$calls = p_cached_instructions(wikiFN($ID), 'cacheonly');
}
list($handler_name, $instructions) = array(0, 1);
$this->section_levels = array('dummy_entry_for_padding');
for ($i = 0, $i_max = count($calls); $i < $i_max; $i++) {
if ($calls[$i][$handler_name] === 'section_open') {
$section_level = $calls[$i][$instructions][0];
if ($section_level <= $conf['maxseclevel']) {
$this->section_levels[] = $section_level;
}
}
}
}
示例15: gather_data
/**
* Find all the node and edge data for the given namespaces
*/
function gather_data($namespaces, $depth = 0, $incmedia = 'ns')
{
global $conf;
$transplugin = plugin_load('helper', 'translation');
$pages = array();
$media = array();
foreach ($namespaces as $ns) {
// find media
if ($incmedia == 'ns') {
$data = array();
search($data, $conf['mediadir'], 'search_universal', array('depth' => $depth, 'listfiles' => true, 'listdirs' => false, 'pagesonly' => false, 'skipacl' => true, 'keeptxt' => true, 'meta' => true), str_replace(':', '/', $ns));
// go through all those media files
while ($item = array_shift($data)) {
$media[$item['id']] = array('title' => noNS($item['id']), 'size' => $item['size'], 'ns' => getNS($item['id']), 'time' => $item['mtime']);
}
}
// find pages
$data = array();
search($data, $conf['datadir'], 'search_universal', array('depth' => $depth, 'listfiles' => true, 'listdirs' => false, 'pagesonly' => true, 'skipacl' => true, 'firsthead' => true, 'meta' => true), str_replace(':', '/', $ns));
// ns start page
if ($ns && page_exists($ns)) {
$data[] = array('id' => $ns, 'ns' => getNS($ns), 'title' => p_get_first_heading($ns, false), 'size' => filesize(wikiFN($ns)), 'mtime' => filemtime(wikiFN($ns)), 'perm' => 16, 'type' => 'f', 'level' => 0, 'open' => 1);
}
// go through all those pages
while ($item = array_shift($data)) {
$time = (int) p_get_metadata($item['id'], 'date created', false);
if (!$time) {
$time = $item['mtime'];
}
$lang = $transplugin ? $transplugin->getLangPart($item['id']) : '';
if ($lang) {
$item['ns'] = preg_replace('/^' . $lang . '(:|$)/', '', $item['ns']);
}
$pages[$item['id']] = array('title' => $item['title'], 'ns' => $item['ns'], 'size' => $item['size'], 'time' => $time, 'links' => array(), 'media' => array(), 'lang' => $lang);
}
}
// now get links and media
foreach ($pages as $pid => $item) {
// get instructions
$ins = p_cached_instructions(wikiFN($pid), false, $pid);
// find links and media usage
foreach ($ins as $i) {
$mid = null;
if ($i[0] == 'internallink') {
$id = $i[1][0];
$exists = true;
resolve_pageid($item['ns'], $id, $exists);
list($id) = explode('#', $id, 2);
if ($id == $pid) {
continue;
}
// skip self references
if ($exists && isset($pages[$id])) {
$pages[$pid]['links'][] = $id;
}
if (is_array($i[1][1]) && $i[1][1]['type'] == 'internalmedia') {
$mid = $i[1][1]['src'];
// image link
} else {
continue;
// we're done here
}
}
if ($i[0] == 'internalmedia') {
$mid = $i[1][0];
}
if (is_null($mid)) {
continue;
}
if ($incmedia == 'none') {
continue;
}
// no media wanted
$exists = true;
resolve_mediaid($item['ns'], $mid, $exists);
list($mid) = explode('#', $mid, 2);
$mid = cleanID($mid);
if ($exists) {
if ($incmedia == 'all') {
if (!isset($media[$mid])) {
//add node
$media[$mid] = array('size' => filesize(mediaFN($mid)), 'time' => filemtime(mediaFN($mid)), 'ns' => getNS($mid), 'title' => noNS($mid));
}
$pages[$pid]['media'][] = $mid;
} elseif (isset($media[$mid])) {
$pages[$pid]['media'][] = $mid;
}
}
}
// clean up duplicates
$pages[$pid]['links'] = array_unique($pages[$pid]['links']);
$pages[$pid]['media'] = array_unique($pages[$pid]['media']);
}
return array('pages' => $pages, 'media' => $media);
}