acf
This commit is contained in:
54
plugins/system/nrframework/NRFramework/Notices/Helper.php
Normal file
54
plugins/system/nrframework/NRFramework/Notices/Helper.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link https://www.tassos.gr
|
||||
* @copyright Copyright © 2024 Tassos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
* @credits https://github.com/codeigniter4/CodeIgniter4/blob/develop/app/Config/Mimes.php
|
||||
*/
|
||||
|
||||
namespace NRFramework\Notices;
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use \NRFramework\Extension;
|
||||
|
||||
class Helper
|
||||
{
|
||||
/**
|
||||
* Returns the extension details for given element.
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $element
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getExtensionDetails($data, $element)
|
||||
{
|
||||
// Return bundle only if its active
|
||||
if (isset($data['bundle']) && $data['bundle']['active'])
|
||||
{
|
||||
return $data['bundle'];
|
||||
}
|
||||
|
||||
$alias = Extension::getExtensionDataFileAlias($element);
|
||||
|
||||
// If no license data found for this extension
|
||||
if (!isset($data[$alias]))
|
||||
{
|
||||
// Return the expired bundle information if it exists
|
||||
if (isset($data['bundle']))
|
||||
{
|
||||
return $data['bundle'];
|
||||
}
|
||||
|
||||
// No bundle exists, return nothing
|
||||
return;
|
||||
}
|
||||
|
||||
// Return the extension's license data details
|
||||
return $data[$alias];
|
||||
}
|
||||
}
|
||||
323
plugins/system/nrframework/NRFramework/Notices/Notices.php
Normal file
323
plugins/system/nrframework/NRFramework/Notices/Notices.php
Normal file
@ -0,0 +1,323 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link https://www.tassos.gr
|
||||
* @copyright Copyright © 2024 Tassos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
* @credits https://github.com/codeigniter4/CodeIgniter4/blob/develop/app/Config/Mimes.php
|
||||
*/
|
||||
|
||||
namespace NRFramework\Notices;
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Layout\LayoutHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
use \NRFramework\Extension;
|
||||
|
||||
class Notices
|
||||
{
|
||||
/**
|
||||
* The payload.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $payload;
|
||||
|
||||
/**
|
||||
* The extension's ext_element we are showing notices.
|
||||
*
|
||||
* Example: acf
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $ext_element;
|
||||
|
||||
/**
|
||||
* The extension's main XML file location folder.
|
||||
*
|
||||
* Example: plg_system_acf, com_rstbox
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $ext_xml;
|
||||
|
||||
/**
|
||||
* The extension type.
|
||||
*
|
||||
* Example: plugin, component, module, etc...
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $ext_type = 'component';
|
||||
|
||||
/**
|
||||
* The notices to exclude.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $exclude = [];
|
||||
|
||||
/**
|
||||
* Define how old (in days) the file that holds all extensions data needs to be set as expired,
|
||||
* so we can fetch new data.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $extensions_data_file_days_old = 1;
|
||||
|
||||
/**
|
||||
* Download Key.
|
||||
*
|
||||
* @var String
|
||||
*/
|
||||
protected $download_key = null;
|
||||
|
||||
/**
|
||||
* The license data for the given download key.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $license_data = [];
|
||||
|
||||
/**
|
||||
* Notices Instance.
|
||||
*
|
||||
* @var Notices
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
public function __construct($payload = [])
|
||||
{
|
||||
$this->payload = $payload;
|
||||
|
||||
$this->ext_element = isset($this->payload['ext_element']) ? $this->payload['ext_element'] : '';
|
||||
$this->ext_xml = isset($this->payload['ext_xml']) ? $this->payload['ext_xml'] : '';
|
||||
$this->ext_type = isset($this->payload['ext_type']) ? $this->payload['ext_type'] : $this->ext_type;
|
||||
$this->exclude = isset($this->payload['exclude']) ? $this->payload['exclude'] : [];
|
||||
|
||||
$this->download_key = \NRFramework\Functions::getDownloadKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns class instance
|
||||
*
|
||||
* @param array $payload
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public static function getInstance($payload = [])
|
||||
{
|
||||
if (is_null(self::$instance))
|
||||
{
|
||||
self::$instance = new self($payload);
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all available notices.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function show()
|
||||
{
|
||||
// Show only for Super Users
|
||||
if (!$this->isSuperUser())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
HTMLHelper::stylesheet('plg_system_nrframework/notices.css', ['relative' => true, 'version' => 'auto']);
|
||||
HTMLHelper::script('plg_system_nrframework/notices.js', ['relative' => true, 'version' => 'auto']);
|
||||
|
||||
$payload = [
|
||||
'ext_element' => $this->ext_element,
|
||||
'ext_xml' => $this->ext_xml,
|
||||
'ext_type' => $this->ext_type,
|
||||
'exclude' => $this->exclude
|
||||
];
|
||||
|
||||
echo LayoutHelper::render('notices/tmpl', $payload, dirname(dirname(__DIR__)) . '/layouts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current user is a Super User.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isSuperUser()
|
||||
{
|
||||
return Factory::getUser()->authorise('core.admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the base notices.
|
||||
*
|
||||
* @param array $notices
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function getBaseNotices()
|
||||
{
|
||||
$base_notices = [
|
||||
'Outdated',
|
||||
'DownloadKey',
|
||||
'Geolocation',
|
||||
'UpgradeToPro',
|
||||
'UpgradeToBundle'
|
||||
];
|
||||
|
||||
// Exclude notices we should not display
|
||||
if (count($this->exclude))
|
||||
{
|
||||
foreach ($base_notices as $key => $notice)
|
||||
{
|
||||
if (!in_array($notice, $this->exclude))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
unset($base_notices[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$notices = [];
|
||||
|
||||
// Initialize notices
|
||||
foreach ($base_notices as $key => $notice)
|
||||
{
|
||||
$class = '\NRFramework\Notices\Notices\\' . $notice;
|
||||
|
||||
// Skip empty notice
|
||||
if (!$html = (new $class($this->payload))->render())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$notices[strtolower($notice)] = $html;
|
||||
}
|
||||
|
||||
return $notices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns which license-related notices to show.
|
||||
*
|
||||
* Notices:
|
||||
* - Extension expires in date
|
||||
* - Extension expired at date
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getLicensesBasedNoticesToShow()
|
||||
{
|
||||
// If no data found for this extension, abort
|
||||
if (!$extension_data = \NRFramework\Notices\Helper::getExtensionDetails($this->license_data, $this->ext_element))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!array_key_exists('active', $extension_data))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$notices = [];
|
||||
|
||||
// Active subscription and we have a expiration date
|
||||
if ($extension_data['active'] && array_key_exists('expires_in', $extension_data) && $extension_data['expires_in'])
|
||||
{
|
||||
$notices[] = (new Notices\Expiring(array_merge($this->payload, [
|
||||
'expires_in' => $extension_data['expires_in'],
|
||||
'plan' => $extension_data['plan']
|
||||
])))->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* We should not have an active subscription and the "expired_at" date must be set.
|
||||
*
|
||||
* If "active" is true and an "expired_at" date is set, it means we have a Bundle plan.
|
||||
*/
|
||||
if (!$extension_data['active'] && array_key_exists('expired_at', $extension_data) && $extension_data['expired_at'])
|
||||
{
|
||||
$notices[] = (new Notices\Expired(array_merge($this->payload, [
|
||||
'expired_at' => $extension_data['expired_at'],
|
||||
'plan' => $extension_data['plan']
|
||||
])))->render();
|
||||
}
|
||||
|
||||
if (!$notices)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return implode('', $notices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the based notices:
|
||||
*
|
||||
* Notices:
|
||||
* - Base notices
|
||||
* - Outdated
|
||||
* - Download Key
|
||||
* - Geolocation
|
||||
* - Upgrade To Pro
|
||||
* - Upgrade To Bundle
|
||||
* - Update notice
|
||||
* - Extension expires in date
|
||||
* - Extension expired at date
|
||||
* - Rate (If none of the license-related notices appear)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNotices()
|
||||
{
|
||||
// Check and Update the local licenses data
|
||||
$this->checkAndUpdateExtensionsData();
|
||||
|
||||
$notices = $this->getBaseNotices();
|
||||
|
||||
// Show Update Notice
|
||||
if ($update_html = (new Notices\Update($this->payload))->render())
|
||||
{
|
||||
$notices['update'] = $update_html;
|
||||
}
|
||||
|
||||
if ($license_notices = $this->getLicensesBasedNoticesToShow())
|
||||
{
|
||||
$notices['license'] = $license_notices;
|
||||
}
|
||||
else if ($rate_html = (new Notices\Rate($this->payload))->render())
|
||||
{
|
||||
$notices['rate'] = $rate_html;
|
||||
}
|
||||
|
||||
return $notices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the current extensions data has expired and updates the data file.
|
||||
*
|
||||
* Also checks and sets the installation date of the extension.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkAndUpdateExtensionsData()
|
||||
{
|
||||
// Sets licenses information
|
||||
$this->license_data = \NRFramework\Helpers\License::getRemoteLicenseData($this->download_key);
|
||||
|
||||
// Add the license data to the payload as well
|
||||
$this->payload['license_data'] = $this->license_data;
|
||||
|
||||
// Set installation date
|
||||
Extension::setInstallationDate($this->ext_element, gmdate('Y-m-d H:i:s'));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link https://www.tassos.gr
|
||||
* @copyright Copyright © 2024 Tassos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Notices\Notices;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use \NRFramework\Functions;
|
||||
|
||||
class DownloadKey extends Notice
|
||||
{
|
||||
protected $notice_payload = [
|
||||
'type' => 'error',
|
||||
'class' => 'download-key',
|
||||
'dismissible' => false,
|
||||
'download_key' => null,
|
||||
'state' => null
|
||||
];
|
||||
|
||||
public function __construct($payload = [])
|
||||
{
|
||||
parent::__construct($payload);
|
||||
|
||||
$this->payload['download_key'] = Functions::getDownloadKey();
|
||||
$this->payload['state'] = isset($this->payload['license_data']['state']) ? $this->payload['license_data']['state'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTitle()
|
||||
{
|
||||
$text = !empty($this->payload['download_key']) || ($this->payload['state'] && in_array($this->payload['state'], ['invalid_key'])) ? Text::_('NR_IS_INVALID') : Text::_('NR_IS_MISSING');
|
||||
return sprintf(Text::_('NR_DOWNLOAD_KEY_TEXT'), $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDescription()
|
||||
{
|
||||
$text = !empty($this->payload['download_key']) || ($this->payload['state'] && in_array($this->payload['state'], ['invalid_key'])) ? Text::_('NR_A_VALID') : Text::_('NR_YOUR');
|
||||
return sprintf(Text::_('NR_DOWNLOAD_KEY_MISSING_DESC'), $this->extension_name, $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice actions.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getActions()
|
||||
{
|
||||
$url = 'https://www.tassos.gr/kb/general/how-to-activate-your-pro-version';
|
||||
|
||||
return '<input type="text" class="tf-notice-download-key" value="' . htmlspecialchars($this->getDownloadKey()) . '" placeholder="' . Text::_('NR_ENTER_YOUR_DOWNLOAD_KEY') . '" />
|
||||
<a href="#" class="tf-notice-download-key-btn tf-notice-btn info">' . Text::_('JAPPLY') . '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="15" height="15" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid">
|
||||
<circle cx="50" cy="50" fill="none" stroke="currentColor" stroke-width="8" r="38" stroke-dasharray="179.0707812546182 61.690260418206066">
|
||||
<animateTransform attributeName="transform" type="rotate" repeatCount="indefinite" dur="1s" values="0 50 50;360 50 50" keyTimes="0;1"></animateTransform>
|
||||
</circle>
|
||||
</svg></a>
|
||||
<a href="' . Functions::getUTMURL($url, 'UserNotice', 'DownloadKey') . '" target="_blank">' . Text::_('JHELP') . '</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the notice can run.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function canRun()
|
||||
{
|
||||
// Ensure customer is using the Pro version
|
||||
if (!\NRFramework\Extension::isPro($this->payload['ext_xml']))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// If user is Pro but has no license details, show it
|
||||
if (!$details = \NRFramework\Notices\Helper::getExtensionDetails($this->payload['license_data'], $this->payload['ext_element']))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// If state exists and key is invalid/or no subscriptions exist, return true
|
||||
if ($this->payload['state'] && in_array($this->payload['state'], ['missing_key', 'invalid_key']))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!empty($this->getDownloadKey()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getDownloadKey()
|
||||
{
|
||||
return isset($this->payload['download_key']) ? $this->payload['download_key'] : '';
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link https://www.tassos.gr
|
||||
* @copyright Copyright © 2024 Tassos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Notices\Notices;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use \NRFramework\Functions;
|
||||
use \NRFramework\Extension;
|
||||
|
||||
class Expired extends Notice
|
||||
{
|
||||
protected $notice_payload = [
|
||||
'type' => 'error',
|
||||
'class' => 'expired',
|
||||
'expired_at' => '',
|
||||
'plan' => ''
|
||||
];
|
||||
|
||||
public function __construct($payload = [])
|
||||
{
|
||||
parent::__construct($payload);
|
||||
|
||||
$this->payload['tooltip'] = Text::_('NR_NOTICE_EXPIRED_TOOLTIP');
|
||||
$this->payload['expired_at'] = isset($payload['expired_at']) ? $payload['expired_at'] : false;
|
||||
$this->payload['plan'] = isset($payload['plan']) ? $payload['plan'] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTitle()
|
||||
{
|
||||
return sprintf(Text::_('NR_SUBSCRIPTION_EXPIRED'), $this->extension_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDescription()
|
||||
{
|
||||
$title = strtolower($this->payload['plan']) === 'bundle' ? $this->payload['plan'] : $this->extension_name . ' ' . $this->payload['plan'];
|
||||
|
||||
return sprintf(Text::_('NR_SUBSCRIPTION_EXPIRED_DESC'), $title, Functions::applySiteTimezoneToDate($this->payload['expired_at'], 'd M o'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice actions.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getActions()
|
||||
{
|
||||
$url = 'https://www.tassos.gr/subscriptions';
|
||||
|
||||
return '<a href="' . Functions::getUTMURL($url, 'UserNotice', 'SubscriptionExpired') . '" target="_blank" class="tf-notice-btn info">' . sprintf(Text::_('NR_RENEW_X_PERCENT_OFF'), 20) . '</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the notice can run.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function canRun()
|
||||
{
|
||||
// If cookie exists, it's already hidden
|
||||
if ($this->factory->getCookie('tfNoticeHideExpiredNotice_' . $this->payload['ext_element']) === 'true')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// The date the extension expired.
|
||||
if (!$this->payload['expired_at'])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link https://www.tassos.gr
|
||||
* @copyright Copyright © 2024 Tassos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Notices\Notices;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use \NRFramework\Functions;
|
||||
|
||||
class Expiring extends Notice
|
||||
{
|
||||
protected $notice_payload = [
|
||||
'type' => 'warning',
|
||||
'class' => 'expiring',
|
||||
'expires_in' => '',
|
||||
'plan' => ''
|
||||
];
|
||||
|
||||
public function __construct($payload = [])
|
||||
{
|
||||
parent::__construct($payload);
|
||||
|
||||
$this->payload['tooltip'] = Text::_('NR_NOTICE_EXPIRING_TOOLTIP');
|
||||
$this->payload['expires_in'] = isset($this->payload['expires_in']) ? $this->payload['expires_in'] : false;
|
||||
$this->payload['plan'] = isset($payload['plan']) ? $payload['plan'] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the remaining days the subscription must have to display the expiring subscription notice.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $expiring_notice_days = 30;
|
||||
|
||||
/**
|
||||
* Notice title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTitle()
|
||||
{
|
||||
return sprintf(Text::_('NR_SUBSCRIPTION_EXPIRING'), $this->extension_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDescription()
|
||||
{
|
||||
$title = strtolower($this->payload['plan']) === 'bundle' ? $this->payload['plan'] : $this->extension_name . ' ' . $this->payload['plan'];
|
||||
|
||||
return sprintf(Text::_('NR_SUBSCRIPTION_EXPIRING_DESC'), $title, Functions::applySiteTimezoneToDate($this->payload['expires_in'], 'd M o'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice actions.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getActions()
|
||||
{
|
||||
$url = 'https://www.tassos.gr/subscriptions';
|
||||
|
||||
return '<a href="' . Functions::getUTMURL($url, 'UserNotice', 'SubscriptionExpiring') . '" target="_blank" class="tf-notice-btn info">' . sprintf(Text::_('NR_RENEW_X_PERCENT_OFF'), 30) . '</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the notice can run.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function canRun()
|
||||
{
|
||||
// If cookie exists, it's already hidden
|
||||
if ($this->factory->getCookie('tfNoticeHideExpiringNotice_' . $this->payload['ext_element']) === 'true')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// The date the extension expires.
|
||||
if (!$this->payload['expires_in'])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// The days difference criteria must be met
|
||||
if ($this->getDaysDifference(strtotime($this->payload['expires_in']), time()) > $this->expiring_notice_days)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link https://www.tassos.gr
|
||||
* @copyright Copyright © 2024 Tassos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Notices\Notices;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use \NRFramework\Extension;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\CMS\Session\Session;
|
||||
|
||||
class Geolocation extends Notice
|
||||
{
|
||||
protected $notice_payload = [
|
||||
'type' => 'warning',
|
||||
'class' => 'geolocation'
|
||||
];
|
||||
|
||||
public function __construct($payload = [])
|
||||
{
|
||||
parent::__construct($payload);
|
||||
|
||||
\NRFramework\Functions::loadLanguage('plg_system_tgeoip');
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTitle()
|
||||
{
|
||||
return Text::_('PLG_SYSTEM_TGEOIP_MAINTENANCE');
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDescription()
|
||||
{
|
||||
return sprintf(Text::_('NR_NOTICE_GEO_MAINTENANCE_DESC'), $this->extension_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice actions.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getActions()
|
||||
{
|
||||
$url = Uri::base() . 'index.php?option=com_ajax&format=raw&plugin=tgeoip&task=update-red&' . Session::getFormToken() . '=1&return=' . base64_encode($this->payload['current_url']);
|
||||
|
||||
return '<a href="' . $url . '" class="tf-notice-btn info">' . Text::_('NR_UPDATE_NOW') . '</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the notice can run.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function canRun()
|
||||
{
|
||||
// If cookie exists, its been hidden
|
||||
if ($this->factory->getCookie('tfNoticeHideGeolocationNotice_' . $this->payload['ext_element']) === 'true')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Extension::geoPluginNeedsUpdate())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link https://www.tassos.gr
|
||||
* @copyright Copyright © 2024 Tassos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Notices\Notices;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use \NRFramework\Extension;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Layout\LayoutHelper;
|
||||
|
||||
class Notice
|
||||
{
|
||||
/**
|
||||
* The notice payload.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $notice_payload = [];
|
||||
|
||||
/**
|
||||
* The payload.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $payload = [
|
||||
/**
|
||||
* The extension's element we are showing notices.
|
||||
*
|
||||
* Example: com_rstbox, plg_system_acf
|
||||
*/
|
||||
'ext_element' => '',
|
||||
|
||||
/**
|
||||
* The extension's main XML file location folder.
|
||||
*/
|
||||
'ext_xml' => '',
|
||||
|
||||
/**
|
||||
* The extension type.
|
||||
*
|
||||
* Example: component, plugin, module, etc...
|
||||
*/
|
||||
'ext_type' => 'component',
|
||||
|
||||
/**
|
||||
* The notice type.
|
||||
*/
|
||||
'type' => '',
|
||||
|
||||
/**
|
||||
* The notice icon.
|
||||
*
|
||||
* Inner part of the SVG icon.
|
||||
*/
|
||||
'icon' => '',
|
||||
|
||||
/**
|
||||
* An array containing classes attached to the notice wrapper HTML Element.
|
||||
*/
|
||||
'class' => '',
|
||||
|
||||
/**
|
||||
* Whether the notice is dismissible.
|
||||
*/
|
||||
'dismissible' => true,
|
||||
|
||||
/**
|
||||
* The notice title.
|
||||
*/
|
||||
'title' => '',
|
||||
|
||||
/**
|
||||
* The notice description.
|
||||
*/
|
||||
'description' => '',
|
||||
|
||||
/**
|
||||
* The tooltip text explaining this action.
|
||||
*/
|
||||
'tooltip' => '',
|
||||
|
||||
/**
|
||||
* The notice actions.
|
||||
*/
|
||||
'actions' => ''
|
||||
];
|
||||
|
||||
/**
|
||||
* The extension name.
|
||||
*
|
||||
* @var String
|
||||
*/
|
||||
protected $extension_name;
|
||||
|
||||
/**
|
||||
* Factory.
|
||||
*
|
||||
* @var Factory
|
||||
*/
|
||||
protected $factory;
|
||||
|
||||
public function __construct($payload = [])
|
||||
{
|
||||
$this->payload = array_merge($this->payload, $this->notice_payload, $payload);
|
||||
|
||||
$this->factory = new \NRFramework\Factory();
|
||||
|
||||
$this->extension_name = Extension::getExtensionName($this->payload['ext_element']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders notice.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
if (!$this->canRun())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->prepare();
|
||||
|
||||
return LayoutHelper::render('notices/notice', $this->payload, dirname(dirname(dirname(__DIR__))) . '/layouts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the notice.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function prepare()
|
||||
{
|
||||
// Set title
|
||||
if (method_exists($this, 'getTitle'))
|
||||
{
|
||||
$this->payload['title'] = $this->getTitle();
|
||||
}
|
||||
|
||||
// Set description
|
||||
if (method_exists($this, 'getDescription'))
|
||||
{
|
||||
$this->payload['description'] = $this->getDescription();
|
||||
}
|
||||
|
||||
// Set actions
|
||||
if (method_exists($this, 'getActions'))
|
||||
{
|
||||
$this->payload['actions'] = $this->getActions();
|
||||
}
|
||||
|
||||
if (isset($this->payload['type']) && !empty($this->payload['type']))
|
||||
{
|
||||
// Set type of notice
|
||||
$this->payload['class'] .= ' ' . $this->payload['type'];
|
||||
|
||||
// Set icon
|
||||
switch ($this->payload['type'])
|
||||
{
|
||||
case 'warning':
|
||||
$icon = '<mask id="mask0_105_19" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="40" height="40"><rect width="40" height="40" fill="#D9D9D9"/></mask><g mask="url(#mask0_105_19)"><path d="M1.66669 35L20 3.33331L38.3334 35H1.66669ZM7.41669 31.6666H32.5834L20 9.99998L7.41669 31.6666ZM20 30C20.4722 30 20.8684 29.84 21.1884 29.52C21.5072 29.2011 21.6667 28.8055 21.6667 28.3333C21.6667 27.8611 21.5072 27.4655 21.1884 27.1466C20.8684 26.8266 20.4722 26.6666 20 26.6666C19.5278 26.6666 19.1322 26.8266 18.8134 27.1466C18.4934 27.4655 18.3334 27.8611 18.3334 28.3333C18.3334 28.8055 18.4934 29.2011 18.8134 29.52C19.1322 29.84 19.5278 30 20 30ZM18.3334 25H21.6667V16.6666H18.3334V25Z" fill="#F4B400"/></g>';
|
||||
break;
|
||||
case 'error':
|
||||
$icon = '<mask id="mask0_105_7" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="40" height="40"><rect width="40" height="40" fill="#D9D9D9"/></mask><g mask="url(#mask0_105_7)"><path d="M20.0001 28.3334C20.4723 28.3334 20.8684 28.1734 21.1884 27.8534C21.5073 27.5345 21.6668 27.139 21.6668 26.6668C21.6668 26.1946 21.5073 25.7984 21.1884 25.4784C20.8684 25.1595 20.4723 25.0001 20.0001 25.0001C19.5279 25.0001 19.1323 25.1595 18.8134 25.4784C18.4934 25.7984 18.3334 26.1946 18.3334 26.6668C18.3334 27.139 18.4934 27.5345 18.8134 27.8534C19.1323 28.1734 19.5279 28.3334 20.0001 28.3334ZM20.0001 21.6668C20.4723 21.6668 20.8684 21.5068 21.1884 21.1868C21.5073 20.8679 21.6668 20.4723 21.6668 20.0001V13.3334C21.6668 12.8612 21.5073 12.4651 21.1884 12.1451C20.8684 11.8262 20.4723 11.6668 20.0001 11.6668C19.5279 11.6668 19.1323 11.8262 18.8134 12.1451C18.4934 12.4651 18.3334 12.8612 18.3334 13.3334V20.0001C18.3334 20.4723 18.4934 20.8679 18.8134 21.1868C19.1323 21.5068 19.5279 21.6668 20.0001 21.6668ZM20.0001 36.6668C17.6945 36.6668 15.5279 36.229 13.5001 35.3534C11.4723 34.479 9.70844 33.2918 8.20844 31.7918C6.70844 30.2918 5.52121 28.5279 4.64677 26.5001C3.77121 24.4723 3.33344 22.3057 3.33344 20.0001C3.33344 17.6945 3.77121 15.5279 4.64677 13.5001C5.52121 11.4723 6.70844 9.70844 8.20844 8.20844C9.70844 6.70844 11.4723 5.52066 13.5001 4.6451C15.5279 3.77066 17.6945 3.33344 20.0001 3.33344C22.3057 3.33344 24.4723 3.77066 26.5001 4.6451C28.5279 5.52066 30.2918 6.70844 31.7918 8.20844C33.2918 9.70844 34.479 11.4723 35.3534 13.5001C36.229 15.5279 36.6668 17.6945 36.6668 20.0001C36.6668 22.3057 36.229 24.4723 35.3534 26.5001C34.479 28.5279 33.2918 30.2918 31.7918 31.7918C30.2918 33.2918 28.5279 34.479 26.5001 35.3534C24.4723 36.229 22.3057 36.6668 20.0001 36.6668ZM20.0001 33.3334C23.7223 33.3334 26.8751 32.0418 29.4584 29.4584C32.0418 26.8751 33.3334 23.7223 33.3334 20.0001C33.3334 16.2779 32.0418 13.1251 29.4584 10.5418C26.8751 7.95844 23.7223 6.66677 20.0001 6.66677C16.2779 6.66677 13.1251 7.95844 10.5418 10.5418C7.95844 13.1251 6.66677 16.2779 6.66677 20.0001C6.66677 23.7223 7.95844 26.8751 10.5418 29.4584C13.1251 32.0418 16.2779 33.3334 20.0001 33.3334Z" fill="#DB4437"/></g>';
|
||||
break;
|
||||
case 'info':
|
||||
$icon = '<mask id="mask0_105_43" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="40" height="40"><rect width="40" height="40" fill="#D9D9D9"/></mask><g mask="url(#mask0_105_43)"><path d="M18.3333 28.3333H21.6666V18.3333H18.3333V28.3333ZM20 15C20.4722 15 20.8683 14.84 21.1883 14.52C21.5072 14.2011 21.6666 13.8056 21.6666 13.3333C21.6666 12.8611 21.5072 12.465 21.1883 12.145C20.8683 11.8261 20.4722 11.6667 20 11.6667C19.5278 11.6667 19.1322 11.8261 18.8133 12.145C18.4933 12.465 18.3333 12.8611 18.3333 13.3333C18.3333 13.8056 18.4933 14.2011 18.8133 14.52C19.1322 14.84 19.5278 15 20 15ZM20 36.6667C17.6944 36.6667 15.5278 36.2289 13.5 35.3533C11.4722 34.4789 9.70831 33.2917 8.20831 31.7917C6.70831 30.2917 5.52109 28.5278 4.64665 26.5C3.77109 24.4722 3.33331 22.3056 3.33331 20C3.33331 17.6944 3.77109 15.5278 4.64665 13.5C5.52109 11.4722 6.70831 9.70833 8.20831 8.20833C9.70831 6.70833 11.4722 5.52056 13.5 4.645C15.5278 3.77056 17.6944 3.33333 20 3.33333C22.3055 3.33333 24.4722 3.77056 26.5 4.645C28.5278 5.52056 30.2916 6.70833 31.7916 8.20833C33.2916 9.70833 34.4789 11.4722 35.3533 13.5C36.2289 15.5278 36.6666 17.6944 36.6666 20C36.6666 22.3056 36.2289 24.4722 35.3533 26.5C34.4789 28.5278 33.2916 30.2917 31.7916 31.7917C30.2916 33.2917 28.5278 34.4789 26.5 35.3533C24.4722 36.2289 22.3055 36.6667 20 36.6667ZM20 33.3333C23.7222 33.3333 26.875 32.0417 29.4583 29.4583C32.0416 26.875 33.3333 23.7222 33.3333 20C33.3333 16.2778 32.0416 13.125 29.4583 10.5417C26.875 7.95833 23.7222 6.66667 20 6.66667C16.2778 6.66667 13.125 7.95833 10.5416 10.5417C7.95831 13.125 6.66665 16.2778 6.66665 20C6.66665 23.7222 7.95831 26.875 10.5416 29.4583C13.125 32.0417 16.2778 33.3333 20 33.3333Z" fill="#4285F4"/></g>';
|
||||
break;
|
||||
case 'success':
|
||||
$icon = '<mask id="mask0_105_31" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="40" height="40"><rect width="40" height="40" fill="#D9D9D9"/></mask><g mask="url(#mask0_105_31)"><path d="M17.6666 27.6667L29.4166 15.9167L27.0833 13.5833L17.6666 23L12.9166 18.25L10.5833 20.5833L17.6666 27.6667ZM20 36.6667C17.6944 36.6667 15.5278 36.2289 13.5 35.3533C11.4722 34.4789 9.70831 33.2917 8.20831 31.7917C6.70831 30.2917 5.52109 28.5278 4.64665 26.5C3.77109 24.4722 3.33331 22.3056 3.33331 20C3.33331 17.6945 3.77109 15.5278 4.64665 13.5C5.52109 11.4722 6.70831 9.70834 8.20831 8.20834C9.70831 6.70834 11.4722 5.52057 13.5 4.64501C15.5278 3.77057 17.6944 3.33334 20 3.33334C22.3055 3.33334 24.4722 3.77057 26.5 4.64501C28.5278 5.52057 30.2916 6.70834 31.7916 8.20834C33.2916 9.70834 34.4789 11.4722 35.3533 13.5C36.2289 15.5278 36.6666 17.6945 36.6666 20C36.6666 22.3056 36.2289 24.4722 35.3533 26.5C34.4789 28.5278 33.2916 30.2917 31.7916 31.7917C30.2916 33.2917 28.5278 34.4789 26.5 35.3533C24.4722 36.2289 22.3055 36.6667 20 36.6667ZM20 33.3333C23.7222 33.3333 26.875 32.0417 29.4583 29.4583C32.0416 26.875 33.3333 23.7222 33.3333 20C33.3333 16.2778 32.0416 13.125 29.4583 10.5417C26.875 7.95834 23.7222 6.66668 20 6.66668C16.2778 6.66668 13.125 7.95834 10.5416 10.5417C7.95831 13.125 6.66665 16.2778 6.66665 20C6.66665 23.7222 7.95831 26.875 10.5416 29.4583C13.125 32.0417 16.2778 33.3333 20 33.3333Z" fill="#0F9D58"/></g>';
|
||||
break;
|
||||
}
|
||||
|
||||
$this->payload['icon'] = $icon;
|
||||
}
|
||||
|
||||
// Set whether dismissible
|
||||
if ($this->payload['dismissible'])
|
||||
{
|
||||
$this->payload['class'] .= ' alert-dismissible';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the notice can run.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function canRun()
|
||||
{
|
||||
// If no title or description is given, do not run
|
||||
if (empty($this->payload['title']) && empty($this->payload['description']))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date difference between today and a given date in the future.
|
||||
*
|
||||
* @param string $date1
|
||||
* @param string $date2
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDaysDifference($date1, $date2)
|
||||
{
|
||||
return (int) round(($date1 - $date2) / (60 * 60 * 24));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link https://www.tassos.gr
|
||||
* @copyright Copyright © 2024 Tassos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Notices\Notices;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use \NRFramework\Functions;
|
||||
use \NRFramework\Extension;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\CMS\Session\Session;
|
||||
|
||||
class Outdated extends Notice
|
||||
{
|
||||
/**
|
||||
* How old the extension needs to be to be defined as "outdated".
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $oudated_notice_days_old = 120;
|
||||
|
||||
protected $notice_payload = [
|
||||
'type' => 'warning',
|
||||
'class' => 'outdated'
|
||||
];
|
||||
|
||||
/**
|
||||
* Notice title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTitle()
|
||||
{
|
||||
return sprintf(Text::_('NR_EXTENSION_IS_OUTDATED'), $this->extension_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDescription()
|
||||
{
|
||||
return sprintf(Text::_('NR_OUTDATED_EXTENSION'), $this->extension_name, $this->oudated_notice_days_old);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice actions.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getActions()
|
||||
{
|
||||
return '<a href="' . Uri::base() . 'index.php?option=com_installer&task=update.find&' . Session::getFormToken() . '=1" class="tf-notice-btn info">' . Text::_('NR_UPDATE_NOW') . '</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the notice can run.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function canRun()
|
||||
{
|
||||
// If cookie exists, its been hidden
|
||||
if ($this->factory->getCookie('tfNoticeHideOutdatedNotice_' . $this->payload['ext_element']) === 'true')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Extension::isOutdated($this->payload['ext_element'], $this->oudated_notice_days_old))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link https://www.tassos.gr
|
||||
* @copyright Copyright © 2024 Tassos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Notices\Notices;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use \NRFramework\Extension;
|
||||
|
||||
class Rate extends Notice
|
||||
{
|
||||
/**
|
||||
* Define how old (in days) the extension needs to be since the installation date
|
||||
* in order to display this notice.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $rate_notice_days_old = 10;
|
||||
|
||||
protected $notice_payload = [
|
||||
'type' => 'info',
|
||||
'class' => 'rate'
|
||||
];
|
||||
|
||||
/**
|
||||
* Notice title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTitle()
|
||||
{
|
||||
return sprintf(Text::_('NR_RATE'), $this->extension_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDescription()
|
||||
{
|
||||
return sprintf(Text::_('NR_RATE_NOTICE_EXTENSION_DESC'), $this->extension_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice actions.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getActions()
|
||||
{
|
||||
return '<a href="#" class="tf-rate-already-rated">' . Text::_('NR_I_ALREADY_DID') . '</a>
|
||||
<a href="' . Extension::getExtensionJEDURL($this->payload['ext_xml']) . '#reviews" target="_blank" class="tf-notice-btn info">' . Text::_('NR_WRITE_A_REVIEW') . '</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the notice can run.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function canRun()
|
||||
{
|
||||
// If cookie exists, it's already hidden
|
||||
if ($this->factory->getCookie('tfNoticeHideRateNotice_' . $this->payload['ext_element']) === 'true')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get extension installation date
|
||||
if (!$install_date = Extension::getInstallationDate($this->payload['ext_element']))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the extension is not old enough, do not show the rate notice
|
||||
if ($this->getDaysDifference(time(), strtotime($install_date)) < $this->rate_notice_days_old)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link https://www.tassos.gr
|
||||
* @copyright Copyright © 2024 Tassos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Notices\Notices;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use \NRFramework\Extension;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
use Joomla\CMS\Session\Session;
|
||||
|
||||
class Update extends Notice
|
||||
{
|
||||
protected $notice_payload = [
|
||||
'type' => 'success',
|
||||
'class' => 'update',
|
||||
'current_version' => '',
|
||||
'latest_version' => ''
|
||||
];
|
||||
|
||||
public function __construct($payload = [])
|
||||
{
|
||||
parent::__construct($payload);
|
||||
|
||||
$this->payload['current_version'] = Extension::getVersion($this->payload['ext_xml']);
|
||||
$this->payload['latest_version'] = Extension::getLatestVersion($this->payload['ext_xml']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTitle()
|
||||
{
|
||||
return sprintf(Text::_('NR_EXTENSION_NEW_VERSION_IS_AVAILABLE'), $this->extension_name . ' v' . $this->payload['latest_version']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDescription()
|
||||
{
|
||||
return sprintf(Text::_('NR_EXTENSION_NOTICE_DESC'), $this->extension_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice actions.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getActions()
|
||||
{
|
||||
$url = Extension::getProductURL($this->payload['ext_xml']) . '/changelog';
|
||||
|
||||
return '<span class="orange-text text-bold">' . sprintf(Text::_('NR_YOUR_USING_VERSION'), $this->payload['current_version']) . '</span>
|
||||
<a href="' . \NRFramework\Functions::getUTMURL($url, 'UserNotice', 'Update') . '" target="_blank" class="tf-notice-btn outline">' . Text::_('NR_VIEW_CHANGELOG') . '</a>
|
||||
<a href="' . Uri::base() . 'index.php?option=com_installer&task=update.find&' . Session::getFormToken() . '=1" class="tf-notice-btn success">' . Text::_('NR_UPDATE_NOW') . '</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the notice can run.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function canRun()
|
||||
{
|
||||
// If cookie exists, its been hidden
|
||||
if ($this->factory->getCookie('tfNoticeHideUpdateNotice_' . $this->payload['ext_element']) === 'true')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$this->payload['latest_version'])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return version_compare($this->payload['latest_version'], $this->payload['current_version'], '>');
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link https://www.tassos.gr
|
||||
* @copyright Copyright © 2024 Tassos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Notices\Notices;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use \NRFramework\Extension;
|
||||
|
||||
class UpgradeToBundle extends Notice
|
||||
{
|
||||
/**
|
||||
* Define how old (in days) the extension needs to be since the installation date
|
||||
* in order to display this notice.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $upgrade_to_bundle_notice_days_old = 60;
|
||||
|
||||
protected $notice_payload = [
|
||||
'type' => 'success',
|
||||
'class' => 'upgradeToBundle'
|
||||
];
|
||||
|
||||
public function __construct($payload = [])
|
||||
{
|
||||
parent::__construct($payload);
|
||||
|
||||
$this->payload['tooltip'] = Text::_('NR_NOTICE_UPGRADE_TO_BUNDLE_TOOLTIP');
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTitle()
|
||||
{
|
||||
return Text::_('NR_UPGRADE_TO_BUNDLE');
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDescription()
|
||||
{
|
||||
return Text::_('NR_UPGRADE_TO_BUNDLE_NOTICE_DESC');
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice actions.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getActions()
|
||||
{
|
||||
$url = 'https://www.tassos.gr/bundle';
|
||||
|
||||
return '<a href="' . \NRFramework\Functions::getUTMURL($url, 'UserNotice', 'UpgradeToBundle') . '" target="_blank" class="tf-notice-btn success">' . Text::_('NR_UPGRADE_NOW') . '</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the notice can run.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function canRun()
|
||||
{
|
||||
// If cookie exists, its been hidden
|
||||
if ($this->factory->getCookie('tfNoticeHideUpgradeToBundleNotice_' . $this->payload['ext_element']) === 'true')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get license details for this extension
|
||||
if ($details = \NRFramework\Notices\Helper::getExtensionDetails($this->payload['license_data'], $this->payload['ext_element']))
|
||||
{
|
||||
// If we already have an active bundle plan, abort
|
||||
if (isset($details['active']) && isset($details['plan']) && $details['active'] && strtolower($details['plan']) === 'bundle')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// The user must have at least 2 installed tassos.gr extensions
|
||||
if (Extension::getTotalInstalledExtensions() < 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// User must have at least 1 paid subscription
|
||||
if (Extension::getUserTotalPaidPlans($this->payload['license_data']) < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get extension installation date
|
||||
if (!$install_date = Extension::getInstallationDate($this->payload['ext_element']))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the extension is not old enough, do not show the rate notice
|
||||
if ($this->getDaysDifference(time(), strtotime($install_date)) < $this->upgrade_to_bundle_notice_days_old)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link https://www.tassos.gr
|
||||
* @copyright Copyright © 2024 Tassos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Notices\Notices;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use \NRFramework\Extension;
|
||||
|
||||
class UpgradeToPro extends Notice
|
||||
{
|
||||
/**
|
||||
* Define how old (in days) the extension needs to be since the installation date
|
||||
* in order to display this notice.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $upgrade_to_pro_notice_days_old = 30;
|
||||
|
||||
protected $notice_payload = [
|
||||
'type' => 'success',
|
||||
'class' => 'upgradeToPro'
|
||||
];
|
||||
|
||||
public function __construct($payload = [])
|
||||
{
|
||||
parent::__construct($payload);
|
||||
|
||||
$this->payload['tooltip'] = Text::_('NR_NOTICE_UPGRADE_TO_PRO_TOOLTIP');
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getTitle()
|
||||
{
|
||||
return sprintf(Text::_('NR_UPGRADE_TO_PRO_X_OFF'), 20);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getDescription()
|
||||
{
|
||||
return sprintf(Text::_('NR_UPGRADE_TO_PRO_NOTICE_DESC'), $this->extension_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notice actions.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getActions()
|
||||
{
|
||||
$url = Extension::getTassosExtensionUpgradeURL($this->payload['ext_xml'], false);
|
||||
|
||||
return '<a href="' . \NRFramework\Functions::getUTMURL($url, 'UserNotice', 'UpgradeToPro') . '" target="_blank" class="tf-notice-btn success">' . Text::_('NR_UPGRADE_NOW') . '</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the notice can run.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function canRun()
|
||||
{
|
||||
// If cookie exists, its been hidden
|
||||
if ($this->factory->getCookie('tfNoticeHideUpgradeToProNotice_' . $this->payload['ext_element']) === 'true')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// If its already Pro, abort
|
||||
if (Extension::isPro($this->payload['ext_xml']))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get extension installation date
|
||||
if (!$install_date = Extension::getInstallationDate($this->payload['ext_element']))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the extension is not old enough, do not show the rate notice
|
||||
if ($this->getDaysDifference(time(), strtotime($install_date)) < $this->upgrade_to_pro_notice_days_old)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user