Skip to content

Commit

Permalink
Manual Deploy through Quick Icon
Browse files Browse the repository at this point in the history
  • Loading branch information
Skullbock committed Feb 12, 2020
0 parents commit ae2fa3a
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 0 deletions.
11 changes: 11 additions & 0 deletions language/en-GB/en-GB.plg_system_sitesauce.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
PLG_SYSTEM_SITESAUCE_BUILD_HOOK_LABEL="Build Hook"
PLG_SYSTEM_SITESAUCE_BUILD_HOOK_DESC="The build hook for you site. You can find it on your sitesace dashboard (Preferences => Misc => Build Hook)."
PLG_SYSTEM_SITESAUCE_QUICKICON_LABEL="Deploy Static Site"
PLG_SYSTEM_SITESAUCE_ENABLE_QUICKICON_LABEL="Enable QuickIcon"
PLG_SYSTEM_SITESAUCE_ENABLE_QUICKICON_DESC="Show Icon in the Quick Icons module"
PLG_SYSTEM_SITESAUCE_QUICKICON_LABEL_LABEL="QuickIcon Label"
PLG_SYSTEM_SITESAUCE_QUICKICON_LABEL_DESC="The text used in the QuickIcon"
PLG_SYSTEM_SITESAUCE_QUICKICON_ICON_LABEL="QuickIcon Icon"
PLG_SYSTEM_SITESAUCE_QUICKICON_ICON_DESC="The FontAwesome Icon used in the QuickIcon"
PLG_SYSTEM_SITESAUCE_DEPLOY_STARTED="Deploy Started"
PLG_SYSTEM_SITESAUCE_DEPLOY_FAILED="Deploy Started"
1 change: 1 addition & 0 deletions language/en-GB/en-GB.plg_system_sitesauce.sys.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PLG
87 changes: 87 additions & 0 deletions sitesauce.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

defined('_JEXEC') or die;

class plgSystemSitesauce extends JPlugin
{
/**
* @var \Joomla\CMS\Application\CMSApplication
*/
protected $app;

/***
* @param $context
* @return array|void
*/
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));
}
}
32 changes: 32 additions & 0 deletions sitesauce.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.1" type="plugin" group="system" method="upgrade">
<name>System - Sitesauce</name>
<version>1.0.0</version>
<description>Sitesauce plugin for Joomla!</description>
<creationDate>February 2020</creationDate>
<copyright>Copyright (C) Sitesauce</copyright>
<license>GNU General Public License v2+</license>
<author>Daniele Rosario</author>
<authorEmail>[email protected]</authorEmail>
<authorUrl>https://sitesauce.app</authorUrl>
<files>
<filename plugin="sitesauce">sitesauce.php</filename>
</files>
<languages folder="language">
<language tag="en-GB">en-GB/en-GB.plg_system_sitesauce.ini</language>
<language tag="en-GB">en-GB/en-GB.plg_system_sitesauce.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="basic">
<field name="build_hook" type="text" default="" size="255" label="PLG_SYSTEM_SITESAUCE_BUILD_HOOK_LABEL" description="PLG_SYSTEM_SITESAUCE_BUILD_HOOK_DESC" />
<field name="enable_quickicon" type="list" default="1" size="255" label="PLG_SYSTEM_SITESAUCE_ENABLE_QUICKICON_LABEL" description="PLG_SYSTEM_SITESAUCE_ENABLE_QUICKICON_DESC">
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<field name="quickicon_label" type="text" default="Deploy Static Site" size="255" label="PLG_SYSTEM_SITESAUCE_QUICKICON_LABEL_LABEL" description="PLG_SYSTEM_SITESAUCE_QUICKICON_LABEL_DESC" />
<field name="quickicon_icon" type="text" default="star" size="255" label="PLG_SYSTEM_SITESAUCE_QUICKICON_ICON_LABEL" description="PLG_SYSTEM_SITESAUCE_QUICKICON_ICON_DESC" />
</fieldset>
</fields>
</config>
</extension>

0 comments on commit ae2fa3a

Please sign in to comment.