/usr/share/php/texy/src/Texy/modules/TexyFigureModule.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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | <?php
/**
* This file is part of the Texy! (http://texy.info)
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/
/**
* The captioned figures.
*
* @author David Grudl
*/
final class TexyFigureModule extends TexyModule
{
/** @var string non-floated box CSS class */
public $class = 'figure';
/** @var string left-floated box CSS class */
public $leftClass;
/** @var string right-floated box CSS class */
public $rightClass;
/** @var int how calculate div's width */
public $widthDelta = 10;
public function __construct($texy)
{
$this->texy = $texy;
$texy->addHandler('figure', array($this, 'solve'));
$texy->registerBlockPattern(
array($this, 'pattern'),
'#^\[\* *+([^\n'.TexyPatterns::MARK.']{1,1000})'.TexyPatterns::MODIFIER.'? *+(\*|(?<!<)>|<)\]' // [* urls .(title)[class]{style} >]
. '(?::('.TexyPatterns::LINK_URL.'|:))?? ++\*\*\* ++(.{0,2000})'.TexyPatterns::MODIFIER_H.'?()$#mUu',
'figure'
);
}
/**
* Callback for [*image*]:link *** .... .(title)[class]{style}>.
*
* @param TexyBlockParser
* @param array regexp matches
* @param string pattern name
* @return TexyHtml|string|FALSE
*/
public function pattern($parser, $matches)
{
list(, $mURLs, $mImgMod, $mAlign, $mLink, $mContent, $mMod) = $matches;
// [1] => URLs
// [2] => .(title)[class]{style}<>
// [3] => * < >
// [4] => url | [ref] | [*image*]
// [5] => ...
// [6] => .(title)[class]{style}<>
$tx = $this->texy;
$image = $tx->imageModule->factoryImage($mURLs, $mImgMod.$mAlign);
$mod = new TexyModifier($mMod);
$mContent = ltrim($mContent);
if ($mLink) {
if ($mLink === ':') {
$link = new TexyLink($image->linkedURL === NULL ? $image->URL : $image->linkedURL);
$link->raw = ':';
$link->type = TexyLink::IMAGE;
} else {
$link = $tx->linkModule->factoryLink($mLink, NULL, NULL);
}
} else {
$link = NULL;
}
return $tx->invokeAroundHandlers('figure', $parser, array($image, $link, $mContent, $mod));
}
/**
* Finish invocation.
*
* @param TexyHandlerInvocation handler invocation
* @param TexyImage
* @param TexyLink
* @param string
* @param TexyModifier
* @return TexyHtml|FALSE
*/
public function solve($invocation, TexyImage $image, $link, $content, $mod)
{
$tx = $this->texy;
$hAlign = $image->modifier->hAlign;
$image->modifier->hAlign = NULL;
$elImg = $tx->imageModule->solve(NULL, $image, $link); // returns TexyHtml or false!
if (!$elImg) {
return FALSE;
}
$el = TexyHtml::el('div');
if (!empty($image->width) && $this->widthDelta !== FALSE) {
$el->attrs['style']['width'] = ($image->width + $this->widthDelta) . 'px';
}
$mod->decorate($tx, $el);
$el[0] = $elImg;
$el[1] = TexyHtml::el('p');
$el[1]->parseLine($tx, ltrim($content));
$class = $this->class;
if ($hAlign) {
$var = $hAlign . 'Class'; // leftClass, rightClass
if (!empty($this->$var)) {
$class = $this->$var;
} elseif (empty($tx->alignClasses[$hAlign])) {
$el->attrs['style']['float'] = $hAlign;
} else {
$class .= '-' . $tx->alignClasses[$hAlign];
}
}
$el->attrs['class'][] = $class;
return $el;
}
}
|