Commit 581787e9 authored by Brett T Bieber's avatar Brett T Bieber
Browse files

Merge pull request #729 from tsteiner2/issue-555

Closes #555
parents ab20073f c554f604
......@@ -13,10 +13,10 @@ This package generates php class files (objects) from Dreamweaver template files
<email>brett.bieber@gmail.com</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>
......@@ -24,22 +24,21 @@ This package generates php class files (objects) from Dreamweaver template files
<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"/>
......
<?php
set_include_path(dirname(__DIR__).'/../src');
error_reporting(E_ALL);
ini_set('display_errors', true);
require_once 'UNL/DWT/Scanner.php';
......@@ -8,5 +10,10 @@ $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;
......@@ -149,17 +149,23 @@ class UNL_DWT
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
);
}
......@@ -299,16 +305,16 @@ class UNL_DWT
*
* @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 '';
}
......
<?php
/**
* Handles scanning a dwt file for regions.
* Handles scanning a dwt file for regions and rendering.
*
* PHP version 5
*
......@@ -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';
/**
......@@ -23,7 +24,7 @@ require_once 'UNL/DWT/Region.php';
* @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;
......@@ -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();
......@@ -133,4 +145,14 @@ class UNL_DWT_Scanner
return null;
}
/**
* Allow directly rendering
*
* @return string
*/
function __toString()
{
return $this->toHtml();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment