/** * returns relative URI path or matching mask array * * @since 3.4 * @param mixed $mask array or string of path keys * @return mixed if mask was provided returns an array mathching path values to keys or empty, else returns string of path */ function getURIPath($inputmask = null, $pad = false) { $relativeURI = no_tsl(getRelRequestURI()); $URIpathAry = explode('/', no_tsl($relativeURI)); if (gettype($inputmask) == 'string') { $inputmask = explode('/', $inputmask); } if ($inputmask) { // assigning path vars to key mask $maskCnt = count($inputmask); $URIcnt = count($URIpathAry); $mask = array_combine($inputmask, array_fill(0, $maskCnt, '')); # flip array with empty values so padding has indices to work with if ($maskCnt == $URIcnt) { // mask count matches path count $mask = array_combine(array_keys($mask), $URIpathAry); return $mask; } else { if ($URIcnt > $maskCnt && in_array('%path%', $inputmask)) { // mask contains %path% token // so splice it out of the path and implode it back in $start = array_search('%path%', $mask); $length = $URIcnt - $maskCnt + 1; $URIpathAry = spliceCompressArray($URIpathAry, $start, $length); $URIpathAry[$start] = implode('/', $URIpathAry[$start]); // debugLog($URIpathAry); // debugLog($mask); $mask = array_combine(array_keys($mask), $URIpathAry); return $mask; } else { if ($URIcnt > $maskCnt && $pad) { // path is larger than mask, overload if pad // @todo splice left OR splice right option // using pad right for now $mask = array_pad($mask, count($URIpathAry), ''); $mask = array_combine(array_keys($mask), $URIpathAry); return $mask; } else { // Mask is larger than URI, return relativeurl as single elem array return array($relativeURI); } } } } else { // no mask specificed so simple str return return $relativeURI; } }
function pageCacheAddRoutes($id, &$cacheItems) { global $pagesArray; if (!$pagesArray) { return false; } // add route $routesNode = $cacheItems->addChild('routes'); $routeNode = $routesNode->addChild('route'); // can lead to infinite loops $permaroute = no_tsl(generate_permalink($id)); $pathNode = $routeNode->addChild('path'); $pathNode->addCData($permaroute); $keyNode = $routeNode->addChild('key'); $keyNode->addCData(md5($permaroute)); }