当前位置: 首页>>代码示例>>PHP>>正文


PHP Parser::replaceVariables方法代码示例

本文整理汇总了PHP中Parser::replaceVariables方法的典型用法代码示例。如果您正苦于以下问题:PHP Parser::replaceVariables方法的具体用法?PHP Parser::replaceVariables怎么用?PHP Parser::replaceVariables使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Parser的用法示例。


在下文中一共展示了Parser::replaceVariables方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: build

 public function build()
 {
     $article = $this->Agent->getArticle();
     $text = $article->getContent(true);
     # Strip comments and <nowiki>
     $text = preg_replace("/<!--.*?-->/s", "", $text);
     $text = preg_replace("@<nowiki>.*?</nowiki>@s", "", $text);
     # change template usage to substitution; note that this is WRONG
     #$tchars = Title::legalChars();
     #$text = preg_replace("/(?<!{){{([$tchars]+)(\|.*?)?}}(?!})/", "{{subst:$1$2}}", $text);
     $parser = new Parser();
     # so the magic variables work out right
     $parser->mOptions = new ParserOptions();
     $parser->mTitle = $this->Agent->getTitle();
     $parser->mOutputType = OT_WIKI;
     $parser->initialiseVariables();
     $parser->clearState();
     $text = $parser->replaceVariables($text);
     preg_match_all("@<rdf>(.*?)</rdf>@s", $text, $matches, PREG_PATTERN_ORDER);
     $content = $matches[1];
     $rdf = implode(' ', array_values($content));
     $model = MwRdf::Model();
     if (strlen($rdf) > 0) {
         $parser->mOutputType = OT_HTML;
         $rdf = $parser->replaceVariables($rdf);
         $turtle_parser = MwRdf::Parser('turtle');
         $base_uri = $this->Agent->getTitle()->getFullUrl();
         $prelude = MwRdf::getNamespacePrelude();
         $model->loadStatementsFromString($turtle_parser, $prelude . $rdf);
     }
     return $model;
 }
开发者ID:schwarer2006,项目名称:wikia,代码行数:32,代码来源:InPage.php

示例2: render

 public static function render($input, $args, Parser $parser)
 {
     // Create InputBox
     $inputBox = new InputBox($parser);
     // Configure InputBox
     $inputBox->extractOptions($parser->replaceVariables($input));
     // Return output
     return $inputBox->render();
 }
开发者ID:Grprashanthkumar,项目名称:ColfusionWeb,代码行数:9,代码来源:InputBox.hooks.php

示例3: parserHook

 /**
  * Parser hook for the <opengraph> tag.
  * 
  * This tag is dual-purpose. By specifying the "type" attribute, the type
  * of Open Graph object represented by the wiki page can be set. The
  * additional attributes set the <meta> properties for the object. Even
  * if "type" isn't specified, the other attributes can still be used to
  * override the default properties.
  * 
  * If the "action" attribute is given, this tag will render a link that,
  * when clicked, adds an action to the Facebook user's Timeline with the
  * wiki page as the target object. If no action is given, $innertext is
  * discarded.
  */
 public static function parserHook($innertext, array $args, Parser $parser, PPFrame $frame)
 {
     global $wgFbOpenGraph, $wgFbOpenGraphCustomObjects;
     if (empty($wgFbOpenGraph) || empty($wgFbOpenGraphCustomObjects)) {
         return '';
         // Open Graph is disabled for this wiki
     }
     if (isset($args['action'])) {
         $action = $args['action'];
         unset($args['action']);
     } else {
         $action = '';
     }
     if (count($args)) {
         foreach ($args as $key => $value) {
             // Expand template arguments
             $value = trim($parser->replaceVariables($value, $frame));
             // Check if $value is a wiki link
             if (substr($value, 0, 2) == '[[') {
                 $resolved = $parser->replaceInternalLinks($value);
                 $parser->replaceLinkHolders($resolved);
                 preg_match('/^<a\\b[^<>]*?\\bhref=("[^"]*"|\'[^\']*\')/', $resolved, $matches);
                 if (count($matches) >= 2) {
                     global $wgServer;
                     // strip quotes
                     $matches[1] = substr($matches[1], 1, strlen($matches[1]) - 2);
                     $url = $wgServer . $matches[1];
                 }
             }
             $value = !empty($url) ? $url : $parser->recursiveTagParse($value, $frame);
             $args[$key] = htmlspecialchars($value);
         }
         self::registerProperties($parser->getTitle(), $args);
     }
     // TODO: Insert a placeholder so that actions can be placed above type definitions on the page
     if ($action != '') {
         // See if the action is available for the object type
         $object = self::newObjectFromTitle($parser->getTitle());
         $actions = $object->getCustomActions();
         if (count($actions) && in_array($action, $actions)) {
             // Let the page know it should load the actions module
             global $wgVersion;
             if (version_compare($wgVersion, '1.17', '>=')) {
                 global $wgOut;
                 $wgOut->addModules('ext.facebook.actions');
             }
             $innertext = htmlspecialchars($parser->replaceVariables($innertext, $frame));
             return '<a href="#" class="mw-facebook-logo opengraph-action opengraph-action-' . $action . '">' . $innertext . '</a>';
         }
     }
     return '';
 }
