From 2183ea04f11f6f8fe696e84782c3a9bccc72687f Mon Sep 17 00:00:00 2001 From: Themroc <7hemroc@gmail.com> Date: Sun, 16 Jan 2022 22:26:57 +0100 Subject: [PATCH] Add some url-variables --- models/AdminForm.php | 19 ++++++++++++------- views/index/index.php | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/models/AdminForm.php b/models/AdminForm.php index c4062ca..d3c4e09 100644 --- a/models/AdminForm.php +++ b/models/AdminForm.php @@ -35,26 +35,31 @@ class AdminForm extends \themroc\humhub\modules\modhelper\models\AdminForm ], 'size'=> [ 'rules'=> ['in', 'range'=> [0, 1]], - 'form'=> ['type'=> 'radio', 'items'=> [self::class, 'sizeModes']], + 'form'=> [ + 'type'=> 'radio', + 'items'=> [self::class, 'sizeModes'] + ], ], 'url'=> [ 'label'=> 'Page URL', - 'hints'=> 'The webpage to be shown', + 'hints'=> 'The webpage to be shown. @UID@, @USER@ and @EMAIL@ will be replaced by the respective values.', ], 'url_reg'=> [ 'label'=> 'Page URL for registered users', - 'hints'=> 'If empty, the above will be used', + 'hints'=> 'If empty, the above will be used.', ], ]; protected $mod= [ - 'form'=> ['btn_post'=> [self::class, 'deleteButton']], + 'form'=> [ + 'btn_post'=> [self::class, 'deleteButton'] + ], ]; /** * @inheritdoc */ - public function save() + public function save () { $frame= strtolower($this->label); $this->mod['prefix']= $frame.'/'; @@ -73,7 +78,7 @@ public function save() return $this->loadSettings(); } - public function deleteButton($model) + public function deleteButton ($model) { return strlen($model->label) ? "\t\t\t".Html::a( @@ -83,7 +88,7 @@ public function deleteButton($model) : ""; } - public function sizeModes() + public function sizeModes () { return [ 0=> Yii::t('IframeModule.base', 'Box'), diff --git a/views/index/index.php b/views/index/index.php index d097142..f5ef2e1 100644 --- a/views/index/index.php +++ b/views/index/index.php @@ -9,6 +9,25 @@ $url= $mod->getSetting('url_reg', $frame); if (empty($url) || Yii::$app->user->isGuest) $url= $mod->getSetting('url', $frame); +if (Yii::$app->user->isGuest) { + $uid= 0; + $user= 'Guest-'.rand(10000000, 99999999); + $email= ''; +} else { + $uid= Yii::$app->user->id; + $user= Yii::$app->user->getIdentity()->__get('username'); + $email= Yii::$app->user->getIdentity()->__get('email'); +} +$ustr= $user.$email.$uid; +$color= ''; +for ($x=0; $x<6; $x++) { + $c= ord(substr($ustr, $x, 1)); + $color.= dechex($c & 0x0f); +} +$url= str_replace('@UID@', $uid, $url); +$url= str_replace('@USER@', urlencode($user), $url); +$url= str_replace('@EMAIL@', urlencode($email), $url); +$url= str_replace('@COLOR@', $color, $url); $js= []; foreach ($mod->getFrames() as $f)