- */
-class PHPTAL_Php_Attribute_TAL_OmitTag extends PHPTAL_Php_Attribute
-{
- public function start()
- {
- if (trim($this->expression) == ''){
- $this->tag->headFootDisabled = true;
- }
- else {
- // print tag header/foot only if condition is false
- $cond = $this->tag->generator->evaluateExpression($this->expression);
- $this->tag->headFootPrintCondition = '!('.$cond.')';
- }
- }
-
- public function end()
- {
- }
-}
-
-?>
diff --git a/PHPTAL/Php/Attribute/TAL/OnError.php b/PHPTAL/Php/Attribute/TAL/OnError.php
deleted file mode 100644
index c22dd9e..0000000
--- a/PHPTAL/Php/Attribute/TAL/OnError.php
+++ /dev/null
@@ -1,81 +0,0 @@
-
-//
-
-require_once PHPTAL_DIR.'PHPTAL/Php/Attribute.php';
-
-// TAL Specifications 1.4
-//
-// argument ::= (['text'] | 'structure') expression
-//
-// Example:
-//
-//
-// My name is .
-// (My login name is
-// Unknown)
-//
-//
-
-/**
- * @package phptal.php.attribute.tal
- * @author Laurent Bedubourg
- */
-class PHPTAL_Php_Attribute_TAL_OnError extends PHPTAL_Php_Attribute
-{
- const ERR_VAR = '$__err__';
-
- public function start()
- {
- $this->tag->generator->doTry();
- $this->tag->generator->pushCode('ob_start()');
- }
-
- public function end()
- {
- $this->tag->generator->pushCode('ob_end_flush()');
- $this->tag->generator->doCatch('Exception '.self::ERR_VAR);
- $this->tag->generator->pushCode('$tpl->addError('.self::ERR_VAR.')');
- $this->tag->generator->pushCode('ob_end_clean()');
-
- $expression = $this->extractEchoType($this->expression);
-
- $code = $this->tag->generator->evaluateExpression($expression);
- switch ($code) {
- case PHPTAL_TALES_NOTHING_KEYWORD:
- break;
-
- case PHPTAL_TALES_DEFAULT_KEYWORD:
- $this->tag->generator->pushHtml('tag->generator->doEcho(self::ERR_VAR);
- $this->tag->generator->pushHtml('');
- break;
-
- default:
- $this->doEcho($code);
- break;
- }
- $this->tag->generator->doEnd();
- }
-}
-
-?>
diff --git a/PHPTAL/Php/Attribute/TAL/Repeat.php b/PHPTAL/Php/Attribute/TAL/Repeat.php
deleted file mode 100644
index d798b6c..0000000
--- a/PHPTAL/Php/Attribute/TAL/Repeat.php
+++ /dev/null
@@ -1,115 +0,0 @@
-
-//
-
-require_once PHPTAL_DIR.'PHPTAL/Php/Attribute.php';
-
-// TAL Specifications 1.4
-//
-// argument ::= variable_name expression
-// variable_name ::= Name
-//
-// Example:
-//
-//
-//
-//
-//
-//
-// | 1 |
-// Widget |
-// $1.50 |
-//
-//
-//
-// The following information is available from an Iterator:
-//
-// * index - repetition number, starting from zero.
-// * number - repetition number, starting from one.
-// * even - true for even-indexed repetitions (0, 2, 4, ...).
-// * odd - true for odd-indexed repetitions (1, 3, 5, ...).
-// * start - true for the starting repetition (index 0).
-// * end - true for the ending, or final, repetition.
-// * length - length of the sequence, which will be the total number of repetitions.
-//
-// * letter - count reps with lower-case letters: "a" - "z", "aa" - "az", "ba" - "bz", ..., "za" - "zz", "aaa" - "aaz", and so forth.
-// * Letter - upper-case version of letter.
-// * roman - count reps with lower-case roman numerals: "i", "ii", "iii", "iv", "v", "vi" ...
-// * Roman - upper-case version of roman numerals.
-///
-// * first - true for the first item in a group - see note below
-// * lasst - true for the last item in a group - see note below
-//
-// Note: first and last are intended for use with sorted sequences. They try to
-// divide the sequence into group of items with the same value. If you provide
-// a path, then the value obtained by following that path from a sequence item
-// is used for grouping, otherwise the value of the item is used. You can
-// provide the path by appending it to the path from the repeat variable,
-// as in "repeat/item/first/color".
-//
-// PHPTAL: index, number, even, etc... will be stored in the
-// $ctx->repeat->'item' object. Thus $ctx->repeat->item->odd
-//
-
-
-/**
- * @package phptal.php.attribute.tal
- * @author Laurent Bedubourg
- */
-class PHPTAL_Php_Attribute_TAL_Repeat extends PHPTAL_Php_Attribute
-{
- const REPEAT = '$__repeat__';
-
- public function start()
- {
- // alias to repeats handler to avoid calling extra getters on each variable access
- $this->tag->generator->doSetVar( self::REPEAT, '$ctx->repeat' );
-
- list( $varName, $expression ) = $this->parseSetExpression( $this->expression );
- $code = $this->tag->generator->evaluateExpression( $expression );
-
- $item = '$ctx->' . $varName;
- $controller = self::REPEAT . '->' . $varName;
-
- // reset item var into template context
- /* // Is this actually needed?
- $this->tag->generator->doIf( '!isset('.$this->item.')' );
- $this->tag->generator->doSetVar( $this->item, 'false' );
- $this->tag->generator->doEnd();
- */
-
- // instantiate controller using expression
- $this->tag->generator->doSetVar( $controller, 'new PHPTAL_RepeatController('.$code.')' );
-
- // Lets loop the iterator with a foreach construct
- $this->tag->generator->doForeach( $item, $controller );
- }
-
- public function end()
- {
- $this->tag->generator->doEnd();
- }
-
- private $item;
- private $controller;
-}
-
-?>
diff --git a/PHPTAL/Php/Attribute/TAL/Replace.php b/PHPTAL/Php/Attribute/TAL/Replace.php
deleted file mode 100644
index 121b457..0000000
--- a/PHPTAL/Php/Attribute/TAL/Replace.php
+++ /dev/null
@@ -1,117 +0,0 @@
-
-//
-
-require_once PHPTAL_DIR.'PHPTAL/Php/Attribute.php';
-
-// TAL Specifications 1.4
-//
-// argument ::= (['text'] | 'structure') expression
-//
-// Default behaviour : text
-//
-// Title
-// Title
-//
-// This element is a comment.
-//
-
-require_once PHPTAL_DIR.'PHPTAL/Php/TalesChainExecutor.php';
-
-/**
- * @package phptal.php.attribute.tal
- * @author Laurent Bedubourg
- */
-class PHPTAL_Php_Attribute_TAL_Replace
-extends PHPTAL_Php_Attribute
-implements PHPTAL_Php_TalesChainReader
-{
- const REPLACE_VAR = '$__replace__';
-
- public function start()
- {
- // tal:replace="" => do nothing and ignore node
- if (trim($this->expression) == ""){
- return;
- }
-
- $expression = $this->extractEchoType($this->expression);
- $code = $this->tag->generator->evaluateExpression($expression);
-
- // chained expression
- if (is_array($code)){
- return $this->replaceByChainedExpression($code);
- }
-
- // nothing do nothing
- if ($code == PHPTAL_TALES_NOTHING_KEYWORD) {
- return;
- }
-
- // default generate default tag content
- if ($code == PHPTAL_TALES_DEFAULT_KEYWORD) {
- return $this->generateDefault();
- }
-
- // replace tag with result of expression
- $this->doEcho($code);
- }
-
- public function end()
- {
- }
-
- private function replaceByChainedExpression($expArray)
- {
- $executor = new PHPTAL_Php_TalesChainExecutor(
- $this->tag->generator, $expArray, $this
- );
- }
-
- public function talesChainNothingKeyword(PHPTAL_Php_TalesChainExecutor $executor)
- {
- $executor->continueChain();
- }
-
- public function talesChainDefaultKeyword(PHPTAL_Php_TalesChainExecutor $executor)
- {
- $executor->doElse();
- $this->generateDefault();
- $executor->breakChain();
- }
-
- public function talesChainPart(PHPTAL_Php_TalesChainExecutor $executor, $exp, $islast)
- {
- $executor->doIf('!phptal_isempty('.self::REPLACE_VAR.' = '.$exp.')');
- $this->doEcho(self::REPLACE_VAR);
- }
-
- private function generateDefault()
- {
- $this->tag->generateSurroundHead();
- $this->tag->generateHead();
- $this->tag->generateContent();
- $this->tag->generateFoot();
- $this->tag->generateSurroundFoot();
- }
-}
-
-?>
diff --git a/PHPTAL/Php/CodeGenerator.php b/PHPTAL/Php/CodeGenerator.php
deleted file mode 100644
index 5d7bb71..0000000
--- a/PHPTAL/Php/CodeGenerator.php
+++ /dev/null
@@ -1,55 +0,0 @@
-_functionName = $function_name;
- $this->_sourceFile = $source_path;
- $this->_state = new PHPTAL_Php_State();
- $this->_writer = new PHPTAL_Php_CodeWriter($this->_state);
- }
-
- public function setOutputMode($mode)
- {
- $this->_state->setOutputMode($mode);
- }
-
- public function setEncoding($enc)
- {
- $this->_state->setEncoding($enc);
- }
-
- public function generate(PHPTAL_Dom_Tree $tree)
- {
- $treeGen = new PHPTAL_Php_Tree($this->_writer, $tree);
-
- $this->_writer->doComment('Generated by PHPTAL from '.$this->_sourceFile);
- $this->_writer->doFunction($this->_functionName, '$tpl, $ctx');
- $this->_writer->setFunctionPrefix($this->_functionName . "_");
- $this->_writer->doSetVar('$glb', '$tpl->getGlobalContext()');
- $this->_writer->doSetVar('$_translator', '$tpl->getTranslator()');
- $treeGen->generate();
- $this->_writer->doEnd();
- }
-
- public function getResult()
- {
- return $this->_writer->getResult();
- }
-
-
- private $_functionName;
- private $_sourceFile;
- private $_writer;
- private $_state;
-}
-
-?>
diff --git a/PHPTAL/Php/CodeWriter.php b/PHPTAL/Php/CodeWriter.php
deleted file mode 100644
index 9feebb2..0000000
--- a/PHPTAL/Php/CodeWriter.php
+++ /dev/null
@@ -1,394 +0,0 @@
-
-//
-
-/**
- * Helps generate php representation of a template.
- *
- * @package phptal.php
- * @author Laurent Bedubourg
- */
-class PHPTAL_Php_CodeWriter
-{
- public $_indentation = 0;
- public function __construct(PHPTAL_Php_State $state)
- {
- $this->_state = $state;
- }
-
- public function getResult()
- {
- $this->flush();
- $this->_result = trim($this->_result);
- return $this->_result;
- }
-
- public function setDocType(PHPTAL_Php_Doctype $dt)
- {
- $this->_doctype = str_replace('\'', '\\\'', $dt->node->getValue());
- }
-
- public function setXmlDeclaration(PHPTAL_Php_XmlDeclaration $dt)
- {
- $this->_xmldeclaration = str_replace('\'', '\\\'', $dt->node->getValue());
- }
-
- public function setFunctionPrefix($prefix)
- {
- $this->_functionPrefix = $prefix;
- }
-
- public function getFunctionPrefix()
- {
- return $this->_functionPrefix;
- }
-
- /**
- * Returns old tales mode.
- */
- public function setTalesMode($mode)
- {
- return $this->_state->setTalesMode($mode);
- }
-
- public function splitExpression($src)
- {
- preg_match_all('/(?:[^;]+|;;)+/sm', $src, $array);
- $array = $array[0];
- foreach($array as &$a) $a = str_replace(';;',';',$a);
- return $array;
- }
-
- public function evaluateExpression($src)
- {
- return $this->_state->evalTalesExpression($src);
- }
-
- public function indent()
- {
- $this->_indentation ++;
- }
-
- public function unindent()
- {
- $this->_indentation --;
- }
-
- public function flush()
- {
- $this->flushCode();
- $this->flushHtml();
- }
-
- public function noThrow($bool)
- {
- if ($bool){
- $this->pushCode('$ctx->noThrow(true)');
- }
- else {
- $this->pushCode('$ctx->noThrow(false)');
- }
- }
-
- public function flushCode()
- {
- if (count($this->_codeBuffer) == 0)
- return;
-
- // special treatment for one code line
- if (count($this->_codeBuffer) == 1){
- $codeLine = $this->_codeBuffer[0];
- // avoid adding ; after } and {
- if (!preg_match('/\}|\{\s+$/', $codeLine))
- $this->_result .= '';
- else
- $this->_result .= '';
- $this->_codeBuffer = array();
- return;
- }
-
- $this->_result .= '_codeBuffer as $codeLine) {
- // avoid adding ; after } and {
- if (!preg_match('/\}|\{\s+$/', $codeLine))
- $this->_result .= $codeLine . ' ;'."\n";
- else
- $this->_result .= $codeLine;
- }
- $this->_result .= '?>';
- $this->_codeBuffer = array();
- }
-
- public function flushHtml()
- {
- if (count($this->_htmlBuffer) == 0) return;
-
- $this->_result .= join( '', $this->_htmlBuffer );
- $this->_htmlBuffer = array();
- }
-
- public function doDoctype()
- {
- if ($this->_doctype){
- $code = '$ctx->setDocType(\''.$this->_doctype.'\')';
- $this->pushCode($code);
- }
- }
-
- public function doXmlDeclaration()
- {
- if ($this->_xmldeclaration){
- $code = '$ctx->setXmlDeclaration(\''.$this->_xmldeclaration.'\')';
- $this->pushCode($code);
- }
- }
-
- public function doFunction($name, $params)
- {
- $name = $this->_functionPrefix . $name;
- $this->pushGeneratorContext();
- $this->pushCode("function $name( $params ) {\n");
- $this->indent();
- array_push($this->_segments, 'function');
- }
-
- public function doComment($comment)
- {
- $comment = str_replace('*/', '* /', $comment);
- $this->pushCode("/* $comment */");
- }
-
- public function doEval($code)
- {
- $this->pushCode($code);
- }
-
- public function doForeach($out, $source)
- {
- array_push($this->_segments, 'foreach');
- $this->pushCode("foreach ($source as \$__key__ => $out ):");
- $this->indent();
- }
-
- public function doEnd()
- {
- $segment = array_pop($this->_segments);
- $this->unindent();
- if ($segment == 'function') {
- $this->pushCode("\n}\n\n");
- $functionCode = $this->getResult();
- $this->popGeneratorContext();
- $this->_result = $functionCode . $this->_result;
- }
- else if ($segment == 'try')
- $this->pushCode('}');
- else if ($segment == 'catch')
- $this->pushCode('}');
- else
- $this->pushCode("end$segment");
- }
-
- public function doTry()
- {
- array_push($this->_segments, 'try');
- $this->pushCode('try {');
- $this->indent();
- }
-
- public function doSetVar($varname, $code)
- {
- $this->pushCode($varname.' = '.$code);
- }
-
- public function doCatch($catch)
- {
- $this->doEnd();
- array_push($this->_segments, 'catch');
- $code = 'catch(%s) {';
- $this->pushCode(sprintf($code, $catch));
- $this->indent();
- }
-
- public function doIf($condition)
- {
- array_push($this->_segments, 'if');
- $this->pushCode('if ('.$condition.'): ');
- $this->indent();
- }
-
- public function doElseIf($condition)
- {
- $this->unindent();
- $this->pushCode('elseif ('.$condition.'): ');
- $this->indent();
- }
-
- public function doElse()
- {
- $this->unindent();
- $this->pushCode('else: ');
- $this->indent();
- }
-
- public function doEcho($code)
- {
- $this->flush();
- $html = '';
- $html = sprintf($html, $this->escapeCode($code));
- $this->pushHtml($html);
- }
-
- public function doEchoRaw($code)
- {
- $this->pushHtml('');
- }
-
- public function pushHtml($html)
- {
- $html = $this->_state->interpolateTalesVarsInHtml($html);
- $this->flushCode();
- array_push($this->_htmlBuffer, $html);
- }
-
- public function pushRawHtml($html)
- {
- $this->flushCode();
- array_push($this->_htmlBuffer, $html);
- }
-
- public function pushString($str)
- {
- $this->flushCode();
-
- // replace ${var} inside strings
- while (preg_match('/^(.*?)((?escapeLTandGT($before);
- array_push($this->_htmlBuffer, $before);
-
- $expression = $this->_state->interpolateTalesVarsInHtml($expression);
- array_push($this->_htmlBuffer, $expression);
-
- $str = $after;
- }
-
- $str = str_replace('$${', '${', $str);
-
- if (strlen($str) > 0){
- $str = $this->escapeLTandGT($str);
- array_push($this->_htmlBuffer, $str);
- }
- }
-
- public function pushCode($codeLine)
- {
- $this->flushHtml();
- $codeLine = $this->indentSpaces() . $codeLine;
- array_push($this->_codeBuffer, $codeLine);
- }
-
- public function escapeLTandGT($str){
- $str = str_replace('<', '<', $str);
- $str = str_replace('>', '>', $str);
- return $str;
- }
-
- public function escapeCode($code)
- {
- return $this->_state->htmlchars($code);
- }
-
- public function getEncoding()
- {
- return $this->_state->getEncoding();
- }
-
- public function interpolateTalesVarsInString($src)
- {
- return $this->_state->interpolateTalesVarsInString($src);
- }
-
- public function setDebug($bool)
- {
- return $this->_state->setDebug($bool);
- }
-
- public function isDebugOn()
- {
- return $this->_state->isDebugOn();
- }
-
- public function getOutputMode()
- {
- return $this->_state->getOutputMode();
- }
-
- public function pushContext()
- {
- $this->pushCode('$ctx = $tpl->pushContext()');
- }
-
- public function popContext()
- {
- $this->pushCode('$ctx = $tpl->popContext()');
- }
-
- // ~~~~~ Private members ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- private function indentSpaces()
- {
- return str_repeat("\t", $this->_indent);
- }
-
- private function pushGeneratorContext()
- {
- array_push($this->_contexts, clone $this);
- $this->_result = "";
- $this->_indent = 0;
- $this->_codeBuffer = array();
- $this->_htmlBuffer = array();
- $this->_segments = array();
- }
-
- private function popGeneratorContext()
- {
- $oldContext = array_pop($this->_contexts);
- $this->_result = $oldContext->_result;
- $this->_indent = $oldContext->_indent;
- $this->_codeBuffer = $oldContext->_codeBuffer;
- $this->_htmlBuffer = $oldContext->_htmlBuffer;
- $this->_segments = $oldContext->_segments;
- }
-
- private $_state;
- private $_result = "";
- private $_indent = 0;
- private $_codeBuffer = array();
- private $_htmlBuffer = array();
- private $_segments = array();
- private $_contexts = array();
- private $_functionPrefix = "";
- private $_doctype = "";
- private $_xmldeclaration = "";
-}
-
-?>
diff --git a/PHPTAL/Php/ElementWriter.php b/PHPTAL/Php/ElementWriter.php
deleted file mode 100644
index 4dd24d1..0000000
--- a/PHPTAL/Php/ElementWriter.php
+++ /dev/null
@@ -1,101 +0,0 @@
-
-//
-
-/**
- * @package phptal.php
- */
-class PHPTAL_Php_ElementWriter
-{
- public function __construct(PHPTAL_Php_CodeWriter $writer, PHPTAL_Php_Element $tag)
- {
- $this->_writer = $writer;
- $this->_tag = $tag;
- }
-
- public function writeHead()
- {
- if ($this->_tag->headFootDisabled)
- return;
-
- if ($this->_tag->headFootPrintCondition){
- $this->_writer->doIf($this->_tag->headFootPrintCondition);
- }
-
- $this->_writer->pushHtml('<'.$this->_tag->name);
- $this->_writeAttributes();
-
- if ($this->_tag->isEmptyNode()){
- $this->_writer->pushHtml('/>');
- }
- else {
- $this->_writer->pushHtml('>');
- }
-
- if ($this->_tag->headFootPrintCondition){
- $this->_writer->doEnd();
- }
-
- }
-
- public function writeFoot()
- {
- if ($this->_tag->headFootDisabled)
- return;
- if ($this->_tag->isEmptyNode())
- return;
-
- if ($this->_tag->headFootPrintCondition){
- $this->_writer->doIf($this->_tag->headFootPrintCondition);
- }
-
- $this->_writer->pushHtml(''.$this->_tag->name.'>');
-
- if ($this->_tag->headFootPrintCondition){
- $this->_writer->doEnd();
- }
- }
-
- public function writeAttributes()
- {
- $fullreplaceRx = PHPTAL_Php_Attribute_TAL_Attributes::REGEX_FULL_REPLACE;
- foreach ($this->_tag->attributes as $key=>$value) {
- if (preg_match($fullreplaceRx, $value)){
- $this->_writer->pushHtml($value);
- }
- /*
- else if (strpos('_writer->pushHtml(' '.$key.'="');
- $this->_writer->pushRawHtml($value);
- $this->_writer->pushHtml('"');
- }
- */
- else {
- $this->_writer->pushHtml(' '.$key.'="'.$value.'"');
- }
- }
- }
-
- private $_tag;
- private $_writer;
-}
-
-?>
diff --git a/PHPTAL/Php/Node.php b/PHPTAL/Php/Node.php
deleted file mode 100644
index 5667a56..0000000
--- a/PHPTAL/Php/Node.php
+++ /dev/null
@@ -1,507 +0,0 @@
-
-//
-
-require_once PHPTAL_DIR.'PHPTAL/Dom/Defs.php';
-require_once PHPTAL_DIR.'PHPTAL/Php/CodeWriter.php';
-require_once PHPTAL_DIR.'PHPTAL/Php/Attribute.php';
-
-/**
- * Document node abstract class.
- * @package phptal.php
- * @author Laurent Bedubourg
- */
-abstract class PHPTAL_Php_Node
-{
- public $node;
- public $generator;
-
- public function __construct(PHPTAL_Php_CodeWriter $generator, PHPTAL_Dom_Node $node)
- {
- $this->generator = $generator;
- $this->node = $node;
- }
-
- public function getSourceFile()
- {
- return $this->node->getSourceFile();
- }
-
- public function getSourceLine()
- {
- return $this->node->getSourceLine();
- }
-
- public abstract function generate();
-}
-
-/**
- * Node container.
- *
- * @package phptal.php
- * @author Laurent Bedubourg
- */
-class PHPTAL_Php_Tree extends PHPTAL_Php_Node
-{
- public $children;
-
- public function __construct(PHPTAL_Php_CodeWriter $gen, $node)
- {
- parent::__construct($gen,$node);
- $this->children = array();
- foreach ($node->getChildren() as $child){
- if ($child instanceOf PHPTAL_Dom_Element){
- $gen = new PHPTAL_Php_Element($this->generator, $child);
- }
- else if ($child instanceOf PHPTAL_Dom_Text){
- $gen = new PHPTAL_Php_Text($this->generator, $child);
- }
- else if ($child instanceOf PHPTAL_Dom_Doctype){
- $gen = new PHPTAL_Php_Doctype($this->generator, $child);
- }
- else if ($child instanceOf PHPTAL_Dom_XmlDeclaration){
- $gen = new PHPTAL_Php_XmlDeclaration($this->generator, $child);
- }
- else if ($child instanceOf PHPTAL_Dom_Specific){
- $gen = new PHPTAL_Php_Specific($this->generator, $child);
- }
- else if ($child instanceOf PHPTAL_Dom_Comment){
- $gen = new PHPTAL_Php_Comment($this->generator, $child);
- }
- else {
- throw new PHPTAL_Exception('Unhandled node class '.get_class($child));
- }
- array_push($this->children, $gen);
- }
- }
-
- public function generate()
- {
- try
- {
- foreach ($this->children as $child){
- $child->generate();
- }
- }
- catch(PHPTAL_Exception $e)
- {
- $e->hintSrcPosition($this->getSourceFile(), $this->getSourceLine());
- throw $e;
- }
- }
-}
-
-/**
- * Document Tag representation.
- *
- * This is the main class used by PHPTAL because TAL is a Template Attribute
- * Language, other Node kinds are (usefull) toys.
- *
- * @package phptal.php
- * @author Laurent Bedubourg
- */
-class PHPTAL_Php_Element extends PHPTAL_Php_Tree
-{
- const ERR_ATTRIBUTES_CONFLICT =
- "Attribute conflict in '%s' at line '%d', '%s' cannot appear with '%s'";
-
- public $name;
- public $attributes = array();
- public $talAttributes = array();
- public $overwrittenAttributes = array();
- public $replaceAttributes = array();
- public $contentAttributes = array();
- public $surroundAttributes = array();
- public $headFootDisabled = false;
- public $headFootPrintCondition = false;
- public $hidden = false;
-
- public function __construct(PHPTAL_Php_CodeWriter $generator, $node)
- {
- parent::__construct($generator, $node);
- $this->name = $node->getName();
- $this->attributes = $node->attributes;
- $this->xmlns = $node->getXmlnsState();
- $this->prepare();
- }
-
- private function prepare()
- {
- $this->prepareAttributes();
- $this->separateAttributes();
- $this->orderTalAttributes();
- }
-
- public function generate()
- {
- if ($this->generator->isDebugOn()){
- $this->generator->pushCode('$ctx->__line = '.$this->getSourceLine());
- $this->generator->doComment('tag "'.$this->name.'" from line '.$this->getSourceLine());
- }
-
-
- if (count($this->replaceAttributes) > 0) {
- $this->generateSurroundHead();
- foreach ($this->replaceAttributes as $att) {
- $att->start();
- $att->end();
- }
- $this->generateSurroundFoot();
- return;
- }
-
- $this->generateSurroundHead();
- // a surround tag may decide to hide us (tal:define for example)
- if (!$this->hidden){
- $this->generateHead();
- $this->generateContent();
- $this->generateFoot();
- }
- $this->generateSurroundFoot();
- }
-
- /** Returns true if the element contains specified PHPTAL attribute. */
- public function hasAttribute($name)
- {
- return $this->node->hasAttribute($name);
- }
-
- /** Returns the value of specified PHPTAL attribute. */
- public function getAttribute($name)
- {
- return $this->node->getAttribute($name);
- }
-
- public function isOverwrittenAttribute($name)
- {
- return array_key_exists($name, $this->overwrittenAttributes);
- }
-
- public function getOverwrittenAttributeVarName($name)
- {
- return $this->overwrittenAttributes[$name];
- }
-
- public function overwriteAttributeWithPhpValue($name, $phpVariable)
- {
- $this->attributes[$name] = '';
- $this->overwrittenAttributes[$name] = $phpVariable;
- }
-
- /**
- * Returns true if this element or one of its PHPTAL attributes has some
- * content to print (an empty text node child does not count).
- */
- public function hasRealContent()
- {
- return $this->node->hasRealContent()
- || count($this->contentAttributes) > 0;
- }
-
- public function hasRealAttributes()
- {
- return ((count($this->attributes) - count($this->talAttributes)) > 0) || $this->hasAttribute('tal:attributes');
- }
-
- // ~~~~~ Generation methods may be called by some PHPTAL attributes ~~~~~
-
- public function generateSurroundHead()
- {
- foreach ($this->surroundAttributes as $att) {
- $att->start();
- }
- }
-
- public function generateHead()
- {
- if ($this->headFootDisabled) return;
- if ($this->headFootPrintCondition) {
- $this->generator->doIf($this->headFootPrintCondition);
- }
-
- $this->generator->pushHtml('<'.$this->name);
- $this->generateAttributes();
-
- if ($this->isEmptyNode()){
- $this->generator->pushHtml('/>');
- }
- else {
- $this->generator->pushHtml('>');
- }
-
- if ($this->headFootPrintCondition) {
- $this->generator->doEnd();
- }
- }
-
- public function generateContent($realContent=false)
- {
- if ($this->isEmptyNode()){
- return;
- }
-
- if (!$realContent && count($this->contentAttributes) > 0) {
- foreach ($this->contentAttributes as $att) {
- $att->start();
- $att->end();
- }
- return;
- }
-
- parent::generate();
- }
-
- public function generateFoot()
- {
- if ($this->headFootDisabled)
- return;
- if ($this->isEmptyNode())
- return;
-
- if ($this->headFootPrintCondition) {
- $this->generator->doIf($this->headFootPrintCondition);
- }
-
- $this->generator->pushHtml( ''.$this->name.'>' );
-
- if ($this->headFootPrintCondition) {
- $this->generator->doEnd();
- }
- }
-
- public function generateSurroundFoot()
- {
- for ($i = (count($this->surroundAttributes)-1); $i >= 0; $i--) {
- $this->surroundAttributes[$i]->end();
- }
- }
-
- // ~~~~~ Private members ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- private function generateAttributes()
- {
- // A phptal attribute can modify any node attribute replacing
- // its value by a .
- //
- // The entire attribute (key="value") can be replaced using the
- // '$__ATT_' value code, it is very usefull for xhtml boolean
- // attributes like selected, checked, etc...
- //
- // example:
- //
- // $tag->generator->pushCode(
- // '$__ATT_checked = $somecondition ? \'checked="checked"\' : \'\''
- // );
- // $tag->attributes['checked'] = '';
- //
-
- $fullreplaceRx = PHPTAL_Php_Attribute_TAL_Attributes::REGEX_FULL_REPLACE;
- foreach ($this->attributes as $key=>$value) {
- if (preg_match($fullreplaceRx, $value)){
- $this->generator->pushHtml($value);
- }
- else if (strpos($value,'generator->pushHtml(' '.$key.'="');
- $this->generator->pushRawHtml($value);
- $this->generator->pushHtml('"');
- }
- else {
- $this->generator->pushHtml(' '.$key.'="'.$value.'"');
- }
- }
- }
-
- private function getNodePrefix()
- {
- $result = false;
- if (preg_match('/^(.*?):block$/', $this->name, $m)){
- list(,$result) = $m;
- }
- return $result;
- }
-
- private function isEmptyNode()
- {
- return ($this->generator->getOutputMode() == PHPTAL::XHTML && PHPTAL_Dom_Defs::getInstance()->isEmptyTag($this->name)) ||
- ($this->generator->getOutputMode() == PHPTAL::XML && !$this->hasContent());
- }
-
- private function hasContent()
- {
- return count($this->children) > 0 || count($this->contentAttributes) > 0;
- }
-
- private function prepareAttributes()
- {
- //TODO: use registered namespaces instead of the raw list
- if (preg_match('/^(tal|metal|phptal|i18n):block$/', $this->name, $m)) {
- $this->headFootDisabled = true;
- list(,$ns) = $m;
- $attributes = array();
- foreach ($this->attributes as $key=>$value) {
- if ($this->xmlns->isPhpTalAttribute("$ns:$key")) {
- $attributes["$ns:$key"] = $value;
- }
- else {
- $attributes[$key] = $value;
- }
- }
- $this->attributes = $attributes;
- }
- }
-
- private function separateAttributes()
- {
- $attributes = array();
- $this->talAttributes = array();
- foreach ($this->attributes as $key=>$value) {
- // remove handled xml namespaces
- if (PHPTAL_Dom_Defs::getInstance()->isHandledXmlNs($key,$value)){
- }
- else if ($this->xmlns->isPhpTalAttribute($key)) {
- $this->talAttributes[$key] = $value;
- }
- else if (PHPTAL_Dom_Defs::getInstance()->isBooleanAttribute($key)) {
- $attributes[$key] = $key;
- }
- else {
- $attributes[$key] = $value;
- }
- }
- $this->attributes = $attributes;
- }
-
- private function orderTalAttributes()
- {
- $attributes = array();
- foreach ($this->talAttributes as $key=>$exp){
- $name = $this->xmlns->unAliasAttribute($key);
- $att = PHPTAL_Dom_Defs::getInstance()->getNamespaceAttribute($name);
- if (array_key_exists($att->getPriority(), $attributes)){
- $err = sprintf(self::ERR_ATTRIBUTES_CONFLICT,
- $this->name,
- $this->getSourceLine(),
- $key,
- $attributes[$att->getPriority()][0]
- );
- throw new PHPTAL_Exception($err);
- }
- $attributes[$att->getPriority()] = array($key, $att, $exp);
- }
- ksort($attributes);
-
- $this->talHandlers = array();
- foreach ($attributes as $prio => $dat){
- list($key, $att, $exp) = $dat;
- $handler = $att->createAttributeHandler($this, $exp);
- $this->talHandlers[$prio] = $handler;
-
- if ($att instanceOf PHPTAL_NamespaceAttributeSurround)
- $this->surroundAttributes[] = $handler;
- else if ($att instanceOf PHPTAL_NamespaceAttributeReplace)
- $this->replaceAttributes[] = $handler;
- else if ($att instanceOf PHPTAL_NamespaceAttributeContent)
- $this->contentAttributes[] = $handler;
- else
- throw new PHPTAL_Exception("Unknown namespace attribute class ".get_class($att));
-
- }
- }
-}
-
-/**
- * @package phptal.php
- */
-class PHPTAL_Php_Comment extends PHPTAL_Php_Node
-{
- public function generate()
- {
- $this->generator->pushRawHtml($this->node->getValue());
- }
-}
-
-/**
- * Document text data representation.
- * @package phptal.php
- */
-class PHPTAL_Php_Text extends PHPTAL_Php_Node
-{
- public function generate()
- {
- $this->generator->pushString($this->node->getValue());
- }
-}
-
-/**
- * Comment, preprocessor, etc... representation.
- *
- * @package phptal.php
- * @author Laurent Bedubourg
- */
-class PHPTAL_Php_Specific extends PHPTAL_Php_Node
-{
- public function generate()
- {
- $this->generator->pushHtml($this->node->getValue());
- }
-}
-
-/**
- * Document doctype representation.
- *
- * @package phptal.php
- * @author Laurent Bedubourg
- */
-class PHPTAL_Php_Doctype extends PHPTAL_Php_Node
-{
- public function __construct(PHPTAL_Php_CodeWriter $generator, $node)
- {
- parent::__construct($generator, $node);
- $this->generator->setDocType($this);
- }
-
- public function generate()
- {;
- $this->generator->doDoctype();
- }
-}
-
-/**
- * XML declaration node.
- *
- * @package phptal.php
- * @author Laurent Bedubourg
- */
-class PHPTAL_Php_XmlDeclaration extends PHPTAL_Php_Node
-{
- public function __construct(PHPTAL_Php_CodeWriter $gen, $node)
- {
- parent::__construct($gen, $node);
- $this->generator->setXmlDeclaration($this);
- }
-
- public function generate()
- {
- $this->generator->doXmlDeclaration();
- }
-}
-
-?>
diff --git a/PHPTAL/Php/State.php b/PHPTAL/Php/State.php
deleted file mode 100644
index ce1ce9c..0000000
--- a/PHPTAL/Php/State.php
+++ /dev/null
@@ -1,152 +0,0 @@
-
-//
-
-require_once PHPTAL_DIR.'PHPTAL/Php/Tales.php';
-
-/**
- * @package phptal.php
- */
-class PHPTAL_Php_State
-{
- public function __construct()
- {
- $this->_debug = false;
- $this->_talesMode = 'tales';
- $this->_encoding = 'UTF-8';
- $this->_outputMode = '';
- }
-
- public function setDebug($bool)
- {
- $old = $this->_debug;
- $this->_debug = $bool;
- return $old;
- }
-
- public function isDebugOn()
- {
- return $this->_debug;
- }
-
- public function setTalesMode($mode)
- {
- $old = $this->_talesMode;
- $this->_talesMode = $mode;
- return $old;
- }
-
- public function getTalesMode()
- {
- return $this->_talesMode;
- }
-
- public function setEncoding($enc)
- {
- $this->_encoding = $enc;
- }
-
- public function getEncoding()
- {
- return $this->_encoding;
- }
-
- public function setOutputMode($mode)
- {
- $this->_outputMode = $mode;
- }
-
- public function getOutputMode()
- {
- return $this->_outputMode;
- }
-
- public function evalTalesExpression($expression)
- {
- if ($this->_talesMode == 'php')
- return PHPTAL_TalesInternal::php($expression);
- return phptal_tales($expression);
- }
-
- public function interpolateTalesVarsInString($string)
- {
- if ($this->_talesMode == 'tales'){
- return PHPTAL_TalesInternal::string($string);
- }
-
- // replace ${var} found in expression
- while (preg_match('/(?_encoding);
- $string = str_replace($ori, $repl, $string);
- }
- $string = str_replace('$${', '${', $string);
- return '\''.$string.'\'';
- }
-
- private function _interpolateTalesVarsStructure($matches) {
- return '';
- }
-
- private function _interpolateTalesVarsEscaped($matches) {
- return '_encoding.'\');?>';
- }
-
- public function interpolateTalesVarsInHtml($src)
- {
- if ($this->_talesMode == 'tales'){
- $result = preg_replace_callback('/(?';
- }
- else {
- $repl = 'htmlchars($php).'; ?>';
- }
- $src = str_replace($ori, $repl, $src);
- }
-
- return str_replace('$${','${', $src);
- }
-
- public function htmlchars($php)
- {
- return 'phptal_escape('.$php.', ENT_QUOTES, \''.$this->_encoding.'\')';
- }
-
- private $_debug;
- private $_talesMode;
- private $_encoding;
- private $_outputMode;
-}
-
-?>
diff --git a/PHPTAL/Php/Tales.php b/PHPTAL/Php/Tales.php
deleted file mode 100644
index 0fb7345..0000000
--- a/PHPTAL/Php/Tales.php
+++ /dev/null
@@ -1,135 +0,0 @@
-
-//
-
-define('PHPTAL_TALES_DEFAULT_KEYWORD', '_DEFAULT_DEFAULT_DEFAULT_DEFAULT_');
-define('PHPTAL_TALES_NOTHING_KEYWORD', '_NOTHING_NOTHING_NOTHING_NOTHING_');
-
-
-// TALES Specification 1.3
-//
-// Expression ::= [type_prefix ':'] String
-// type_prefix ::= Name
-//
-// Examples:
-//
-// a/b/c
-// path:a/b/c
-// nothing
-// path:nothing
-// python: 1 + 2
-// string:Hello, ${username}
-//
-//
-// Builtin Names in Page Templates (for PHPTAL)
-//
-// * nothing - special singleton value used by TAL to represent a
-// non-value (e.g. void, None, Nil, NULL).
-//
-// * default - special singleton value used by TAL to specify that
-// existing text should not be replaced.
-//
-// * repeat - the repeat variables (see RepeatVariable).
-//
-
-function _phptal_tale_wrap($array, $nothrow)
-{
- if (count($array)==1) return '($ctx->noThrow('.($nothrow?'true':'false').')||1?('.
- ($array[0]==PHPTAL_TALES_NOTHING_KEYWORD?'NULL':$array[0]).
- '):"")';
-
- $expr = array_shift($array);
-
- return "((\$tmp5=$expr) && (\$ctx->noThrow(false)||1)?\$tmp5:"._phptal_tale_wrap($array, $nothrow).')';
-}
-
-/** translates array of alternative expressions into single PHP expression. Identical to phptal_tales() for singular expressions. */
-function phptal_tale($expression, $nothrow=false)
-{
- $r = phptal_tales($expression,true);
- if (!is_array($r)) return $r;
-
- // this weird ternary operator construct is to execute noThrow inside the expression
- return '($ctx->noThrow(true)||1?'._phptal_tale_wrap($r, $nothrow).':"")';
-}
-
-function phptal_tales($expression, $nothrow=false)
-{
- $expression = trim($expression);
-
- // Look for tales modifier (string:, exists:, etc...)
- //if (preg_match('/^([-a-z]+):(.*?)$/', $expression, $m)) {
- if (preg_match('/^([a-z][-.a-z]*[a-z]):(.*?)$/i', $expression, $m)) {
- list(,$typePrefix,$expression) = $m;
- }
- // may be a 'string'
- else if (preg_match('/^\'((?:[^\']|\\\\.)*)\'$/', $expression, $m)) {
- $expression = stripslashes($m[1]);
- $typePrefix = 'string';
- }
- // failback to path:
- else {
- $typePrefix = 'path';
- }
-
- // is a registered TALES expression modifier
- if(PHPTAL_TalesRegistry::getInstance()->isRegistered($typePrefix)) {
- $callback = PHPTAL_TalesRegistry::getInstance()->getCallback($typePrefix);
- return call_user_func($callback, $expression, $nothrow);
- }
-
- // class method
- if (strpos($typePrefix, '.')){
- $classCallback = explode('.', $typePrefix, 2);
- $callbackName = NULL;
- if(!is_callable($classCallback, FALSE, $callbackName)) {
- $err = 'Unknown phptal modifier %s function %s does not exists or is not statically callable.';
- $err = sprintf($err, $typePrefix, $callbackName);
- throw new PHPTAL_Exception($err);
- }
- $ref = new ReflectionClass($classCallback[0]);
- if(!$ref->implementsInterface('PHPTAL_Tales')){
- $err = 'Unable to use phptal modifier %s as the class %s does not implement the PHPTAL_Tales interface.';
- $err = sprintf($err, $typePrefix, $callbackName);
- throw new PHPTAL_Exception($err);
- }
- return call_user_func($classCallback, $expression, $nothrow);
- }
-
- // check if it is implemented via code-generating function
- $func = 'phptal_tales_'.str_replace('-','_',$typePrefix);
- if (function_exists($func)) {
- return $func($expression, $nothrow);
- }
-
- // check if it is implemented via runtime function
- $runfunc = 'phptal_runtime_tales_'.str_replace('-','_',$typePrefix);
- if (function_exists($runfunc)) {
- return "$runfunc(".phptal_tale($expression, $nothrow).")";
- }
-
- throw new PHPTAL_Exception("Unknown phptal modifier '$typePrefix'. Function '$func' does not exist");
-}
-
-// Register internal Tales expression modifiers
-require_once PHPTAL_DIR.'PHPTAL/Php/TalesInternal.php';
-PHPTAL_TalesInternal::registerInternalTales();
-?>
diff --git a/PHPTAL/Php/TalesChainExecutor.php b/PHPTAL/Php/TalesChainExecutor.php
deleted file mode 100644
index f0d649a..0000000
--- a/PHPTAL/Php/TalesChainExecutor.php
+++ /dev/null
@@ -1,99 +0,0 @@
-_chain = $chain;
- $this->_chainStarted = false;
- $this->_chainGenerator = $generator;
- $this->_reader = $reader;
- $this->_executeChain();
- }
-
- public function doIf($condition)
- {
- if ($this->_chainStarted == false){
- $this->_chainStarted = true;
- $this->_chainGenerator->doIf($condition);
- }
- else {
- $this->_chainGenerator->doElseIf($condition);
- }
- }
-
- public function doElse()
- {
- if ($this->_chainStarted){
- $this->_chainGenerator->doElse();
- }
- }
-
- public function breakChain()
- {
- $this->_state = self::CHAIN_BREAK;
- }
-
- public function continueChain()
- {
- $this->_state = self::CHAIN_CONT;
- }
-
- private function _executeChain()
- {
- $this->_chainGenerator->noThrow(true);
-
- end($this->_chain); $lastkey = key($this->_chain);
-
- foreach ($this->_chain as $key => $exp){
- $this->_state = 0;
- if ($exp == PHPTAL_TALES_NOTHING_KEYWORD){
- $this->_reader->talesChainNothingKeyword($this);
- if ($this->_state == self::CHAIN_BREAK)
- break;
- if ($this->_state == self::CHAIN_CONT)
- continue;
- }
- else if ($exp == PHPTAL_TALES_DEFAULT_KEYWORD){
- $this->_reader->talesChainDefaultKeyword($this);
- if ($this->_state == self::CHAIN_BREAK)
- break;
- if ($this->_state == self::CHAIN_CONT)
- continue;
- }
- else {
- $this->_reader->talesChainPart($this, $exp, $lastkey === $key);
- if ($this->_state == self::CHAIN_BREAK)
- break;
- if ($this->_state == self::CHAIN_CONT)
- continue;
- }
- }
- $this->_chainGenerator->doEnd();
- $this->_chainGenerator->noThrow(false);
- }
-
- private $_state = 0;
- private $_chain;
- private $_chainStarted = false;
- private $_chainGenerator = null;
-}
-
-?>
diff --git a/PHPTAL/Php/TalesInternal.php b/PHPTAL/Php/TalesInternal.php
deleted file mode 100644
index 3cfe2c5..0000000
--- a/PHPTAL/Php/TalesInternal.php
+++ /dev/null
@@ -1,331 +0,0 @@
-
-// Moritz Bechler
-//
-
-require_once PHPTAL_DIR.'PHPTAL/TalesRegistry.php';
-
-class PHPTAL_TalesInternal implements PHPTAL_Tales {
-
- //
- // This function registers all internal expression modifiers
- //
- static public function registerInternalTales() {
-
- static $registered = false;
-
- if($registered) {
- return;
- }
-
- $registry = PHPTAL_TalesRegistry::getInstance();
-
- $registry->registerPrefix('not', array(__CLASS__, 'not'));
- $registry->registerPrefix('path', array(__CLASS__, 'path'));
- $registry->registerPrefix('string', array(__CLASS__, 'string'));
- $registry->registerPrefix('php', array(__CLASS__, 'php'));
- $registry->registerPrefix('exists', array(__CLASS__, 'exists'));
- $registry->registerPrefix('number', array(__CLASS__, 'number'));
- $registry->registerPrefix('true', array(__CLASS__, 'true'));
-
- $registered = true;
- }
-
- static public function true($src, $nothrow)
- {
- return sprintf('phptal_true($ctx, %s)', self::string(trim($src), $nothrow));
- }
-
- //
- // not:
- //
- // not: Expression
- //
- // evaluate the expression string (recursively) as a full expression,
- // and returns the boolean negation of its value
- //
- // return boolean based on the following rules:
- //
- // 1. integer 0 is false
- // 2. integer > 0 is true
- // 3. an empty string or other sequence is false
- // 4. a non-empty string or other sequence is true
- // 5. a non-value (e.g. void, None, Nil, NULL, etc) is false
- // 6. all other values are implementation-dependent.
- //
- // Examples:
- //
- // not: exists: foo/bar/baz
- // not: php: object.hasChildren()
- // not: string:${foo}
- // not: foo/bar/booleancomparable
- //
- static public function not($expression, $nothrow)
- {
- return '!(' . phptal_tales($expression, $nothrow) . ')';
- }
-
-
- //
- // path:
- //
- // PathExpr ::= Path [ '|' Path ]*
- // Path ::= variable [ '/' URL_Segment ]*
- // variable ::= Name
- //
- // Examples:
- //
- // path: username
- // path: user/name
- // path: object/method/10/method/member
- // path: object/${dynamicmembername}/method
- // path: maybethis | path: maybethat | path: default
- //
- // PHPTAL:
- //
- // 'default' may lead to some 'difficult' attributes implementation
- //
- // For example, the tal:content will have to insert php code like:
- //
- // if (isset($ctx->maybethis)) {
- // echo $ctx->maybethis;
- // }
- // else if (isset($ctx->maybethat) {
- // echo $ctx->maybethat;
- // }
- // else {
- // // process default tag content
- // }
- //
- // @returns string or array
- //
- static public function path($expression, $nothrow=false)
- {
- $expression = trim($expression);
- if ($expression == 'default') return PHPTAL_TALES_DEFAULT_KEYWORD;
- if ($expression == 'nothing') return PHPTAL_TALES_NOTHING_KEYWORD;
- if ($expression == '') return PHPTAL_TALES_NOTHING_KEYWORD;
-
- // split OR expressions terminated by a string
- if (preg_match('/^(.*?)\s*\|\s*?(string:.*)$/sm', $expression, $m)){
- list(, $expression, $string) = $m;
- }
- // split OR expressions terminated by a 'fast' string
- else if (preg_match('/^(.*?)\s*\|\s*\'((?:[^\'\\\\]|\\\\.)*)\'\s*$/sm', $expression, $m)){
- list(, $expression, $string) = $m;
- $string = 'string:'.stripslashes($string);
- }
-
- // split OR expressions
- $exps = preg_split('/\s*\|\s*/sm', $expression);
-
- // if (many expressions) or (expressions or terminating string) found then
- // generate the array of sub expressions and return it.
- if (count($exps) > 1 || isset($string)) {
- $result = array();
- foreach ($exps as $exp) {
- $result[] = phptal_tales(trim($exp), true);
- }
- if (isset($string)){
- $result[] = phptal_tales($string, true);
- }
- return $result;
- }
-
- // only one expression to process
-
- // first evaluate ${foo} inside the expression and threat the expression
- // as if it was a string to interpolate
- $expression = self::string($expression);
- $expression = substr($expression, 1, -1);
-
- $pos = strpos($expression, '/');
- // if no sub part for this expression, just optimize the generated code
- // and access the $ctx->var
- if ($pos === false) {
- if (!self::checkExpressionPart($expression)) throw new PHPTAL_Exception("Invalid TALES path: '$expression', expected variable name");
- return '$ctx->'.$expression;
- }
-
- // otherwise we have to call phptal_path() to resolve the path at runtime
- // extract the first part of the expression (it will be the phptal_path()
- // $base and pass the remaining of the path to phptal_path()
- $next = substr($expression, 0, $pos);
- $expression = substr($expression, $pos+1);
-
- if (!self::checkExpressionPart($next)) throw new PHPTAL_Exception("Invalid TALES path: '$next/$expression', expected '$next' to be variable name");
-
- // return php code invoking phptal_path($next, $expression, $notrhow)
- return 'phptal_path($ctx->'.$next.', \''.$expression.'\''.($nothrow ? ', true' : '').')';
- }
-
- private static function checkExpressionPart($expression)
- {
- return preg_match('/^(\$?[a-z_][a-z0-9_]*|{.*})$/i',$expression);
- }
-
- //
- // string:
- //
- // string_expression ::= ( plain_string | [ varsub ] )*
- // varsub ::= ( '$' Path ) | ( '${' Path '}' )
- // plain_string ::= ( '$$' | non_dollar )*
- // non_dollar ::= any character except '$'
- //
- // Examples:
- //
- // string:my string
- // string:hello, $username how are you
- // string:hello, ${user/name}
- // string:you have $$130 in your bank account
- //
- static public function string($expression, $nothrow=false)
- {
- // This is a simple parser which evaluates ${foo} inside
- // 'string:foo ${foo} bar' expressions, it returns the php code which will
- // print the string with correct interpollations.
- // Nothing special there :)
-
- $inPath = false;
- $inAccoladePath = false;
- $lastWasDollar = false;
- $result = '';
- $len = strlen($expression);
- for ($i=0; $i<$len; $i++) {
- $c = $expression[$i];
- switch ($c) {
- case '$':
- if ($lastWasDollar) {
- $lastWasDollar = false;
- }
- else {
- $lastWasDollar = true;
- $c = '';
- }
- break;
-
- case '\\':
- $c = '\\\\';
- break;
-
- case '\'':
- $c = '\\\'';
- break;
-
- case '{':
- if ($lastWasDollar) {
- $lastWasDollar = false;
- $inAccoladePath = true;
- $subPath = '';
- $c = '';
- }
- break;
-
- case '}':
- if ($inAccoladePath) {
- $inAccoladePath = false;
- $subEval = self::path($subPath);
- if (is_array($subEval)) {
- $err = 'cannot use | operator in evaluated expressions';
- throw new PHPTAL_Exception($err);
- }
- $result .= "'." . $subEval . ".'";
- $subPath = '';
- $lastWasDollar = false;
- $c = '';
- }
- break;
-
- default:
- if ($lastWasDollar) {
- $lastWasDollar = false;
- $inPath = true;
- $subPath = $c;
- $c = '';
- }
- else if ($inAccoladePath) {
- $subPath .= $c;
- $c = '';
- }
- else if ($inPath) {
- $t = strtolower($c);
- if (($t >= 'a' && $t <= 'z') || ($t >= '0' && $t <= '9') || ($t == '_')){
- $subPath .= $c;
- $c = '';
- }
- else {
- $inPath = false;
- $subEval = self::path($subPath);
- if (is_array($subEval)) {
- $err = 'cannot use | operator in evaluated expressions';
- throw new PHPTAL_Exception($err);
- }
- $result .= "'." . $subEval . ".'";
- }
- }
- break;
- }
- $result .= $c;
- }
- if ($inPath){
- $subEval = self::path($subPath);
- if (is_array($subEval)){
- $err = 'cannot use | operator in evaluated expressions';
- throw new PHPTAL_Exception($err);
- }
- $result .= "'." . $subEval . ".'";
- }
- return '\''.$result.'\'';
- }
-
- /**
- * php: modifier.
- *
- * Transform the expression into a regular PHP expression.
- */
- static public function php($src)
- {
- require_once PHPTAL_DIR.'PHPTAL/Php/Transformer.php';
- return PHPTAL_Php_Transformer::transform($src, '$ctx->');
- }
-
- /**
- * exists: modifier.
- *
- * Returns the code required to invoke phptal_exists() on specified path.
- */
- static public function exists($src, $nothrow)
- {
- return sprintf('phptal_exists($ctx, %s)', self::string(trim($src), $nothrow));
- }
-
- /**
- * number: modifier.
- *
- * Returns the number as is.
- */
- static public function number($src, $nothrow)
- {
- return trim($src);
- }
-}
-
-?>
diff --git a/PHPTAL/Php/Transformer.php b/PHPTAL/Php/Transformer.php
deleted file mode 100644
index e7a81bc..0000000
--- a/PHPTAL/Php/Transformer.php
+++ /dev/null
@@ -1,384 +0,0 @@
-
-//
-
-
-/**
- * Tranform php: expressions into their php equivalent.
- *
- * This transformer produce php code for expressions like :
- *
- * - a.b["key"].c().someVar[10].foo()
- * - (a or b) and (c or d)
- * - not myBool
- * - ...
- *
- * The $prefix variable may be changed to change the context lookup.
- *
- * example:
- *
- * $res = PHPTAL_Php_Transformer::transform('a.b.c[x]', '$ctx->');
- * $res == '$ctx->a->b->c[$ctx->x]';
- *
- * @package phptal.php
- * @author Laurent Bedubourg
- */
-class PHPTAL_Php_Transformer
-{
- const ST_NONE = 0;
- const ST_STR = 1; // 'foo'
- const ST_ESTR = 2; // "foo ${x} bar"
- const ST_VAR = 3; // abcd
- const ST_NUM = 4; // 123.02
- const ST_EVAL = 5; // ${somevar}
- const ST_MEMBER = 6; // abcd.x
- const ST_STATIC = 7; // class::[$]static|const
- const ST_DEFINE = 8; // @MY_DEFINE
-
- public static function transform( $str, $prefix='$' )
- {
-
- //
- // Here comes the good old state machine.
- // TODO: benchmark this version and then benchmark a refactored version
- // with states behaviour separated into methods, keep the fastest.
- //
-
- $len = strlen($str);
- $state = self::ST_NONE;
- $result = '';
- $i = 0;
- $inString = false;
- $backslashed = false;
- $instanceOf = false;
- $eval = false;
-
- for ($i = 0; $i <= $len; $i++) {
- if ($i == $len) $c = "\0";
- else $c = $str[$i];
-
- switch ($state) {
- // no state defined, just eat char and see what to do with it.
- case self::ST_NONE:
- // begin of eval without {
- if ($c == '$' && $i < $len && self::isAlpha($str[$i+1])){
- $state = self::ST_EVAL;
- $mark = $i+1;
- $result .= $prefix.'{';
- }
- // that an alphabetic char, then it should be the begining
- // of a var
- else if (self::isAlpha($c) || $c==='_') {
- $state = self::ST_VAR;
- $mark = $i;
- }
- // begining of double quoted string
- else if ($c == '"') {
- $state = self::ST_ESTR;
- $mark = $i;
- $inString = true;
- }
- // begining of single quoted string
- else if ($c == '\'') {
- $state = self::ST_STR;
- $mark = $i;
- $inString = true;
- }
- // closing a method, an array access or an evaluation
- else if ($c == ')' || $c == ']' || $c == '}') {
- $result .= $c;
- // if next char is dot then an object member must
- // follow
- if ($i < $len-1 && $str[$i+1] == '.') {
- $result .= '->';
- $state = self::ST_MEMBER;
- $mark = $i+2;
- $i+=2;
- }
- }
- // @ is an access to some defined variable
- else if ($c == '@') {
- $state = self::ST_DEFINE;
- $mark = $i+1;
- }
- // character we don't mind about
- else {
- $result .= $c;
- }
- break;
-
- // $xxx
- case self::ST_EVAL:
- if (!self::isVarNameChar($c)){
- $result .= $prefix . substr($str, $mark, $i-$mark);
- $result .= '}';
- $state = self::ST_NONE;
- }
- break;
-
- // single quoted string
- case self::ST_STR:
- if ($c == '\\') {
- $backslashed = true;
- }
- else if ($backslashed) {
- $backslashed = false;
- }
- // end of string, back to none state
- else if ($c == '\'') {
- $result .= substr( $str, $mark, $i-$mark+1 );
- $inString = false;
- $state = self::ST_NONE;
- }
- break;
-
- // double quoted string
- case self::ST_ESTR:
- if ($c == '\\') {
- $backslashed = true;
- }
- else if ($backslashed) {
- $backslashed = false;
- }
- // end of string, back to none state
- else if ($c == '"') {
- $result .= substr( $str, $mark, $i-$mark+1 );
- $inString = false;
- $state = self::ST_NONE;
- }
- // instring interpolation, search } and transform the
- // interpollation to insert it into the string
- else if ($c == '$' && $i < $len && $str[$i+1] == '{') {
- $result .= substr( $str, $mark, $i-$mark ) . '{';
-
- $sub = 0;
- for ($j = $i; $j<$len; $j++) {
- if ($str[$j] == '{') {
- $sub++;
- }
- elseif ($str[$j] == '}' && (--$sub) == 0) {
- $part = substr( $str, $i+2, $j-$i-2 );
- $result .= self::transform($part, $prefix);
- $i = $j;
- $mark = $i;
- }
- }
- }
- break;
-
- // var state
- case self::ST_VAR:
- if (self::isVarNameChar($c)) {
- }
- // end of var, begin of member (method or var)
- else if ($c == '.') {
- $result .= $prefix . substr( $str, $mark, $i-$mark );
- $result .= '->';
- $state = self::ST_MEMBER;
- $mark = $i+1;
- }
- // static call, the var is a class name
- else if ($c == ':') {
- $result .= substr( $str, $mark, $i-$mark+1 );
- $mark = $i+1;
- $i++;
- $state = self::ST_STATIC;
- break;
- }
- // function invocation, the var is a function name
- else if ($c == '(') {
- $result .= substr( $str, $mark, $i-$mark+1 );
- $state = self::ST_NONE;
- }
- // array index, the var is done
- else if ($c == '[') {
- if ($str[$mark]==='_') { // superglobal?
- $result .= '$' . substr( $str, $mark, $i-$mark+1 );
- }
- else {
- $result .= $prefix . substr( $str, $mark, $i-$mark+1 );
- }
- $state = self::ST_NONE;
- }
- // end of var with non-var-name character, handle keywords
- // and populate the var name
- else {
- $var = substr( $str, $mark, $i-$mark );
- $low = strtolower($var);
- // boolean and null
- if ($low == 'true' || $low == 'false' || $low == 'null') {
- $result .= $var;
- }
- // lt, gt, ge, eq, ...
- else if (array_key_exists($low, self::$TranslationTable)){
- $result .= self::$TranslationTable[$low];
- }
- // instanceof keyword
- else if ($low == 'instanceof'){
- $result .= $var;
- $instanceOf = true;
- }
- // previous was instanceof
- else if ($instanceOf){
- // last was instanceof, this var is a class name
- $result .= $var;
- $instanceOf = false;
- }
- // regular variable
- else {
- $result .= $prefix . $var;
- }
- $i--;
- $state = self::ST_NONE;
- }
- break;
-
- // object member
- case self::ST_MEMBER:
- if (self::isVarNameChar($c)) {
- }
- // eval mode ${foo}
- else if ($c == '$') {
- $result .= '{' . $prefix;
- $mark++;
- $eval = true;
- }
- // end of var member var, begin of new member
- else if ($c == '.') {
- $result .= substr( $str, $mark, $i-$mark );
- if ($eval) { $result .='}'; $eval = false; }
- $result .= '->';
- $mark = $i+1;
- $state = self::ST_MEMBER;
- }
- // begin of static access
- else if ($c == ':') {
- $result .= substr( $str, $mark, $i-$mark+1 );
- if ($eval) { $result .='}'; $eval = false; }
- $state = self::ST_STATIC;
- break;
- }
- // the member is a method or an array
- else if ($c == '(' || $c == '[') {
- $result .= substr( $str, $mark, $i-$mark+1 );
- if ($eval) { $result .='}'; $eval = false; }
- $state = self::ST_NONE;
- }
- // regular end of member, it is a var
- else {
- $result .= substr( $str, $mark, $i-$mark );
- if ($eval) { $result .='}'; $eval = false; }
- $state = self::ST_NONE;
- $i--;
- }
- break;
-
- // wait for separator
- case self::ST_DEFINE:
- if (self::isVarNameChar($c)) {
- }
- else {
- $state = self::ST_NONE;
- $result .= substr( $str, $mark, $i-$mark );
- $i--;
- }
- break;
-
- // static call, can be const, static var, static method
- // Klass::$static
- // Klass::const
- // Kclass::staticMethod()
- //
- case self::ST_STATIC:
- if (self::isVarNameChar($c)) {
- }
- // static var
- else if ($c == '$') {
- }
- // end of static var which is an object and begin of member
- else if ($c == '.') {
- $result .= substr( $str, $mark, $i-$mark );
- $result .= '->';
- $mark = $i+1;
- $state = self::ST_MEMBER;
- }
- // end of static var which is a class name
- else if ($c == ':') {
- $result .= substr( $str, $mark, $i-$mark+1 );
- $state = self::ST_STATIC;
- break;
- }
- // static method or array
- else if ($c == '(' || $c == '[') {
- $result .= substr( $str, $mark, $i-$mark+1 );
- $state = self::ST_NONE;
- }
- // end of static var or const
- else {
- $result .= substr( $str, $mark, $i-$mark );
- $state = self::ST_NONE;
- $i--;
- }
- break;
-
- // numeric value
- case self::ST_NUM:
- if (!self::isDigitCompound($c)) {
- $result .= substr( $str, $mark, $i-$mark );
- $state = self::ST_NONE;
- }
- break;
- }
- }
-
- return trim($result);
- }
-
- private static function isAlpha($c)
- {
- $c = strtolower($c);
- return $c >= 'a' && $c <= 'z';
- }
-
- private static function isDigitCompound($c)
- {
- return ($c >= '0' && $c <= '9' || $c == '.');
- }
-
- private static function isVarNameChar($c)
- {
- return self::isAlpha($c) || ($c >= '0' && $c <= '9') || $c == '_';
- }
-
- private static $TranslationTable = array(
- 'not' => '!',
- 'ne' => '!=',
- 'and' => '&&',
- 'or' => '||',
- 'lt' => '<',
- 'gt' => '>',
- 'ge' => '>=',
- 'le' => '<=',
- 'eq' => '==',
- );
-}
-
-?>
diff --git a/PHPTAL/RepeatController.php b/PHPTAL/RepeatController.php
deleted file mode 100644
index 6d05807..0000000
--- a/PHPTAL/RepeatController.php
+++ /dev/null
@@ -1,477 +0,0 @@
-
-//
-
-/**
- * Stores tal:repeat information during template execution.
- *
- * An instance of this class is created and stored into PHPTAL context on each
- * tal:repeat usage.
- *
- * repeat/item/index
- * repeat/item/number
- * ...
- * are provided by this instance.
- *
- * 'repeat' is an StdClass instance created to handle RepeatControllers,
- * 'item' is an instance of this class.
- *
- * @package phptal
- * @author Laurent Bedubourg
- */
-class PHPTAL_RepeatController implements Iterator
-{
- private $key;
- private $current;
- private $valid;
- private $validOnNext;
-
- protected $iterator;
- protected $index;
- protected $end;
- protected $length;
-
- /**
- * Construct a new RepeatController.
- *
- * @param $source array, string, iterator, iterable.
- */
- public function __construct($source)
- {
- if ( is_string($source) ) {
- $this->iterator = new ArrayIterator( str_split($source) ); // FIXME: invalid for UTF-8 encoding, use preg_match_all('/./u') trick
- } else if ( is_array($source) ) {
- $this->iterator = new ArrayIterator($source);
- } else if ( $source instanceof IteratorAggregate ) {
- $this->iterator = $source->getIterator();
- } else if ( $source instanceof Iterator ) {
- $this->iterator = $source;
- } else if ( $source instanceof SimpleXMLElement) { // has non-unique keys!
- $array = array();
- foreach ( $source as $v ) {
- $array[] = $v;
- }
- $this->iterator = new ArrayIterator($array);
- } else if ( $source instanceof Traversable || $source instanceof DOMNodeList ) {
- // PDO Statements for example implement the engine internal Traversable
- // interface. To make it fully iterable we traverse the set to populate
- // an array which will be actually used for iteration.
- $array = array();
- foreach ( $source as $k=>$v ) {
- $array[$k] = $v;
- }
- $this->iterator = new ArrayIterator($array);
- } else {
- $this->iterator = new ArrayIterator( array() );
- }
-
- // Try to find the set length
- $this->length = 0;
- if ( $this->iterator instanceof Countable ) {
- $this->length = count($this->iterator);
- } else if ( is_object($this->iterator) ) {
- // This should be removed since there is already the Countable interface in PHP5
- if ( method_exists( $this->iterator, 'size' ) ) {
- $this->length = $this->iterator->size();
- } else if ( method_exists( $this->iterator, 'length' ) ) {
- $this->length = $this->iterator->length();
- }
- }
-
- $this->groups = new PHPTAL_RepeatController_Groups();
-
- $this->rewind();
- }
-
- /**
- * Returns the current element value in the iteration
- *
- * @return Mixed The current element value
- */
- public function current()
- {
- return $this->current;
- }
-
- /**
- * Returns the current element key in the iteration
- *
- * @return String/Int The current element key
- */
- public function key()
- {
- return $this->key;
- }
-
- /**
- * Tells if the iteration is over
- *
- * @return bool True if the iteration is not finished yet
- */
- public function valid()
- {
- $valid = $this->valid || $this->validOnNext;
- $this->validOnNext = $this->valid;
-
- return $valid;
- }
-
- /**
- * Restarts the iteration process going back to the first element
- *
- */
- public function rewind()
- {
- $this->index = 0;
- $this->end = false;
-
- $this->iterator->rewind();
-
- // Prefetch the next element
- if ( $this->iterator->valid() ) {
- $this->validOnNext = true;
- $this->prefetch();
- } else {
- $this->validOnNext = false;
- }
-
- // Notify the grouping helper of the change
- $this->groups->reset();
- }
-
- /**
- * Fetches the next element in the iteration and advances the pointer
- *
- */
- public function next()
- {
- $this->index++;
-
- // Prefetch the next element
- $this->prefetch();
-
- // Notify the grouping helper of the change
- $this->groups->reset();
- }
-
- /**
- * Gets an object property
- *
- * @return $var Mixed The variable value
- */
- public function __get( $var )
- {
- switch ( $var ) {
- case 'index':
- case 'end':
- case 'length':
- return $this->$var;
- case 'number':
- return $this->index + 1;
- case 'start':
- return $this->index === 0;
- case 'even':
- return ($this->index % 2) === 0;
- case 'odd':
- return ($this->index % 2) === 1;
- case 'key':
- return $this->key();
- case 'letter':
- return strtolower( $this->int2letter($this->index+1) );
- case 'Letter':
- return strtoupper( $this->int2letter($this->index+1) );
- case 'roman':
- return strtolower( $this->int2roman($this->index+1) );
- case 'Roman':
- return strtoupper( $this->int2roman($this->index+1) );
-
- case 'first':
- // Compare the current one with the previous in the dictionary
- $res = $this->groups->first( $this->current );
- return is_bool($res) ? $res : $this->groups;
- case 'last':
- // Compare the next one with the dictionary
- $res = $this->groups->last( $this->iterator->current() );
- return is_bool($res) ? $res : $this->groups;
-
- default:
- throw new PHPTAL_Exception( "Unable to find part '$var' in repeater controller" );
- }
- }
-
- /**
- * Fetches the next element from the source data store and
- * updates the end flag if needed.
- *
- * @access protected
- */
- protected function prefetch()
- {
- $this->valid = true;
- $this->key = $this->iterator->key();
- $this->current = $this->iterator->current();
-
- $this->iterator->next();
- if ( !$this->iterator->valid() ) {
- $this->valid = false;
- $this->end = true;
- }
- }
-
- /**
- * Converts an integer number (1 based) to a sequence of letters
- *
- * @param $int Int The number to convert
- * @return String The letters equivalent as a, b, c-z ... aa, ab, ac-zz ...
- * @access protected
- */
- protected function int2letter( $int )
- {
- $lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
- $size = strlen($lookup);
-
- $letters = '';
- while ( $int > 0 ) {
- $int--;
- $letters = $lookup[$int % $size] . $letters;
- $int = floor($int / $size);
- }
- return $letters;
- }
-
- /**
- * Converts an integer number (1 based) to a roman numeral
- *
- * @param $int Int The number to convert
- * @return String The roman numeral
- * @access protected
- */
- protected function int2roman( $int )
- {
- $lookup = array(
- '1000' => 'M',
- '900' => 'CM',
- '500' => 'D',
- '400' => 'CD',
- '100' => 'C',
- '90' => 'XC',
- '50' => 'L',
- '40' => 'XL',
- '10' => 'X',
- '9' => 'IX',
- '5' => 'V',
- '4' => 'IV',
- '1' => 'I',
- );
-
- $roman = '';
- foreach ( $lookup as $max => $letters ) {
- while ( $int >= $max ) {
- $roman .= $letters;
- $int -= $max;
- }
- }
-
- return $roman;
- }
-}
-
-
-/**
- * Keeps track of variable contents when using grouping in a path (first/ and last/)
- *
- * @package phptal
- * @author Ivбn Montes
- */
-class PHPTAL_RepeatController_Groups {
-
- protected $dict = array();
- protected $cache = array();
- protected $data = null;
- protected $vars = array();
- protected $branch;
-
-
- public function __construct()
- {
- $this->dict = array();
- $this->reset();
- }
-
- /**
- * Resets the result caches. Use it to signal an iteration in the loop
- *
- */
- public function reset()
- {
- $this->cache = array();
- }
-
- /**
- * Checks if the data passed is the first one in a group
- *
- * @param $data Mixed The data to evaluate
- * @return Mixed True if the first item in the group, false if not and
- * this same object if the path is not finished
- */
- public function first( $data )
- {
- if ( !is_array($data) && !is_object($data) && !is_null($data) ) {
-
- if ( !isset($this->cache['F']) ) {
-
- $hash = md5($data);
-
- if ( !isset($this->dict['F']) || $this->dict['F'] !== $hash ) {
- $this->dict['F'] = $hash;
- $res = true;
- } else {
- $res = false;
- }
-
- $this->cache['F'] = $res;
- }
-
- return $this->cache['F'];
- }
-
- $this->data = $data;
- $this->branch = 'F';
- $this->vars = array();
- return $this;
- }
-
- /**
- * Checks if the data passed is the last one in a group
- *
- * @param $data Mixed The data to evaluate
- * @return Mixed True if the last item in the group, false if not and
- * this same object if the path is not finished
- */
- public function last( $data )
- {
- if ( !is_array($data) && !is_object($data) && !is_null($data) ) {
-
- if ( !isset($this->cache['L']) ) {
-
- $hash = md5($data);
-
- if (empty($this->dict['L'])) {
- $this->dict['L'] = $hash;
- $res = false;
- } else if ( $this->dict['L'] !== $hash ) {
- $this->dict['L'] = $hash;
- $res = true;
- } else {
- $res = false;
- }
-
- $this->cache['L'] = $res;
- }
-
- return $this->cache['L'];
- }
-
- $this->data = $data;
- $this->branch = 'L';
- $this->vars = array();
- return $this;
- }
-
- /**
- * Handles variable accesses for the tal path resolver
- *
- * @param $var String The variable name to check
- * @return Mixed An object/array if the path is not over or a boolean
- *
- * @todo replace the phptal_path() with custom code
- */
- public function __get( $var )
- {
- // When the iterator item is empty we just let the tal
- // expression consume by continuously returning this
- // same object which should evaluate to true for 'last'
- if ( is_null($this->data) ) {
- return $this;
- }
-
- // Find the requested variable
- $value = @phptal_path( $this->data, $var, true );
-
- // Check if it's an object or an array
- if ( is_array($value) || is_object($value) ) {
- // Move the context to the requested variable and return
- $this->data = $value;
- $this->addVarName( $var );
- return $this;
- }
-
- // get a hash of the variable contents
- $hash = md5( $value );
-
- // compute a path for the variable to use as dictionary key
- $path = $this->branch . $this->getVarPath() . $var;
-
- // If we don't know about this var store in the dictionary
- if ( !isset($this->cache[$path]) ) {
-
- if ( !isset($this->dict[$path]) ) {
- $this->dict[$path] = $hash;
- $res = $this->branch === 'F';
- } else {
- // Check if the value has changed
- if ( $this->dict[$path] !== $hash ) {
- $this->dict[$path] = $hash;
- $res = true;
- } else {
- $res = false;
- }
- }
-
- $this->cache[$path] = $res;
- }
-
- return $this->cache[$path];
-
- }
-
- /**
- * Adds a variable name to the current path of variables
- *
- * @param $varname String The variable name to store as a path part
- * @access protected
- */
- protected function addVarName( $varname )
- {
- $this->vars[] = $varname;
- }
-
- /**
- * Returns the current variable path separated by a slash
- *
- * @return String The current variable path
- * @access protected
- */
- protected function getVarPath()
- {
- return implode('/', $this->vars) . '/';
- }
-}
diff --git a/PHPTAL/Source.php b/PHPTAL/Source.php
deleted file mode 100644
index dc5f070..0000000
--- a/PHPTAL/Source.php
+++ /dev/null
@@ -1,16 +0,0 @@
-
diff --git a/PHPTAL/SourceResolver.php b/PHPTAL/SourceResolver.php
deleted file mode 100644
index 065a8f1..0000000
--- a/PHPTAL/SourceResolver.php
+++ /dev/null
@@ -1,16 +0,0 @@
-
diff --git a/PHPTAL/StringSource.php b/PHPTAL/StringSource.php
deleted file mode 100644
index f62546d..0000000
--- a/PHPTAL/StringSource.php
+++ /dev/null
@@ -1,34 +0,0 @@
-_data = $data;
- $this->_realpath = $realpath;
- }
-
- public function getLastModifiedTime()
- {
- if (file_exists($this->_realpath))
- return @filemtime($this->_realpath);
- return 0;
- }
-
- public function getData()
- {
- return $this->_data;
- }
-
- public function getRealPath()
- {
- return $this->_realpath;
- }
-}
-
-?>
diff --git a/PHPTAL/Tales.php b/PHPTAL/Tales.php
deleted file mode 100644
index c9a203c..0000000
--- a/PHPTAL/Tales.php
+++ /dev/null
@@ -1,7 +0,0 @@
-
diff --git a/PHPTAL/TalesRegistry.php b/PHPTAL/TalesRegistry.php
deleted file mode 100644
index 7973952..0000000
--- a/PHPTAL/TalesRegistry.php
+++ /dev/null
@@ -1,109 +0,0 @@
-
-//
-
-require_once PHPTAL_DIR.'PHPTAL/Tales.php';
-
-/**
- * Global registry of TALES expression modifiers
- *
- */
-class PHPTAL_TalesRegistry {
-
- static $instance;
-
- static public function initialize() {
- self::$instance = new PHPTAL_TalesRegistry();
- }
-
- /**
- * Enter description here...
- *
- * @return PHPTAL_TalesRegistry
- */
- static public function getInstance() {
- if(!(self::$instance instanceof PHPTAL_TalesRegistry)) {
- self::initialize();
- }
-
- return self::$instance;
- }
-
- protected function __construct() {
-
- }
-
- /**
- *
- * Expects an either a function name or an array of class and method as
- * callback.
- *
- * @param unknown_type $prefix
- * @param unknown_type $callback
- */
- public function registerPrefix($prefix, $callback) {
- if($this->isRegistered($prefix)) {
- throw new PHPTAL_Exception(sprintf('Expression modifier "%s" is already registered.',$prefix));
- }
-
- // Check if valid callback
-
- if(is_array($callback)) {
-
- $class = new ReflectionClass($callback[0]);
-
- if(!$class->isSubclassOf('PHPTAL_Tales')) {
- throw new PHPTAL_Exception('The class you want to register does not implement "PHPTAL_Tales".');
- }
-
- $method = new ReflectionMethod($callback[0], $callback[1]);
-
- if(!$method->isStatic()) {
- throw new PHPTAL_Exception('The method you want to register is not static.');
- }
-
- // maybe we want to check the parameters the method takes
-
- } else {
- if(!function_exists($callback)) {
- throw new PHPTAL_Exception('The function you are trying to register does not exist.');
- }
- }
-
-
- $this->_callbacks[$prefix] = $callback;
- }
-
- public function isRegistered($prefix) {
- return (array_key_exists($prefix, $this->_callbacks));
- }
-
- public function getCallback($prefix) {
- if(!$this->isRegistered($prefix)) {
- throw new PHPTAL_Exception(sprintf('Expression modifier "%s" is not registered.', $prefix));
- }
- return $this->_callbacks[$prefix];
- }
-
- private $_callbacks = array();
-}
-
-?>
diff --git a/PHPTAL/TranslationService.php b/PHPTAL/TranslationService.php
deleted file mode 100644
index 8fd63a8..0000000
--- a/PHPTAL/TranslationService.php
+++ /dev/null
@@ -1,41 +0,0 @@
-
diff --git a/PHPTAL/Trigger.php b/PHPTAL/Trigger.php
deleted file mode 100644
index 75a5bc9..0000000
--- a/PHPTAL/Trigger.php
+++ /dev/null
@@ -1,36 +0,0 @@
-
-//
-
-/**
- * @package phptal
- */
-interface PHPTAL_Trigger
-{
- const SKIPTAG = 1;
- const PROCEED = 2;
-
- public function start($id, $tpl);
-
- public function end($id, $tpl);
-}
-
-?>
diff --git a/core/adapter.php b/core/adapter.php
index 9200f43..39af4c2 100644
--- a/core/adapter.php
+++ b/core/adapter.php
@@ -11,7 +11,7 @@ class Adapter
$this->adaptee = $adaptee;
}
- public function get ($name)
+ public function get($name)
{
if (is_array ($this->adaptee)) {
return $this->adaptee [$name];
@@ -20,5 +20,3 @@ class Adapter
}
}
}
-
-?>
\ No newline at end of file
diff --git a/core/config.php b/core/config.php
index a88e625..3bbc19a 100644
--- a/core/config.php
+++ b/core/config.php
@@ -1,7 +1,7 @@
file['title']) ? $this->file['title'] : $this->getName();
}
}
-
-?>
diff --git a/core/filesystem.php b/core/filesystem.php
deleted file mode 100644
index b28f17a..0000000
--- a/core/filesystem.php
+++ /dev/null
@@ -1,583 +0,0 @@
-visible = $visible;
- }
-
- public function setHiddenFiles(array $hidden)
- {
- $this->hidden = array_merge($this->hidden, $hidden);
- }
-
- /**
- *
- */
- public function makeDirectory($name)
- {
- if (file_exists($name) === false) {
- mkdir($name);
- }
- }
-
- /**
- *
- */
- public function makeFile($name)
- {
- if (file_exists($name) === false) {
- file_put_contents($name, '');
- }
- }
-
- /**
- *
- */
- public function deleteDirectory($name)
- {
- rmdir($name);
- }
-
- /**
- *
- */
- public function deleteDirectoryRecursive($name)
- {
- if ($handle = opendir($name)) {
- while (false !== ($file = readdir($handle))) {
- if ($file != "." && $file != "..") {
- $sf = $name . DIRECTORY_SEPARATOR . $file;
- if (is_dir($sf) && !is_link($sf)) {
- self::deleteDirectoryRecursive($sf);
- } else {
- unlink($sf);
- }
- }
- }
- closedir($handle);
- @rmdir($name);
- }
- }
-
- /**
- *
- */
- public function deleteFile($name)
- {
- if (file_exists($name)) {
- unlink($name);
- }
- }
-
- // При перемещении или все файлы если есть совпадения переписываются
- /**
- *
- */
- public function renameFile($source, $destination)
- {
- rename($source, $destination);
- }
-
- /**
- *
- */
- public function copyFile($source, $destination)
- {
- copy($source, $destination);
- }
-
- /**
- *
- */
- public function copyDirectory($source, $destination)
- {
- if (is_dir($source)) {
- if (! file_exists($destination)) mkdir($destination);
- $handle = opendir($source);
- while (false !== ($file = readdir($handle))) {
- $entry = $source . DIRECTORY_SEPARATOR . $file;
- if (is_dir($entry)) {
- self::copyDirectory($entry, $destination . DIRECTORY_SEPARATOR . $file);
- } else {
- copy($entry, $destination . DIRECTORY_SEPARATOR . $file);
- }
- }
- }
- }
-
- /**
- *
- */
- public function moveUploadedFile($source, $destination)
- {
- move_uploaded_file($source, $destination);
- }
-
- /**
- *
- */
- public function isVisible($file)
- {
- if (in_array(basename($file), $this->hidden) === true) {
- return false;
- }
- return ($this->isDir($file) || $this->visible == null) || in_array(pathinfo($file, PATHINFO_EXTENSION), $this->visible);
- }
-
- /**
- *
- */
- public function directoryFiles($name)
- {
- $result = array();
- $files = scandir($name);
- foreach ($files as $file) {
- $fullname = $name . DIRECTORY_SEPARATOR . $file;
- if ($this->isVisible($fullname)) {
- $result [$file] = new FileRecord(array(), $fullname);
- }
- }
- return $result;
- }
-
- /**
- *
- */
- public function readFile($name)
- {
- return file_get_contents($name);
- }
-
- /**
- *
- */
- public function writeFile($name, $content)
- {
- file_put_contents($name, $content);
- }
-
- /**
- *
- */
- public function directoryFilesRecursive($name)
- {
- }
-
- function isDir($name)
- {
- return is_dir($name);
- }
-}
-
-// То что хранится в базе данных
-class EFileSystem implements IFileSystem, IFileControl
-{
-
- protected $basepath;
- protected $db;
-
- public function __construct($basepath, $db, $fs)
- {
- $this->basepath = $basepath;
- $this->db = $db;
- $this->fs = $fs;
- }
-
- /*function createExtendRecord($index)
- {
- static $fileSQL = "INSERT INTO file (id_record) VALUES (?)";
- $query = $this->db->prepareStatement($fileSQL);
- $query->setString(1, $index);
- $query->executeQuery();
- }*/
-
- private function createRecord($name, $type, $path)
- {
- static $recordSQL = "INSERT INTO files (filename, idfile, lastrevdate, filepath, filetype) VALUES (?, ?, ?, ?, ?)";
- $last = $this->db->getIdGenerator();
- $index = $last->getId('files_idfile_seq');
-
- $query = $this->db->prepareStatement($recordSQL);
- $query->setString(1, $name);
- $query->setInt(2, $index);
- $query->setInt(3, 0);
- $query->setString(4, $path);
- $query->setString(5, $type);
- $query->executeQuery();
- /*if ($type == 0) {
- $this->createExtendRecord($index);
- }*/
-
- return $index;
- }
-
- function setVisibleFiles(array $visible)
- {
- $this->fs->setVisibleFiles($visible);
- }
-
- function setHiddenFiles(array $hidden)
- {
- $this->fs->setHiddenFiles($hidden);
- }
-
- public function getFullPath($name)
- {
- return Path::join($this->basepath, $name);
- }
-
- private function getRecordId($name, $path)
- {
- static $recordSQL = "SELECT idfile FROM files WHERE filename = ? AND filepath = ?";
-
- $query = $this->db->prepareStatement($recordSQL);
- $query->setString(1, $name);
- $query->setString(2, $path);
- $result = $query->executeQuery();
- if ($result->next()) {
- $index = $result->getInt('idfile');
- return $index;
- }
- return false; // Может лучше кидать исключение ??
- }
-
- function getIdFromPath($name)
- {
- return $this->getRecordId(basename($name), self::getPathName($name));
- }
-
- // Создание новой директории
- public function makeDirectory($name)
- {
- $path = new Path($name);
- $fullpath = $this->basepath;
- $temp_path = '';
- foreach ($path->getParts() as $subpath)
- {
- $index = $this->getRecordId($subpath, $temp_path);
- if ($index === false) {
- $index = $this->createRecord($subpath, 1, $temp_path);
- }
- $temp_path = Path::join($temp_path, $subpath);
- }
-
- $this->fs->makeDirectory($this->getFullPath($name));
- }
-
- public function isDir($name)
- {
- return $this->fs->isDir($this->getFullPath($name));
- }
-
- // Переименование файла или директории все изменения должны записываться в базу чтобы можно было сделать отмену !!!
- public function renameFile($source, $destination)
- {
- // При перемещении файлы могут совпадать
- $stmt = $this->db->prepareStatement('UPDATE files SET filepath = ?, filename = ? WHERE filepath = ? AND filename = ?');
- $stmt->setString(1, self::getPathName($destination));
- $stmt->setString(2, basename($destination));
- $stmt->setString(3, self::getPathName($source));
- $stmt->setString(4, basename($source));
- $stmt->executeQuery();
-
- if ($this->isDir($source)) {
- $length = strlen($from) + 1;
- $stmt = $this->db->prepareStatement("UPDATE file
- SET filepath = '?' || substr(filepath, ?) WHERE filepath LIKE (?) OR filepath LIKE (? || '/%')");
- $stmt->setString(1, $destination);
- $stmt->setInt(2, $length);
- $stmt->setString(3, $source);
- $stmt->setString(4, $source);
- }
-
- $this->fs->renameFile($this->getFullPath($source), $this->getFullPath($destination));
- }
-
- // Копирование файла или директории
- public function copyFile($source, $destination)
- {
- // При копировании файлы могут совпадать
- $stmt = $this->db->prepareStatement('INSERT INTO files (filepath, filename, lastrevdate) VALUES (?, ?, ?)');
- $stmt->setString(1, self::getPathName($destination));
- $stmt->setString(2, basename($destination));
- $stmt->setString(3, time());
- $stmt->executeQuery();
-
- if ($this->isDir($source)) {
- $stmt = $this->db->prepareStatement("INSERT INTO files (filepath, filename, lastrevdate)
- SELECT '?' || substr(filepath, ?) AS filepath, filename, lastrevdate WHERE WHERE filepath LIKE (?) OR filepath LIKE (? || '/%')");
-
- $stmt->setString(1, $destination);
- $stmt->setInt(2, $length);
- $stmt->setString(3, $source);
- $stmt->setString(4, $source);
- }
-
- $this->fs->copyFile($this->getFullPath($source), $this->getFullPath($destination));
- }
-
- private function getPathName($name)
- {
- $path = dirname($name);
- return ($path == '.') ? '' : $path;
- }
-
- public function makeFile($name)
- {
- $base = self::getPathName($name);
- $this->makeDirectory($base);
-
- $filename = basename($name);
- $index = $this->getRecordId($filename, $base);
-
- if ($index === false) {
- $index = $this->createRecord($filename, 0, $base);
- }
- $this->fs->makeFile($this->getFullPath($name));
- }
-
- public function readFile($name)
- {
- return $this->fs->readFile($this->getFullPath($name));
- }
-
- public function readFileVersion($name, $revision = false)
- {
- if ($revision === false) {
- return $this->readFile($name);
- } else {
- $id_file = $this->getIdFromPath($name);
- $query = $this->db->prepareStatement("SELECT * FROM history WHERE revision = ? AND idfile = ?");
- $query->setInt(1, $revision);
- $query->setInt(2, $id_file);
- $file = $query->executeQuery();
- if ($file->next()) {
- return gzuncompress($file->getBlob('content'));
- }
- }
- return null;
- }
-
- public function writeFile($name, $content)
- {
- $this->makeFile($name);
- $this->fs->writeFile($this->getFullPath($name), $content);
- }
-
- public function getLastRevision($name)
- {
- $id_file = $this->getIdFromPath($name);
- $stmt = $this->db->prepareStatement("SELECT * FROM history WHERE revision IN (SELECT MAX(revision) AS lastrev FROM history WHERE idfile = ?)");
- $stmt->setInt(1, $id_file);
- $rev = $stmt->executeQuery();
- if ($rev->next()) {
- return $rev;
- }
- return false;
- }
-
- /**
- *
- */
- public function commitFile($name, $owner, $message)
- {
- $id_file = $this->getIdFromPath($name);
- $content = $this->readFile($name);
-
- $stmt = $this->db->prepareStatement("SELECT MAX(revision) AS lastrev FROM history WHERE idfile = ?");
- $stmt->setInt(1, $id_file);
- $rev = $stmt->executeQuery();
- $revision = ($rev->next()) ? $rev->getInt('lastrev') + 1 : 1;
-
- $query = $this->db->prepareStatement("INSERT INTO history (content, owner, revsummary, revdate, revision, idfile) VALUES (?, ?, ?, ?, ?, ?)");
- $query->setBlob(1, gzcompress($content));
- $query->setString(2, $owner);
- $query->setString(3, $message);
- $query->setInt(4, time());
- $query->setInt(5, $revision);
- $query->setInt(6, $id_file);
- $query->executeQuery();
- }
-
- /**
- *
- */
- public function getFileDifference($name, $revision1, $revision2 = false)
- {
- $first = $this->readFileVersion($name, $revision1);
- $second = $this->readFileVersion($name, $revision2);
- }
-
- /**
- *
- */
- public function getFileLog($name)
- {
- $id_file = $this->getIdFromPath($name);
- $query = $this->db->prepareStatement("SELECT revision,revsummary,owner,revdate FROM history WHERE idfile = ? ORDER BY revision");
- $query->setInt(1, $id_file);
- $list = $query->executeQuery();
- return iterator_to_array($list->getIterator());
- }
-
- public function directoryFiles($name)
- {
- $result = $this->fs->directoryFiles($this->getFullPath($name));
-
- /* Список файлов из базы данных */
- $query = $this->db->prepareStatement("SELECT * FROM files WHERE filepath = ?");
- $query->setString(1, $name);
- $list = $query->executeQuery();
-
- foreach ($list as $file) {
- $fullpath = $this->getFullPath($name . DIRECTORY_SEPARATOR . $file['filename']);
- if ($this->fs->isVisible($fullpath)) {
- $file['state'] =
- ((isset($result[$file['filename']])) ?
- (($file['lastrevdate'] > $file['change']) ? 'exclamation' : 'unchanged')
- : 'expected');
- $record = new FileRecord($file, $fullpath);
- $result [$file['filename']] = $record;
- }
- }
- return $result;
- }
-
- public function getFileInfo($name)
- {
- $index = $this->getIdFromPath($name);
- $fullpath = $this->basepath . DIRECTORY_SEPARATOR . $name;
- if ($index !== false) {
- $query = $this->db->prepareStatement("SELECT * FROM files AS r LEFT JOIN filemeta AS f ON r.idfile = f.id_record WHERE r.idfile = ?");
- $query->setInt(1, $index);
- $list = $query->executeQuery();
- $list->next();
- $file = $list->getRow();
- $file['state'] = (file_exists($fullpath) ? 'unchanged' : 'expected');
- $result = new FileRecord($file, $fullpath);
- } else {
- $result = new FileRecord(array(), $fullpath);
- }
- return $result;
- }
-
- public function setFileInfo($name, Collection $list)
- {
- $index = $this->getIdFromPath($name);
- if ($index !== false) {
- $stmt = $this->db->prepareStatement("UPDATE files SET title = ? WHERE idfile = ?");
- $stmt->setString(1, $list->get('title'));
- $stmt->setInt(2, $index);
- $stmt->executeQuery();
- /*if (some($list, array('keywords', 'author', 'description'))) {
- $hasfile = $this->db->executeQuery("SELECT * FROM file WHERE id_record = $index");
- if(!$hasfile->next()) {
- static $fileSQL = "INSERT INTO file (id_record) VALUES (?)";
- $query = $this->db->prepareStatement($fileSQL);
- $query->setString(1, $index);
- $query->executeQuery();
- }
- $query = $this->db->prepareStatement("UPDATE file SET keywords = ?, author = ?, description = ? WHERE id_record = ?");
- $query->setString(1, $list->get('keywords'));
- $query->setString(2, $list->get('author'));
- $query->setString(3, $list->get('description'));
- $query->setInt(4, $index);
- $query->executeQuery();
- }*/
- }
- }
-
- /**
- * Удаляем директорию если она не пустая
- */
- function deleteDirectory($name)
- {
- $index = $this->getIdFromPath($name);
-
- $query = $this->db->prepareStatement("SELECT COUNT(*) AS col FROM files WHERE filepath = (?) OR filepath LIKE(? || '/%')");
- $query->setString(1, $name);
- $query->setString(2, $name);
- $result = $query->executeQuery();
- $result->next();
-
- if ($index && $result->getInt('col') == 0) {
- $query = $this->db->prepareStatement("DELETE FROM files WHERE idfile = ?");
- $query->setInt(1, $index);
- $query->executeQuery();
- }
- $this->fs->deleteDirectory($this->getFullPath($name));
- }
-
- function deleteFile($name)
- {
- $index = $this->getIdFromPath($name);
- if ($index) {
-
- $query = $this->db->prepareStatement("DELETE FROM history WHERE idfile = ?;
- DELETE FROM filemeta WHERE id_record = ?;DELETE FROM files WHERE idfile = ?");
- $query->setInt(1, $index);
- $query->setInt(2, $index);
- $query->setInt(3, $index);
- $query->executeQuery();
- }
- $this->fs->deleteFile($this->getFullPath($name));
- }
-
- function moveUploadedFile($source, $destination)
- {
- $this->fs->moveUploadedFile($source, $this->getFullPath($destination));
- $this->makeFile($destination);
- }
-
- function directoryFilesRecursive($name)
- {
- $files = $this->fs->directoryFilesRecursive($this->getFullPath($name));
-
- $query = $this->db->prepareStatement("DELETE FROM files WHERE filepath = (?) OR filepath LIKE (? || '/%')");
- $query->setString(1, $name);
- $query->setString(2, $name);
- $query->executeQuery();
- }
-}
diff --git a/core/form.php b/core/form.php
deleted file mode 100644
index af3dfac..0000000
--- a/core/form.php
+++ /dev/null
@@ -1,335 +0,0 @@
-render () -> html,
- * $form->adjust ($scheme);
- * $form->input ($name, $type, $label, );
- * $form->set($name, $value);
- * $form->get($name); -> value
- * $form->parse ($request),
- * $form->validate () -> boolean,
- * $form->values () -> pair[key] = value
- */
-
-/**
- * Элемент формы
- * @package core
- */
-class TField {
- protected $_value; // Форматированное значение поля
-
- var $label; // Метка поля
- var $rule = array ();// Правила для проверки поля
- var $value; // Форматированное Значение поля
-// var $default; // Значение по умолчанию
- var $error = false; // в XRule Правила для проверки значений
- var $error_msg = "Поле не может быть пустым";
- var $type; // Каждому типу элемента соответствует макрос TAL
-
- public function __construct ($input) {
-// $this->deafult = null;
- $this->require = false;
- // Инициализация свойст обьетка
- foreach ($input as $key => $value) {
- $this->$key = $value;
- }
- }
-
- public function __toString () {
- return $this->value;
- }
-
- public function isValid ($name) {
- if ($this->require == true && empty($this->value)) {
- $this->error = true;
- return false;
- }
- $this->setValue ($this->value);
- return true;
- }
-
- // Добавить методы getString, setString ??
-
- function setValue ($value) {
- $this->_value = $value;
- $this->value = $value;
- }
-
- function getValue () {
- return $this->_value;
- }
-}
-
-/**
- * Поле ввода Input
- * @package core
- */
-class TInput extends TField {
- public function __construct ($input) {
- parent::__construct ($input);
- $this->setValue ("");
- }
-}
-
-// checkbox
-class TCheckbox extends TField {
- public $checked = false;
- public function __construct ($input) {
- parent::__construct ($input);
- $this->setValue (1);
- }
-
- function setValue ($value) {
- $this->_value = intval ($value);
- $this->value = 1;
- if ($this->_value == 1) $this->checked = true; else $this->checked = false;
- }
-}
-
-/**
- * Выбор из одного элемента
- */
-class TSelect1 extends TField {
- var $options = array ();
-
- public function __construct ($input) {
- parent::__construct ($input);
- $this->setValue (0);
- }
-
- function setValue ($value) {
- $this->_value = $value;
- $this->value = $value;
- foreach ($this->options as $key => $o) {
- $this->options[$key]['selected'] = ($this->options[$key]['value'] == $this->_value);
- }
- }
-}
-
-class TSelectGroup extends TField {
- var $groups = array ();
-
- public function __construct ($input) {
- parent::__construct ($input);
- $this->setValue (0);
- }
-
- function setValue ($value) {
- $this->_value = $value;
- $this->value = $value;
- foreach ($this->groups as $gkey => $o) {
- foreach ($this->groups[$gkey]['options'] as $key => $v) {
- $this->groups[$gkey]['options'][$key]['selected'] = ($this->groups[$gkey]['options'][$key]['value'] == $this->_value);
- }
- }
- }
-}
-
-/**
- * Поле с датой
- * @package core
- */
-class TDate extends TField {
- var $error_msg = "Неверный формат даты";
- var $separator = ".";
-
- public function __construct ($input) {
- parent::__construct ($input);
- $this->setValue (time ());
- }
-
- function isValid ($name) {
- $value = $this->value;
- if ($tmp = explode(".", $value, 3)) {
- if ($tmp[1] && $tmp[0] && $tmp[2]) {
- if (checkdate ($tmp[1], $tmp[0], $tmp[2])) {
- $this->setValue (mktime (0, 0, 0, $tmp[1], $tmp[0], $tmp[2]));
- return true;
- }
- }
- }
- $this->error = true;
- return false;
- }
-
- function setValue ($value) {
- $this->_value = $value;
- $this->value = date ("d.m.Y", $value);
- }
-}
-
-class TTime extends TField {
- var $error_msg = "Неверный формат времени";
-
- public function __construct ($input) {
- parent::__construct ($input);
- $this->setValue (mktime(0, 0, 0, 11, 30, 1999));
- }
-
- function isValid ($name) {
- $value = $this->value;
- if ($tmp = explode(":", $value, 2)) {
- if ($this->checktime ($tmp[0], $tmp[1])) {
- $this->setValue (mktime ($tmp[0], $tmp[1], 0, 0, 0, 0));
- return true;
- }
- }
- $this->error = true;
- return false;
- }
-
- function checktime($hour, $minute) {
- if ($hour > -1 && $hour < 24 && $minute > -1 && $minute < 60) {
- return true;
- }
- }
-
- function setValue ($value) {
- $this->_value = $value;
- $this->value = date ("H:i", $value);
- }
-}
-
-
-/* *
- * Текстовое поле
- * @package core
- */
-class TTextArea extends TField {
- public function __construct ($input) {
- parent::__construct ($input);
- $this->setValue ("");
- }
-}
-
-/**
- * Поле для ввода пароля
- * @package core
- */
-class TSecret extends TField {
- public function __construct ($input) {
- parent::__construct ($input);
- $this->setValue ("");
- }
-}
-
-class TUpload extends TField {
- public $types = array ();
- public function __construct ($input) {
- parent::__construct ($input);
- $this->setValue ("");
- }
-
- public function setValue ($value) {
- $this->_value = basename ($value);
- $this->value = $value;
- }
-}
-
-/**
- * Форма для ввода
- * @package core
- */
-class TForm {
- var $field = array ();
- var $action = "";
- var $method = 'post';
- var $request;
- var $replace;
-
- public function __construct ($request) {
- $this->uid = get_form_uid ();
- $this->constructor = array (
- 'input' => 'TInput',
- 'checkbox' => 'TCheckbox',
- 'date' => 'TDate',
- 'time' => 'TTime',
- 'textarea' => 'TTextArea',
- 'select' => 'TSelect',
- 'select1' => 'TSelect1',
- 'selgroup' => 'TSelectGroup',
- 'secret' => 'TSecret',
- 'upload' => 'TUpload'
- );
- $this->request = $request;
- }
-
- function get ($name) {
- return $this->field [$name]->getValue ();
- }
-
- function addFieldObject ($name, $el) {
- $this->field [$name] = $el;
- }
-
- /**
- * Метод должен проверять значения полей формы полсле заполнения
- * Проверка правильности заполнения формы и установка значений
- */
- function isValid () {
- $haveErrors = false;
- foreach ($this->field as $name => $el) { // ссылка
- if ($this->field [$name] instanceof TUpload) {
-// print_r ($_POST);
- $filename = $this->request->getRawData ('files', $name);
- if ((bool) $filename['name']) {
- $this->field [$name]->value = $filename['name'];
- } else {
- $this->field [$name]->value = $this->request->getRawData ($this->method, $name."_file");
- }
- } else {
- $this->field [$name]->value = $this->request->getRawData ($this->method, $name);
- }
- if (!$this->field [$name]->isValid($name)) {
- $haveErrors = true;
- }
- }
- return !$haveErrors;
- }
-
- /**
- * Добавляет одно поле ввода на форму
- */
- public function addField ($init) {
- assert ($init['type']);
- assert ($init['name']);
- $constructor = $this->constructor[$init['type']];
- $el = new $constructor ($init);
- $el->type = $init['type'];
-
- $this->addFieldObject ($init['name'], $el);
- return $el;
- }
-
- /**
- * Добавляет спсок полей для формы
- * @param array $list
- */
- public function addFieldList ($list) {
- foreach ($list as $init) {
- $this->addField ($init);
- }
- }
-
- /**
- * Заполняет форму данными из коллекции
- * Для обьектов и массивов можно использовать Adapter pattern
- * @param object $data
- * @param array $schema Связь между элементами формы и свойствами обьекта
- */
- public function fill ($data) {
- foreach ($this->field as $name => $el) {
- $this->field [$name]->setValue ($data->get ($name));
- }
- }
-}
-
-?>
\ No newline at end of file
diff --git a/core/form/form.php b/core/form/form.php
index e32b431..bd0ddd6 100644
--- a/core/form/form.php
+++ b/core/form/form.php
@@ -176,5 +176,3 @@ class TForm
$this->field[$name]->setValue($value);
}
}
-
-?>
\ No newline at end of file
diff --git a/core/formats/helix.php b/core/formats/helix.php
index 05da09f..ff52c53 100644
--- a/core/formats/helix.php
+++ b/core/formats/helix.php
@@ -83,4 +83,3 @@ class HFile {
}
}
-?>
diff --git a/core/geometry/point.php b/core/geometry/point.php
index b932196..61254e6 100644
--- a/core/geometry/point.php
+++ b/core/geometry/point.php
@@ -10,4 +10,3 @@ class Point
}
}
-?>
\ No newline at end of file
diff --git a/core/geometry/rectangle.php b/core/geometry/rectangle.php
index 36bd13a..4c7c0e0 100644
--- a/core/geometry/rectangle.php
+++ b/core/geometry/rectangle.php
@@ -49,5 +49,3 @@ class Rectangle
return new Point((($base->left + $base->right) - ($this->left + $this->right)) / 2, $base->bottom - $this->height);
}
}
-
-?>
\ No newline at end of file
diff --git a/core/mapper/factory.php b/core/mapper/factory.php
index 4c24c0b..d3dbe87 100644
--- a/core/mapper/factory.php
+++ b/core/mapper/factory.php
@@ -26,5 +26,3 @@ class ModelFactory
return $model;
}
}
-
-?>
\ No newline at end of file
diff --git a/core/query/meta.php b/core/query/meta.php
index 0086fac..c1320a7 100644
--- a/core/query/meta.php
+++ b/core/query/meta.php
@@ -7,4 +7,3 @@ class Meta
{
}
-?>
\ No newline at end of file
diff --git a/core/query/query.php b/core/query/query.php
index 717859f..3e4b395 100644
--- a/core/query/query.php
+++ b/core/query/query.php
@@ -203,4 +203,3 @@ class Query
}
}
-?>
\ No newline at end of file
diff --git a/core/query/sql.txt b/core/query/sql.txt
deleted file mode 100644
index 9866102..0000000
--- a/core/query/sql.txt
+++ /dev/null
@@ -1,865 +0,0 @@
-// Version: 0.8
-// ANTLR Version: 2.7.2
-// Date: 2003.08.25
-//
-// Description: This is a MS SQL Server 2000 SELECT statement grammar.
-//
-// =======================================================================================
-// Author: Tomasz Jastrzebski
-// Contact: tdjastrzebski@yahoo.com
-// Working parser/lexer generated based on this grammar will available for some time at:
-// http://jastrzebski.europe.webmatrixhosting.net/mssqlparser.aspx
-
-options {
- language = "CSharp";
-}
-
-// PARSER ********************************************************************************
-
-class SqlParser extends Parser;
-options {
- k = 2;
-}
-
-// starting rule
-statement
- : selectStatement (SEMICOLON)? EOF
- ;
-
-selectStatement
- :
- queryExpression
- (computeClause)?
- (forClause)?
- (optionClause)?
- ;
-
-queryExpression
- : subQueryExpression (unionOperator subQueryExpression)* (orderByClause)?
- ;
-
-subQueryExpression
- :
- querySpecification
- | LPAREN queryExpression RPAREN
- ;
-
-querySpecification
- :
- selectClause
- (fromClause)?
- (whereClause)?
- (groupByClause (havingClause)? )?
- ;
-
-selectClause
- : SELECT (ALL | DISTINCT)? (TOP Integer (PERCENT)? (WITH TIES)? )? selectList
- ;
-
-whereClause
- : WHERE searchCondition
- ;
-
-orderByClause
- : ORDER BY expression (ASC | DESC)? (COMMA expression (ASC | DESC)? )*
- ;
-
-groupByClause
- : GROUP BY (ALL)? expression (COMMA expression)* (WITH (CUBE | ROLLUP) )?
- ;
-
-havingClause
- : HAVING searchCondition
- ;
-
-optionClause
- : OPTION LPAREN queryHint (COMMA queryHint)* RPAREN
- ;
-
-queryHint
- :
- (HASH | ORDER) GROUP
- | (CONCAT | HASH | MERGE) UNION
- | (LOOP | MERGE | HASH) JOIN
- | FAST Integer
- | FORCE ORDER
- | MAXDOP Integer
- | ROBUST PLAN
- | KEEP PLAN
- | KEEPFIXED PLAN
- | EXPAND VIEWS
- ;
-
-forClause
- :
- FOR (
- BROWSE
- | XML (RAW | AUTO | EXPLICIT) (COMMA XMLDATA)? (COMMA ELEMENTS)? (COMMA BINARY BASE64)
- )
- ;
-
-computeClause
- :
- COMPUTE
- // only allowed functions are: AVG, COUNT, MAX, MIN, STDEV, STDEVP, VAR, VARP, SUM
- identifier LPAREN expression RPAREN
- (COMMA identifier LPAREN expression RPAREN)*
- (BY expression (COMMA expression)* )?
- ;
-
-searchCondition
- : subSearchCondition ( (AND | OR) subSearchCondition )*
- ;
-
-subSearchCondition
- :
- (NOT)? (
- (LPAREN searchCondition RPAREN) => LPAREN searchCondition RPAREN
- | predicate
- )
- ;
-
-predicate
- :
- (
- expression (
- // expression comparisonOperator expression
- comparisonOperator (
- expression
- | (ALL | SOME | ANY) LPAREN selectStatement RPAREN
- )
- | IS (NOT)? NULL
- | (NOT)? (
- LIKE expression (ESCAPE expression)? // only single char
- | BETWEEN expression AND expression
- | IN LPAREN (
- (selectStatement) => selectStatement
- | expression (COMMA expression)*
- ) RPAREN
- )
- | CONTAINS LPAREN (dbObject | STAR) COMMA (stringLiteral | Variable) RPAREN
- | FREETEXT LPAREN (dbObject | STAR) COMMA (stringLiteral | Variable) RPAREN
- )
- | EXISTS LPAREN selectStatement RPAREN
- )
- ;
-
-selectList
- : selectItem ( COMMA selectItem )*
- ;
-
-selectItem
- :
- STAR // "*, *" is a valid select list
- | (
- // starts with: "alias = column_name"
- (alias2) => (
- (alias2 dbObject COMMA) => alias2 column
- | (alias2 dbObject (binaryOperator | LPAREN)) => alias2 expression
- | (alias2 column) => alias2 column
- | (alias2 expression) => alias2 expression
- )
-
- // all table columns: "table.*"
- | (tableColumns) => tableColumns
-
- // some shortcuts:
- | (dbObject (alias1)? COMMA) => column (alias1)?
- | (dbObject (binaryOperator | LPAREN) ) => expression (alias1)?
-
- // less obvious cases:
- | (column) => column (alias1)?
- | (expression) => expression (alias1)?
- )
- ;
-
-fromClause
- : FROM tableSource (COMMA tableSource)*
- ;
-
-tableSource
- : subTableSource (joinedTable)*
- ;
-
-subTableSource
- :
- (
- LPAREN (
- (joinedTables) => joinedTables RPAREN
- | (queryExpression) => queryExpression RPAREN alias1 // "derived table", mandatory alias
- )
- | (function) => function (alias1)?
- | dbObject (alias1)? ( (WITH)? LPAREN tableHint (COMMA tableHint)* RPAREN )?
- | Variable (alias1)?
- | (CONTAINSTABLE | FREETEXTTABLE) LPAREN
- dbObject COMMA (dbObject | STAR) COMMA (stringLiteral | Variable) (COMMA Integer)?
- RPAREN (alias1)?
- | COLON COLON function (alias1)? // built-in function
- )
- ;
-
-joinedTable
- :
- CROSS JOIN subTableSource
- // "joinHint JOIN" is invalid join expression
- | ( (INNER | (LEFT | RIGHT | FULL) (OUTER)? ) (joinHint)? )? JOIN tableSource ON searchCondition
- ;
-
-joinedTables
- : subTableSource (joinedTable)+
- ;
-
-joinHint
- :
- LOOP
- | HASH
- | MERGE
- | REMOTE
- ;
-
-tableHint
- :
- INDEX (
- LPAREN (identifier | Integer) ( COMMA (identifier | Integer) )* RPAREN
- | ASSIGNEQUAL identifier // old index hint syntax
- )
- | FASTFIRSTROW
- | HOLDLOCK
- | NOLOCK
- | PAGLOCK
- | READCOMMITED
- | READPAST
- | READUNCOMMITED
- | REPEATABLEREAD
- | ROWLOCK
- | SERIALIZABLE
- | TABLOCK
- | TABLOCKX
- | UPDLOCK
- | XLOCK
- ;
-
-collate
- : COLLATE identifier
- ;
-
-alias1
- : // alias name can also be single-quoted literal (but not for table names)
- (AS)? (
- identifier
- | stringLiteral
- | keywordAsIdentifier
- )
- ;
-
-alias2
- :
- (
- identifier
- | stringLiteral
- | keywordAsIdentifier
- )
- ASSIGNEQUAL
- ;
-
-tableColumns
- :
- o:dbObject DOT_STAR
- ;
-
-column
- :
- (PLUS)* // "++column_name" is valid and updatable column name
- (
- dbObject
- // for expression like "(column)" SQL Server returns updatable column
- | LPAREN column RPAREN
- )
- (collate)? // it is not well documented but COLLATE can be used almost anywhere ...
- ;
-
-expression
- : // current definition ignores operator precedence
- subExpression (binaryOperator subExpression)*
- ;
-
-subExpression
- :
- (unaryOperator)?
- (
- constant
- | Variable
- | (function) => function
- | LPAREN (
- (selectStatement) => selectStatement // select statement returning a single value
- | expression
- ) RPAREN
- | dbObject // column
- | parameterlessFunction
- | caseFunction
- | castFunction
- )
- (collate)? // it is not well documented but COLLATE can be used almost everywhere ...
- ;
-
-// todo: create a separate rule for aggregate functions
-function
- : // LEFT and RIGHT keywords are also function names
- (dbObject | LEFT | RIGHT) LPAREN (
- expression (COMMA expression)*
- | STAR // aggregate functions like Count(), Checksum() accept "*" as a parameter
- | (ALL | DISTINCT) (STAR | expression) // aggregate function
- | Variable ASSIGNEQUAL expression (COMMA Variable ASSIGNEQUAL expression)*
- )?
- RPAREN
- ;
-
-caseFunction
- : CASE (
- expression (WHEN expression THEN expression)+
- | (WHEN searchCondition THEN expression)+ // boolean expression
- )
- (ELSE expression)? END
- ;
-
-castFunction
- : CAST LPAREN expression AS identifier (LPAREN Integer (COMMA Integer)? RPAREN)? RPAREN
- ;
-
-dbObject
- // server.catalog.schema.object
- // server.catalog..object
- :
- (identifier | IDENTITYCOL | ROWGUIDCOL | keywordAsIdentifier) (
- DOT (identifier | IDENTITYCOL | ROWGUIDCOL | keywordAsIdentifier)
- | (DOT DOT) => DOT DOT (identifier | IDENTITYCOL | ROWGUIDCOL | keywordAsIdentifier)
- )*
- ;
-
-parameterlessFunction
- : // any others ?
- CURRENT_TIMESTAMP
- | CURRENT_USER
- | SESSION_USER
- | SYSTEM_USER
- ;
-
-systemVariable
- :
- F_CONNECTIONS
- | F_CPU_BUSY
- | F_CURSOR_ROWS
- | F_DATEFIRST
- | F_DBTS
- | F_ERROR
- | F_FETCH_STATUS
- | F_IDENTITY
- | F_IDLE
- | F_IO_BUSY
- | F_LANGID
- | F_LANGUAGE
- | F_LOCK_TIMEOUT
- | F_MAX_CONNECTIONS
- | F_MAX_PRECISION
- | F_NESTLEVEL
- | F_OPTIONS
- | F_PACK_RECEIVED
- | F_PACK_SENT
- | F_PACKET_ERRORS
- | F_PROCID
- | F_REMSERVER
- | F_ROWCOUNT
- | F_SERVERNAME
- | F_SERVICENAME
- | F_SPID
- | F_TEXTSIZE
- | F_TIMETICKS
- | F_TOTAL_ERRORS
- | F_TOTAL_READ
- | F_TOTAL_WRITE
- | F_TRANCOUNT
- | F_VERSION
- ;
-
-keywordAsIdentifier
- :
- (
- AUTO
- | BASE64
- | BINARY
- | CAST
- | CONCAT
- | CUBE
- | ELEMENTS
- | EXPAND
- | EXPLICIT
- | FAST
- | FASTFIRSTROW
- | FORCE
- | HASH
- | KEEP
- | KEEPFIXED
- | LOOP
- | MAXDOP
- | MERGE
- | NOLOCK
- | PAGLOCK
- | RAW
- | READCOMMITED
- | READPAST
- | READUNCOMMITED
- | REMOTE
- | REPEATABLEREAD
- | ROBUST
- | ROLLUP
- | ROWLOCK
- | SERIALIZABLE
- | TABLOCK
- | TABLOCKX
- | TIES
- | UPDLOCK
- | VIEWS
- | XLOCK
- | XML
- | XMLDATA
- )
- ;
-
-stringLiteral
- :
- UnicodeStringLiteral
- | ASCIIStringLiteral
- ;
-
-identifier
- :
- NonQuotedIdentifier
- | QuotedIdentifier
- ;
-
-constant
- : Integer | Real | NULL | stringLiteral | HexLiteral | Currency | ODBCDateTime | systemVariable
- ;
-
-unaryOperator
- : PLUS | MINUS | TILDE
- ;
-
-binaryOperator
- : arithmeticOperator | bitwiseOperator
- ;
-
-arithmeticOperator
- : PLUS | MINUS | STAR | DIVIDE | MOD
- ;
-
-bitwiseOperator
- : AMPERSAND | TILDE | BITWISEOR | BITWISEXOR
- ;
-
-comparisonOperator
- :
- ASSIGNEQUAL | NOTEQUAL1 | NOTEQUAL2 | LESSTHANOREQUALTO1 | LESSTHANOREQUALTO2
- | LESSTHAN | GREATERTHANOREQUALTO1 | GREATERTHANOREQUALTO2 | GREATERTHAN
- ;
-
-logicalOperator
- : ALL | AND | ANY | BETWEEN | EXISTS | IN | LIKE | NOT | OR | SOME
- ;
-
-unionOperator
- : UNION (ALL)?
- ;
-
-// LEXER *********************************************************************************
-
-class SqlLexer extends Lexer;
-
-options {
- testLiterals = false;
- k = 2;
- caseSensitive = false;
- caseSensitiveLiterals = false;
- charVocabulary='\u0000'..'\uFFFE';
-}
-
-tokens {
- ADD = "add" ;
- ALL = "all" ;
- ALTER = "alter" ;
- AND = "and" ;
- ANY = "any" ;
- AS = "as" ;
- ASC = "asc" ;
- AUTHORIZATION = "authorization" ;
- AUTO = "auto" ;
- BACKUP = "backup" ;
- BASE64 = "base64" ;
- BEGIN = "begin" ;
- BETWEEN = "between" ;
- BINARY = "binary" ;
- BREAK = "break" ;
- BROWSE = "browse" ;
- BULK = "bulk" ;
- BY = "by" ;
- CASCADE = "cascade" ;
- CASE = "case" ;
- CAST = "cast" ;
- CHECK = "check" ;
- CHECKPOINT = "checkpoint" ;
- CLOSE = "close" ;
- CLUSTERED = "clustered" ;
- // COALESCE = "coalesce" ;
- COLLATE = "collate" ;
- COLUMN = "column" ;
- COMMIT = "commit" ;
- COMPUTE = "compute" ;
- CONCAT = "concat" ;
- CONSTRAINT = "constraint" ;
- CONTAINS = "contains" ;
- CONTAINSTABLE = "containstable" ;
- CONTINUE = "continue" ;
- // CONVERT = "convert" ;
- CREATE = "create" ;
- CROSS = "cross" ;
- CUBE = "cube" ;
- CURRENT = "current" ;
- CURRENT_DATE = "current_date" ;
- CURRENT_TIME = "current_time" ;
- CURRENT_TIMESTAMP = "current_timestamp" ;
- CURRENT_USER = "current_user" ;
- CURSOR = "cursor" ;
- DATABASE = "database" ;
- DBCC = "dbcc" ;
- DEALLOCATE = "deallocate" ;
- DECLARE = "declare" ;
- DEFAULT = "default" ;
- DELETE = "delete" ;
- DENY = "deny" ;
- DESC = "desc" ;
- DISK = "disk" ;
- DISTINCT = "distinct" ;
- DISTRIBUTED = "distributed" ;
- DOUBLE = "double" ;
- DROP = "drop" ;
- // DUMMY = "dummy" ;
- DUMP = "dump" ;
- ELEMENTS = "elements" ;
- ELSE = "else" ;
- END = "end" ;
- ERRLVL = "errlvl" ;
- ESCAPE = "escape" ;
- EXCEPT = "except" ;
- EXEC = "exec" ;
- EXECUTE = "execute" ;
- EXISTS = "exists" ;
- EXIT = "exit" ;
- EXPAND = "expand" ;
- EXPLICIT = "explicit" ;
- FAST = "fast" ;
- FASTFIRSTROW = "fastfirstrow" ;
- FETCH = "fetch" ;
- FILE = "file" ;
- FILLFACTOR = "fillfactor" ;
- FOR = "for" ;
- FORCE = "force" ;
- FOREIGN = "foreign" ;
- FREETEXT = "freetext" ;
- FREETEXTTABLE = "freetexttable" ;
- FROM = "from" ;
- FULL = "full" ;
- FUNCTION = "function" ;
- GOTO = "goto" ;
- GRANT = "grant" ;
- GROUP = "group" ;
- HASH = "hash" ;
- HAVING = "having" ;
- HOLDLOCK = "holdlock" ;
- IDENTITY = "identity" ;
- IDENTITY_INSERT = "identity_insert" ;
- IDENTITYCOL = "identitycol" ;
- IF = "if" ;
- IN = "in" ;
- INDEX = "index" ;
- INNER = "inner" ;
- INSERT = "insert" ;
- INTERSECT = "intersect" ;
- INTO = "into" ;
- IS = "is" ;
- JOIN = "join" ;
- KEEP = "keep" ;
- KEEPFIXED = "keepfixed" ;
- KEY = "key" ;
- KILL = "kill" ;
- LEFT = "left" ;
- LIKE = "like" ;
- LINENO = "lineno" ;
- LOAD = "load" ;
- LOOP = "loop" ;
- MAXDOP = "maxdop" ;
- MERGE = "merge" ;
- NATIONAL = "national" ;
- NOCHECK = "nocheck" ;
- NOLOCK = "nolock" ;
- NONCLUSTERED = "nonclustered" ;
- NOT = "not" ;
- NULL = "null" ;
- // NULLIF = "nullif" ;
- OF = "of" ;
- OFF = "off" ;
- OFFSETS = "offsets" ;
- ON = "on" ;
- OPEN = "open" ;
- OPENDATASOURCE = "opendatasource" ;
- OPENQUERY = "openquery" ;
- OPENROWSET = "openrowset" ;
- OPENXML = "openxml" ;
- OPTION = "option" ;
- OR = "or" ;
- ORDER = "order" ;
- OUTER = "outer" ;
- OVER = "over" ;
- PAGLOCK = "paglock" ;
- PERCENT = "percent" ;
- PLAN = "plan" ;
- PRECISION = "precision" ;
- PRIMARY = "primary" ;
- PRINT = "print" ;
- PROC = "proc" ;
- PROCEDURE = "procedure" ;
- PUBLIC = "public" ;
- RAISERROR = "raiserror" ;
- RAW = "raw" ;
- READ = "read" ;
- READCOMMITED = "readcommited" ;
- READPAST = "readpast" ;
- READTEXT = "readtext" ;
- READUNCOMMITED = "readuncommited" ;
- RECONFIGURE = "reconfigure" ;
- REFERENCES = "references" ;
- REMOTE = "remote" ;
- REPEATABLEREAD = "repeatableread" ;
- REPLICATION = "replication" ;
- RESTORE = "restore" ;
- RESTRICT = "restrict" ;
- RETURN = "return" ;
- REVOKE = "revoke" ;
- RIGHT = "right" ;
- ROBUST = "robust" ;
- ROLLBACK = "rollback" ;
- ROLLUP = "rollup" ;
- ROWCOUNT = "rowcount" ;
- ROWGUIDCOL = "rowguidcol" ;
- ROWLOCK = "rowlock" ;
- RULE = "rule" ;
- SAVE = "save" ;
- SCHEMA = "schema" ;
- SELECT = "select" ;
- SERIALIZABLE = "serializable" ;
- SESSION_USER = "session_user" ;
- SET = "set" ;
- SETUSER = "setuser" ;
- SHUTDOWN = "shutdown" ;
- SOME = "some" ;
- STATISTICS = "statistics" ;
- SYSTEM_USER = "system_user" ;
- TABLE = "table" ;
- TABLOCK = "tablock" ;
- TABLOCKX = "tablockx" ;
- TEXTSIZE = "textsize" ;
- THEN = "then" ;
- TIES = "ties" ;
- TO = "to" ;
- TOP = "top" ;
- TRAN = "tran" ;
- TRANSACTION = "transaction" ;
- TRIGGER = "trigger" ;
- TRUNCATE = "truncate" ;
- TSEQUAL = "tsequal" ;
- UNION = "union" ;
- UNIQUE = "unique" ;
- UPDATE = "update" ;
- UPDATETEXT = "updatetext" ;
- UPDLOCK = "updlock" ;
- USE = "use" ;
- USER = "user" ;
- VALUES = "values" ;
- VARYING = "varying" ;
- VIEW = "view" ;
- VIEWS = "views" ;
- WAITFOR = "waitfor" ;
- WHEN = "when" ;
- WHERE = "where" ;
- WHILE = "while" ;
- WITH = "with" ;
- WRITETEXT = "writetext" ;
- XLOCK = "xlock" ;
- XML = "xml" ;
- XMLDATA = "xmldata" ;
-
- // system variables
- F_CONNECTIONS = "@@connections" ;
- F_CPU_BUSY = "@@cpu_busy" ;
- F_CURSOR_ROWS = "@@cursor_rows" ;
- F_DATEFIRST = "@@datefirst" ;
- F_DBTS = "@@dbts" ;
- F_ERROR = "@@error" ;
- F_FETCH_STATUS = "@@fetch_status" ;
- F_IDENTITY = "@@identity" ;
- F_IDLE = "@@idle" ;
- F_IO_BUSY = "@@io_busy" ;
- F_LANGID = "@@langid" ;
- F_LANGUAGE = "@@language" ;
- F_LOCK_TIMEOUT = "@@lock_timeout" ;
- F_MAX_CONNECTIONS = "@@max_connections" ;
- F_MAX_PRECISION = "@@max_precision" ;
- F_NESTLEVEL = "@@nestlevel" ;
- F_OPTIONS = "@@options" ;
- F_PACK_RECEIVED = "@@pack_received" ;
- F_PACK_SENT = "@@pack_sent" ;
- F_PACKET_ERRORS = "@@packet_errors" ;
- F_PROCID = "@@procid" ;
- F_REMSERVER = "@@remserver" ;
- F_ROWCOUNT = "@@rowcount" ;
- F_SERVERNAME = "@@servername" ;
- F_SERVICENAME = "@@servicename" ;
- F_SPID = "@@spid" ;
- F_TEXTSIZE = "@@textsize" ;
- F_TIMETICKS = "@@timeticks" ;
- F_TOTAL_ERRORS = "@@total_errors" ;
- F_TOTAL_READ = "@@total_read" ;
- F_TOTAL_WRITE = "@@total_write" ;
- F_TRANCOUNT = "@@trancount" ;
- F_VERSION = "@@version" ;
-}
-
-// Operators
-
-protected DOT:; // generated as a part of Number rule
-COLON : ':' ;
-COMMA : ',' ;
-SEMICOLON : ';' ;
-
-LPAREN : '(' ;
-RPAREN : ')' ;
-//LSQUARE : '[' ;
-//RSQUARE : ']' ;
-
-ASSIGNEQUAL : '=' ;
-NOTEQUAL1 : "<>" ;
-NOTEQUAL2 : "!=" ;
-LESSTHANOREQUALTO1 : "<=" ;
-LESSTHANOREQUALTO2 : "!>" ;
-LESSTHAN : "<" ;
-GREATERTHANOREQUALTO1 : ">=" ;
-GREATERTHANOREQUALTO2 : "!<" ;
-GREATERTHAN : ">" ;
-
-DIVIDE : '/' ;
-PLUS : '+' ;
-MINUS : '-' ;
-STAR : '*' ;
-MOD : '%' ;
-
-AMPERSAND : '&' ;
-TILDE : '~' ;
-BITWISEOR : '|' ;
-BITWISEXOR : '^' ;
-DOT_STAR : ".*" ;
-
-Whitespace
- : (' ' | '\t' | '\n' | '\r')
- { _ttype = Token.SKIP; }
- ;
-
-// COMMENTS
-SingleLineComment
- : "--"( ~('\r' | '\n') )*
- { _ttype = Token.SKIP; }
- ;
-
-MultiLineComment
- : "/*" (~'*')* '*' ('*' | ( ~('*' | '/') (~'*')* '*') )* '/'
- { _ttype = Token.SKIP; }
- ;
-
-// LITERALS
-
-protected
-Letter
- : 'a'..'z' | '_' | '#' | '@' | '\u0080'..'\ufffe'
- ;
-
-protected
-Digit
- : '0'..'9'
- ;
-
-protected
-Integer :;
-
-protected
-Real :;
-
-protected
-Exponent
- : 'e' ( '+' | '-' )? (Digit)+
- ;
-
-Number
- :
- ( (Digit)+ ('.' | 'e') ) => (Digit)+ ( '.' (Digit)* (Exponent)? | Exponent) { _ttype = Real; }
- | '.' { _ttype = DOT; } ( (Digit)+ (Exponent)? { _ttype = Real; } )?
- | (Digit)+ { _ttype = Integer; }
- | "0x" ('a'..'f' | Digit)* { _ttype = HexLiteral; } // "0x" is valid hex literal
- ;
-
-protected
-Currency
- : // generated as a part of NonQuotedIdentifier rule
- ('$' | '\u00a3'..'\u00a5' | '\u09f2'..'\u09f3' | '\u0e3f' | '\u20a0'..'\u20a4' | '\u20a6'..'\u20ab')
- ((Digit)+ ('.' (Digit)* )? | '.' (Digit)+)
- ;
-
-ODBCDateTime
- : '{' (Whitespace)? ("ts" | 't' | 'd') (Whitespace)?
- ('n')? '\'' (~'\'')* '\'' ( '\'' (~'\'')* '\'' )* (Whitespace)? '}'
- ;
-
-NonQuotedIdentifier
- options { testLiterals = true; }
- :
- (Currency) => Currency { _ttype = Currency; }
- | ('a'..'z' | '_' | '#' | '\u0080'..'\ufffe') (Letter | Digit)* // first char other than '@'
- ;
-
-QuotedIdentifier
- :
- (
- '[' (~']')* ']' (']' (~']')* ']')*
- | '"' (~'"')* '"' ('"' (~'"')* '"')*
- )
- ;
-
-Variable
- // test for literals in case of a function begining with '@' (eg. "@@ERROR")
- options { testLiterals = true; }
- : '@' (Letter | Digit)+
- ;
-
-ASCIIStringLiteral
- :
- '\'' (~'\'')* '\'' ( '\'' (~'\'')* '\'' )*
- ;
-
-UnicodeStringLiteral
- :
- 'n' '\'' (~'\'')* '\'' ( '\'' (~'\'')* '\'' )*
- ;
-
-// Numeric Constants
-
-protected
-HexLiteral // generated as a part of Number rule
- : // "0x" ('0'..'9' | 'a'..'f')*
- ;
\ No newline at end of file
diff --git a/core/query/table.php b/core/query/table.php
index 0566a24..19f67a4 100644
--- a/core/query/table.php
+++ b/core/query/table.php
@@ -12,4 +12,3 @@ class Table
public $condition;
}
-?>
\ No newline at end of file
diff --git a/core/spyc.php b/core/spyc.php
deleted file mode 100644
index 968aafe..0000000
--- a/core/spyc.php
+++ /dev/null
@@ -1,741 +0,0 @@
-
- * @author Vlad Andersen
- * @link http://spyc.sourceforge.net/
- * @copyright Copyright 2005-2006 Chris Wanstrath
- * @license http://www.opensource.org/licenses/mit-license.php MIT License
- * @package Spyc
- */
-/**
- * The Simple PHP YAML Class.
- *
- * This class can be used to read a YAML file and convert its contents
- * into a PHP array. It currently supports a very limited subsection of
- * the YAML spec.
- *
- * Usage:
- *
- * $parser = new Spyc;
- * $array = $parser->load($file);
- *
- * @package Spyc
- */
-class Spyc {
-
- /**#@+
- * @access private
- * @var mixed
- */
- private $_haveRefs;
- private $_allNodes;
- private $_allParent;
- private $_lastIndent;
- private $_lastNode;
- private $_inBlock;
- private $_isInline;
- private $_dumpIndent;
- private $_dumpWordWrap;
- private $_containsGroupAnchor = false;
- private $_containsGroupAlias = false;
- private $path;
- private $result;
- private $LiteralBlockMarkers = array ('>', '|');
- private $LiteralPlaceHolder = '___YAML_Literal_Block___';
- private $SavedGroups = array();
-
- /**#@+
- * @access public
- * @var mixed
- */
- public $_nodeId;
-
- /**
- * Load YAML into a PHP array statically
- *
- * The load method, when supplied with a YAML stream (string or file),
- * will do its best to convert YAML in a file into a PHP array. Pretty
- * simple.
- * Usage:
- *
- * $array = Spyc::YAMLLoad('lucky.yaml');
- * print_r($array);
- *
- * @access public
- * @return array
- * @param string $input Path of YAML file or string containing YAML
- */
- public static function YAMLLoad($input) {
- $Spyc = new Spyc;
- return $Spyc->load($input);
- }
-
- /**
- * Dump YAML from PHP array statically
- *
- * The dump method, when supplied with an array, will do its best
- * to convert the array into friendly YAML. Pretty simple. Feel free to
- * save the returned string as nothing.yaml and pass it around.
- *
- * Oh, and you can decide how big the indent is and what the wordwrap
- * for folding is. Pretty cool -- just pass in 'false' for either if
- * you want to use the default.
- *
- * Indent's default is 2 spaces, wordwrap's default is 40 characters. And
- * you can turn off wordwrap by passing in 0.
- *
- * @access public
- * @return string
- * @param array $array PHP array
- * @param int $indent Pass in false to use the default, which is 2
- * @param int $wordwrap Pass in 0 for no wordwrap, false for default (40)
- */
- public static function YAMLDump($array,$indent = false,$wordwrap = false) {
- $spyc = new Spyc;
- return $spyc->dump($array,$indent,$wordwrap);
- }
-
-
- /**
- * Dump PHP array to YAML
- *
- * The dump method, when supplied with an array, will do its best
- * to convert the array into friendly YAML. Pretty simple. Feel free to
- * save the returned string as tasteful.yaml and pass it around.
- *
- * Oh, and you can decide how big the indent is and what the wordwrap
- * for folding is. Pretty cool -- just pass in 'false' for either if
- * you want to use the default.
- *
- * Indent's default is 2 spaces, wordwrap's default is 40 characters. And
- * you can turn off wordwrap by passing in 0.
- *
- * @access public
- * @return string
- * @param array $array PHP array
- * @param int $indent Pass in false to use the default, which is 2
- * @param int $wordwrap Pass in 0 for no wordwrap, false for default (40)
- */
- public function dump($array,$indent = false,$wordwrap = false) {
- // Dumps to some very clean YAML. We'll have to add some more features
- // and options soon. And better support for folding.
-
- // New features and options.
- if ($indent === false or !is_numeric($indent)) {
- $this->_dumpIndent = 2;
- } else {
- $this->_dumpIndent = $indent;
- }
-
- if ($wordwrap === false or !is_numeric($wordwrap)) {
- $this->_dumpWordWrap = 40;
- } else {
- $this->_dumpWordWrap = $wordwrap;
- }
-
- // New YAML document
- $string = "---\n";
-
- // Start at the base of the array and move through it.
- foreach ($array as $key => $value) {
- $string .= $this->_yamlize($key,$value,0);
- }
- return $string;
- }
-
- /**
- * Attempts to convert a key / value array item to YAML
- * @access private
- * @return string
- * @param $key The name of the key
- * @param $value The value of the item
- * @param $indent The indent of the current node
- */
- private function _yamlize($key,$value,$indent) {
- if (is_array($value)) {
- // It has children. What to do?
- // Make it the right kind of item
- $string = $this->_dumpNode($key,NULL,$indent);
- // Add the indent
- $indent += $this->_dumpIndent;
- // Yamlize the array
- $string .= $this->_yamlizeArray($value,$indent);
- } elseif (!is_array($value)) {
- // It doesn't have children. Yip.
- $string = $this->_dumpNode($key,$value,$indent);
- }
- return $string;
- }
-
- /**
- * Attempts to convert an array to YAML
- * @access private
- * @return string
- * @param $array The array you want to convert
- * @param $indent The indent of the current level
- */
- private function _yamlizeArray($array,$indent) {
- if (is_array($array)) {
- $string = '';
- foreach ($array as $key => $value) {
- $string .= $this->_yamlize($key,$value,$indent);
- }
- return $string;
- } else {
- return false;
- }
- }
-
- /**
- * Returns YAML from a key and a value
- * @access private
- * @return string
- * @param $key The name of the key
- * @param $value The value of the item
- * @param $indent The indent of the current node
- */
- private function _dumpNode($key,$value,$indent) {
- // do some folding here, for blocks
- if (strpos($value,"\n") !== false || strpos($value,": ") !== false || strpos($value,"- ") !== false) {
- $value = $this->_doLiteralBlock($value,$indent);
- } else {
- $value = $this->_doFolding($value,$indent);
- }
-
- if (is_bool($value)) {
- $value = ($value) ? "true" : "false";
- }
-
- $spaces = str_repeat(' ',$indent);
-
- if (is_int($key)) {
- // It's a sequence
- $string = $spaces.'- '.$value."\n";
- } else {
- // It's mapped
- $string = $spaces.$key.': '.$value."\n";
- }
- return $string;
- }
-
- /**
- * Creates a literal block for dumping
- * @access private
- * @return string
- * @param $value
- * @param $indent int The value of the indent
- */
- private function _doLiteralBlock($value,$indent) {
- $exploded = explode("\n",$value);
- $newValue = '|';
- $indent += $this->_dumpIndent;
- $spaces = str_repeat(' ',$indent);
- foreach ($exploded as $line) {
- $newValue .= "\n" . $spaces . trim($line);
- }
- return $newValue;
- }
-
- /**
- * Folds a string of text, if necessary
- * @access private
- * @return string
- * @param $value The string you wish to fold
- */
- private function _doFolding($value,$indent) {
- // Don't do anything if wordwrap is set to 0
- if ($this->_dumpWordWrap === 0) {
- return $value;
- }
-
- if (strlen($value) > $this->_dumpWordWrap) {
- $indent += $this->_dumpIndent;
- $indent = str_repeat(' ',$indent);
- $wrapped = wordwrap($value,$this->_dumpWordWrap,"\n$indent");
- $value = ">\n".$indent.$wrapped;
- }
- return $value;
- }
-
-/* LOADING FUNCTIONS */
-
- private function load($input) {
- $Source = $this->loadFromSource($input);
- if (empty ($Source)) return array();
- $this->path = array();
- $this->result = array();
-
-
- for ($i = 0; $i < count($Source); $i++) {
- $line = $Source[$i];
- $lineIndent = $this->_getIndent($line);
- $this->path = $this->getParentPathByIndent($lineIndent);
- $line = $this->stripIndent($line, $lineIndent);
- if ($this->isComment($line)) continue;
-
- if ($literalBlockStyle = $this->startsLiteralBlock($line)) {
- $line = rtrim ($line, $literalBlockStyle . "\n");
- $literalBlock = '';
- $line .= $this->LiteralPlaceHolder;
-
- while ($this->literalBlockContinues($Source[++$i], $lineIndent)) {
- $literalBlock = $this->addLiteralLine($literalBlock, $Source[$i], $literalBlockStyle);
- }
- $i--;
- }
- $lineArray = $this->_parseLine($line);
- if ($literalBlockStyle)
- $lineArray = $this->revertLiteralPlaceHolder ($lineArray, $literalBlock);
-
- $this->addArray($lineArray, $lineIndent);
- }
- return $this->result;
- }
-
- private function loadFromSource ($input) {
- if (!empty($input) && strpos($input, "\n") === false && file_exists($input))
- return file($input);
-
- $foo = explode("\n",$input);
- foreach ($foo as $k => $_) {
- $foo[$k] = trim ($_, "\r");
- }
- return $foo;
- }
-
- /**
- * Finds and returns the indentation of a YAML line
- * @access private
- * @return int
- * @param string $line A line from the YAML file
- */
- private function _getIndent($line) {
- if (!preg_match('/^ +/',$line,$match)) return 0;
- if (!empty($match[0])) return strlen ($match[0]);
- return 0;
- }
-
- /**
- * Parses YAML code and returns an array for a node
- * @access private
- * @return array
- * @param string $line A line from the YAML file
- */
- private function _parseLine($line) {
- if (!$line) return array();
- $line = trim($line);
- if (!$line) return array();
- $array = array();
-
- if ($group = $this->nodeContainsGroup($line)) {
- $this->addGroup($line, $group);
- $line = $this->stripGroup ($line, $group);
- }
-
- if ($this->startsMappedSequence($line))
- return $this->returnMappedSequence($line);
-
- if ($this->startsMappedValue($line))
- return $this->returnMappedValue($line);
-
- if ($this->isArrayElement($line))
- return $this->returnArrayElement($line);
-
- return $this->returnKeyValuePair($line);
-
- }
-
-
-
- /**
- * Finds the type of the passed value, returns the value as the new type.
- * @access private
- * @param string $value
- * @return mixed
- */
- private function _toType($value) {
-
- if (strpos($value, '#') !== false)
- $value = trim(preg_replace('/#(.+)$/','',$value));
-
-
- if (preg_match('/^("(.*)"|\'(.*)\')/',$value,$matches)) {
- $value = (string)preg_replace('/(\'\'|\\\\\')/',"'",end($matches));
- $value = preg_replace('/\\\\"/','"',$value);
- } elseif (preg_match('/^\\[(.+)\\]$/',$value,$matches)) {
- // Inline Sequence
-
- // Take out strings sequences and mappings
- $explode = $this->_inlineEscape($matches[1]);
-
- // Propogate value array
- $value = array();
- foreach ($explode as $v) {
- $value[] = $this->_toType($v);
- }
- } elseif (strpos($value,': ')!==false && !preg_match('/^{(.+)/',$value)) {
-
- // It's a map
- $array = explode(': ',$value);
- $key = trim($array[0]);
- array_shift($array);
- $value = trim(implode(': ',$array));
- $value = $this->_toType($value);
- $value = array($key => $value);
- } elseif (preg_match("/{(.+)}$/",$value,$matches)) {
- // Inline Mapping
-
- // Take out strings sequences and mappings
- $explode = $this->_inlineEscape($matches[1]);
-
- // Propogate value array
- $array = array();
- foreach ($explode as $v) {
- $array = $array + $this->_toType($v);
- }
- $value = $array;
- } elseif (strtolower($value) == 'null' or $value == '' or $value == '~') {
- $value = null;
- } elseif (preg_match ('/^[0-9]+$/', $value)) {
- $value = (int)$value;
- } elseif (in_array(strtolower($value),
- array('true', 'on', '+', 'yes', 'y'))) {
- $value = true;
- } elseif (in_array(strtolower($value),
- array('false', 'off', '-', 'no', 'n'))) {
- $value = false;
- } elseif (is_numeric($value)) {
- $value = (float)$value;
- } else {
- // Just a normal string, right?
- // $value = trim(preg_replace('/#(.+)$/','',$value));
- }
-
-
- // print_r ($value);
- return $value;
- }
-
- /**
- * Used in inlines to check for more inlines or quoted strings
- * @access private
- * @return array
- */
- private function _inlineEscape($inline) {
- // There's gotta be a cleaner way to do this...
- // While pure sequences seem to be nesting just fine,
- // pure mappings and mappings with sequences inside can't go very
- // deep. This needs to be fixed.
-
- $saved_strings = array();
-
- // Check for strings
- $regex = '/(?:(")|(?:\'))((?(1)[^"]+|[^\']+))(?(1)"|\')/';
- if (preg_match_all($regex,$inline,$strings)) {
- $saved_strings = $strings[0];
- $inline = preg_replace($regex,'YAMLString',$inline);
- }
- unset($regex);
-
- // Check for sequences
- if (preg_match_all('/\[(.+)\]/U',$inline,$seqs)) {
- $inline = preg_replace('/\[(.+)\]/U','YAMLSeq',$inline);
- $seqs = $seqs[0];
- }
-
- // Check for mappings
- if (preg_match_all('/{(.+)}/U',$inline,$maps)) {
- $inline = preg_replace('/{(.+)}/U','YAMLMap',$inline);
- $maps = $maps[0];
- }
-
- $explode = explode(', ',$inline);
-
-
- // Re-add the sequences
- if (!empty($seqs)) {
- $i = 0;
- foreach ($explode as $key => $value) {
- if (strpos($value,'YAMLSeq') !== false) {
- $explode[$key] = str_replace('YAMLSeq',$seqs[$i],$value);
- ++$i;
- }
- }
- }
-
- // Re-add the mappings
- if (!empty($maps)) {
- $i = 0;
- foreach ($explode as $key => $value) {
- if (strpos($value,'YAMLMap') !== false) {
- $explode[$key] = str_replace('YAMLMap',$maps[$i],$value);
- ++$i;
- }
- }
- }
-
-
- // Re-add the strings
- if (!empty($saved_strings)) {
- $i = 0;
- foreach ($explode as $key => $value) {
- while (strpos($value,'YAMLString') !== false) {
- $explode[$key] = preg_replace('/YAMLString/',$saved_strings[$i],$value, 1);
- ++$i;
- $value = $explode[$key];
- }
- }
- }
-
- return $explode;
- }
-
- private function literalBlockContinues ($line, $lineIndent) {
- if (!trim($line)) return true;
- if ($this->_getIndent($line) > $lineIndent) return true;
- return false;
- }
-
- private function addArray ($array, $indent) {
-
- $key = key ($array);
- if (!isset ($array[$key])) return false;
- if ($array[$key] === array()) { $array[$key] = ''; };
- $value = $array[$key];
-
- // Unfolding inner array tree as defined in $this->_arrpath.
- //$_arr = $this->result; $_tree[0] = $_arr; $i = 1;
-
- $tempPath = Spyc::flatten ($this->path);
- eval ('$_arr = $this->result' . $tempPath . ';');
-
-
- if ($this->_containsGroupAlias) {
- do {
- if (!isset($this->SavedGroups[$this->_containsGroupAlias])) { echo "Bad group name: $this->_containsGroupAlias."; break; }
- $groupPath = $this->SavedGroups[$this->_containsGroupAlias];
- eval ('$value = $this->result' . Spyc::flatten ($groupPath) . ';');
- } while (false);
- $this->_containsGroupAlias = false;
- }
-
-
- // Adding string or numeric key to the innermost level or $this->arr.
- if ($key)
- $_arr[$key] = $value;
- else {
- if (!is_array ($_arr)) { $_arr = array ($value); $key = 0; }
- else { $_arr[] = $value; end ($_arr); $key = key ($_arr); }
-
- }
-
- $this->path[$indent] = $key;
-
- eval ('$this->result' . $tempPath . ' = $_arr;');
-
- if ($this->_containsGroupAnchor) {
- $this->SavedGroups[$this->_containsGroupAnchor] = $this->path;
- $this->_containsGroupAnchor = false;
- }
-
-
- }
-
-
- private function flatten ($array) {
- $tempPath = array();
- if (!empty ($array)) {
- foreach ($array as $_) {
- if (!is_int($_)) $_ = "'$_'";
- $tempPath[] = "[$_]";
- }
- }
- //end ($tempPath); $latestKey = key($tempPath);
- $tempPath = implode ('', $tempPath);
- return $tempPath;
- }
-
-
-
- private function startsLiteralBlock ($line) {
- $lastChar = substr (trim($line), -1);
- if (in_array ($lastChar, $this->LiteralBlockMarkers))
- return $lastChar;
- return false;
- }
-
- private function addLiteralLine ($literalBlock, $line, $literalBlockStyle) {
- $line = $this->stripIndent($line);
- $line = str_replace ("\r\n", "\n", $line);
-
- if ($literalBlockStyle == '|') {
- return $literalBlock . $line;
- }
- if (strlen($line) == 0) return $literalBlock . "\n";
-
- // echo "|$line|";
- if ($line != "\n")
- $line = trim ($line, "\r\n ") . " ";
-
- return $literalBlock . $line;
- }
-
- private function revertLiteralPlaceHolder ($lineArray, $literalBlock) {
-
- foreach ($lineArray as $k => $_) {
- if (substr($_, -1 * strlen ($this->LiteralPlaceHolder)) == $this->LiteralPlaceHolder)
- $lineArray[$k] = rtrim ($literalBlock, " \r\n");
- }
- return $lineArray;
- }
-
- private function stripIndent ($line, $indent = -1) {
- if ($indent == -1) $indent = $this->_getIndent($line);
- return substr ($line, $indent);
- }
-
- private function getParentPathByIndent ($indent) {
-
- if ($indent == 0) return array();
-
- $linePath = $this->path;
- do {
- end($linePath); $lastIndentInParentPath = key($linePath);
- if ($indent <= $lastIndentInParentPath) array_pop ($linePath);
- } while ($indent <= $lastIndentInParentPath);
- return $linePath;
- }
-
-
- private function clearBiggerPathValues ($indent) {
-
-
- if ($indent == 0) $this->path = array();
- if (empty ($this->path)) return true;
-
- foreach ($this->path as $k => $_) {
- if ($k > $indent) unset ($this->path[$k]);
- }
-
- return true;
- }
-
-
- private function isComment ($line) {
- if (preg_match('/^#/', $line)) return true;
- return false;
- }
-
- private function isArrayElement ($line) {
- if (!$line) return false;
- if ($line[0] != '-') return false;
- if (strlen ($line) > 3)
- if (substr($line,0,3) == '---') return false;
-
- return true;
- }
-
- private function isHashElement ($line) {
- if (!preg_match('/^(.+?):/', $line, $matches)) return false;
- $allegedKey = $matches[1];
- if ($allegedKey) return true;
- //if (substr_count($allegedKey, )
- return false;
- }
-
- private function isLiteral ($line) {
- if ($this->isArrayElement($line)) return false;
- if ($this->isHashElement($line)) return false;
- return true;
- }
-
-
- private function startsMappedSequence ($line) {
- if (preg_match('/^-(.*):$/',$line)) return true;
- }
-
- private function returnMappedSequence ($line) {
- $array = array();
- $key = trim(substr(substr($line,1),0,-1));
- $array[$key] = '';
- return $array;
- }
-
- private function returnMappedValue ($line) {
- $array = array();
- $key = trim(substr($line,0,-1));
- $array[$key] = '';
- return $array;
- }
-
- private function startsMappedValue ($line) {
- if (preg_match('/^(.*):$/',$line)) return true;
- }
-
- private function returnKeyValuePair ($line) {
-
- $array = array();
-
- if (preg_match('/^(.+):/',$line,$key)) {
- // It's a key/value pair most likely
- // If the key is in double quotes pull it out
- if (preg_match('/^(["\'](.*)["\'](\s)*:)/',$line,$matches)) {
- $value = trim(str_replace($matches[1],'',$line));
- $key = $matches[2];
- } else {
- // Do some guesswork as to the key and the value
- $explode = explode(':',$line);
- $key = trim($explode[0]);
- array_shift($explode);
- $value = trim(implode(':',$explode));
- }
-
- // Set the type of the value. Int, string, etc
- $value = $this->_toType($value);
- if (empty($key)) {
- $array[] = $value;
- } else {
- $array[$key] = $value;
- }
- }
-
- return $array;
-
- }
-
-
- private function returnArrayElement ($line) {
- if (strlen($line) <= 1) return array(array()); // Weird %)
- $array = array();
- $value = trim(substr($line,1));
- $value = $this->_toType($value);
- $array[] = $value;
- return $array;
- }
-
-
- private function nodeContainsGroup ($line) {
- if (strpos($line, '&') === false && strpos($line, '*') === false) return false; // Please die fast ;-)
- if (preg_match('/^(&[^ ]+)/', $line, $matches)) return $matches[1];
- if (preg_match('/^(\*[^ ]+)/', $line, $matches)) return $matches[1];
- if (preg_match('/(&[^" ]+$)/', $line, $matches)) return $matches[1];
- if (preg_match('/(\*[^" ]+$)/', $line, $matches)) return $matches[1];
- return false;
- }
-
- private function addGroup ($line, $group) {
- if (substr ($group, 0, 1) == '&') $this->_containsGroupAnchor = substr ($group, 1);
- if (substr ($group, 0, 1) == '*') $this->_containsGroupAlias = substr ($group, 1);
- //print_r ($this->path);
- }
-
- private function stripGroup ($line, $group) {
- $line = trim(str_replace($group, '', $line));
- return $line;
- }
-
-
-}
-?>
diff --git a/core/tools/drawing.php b/core/tools/drawing.php
index bb7674b..b0cf247 100644
--- a/core/tools/drawing.php
+++ b/core/tools/drawing.php
@@ -120,4 +120,3 @@ class Drawing
}
}
}
-?>
\ No newline at end of file
diff --git a/core/tools/exceltable.php b/core/tools/exceltable.php
index dc65a4f..ded9278 100644
--- a/core/tools/exceltable.php
+++ b/core/tools/exceltable.php
@@ -435,4 +435,3 @@ class ExcelDocument {
}
}
-?>
\ No newline at end of file
diff --git a/core/tools/password.php b/core/tools/password.php
index 72e7927..1308a52 100644
--- a/core/tools/password.php
+++ b/core/tools/password.php
@@ -30,4 +30,3 @@ function generatePassword($length = 9, $strength = 0) {
return $password;
}
-?>
\ No newline at end of file
diff --git a/core/tools/templateimage.php b/core/tools/templateimage.php
index 825a5c2..302678e 100644
--- a/core/tools/templateimage.php
+++ b/core/tools/templateimage.php
@@ -204,4 +204,3 @@ class TemplateImage
}
}
-?>
diff --git a/core/widgets/dialog.php b/core/widgets/dialog.php
deleted file mode 100644
index 2aaf917..0000000
--- a/core/widgets/dialog.php
+++ /dev/null
@@ -1,36 +0,0 @@
-friend = $friend->getName();
- }
-
- function getPostCode()
- {
- return $this->getName() . ".setFriend(" . $this->friend . ");";
- }
-
- function setTitle($title)
- {
- $this->title = $title;
- }
-
- function setAction($action)
- {
- $this->action = forceUrl($action);
- }
-}
-
-?>
\ No newline at end of file
diff --git a/core/widgets/filebrowser.php b/core/widgets/filebrowser.php
deleted file mode 100644
index 0b55d5b..0000000
--- a/core/widgets/filebrowser.php
+++ /dev/null
@@ -1,39 +0,0 @@
-setData('type', $type);
- }
-
- function setHeader($header)
- {
- $this->setData('table', $header);
- }
-
- function setFriend(Widget $friend)
- {
- $this->friend = $friend->getName();
- }
-
- function getPostCode()
- {
- if ($this->friend) {
- return $this->getName() . ".setFriend(" . $this->friend . ");";
- }
- return "";
- }
-
- function postMake() {
- $this->view->addScriptRaw($this->getPostCode(), true); // CompositeView
- }
-}
-
-?>
\ No newline at end of file
diff --git a/core/widgets/listtable.php b/core/widgets/listtable.php
deleted file mode 100644
index 9bbe6c7..0000000
--- a/core/widgets/listtable.php
+++ /dev/null
@@ -1,71 +0,0 @@
-menu = array();
- $this->template = "table";
- }
-
- /**
- * Устанавливает формат таблицы, структуру $header см. table.js
- */
- function setHeader($header)
- {
- $this->setData('table', $header);
- }
-
- function setView($visible)
- {
- $this->visible = $visible;
- }
-
- function setAction($action)
- {
- $this->setData('list', forceUrl($action));
- }
-
- function addMenuItem($href, $name, $to = 'item')
- {
- if ($href) {
- if ($to === true) $to = 'all';
- if (! isset($this->menu[$to])) {
- $this->menu[$to] = array('group' => $to, 'all' => ($to == 'all'), 'items' => array());
- }
- $this->menu[$to]['items'][] = array('href' => $href, 'name' => $name);
- }
- }
-
- function make(Controller $parent)
- {
- $view = $this->visible;
- if (is_null($view)) {
- $view = array('left' => key_values('key', $this->data['table']), 'right' => array());
- }
-
- $this->setData('setup', $view);
-
- foreach ($this->menu as &$menu) {
- foreach ($menu['items'] as &$item) {
- $item['href'] = forceUrl($item['href']);
- }
- }
- $this->setData('menu', array_keys($this->menu));
-
- parent::make($parent);
-
- $this->view->menus = $this->menu;
- }
-}
-
-?>
\ No newline at end of file
diff --git a/core/widgets/menu.php b/core/widgets/menu.php
deleted file mode 100644
index 27c539f..0000000
--- a/core/widgets/menu.php
+++ /dev/null
@@ -1,38 +0,0 @@
-items[] = array('href' => $href, 'name' => ucfirst($name)); // menu_item
- }
- }
-
- /**
- * Массив ссылок
- * @return Массив
- */
- function getItems()
- {
- foreach ($this->items as &$item) {
- if (is_callable($item['href'])) {
- $item['href'] = call_user_func($item['href']);
- }
- }
- return $this->items;
- }
-}
-
-?>
\ No newline at end of file
diff --git a/core/widgets/pagemenu.php b/core/widgets/pagemenu.php
deleted file mode 100644
index 98100a5..0000000
--- a/core/widgets/pagemenu.php
+++ /dev/null
@@ -1,30 +0,0 @@
-menu = new SimpleMenu();
- $this->template = "menu";
- }
-
- function addMenuItem($name, $value)
- {
- $this->menu->addMenuItem($name, $value);
- }
-
- function postMake()
- {
- $this->view->items = $this->menu->getItems();
- }
-}
-
-?>
\ No newline at end of file
diff --git a/core/widgets/pages.php b/core/widgets/pages.php
deleted file mode 100644
index 2f667bc..0000000
--- a/core/widgets/pages.php
+++ /dev/null
@@ -1,16 +0,0 @@
-template = "pages";
- }
-}
-
-?>
\ No newline at end of file
diff --git a/core/widgets/search.php b/core/widgets/search.php
deleted file mode 100644
index 2682bd7..0000000
--- a/core/widgets/search.php
+++ /dev/null
@@ -1,32 +0,0 @@
-template = "search";
- }
-
- function addFields($fields)
- {
- $this->fields = $fields;
- }
-
- function postMake()
- {
- $form = new TForm (); // Показывем форму
- $form->addFieldList ($this->fields); // Разделить форму поиска и редактирования
- $this->view->form = $form;
-
- $this->view->action = $this->action;
- $this->view->title = $this->title;
- $this->view->addScriptRaw($this->getPostCode(), true); // CompositeView
- }
-}
-
-?>
-
diff --git a/core/widgets/setup.php b/core/widgets/setup.php
deleted file mode 100644
index 8931e81..0000000
--- a/core/widgets/setup.php
+++ /dev/null
@@ -1,20 +0,0 @@
-template = "setup";
- }
-
- function postMake()
- {
- $this->view->action = $this->action;
- $this->view->title = $this->title;
- $this->view->addScriptRaw($this->getPostCode(), true); // CompositeView
- }
-}
-
-?>
\ No newline at end of file
diff --git a/core/widgets/tree.php b/core/widgets/tree.php
deleted file mode 100644
index 1faea59..0000000
--- a/core/widgets/tree.php
+++ /dev/null
@@ -1,17 +0,0 @@
-template = "tree";
- }
- // Добавление ветки дерева
-}
-
-?>
\ No newline at end of file
diff --git a/core/widgets/widget.php b/core/widgets/widget.php
deleted file mode 100644
index 95ef5ff..0000000
--- a/core/widgets/widget.php
+++ /dev/null
@@ -1,87 +0,0 @@
-id = self::$idx ++;
- $this->setUp();
- }
-
- function setUp()
- {
- }
-
- public function getName()
- {
- return self::$prefix . intval($this->id);
- }
-
- /**
- * Генерация кода инициализации компонента на стороне клиента
- */
- public function getCodeBefore()
- {
- $result =
-// "alert('".$this->getName()."');" .
- "var " . $this->getName() . " = new " . get_class($this) . "("
- . json::encode($this->data) . ");";
- return $result;
- }
-
- public function setData($name, $value)
- {
- $this->data[$name] = $value;
- }
-
- public function getCodeAfter()
- {
- return $this->getName() . ".appendTo(document.getElementById('" . $this->getName() . "'));\n";
- }
-
- public function postMake()
- {
- }
-
- /**
- * Генерация компонента
- */
- function make(Controller $parent)
- {
- $this->view = $parent->getView($this->template); // Controller
- $this->view->index = $this->getName();
- foreach ($this->data as $name => $value) {
- $this->view->set($name, $value);
- }
- $this->view->addScriptRaw($this->getCodeBefore(), true);
- $this->postMake();
- $this->view->addScriptRaw($this->getCodeAfter(), true);
- }
-}
-
-?>
\ No newline at end of file
diff --git a/core/zipfile.php b/core/zipfile.php
index e615890..e55c100 100644
--- a/core/zipfile.php
+++ b/core/zipfile.php
@@ -1,16 +1,11 @@
addDirDo($location, $name);
}
}
-
-?>
\ No newline at end of file
diff --git a/core/search/htmlhelper.php b/search/htmlhelper.php
similarity index 99%
rename from core/search/htmlhelper.php
rename to search/htmlhelper.php
index 99a9fdf..60f29f2 100644
--- a/core/search/htmlhelper.php
+++ b/search/htmlhelper.php
@@ -80,6 +80,3 @@ function not_ctype_alpha ($ch)
{
return !ctype_alpha($ch);
}
-
-
-?>
\ No newline at end of file
diff --git a/core/search/index.php b/search/index.php
similarity index 99%
rename from core/search/index.php
rename to search/index.php
index 49e8979..0d4cc9e 100644
--- a/core/search/index.php
+++ b/search/index.php
@@ -82,5 +82,3 @@ class Index
}
}
}
-
-?>
\ No newline at end of file
diff --git a/core/search/lexer.php b/search/lexer.php
similarity index 99%
rename from core/search/lexer.php
rename to search/lexer.php
index b9707ef..b555006 100644
--- a/core/search/lexer.php
+++ b/search/lexer.php
@@ -89,5 +89,3 @@ class Lexer
$this->token = $this->getToken();
}
}
-
-?>
\ No newline at end of file
diff --git a/core/search/search.php b/search/search.php
similarity index 99%
rename from core/search/search.php
rename to search/search.php
index 49dd2b5..d2b6266 100644
--- a/core/search/search.php
+++ b/search/search.php
@@ -95,4 +95,3 @@ class Search
}
}
-?>
\ No newline at end of file
diff --git a/core/search/searcher.php b/search/searcher.php
similarity index 99%
rename from core/search/searcher.php
rename to search/searcher.php
index 38f7af2..c320809 100644
--- a/core/search/searcher.php
+++ b/search/searcher.php
@@ -99,4 +99,3 @@ class Searcher {
}
}
-?>
\ No newline at end of file
diff --git a/core/search/stemmer.php b/search/stemmer.php
similarity index 99%
rename from core/search/stemmer.php
rename to search/stemmer.php
index 42fa1df..f3bee01 100644
--- a/core/search/stemmer.php
+++ b/search/stemmer.php
@@ -178,4 +178,3 @@ class Stemmer {
return $word;
}
}
-?>
\ No newline at end of file