/** * Callback function for the designer fix preg_replace_callback * Automatically adjusts paths if they have .. in them * * @access private * @final * @param array $match An array of the found items from the regular expression * @return string */ private final function _designerFixCallback($match) { // if this isn't empty then it is a link $link = !empty($match[2]); // get the tag $tag = $match[1]; // set the default to return the full string that was matched $return = $match[0]; $custom = false; // do the replacement switch ($tag) { case "[current]": $return = Reg::get("Path.current"); break; case "[site]": $return = Reg::get("Path.site"); break; case "[skin]": $return = Reg::get("Path.skin"); break; case "[root]": $return = Reg::get("Path.root"); break; case "[branch.site]": $return = Reg::get("Path.branch"); break; case "[branch.skin]": $return = Reg::get("Path.branchSkin"); break; case "[branch.root]": $return = Reg::get("Path.branchRoot"); break; default: // see if it is a php variable. Quick way to echo variables from $this if (strpos($tag, '$') === 1) { $custom = true; $var = str_replace(array('[', ']', '$', 'this->'), '', $tag); // if it is in an object then we need to go down the objects pulling out the variables // not pretty if (strpos($var, '->') !== false) { $parts = explode('->', $var); $failed = false; $var = $this->{array_shift($parts)}; foreach ($parts as $part) { if (!isset($var->{$part})) { // variable isn't set so it failed $failed = true; break; } $var = $var->{$part}; } if ($failed === false) { $return = $var; } } else { // it is a variable that isn't an object if (isset($this->{$var})) { $return = $this->{$var}; } } // the variable didn't exist so send nothing back to the page // don't want variable names to sneak in if ($return == $tag) { $return = ''; } } else { if (Reg::has(str_replace(array('[', ']'), '', $tag))) { $custom = true; // get the variable from the registry $return = Reg::get(str_replace(array('[', ']'), '', $tag)); } else { // look for the tag within the working URI $working_uri = Reg::get("URI.working"); if (Reg::hasVal("Branch.name")) { $working_uri = array_merge(array("branch" => Reg::get("Branch.name")), $working_uri); } foreach ($working_uri as $key => $item) { $tmp_key = "[" . $key . "]"; if ($tag == $tmp_key && Reg::has('Path.' . $key)) { $return = Reg::get('Path.' . $key); break 1; } } } } break; } // if it is a link then we need to do some more processing if ($link === true && $custom === false) { // remove any ../ from the url so that they are clean $link_arr = explode("/", $match[2]); $up_link_count = count(array_keys(array_slice($link_arr, 1), "..")); $return = explode('/', $return); $return = implode("/", $up_link_count ? array_slice($return, 0, -1 * $up_link_count) : $return) . implode("/", array_pad(array_slice($link_arr, $up_link_count + 1), -(count(array_slice($link_arr, $up_link_count + 1)) + 1), "")); // if mod_rewrite isn't being used then need to make sure the URL is valid by turning any extra ? into & if (Reg::get("URI.useModRewrite") != true && !empty($return)) { if (substr_count($return, "?", 0) > 1) { $return = strrev(preg_replace("/\\?/i", "&", strrev($return), substr_count($return, "?", 0) - 1)); } } } else { if (!empty($match[2])) { $return .= $match[2]; } } // call hook Hook::call('Controller.designerFixCallback', array(&$match, &$return)); return $return; }