/usr/share/php/texy/src/Texy/modules/TexyScriptModule.php is in php-texy 2.6-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | <?php
/**
* This file is part of the Texy! (http://texy.info)
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/
/**
* Scripts module.
*
* @author David Grudl
*/
final class TexyScriptModule extends TexyModule
{
/**
* @var callback|object script elements handler
* function myFunc($parser, $cmd, $args, $raw)
*/
public $handler;
/** @var string arguments separator */
public $separator = ',';
public function __construct($texy)
{
$this->texy = $texy;
$texy->addHandler('script', array($this, 'solve'));
$texy->registerLinePattern(
array($this, 'pattern'),
'#\{\{((?:[^'.TexyPatterns::MARK.'}]++|[}])+)\}\}()#U',
'script'
);
}
/**
* Callback for: {{...}}.
*
* @param TexyLineParser
* @param array regexp matches
* @param string pattern name
* @return TexyHtml|string|FALSE
*/
public function pattern($parser, $matches)
{
list(, $mContent) = $matches;
// [1] => ...
$cmd = trim($mContent);
if ($cmd === '') {
return FALSE;
}
$args = $raw = NULL;
// function(arg, arg, ...) or function: arg, arg
if ($matches = TexyRegexp::match($cmd, '#^([a-z_][a-z0-9_-]*)\s*(?:\(([^()]*)\)|:(.*))$#iu')) {
$cmd = $matches[1];
$raw = isset($matches[3]) ? trim($matches[3]) : trim($matches[2]);
if ($raw === '') {
$args = array();
} else {
$args = preg_split('#\s*' . preg_quote($this->separator, '#') . '\s*#u', $raw);
}
}
// Texy 1.x way
if ($this->handler) {
if (is_callable(array($this->handler, $cmd))) {
array_unshift($args, $parser);
return call_user_func_array(array($this->handler, $cmd), $args);
}
if (is_callable($this->handler)) {
return call_user_func_array($this->handler, array($parser, $cmd, $args, $raw));
}
}
// Texy 2 way
return $this->texy->invokeAroundHandlers('script', $parser, array($cmd, $args, $raw));
}
/**
* Finish invocation.
*
* @param TexyHandlerInvocation handler invocation
* @param string command
* @param array arguments
* @param string arguments in raw format
* @return TexyHtml|string|FALSE
*/
public function solve($invocation, $cmd, $args, $raw)
{
if ($cmd === 'texy') {
if (!$args) {
return FALSE;
}
switch ($args[0]) {
case 'nofollow':
$this->texy->linkModule->forceNoFollow = TRUE;
break;
}
return '';
} else {
return FALSE;
}
}
}
|