From: hickert Date: Fri, 12 Mar 2010 09:46:56 +0000 (+0000) Subject: Added filter indentation X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=789fee51ff7c1128136683023bd7904981957418;p=gosa.git Added filter indentation git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@16481 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-core/include/class_userFilterEditor.inc b/gosa-core/include/class_userFilterEditor.inc index a6d4048e9..1ac98ae95 100644 --- a/gosa-core/include/class_userFilterEditor.inc +++ b/gosa-core/include/class_userFilterEditor.inc @@ -35,7 +35,7 @@ class userFilterEditor extends plugin $this->parent = $entry['parent']; $this->name = $entry['name']; $this->description = $entry['description']; - $this->filter = $entry['filter']; + $this->filter = userFilterEditor::_autoIndentFilter($entry['filter'], "\t"); $this->selectedCategories = $entry['categories']; $this->share = in_array("share",$entry['flags']); $this->enable = in_array("enable",$entry['flags']); @@ -44,6 +44,49 @@ class userFilterEditor extends plugin } + /*! \brief Automatic indent indentation for filters. + */ + static function _autoIndentFilter($str, $indent = " ") + { + // Remove line breaks and escaped brackets + $str = preg_replace('/[\t ]*\n[\t ]*/', "", $str); + $str = preg_replace('/\\\\\\(/', "::OPEN::", $str); + $str = preg_replace('/\\\\\\)/', "::CLOSE::", $str); + + // Add a line break infront of every bracket + $str = preg_replace('/\\(/', "\n(", $str); + $str = preg_replace('/\\)/', ")\n", $str); + + // Split by linebreaks + $lines = preg_split("/\n/", $str); + $str = ""; + $i = 0; + + // Walk trough search blocks + foreach($lines as $line){ + $line = trim($line); + if(empty($line)) continue; + + // Go back one level in indentation + if(!preg_match("/\\(.*\\)/", $line) && preg_match('/\\)$/', $line)){ + $i --; + } + + $str.= "\n"; + $str = str_pad($str,strlen($str)+$i, $indent); + $str.= $line; + + // Go one level deeper in indentation + if(!preg_match("/\\(.*\\)/", $line) && preg_match('/^\\(/', $line)){ + $i ++; + } + } + $str = preg_replace('/::OPEN::/', "(", $str); + $str = preg_replace('/::CLOSE::/', ")", $str); + return($str); + } + + /*! \brief Retunrs the filters original name * @param The original name of the filter (if none was given * an empty string is returned)