开发者ID:Jobava,项目名称:diacritice-meta-repo,代码行数:66,代码来源:FacebookOpenGraph.php

示例4: wfCOQuestionBoxRender

function wfCOQuestionBoxRender($input, $argv, Parser $parser)
{
    global $wgUser;
    if (wfReadOnly() || !$wgUser->isAllowed('edit') || $wgUser->isBlocked()) {
        return '';
    }
    $submit = SpecialPage::getTitleFor("NewCommentsOnlyQuestion")->getLocalURL();
    $text = '';
    $width = 100;
    //TODO read params from input
    $label = wfMsgHtml('comments-only-new-thread');
    $output = <<<ENDFORM
<div class="questionbox">
<form name="questionbox" action="{$submit}" method="get" class="questionboxForm">
<input class="questionboxInput" name="question" type="text" value="{$text}" size="{$width}"/>
<input type='submit' name="create" class="questionboxButton" value="{$label}"/>
</form></div>
ENDFORM;
    return $parser->replaceVariables($output);
}
开发者ID:schwarer2006,项目名称:wikia,代码行数:20,代码来源:CommentsOnly.php

示例5: parseArticleText

 function parseArticleText($text)
 {
     if ($text === '') {
         return '';
     } else {
         if ($this->mExpandTemplates) {
             global $wgTitle;
             $parser = new Parser();
             $parser->Options(new ParserOptions());
             // We don't want this to be user-specific
             $parser->Title($wgTitle);
             $parser->OutputType(OT_HTML);
             return $parser->replaceVariables($text);
         } else {
             return $text;
         }
     }
 }
开发者ID:k-hasan-19,项目名称:wiki,代码行数:18,代码来源:RawPage.php

