-
Notifications
You must be signed in to change notification settings - Fork 4
/
VCardUser.php
59 lines (49 loc) · 1.56 KB
/
VCardUser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2018 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\popovervcard\widgets;
use humhub\components\Widget;
use humhub\modules\popovervcard\Module;
use humhub\modules\user\models\Profile;
use humhub\modules\user\models\ProfileField;
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use Twig\Extension\SandboxExtension;
use Twig\Loader\ArrayLoader;
use Twig\Sandbox\SecurityPolicy;
use Yii;
/**
* Class VCardUser
* @package humhub\modules\popovervcard\widgets
*/
class VCardUser extends Widget
{
public $user;
public function run()
{
/** @var Module $module */
$module = Yii::$app->getModule('popover-vcard');
$twig = new Environment(new ArrayLoader());
$twig->addExtension(new SandboxExtension(new SecurityPolicy(
['if', 'for'],
['escape', 'e'],
[Profile::class => ProfileField::find()->select('internal_name')->column()]
), true));
$templateParams = ['user' => $this->user, 'profile' => $this->user->profile];
try {
$description = $twig->createTemplate($module->getConfiguration()->userContent)
->render($templateParams);
} catch (LoaderError|RuntimeError|SyntaxError $e) {
$description = $e->getMessage();
}
return $this->render('vcard-user', [
'user' => $this->user,
'description' => $description
]);
}
}