Skip to content

Commit

Permalink
Merge branch 'image-handling'
Browse files Browse the repository at this point in the history
Conflicts:
	classTextile.php
  • Loading branch information
netcarver committed Nov 13, 2012
2 parents ecba301 + 68581aa commit 7047f37
Showing 1 changed file with 27 additions and 32 deletions.
59 changes: 27 additions & 32 deletions classTextile.php
Original file line number Diff line number Diff line change
Expand Up @@ -726,16 +726,15 @@ function hasRawText($text)
function table($text)
{
$text = $text . "\n\n";
return preg_replace_callback("/^(?:table(_?{$this->s}{$this->a}{$this->c})\.(.*)?\n)?^({$this->a}{$this->c}\.? ?\|.*\|)[\s]*\n\n/smU",
array(&$this, "fTable"), $text);
return preg_replace_callback("/^(?:table(_?{$this->s}{$this->a}{$this->c})\.(.*)?\n)?^({$this->a}{$this->c}\.? ?\|.*\|)[\s]*\n\n/smU", array(&$this, "fTable"), $text);
}

// -------------------------------------------------------------
function fTable($matches)
{
$tatts = $this->pba($matches[1], 'table');

$sum = trim($matches[2]) ? ' summary="'.htmlspecialchars(trim($matches[2])).'"' : '';
$sum = trim($matches[2]) ? ' summary="'.htmlspecialchars(trim($matches[2]), ENT_QUOTES, 'UTF-8').'"' : '';
$cap = '';
$colgrp = $last_rgrp = '';
$c_row = 1;
Expand Down Expand Up @@ -1281,15 +1280,13 @@ function retrieveTags($text)
// -------------------------------------------------------------
function fRetrieveOpenTags($m)
{
list(, $key ) = $m;
return $this->tagCache[$key]['open'];
return $this->tagCache[$m[1]]['open'];
}

// -------------------------------------------------------------
function fRetrieveCloseTags($m)
{
list(, $key ) = $m;
return $this->tagCache[$key]['close'];
return $this->tagCache[$m[1]]['close'];
}

// -------------------------------------------------------------
Expand Down Expand Up @@ -1633,8 +1630,7 @@ function shelveURL($text)
// -------------------------------------------------------------
function retrieveURLs($text)
{
return preg_replace_callback('/urlref:(\w{32})/',
array(&$this, "retrieveURL"), $text);
return preg_replace_callback('/urlref:(\w{32})/', array(&$this, "retrieveURL"), $text);
}

// -------------------------------------------------------------
Expand Down Expand Up @@ -1673,26 +1669,27 @@ function isRelURL($url)
// -------------------------------------------------------------
function image($text)
{
return preg_replace_callback("/
(?:[[{])? # pre
\! # opening !
(\<|\=|\>)? # optional alignment atts
($this->c) # optional style,class atts
(?:\. )? # optional dot-space
([^\s(!]+) # presume this is the src
\s? # optional space
(?:\(([^\)]+)\))? # optional title
\! # closing
(?::(\S+))? # optional href
(?:[\]}]|(?=\s|$|\))) # lookahead: space or end of string
/x", array(&$this, "fImage"), $text);
return preg_replace_callback('/
(?:[[{])? # pre
\! # opening !
(\<|\=|\>)? # optional alignment $algn
('.$this->lc.') # optional style,class atts $atts
(?:\.\s)? # optional dot-space
([^\s(!]+) # presume this is the src $url
\s? # optional space
(?:\(([^\)]+)\))? # optional title $title
\! # closing
(?::(\S+)(?<![\]).,]))? # optional href sans final punct. $href
(?:[\]}]|(?=[.,\s)|]|$)) # lookahead: space , . ) | or end of string ... "|" needed if image in table cell
/x', array(&$this, "fImage"), $text);
}

// -------------------------------------------------------------
function fImage($m)
{
list(, $algn, $atts, $url) = $m;
$url = htmlspecialchars($url);
list(, $algn, $atts, $url, $title, $href) = array_pad($m, 6, null);

$url = htmlspecialchars($url, ENT_QUOTES, 'UTF-8');

$extras = $align = '';
if( '' !== $algn ) {
Expand All @@ -1709,9 +1706,9 @@ function fImage($m)
}
$atts = $this->pba($atts , '' , 1 , $extras) . $align;

if(isset($m[4]) && '' !== $m[4]) {
$m[4] = htmlspecialchars($m[4]);
$atts .= ' title="' . $m[4] . '" alt="' . $m[4] . '"';
if($title) {
$title = $this->encode_html($title);
$atts .= ' title="' . $title . '" alt="' . $title . '"';
}
else
$atts .= ' alt=""';
Expand All @@ -1721,7 +1718,7 @@ function fImage($m)
$size = @getimagesize(realpath($this->doc_root.ltrim($url, $this->ds)));
if ($size) $atts .= " $size[3]";

$href = (isset($m[5])) ? $this->shelveURL($m[5]) : '';
$href = ($href) ? $this->shelveURL($href) : '';
$url = $this->shelveURL($url);

$out = array(
Expand Down Expand Up @@ -1790,8 +1787,7 @@ function cleanWhiteSpace($text)
// -------------------------------------------------------------
function doSpecial($text, $start, $end, $method='fSpecial')
{
return preg_replace_callback('/(^|\s|[[({>])'.preg_quote($start, '/').'(.*?)'.preg_quote($end, '/').'(\s|$|[\])}])?/ms',
array(&$this, $method), $text);
return preg_replace_callback('/(^|\s|[[({>])'.preg_quote($start, '/').'(.*?)'.preg_quote($end, '/').'(\s|$|[\])}])?/ms', array(&$this, $method), $text);
}

// -------------------------------------------------------------
Expand Down Expand Up @@ -1821,8 +1817,7 @@ function fTextile($m)
// -------------------------------------------------------------
function footnoteRef($text)
{
return preg_replace('/(?<=\S)\[([0-9]+)([\!]?)\](\s)?/Ue',
'$this->footnoteID(\'\1\',\'\2\',\'\3\')', $text);
return preg_replace('/(?<=\S)\[([0-9]+)([\!]?)\](\s)?/Ue', '$this->footnoteID(\'\1\',\'\2\',\'\3\')', $text);
}

// -------------------------------------------------------------
Expand Down

0 comments on commit 7047f37

Please # to comment.