Skip to content

Commit

Permalink
* new handler system via TexyHandlerInvocation
Browse files Browse the repository at this point in the history
* added Texy::addHandler, removed Texy::$handler
  • Loading branch information
dg committed Aug 10, 2007
1 parent b2872df commit be1ee4b
Show file tree
Hide file tree
Showing 55 changed files with 1,146 additions and 1,001 deletions.
3 changes: 3 additions & 0 deletions changelog.cs.texy
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog
Verze 2.0 Beta 2
=========

rev. 155
- nový systém handlerů. Odstraněno `$texy->handler` a konstanta `Texy::PROCEED`. Přidáno `$texy::addHandler()`. Více ve "fóru":http://forum.texy.info/viewtopic.php?pid=1871

rev. 150
- všechny příklady nyní fungují i v PHP 4. Jen je potřeba "inkludovat" odpovídající verzi Texy.
- verze pro PHP 5 podporuje kvůli zpětné kompatibilitě i původní konstanty `TEXY_ALL`, `TEXY_NONE`, `TEXY_HEADING_DYNAMIC`, `TEXY_HEADING_FIXED`, `TEXY_PROCEED`, `TEXY_CONTENT_*`
Expand Down
54 changes: 25 additions & 29 deletions examples/Figure as Definition List/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,36 @@



