1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* SEOmatic plugin for Craft CMS 3.x |
4
|
|
|
* |
5
|
|
|
* A turnkey SEO implementation for Craft CMS that is comprehensive, powerful, |
6
|
|
|
* and flexible |
7
|
|
|
* |
8
|
|
|
* @link https://nystudio107.com |
9
|
|
|
* @copyright Copyright (c) 2017 nystudio107 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace nystudio107\seomatic\controllers; |
13
|
|
|
|
14
|
|
|
use Craft; |
15
|
|
|
use craft\base\Element; |
16
|
|
|
use craft\elements\Entry; |
17
|
|
|
use craft\web\Controller; |
18
|
|
|
use nystudio107\seomatic\assetbundles\seomatic\SeomaticAsset; |
19
|
|
|
use nystudio107\seomatic\helpers\PluginTemplate; |
20
|
|
|
use nystudio107\seomatic\Seomatic; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author nystudio107 |
|
|
|
|
24
|
|
|
* @package Seomatic |
25
|
|
|
* @since 3.2.13 |
|
|
|
|
26
|
|
|
*/ |
27
|
|
|
class PreviewController extends Controller |
28
|
|
|
{ |
29
|
|
|
// Properties |
30
|
|
|
// ========================================================================= |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @inheritdoc |
34
|
|
|
*/ |
35
|
|
|
protected $allowAnonymous = [ |
36
|
|
|
'social-media', |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
// Public Methods |
40
|
|
|
// ========================================================================= |
41
|
|
|
|
42
|
|
|
/** |
|
|
|
|
43
|
|
|
* @param $elementId |
|
|
|
|
44
|
|
|
* @param $siteId |
|
|
|
|
45
|
|
|
* |
46
|
|
|
* @return \yii\web\Response |
47
|
|
|
* @throws \yii\web\BadRequestHttpException |
48
|
|
|
* @throws \yii\base\InvalidConfigException |
49
|
|
|
*/ |
50
|
|
|
public function actionSocialMedia($elementId, $siteId) |
51
|
|
|
{ |
52
|
|
|
$html = ''; |
53
|
|
|
|
54
|
|
|
/** @var Element $element */ |
|
|
|
|
55
|
|
|
$element = Craft::$app->getElements()->getElementById($elementId, null, $siteId); |
56
|
|
|
if ($element !== null) { |
57
|
|
|
Seomatic::$view->registerAssetBundle(SeomaticAsset::class); |
58
|
|
|
/** @var $entry Entry */ |
|
|
|
|
59
|
|
|
if ($element->uri !== null) { |
60
|
|
|
Seomatic::$plugin->metaContainers->previewMetaContainers($element->uri, $element->siteId, true); |
61
|
|
|
// Render our preview sidebar template |
62
|
|
|
if (Seomatic::$matchedElement) { |
63
|
|
|
$html = PluginTemplate::renderPluginTemplate('_frontend/preview/social-media.twig'); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
return $this->asRaw($html); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|