Skip to content

Commit

Permalink
Add some url-variables
Browse files Browse the repository at this point in the history
  • Loading branch information
Themroc committed Jan 16, 2022
1 parent bd92590 commit 2183ea0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
19 changes: 12 additions & 7 deletions models/AdminForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'/';
Expand All @@ -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(
Expand All @@ -83,7 +88,7 @@ public function deleteButton($model)
: "";
}

public function sizeModes()
public function sizeModes ()
{
return [
0=> Yii::t('IframeModule.base', 'Box'),
Expand Down
19 changes: 19 additions & 0 deletions views/index/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2183ea0

Please sign in to comment.