class myHandler {

/**
* @param TexyBlockParser
* @param TexyImage
* @param TexyLink
* @param string
* @param TexyModifier
* @return TexyHtml|string|FALSE|Texy::PROCEED
*/
function figure($parser, $image, $link, $content, $modifier)
{
// finish invocation by default way
$el = $parser->texy->figureModule->solve($image, $link, $content, $modifier);

// change div -> dl
$el->setName('dl');

// change p -> dd
$el->children['caption']->setName('dd');

// wrap img into dt
$dt = TexyHtml::el('dt');
$dt->addChild($el->children['img']);
$el->children['img'] = $dt;

return $el;
}
/**
* @param TexyHandlerInvocation handler invocation
* @param TexyImage
* @param TexyLink
* @param string
* @param TexyModifier
* @return TexyHtml|string|FALSE
*/
function figureHandler($invocation, $image, $link, $content, $modifier)
{
// finish invocation by default way
$el = $invocation->proceed();

// change div -> dl
$el->setName('dl');

// change p -> dd
$el->children['caption']->setName('dd');

// wrap img into dt
$dt = TexyHtml::el('dt');
$dt->addChild($el->children['img']);
$el->children['img'] = $dt;

return $el;
}


$texy = new Texy();
$texy->handler = new myHandler;
$texy->addHandler('figure', 'figureHandler');

// optionally set CSS classes
/*
Expand Down
54 changes: 24 additions & 30 deletions examples/Flash movie/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,31 @@



class myHandler {


/**
* User handler for images
*
* @param TexyLineParser
* @param TexyImage
* @param TexyLink
* @return TexyHtml|string|FALSE|Texy::PROCEED
*/
function image($parser, $image, $link)
{
$texy = $parser->texy;
/**
* User handler for images
*
* @param TexyHandlerInvocation handler invocation
* @param TexyImage
* @param TexyLink
* @return TexyHtml|string|FALSE
*/
function imageHandler($invocation, $image, $link)
{
$texy = $invocation->getTexy();

if (substr($image->URL, -4) === '.swf') // accepts only *.swf
{
$movie = Texy::prependRoot($image->URL, $texy->imageModule->root);
if (substr($image->URL, -4) === '.swf') // accepts only *.swf
{
$movie = Texy::prependRoot($image->URL, $texy->imageModule->root);

$dimensions =
($image->width ? 'width="'.$image->width.'" ' : '')
. ($image->height ? 'width="'.$image->height.'" ' : '');
$dimensions =
($image->width ? 'width="'.$image->width.'" ' : '')
. ($image->height ? 'width="'.$image->height.'" ' : '');

$movie = htmlSpecialChars($movie);
$altContent = htmlSpecialChars($image->modifier->title);
$movie = htmlSpecialChars($movie);
$altContent = htmlSpecialChars($image->modifier->title);

// @see http://www.dgx.cz/trine/item/how-to-correctly-insert-a-flash-into-xhtml
$code = '
// @see http://www.dgx.cz/trine/item/how-to-correctly-insert-a-flash-into-xhtml
$code = '
<!--[if !IE]> -->
<object type="application/x-shockwave-flash" data="'.$movie.'" '.$dimensions.'>
<!-- <![endif]-->
Expand All @@ -57,18 +54,15 @@ function image($parser, $image, $link)
</object>
<!-- <![endif]-->
';
return $texy->protect($code, TEXY_CONTENT_BLOCK); // or Texy::CONTENT_BLOCK in PHP 5
}

return TEXY_PROCEED; // or Texy::PROCEED in PHP 5
// or return $texy->imageModule->solve($image, $link);
return $texy->protect($code, TEXY_CONTENT_BLOCK); // or Texy::CONTENT_BLOCK in PHP 5
}

return $invocation->proceed();
}


$texy = new Texy();
$texy->handler = new myHandler;
$texy->addHandler('image', 'imageHandler');


// processing
Expand Down
55 changes: 26 additions & 29 deletions examples/Youtube video/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,37 @@



class myHandler {


/**
* User handler for images
*
* @param TexyLineParser
* @param TexyImage
* @param TexyLink
* @return TexyHtml|string|FALSE|Texy::PROCEED
*/
function image($parser, $image, $link)
{
$parts = explode(':', $image->URL);
if (count($parts) !== 2) return TEXY_PROCEED; // or Texy::PROCEED in PHP 5

switch ($parts[0]) {
case 'youtube':
$video = htmlSpecialChars($parts[1]);
$dimensions = 'width="'.($image->width ? $image->width : 425).'" height="'.($image->height ? $image->height : 350).'"';
$code = '<div><object '.$dimensions.'>'
. '<param name="movie" value="http://www.youtube.com/v/'.$video.'" /><param name="wmode" value="transparent" />'
. '<embed src="http://www.youtube.com/v/'.$video.'" type="application/x-shockwave-flash" wmode="transparent" '.$dimensions.' /></object></div>';

return $parser->texy->protect($code, TEXY_CONTENT_BLOCK); // or Texy::CONTENT_BLOCK in PHP 5
}

return TEXY_PROCEED; // or Texy::PROCEED in PHP 5
/**
* User handler for images
*
* @param TexyHandlerInvocation handler invocation
* @param TexyImage
* @param TexyLink
* @return TexyHtml|string|FALSE
*/
function imageHandler($invocation, $image, $link)
{
$parts = explode(':', $image->URL);
if (count($parts) !== 2) return $invocation->proceed();

switch ($parts[0]) {
case 'youtube':
$video = htmlSpecialChars($parts[1]);
$dimensions = 'width="'.($image->width ? $image->width : 425).'" height="'.($image->height ? $image->height : 350).'"';
$code = '<div><object '.$dimensions.'>'
. '<param name="movie" value="http://www.youtube.com/v/'.$video.'" /><param name="wmode" value="transparent" />'
. '<embed src="http://www.youtube.com/v/'.$video.'" type="application/x-shockwave-flash" wmode="transparent" '.$dimensions.' /></object></div>';

$texy = $invocation->getTexy();
return $texy->protect($code, TEXY_CONTENT_BLOCK); // or Texy::CONTENT_BLOCK in PHP 5
}

return $invocation->proceed();
}


$texy = new Texy();
$texy->handler = new myHandler;
$texy->addHandler('image', 'imageHandler');


// processing
Expand Down
2 changes: 1 addition & 1 deletion examples/cache/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* TEXY! CACHE DEMO
* --------------------------------------
* ----------------
*
* This demo shows how cache Texy! output and
* demonstrates advantages of inheriting from base Texy object
Expand Down
2 changes: 1 addition & 1 deletion examples/cache/mytexy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* TEXY! CACHE DEMO
* --------------------------------------
* ----------------
*
* @author David Grudl aka -dgx- (http://www.dgx.cz)
* @version $Revision$ $Date$
Expand Down
1 change: 1 addition & 0 deletions examples/emoticons/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

// EMOTICONS ARE DISABLED BY DEFAULT!
$texy->allowed['emoticon'] = TRUE;

// configure it
$texy->emoticonModule->class = 'smilie';
$texy->emoticonModule->icons[':oops:'] = 'redface.gif'; // user-defined emoticon
Expand Down
Loading

0 comments on commit be1ee4b

Please sign in to comment.