mirror of
https://github.com/humhub/humhub.git
synced 2025-03-02 22:19:18 +01:00
Improved user url rule
This commit is contained in:
parent
48590467c3
commit
2bb4db6ba1
@ -59,7 +59,6 @@ class SettingController extends Controller
|
||||
{
|
||||
$form = new \humhub\modules\admin\models\forms\BasicSettingsForm();
|
||||
if ($form->load(Yii::$app->request->post()) && $form->validate() && $form->save()) {
|
||||
// set flash message
|
||||
Yii::$app->getSession()->setFlash('data-saved', Yii::t('AdminModule.controllers_SettingController', 'Saved'));
|
||||
return $this->redirect(['/admin/setting/basic']);
|
||||
}
|
||||
|
@ -20,6 +20,11 @@ use humhub\modules\user\models\User;
|
||||
class UrlRule extends Object implements UrlRuleInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array cache map with user guid/username pairs
|
||||
*/
|
||||
protected static $userUrlMap = [];
|
||||
|
||||
/**
|
||||
* @var string default route to space home
|
||||
*/
|
||||
@ -31,15 +36,15 @@ class UrlRule extends Object implements UrlRuleInterface
|
||||
public function createUrl($manager, $route, $params)
|
||||
{
|
||||
if (isset($params['uguid'])) {
|
||||
$user = User::find()->where(['guid' => $params['uguid']])->one();
|
||||
if ($user !== null) {
|
||||
$username = static::getUrlByUserGuid($params['uguid']);
|
||||
if ($username !== null) {
|
||||
unset($params['uguid']);
|
||||
|
||||
if ($this->defaultRoute == $route) {
|
||||
$route = "";
|
||||
}
|
||||
|
||||
$url = "u/" . urlencode(strtolower($user->username)) . "/" . $route;
|
||||
$url = "u/" . urlencode(strtolower($username)) . "/" . $route;
|
||||
if (!empty($params) && ($query = http_build_query($params)) !== '') {
|
||||
$url .= '?' . $query;
|
||||
}
|
||||
@ -73,4 +78,25 @@ class UrlRule extends Object implements UrlRuleInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets usernameby given guid
|
||||
*
|
||||
* @param string $guid
|
||||
* @return string|null the username
|
||||
*/
|
||||
public static function getUrlByUserGuid($guid)
|
||||
{
|
||||
if (isset(static::$userUrlMap[$guid])) {
|
||||
return static::$userUrlMap[$guid];
|
||||
}
|
||||
|
||||
$user = User::findOne(['guid' => $guid]);
|
||||
if ($user !== null) {
|
||||
static::$userUrlMap[$user->guid] = $user->username;
|
||||
return static::$userUrlMap[$user->guid];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user