Skip to content

Commit

Permalink
[gh-555] Upgrade to UNL_DWT 0.9.0. @1h00
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteiner committed May 24, 2013
1 parent f37d953 commit 40e8038
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 24 deletions.
Binary file modified lib/.pear2registry
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,32 @@ This package generates php class files (objects) from Dreamweaver template files
<email>[email protected]</email>
<active>yes</active>
</lead>
<date>2012-10-02</date>
<time>11:50:32</time>
<date>2013-05-24</date>
<time>10:02:57</time>
<version>
<release>0.8.0</release>
<release>0.9.0</release>
<api>0.7.1</api>
</version>
<stability>
<release>beta</release>
<api>beta</api>
</stability>
<license uri="http://www1.unl.edu/wdn/wiki/Software_License">BSD</license>
<notes>Feature Release:

* Dreamweaver templates using params are now properly supported
* Minor API changes
** Add UNL_DWT::getTemplateFile() which is used during the rendering process
<notes>Feature Release
* Add support for immedaitely rendering a scanned DWT [saltybeagle]

Bug Fixes
* Prevent greedy matching of template regions [spam38]
</notes>
<contents>
<dir name="/">
<file role="php" name="php/UNL/DWT/Scanner.php" md5sum="042fb529bbc104b3eb742e8946e0961e"/>
<file role="php" name="php/UNL/DWT/Scanner.php" md5sum="276e82e5db587c9c18a100e1e877082e"/>
<file role="php" name="php/UNL/DWT/Region.php" md5sum="858136d43bf29868dca876783e51d196"/>
<file role="php" name="php/UNL/DWT/Generator.php" md5sum="a3b933a0d7f8d81f72836bb2c5fb6914"/>
<file role="php" name="php/UNL/DWT/Exception.php" md5sum="5b99b44fbfde7349c6b9e6d9be78e9dc"/>
<file role="php" name="php/UNL/DWT/createTemplates.php" md5sum="9089565d275b52e0cd65c52edd50ef18"/>
<file role="php" name="php/UNL/DWT.php" md5sum="0889c13bcecd0ebf5e517367345772f9"/>
<file role="doc" name="doc/pear.unl.edu/UNL_DWT/examples/scanner_example.php" md5sum="f0807792c3c0c4a0524f9186e69e0be7"/>
<file role="php" name="php/UNL/DWT.php" md5sum="ca9d707c266ad9150e39d1a9a60c5643"/>
<file role="doc" name="doc/pear.unl.edu/UNL_DWT/examples/scanner_example.php" md5sum="2d16f0e62c4227aa28108bf78d74156a"/>
<file role="doc" name="doc/pear.unl.edu/UNL_DWT/examples/basic/Template_style1.tpl" md5sum="b524ef4684be7dba47ed8c245577347a"/>
<file role="doc" name="doc/pear.unl.edu/UNL_DWT/examples/basic/Template_style1.php" md5sum="096998b112a1e27bddc6c171380d590e"/>
<file role="doc" name="doc/pear.unl.edu/UNL_DWT/examples/basic/template_style1.dwt" md5sum="0d5a4f5ca86e9c2a3c0050f39acbb034"/>
Expand Down
11 changes: 9 additions & 2 deletions lib/docs/pear.unl.edu/UNL_DWT/examples/scanner_example.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
<?php

set_include_path(dirname(__DIR__).'/../src');
error_reporting(E_ALL);
ini_set('display_errors', true);

require_once 'UNL/DWT/Scanner.php';

$file = file_get_contents(dirname(__FILE__).'/basic/'.'template_style1.dwt');

$scanned = new UNL_DWT_Scanner($file);

echo $scanned->leftnav;
echo $scanned->content;
// Modify the scanned content
$scanned->content .= '<h3>Scanned content from the left nav:</h3>';

// Also, access the content that was scanned in
$scanned->content .= '<pre>'.$scanned->leftnav.'</pre>';

echo $scanned;
24 changes: 15 additions & 9 deletions lib/php/UNL/DWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,23 @@ function replaceRegions($p, $regions)

foreach ($regions as $region => $value) {
/* Replace the region with the replacement text */
$startMarker = $this->getRegionBeginMarker(self::TEMPLATE_TOKEN, $region);
$endMarker = $this->getRegionEndMarker(self::TEMPLATE_TOKEN);
$p = str_replace(
self::strBetween($this->getRegionBeginMarker(self::TEMPLATE_TOKEN, $region),
$this->getRegionEndMarker(self::TEMPLATE_TOKEN), $p),
$value, $p, $count
self::strBetween($startMarker, $endMarker, $p, true),
$startMarker . $value . $endMarker,
$p,
$count
);

if (!$count) {
$startMarker = $this->getRegionBeginMarker(self::INSTANCE_TOKEN, $region);
$endMarker = $this->getRegionEndMarker(self::INSTANCE_TOKEN);
$p = str_replace(
self::strBetween($this->getRegionBeginMarker(self::INSTANCE_TOKEN, $region),
$this->getRegionEndMarker(self::INSTANCE_TOKEN), $p),
$value, $p, $count
self::strBetween($startMarker, $endMarker, $p, true),
$startMarker . $value . $endMarker,
$p,
$count
);
}

Expand Down Expand Up @@ -299,16 +305,16 @@ static function debugLevel($v = null)
*
* @return string
*/
static function strBetween($start, $end, $p)
static function strBetween($start, $end, $p, $inclusive = false)
{
if (!empty($start) && strpos($p, $start) !== false) {
$p = substr($p, strpos($p, $start)+strlen($start));
$p = substr($p, strpos($p, $start)+($inclusive ? 0 : strlen($start)));
} else {
return '';
}

if (strpos($p, $end) !==false) {
$p = substr($p, 0, strpos($p, $end));
$p = substr($p, 0, strpos($p, $end)+($inclusive ? strlen($end) : 0));
} else {
return '';
}
Expand Down
26 changes: 24 additions & 2 deletions lib/php/UNL/DWT/Scanner.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Handles scanning a dwt file for regions.
* Handles scanning a dwt file for regions and rendering.
*
* PHP version 5
*
Expand All @@ -12,6 +12,7 @@
* @license http://www1.unl.edu/wdn/wiki/Software_License BSD License
* @link http://pear.unl.edu/package/UNL_DWT
*/
require_once 'UNL/DWT.php';
require_once 'UNL/DWT/Region.php';

/**
Expand All @@ -23,7 +24,7 @@
* @license http://www1.unl.edu/wdn/wiki/Software_License BSD License
* @link http://pear.unl.edu/package/UNL_DWT
*/
class UNL_DWT_Scanner
class UNL_DWT_Scanner extends UNL_DWT
{
protected $_regions;

Expand All @@ -34,9 +35,20 @@ class UNL_DWT_Scanner
*/
function __construct($dwt)
{
$this->__template = $dwt;
$this->scanRegions($dwt);
}

/**
* Return the template markup
*
* @return string
*/
function getTemplateFile()
{
return $this->__template;
}

function scanRegions($dwt)
{
$this->_regions[] = array();
Expand Down Expand Up @@ -133,4 +145,14 @@ public function __get($region)
return null;
}

/**
* Allow directly rendering
*
* @return string
*/
function __toString()
{
return $this->toHtml();
}

}

0 comments on commit 40e8038

Please sign in to comment.