-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEmbedComponent.php
71 lines (61 loc) · 2.08 KB
/
EmbedComponent.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
60
61
62
63
64
65
66
67
68
69
70
71
<?php namespace Inerba\Embedd\Components;
use Cache;
use Embed\Embed;
use Cms\Classes\ComponentBase;
use Inerba\Embedd\Classes\Embedd;
use Inerba\Embedd\Models\Settings;
class EmbedComponent extends ComponentBase
{
public function componentDetails()
{
return [
'name' => 'inerba.embedd::lang.plugin.name',
'description' => 'inerba.embedd::lang.plugin.description'
];
}
public function defineProperties()
{
return [
'url' => [
'title' => 'inerba.embedd::lang.EmbedComponent.url.title',
'description' => 'inerba.embedd::lang.EmbedComponent.url.description',
'type' => 'string',
],
'cache' => [
'title' => 'inerba.embedd::lang.EmbedComponent.cache.title',
'description' => 'inerba.embedd::lang.EmbedComponent.cache.description',
'validationPattern' => '^[0-9]+$',
'validationMessage' => 'inerba.embedd::lang.EmbedComponent.cache.validationMessage',
'default' => '1440',
'type' => 'string',
],
];
}
public function onRun()
{
/*$start = microtime(true);
dd($this->retrieve(),microtime(true) - $start);*/
$Embedd = new Embedd();
$e = $Embedd->retrieve(
$this->property('url'),
$this->property('cache')
);
if(!is_object($e)){
// ERRORE
$this->page['provider_partial'] = 'error';
$this->page['error'] = $e;
return false;
}
$this->page['provider_partial'] = $this->get_partial($e->providerName);
$this->page['embed'] = $e;
}
private function get_partial($name)
{
$name = str_slug($name);
$filename = plugins_path('inerba/embedd/components/embedcomponent/provider/'.$name.'.htm');
if (file_exists($filename)) {
return $name;
}
return false;
}
}