public function getURL($urlCode, $name = NULL, $value = NULL, $full = TRUE) { if (is_null($name)) { $name = array(); } elseif (!is_object($name) and !is_array($name)) { $name = array($name => $value); } list($urlId, $args) = _U_helper($urlCode, $name); if (!isset($this->_config[$urlId])) { throw new Exception("Unknown URL '" . $urlId . "'"); } $params = array(); foreach ($args as $k => $v) { $params["\${$k}"] = urlencode($v); } $url = str_replace(array_keys($params), array_values($params), $this->_config[$urlId][0]); if ($full && !strstr($url, '://')) { $domain = @$this->_config[$urlId][2] ? $this->_config[$urlId][2] : "www"; // (M('Tools')->web()->isHTTPS() ? "https://" : "http://") if (!@$this->_domains[$domain]) { $this->_domains[$domain] = $domain == '_current_' ? $_SERVER['HTTP_HOST'] : preg_replace(C("url.domain-regex"), $domain . '.$2', $_SERVER['HTTP_HOST']); } $url = $this->_domains[$domain] . "/" . $url; $url = $this->_getProtocol($urlId) . $url; } else { $url = '/' . $url; } return $url; }
function _U_helper($urlCode, $object) { $args = array(); $urlId = $urlCode; $class = is_object($object) ? get_class($object) : ''; switch ($class) { case '': if (is_array($object)) { foreach ($object as $id => $item) { if (is_object($item)) { list($k, $v) = _U_helper($urlCode, $item); $args = array_merge($args, $v); } else { $args[$id] = $item; } } } else { $args = $object; } break; case 'RM_List_Object': $args['report_id'] = $object->id(); break; case 'RM_Barcode_Object': $args['value'] = $object->value; break; case 'RM_User_Object': case 'RM_Account_Object': $args['login'] = $object->login; $args['type'] = 'user'; $args['id'] = $object->id(); $args['user_id'] = $object->id(); $urlId = _U_prefix($urlId, 'user'); break; case 'RM_ObjectFs_Dir': case 'RM_ObjectFs_File': $obOwner = $object->getFs()->getOwner(); if (!isNull($obOwner)) { if ($obOwner->guidType() == M('CombyUser')->getProfileGuidType()) { $args['owner_type'] = 'user'; } elseif ($obOwner->guidType() == M('CombyCommunity')->getCommunityGuidType()) { $args['owner_type'] = 'community'; } if (isset($args['owner_type'])) { $args['login'] = $obOwner->login; $urlId = _U_prefix($urlId, $args['owner_type']); } } break; case 'RM_Anketa_Entity_Object': $args['aid'] = $object->id(); break; case 'RM_Anketa_Entity_Question': $args['qid'] = $object->id(); break; case 'RM_Wizard_Object': $args['wizard_id'] = $object->id(); break; case 'RM_Wizard_Step': $args['step_id'] = $object->id(); break; } if ($object instanceof RM_Anketa_iRespondent) { $args['rid'] = $object->getRespondentId(); } if (is_object($object) && $object instanceof RM_Store_Object) { $args['id'] = $object->id(); if ($object instanceof RM_Guid_iObject && empty($args['guid_type'])) { $args['guid_type'] = $object->guidType(); } } return array($urlId, $args); }