acf
This commit is contained in:
149
plugins/system/nrframework/helpers/field.php
Normal file
149
plugins/system/nrframework/helpers/field.php
Normal file
@ -0,0 +1,149 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Form\Field\TextField;
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Factory;
|
||||
|
||||
class NRFormField extends TextField
|
||||
{
|
||||
public $type = 'Field';
|
||||
|
||||
/**
|
||||
* Document object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $doc;
|
||||
|
||||
/**
|
||||
* Database object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $db;
|
||||
|
||||
/**
|
||||
* Application Object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
$this->doc = Factory::getDocument();
|
||||
$this->app = Factory::getApplication();
|
||||
$this->db = Factory::getDbo();
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the field label markup.
|
||||
*
|
||||
* @return string The field label markup.
|
||||
*/
|
||||
protected function getLabel()
|
||||
{
|
||||
$label = $this->get("label");
|
||||
if (empty($label))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
return parent::getLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares string through Text
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function prepareText($string = '')
|
||||
{
|
||||
$string = trim($string);
|
||||
|
||||
if ($string == '')
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
return Text::_($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get field parameters
|
||||
*
|
||||
* @param string $val Field parameter
|
||||
* @param string $default The default value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get($val, $default = '')
|
||||
{
|
||||
return (isset($this->element[$val]) && (string) $this->element[$val] != '') ? (string) $this->element[$val] : $default;
|
||||
}
|
||||
|
||||
public function getOptionsByList($list, $extras = array(), $levelOffset = 0)
|
||||
{
|
||||
$options = array();
|
||||
foreach ($list as $item)
|
||||
{
|
||||
$options[] = $this->getOptionByListItem($item, $extras, $levelOffset);
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function getOptionByListItem($item, $extras = array(), $levelOffset = 0)
|
||||
{
|
||||
$name = trim($item->name);
|
||||
|
||||
foreach ($extras as $key => $extra)
|
||||
{
|
||||
if (empty($item->{$extra}))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($extra == 'language' && $item->{$extra} == '*')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($extra, array('id', 'alias')) && $item->{$extra} == $item->name)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$name .= ' [' . $item->{$extra} . ']';
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/text.php';
|
||||
|
||||
$name = NRText::prepareSelectItem($name, isset($item->published) ? $item->published : 1);
|
||||
|
||||
$option = HTMLHelper::_('select.option', $item->id, $name, 'value', 'text', 0);
|
||||
|
||||
if (isset($item->level))
|
||||
{
|
||||
$option->level = $item->level + $levelOffset;
|
||||
}
|
||||
|
||||
return $option;
|
||||
}
|
||||
}
|
||||
83
plugins/system/nrframework/helpers/fieldlist.php
Normal file
83
plugins/system/nrframework/helpers/fieldlist.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Form\Field\ListField;
|
||||
use Joomla\CMS\Factory;
|
||||
|
||||
class NRFormFieldList extends ListField
|
||||
{
|
||||
/**
|
||||
* Document object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $doc;
|
||||
|
||||
/**
|
||||
* Database object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $db;
|
||||
|
||||
/**
|
||||
* Application Object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*/
|
||||
function __construct()
|
||||
{
|
||||
$this->doc = Factory::getDocument();
|
||||
$this->app = Factory::getApplication();
|
||||
$this->db = Factory::getDbo();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get the field label markup.
|
||||
*
|
||||
* @return string The field label markup.
|
||||
*/
|
||||
protected function getLabel()
|
||||
{
|
||||
$label = $this->get("label");
|
||||
if (empty($label))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
return parent::getLabel();
|
||||
}
|
||||
|
||||
protected function showSelect($default = "true")
|
||||
{
|
||||
return $this->get("showselect", $default) == "true" ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get field parameters
|
||||
*
|
||||
* @param string $val Field parameter
|
||||
* @param string $default The default value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get($val, $default = '')
|
||||
{
|
||||
return (isset($this->element[$val]) && (string) $this->element[$val] != '') ? (string) $this->element[$val] : $default;
|
||||
}
|
||||
}
|
||||
64
plugins/system/nrframework/helpers/groupfield.php
Normal file
64
plugins/system/nrframework/helpers/groupfield.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use \NRFramework\HTML;
|
||||
|
||||
require_once __DIR__ . '/field.php';
|
||||
|
||||
class NRFormGroupField extends NRFormField
|
||||
{
|
||||
public $type = 'Field';
|
||||
public $default_group = 'Categories';
|
||||
|
||||
protected function getInput()
|
||||
{
|
||||
return $this->getSelectList();
|
||||
}
|
||||
|
||||
public function getGroup()
|
||||
{
|
||||
return $this->get('group', $this->default_group ?: $this->type);
|
||||
}
|
||||
|
||||
public function getOptions()
|
||||
{
|
||||
$group = $this->getGroup();
|
||||
|
||||
$id = $this->type . '_' . $group;
|
||||
|
||||
$data[$id] = $this->{'get' . $group}();
|
||||
|
||||
return $data[$id];
|
||||
}
|
||||
|
||||
public function getSelectList($group = '')
|
||||
{
|
||||
if (!is_array($this->value))
|
||||
{
|
||||
$this->value = explode(',', $this->value);
|
||||
}
|
||||
|
||||
$size = (int) $this->get('size', 300);
|
||||
|
||||
$group = $group ?: $this->getGroup();
|
||||
$options = $this->getOptions();
|
||||
|
||||
switch ($group)
|
||||
{
|
||||
case 'categories':
|
||||
return HTML::treeselect($options, $this->name, $this->value, $this->id, $size, 0, $this->class);
|
||||
|
||||
default:
|
||||
return HTML::treeselectSimple($options, $this->name, $this->value, $this->id, $size, $this->class);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
280
plugins/system/nrframework/helpers/imageresize.php
Normal file
280
plugins/system/nrframework/helpers/imageresize.php
Normal file
@ -0,0 +1,280 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// no direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\Filesystem\Folder;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
|
||||
class NRFrameworkImage {
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
private $image;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $variables;
|
||||
|
||||
/**
|
||||
* @param $image
|
||||
*/
|
||||
function __construct($image)
|
||||
{
|
||||
$this->image = str_replace(Uri::root(true), '', $image);
|
||||
|
||||
if (substr($this->image, 0, 1) == "/")
|
||||
{
|
||||
$this->image = substr($this->image, 1);
|
||||
}
|
||||
|
||||
// Default values
|
||||
$this->variables = array (
|
||||
'height' => '100',
|
||||
'width' => '100',
|
||||
'ratio' => '1',
|
||||
'crop' => true,
|
||||
'quality' => 100,
|
||||
'cache' => true,
|
||||
'filename' => 'img_'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $width
|
||||
* @param $height
|
||||
*/
|
||||
public function setSize($width, $height) {
|
||||
$this->variables['width'] = (int) $width;
|
||||
$this->variables['height'] = (int) $height;
|
||||
$this->variables['ratio'] = ((int) $width / (int) $height);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $crop
|
||||
*/
|
||||
public function setCrop($crop) {
|
||||
$this->variables['crop'] = (bool) $crop;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $quality
|
||||
*/
|
||||
public function setQuality($quality) {
|
||||
$this->variables['quality'] = (int) $quality;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $cache
|
||||
*/
|
||||
public function setCache($cache) {
|
||||
$this->variables['cache'] = (bool) $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get some basic information from the source image
|
||||
* @return array
|
||||
*/
|
||||
private function imageInfo() {
|
||||
|
||||
$image = getimagesize($this->image);
|
||||
|
||||
$info = array();
|
||||
|
||||
$info['width'] = $image[0];
|
||||
$info['height'] = $image[1];
|
||||
$info['ratio'] = $image[0]/$image[1];
|
||||
$info['mime'] = $image['mime'];
|
||||
|
||||
return $info;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return resource
|
||||
* Loads the image
|
||||
*/
|
||||
private function openImage() {
|
||||
|
||||
switch ($this->imageInfo()['mime']) {
|
||||
case 'image/jpeg':
|
||||
$image = imagecreatefromjpeg ($this->image);
|
||||
break;
|
||||
|
||||
case 'image/png':
|
||||
$image = imagecreatefrompng ($this->image);
|
||||
imagealphablending( $image, true );
|
||||
imagesavealpha( $image, true );
|
||||
break;
|
||||
|
||||
case 'image/gif':
|
||||
$image = imagecreatefromgif ($this->image);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new RuntimeException('Unknown file type');
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $image
|
||||
* @return resource
|
||||
* Does the actual image resize
|
||||
*/
|
||||
private function resizeImage($image) {
|
||||
|
||||
if (!is_resource($image)) {
|
||||
throw new RuntimeException('Wrong path or this is not an image');
|
||||
}
|
||||
|
||||
$newImage = imagecreatetruecolor($this->variables['width'], $this->variables['height']);
|
||||
|
||||
if (($this->variables['crop'] == true) and ($this->imageInfo()['ratio'] != $this->variables['ratio'])) {
|
||||
|
||||
$src_x = $src_y = 0;
|
||||
$src_w = $this->imageInfo()['width'];
|
||||
$src_h = $this->imageInfo()['height'];
|
||||
|
||||
$cmp_x = $src_w / $this->variables['width'];
|
||||
$cmp_y = $src_h / $this->variables['height'];
|
||||
|
||||
// calculate x or y coordinate and width or height of source
|
||||
if ($cmp_x > $cmp_y) {
|
||||
|
||||
$src_w = round ($src_w / $cmp_x * $cmp_y);
|
||||
$src_x = round (($src_w - ($src_w / $cmp_x * $cmp_y)) / 2);
|
||||
|
||||
} else if ($cmp_y > $cmp_x) {
|
||||
|
||||
$src_h = round ($src_h / $cmp_y * $cmp_x);
|
||||
$src_y = round (($src_h - ($src_h / $cmp_y * $cmp_x)) / 2);
|
||||
|
||||
}
|
||||
|
||||
imagecopyresampled($newImage,
|
||||
$image,
|
||||
0, 0,
|
||||
$src_x,
|
||||
$src_y,
|
||||
$this->variables['width'],
|
||||
$this->variables['height'],
|
||||
$src_w,
|
||||
$src_h);
|
||||
|
||||
return $newImage;
|
||||
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
imagecopyresampled($newImage,
|
||||
$image,
|
||||
0, 0, 0, 0,
|
||||
$this->variables['width'],
|
||||
$this->variables['height'],
|
||||
$this->imageInfo()['width'],
|
||||
$this->imageInfo()['height']);
|
||||
|
||||
}
|
||||
|
||||
return $newImage;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* Generate the filename for the image, based on original name, width, height and quality
|
||||
*/
|
||||
private function createFilename() {
|
||||
return $this->variables['filename'].md5($this->image.$this->variables['width'].$this->variables['height'].$this->variables['quality']).'.jpg';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* Check if an image exists in the cache
|
||||
*/
|
||||
private function checkCache() {
|
||||
return file_exists(JPATH_SITE.'/cache/images/'.$this->createFilename());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the cache folder exists, and if not, it creates it *
|
||||
*/
|
||||
private function cacheFolder() {
|
||||
|
||||
if (!is_dir(JPATH_SITE.'/cache/images'))
|
||||
{
|
||||
try {
|
||||
Folder::create(JPATH_SITE.'/cache/images');
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
echo 'Caught exception: ', $e->getMessage(), "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $image
|
||||
* Saves the image
|
||||
* @throws ErrorException
|
||||
*/
|
||||
private function saveImage($image) {
|
||||
$this->cacheFolder();
|
||||
imageinterlace($image, true);
|
||||
$saved = imagejpeg($image, JPATH_SITE . '/cache/images/' . $this->createFilename(), $this->variables['quality']);
|
||||
if ($saved == false) {
|
||||
throw new ErrorException('Cannot save file, please check directory and permissions');
|
||||
}
|
||||
imagedestroy($image);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $image
|
||||
* Processes the image, unless it is already in the cache
|
||||
* @throws ErrorException
|
||||
* @returns string
|
||||
*/
|
||||
private function processImage($image) {
|
||||
|
||||
if (($this->variables['cache'] == true) and $this->checkCache()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
else {
|
||||
try {
|
||||
$newImage = $this->openImage($image);
|
||||
$newImage = $this->resizeImage($newImage);
|
||||
$this->saveImage($newImage);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
echo 'Caught exception: ', $e->getMessage(), "\n";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to process the image and get the new image's URL
|
||||
*/
|
||||
public function get() {
|
||||
|
||||
$this->processImage($this->image);
|
||||
return Uri::root(true).'/cache/images/'.$this->createFilename();
|
||||
|
||||
}
|
||||
}
|
||||
59
plugins/system/nrframework/helpers/text.php
Normal file
59
plugins/system/nrframework/helpers/text.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
|
||||
class NRText
|
||||
{
|
||||
|
||||
public static function prepareSelectItem($string, $published = 1, $type = '', $remove_first = 0)
|
||||
{
|
||||
if (empty($string))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$string = str_replace(array(' ', ' '), ' ', $string);
|
||||
$string = preg_replace('#- #', ' ', $string);
|
||||
|
||||
for ($i = 0; $remove_first > $i; $i++)
|
||||
{
|
||||
$string = preg_replace('#^ #', '', $string);
|
||||
}
|
||||
|
||||
if (preg_match('#^( *)(.*)$#', $string, $match))
|
||||
{
|
||||
list($string, $pre, $name) = $match;
|
||||
|
||||
$pre = preg_replace('# #', ' · ', $pre);
|
||||
$pre = preg_replace('#(( · )*) · #', '\1 » ', $pre);
|
||||
$pre = str_replace(' ', ' ', $pre);
|
||||
|
||||
$string = $pre . $name;
|
||||
}
|
||||
|
||||
switch (true)
|
||||
{
|
||||
case ($type == 'separator'):
|
||||
$string = $string;
|
||||
break;
|
||||
case (!$published):
|
||||
$string = $string . ' [' . Text::_('JUNPUBLISHED') . ']';
|
||||
break;
|
||||
case ($published == 2):
|
||||
$string = $string . ' [' . Text::_('JARCHIVED') . ']';
|
||||
break;
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
19
plugins/system/nrframework/helpers/urls/bitly.php
Normal file
19
plugins/system/nrframework/helpers/urls/bitly.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class nrURLShortBitly extends NRURLShortener
|
||||
{
|
||||
|
||||
function baseURL()
|
||||
{
|
||||
return 'http://api.bit.ly/v3/shorten?login='.$this->service->login.'&apiKey='.$this->service->api.'&format=txt&uri='.urlencode($this->url);
|
||||
}
|
||||
}
|
||||
58
plugins/system/nrframework/helpers/urls/google.php
Normal file
58
plugins/system/nrframework/helpers/urls/google.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use \Joomla\CMS\Http\HttpFactory;
|
||||
|
||||
class nrURLShortGoogle extends NRURLShortener
|
||||
{
|
||||
|
||||
function get()
|
||||
{
|
||||
|
||||
if (!$this->validateCredentials())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$baseURL = "https://www.googleapis.com/urlshortener/v1/url?key=".$this->service->api;
|
||||
|
||||
$data = '{ "longUrl": "'.$this->url.'" }';
|
||||
$headers['Content-Type'] = 'application/json';
|
||||
|
||||
try
|
||||
{
|
||||
$response = HttpFactory::getHttp()->post($baseURL, $data, $headers, 5);
|
||||
|
||||
if ($response === null || $response->code !== 200)
|
||||
{
|
||||
$result = json_decode($response->body);
|
||||
$this->throwError($result->error->message);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$this->throwError($e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = json_decode($response->body);
|
||||
|
||||
if (!isset($data->id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $data->id;
|
||||
}
|
||||
}
|
||||
140
plugins/system/nrframework/helpers/urls/shortener.php
Normal file
140
plugins/system/nrframework/helpers/urls/shortener.php
Normal file
@ -0,0 +1,140 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Http\HttpFactory;
|
||||
|
||||
/**
|
||||
* Framework URL Shortening Class
|
||||
* Should be extended. The get() method is required.
|
||||
*/
|
||||
class NRURLShortener {
|
||||
|
||||
/**
|
||||
* The Shortener Service
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $service;
|
||||
|
||||
/**
|
||||
* The URL to be shortened
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* Sets if the service needs a valid login name
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $needsLogin = true;
|
||||
|
||||
/**
|
||||
* Sets if the service needs a valid API Key
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $needsKey = true;
|
||||
|
||||
/**
|
||||
* Constructor of class
|
||||
*
|
||||
* @param object $service The Shortener service information
|
||||
* @param string $url The URL to be shortened
|
||||
*/
|
||||
public function __construct($service, $url) {
|
||||
$this->service = $service;
|
||||
$this->url = $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an exception
|
||||
*
|
||||
* @param string $msg
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function throwError($msg)
|
||||
{
|
||||
throw new Exception(Text::sprintf('NR_URL_SHORTENING_FAILED', $this->url, $this->service->name, $msg));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if credentials are set
|
||||
*
|
||||
* @return boolean Returns true if credentials are set
|
||||
*/
|
||||
protected function validateCredentials()
|
||||
{
|
||||
|
||||
if ($this->needsKey && !isset($this->service->api))
|
||||
{
|
||||
$this->throwError("API Key not set");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->needsLogin && !isset($this->service->login))
|
||||
{
|
||||
$this->throwError("Login not set");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortens the URL
|
||||
*
|
||||
* @return string On success returns the shortened URL
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
|
||||
if (!$this->validateCredentials())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$baseURL = $this->baseURL();
|
||||
|
||||
if (!$baseURL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$response = HttpFactory::getHttp()->get($baseURL, null, 5);
|
||||
|
||||
if ($response === null || $response->code !== 200)
|
||||
{
|
||||
$this->throwError($response->body);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (RuntimeException $e)
|
||||
{
|
||||
$this->throwError($e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return trim($response->body);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
23
plugins/system/nrframework/helpers/urls/tinyurl.php
Normal file
23
plugins/system/nrframework/helpers/urls/tinyurl.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class nrURLShortTinyURL extends NRURLShortener
|
||||
{
|
||||
|
||||
protected $needsKey = false;
|
||||
protected $needsLogin = false;
|
||||
|
||||
function baseURL()
|
||||
{
|
||||
return "http://tinyurl.com/api-create.php?url=".urlencode($this->url);
|
||||
}
|
||||
|
||||
}
|
||||
158
plugins/system/nrframework/helpers/urls/urls.php
Normal file
158
plugins/system/nrframework/helpers/urls/urls.php
Normal file
@ -0,0 +1,158 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use \NRFramework\Cache;
|
||||
|
||||
class NRURLs {
|
||||
|
||||
private $url;
|
||||
private $shortener;
|
||||
private $cache;
|
||||
|
||||
function __construct($url = null)
|
||||
{
|
||||
if (isset($url)) {
|
||||
$this->set($url);
|
||||
}
|
||||
|
||||
$this->setCache(true);
|
||||
}
|
||||
|
||||
public function set($url)
|
||||
{
|
||||
$url = trim(filter_var($url, FILTER_SANITIZE_URL));
|
||||
return ($this->url = $url);
|
||||
}
|
||||
|
||||
public function setCache($state)
|
||||
{
|
||||
$this->cache = (bool) $state;
|
||||
}
|
||||
|
||||
public function setShortener($service)
|
||||
{
|
||||
$this->shortener = $service;
|
||||
}
|
||||
|
||||
public function get()
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
public function validate($url_ = null)
|
||||
{
|
||||
$url = isset($url_) ? $url_ : $this->url;
|
||||
|
||||
if (!$url)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove all illegal characters from the URL
|
||||
$url = filter_var($url, FILTER_SANITIZE_URL);
|
||||
|
||||
// Validate URL
|
||||
if (!filter_var($url, FILTER_VALIDATE_URL) === false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getShort()
|
||||
{
|
||||
if (!$this->validate() || !isset($this->shortener))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$hash = MD5($this->shortener->name . $this->url);
|
||||
$cache = Cache::read($hash, true);
|
||||
|
||||
if ($cache)
|
||||
{
|
||||
return $cache;
|
||||
}
|
||||
|
||||
// Load Shorten Service Class
|
||||
$file = __DIR__ . "/" . strtolower($this->shortener->name) . '.php';
|
||||
$class = 'nrURLShort' . $this->shortener->name;
|
||||
$method = "get";
|
||||
|
||||
require_once(__DIR__ . "/shortener.php");
|
||||
|
||||
if (!class_exists($class) && file_exists($file)) {
|
||||
require_once($file);
|
||||
}
|
||||
|
||||
if (!class_exists($class) || !method_exists($class, $method))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$class_ = new $class($this->shortener, $this->url);
|
||||
$data = $class_->$method();
|
||||
|
||||
// Return the original URL if we don't have a valid short URL
|
||||
if (!$this->validate($data))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Cache::set($hash, $data);
|
||||
|
||||
// Store to cache
|
||||
if ($this->cache)
|
||||
{
|
||||
Cache::write($hash, $data);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends extra parameters to the end of the URL
|
||||
*
|
||||
* @param String $url Pass URL
|
||||
* @param String $params String of parameters (param=1¶m=2)
|
||||
*
|
||||
* @return string Returns new url
|
||||
*/
|
||||
public function appendParams($params)
|
||||
{
|
||||
|
||||
if (!$params)
|
||||
{
|
||||
return $this;
|
||||
}
|
||||
|
||||
$url = $this->url;
|
||||
|
||||
$query = parse_url($url, PHP_URL_QUERY);
|
||||
$params = trim($params, "?");
|
||||
$params = trim($params, "&");
|
||||
|
||||
if ($query)
|
||||
{
|
||||
$url .= '&' . $params;
|
||||
} else
|
||||
{
|
||||
$url .= '?' . $params;
|
||||
}
|
||||
|
||||
$this->set($url);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@ -0,0 +1,15 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is deprecated. Use \NRFramework\Integrations\ActiveCampaign instead.
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
@ -0,0 +1,15 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is deprecated. Use \NRFramework\Integrations\CampaignMonitor instead.
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
@ -0,0 +1,15 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is deprecated. Use \NRFramework\Integrations\ConstantContact instead.
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
15
plugins/system/nrframework/helpers/wrappers/convertkit.php
Normal file
15
plugins/system/nrframework/helpers/wrappers/convertkit.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is deprecated. Use \NRFramework\Integrations\ConvertKit instead.
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
15
plugins/system/nrframework/helpers/wrappers/drip.php
Normal file
15
plugins/system/nrframework/helpers/wrappers/drip.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is deprecated. Use \NRFramework\Integrations\Drip instead.
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
15
plugins/system/nrframework/helpers/wrappers/elasticemail.php
Normal file
15
plugins/system/nrframework/helpers/wrappers/elasticemail.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is deprecated. Use \NRFramework\Integrations\ElasticEmail instead.
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
15
plugins/system/nrframework/helpers/wrappers/getresponse.php
Normal file
15
plugins/system/nrframework/helpers/wrappers/getresponse.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is deprecated. Use \NRFramework\Integrations\GetResponse instead.
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
15
plugins/system/nrframework/helpers/wrappers/hubspot.php
Normal file
15
plugins/system/nrframework/helpers/wrappers/hubspot.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is deprecated. Use \NRFramework\Integrations\HubSpot instead.
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
15
plugins/system/nrframework/helpers/wrappers/icontact.php
Normal file
15
plugins/system/nrframework/helpers/wrappers/icontact.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is deprecated. Use \NRFramework\Integrations\iContact instead.
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
15
plugins/system/nrframework/helpers/wrappers/mailchimp.php
Normal file
15
plugins/system/nrframework/helpers/wrappers/mailchimp.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is deprecated. Use \NRFramework\Integrations\MailChimp instead.
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
15
plugins/system/nrframework/helpers/wrappers/recaptcha.php
Normal file
15
plugins/system/nrframework/helpers/wrappers/recaptcha.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is deprecated. Use \NRFramework\Integrations\ReCaptcha instead.
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
15
plugins/system/nrframework/helpers/wrappers/salesforce.php
Normal file
15
plugins/system/nrframework/helpers/wrappers/salesforce.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is deprecated. Use \NRFramework\Integrations\SalesForce instead.
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
15
plugins/system/nrframework/helpers/wrappers/sendinblue.php
Normal file
15
plugins/system/nrframework/helpers/wrappers/sendinblue.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is deprecated. Use \NRFramework\Integrations\SendInBlue instead.
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
15
plugins/system/nrframework/helpers/wrappers/zoho.php
Normal file
15
plugins/system/nrframework/helpers/wrappers/zoho.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is deprecated. Use \NRFramework\Integrations\ZoHo instead.
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
15
plugins/system/nrframework/helpers/wrappers/zohocrm.php
Normal file
15
plugins/system/nrframework/helpers/wrappers/zohocrm.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is deprecated. Use \NRFramework\Integrations\ZohoCRM instead.
|
||||
*/
|
||||
|
||||
// No direct access
|
||||
defined('_JEXEC') or die;
|
||||
Reference in New Issue
Block a user