示例6: parse

 protected function parse($wikitext, $params, $newline = false)
 {
     $withVars = $this->parser->replaceVariables($wikitext, $this->parser->getPreprocessor()->newCustomFrame($params));
     $parserOutput = $this->parser->parse($withVars, $this->parser->getTitle(), $this->parser->getOptions(), $newline);
     return preg_replace('|{{{.*}}}|Us', '', preg_replace('|[\\n\\r]|Us', '', $parserOutput->getText()));
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:6,代码来源:MediaWikiParserTest.php

示例7: MwRdfInPage

 function MwRdfInPage($article)
 {
     $text = $article->getContent(true);
     $parser = new Parser();
     $text = $parser->preprocess($text, $article->mTitle, new ParserOptions());
     preg_match_all("@<rdf>(.*?)</rdf>@s", $text, $matches, PREG_PATTERN_ORDER);
     $content = $matches[1];
     $rdf = implode(' ', array_values($content));
     $model = null;
     if (strlen($rdf) > 0) {
         $parser->mOutputType = OT_HTML;
         $rdf = $parser->replaceVariables($rdf);
         global $default_prefixes, $wgRdfNamespaces;
         require_once RDFAPI_INCLUDE_DIR . PACKAGE_SYNTAX_N3;
         $parser = new N3Parser();
         $parser->baseURI = $article->mTitle->getFullURL();
         $prefixes = array_merge($default_prefixes, $wgRdfNamespaces, MwRdfNamespacePrefixes());
         $prelude = "";
         foreach ($prefixes as $prefix => $uri) {
             $prelude .= "@prefix {$prefix}: <{$uri}> .\n";
         }
         # XXX: set correct properties
         $model = $parser->parse2model($prelude . $rdf);
         if ($model === false) {
             global $RDFS_comment;
             $model = ModelFactory::getDefaultModel();
             $model->add(new Statement(MwRdfArticleResource($article), $RDFS_comment, MwRdfLiteral("Error parsing in-page RDF: " . $parser->errors[0] . "\n code here: \n '" . $prelude . $rdf . "'", null, "en")));
         } else {
             # To make it unique, we unite with an empty model
             $fake = new MemModel();
             $model =& $fake->unite($model);
         }
     }
     return $model;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:35,代码来源:Rdf.php

示例8: render

 /**
  * Renrder the spark div.
  *
  * @since 0.1
  *
  * @param Parser $parser
  *
  * @return string
  */
 public function render(Parser $parser, $frame)
 {
     global $wgVersion;
     global $wgOut;
     global $egSparkScriptPath;
     global $wgResourceModules;
     // What is loaded already?
     static $loadedJsses = array();
     wfDebugLog('myextension', 'Parameters alright? ' . print_r($this->parameters, true));
     if (array_key_exists(egSparkQuery, $this->parameters)) {
         $query = htmlspecialchars($this->parameters[egSparkQuery]);
         // Before that, shall we allow internal parse, at least for the query?
         // We replace variables, templates etc.
         $query = $parser->replaceVariables($query, $frame);
         //$query = $parser->recursiveTagParse( $query );
         // Replace special characters
         $query = str_replace(array('&lt;', '&gt;'), array('<', '>'), $query);
         unset($this->parameters[egSparkQuery]);
         // Depending on the format, we possibly need to add modules
         if (array_key_exists(egSparkFormat, $this->parameters)) {
             $format = htmlspecialchars($this->parameters[egSparkFormat]);
             // Remove everything before "spark.XXX"
             $format = substr($format, strpos($format, "spark."));
             // Remove .js at the end
             $format = str_replace(array('.js'), array(''), $format);
             $module = 'ext.' . $format;
             // for older versions of MW, different
             if (version_compare($wgVersion, '1.17', '<')) {
                 if (isset($wgResourceModules) && array_key_exists($module, $wgResourceModules)) {
                     // only if not already loaded
                     if (!isset($loadedJsses[$module])) {
                         // scripts
                         foreach ($wgResourceModules[$module]['scripts'] as $script) {
                             $wgOut->addScript('<script src="' . $egSparkScriptPath . "/" . $script . '" type="text/javascript"></script>');
                             wfDebugLog('spark', "AddScript:" . ' <script src="' . $egSparkScriptPath . "/" . $script . '" type="text/javascript"></script>');
                         }
                         // css
                         foreach ($wgResourceModules[$module]['styles'] as $style) {
                             $wgOut->addScript('<link rel="stylesheet" href="' . $egSparkScriptPath . "/" . $style . '" type="text/css" />');
                             wfDebugLog('spark', "AddLink:" . ' <link rel="stylesheet" href="' . $egSparkScriptPath . "/" . $style . '" type="text/css" />');
                         }
                         $loadedJsses[$module] = true;
                     }
                 }
             } else {
                 // $wgResourceModules might not exist
                 if (isset($wgResourceModules) && array_key_exists($module, $wgResourceModules)) {
                     // TODO: Do we need to check, whether module has been added already?
                     $parser->getOutput()->addModules($module);
                 }
             }
         }
         $html = '<div class="spark" data-spark-query="' . $query . '" ' . Html::expandAttributes($this->parameters) . ' >' . (is_null($this->contents) ? '' : htmlspecialchars($this->contents)) . '</div>';
         // In MW 1.17 there seems to be the problem that ? after an empty space is replaced by a non-breaking space (&#160;) Therefore we remove all spaces before ? which should still make the SPARQL query work
         $html = preg_replace('/[ \\t]+(\\?)/', '$1', $html);
         // for older versions of MW, different
         if (version_compare($wgVersion, '1.17', '<')) {
             $parser->disableCache();
             return $html;
         } else {
             return array($parser->insertStripItem($html, $parser->mStripState), 'noparse' => true, 'isHTML' => true);
         }
     } else {
         return Html::element('i', array(), wfMsg('spark-missing-query'));
     }
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:75,代码来源:Spark.class.php


注:本文中的Parser::replaceVariables方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。