Permalink
Browse files

build 936: add ZenCoding to the $errorTag property and the $menuTag p…

…arameter (of the createMenu..() methods); removed $errorId, $errorClass, $errorAttribute

Signed-off-by: Fabian Vogelsteller <fabian@frozeman.de>
  • Loading branch information...
frozeman committed Jun 15, 2012
1 parent 96aa64f commit 9072594c543cfedc563f7654c5d9c348d429b280
View
@@ -1,7 +1,7 @@
feindura - Flat File Content Management System
Version
2.0
-Build 935
+Build 936
==================================================
Copyright (C) Fabian Vogelsteller [frozeman.de]
published under the GNU General Public License version 3
@@ -24,6 +24,7 @@ ChangeLog:
2.0
+ build 936: add ZenCoding to the $errorTag property and the $menuTag parameter (of the createMenu..() methods); removed $errorId, $errorClass, $errorAttribute
build 935: add 'position' to the returned listPages and createMenu array! helps to style the menus...
build 934: fixed snippets; dont allow to add frontend editing divs..
build 933: add possibility to use %href% in the shortenText parameter array(), to be replaced with the pages href
@@ -31,7 +31,7 @@
'votes' => 0
)
),
- 'error' => false
+ 'error' => false // will be set to TRUE when the page doesn't exist or is deactivated
)
?>

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -563,20 +563,44 @@ protected function generateMenu($links, $menuTag = false,$breakAfter = false) {
// ----------------------------
$menuStartTag = '';
$menuEndTag = '';
- $menuTagSet = false;
+ $pureTag = false;
// -> CREATEs the MENU-TAG (START and END-TAG)
if($menuTag) { // || !empty($menuAttributes) <- not used because there is no menuTag property, the tag is only set when a $menuTag parameter is given
- $menuAttributes = $this->createAttributes($this->menuId, $this->menuClass, $this->menuAttributes);
+ // $menuAttributes = $this->createAttributes($this->menuId, $this->menuClass, $this->menuAttributes);
+
+ // get the pure tag
+ if(is_string($menuTag)) {
+
+ // remove "
+ $menuTag = str_replace('"', '', $menuTag);
+ $pureTag = strtolower(preg_replace('#([\.|\#|\>|\[|\{|\+|\<].*)#i', '', $menuTag));
- // set tag
- if(is_string($menuTag)) $menuTagSet = strtolower($menuTag);
// or uses standard tag
- else $menuTagSet = 'div';
-
- $menuStartTag = "\n<".$menuTagSet.$menuAttributes.'>'."\n";
- $menuEndTag = "</".$menuTagSet.'>'."\n\n";
+ } else {
+ $pureTag = 'div';
+ $menuTag = 'div';
+ }
+
+ // add menuClass property to the zencode string
+ if(is_string($this->menuClass))
+ $menuTag = substr_replace($menuTag, '.'.$this->menuClass, strpos($menuTag, '.'), 0);
+ // add menuId property to the zencode string
+ if(strpos($menuTag, '#') === false && is_string($this->menuId))
+ $menuTag = str_replace($pureTag, $pureTag.'#'.$this->menuId, $menuTag);
+ // add Attributes
+ if(is_string($this->menuAttributes))
+ $menuTag .= '['.str_replace(array('"',' '), array('',']['), $this->menuAttributes).']';
+
+ // generate tag with id, classes and attributes
+ $menuTag = ZenPHP::expand($menuTag);
+
+ // remove end tag
+ $menuTag = str_replace('</'.$pureTag.'>', '', $menuTag);
+
+ $menuStartTag = "\n".$menuTag;
+ $menuEndTag = "</".$pureTag.'>'."\n\n";
}
// --------------------------------------
@@ -597,7 +621,7 @@ protected function generateMenu($links, $menuTag = false,$breakAfter = false) {
$menuItemCopy = $menuItem;
// creating the START TR tag
- if($menuTagSet == 'table') {
+ if($pureTag == 'table') {
$menuItemCopy['menuItem'] = "<tbody><tr>\n";
$menuItemCopy['item'] = "<tbody><tr>\n";
$menuItemCopy['startTag'] = "<tbody><tr>\n";
@@ -612,7 +636,7 @@ protected function generateMenu($links, $menuTag = false,$breakAfter = false) {
foreach($links as $link) {
// breaks the CELLs with TR after the given NUMBER of CELLS
- if($menuTagSet == 'table' &&
+ if($pureTag == 'table' &&
is_numeric($breakAfter) &&
($breakAfter + 1) == $countCells) {
$menuItemCopy['menuItem'] = "\n</tr><tr>\n";
@@ -627,14 +651,14 @@ protected function generateMenu($links, $menuTag = false,$breakAfter = false) {
$menuItemCopy = $menuItem;
// if menuTag is a LIST ------
- if($menuTagSet == 'menu' || $menuTagSet == 'ul' || $menuTagSet == 'ol') {
+ if($pureTag == 'menu' || $pureTag == 'ul' || $pureTag == 'ol') {
$menuItemCopy['menuItem'] = '<li>'.$link['link']."</li>\n";
$menuItemCopy['item'] = '<li>'.$link['link']."</li>\n";
$menuItemCopy['startTag'] = '<li>';
$menuItemCopy['endTag'] = "</li>\n";
// if menuTag is a TABLE -----
- } elseif($menuTagSet == 'table') {
+ } elseif($pureTag == 'table') {
$menuItemCopy['menuItem'] = "<td>\n".$link['link']."\n</td>";
$menuItemCopy['item'] = "<td>\n".$link['link']."\n</td>";
$menuItemCopy['startTag'] = "<td>\n";
@@ -688,7 +712,7 @@ protected function generateMenu($links, $menuTag = false,$breakAfter = false) {
}
// fills in the missing TABLE CELLs
- while($menuTagSet == 'table' &&
+ while($pureTag == 'table' &&
is_numeric($breakAfter) &&
$breakAfter >= $countCells) {
$menuItemCopy['menuItem'] = "\n<td></td>\n";
@@ -703,7 +727,7 @@ protected function generateMenu($links, $menuTag = false,$breakAfter = false) {
$menuItemCopy = $menuItem;
// creating the END TR tag
- if($menuTagSet == 'table') {
+ if($pureTag == 'table') {
$menuItemCopy['menuItem'] = "</tr></tbody>\n";
$menuItemCopy['item'] = "</tr></tbody>\n";
$menuItemCopy['endTag'] = "</tr></tbody>\n";
@@ -836,27 +860,29 @@ protected function generatePage($page, $showErrors = true, $shortenText = false,
$return['content'] = '<span style="font-size:15px;">'.$this->languageFile['ADMINSETUP_ERROR_PHPVERSION'].' '.REQUIREDPHPVERSION.'</span>'; // if not throw error and and the method
return $return;
}
-
- // LOOKS FOR A GIVEN PAGE, IF NOT STOP THE METHOD
- if(!is_numeric($page) && !is_array($page))
- return array();
// -> sets the ERROR SETTINGS
// ----------------------------
if($showErrors) {
// adds ATTRIBUTES
$errorStartTag = '';
$errorEndTag = '';
- $errorAttributes = $this->createAttributes($this->errorId, $this->errorClass, $this->errorAttributes);
+ // $errorAttributes = $this->createAttributes($this->errorId, $this->errorClass, $this->errorAttributes);
- if(is_string($this->errorTag)) { //|| !empty($errorAttributes)
- // set tag
- $errorTag = $this->errorTag;
- // or uses standard tag
- //else $errorTag = 'span';
+ if(is_string($this->errorTag)) {
+
+ // remove "
+ $errorTag = str_replace('"', '', $this->errorTag);
+ $pureErrorTag = strtolower(preg_replace('#([\.|\#|\>|\[|\{|\+|\<].*)#i', '', $errorTag));
+
+ // generate tag with id, classes and attributes
+ $errorTag = ZenPHP::expand($errorTag);
+
+ // remove end tag
+ $errorTag = str_replace('</'.$pureErrorTag.'>', '', $errorTag);
- $errorStartTag = '<'.$errorTag.$errorAttributes.'>';
- $errorEndTag = '</'.$errorTag.'>';
+ $errorStartTag = $errorTag;
+ $errorEndTag = '</'.$pureErrorTag.'>';
}
}
@@ -874,19 +900,19 @@ protected function generatePage($page, $showErrors = true, $shortenText = false,
// if could not load throw ERROR
if($showErrors) {
$return['content'] = $errorStartTag.$this->languageFile['PAGE_ERROR_NOPAGE'].$errorEndTag; // if not throw error and and the method
- return $return;
- } else
- return array();
+ }
+
+ return $return;
}
}
-
+
// -> PAGE is PUBLIC? if not throw ERROR
if(!$pageContent['public'] || GeneralFunctions::isPublicCategory($pageContent['category']) === false) {
if($showErrors) {
$return['content'] = $errorStartTag.$this->languageFile['PAGE_ERROR_PAGENOTPUBLIC'].$errorEndTag; // if not throw error and and the method
- return $return;
- } else
- return array();
+ }
+
+ return $return;
}
// -> START to BUILD THE PAGE CONTENT
@@ -24,7 +24,7 @@
// $startTime = $timer[1] + $timer[0];
// set error reporting
-error_reporting(E_ALL & ~E_NOTICE);// E_ALL ^ E_NOTICE ^ E_WARNING
+error_reporting(E_ALL & ~E_NOTICE);// E_ALL ^ E_NOTICE ^ E_WARNING // ~E_NOTICE
/**
* set mb_ functions encoding
@@ -54,7 +54,11 @@ function __autoload($class_name) {
$class_name == 'Search' ||
$class_name == 'FeinduraBase' ||
$class_name == 'Feindura')
- require_once(dirname(__FILE__)."/../classes/".$class_name.".class.php");
+ require_once(dirname(__FILE__)."/../classes/".$class_name.".class.php");
+
+ if($class_name == 'ZenPHP')
+ require_once(dirname(__FILE__)."/../thirdparty/ZenPHP/".$class_name.".php");
+
return true;
}
@@ -0,0 +1,104 @@
+<?php
+
+class Element {
+
+ private $tagName;
+ private $attrs = array();
+ private $parent = null;
+ private $children = array();
+ private $isEmptyTag = false;
+
+
+ private $tabString = " ";
+
+ function __construct($tagName, $parent = null, $isEmptyTag = false) {
+ $this->tagName = $tagName;
+ $this->isEmptyTag = $isEmptyTag;
+ if ($parent instanceof Element)
+ $this->parent = $parent;
+ }
+
+ function addChild(Element $child) {
+ $this->children[] = $child;
+ $child->setParent($this);
+ }
+
+ function getTabString($count) {
+ if ($count > 0)
+ return str_repeat($this->tabString, $count);
+ return '';
+ }
+
+
+ function parse($tabCount = 0) {
+ $tabs = $this->getTabString($tabCount);
+ $attrStr = $this->parseAttrs();
+ $lTag = '<' . $this->tagName . $attrStr;
+ if ($this->isEmptyTag) {
+ $lTag .= " />\n";
+ return $tabs . $lTag;
+ } else
+ $lTag .= ">";
+
+ $content = '';
+ if (!empty($this->children)) {
+ foreach ($this->children as $child) {
+ $content .= $child->parse($tabCount + 1);
+ }
+ $content .= $tabs;
+ }
+ if (!empty($content))
+ $lTag .= "\n";
+
+ $rTag = '</' . $this->tagName . '>';
+
+ return $tabs . $lTag . $content . $rTag . "\n";
+ }
+
+ protected function parseAttrs() {
+ if (empty($this->attrs))
+ return '';
+ $attrs = array();
+ foreach ( $this->attrs as $attr => $value ) {
+ $attrs[] = $attr . '="' . $value . '"';
+ }
+ return ' ' . implode(' ', $attrs);
+ }
+
+ function attr($name, $value) {
+ $this->attrs[$name] = $value;
+ }
+
+ public function getTagName() {
+ return $this->tagName;
+ }
+
+ public function getAttrs() {
+ return $this->attrs;
+ }
+
+ public function getParent() {
+ return $this->parent;
+ }
+
+ public function getChildren() {
+ return $this->children;
+ }
+
+ public function setTagName($tagName) {
+ $this->tagName = $tagName;
+ }
+
+ public function setAttrs($attrs) {
+ $this->attrs = $attrs;
+ }
+
+ public function setParent($parent) {
+ $this->parent = $parent;
+ }
+
+ public function setChildren($children) {
+ $this->children = $children;
+ }
+
+}
@@ -0,0 +1,14 @@
+<?php
+require_once(dirname(__FILE__) . '/Element.php');
+class RootElement extends Element {
+
+ function __construct(){}
+
+ function parse($tabCount = 0) {
+ $content = '';
+ foreach ($this->getChildren() as $child) {
+ $content .= $child->parse($tabCount);
+ }
+ return $content;
+ }
+}
@@ -0,0 +1,24 @@
+<?php
+require_once(dirname(__FILE__) . '/Element.php');
+class TextElement extends Element {
+
+ private $content;
+
+ function __construct($content, $parent = null) {
+ $this->setParent($parent);
+ $this->content = $content;
+ }
+
+ function addChild($child){
+ if ($this->getParent() != null)
+ $this->getParent()->addChild($child);
+ }
+
+ function parse($tabCount = 0) {
+ $tabs = $this->getTabString($tabCount);
+ return $tabs . implode("\n" . $tabs, explode("\n", $this->content)) . "\n";
+ }
+
+}
+
+
Oops, something went wrong.

0 comments on commit 9072594

Please sign in to comment.