-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsitesauce.php
107 lines (86 loc) · 2.59 KB
/
sitesauce.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
defined('_JEXEC') or die;
class plgSystemSitesauce extends JPlugin
{
/**
* @var \Joomla\CMS\Application\CMSApplication
*/
protected $app;
public function onContentAfterSave()
{
$this->automaticDeploy();
}
public function onContentAfterDelete()
{
$this->automaticDeploy();
}
public function onContentChangeState()
{
$this->automaticDeploy();
}
public function onGetIcons($context)
{
if ($context !== 'mod_quickicon') {
return;
}
if (!$this->params->get('build_hook', false)) {
return;
}
if (!$this->params->get('enable_quickicon', true)) {
return;
}
$this->loadLanguage('plg_system_sitesauce');
return [
[
'image' => $this->params->get('quickicon_icon', 'star'),
'text' => $this->params->get('quickicon_label', \JText::_('PLG_SYSTEM_SITESAUCE_QUICKICON_LABEL')),
'link' => "index.php?option=com_ajax&p=sitesauce&t=deploy",
]
];
}
public function onAfterRoute()
{
if (!$this->app->isClient('administrator')) {
return;
}
$this->handleRequest();
}
protected function handleRequest()
{
$path = $this->app->input->get('p');
$task = $this->app->input->get('t');
$option = $this->app->input->getCmd('option');
if ($option !== 'com_ajax' || $path !== 'sitesauce') {
return;
}
if (!$this->params->get('build_hook', false)) {
return;
}
if (\JFactory::getUser()->guest) {
$this->app->redirect(\JRoute::_('index.php?option=com_users&view=login', false));
return;
}
if ($task === 'deploy') {
$this->deploy();
return;
}
}
protected function deploy()
{
$response = JHttpFactory::getHttp()->get($this->params->get('build_hook'));
if ($response->code >= 200 && $response->code <= 299) {
$this->app->enqueueMessage(\JText::_('PLG_SYSTEM_SITESAUCE_DEPLOY_STARTED'));
$this->app->redirect(\JRoute::_('index.php', false));
return;
}
$this->app->enqueueMessage('PLG_SYSTEM_SITESAUCE_DEPLOY_FAILED');
$this->app->redirect(\JRoute::_('index.php', false));
}
protected function automaticDeploy()
{
if (!$this->params->get('autodeploy', false)) {
return;
}
JHttpFactory::getHttp()->get($this->params->get('build_hook'));
}
}