------------------------------------------------------------
revno: 1211
committer: Roger Martin <[email protected]>
branch nick: aikiframework
timestamp: Wed 2012-07-04 21:41:04 +0200
message:
adding normalize function
modified:
libs/config.php
--
lp:aikiframework
https://code.launchpad.net/~aikiframework-devel/aikiframework/trunk
Your team Aiki Framework Developers is subscribed to branch lp:aikiframework.
To unsubscribe from this branch go to
https://code.launchpad.net/~aikiframework-devel/aikiframework/trunk/+edit-subscription
=== modified file 'libs/config.php'
--- libs/config.php 2012-05-07 11:48:22 +0000
+++ libs/config.php 2012-07-04 19:41:04 +0000
@@ -22,7 +22,7 @@
if (!defined('IN_AIKI')) {
die('No direct script access allowed');
-}
+}
/**
@@ -64,7 +64,6 @@
date_default_timezone_set( @date_default_timezone_get());
}
}
-
}
@@ -216,12 +215,12 @@
// if any value is valid only seek first.
// note: apps that don't have site/view/language use this way.
- if ($selector=="*" || $selector=="*/*/*") {
+ if ( $selector=="*" || $selector=="*/*/*" ){
$value = $db->get_var($sql);
- if (is_null($value)) {
+ if ( is_null($value) ) {
return $default;
}
- $ret = $this->_unserialize($value);
+ $ret= $this->_unserialize($value);
$config[$setting]= $ret;
return $ret;
}
@@ -348,6 +347,58 @@
}
+ /**
+ * normalize selector adding the view and languages selector if it is
+ * necesary
+ *
+ * @param string $selector
+ * @return mixed normalized selector as string or false (boolean) if contains
+ * more than 3 values.
+ * @example "site/foo" => site/foo/*
+ *
+ */
+
+ function normalize( $selector ){
+ switch ( substr_count( $selector, "/") ) {
+ case 0 : return $selector.= "/*/*";
+ case 1 : return $selector.= "/*";
+ case 2 : return $selector;
+ default: return false;
+ }
+ }
+
+
+ function get_sql_filter( $selector ){
+
+ $selector = config::normalize($selector);
+ if (!$selector) {
+ return NULL;
+ }
+ $match="";
+ $nomatch= array();
+ $matchRequired =false;
+ foreach ( explode("/", $selector) as $i=>$part ){
+ if ($part=="" || $part=="*"){
+ $match [] = "%" ;
+ } elseif ( $part[0]!="!" ) {
+ $match [] = $part ;
+ $matchRequired= true;
+ } else {
+ $match [] = "%";
+ $nomatch[] = substr_replace("%/%/%", substr($part,1),$i*2,1);
+ }
+ }
+ $ret = $matchRequired ? "config_selector LIKE '".implode($match,"/")."'" : "";
+
+ if ( count($nomatch) ){
+ $ret .= ($matchRequired ? " AND " : "" ) .
+ "(config_selector NOT LIKE '" .implode($nomatch, "' AND config_selector NOT LIKE '") . "')";
+ }
+ return $ret;
+
+ }
+
+
}
_______________________________________________
Mailing list: https://launchpad.net/~aikiframework-devel
Post to : [email protected]
Unsubscribe : https://launchpad.net/~aikiframework-devel
More help : https://help.launchpad.net/ListHelp