Changeset 20509
- Timestamp:
- 07/26/09 23:30:50 (4 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfTabMenuPeytzPlugin/lib/sfTabMenuPeytz.class.php
r20508 r20509 45 45 'security' => array( 46 46 'is_secure' => false, 47 'credentials' => array() 48 /* 49 This is run before anything else, and will determaine if the user got access to this, if u set a permission the 50 is_secure it not needed since the user will be check for authenticated before checking for is_secure. 51 */ 47 'credentials' => array(), 52 48 ), 53 'matches' => array( //Must match one of these 54 'module/action?get=asdad&get=sadasd', 55 /* 56 Written in the same syntax as routes, if a parameter has a value specified, that value will be check 57 else it will just verify that the parameter is availible by sfWebRequest. 58 This makes a tab able to match different things. the match with highest score for that tab 59 will be used in the overall score matching. 60 */ 61 ), 49 'matches' => array(), 62 50 'match' => array( 63 51 'module' => null, … … 163 151 //Render the active tab 164 152 $this->renderTab($this->_ActiveTabIndex, true); 165 166 //Now we have the items renderer lets find the active one, if none found the $default wins167 168 153 169 154 //Render the ul and decorator … … 177 162 178 163 /** 164 * Handles parsing of our Route like matchings 165 * 166 * @param string $match 167 * @return array 168 */ 169 private function parseMatch($match) 170 { 171 $parseArray = array( 172 'module' => null, 173 'action' => null, 174 'parameters' => array(), 175 ); 176 177 $parse = parse_url($match); 178 $query = array(); 179 if (isset($parse['query'])) { 180 parse_str($parse['query'], $parseArray['parameters']); 181 } 182 183 $moduleAction = array_filter(explode('/', $parse['path'])); 184 if (isset($moduleAction[0])) { 185 $parseArray['module'] = $moduleAction[0]; 186 187 $parseArray['action'] = 'index'; 188 if (isset($moduleAction[1])) { 189 $parseArray['action'] = $moduleAction[1]; 190 } 191 } 192 193 return $parseArray; 194 } 195 196 /** 179 197 * Calculates the scores 180 198 */ … … 196 214 $scores[$key] = 0; 197 215 $tab = self::merge($this->_DefaultTabConfig, $tab); 198 $match = $tab['match'];216 $matches = $tab['matches']; 199 217 200 //Lets make score 201 $modules = is_array($match['module']) ? $match['module'] : array($match['module']); 202 $actions = is_array($match['action']) ? $match['action'] : array($match['action']); 203 204 if (in_array($module, $modules)) { 205 $scores[$key]++; 218 foreach ($matches as $match) { 219 $score = 0; 220 $match = $this->parseMatch($match);; 206 221 207 if ( in_array($action, $actions)) {208 $score s[$key]++;222 if ($module == $match['module']) { 223 $score++; 209 224 210 foreach ($match['params'] as $param) { 211 if (isset($parameters[$param])) { 212 $scores[$key]++; 225 if ($action == $match['action']) { 226 $score++; 227 228 foreach ($match['parameters'] as $name => $value) { 229 if (!empty($value)) { 230 if ($request->getParameter($name) == $value) { 231 $score++; 232 } elseif ($request->hasParameter($name)) { 233 $score++; 234 } 235 } 213 236 } 214 237 } 238 } 239 240 if ($score > $scores[$key]) { 241 $scores[$key] = $score; 215 242 } 216 243 }