Skip to content

Commit

Permalink
* TexyLinkModule -> added solveUrlEmail, changed textualURL
Browse files Browse the repository at this point in the history
* URL are protected, without ­
* www.dgx.cz/trine -> latrine.dgx.cz
* updated TexyHtml
  • Loading branch information
dg committed Oct 21, 2007
1 parent d232bb8 commit 11e8e22
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 103 deletions.
2 changes: 1 addition & 1 deletion changelog.cs.texy
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ htmlOutputModule

TexyDOM a zděděné třídy
-----------------------
- odstraněno, náhradou je TexyHtml (obdoba NHtml, viz http://www.dgx.cz/trine/item/nhtml-pomocnik-php-programatora)
- odstraněno, náhradou je TexyHtml (obdoba NHtml, viz http://latrine.dgx.cz/nhtml-pomocnik-php-programatora)
- vlastnost TexyHtml::$xhtml - přepínač mezi XHTML a HTML výstupem
- ve všech handlerech se nyní operuje s elementy reprezentovanými tímto objektem, manipulace je tedy extrémně snadná

Expand Down
2 changes: 1 addition & 1 deletion documentation/syntax.cs.texy
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Odkazy
======

- Look at "homepage":http://texy.info.
- Do you know "La Trine":[http://www.dgx.cz/trine/]?
- Do you know "La Trine":[http://latrine.dgx.cz/]?
- This picture [* image.gif *]:www.texy.info is clickable


Expand Down
2 changes: 1 addition & 1 deletion documentation/syntax.en.texy
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Links
=====

- Look at "homepage":http://texy.info.
- Do you know "La Trine":[http://www.dgx.cz/trine/]?
- Do you know "La Trine":[http://latrine.dgx.cz/]?
- This picture [* image.gif *]:www.texy.info is clickable


Expand Down
2 changes: 1 addition & 1 deletion examples/Flash movie/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function imageHandler($invocation, $image, $link)
$movie = htmlSpecialChars($movie);
$altContent = htmlSpecialChars($image->modifier->title);

// @see http://www.dgx.cz/trine/item/how-to-correctly-insert-a-flash-into-xhtml
// @see http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml
$code = '
<!--[if !IE]> -->
<object type="application/x-shockwave-flash" data="'.$movie.'" '.$dimensions.'>
Expand Down
6 changes: 2 additions & 4 deletions examples/handler/handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ function linkReference($invocation, $link, $content)
/**
* @param TexyHandlerInvocation handler invocation
* @param TexyLink
* @param string
* @return TexyHtml|string|FALSE
*/
function linkEmail($invocation, $link, $content)
function linkEmail($invocation, $link)
{
return $invocation->proceed();
}
Expand All @@ -100,10 +99,9 @@ function linkEmail($invocation, $link, $content)
/**
* @param TexyHandlerInvocation handler invocation
* @param TexyLink
* @param string
* @return TexyHtml|string|FALSE
*/
function linkURL($invocation, $link, $content)
function linkURL($invocation, $link)
{
return $invocation->proceed();
}
Expand Down
12 changes: 4 additions & 8 deletions examples/syntax highlighting/demo-fshl.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,15 @@ function blockHandler($invocation, $blocktype, $content, $lang, $modifier)
return $invocation->proceed();
}

$texy = $invocation->getTexy();

$lang = strtoupper($lang);
if ($lang == 'JAVASCRIPT') $lang = 'JS';
if (!in_array(
$lang,
array('CPP', 'CSS', 'HTML', 'JAVA', 'PHP', 'JS', 'SQL'))
) {
return $invocation->proceed();
}

$parser = new fshlParser('HTML_UTF8', P_TAB_INDENT);
if (!$parser->isLanguage($lang)) {
return $invocation->proceed();
}

$texy = $invocation->getTexy();
$content = $texy->blockModule->outdent($content);
$content = $parser->highlightString($lang, $content);
$content = $texy->protect($content, TEXY_CONTENT_BLOCK); // or Texy::CONTENT_BLOCK in PHP 5
Expand Down
2 changes: 1 addition & 1 deletion readme.cs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ HTML kód najdete v adresáři /icons/

-----
Chcete-li další informace, navštivte autorův weblog:
http://www.dgx.cz/trine/
http://latrine.dgx.cz/
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ Choose buttons and look at exemplary HTML code in directory /icons/

-----
For more information, visit the author's weblog (in czech language):
http://www.dgx.cz/trine/
http://latrine.dgx.cz/
2 changes: 1 addition & 1 deletion texy-for-php4/libs/TexyBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function __construct() /* PHP 5 constructor */

function TexyBase() /* PHP 4 constructor */
{
// generate references (see http://www.dgx.cz/trine/item/how-to-emulate-php5-object-model-in-php4)
// generate references (see http://latrine.dgx.cz/how-to-emulate-php5-object-model-in-php4)
foreach ($this as $key => $foo) $GLOBALS['$$HIDDEN$$'][] = & $this->$key;

$args = func_get_args();
Expand Down
43 changes: 14 additions & 29 deletions texy-for-php4/libs/TexyHtml.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,25 +99,18 @@ class TexyHtml extends TexyBase
/**
* Static factory
* @param string element name (or NULL)
* @param array element's attributes
* @param array|string element's attributes (or textual content)
* @return TexyHtml
*/
function el($name = NULL, $attrs = NULL) /* static */
{
$el = new TexyHtml;

if ($name !== NULL) {
$el->setName($name);
}

if ($attrs !== NULL) {
if (!is_array($attrs)) {
return throw (new TexyException('Attributes must be array'));
}

$el->setName($name);
if (is_array($attrs)) {
$el->attrs = $attrs;
} elseif ($attrs !== NULL) {
$el->setText($attrs);
}

return $el;
}

Expand All @@ -126,16 +119,18 @@ function el($name = NULL, $attrs = NULL) /* static */
/**
* Changes element's name
* @param string
* @param bool Is element empty?
* @throws TexyException
* @return TexyHtml provides a fluent interface
*/
function setName($name)
function setName($name, $empty = NULL)
{
if ($name !== NULL && !is_string($name)) {
return throw (new TexyException('Name must be string or NULL'));
}

$this->name = $name;
$this->isEmpty = isset($GLOBALS['TexyHtml::$emptyElements'][$name]);
$this->isEmpty = $empty === NULL ? isset($GLOBALS['TexyHtml::$emptyElements'][$name]) : (bool) $empty;
return $this;
}

Expand All @@ -154,15 +149,10 @@ function getName()

/**
* Is element empty?
* @param optional setter
* @return bool
*/
function isEmpty($value = NULL)
function isEmpty()
{
if (is_bool($value)) {
$this->isEmpty = $value;
}

return $this->isEmpty;
}

Expand Down Expand Up @@ -230,19 +220,14 @@ function get($index)


/**
* Creates and adds a new TexyHtml child
* Adds and creates new TexyHtml child
* @param string elements's name
* @param string optional textual content
* @param array|string element's attributes (or textual content)
* @return TexyHtml created element
*/
function create($name, $text = NULL)
function create($name, $attrs = NULL)
{
$child = new TexyHtml;
$child->setName($name);
if ($text !== NULL) {
$child->setText($text);
}
return $this->children[] = $child;
return $this->children[] = TexyHtml::el($name, $attrs);
}


Expand Down
2 changes: 1 addition & 1 deletion texy-for-php4/modules/TexyHtmlModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function solveTag($invocation, /*TexyHtml*/ $el, $isStart, $forceEmpty = NULL)

} else {
// allowedTags === Texy::ALL
if ($forceEmpty) $el->isEmpty(TRUE);
if ($forceEmpty) $el->setName($name, TRUE);
$allowedAttrs = TEXY_ALL; // all attrs are allowed
}

Expand Down
40 changes: 28 additions & 12 deletions texy-for-php4/modules/TexyLinkModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ function __construct($texy)
$texy->allowed['link/definition'] = TRUE;
$texy->addHandler('newReference', array($this, 'solveNewReference'));
$texy->addHandler('linkReference', array($this, 'solve'));
$texy->addHandler('linkEmail', array($this, 'solve'));
$texy->addHandler('linkURL', array($this, 'solve'));
$texy->addHandler('linkEmail', array($this, 'solveUrlEmail'));
$texy->addHandler('linkURL', array($this, 'solveUrlEmail'));
$texy->addHandler('beforeParse', array($this, 'beforeParse'));

// [reference]
Expand Down Expand Up @@ -84,7 +84,7 @@ function beforeParse($texy, & $text)
{
$GLOBALS['TexyLinkModule::$deadlock']= array();

// [la trine]: http://www.dgx.cz/trine/ text odkazu .(title)[class]{style}
// [la trine]: http://latrine.dgx.cz/ text odkazu .(title)[class]{style}
if ($texy->allowed['link/definition']) {
$text = preg_replace_callback(
'#^\[([^\[\]\#\?\*\n]+)\]: +(\S+)(\ .+)?'.TEXY_MODIFIER.'?\s*()$#mUu',
Expand All @@ -97,7 +97,7 @@ function beforeParse($texy, & $text)


/**
* Callback for: [la trine]: http://www.dgx.cz/trine/ text odkazu .(title)[class]{style}
* Callback for: [la trine]: http://latrine.dgx.cz/ text odkazu .(title)[class]{style}
*
* @param array regexp matches
* @return string
Expand Down Expand Up @@ -156,7 +156,8 @@ function patternReference($parser, $matches)
unset($GLOBALS['TexyLinkModule::$deadlock'][$link->name]);
}
} else {
$content = $this->textualURL($link);
$content = $this->textualUrl($link);
$content = $this->texy->protect($content, TEXY_CONTENT_TEXTUAL);
}

return $tx->invokeAroundHandlers('linkReference', $parser, array($link, $content));
Expand All @@ -179,12 +180,11 @@ function patternUrlEmail($parser, $matches, $name)

$link = new TexyLink($mURL);
$this->checkLink($link);
$content = $this->textualURL($link);

return $this->texy->invokeAroundHandlers(
$name === 'link/email' ? 'linkEmail' : 'linkURL',
$parser,
array($link, $content)
array($link)
);
}

Expand Down Expand Up @@ -329,6 +329,22 @@ function solve($invocation, $link, $content = NULL)



/**
* Finish invocation
*
* @param TexyHandlerInvocation handler invocation
* @param TexyLink
* @return TexyHtml|string
*/
function solveUrlEmail($invocation, $link)
{
$content = $this->textualUrl($link);
$content = $this->texy->protect($content, TEXY_CONTENT_TEXTUAL);
return $this->solve(NULL, $link, $content);
}



/**
* Finish invocation
*
Expand Down Expand Up @@ -376,13 +392,13 @@ function checkLink($link) /* private */
* @param TexyLink
* @return string
*/
function textualURL($link) /* private */
function textualUrl($link) /* private */
{
$URL = $link->raw === NULL ? $link->URL : $link->raw;

if (preg_match('#^'.TEXY_EMAIL.'$#i', $URL)) { // email
return $this->texy->obfuscateEmail
? str_replace('@', $this->texy->protect("&#64;<!---->", TEXY_CONTENT_MARKUP), $URL)
? str_replace('@', "&#64;<!---->", $URL)
: $URL;
}

Expand All @@ -401,12 +417,12 @@ function textualURL($link) /* private */
$res .= $parts['host'];

if (isset($parts['path']))
$res .= (strlen($parts['path']) > 16 ? ('/...' . preg_replace('#^.*(.{0,12})$#U', '$1', $parts['path'])) : $parts['path']);
$res .= (strlen($parts['path']) > 16 ? ("/\xe2\x80\xa6" . preg_replace('#^.*(.{0,12})$#U', '$1', $parts['path'])) : $parts['path']);

if (isset($parts['query'])) {
$res .= strlen($parts['query']) > 4 ? '?...' : ('?'.$parts['query']);
$res .= strlen($parts['query']) > 4 ? "?\xe2\x80\xa6" : ('?'.$parts['query']);
} elseif (isset($parts['fragment'])) {
$res .= strlen($parts['fragment']) > 4 ? '#...' : ('#'.$parts['fragment']);
$res .= strlen($parts['fragment']) > 4 ? "#\xe2\x80\xa6" : ('#'.$parts['fragment']);
}
return $res;
}
Expand Down
Loading

0 comments on commit 11e8e22

Please sign in to comment.