|
|
Subject: cvs: pearweb /weeklynews 20030119.pl.html - msg#00488
List: php.cvs.pear
Was this page helpful?
Thread at a glance:
Previous Message by Date:
click to view message preview
cvs: pear /HTML_Template_Flexy Flexy.php
alan_k Sat Jan 25 23:29:54 2003 EDT
Modified files:
/pear/HTML_Template_Flexy Flexy.php
Log:
add Hooks for new tokenizer
Index: pear/HTML_Template_Flexy/Flexy.php
diff -u pear/HTML_Template_Flexy/Flexy.php:1.6
pear/HTML_Template_Flexy/Flexy.php:1.7
--- pear/HTML_Template_Flexy/Flexy.php:1.6 Sat Jan 4 06:55:18 2003
+++ pear/HTML_Template_Flexy/Flexy.php Sat Jan 25 23:29:54 2003
@@ -38,7 +38,7 @@
* - heavily focused on displaying objects as pages.
* (so you can document your tags.)
*
-* @version $Id: Flexy.php,v 1.6 2003/01/04 11:55:18 mj Exp $
+* @version $Id: Flexy.php,v 1.7 2003/01/26 04:29:54 alan_k Exp $
*/
class HTML_Template_Flexy
{
@@ -51,7 +51,8 @@
'forceCompile' => false, // only suggested for
debugging
'filters' => array(),
'debug' => false,
- 'locale' => 'en'
+ 'locale' => 'en',
+ 'useTokenizer' => false
);
@@ -198,6 +199,7 @@
/**
+ * classicParse - the older regex based code generator.
* here all the replacing, filtering and writing of the compiled file is
done
* well this is not much work, but still its in here :-)
*
@@ -207,7 +209,7 @@
* @param
* @return
*/
- function parse()
+ function classicParse()
{
// read the entire file into one variable
if ( $input = @file($this->currentTemplate) ) {
@@ -232,6 +234,99 @@
}
/**
+ * parse - the new tokenizer based generator
+ *
+ * @access private
+ * @version 01/12/03
+ * @author Alan Knowles <alan@xxxxxxxxxxx>
+ * @param
+ * @return
+ */
+
+
+
+
+ function parse()
+ {
+ // read the entire file into one variable
+ $data = file_get_contents($this->currentTemplate);
+ //echo strlen($data);
+ $tokenizer = new HTML_Template_Flexy_Tokenizer($data);
+ //$tokenizer->debug=1;
+ $i=0;
+ $res = array();
+
+ while ($t = $tokenizer->yylex()) {
+ //if ($tokenizer->value === '') {
+ // continue;
+ // }
+
+ if ($t == HTML_TEMPLATE_FLEXY_TOKEN_ERROR) {
+ PEAR::raiseError('HTML_Template_Flexy::Syntax error in
Template line:'. $t->line,null,PEAR_ERROR_DIE);
+ }
+ if ($t == HTML_TEMPLATE_FLEXY_TOKEN_NONE) {
+ continue;
+ }
+
+ $i++;
+ $res[$i] = $tokenizer->value;
+ $res[$i]->id = $i;
+ //print_r($res[$i]);
+
+ $tokenizer->value = '';
+
+ }
+ // connect parent and child tags.
+ $stack = array();
+ for($i=0;$i<count($res);$i++) {
+ if (!@$res[$i]->tag) {
+ continue;
+ }
+ if ($res[$i]->tag{0} == '/') { // it's a close tag..
+ //echo "GOT END TAG: {$res[$i]->tag}\n";
+ $tag = strtoupper(substr($res[$i]->tag,1));
+ if (!isset($stack[$tag]['pos'])) {
+ continue; // unmatched
+ }
+ $npos = $stack[$tag]['pos'];
+ //echo "matching it to {$stack[$tag][$npos]}\n";
+ $res[$stack[$tag][$npos]]->close = &$res[$i];
+ $stack[$tag]['pos']--;
+ if ($stack[$tag]['pos'] < 0) {
+ // too many closes - just ignore it..
+ $stack[$tag]['pos'] = 0;
+ }
+ continue;
+ }
+ // new entry on stack..
+ $tag = strtoupper($res[$i]->tag);
+
+ if (!isset($stack[$tag])) {
+ $npos = $stack[$tag]['pos'] = 0;
+ } else {
+ $npos = ++$stack[$tag]['pos'];
+ }
+ $stack[$tag][$npos] = $i;
+ }
+
+
+ //new Gtk_VarDump($res);
+ $data = '';
+ foreach($res as $v) {
+ $data .= $v->toHTML();
+ }
+
+ // error checking?
+ if( ($cfp = fopen( $this->compiledTemplate , 'w' )) ) {
+ fwrite($cfp,$data);
+ fclose($cfp);
+ @chmod($this->compiledTemplate,0775);
+ }
+
+ return true;
+ }
+
+ /**
* compile the template
*
* @access public
@@ -333,9 +428,12 @@
$recompile = true;
}
}
-
+ $method = 'classicParse';
+ if (@$this->options['useTokenizer']) {
+ $method = 'parse';
+ }
if( $recompile ) { // or any of the config files
- if( !$this->parse() ) {
+ if( !$this->$method() ) {
return false;
}
}
--
PEAR CVS Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Next Message by Date:
click to view message preview
cvs: pear /Cache_Lite Lite.php
fab Sun Jan 26 07:49:22 2003 EDT
Modified files:
/pear/Cache_Lite Lite.php
Log:
Little fix to avoid file names problems with an exotic group name (thanks to
Brian Webb <bwebb9@xxxxxxxxx>)
Index: pear/Cache_Lite/Lite.php
diff -u pear/Cache_Lite/Lite.php:1.7 pear/Cache_Lite/Lite.php:1.8
--- pear/Cache_Lite/Lite.php:1.7 Tue Jan 14 17:26:42 2003
+++ pear/Cache_Lite/Lite.php Sun Jan 26 07:49:22 2003
@@ -15,7 +15,7 @@
*
* @package Cache_Lite
* @category Caching
-* @version $Id: Lite.php,v 1.7 2003/01/14 22:26:42 fab Exp $
+* @version $Id: Lite.php,v 1.8 2003/01/26 12:49:22 fab Exp $
* @author Fabien MARTY <fab@xxxxxxx>
*/
@@ -309,7 +309,7 @@
*/
function clean($group = false)
{
- $motif = ($group) ? 'cache_'.$group.'_' : 'cache_';
+ $motif = ($group) ? 'cache_'.md5($group).'_' : 'cache_';
if ($this->_memoryCaching) {
while (list($key, $value) = each($this->_memoryCaching)) {
if (strpos($key, $motif, 0)) {
@@ -440,7 +440,7 @@
*/
function _setFileName($id, $group)
{
- $this->_file = ($this->_cacheDir.'cache_'.$group.'_'.md5($id));
+ $this->_file = ($this->_cacheDir.'cache_'.md5($group).'_'.md5($id));
}
/**
--
PEAR CVS Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Previous Message by Thread:
click to view message preview
cvs: pear /HTML_Template_Flexy Flexy.php
alan_k Sat Jan 25 23:29:54 2003 EDT
Modified files:
/pear/HTML_Template_Flexy Flexy.php
Log:
add Hooks for new tokenizer
Index: pear/HTML_Template_Flexy/Flexy.php
diff -u pear/HTML_Template_Flexy/Flexy.php:1.6
pear/HTML_Template_Flexy/Flexy.php:1.7
--- pear/HTML_Template_Flexy/Flexy.php:1.6 Sat Jan 4 06:55:18 2003
+++ pear/HTML_Template_Flexy/Flexy.php Sat Jan 25 23:29:54 2003
@@ -38,7 +38,7 @@
* - heavily focused on displaying objects as pages.
* (so you can document your tags.)
*
-* @version $Id: Flexy.php,v 1.6 2003/01/04 11:55:18 mj Exp $
+* @version $Id: Flexy.php,v 1.7 2003/01/26 04:29:54 alan_k Exp $
*/
class HTML_Template_Flexy
{
@@ -51,7 +51,8 @@
'forceCompile' => false, // only suggested for
debugging
'filters' => array(),
'debug' => false,
- 'locale' => 'en'
+ 'locale' => 'en',
+ 'useTokenizer' => false
);
@@ -198,6 +199,7 @@
/**
+ * classicParse - the older regex based code generator.
* here all the replacing, filtering and writing of the compiled file is
done
* well this is not much work, but still its in here :-)
*
@@ -207,7 +209,7 @@
* @param
* @return
*/
- function parse()
+ function classicParse()
{
// read the entire file into one variable
if ( $input = @file($this->currentTemplate) ) {
@@ -232,6 +234,99 @@
}
/**
+ * parse - the new tokenizer based generator
+ *
+ * @access private
+ * @version 01/12/03
+ * @author Alan Knowles <alan@xxxxxxxxxxx>
+ * @param
+ * @return
+ */
+
+
+
+
+ function parse()
+ {
+ // read the entire file into one variable
+ $data = file_get_contents($this->currentTemplate);
+ //echo strlen($data);
+ $tokenizer = new HTML_Template_Flexy_Tokenizer($data);
+ //$tokenizer->debug=1;
+ $i=0;
+ $res = array();
+
+ while ($t = $tokenizer->yylex()) {
+ //if ($tokenizer->value === '') {
+ // continue;
+ // }
+
+ if ($t == HTML_TEMPLATE_FLEXY_TOKEN_ERROR) {
+ PEAR::raiseError('HTML_Template_Flexy::Syntax error in
Template line:'. $t->line,null,PEAR_ERROR_DIE);
+ }
+ if ($t == HTML_TEMPLATE_FLEXY_TOKEN_NONE) {
+ continue;
+ }
+
+ $i++;
+ $res[$i] = $tokenizer->value;
+ $res[$i]->id = $i;
+ //print_r($res[$i]);
+
+ $tokenizer->value = '';
+
+ }
+ // connect parent and child tags.
+ $stack = array();
+ for($i=0;$i<count($res);$i++) {
+ if (!@$res[$i]->tag) {
+ continue;
+ }
+ if ($res[$i]->tag{0} == '/') { // it's a close tag..
+ //echo "GOT END TAG: {$res[$i]->tag}\n";
+ $tag = strtoupper(substr($res[$i]->tag,1));
+ if (!isset($stack[$tag]['pos'])) {
+ continue; // unmatched
+ }
+ $npos = $stack[$tag]['pos'];
+ //echo "matching it to {$stack[$tag][$npos]}\n";
+ $res[$stack[$tag][$npos]]->close = &$res[$i];
+ $stack[$tag]['pos']--;
+ if ($stack[$tag]['pos'] < 0) {
+ // too many closes - just ignore it..
+ $stack[$tag]['pos'] = 0;
+ }
+ continue;
+ }
+ // new entry on stack..
+ $tag = strtoupper($res[$i]->tag);
+
+ if (!isset($stack[$tag])) {
+ $npos = $stack[$tag]['pos'] = 0;
+ } else {
+ $npos = ++$stack[$tag]['pos'];
+ }
+ $stack[$tag][$npos] = $i;
+ }
+
+
+ //new Gtk_VarDump($res);
+ $data = '';
+ foreach($res as $v) {
+ $data .= $v->toHTML();
+ }
+
+ // error checking?
+ if( ($cfp = fopen( $this->compiledTemplate , 'w' )) ) {
+ fwrite($cfp,$data);
+ fclose($cfp);
+ @chmod($this->compiledTemplate,0775);
+ }
+
+ return true;
+ }
+
+ /**
* compile the template
*
* @access public
@@ -333,9 +428,12 @@
$recompile = true;
}
}
-
+ $method = 'classicParse';
+ if (@$this->options['useTokenizer']) {
+ $method = 'parse';
+ }
if( $recompile ) { // or any of the config files
- if( !$this->parse() ) {
+ if( !$this->$method() ) {
return false;
}
}
--
PEAR CVS Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Next Message by Thread:
click to view message preview
cvs: pear /Cache_Lite/Lite Function.php Output.php
fab Sun Jan 26 07:50:40 2003 EDT
Modified files:
/pear/Cache_Lite/Lite Function.php Output.php
Log:
Little bug fix (cache was inefficient if the output is only 0 for example)
(thanks to Brian Webb <bwebb9@xxxxxxxxx>)
Index: pear/Cache_Lite/Lite/Function.php
diff -u pear/Cache_Lite/Lite/Function.php:1.2
pear/Cache_Lite/Lite/Function.php:1.3
--- pear/Cache_Lite/Lite/Function.php:1.2 Wed Jan 1 12:49:27 2003
+++ pear/Cache_Lite/Lite/Function.php Sun Jan 26 07:50:40 2003
@@ -11,7 +11,7 @@
* Technical choices are described in the 'docs/technical' file
*
* @package Cache_Lite
-* @version $Id: Function.php,v 1.2 2003/01/01 17:49:27 sterling Exp $
+* @version $Id: Function.php,v 1.3 2003/01/26 12:50:40 fab Exp $
* @author Sebastian BERGMANN <sb@xxxxxxxxxxxxxxxxxxxxx>
* @author Fabien MARTY <fab@xxxxxxx>
*/
@@ -70,7 +70,8 @@
{
$arguments = func_get_args();
$id = serialize($arguments); // Generate a cache id
- if ($data = $this->get($id, $this->_defaultGroup)) {
+ $data = $this->get($id, $this->_defaultGroup);
+ if ($data !== false) {
$array = unserialize($data);
$output = $array['output'];
$result = $array['result'];
Index: pear/Cache_Lite/Lite/Output.php
diff -u pear/Cache_Lite/Lite/Output.php:1.1 pear/Cache_Lite/Lite/Output.php:1.2
--- pear/Cache_Lite/Lite/Output.php:1.1 Fri Sep 20 12:12:23 2002
+++ pear/Cache_Lite/Lite/Output.php Sun Jan 26 07:50:40 2003
@@ -7,7 +7,7 @@
* Technical choices are described in the 'docs/technical' file
*
* @package Cache_Lite
-* @version $Id: Output.php,v 1.1 2002/09/20 16:12:23 sebastian Exp $
+* @version $Id: Output.php,v 1.2 2003/01/26 12:50:40 fab Exp $
* @author Fabien MARTY <fab@xxxxxxx>
*/
@@ -42,7 +42,8 @@
*/
function start($id, $group = 'default')
{
- if ($data = $this->get($id, $group)) {
+ $data = $this->get($id, $group);
+ if ($data !== false) {
echo($data);
return true;
} else {
@@ -68,4 +69,4 @@
}
-?>
\ No newline at end of file
+?>
--
PEAR CVS Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
|
|