From: <rob...@us...> - 2011-10-18 14:39:17
|
Revision: 38357 http://tikiwiki.svn.sourceforge.net/tikiwiki/?rev=38357&view=rev Author: robertplummer Date: 2011-10-18 14:39:11 +0000 (Tue, 18 Oct 2011) Log Message: ----------- [NEW] Added flatten as a method Modified Paths: -------------- trunk/lib/core/TikiFilter/PrepareInput.php Modified: trunk/lib/core/TikiFilter/PrepareInput.php =================================================================== --- trunk/lib/core/TikiFilter/PrepareInput.php 2011-10-18 14:24:35 UTC (rev 38356) +++ trunk/lib/core/TikiFilter/PrepareInput.php 2011-10-18 14:39:11 UTC (rev 38357) @@ -46,5 +46,24 @@ return $output; } + + function flatten(array $input) + { + function flattenValues($values, &$newValues = array(),$prefix = '', $delimiter = '_') { + + foreach ($values as $key => $value) { + if (is_array($value)) { + $newPrefix = $prefix.$key.$delimiter; + $newValues =& flattenValues($value, $newValues ,$newPrefix, $delimiter); + } else { + $newValues[$prefix.$key] = $value; + } + } + + return $newValues; + } + + return flattenValues($input); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rob...@us...> - 2011-10-28 18:57:54
|
Revision: 38536 http://tikiwiki.svn.sourceforge.net/tikiwiki/?rev=38536&view=rev Author: robertplummer Date: 2011-10-28 18:57:48 +0000 (Fri, 28 Oct 2011) Log Message: ----------- [FIX] Removed recursive call, no need Modified Paths: -------------- trunk/lib/core/TikiFilter/PrepareInput.php Modified: trunk/lib/core/TikiFilter/PrepareInput.php =================================================================== --- trunk/lib/core/TikiFilter/PrepareInput.php 2011-10-28 16:35:08 UTC (rev 38535) +++ trunk/lib/core/TikiFilter/PrepareInput.php 2011-10-28 18:57:48 UTC (rev 38536) @@ -47,23 +47,17 @@ return $output; } - function flatten(array $input) - { - function flattenValues($values, &$newValues = array(),$prefix = '', $delimiter = '_') { - - foreach ($values as $key => $value) { - if (is_array($value)) { - $newPrefix = $prefix.$key.$delimiter; - $newValues =& flattenValues($value, $newValues ,$newPrefix, $delimiter); - } else { - $newValues[$prefix.$key] = $value; - } + function flatten($values, &$newValues = array(), $prefix = '', $delimiter = '_') { + foreach ($values as $key => $value) { + if (is_array($value)) { + $newPrefix = $prefix.$key.$delimiter; + $newValues =& $this->flatten($value, $newValues ,$newPrefix, $delimiter); + } else { + $newValues[$prefix.$key] = $value; } - - return $newValues; } - return flattenValues($input); + return $newValues; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rob...@us...> - 2011-10-28 19:06:14
|
Revision: 38537 http://tikiwiki.svn.sourceforge.net/tikiwiki/?rev=38537&view=rev Author: robertplummer Date: 2011-10-28 19:06:08 +0000 (Fri, 28 Oct 2011) Log Message: ----------- [FIX] Removed from method and changed $delimiter to $this->delimiter Modified Paths: -------------- trunk/lib/core/TikiFilter/PrepareInput.php Modified: trunk/lib/core/TikiFilter/PrepareInput.php =================================================================== --- trunk/lib/core/TikiFilter/PrepareInput.php 2011-10-28 18:57:48 UTC (rev 38536) +++ trunk/lib/core/TikiFilter/PrepareInput.php 2011-10-28 19:06:08 UTC (rev 38537) @@ -47,11 +47,11 @@ return $output; } - function flatten($values, &$newValues = array(), $prefix = '', $delimiter = '_') { + function flatten($values, &$newValues = array(), $prefix = '') { foreach ($values as $key => $value) { if (is_array($value)) { - $newPrefix = $prefix.$key.$delimiter; - $newValues =& $this->flatten($value, $newValues ,$newPrefix, $delimiter); + $newPrefix = $prefix.$key.$this->delimiter; + $newValues =& $this->flatten($value, $newValues ,$newPrefix, $this->delimiter); } else { $newValues[$prefix.$key] = $value; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rob...@us...> - 2012-05-24 19:03:39
|
Revision: 41559 http://tikiwiki.svn.sourceforge.net/tikiwiki/?rev=41559&view=rev Author: robertplummer Date: 2012-05-24 19:03:32 +0000 (Thu, 24 May 2012) Log Message: ----------- [NEW] Add methods to go to and from string directly and then prepair Modified Paths: -------------- trunk/lib/core/TikiFilter/PrepareInput.php Modified: trunk/lib/core/TikiFilter/PrepareInput.php =================================================================== --- trunk/lib/core/TikiFilter/PrepareInput.php 2012-05-24 19:02:27 UTC (rev 41558) +++ trunk/lib/core/TikiFilter/PrepareInput.php 2012-05-24 19:03:32 UTC (rev 41559) @@ -50,9 +50,10 @@ function flatten($values, &$newValues = array(), $prefix = '') { foreach ($values as $key => $value) { - if (is_array($value)) { + if (is_array($value) || is_object($value)) { $newPrefix = $prefix.$key.$this->delimiter; - $newValues =& $this->flatten($value, $newValues, $newPrefix, $this->delimiter); + $newValue = $this->flatten($value, $newValues, $newPrefix, $this->delimiter); + $newValues =& $newValue; } else { $newValues[$prefix.$key] = $value; } @@ -60,5 +61,35 @@ return $newValues; } + + function toString($values, &$newValues = array(), $prefex = '') + { + $flatArray = self::flatten($values, $newValues, $prefex); + + $output = ''; + + foreach($flatArray as $key => $value) + { + $output .= urlencode($key) . ':' . urlencode($value) . "\n"; + } + + return $output; + } + + function prepareFromString($input = '') + { + $stringArray = explode("\n", $input); + + $flatArray = array(); + + foreach($stringArray as $string) { + $string = explode(":", $string); + if (isset($string[0], $string[1])) { + $flatArray[urldecode($string[0])] = urldecode($string[1]); + } + } + + return self::prepare($flatArray); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |