summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 491d549)
raw | patch | inline | side by side (parent: 491d549)
author | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 12 Mar 2010 09:46:56 +0000 (09:46 +0000) | ||
committer | hickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 12 Mar 2010 09:46:56 +0000 (09:46 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@16481 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-core/include/class_userFilterEditor.inc | patch | blob | history |
diff --git a/gosa-core/include/class_userFilterEditor.inc b/gosa-core/include/class_userFilterEditor.inc
index a6d4048e90008b9b959d9c3519d9cf78da9d5967..1ac98ae956e53cadc46b1a21426c1bc991653c32 100644 (file)
$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']);
}
+ /*! \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)