primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

View File

@ -0,0 +1,227 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework;
defined('_JEXEC') or die();
class AutoLoader
{
/**
* Associative array where the key is a namespace prefix and the value
* is an array of base directories for classes in that namespace.
*
* @var array
*/
protected static $prefixes = [];
/**
* Associative array of prefixes for loading specialized camelCase classes
* where Uppercase letters in the class name indicate directory structure
*
* @var array
*/
protected static $camelPrefixes = [];
/**
* @var AutoLoader
*/
protected static $instance = null;
/**
* @param string $method
*
* @return void
*/
protected static function registerLoader(string $method)
{
if (static::$instance === null) {
static::$instance = new static();
}
spl_autoload_register([static::$instance, $method]);
}
/**
* Register a psr4 namespace
*
* @param ?string $prefix The namespace prefix.
* @param ?string $baseDir A base directory for class files in the
* namespace.
* @param ?bool $prepend If true, prepend the base directory to the stack
* instead of appending it; this causes it to be searched first rather
* than last.
*
* @return void
*/
public static function register(?string $prefix = null, ?string $baseDir = null, ?bool $prepend = false)
{
if ($prefix !== null && $baseDir !== null && is_dir($baseDir)) {
if (count(static::$prefixes) == 0) {
// Register function on first call
static::registerLoader('loadClass');
}
// normalize namespace prefix
$prefix = trim($prefix, '\\') . '\\';
// normalize the base directory with a trailing separator
$baseDir = rtrim($baseDir, '\\/') . '/';
// initialise the namespace prefix array
if (empty(static::$prefixes[$prefix])) {
static::$prefixes[$prefix] = [];
}
// retain the base directory for the namespace prefix
if ($prepend) {
$firstDir = static::$prefixes[$prefix][0] ?? null;
if ($firstDir != $baseDir) {
array_unshift(static::$prefixes[$prefix], $baseDir);
}
} else {
$lastDir = static::$prefixes[$prefix][count(static::$prefixes[$prefix]) - 1] ?? null;
if ($lastDir != $baseDir) {
static::$prefixes[$prefix][] = $baseDir;
}
}
}
}
/**
* Loads the namespaced class file for a given class name.
*
* @param string $class The fully-qualified class name.
*
* @return ?string The mapped file name on success, or boolean false on failure.
*/
protected function loadClass(string $class): ?string
{
$prefixes = explode('\\', $class);
$className = '';
while ($prefixes) {
$className = array_pop($prefixes) . $className;
$prefix = join('\\', $prefixes) . '\\';
if ($filePath = $this->loadMappedFile($prefix, $className)) {
return $filePath;
}
$className = '\\' . $className;
}
return null;
}
/**
* Load the mapped file for a namespace prefix and class.
*
* @param string $prefix The namespace prefix.
* @param string $className The relative class name.
*
* @return ?string false if no mapped file can be loaded | path that was loaded
*/
protected function loadMappedFile(string $prefix, string $className): ?string
{
// are there any base directories for this namespace prefix?
if (isset(static::$prefixes[$prefix]) === false) {
return null;
}
// look through base directories for this namespace prefix
foreach (static::$prefixes[$prefix] as $baseDir) {
$path = $baseDir . str_replace('\\', '/', $className) . '.php';
if (is_file($path)) {
require_once $path;
return $path;
}
}
return null;
}
/**
* Register a base directory for classes organized using camelCase.
* Class names beginning with the prefix will be automatically loaded
* if there is a matching file in the directory tree starting with $baseDir.
* File names and directory names are all expected to be lower case.
*
* Example:
*
* $prefix = 'Simplerenew'
* $baseDir = '/library/joomla'
*
* A class name of: SimplerenewViewAdmin
* Would be in : /library/joomla/view/admin.php
*
* This system is intended for situations where full name spacing is either
* unavailable or impractical due to integration with other systems.
*
* @param string $prefix
* @param string $baseDir
*
* @return void
*/
public static function registerCamelBase(string $prefix, string $baseDir)
{
if (is_dir($baseDir)) {
if (count(static::$camelPrefixes) == 0) {
// Register function on first call
static::registerLoader('loadCamelClass');
}
if (empty(static::$camelPrefixes[$prefix])) {
static::$camelPrefixes[$prefix] = $baseDir;
}
}
}
/**
* Autoload a class using the camelCase structure
*
* @param string $class
*
* @return ?string
*/
protected function loadCamelClass(string $class): ?string
{
if (!class_exists($class)) {
foreach (static::$camelPrefixes as $prefix => $baseDir) {
if (strpos($class, $prefix) === 0) {
$parts = preg_split('/(?<=[a-z])(?=[A-Z])/x', substr($class, strlen($prefix)));
$file = strtolower(join('/', $parts));
$filePath = $baseDir . '/' . $file . '.php';
if (is_file($filePath)) {
require_once $filePath;
return $filePath;
}
}
}
}
return null;
}
}

View File

@ -0,0 +1,224 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework;
defined('_JEXEC') or die();
class Base
{
public const MAP_UNDEFINED = 'undefined';
/**
* Retrieve all public properties and their values
* Although this duplicates get_object_vars(), it
* is mostly useful for internal calls when we need
* to filter out the non-public properties.
*
* @param bool $publicOnly
*
* @return array
*/
public function getProperties($publicOnly = true)
{
$reflection = new \ReflectionObject($this);
$properties = $reflection->getProperties(\ReflectionProperty::IS_PUBLIC);
if (!$publicOnly) {
$properties = array_merge(
$properties,
$reflection->getProperties(\ReflectionProperty::IS_PROTECTED)
);
}
$data = [];
foreach ($properties as $property) {
$name = $property->name;
$data[$name] = $this->{$name};
}
return $data;
}
/**
* Set the public properties from the passed array/object
*
* @param array|Base $data Values to copy to $this
* @param ?array $map Use properties from $data translated using a field map
*
* @return $this
* @throws Exception
*/
public function setProperties($data, ?array $map = null)
{
$properties = $this->getProperties();
if ($map !== null) {
$data = $this->map($data, array_keys($properties), $map);
} elseif (is_object($data)) {
$data = get_object_vars($data);
}
if (!is_array($data)) {
throw new Exception('Invalid argument given - ' . gettype($data));
}
foreach ($data as $k => $v) {
if (array_key_exists($k, $properties)) {
$this->{$k} = $v;
}
}
return $this;
}
/**
* Set all properties to null
*
* @param bool $publicOnly Pass false to include protected properties as well
*
* @return $this
*/
public function clearProperties($publicOnly = true)
{
$properties = array_keys($this->getProperties($publicOnly));
foreach ($properties as $property) {
$this->{$property} = null;
}
return $this;
}
/**
* Map values in a source object/array to Joomlashack Framework keys using a map
* of key equivalences. Any fields in $keys not present in $map will be
* mapped name to name. Map fields mapped to null will be ignored.
*
* Special mappings for field values are recognized with another array. e.g.:
*
* $map['status'] = array(
* 'state' => array(
* 'active' => 1,
* 'closed' => 0,
* Object::MAP_UNDEFINED => -1
* )
* )
* Will map the extension field 'status' to the source field 'state' and
* set status based on the value in the state field. If no match, Object::MAP_UNDEFINED
* will be used for the unknown value.
*
*
* @param array|object $source Source data to be mapped
* @param array $keys Extension keys for which values are being requested
* @param array $map Associative array where key=Extension Key, value=Source Key
*
* @return array An array of all specified keys with values filled in based on map
* @throws Exception
*/
public function map($source, array $keys, array $map = [])
{
if (!is_object($source) && !is_array($source)) {
throw new Exception('Expected array or object for source argument');
}
$result = array_fill_keys($keys, null);
foreach ($keys as $srKey) {
$value = null;
if (!array_key_exists($srKey, $map)) {
$field = $srKey;
$value = $this->getKeyValue($source, $field);
} else {
// This is a mapped key
$field = $map[$srKey];
if (!is_array($field)) {
$value = $this->getKeyValue($source, $field);
} else {
// Mapped to field value
$values = reset($map[$srKey]);
$field = key($map[$srKey]);
$srcValue = $this->getKeyValue($source, $field);
if (isset($values[$srcValue])) {
$value = $values[$srcValue];
} elseif (isset($values[self::MAP_UNDEFINED])) {
$value = $values[self::MAP_UNDEFINED];
}
}
}
$result[$srKey] = $value;
}
return $result;
}
/**
* Safely get a value from an object|array
*
* @param Base|array $data
* @param string $var
* @param mixed $default
*
* @return mixed
*/
public function getKeyValue($data, $var, $default = null)
{
if (is_object($data)) {
return $data->{$var} ?? $default;
}
return $data[$var] ?? $default;
}
/**
*
* Default string rendering for the object. Subclasses should feel
* free to override as desired.
*
* @return string
*/
public function asString()
{
return get_class($this);
}
/**
* Expose properties with defined getters for direct use
*
* @param $name
*
* @return mixed
*/
public function __get($name)
{
$method = 'get' . ucfirst($name);
if (method_exists($this, $method)) {
return $this->$method();
}
return null;
}
/**
* @return string
*/
public function __toString()
{
return $this->asString();
}
}

View File

@ -0,0 +1,340 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2022-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework;
use Joomla\String\StringHelper;
defined('_JEXEC') or die();
abstract class Color
{
/**
* 140 color names recognized by browsers (Aug 2022)
*
* @var string[]
*/
protected static $colorNames = [
'aliceblue' => '#F0F8FF',
'antiquewhite' => '#FAEBD7',
'aqua' => '#00FFFF',
'aquamarine' => '#7FFFD4',
'azure' => '#F0FFFF',
'beige' => '#F5F5DC',
'bisque' => '#FFE4C4',
'black' => '#000000',
'blanchedalmond' => '#FFEBCD',
'blue' => '#0000FF',
'blueviolet' => '#8A2BE2',
'brown' => '#A52A2A',
'burlywood' => '#DEB887',
'cadetblue' => '#5F9EA0',
'chartreuse' => '#7FFF00',
'chocolate' => '#D2691E',
'coral' => '#FF7F50',
'cornflowerblue' => '#6495ED',
'cornsilk' => '#FFF8DC',
'crimson' => '#DC143C',
'cyan' => '#00FFFF',
'darkblue' => '#00008B',
'darkcyan' => '#008B8B',
'darkgoldenrod' => '#B8860B',
'darkgray' => '#A9A9A9',
'darkgreen' => '#006400',
'darkkhaki' => '#BDB76B',
'darkmagenta' => '#8B008B',
'darkolivegreen' => '#556B2F',
'darkorange' => '#FF8C00',
'darkorchid' => '#9932CC',
'darkred' => '#8B0000',
'darksalmon' => '#E9967A',
'darkseagreen' => '#8FBC8F',
'darkslateblue' => '#483D8B',
'darkslategray' => '#2F4F4F',
'darkturquoise' => '#00CED1',
'darkviolet' => '#9400D3',
'deeppink' => '#FF1493',
'deepskyblue' => '#00BFFF',
'dimgray' => '#696969',
'dodgerblue' => '#1E90FF',
'firebrick' => '#B22222',
'floralwhite' => '#FFFAF0',
'forestgreen' => '#228B22',
'fuchsia' => '#FF00FF',
'gainsboro' => '#DCDCDC',
'ghostwhite' => '#F8F8FF',
'gold' => '#FFD700',
'goldenrod' => '#DAA520',
'gray' => '#808080',
'green' => '#008000',
'greenyellow' => '#ADFF2F',
'honeydew' => '#F0FFF0',
'hotpink' => '#FF69B4',
'indianred' => '#CD5C5C',
'indigo' => '#4B0082',
'ivory' => '#FFFFF0',
'khaki' => '#F0E68C',
'lavender' => '#E6E6FA',
'lavenderblush' => '#FFF0F5',
'lawngreen' => '#7CFC00',
'lemonchiffon' => '#FFFACD',
'lightblue' => '#ADD8E6',
'lightcoral' => '#F08080',
'lightcyan' => '#E0FFFF',
'lightgoldenrodyellow' => '#FAFAD2',
'lightgrey' => '#D3D3D3',
'lightgreen' => '#90EE90',
'lightpink' => '#FFB6C1',
'lightsalmon' => '#FFA07A',
'lightseagreen' => '#20B2AA',
'lightskyblue' => '#87CEFA',
'lightslategray' => '#778899',
'lightsteelblue' => '#B0C4DE',
'lightyellow' => '#FFFFE0',
'lime' => '#00FF00',
'limegreen' => '#32CD32',
'linen' => '#FAF0E6',
'magenta' => '#FF00FF',
'maroon' => '#800000',
'mediumaquamarine' => '#66CDAA',
'mediumblue' => '#0000CD',
'mediumorchid' => '#BA55D3',
'mediumpurple' => '#9370D8',
'mediumseagreen' => '#3CB371',
'mediumslateblue' => '#7B68EE',
'mediumspringgreen' => '#00FA9A',
'mediumturquoise' => '#48D1CC',
'mediumvioletred' => '#C71585',
'midnightblue' => '#191970',
'mintcream' => '#F5FFFA',
'mistyrose' => '#FFE4E1',
'moccasin' => '#FFE4B5',
'navajowhite' => '#FFDEAD',
'navy' => '#000080',
'oldlace' => '#FDF5E6',
'olive' => '#808000',
'olivedrab' => '#6B8E23',
'orange' => '#FFA500',
'orangered' => '#FF4500',
'orchid' => '#DA70D6',
'palegoldenrod' => '#EEE8AA',
'palegreen' => '#98FB98',
'paleturquoise' => '#AFEEEE',
'palevioletred' => '#D87093',
'papayawhip' => '#FFEFD5',
'peachpuff' => '#FFDAB9',
'peru' => '#CD853F',
'pink' => '#FFC0CB',
'plum' => '#DDA0DD',
'powderblue' => '#B0E0E6',
'purple' => '#800080',
'red' => '#FF0000',
'rosybrown' => '#BC8F8F',
'royalblue' => '#4169E1',
'saddlebrown' => '#8B4513',
'salmon' => '#FA8072',
'sandybrown' => '#F4A460',
'seagreen' => '#2E8B57',
'seashell' => '#FFF5EE',
'sienna' => '#A0522D',
'silver' => '#C0C0C0',
'skyblue' => '#87CEEB',
'slateblue' => '#6A5ACD',
'slategray' => '#708090',
'snow' => '#FFFAFA',
'springgreen' => '#00FF7F',
'steelblue' => '#4682B4',
'tan' => '#D2B48C',
'teal' => '#008080',
'thistle' => '#D8BFD8',
'tomato' => '#FF6347',
'turquoise' => '#40E0D0',
'violet' => '#EE82EE',
'wheat' => '#F5DEB3',
'white' => '#FFFFFF',
'whitesmoke' => '#F5F5F5',
'yellow' => '#FFFF00',
'yellowgreen' => '#9ACD32',
];
/**
* Darken or lighten a color from a named or hex color string. Leading
* hash mark is optional and the result will be returned in the
* same format.
*
* $percent == 100 means no change.
* $percent > 100 means lighten
* $percent < 100 means darken
*
* Since the math will generate floating point numbers, and we need integers,
* by default the result will be the next highest integer. More subtle results
* may be obtained by using rounding.
*
* @see https://gist.github.com/stephenharris/5532899
*
* @param string $color
* @param float $percent
* @param bool $useRounding
*
* @return string
*/
public static function adjust(string $color, float $percent, ?bool $useRounding = false): string
{
$hexColor = static::nameToHex($color);
if (empty($hexColor)) {
// Bad color string given
return $color;
}
$hash = strpos($color, '#') === 0 ? '#' : '';
$rawHex = str_replace('#', '', $hexColor);
switch (strlen($rawHex)) {
case 3:
$color = array_map(
function ($hex) {
return $hex . $hex;
},
str_split($rawHex)
);
break;
case 6:
$color = str_split($rawHex, 2);
break;
default:
// It's just wrong, so just send it back
return $color;
}
$color = array_map('hexdec', $color);
foreach ($color as &$value) {
$value = $value * ($percent / 100);
}
$color = array_map(
function ($value) use ($useRounding) {
$value = $useRounding ? round($value) : ceil($value);
return str_pad(dechex($value), 2, '0', STR_PAD_LEFT);
},
$color
);
return $hash . join('', $color);
}
/**
* Determine if a color is brighter than some midpoint. By default,
* half of pure white (255/2) is used
*
* See: https://www.w3.org/TR/AERT/#color-contrast
*
* @param ?string $color
* @param ?float $midpoint
*
* @return bool
*/
public static function isTooBright(?string $color, float $midpoint = 127.5): bool
{
$rgb = static::hexToRgb(static::nameToHex($color));
if ($rgb) {
$whiteValue = (($rgb['r'] * .299) + ($rgb['g'] * .587) + ($rgb['b'] * .114));
return $whiteValue > $midpoint;
}
return false;
}
/**
* Converts a 3 or 6 character hex color to an rgb array
*
* @param ?string $hex
*
* @return ?string[]
*/
public static function hexToRgb(?string $hex): ?array
{
if ($hex) {
// Strip hash if needed
if (strpos($hex, '#') === 0) {
$hex = trim($hex, '#');
}
$hexType = StringHelper::strlen($hex);
if (in_array($hexType, [3, 6]) && preg_match('/[0-9a-fA-F]/', $hex)) {
// Valid hex code in short or full form
switch ($hexType) {
case 3:
$rgb = array_map(
function ($c) {
return str_repeat($c, 2);
},
StringHelper::str_split($hex, 1)
);
break;
case 6:
$rgb = StringHelper::str_split($hex, 2);
break;
}
return array_map(
'hexdec',
array_combine(
['r', 'g', 'b'],
$rgb
)
);
}
return null;
}
}
/**
* @param string $name
*
* @return ?string
*/
public static function nameToHex(string $name): ?string
{
$hex = null;
$hashtag = strpos($name, '#');
if ($hashtag === false) {
$hex = static::$colorNames[strtolower($name)] ?? $hex;
} elseif ($hashtag === 0) {
$hex = $name;
} elseif (in_array(strlen($name), [3, 6])) {
$hex = '#' . $name;
}
return $hex;
}
}

View File

@ -0,0 +1,195 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Content;
use Alledia\Framework\Base;
use Joomla\Registry\Registry;
defined('_JEXEC') or die();
class Tag extends Base
{
/**
* The unparsed tag string
*
* @var string
*/
protected $unparsedString = null;
/**
* The tag name
*
* @var string
*/
protected $name = null;
/**
* The tag content
*
* @var string
*/
protected $content = '';
/**
* The regex used to find the tag
*
* @var string
*/
protected $regex = null;
/**
* The tag params
*
* @var Registry
*/
public $params = null;
/**
* Constructor method, that defines the internal content
*
* @param string $name
* @param string $unparsedString
*
* @return void
*/
public function __construct($name, $unparsedString)
{
$this->name = $name;
$this->unparsedString = $unparsedString;
$this->regex = static::getRegex($this->name);
$this->parse();
}
/**
* Return the regex used to find tags inside a text.
*
* @param string $tagName
*
* @return string
*/
public static function getRegex($tagName)
{
return '/\{' . $tagName . '(?:(?!\{\/' . $tagName
. '\}).)*\}[\s]*([^{]*)[\s]*\{\/' . $tagName . '\}/i';
}
/**
* Parse this tag storing the content and params.
*
* @return void
*/
protected function parse()
{
$this->content = $this->parseContent();
$this->params = $this->parseParams();
}
/**
* Parse the {tagName}{/tagName} returning the content
*
* @return string
*/
protected function parseContent()
{
$content = '';
if (!empty($this->unparsedString)) {
if (strpos($this->unparsedString, '{' . $this->name) !== false) {
// Check if the source has the tag name
if (preg_match($this->regex, $this->unparsedString, $match)) {
$content = trim($match[1]);
}
}
}
return trim($content);
}
/**
* Parse inline parameters from the tag
*
* @return Registry
*/
protected function parseParams()
{
// Remove the tag name, extracting only the tag attributes
$inlineParams = preg_replace('/^{' . $this->name . '/', '', $this->unparsedString);
$inlineParams = trim(preg_replace('/}[a-z0-9\s]*{\/' . $this->name . '}/', '', $inlineParams));
// Parse the inline params
$regex = '/([a-z0-9_]*)(?:="([^"]*)")?\s?/i';
$parsed = new Registry();
if (preg_match_all($regex, $inlineParams, $vars)) {
$fullParams = $vars[0];
$paramNames = $vars[1];
$paramValues = $vars[2];
foreach ($fullParams as $i => $param) {
if (!empty($paramNames[$i])) {
$parsed->set(trim($paramNames[$i]), trim($paramValues[$i]));
}
}
}
return $parsed;
}
/**
* Return the unparsed string
*
* @return string
*/
public function toString()
{
return $this->unparsedString;
}
/**
* Returns the tag content
*
* @return string
*/
public function getContent()
{
return $this->content;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @return Registry
*/
public function getParams()
{
return $this->params;
}
}

View File

@ -0,0 +1,94 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Content;
use Alledia\Framework\Base;
defined('_JEXEC') or die();
class Text extends Base
{
public $content = '';
/**
* Constructor method, that defines the internal content
*
* @param string $content
*/
public function __construct($content)
{
$this->content = $content;
}
/**
* Extract multiple {mytag} tags from the content
*
* @todo Recognize unclose tags like {dumbtag param1="12"}
*
* @param string $tagName
*
* @return array An array with all tags {tagName} found on the text
*/
protected function extractPluginTags($tagName)
{
preg_match_all(Tag::getRegex($tagName), $this->content, $matches);
return $matches[0];
}
/**
* Extract multiple {mytag} tags from the content, returning
* as Tag instances
*
* @param string $tagName
*
* @return Tag[] An array with all tags {tagName} found on the text
*/
public function getPluginTags($tagName)
{
$unparsedTags = $this->extractPluginTags($tagName);
$tags = [];
foreach ($unparsedTags as $unparsedTag) {
$tags[] = new Tag($tagName, $unparsedTag);
}
return $tags;
}
/**
* Extract multiple {mytag} tags from the content, returning
* as Tag instances
*
* @param string $tagName
*
* @return array An array with all tags {tagName} found on the text
* @deprecated 1.3.1 Use getPluginsTags instead
*/
public function getTags($tagName)
{
// Deprecated. Use getPluginTags instead
return $this->getPluginTags($tagName);
}
}

View File

@ -0,0 +1,93 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework;
defined('_JEXEC') or die();
class Exception extends \Exception
{
/**
* Set error message to include class::method() information. Could be used live
* but very helpful during development.
*
* @return string
*/
public function getTraceMessage()
{
$trace = $this->getTrace();
$caller = array_shift($trace);
$result = '';
if (!empty($caller['class'])) {
$result .= $caller['class'] . '::';
}
if (!empty($caller['function'])) {
$result .= $caller['function'] . '()';
}
return trim($result . ' ' . $this->message);
}
/**
* Get single line listing of call stack
*
* @return array
*/
public function getCallStack()
{
$trace = $this->getTrace();
$stack = [];
foreach ($trace as $caller) {
$row = 'Line ' . (empty($caller['line']) ? '' : $caller['line'] . ' - ');
if (!empty($caller['class'])) {
$row .= $caller['class'] . '::';
}
if (!empty($caller['function'])) {
$row .= $caller['function'] . '()';
}
if (!empty($caller['file'])) {
$row .= ' [' . $caller['file'] . ']';
}
$stack[] = $row;
}
return $stack;
}
/**
* Allow custom exceptions to be created. Note
* that
*
* @param string $file
*
* @return void
*/
public function setLocation(string $file, int $line)
{
$this->file = $file;
$this->line = $line;
}
}

View File

@ -0,0 +1,33 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Exception;
use Alledia\Framework\Exception;
defined('_JEXEC') or die();
class NotFound extends Exception
{
}

View File

@ -0,0 +1,125 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework;
use Alledia\Framework\Joomla\Extension\Licensed;
use JEventDispatcher;
use Joomla\CMS\Version;
use Joomla\Database\DatabaseDriver;
use Joomla\Event\DispatcherInterface;
use Joomla\Event\Event;
defined('_JEXEC') or die();
abstract class Factory extends \Joomla\CMS\Factory
{
/**
* Instances of extensions
*
* @var array
*/
protected static $extensionInstances = [];
/**
* @var JEventDispatcher|DispatcherInterface
*/
protected static $dispatcher = null;
/**
* Get an extension
*
* @param string $namespace The extension namespace
* @param string $type The extension type
* @param string $folder The extension folder (plugins only)
*
* @return Licensed The extension instance
*/
public static function getExtension($namespace, $type, $folder = null)
{
$key = $namespace . $type . $folder;
if (empty(static::$extensionInstances[$key])) {
$instance = new Joomla\Extension\Licensed($namespace, $type, $folder);
static::$extensionInstances[$key] = $instance;
}
return static::$extensionInstances[$key];
}
/**
* @return \JDatabaseDriver|DatabaseDriver
*/
public static function getDatabase()
{
if (is_callable([static::class, 'getContainer'])) {
return static::getContainer()->get('DatabaseDriver');
}
return static::getDbo();
}
/**
* @return JEventDispatcher|DispatcherInterface
*/
public static function getDispatcher()
{
if (Version::MAJOR_VERSION < 4) {
if (static::$dispatcher === null) {
static::$dispatcher = JEventDispatcher::getInstance();
}
return static::$dispatcher;
}
return static::getApplication()->getDispatcher();
}
/**
* @param string $eventName
* @param array $args
*
* @return array
*/
public static function triggerEvent(string $eventName, array $args)
{
try {
$dispatcher = static::getDispatcher();
} catch (\UnexpectedValueException $exception) {
// ignore for now
return [];
}
if (Version::MAJOR_VERSION < 4) {
$result = $dispatcher->trigger($eventName, $args);
} else {
$event = new Event($eventName, $args);
$result = $dispatcher->dispatch($eventName, $event);
$result = $result['result'] ?? [];
}
return $result;
}
}

View File

@ -0,0 +1,280 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework;
use Alledia\Framework\Joomla\Extension\Helper as ExtensionHelper;
use Joomla\CMS\Form\Form;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Version;
use Joomla\Database\DatabaseDriver;
use Joomla\Database\DatabaseQuery;
use ReflectionMethod;
defined('_JEXEC') or die();
abstract class Helper
{
/**
* @var int[]
*/
protected static $errorConstants = null;
/**
* Return an array of Alledia extensions
*
* @param ?string $license
*
* @return object[]
*/
public static function getAllediaExtensions(?string $license = ''): array
{
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select([
$db->quoteName('extension_id'),
$db->quoteName('type'),
$db->quoteName('element'),
$db->quoteName('folder'),
])
->from('#__extensions')
->where([
sprintf('%s LIKE %s', $db->quoteName('custom_data'), $db->quote('%"author":"Alledia"%')),
sprintf('%s LIKE %s', $db->quoteName('custom_data'), $db->quote('%"author":"OSTraining"%')),
sprintf('%s LIKE %s', $db->quoteName('custom_data'), $db->quote('%"author":"Joomlashack"%')),
sprintf('%s LIKE %s', $db->quoteName('manifest_cache'), $db->quote('%"author":"Alledia"%')),
sprintf('%s LIKE %s', $db->quoteName('manifest_cache'), $db->quote('%"author":"OSTraining"%')),
sprintf('%s LIKE %s', $db->quoteName('manifest_cache'), $db->quote('%"author":"Joomlashack"%')),
], 'OR')
->group($db->quoteName('extension_id'));
$rows = $db->setQuery($query)->loadObjectList();
$extensions = [];
foreach ($rows as $row) {
if ($fullElement = ExtensionHelper::getFullElementFromInfo($row->type, $row->element, $row->folder)) {
if ($extensionInfo = ExtensionHelper::getExtensionInfoFromElement($fullElement)) {
$extension = new Joomla\Extension\Licensed($extensionInfo['namespace'], $row->type, $row->folder);
if (
empty($license)
||
($license == 'pro' && $extension->isPro())
|| ($license == 'free' && $extension->isFree())
) {
$extensions[$row->extension_id] = $extension;
}
}
}
}
return $extensions;
}
/**
* @return string
*/
public static function getJoomlaVersionCssClass(): string
{
return sprintf('joomla%sx', Version::MAJOR_VERSION);
}
/**
* Create class alias for classes that may not exist
*
* @param array $classes
*
* @return void
*/
public static function createClassAliases(array $classes): void
{
foreach ($classes as $class => $classAlias) {
if (class_exists($classAlias) == false) {
class_alias($class, $classAlias);
}
}
}
/**
* Create common database class aliases for classes that don't exist
*
* @return void
*/
public static function createDatabaseClassAliases(): void
{
static::createClassAliases([
\JDatabaseQuery::class => DatabaseQuery::class,
\JDatabaseDriver::class => DatabaseDriver::class,
]);
}
/**
* @param string $className
* @param string $methodName
* @param array $params
*
* @return mixed
*/
public static function callMethod(string $className, string $methodName, ?array $params = [])
{
$result = true;
if (method_exists($className, $methodName)) {
$method = new ReflectionMethod($className, $methodName);
if ($method->isStatic()) {
$result = call_user_func_array("{$className}::{$methodName}", $params);
} else {
// Check if we have a singleton class
if (method_exists($className, 'getInstance')) {
$instance = $className::getInstance();
} else {
$instance = new $className();
}
$result = call_user_func_array([$instance, $methodName], $params);
}
}
return $result;
}
/**
* @param string $name
*
* @return Form
*/
public static function createForm(string $name): Form
{
$form = new Form($name);
$form->load('<?xml version="1.0" encoding="UTF-8"?><form/>');
return $form;
}
/**
* @param string $name
* @param ?string $appName
* @param ?array $options
*
* @return mixed
*/
public static function getContentModel(string $name, ?string $appName = null, array $options = [])
{
return static::getJoomlaModel($name, 'ContentModel', 'com_content', $appName, $options);
}
/**
* @param string $name
* @param ?string $appName
* @param ?array $options
*
* @return mixed
*/
public static function getCategoryModel(string $name, ?string $appName = null, ?array $options = [])
{
return static::getJoomlaModel($name, 'CategoriesModel', 'com_categories', $appName, $options);
}
/**
* @param string $name
* @param string $prefix
* @param string $component
* @param ?string $appName
* @param ?array $options
*
* @return mixed
* @throws \Exception
*/
public static function getJoomlaModel(
string $name,
string $prefix,
string $component,
?string $appName = null,
?array $options = []
) {
$defaultApp = 'Site';
$appNames = [$defaultApp, 'Administrator'];
$appName = ucfirst($appName ?: $defaultApp);
$appName = in_array($appName, $appNames) ? $appName : $defaultApp;
$basePath = $appName == 'Administrator' ? JPATH_ADMINISTRATOR : JPATH_SITE;
$componentPath = $basePath . '/components/' . $component;
Table::addIncludePath($componentPath . '/tables');
Form::addFormPath($componentPath . '/forms');
Form::addFormPath($componentPath . '/models/forms');
Form::addFieldPath($componentPath . '/models/fields');
Form::addFormPath($componentPath . '/model/form');
Form::addFieldPath($componentPath . '/model/field');
if (Version::MAJOR_VERSION < 4) {
BaseDatabaseModel::addIncludePath($componentPath . '/models');
$model = BaseDatabaseModel::getInstance($name, $prefix, $options);
} else {
$model = Factory::getApplication()->bootComponent($component)
->getMVCFactory()->createModel($name, $appName, $options);
}
return $model;
}
/**
* For use by custom error handlers created using
* set_error_handler() intended to catch php errors.
*
* @param int $number
* @param string $message
* @param string $file
* @param int $line
*
* @return Exception
*/
public static function errorToException(int $number, string $message, string $file, int $line): Exception
{
if (static::$errorConstants === null) {
static::$errorConstants = [];
$allErrors = get_defined_constants(true);
foreach ($allErrors['Core'] as $name => $value) {
if (strpos($name, 'E_') === 0) {
static::$errorConstants[$name] = $value;
}
}
}
$error = array_search($number, static::$errorConstants);
$message = sprintf('%s - %s', $error === false ? $number : $error, $message);
$exception = new Exception($message, 0);
$exception->setLocation($file, $line);
return $exception;
}
}

View File

@ -0,0 +1,63 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla;
use Alledia\Framework\Factory;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Version;
defined('_JEXEC') or die();
abstract class AbstractTable extends Table
{
/**
* Joomla version agnostic loading of other component tables
*
* @param string $component
* @param string $name
* @param string $prefix
*
* @return ?Table
*/
public static function getComponentInstance($component, $name, $prefix): ?Table
{
if (Version::MAJOR_VERSION < 4) {
Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/' . $component . '/tables');
$table = Table::getInstance($name, $prefix);
} else {
try {
$table = Factory::getApplication()
->bootComponent($component)
->getMVCFactory()
->createTable($name, 'Administrator');
} catch (\Throwable $error) {
// Ignore
}
}
return $table ?? null;
}
}

View File

@ -0,0 +1,130 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2021-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla;
use Joomla\CMS\Form\Form;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\MVC\View\HtmlView;
use Joomla\CMS\Object\CMSObject;
defined('_JEXEC') or die();
abstract class AbstractView extends HtmlView
{
use TraitAllediaView;
/**
* @var BaseDatabaseModel
*/
protected $model = null;
/**
* Formally declare this since Joomla core does not
*
* @var Form
*/
protected $form = null;
/**
* @var CMSObject
*/
protected $state = null;
/**
* @inheritDoc
* @throws \Exception
*/
public function __construct($config = [])
{
$this->setup();
parent::__construct($config);
}
/**
* @inheritDoc
*/
public function setModel($model, $default = false)
{
$model = parent::setModel($model, $default);
if ($model && $default) {
$this->model = $model;
$this->state = $this->model->getState();
}
return $model;
}
/**
* @inheritDoc
*/
public function display($tpl = null)
{
if ($this->initSuccess) {
$this->displayHeader();
parent::display($tpl);
$this->displayFooter();
}
}
/**
* For use by subclasses
*
* @return void
*/
protected function displayHeader()
{
// Display custom text
}
/**
* For use by subclasses
*
* @return void
*/
protected function displayFooter()
{
// Display custom text
}
/**
* @param string $name
* @param string $layout
*
* @return string
* @throws \Exception
*/
public function loadDefaultTemplate(string $name, ?string $layout = 'default'): string
{
$currentLayout = $this->setLayout($layout);
$output = $this->loadTemplate($name);
$this->setLayout($currentLayout);
return $output;
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Controller;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\MVC\Controller\AdminController;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\Input\Input;
defined('_JEXEC') or die();
class Admin extends AdminController
{
use TraitController;
/**
* @inheritDoc
*/
public function __construct(
$config = [],
MVCFactoryInterface $factory = null,
?CMSApplication $app = null,
?Input $input = null
) {
parent::__construct($config, $factory, $app, $input);
$this->customInit();
}
}

View File

@ -0,0 +1,44 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Controller;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
defined('_JEXEC') or die();
class Base extends BaseController
{
use TraitController;
/**
* @inheritDoc
*/
public function __construct($config = [], MVCFactoryInterface $factory = null)
{
parent::__construct($config, $factory);
$this->customInit();
}
}

View File

@ -0,0 +1,80 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Controller;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\Router\Route;
use Joomla\Input\Input;
defined('_JEXEC') or die();
class Form extends FormController
{
use TraitController;
/**
* @inheritDoc
*/
public function __construct(
$config = [],
MVCFactoryInterface $factory = null,
?CMSApplication $app = null,
?Input $input = null
) {
parent::__construct($config, $factory, $app, $input);
$this->customInit();
}
/**
* @inheritDoc
* @throws \Exception
*/
public function batch($model = null)
{
$this->checkToken();
$inflector = $this->getStringInflector();
$view = $this->app->input->getCmd('view', $this->default_view);
if ($inflector->isPlural($view)) {
$modelName = $inflector->toSingular($view);
$model = $this->getModel($modelName, '', []);
$linkQuery = http_build_query([
'option' => $this->app->input->getCmd('option'),
'view' => $view
]);
$this->setRedirect(Route::_('index.php?' . $linkQuery . $this->getRedirectToListAppend(), false));
return parent::batch($model);
}
return null;
}
}

View File

@ -0,0 +1,79 @@
<?php
/**
* @package OSCampus
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2015-2023 Joomlashack.com. All rights reserved
* @license http://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of OSCampus.
*
* OSCampus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* OSCampus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OSCampus. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Controller;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Response\JsonResponse;
defined('_JEXEC') or die();
abstract class Json extends Base
{
/**
* @inheritDoc
* @throws \Exception`
*/
public function checkToken($method = 'post', $redirect = false)
{
$valid = parent::checkToken($method, $redirect);
if (!$valid) {
throw new \Exception(Text::_('JINVALID_TOKEN'), 403);
}
return true;
}
/**
* Sends a json package to output. All php processing ended to prevent any
* plugin processing that might slow things down or waste memory.
*
* @param ?string|\Throwable $message
*
* @return void
*/
protected function returnJson($message = null)
{
$result = new JsonResponse();
if ($message) {
if ($message instanceof \Throwable) {
$result->success = false;
$result->message = $message->getMessage();
$result->data = [
'file' => $message->getFile(),
'line' => $message->getLine()
];
} else {
$result->message = $message;
}
}
header('Content-Type: application/json');
echo $result;
jexit();
}
}

View File

@ -0,0 +1,128 @@
<?php
/**
* @package OSCampus
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2021-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of OSCampus.
*
* OSCampus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* OSCampus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OSCampus. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Controller;
use Alledia\Framework\Factory;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;
use Joomla\String\Inflector;
defined('_JEXEC') or die();
trait TraitController
{
/**
* For consistency between Joomla 3 & 4
*
* @var CMSApplication
* @since Joomla v4
*/
protected $app = null;
/**
* Standard return to calling url. In order:
* - Looks for base64 encoded 'return' URL variable
* - Uses current 'Itemid' URL variable
* - Uses current 'option', 'view', 'layout' URL variables
* - Goes to site default page
*
* @param ?array|string $message The message to queue up
* @param ?string $type message|notice|error
* @param ?string $return (optional) base64 encoded url for redirect
*
* @return void
*/
protected function callerReturn($message = null, ?string $type = null, ?string $return = null)
{
$url = $return ?: $this->app->input->getBase64('return');
if ($url) {
$url = base64_decode($url);
} else {
$url = new Uri('index.php');
if ($itemId = $this->app->input->getInt('Itemid')) {
$url->setVar('Itemid', $itemId);
} elseif ($option = $this->app->input->getCmd('option')) {
$url->setVar('option', $option);
}
if ($view = $this->app->input->getCmd('view')) {
$url->setVar('view', $view);
if ($layout = $this->app->input->getCmd('layout')) {
$url->setVar('layout', $layout);
}
}
}
if (is_array($message)) {
$message = join('<br>', $message);
}
$this->setRedirect(Route::_((string)$url), $message, $type);
}
/**
* Return to referrer if internal, home page if external
*
* @param string $message
* @param string $type
*
* @return void
*/
protected function errorReturn(string $message, string $type = 'error')
{
$referrer = $this->input->server->getString('HTTP_REFERER');
if (Uri::isInternal($referrer) == false) {
$referrer = 'index.php';
}
$this->app->enqueueMessage($message, $type);
$this->app->redirect($referrer);
}
/**
* Provide consistency between Joomla 3/Joomla 4 among other possibilities
*
* @return void
*/
protected function customInit()
{
if (empty($this->app)) {
$this->app = Factory::getApplication();
}
}
/**
* @return Inflector
*/
protected function getStringInflector(): Inflector
{
return Inflector::getInstance();
}
}

View File

@ -0,0 +1,149 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2022-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Events;
use Alledia\Framework\Factory;
use Joomla\Event\AbstractEvent;
use Joomla\Event\Dispatcher;
defined('_JEXEC') or die();
trait TraitObservable
{
/**
* @var \JEventDispatcher|Dispatcher
*/
protected static $coreDispatcher = null;
/**
* @var bool
*/
protected static $legacyDispatch = null;
/**
* @return \JEventDispatcher|Dispatcher
*/
public function getDispatcher()
{
if (static::$coreDispatcher === null) {
static::$coreDispatcher = Factory::getDispatcher();
static::$legacyDispatch = is_callable([static::$coreDispatcher, 'register']);
}
return static::$coreDispatcher;
}
/**
* $events is accepted in these forms:
*
* ['handler1', 'handler2',...]: array of specific methods to register
* 'handler' : a single method to register
* 'prefix*' : all public methods in $observable that begin with 'prefix'
* '*string' : all public methods in $observable that contain 'string'
*
* @param string|string[] $events
* @param ?object $observable
* @param ?bool $legacyListeners
*
* @return void
*/
public function registerEvents($events, object $observable = null, bool $legacyListeners = true): void
{
$observable = $observable ?: $this;
if (is_string($events) && strpos($events, '*') !== false) {
$startsWith = strpos($events, '*') !== 0;
$event = preg_replace('/[^a-z\d_]/i', '', $events);
// Look for methods that match the wildcarded name
$observableInfo = new \ReflectionClass($observable);
$methods = $observableInfo->getMethods(\ReflectionMethod::IS_PUBLIC);
$events = [];
foreach ($methods as $method) {
$position = strpos($method->name, $event);
if (
($startsWith && $position === 0)
|| ($startsWith == false && $position > 0)
) {
$events[] = $method->name;
}
}
} elseif (is_string($events)) {
$events = [$events];
}
if ($events && is_array($events)) {
$dispatcher = Factory::getDispatcher();
foreach ($events as $event) {
$handler = [$observable, $event];
if (is_callable([$dispatcher, 'register'])) {
$dispatcher->register($event, $handler);
} elseif (is_callable([$dispatcher, 'addListener'])) {
if ($legacyListeners) {
$dispatcher->addListener($event, $this->createLegacyHandler($handler));
} else {
$dispatcher->addListener($event, $handler);
}
}
}
}
}
/**
* @param callable $handler
*
* @return callable
*/
final protected function createLegacyHandler(callable $handler): callable
{
return function (AbstractEvent $event) use ($handler) {
$arguments = $event->getArguments();
// Extract any old results; they must not be part of the method call.
$allResults = [];
if (isset($arguments['result'])) {
$allResults = $arguments['result'];
unset($arguments['result']);
}
// Convert to indexed array for unpacking.
$arguments = \array_values($arguments);
$result = $handler(...$arguments);
// Ignore null results
if ($result === null) {
return;
}
// Restore the old results and add the new result from our method call
$allResults[] = $result;
$event['result'] = $allResults;
};
}
}

View File

@ -0,0 +1,154 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Extension;
defined('_JEXEC') or die();
use Alledia\Framework\Factory;
use Alledia\Framework\Joomla\Table\Base as BaseTable;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Table\Table;
abstract class AbstractComponent extends Licensed
{
/**
* @var self
*/
protected static $instance = null;
/**
* @var object
*/
protected $controller = null;
/**
* @inheritDoc
*/
public function __construct($namespace)
{
parent::__construct($namespace, 'component');
BaseDatabaseModel::addIncludePath(JPATH_COMPONENT . '/models');
Table::addIncludePath(JPATH_COMPONENT . '/tables');
$this->loadLibrary();
}
/**
* @param string $namespace
*
* @return self
*/
public static function getInstance($namespace = null)
{
if (empty(static::$instance)) {
static::$instance = new static($namespace);
}
return static::$instance;
}
/**
* @return void
* @throws \Exception
*/
public function init()
{
$this->loadController();
$this->executeRedirectTask();
}
/**
* @return void
* @throws \Exception
*/
public function loadController()
{
if (!is_object($this->controller)) {
$app = Factory::getApplication();
$client = $app->isClient('administrator') ? 'Admin' : 'Site';
$controllerClass = 'Alledia\\' . $this->namespace . '\\' . ucfirst($this->license)
. '\\Joomla\\Controller\\' . $client;
require JPATH_COMPONENT . '/controller.php';
$this->controller = $controllerClass::getInstance($this->namespace);
}
}
/**
* @return void
* @throws \Exception
*/
public function executeRedirectTask()
{
$app = Factory::getApplication();
$task = $app->input->getCmd('task');
$this->controller->execute($task);
$this->controller->redirect();
}
/**
* @param string $type
*
* @return ?BaseDatabaseModel
*/
public function getModel(string $type): ?BaseDatabaseModel
{
$class = sprintf(
'Alledia\\%s\\%s\\Joomla\\Model\\%s',
$this->namespace,
$this->isPro() ? 'Pro' : 'Free',
$type
);
if (class_exists($class)) {
return new $class();
}
return BaseDatabaseModel::getInstance($type, $this->namespace . 'Model');
}
/**
* @param string $type
*
* @return ?Table
*/
public function getTable(string $type): ?Table
{
$class = sprintf(
'Alledia\\%s\\%s\\Joomla\\Table\\%s',
$this->namespace,
$this->isPro() ? 'Pro' : 'Free',
$type
);
if (class_exists($class)) {
$db = Factory::getDbo();
return new $class($db);
}
return BaseTable::getInstance($type, $this->namespace . 'Table');
}
}

View File

@ -0,0 +1,108 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Extension;
defined('_JEXEC') or die();
use Joomla\CMS\Helper\ModuleHelper;
use Joomla\Registry\Registry;
abstract class AbstractFlexibleModule extends Licensed
{
/**
* @var string
*/
public $title = null;
/**
* @var
*/
public $module = null;
/**
* @var
*/
public $position = null;
/**
* @var string
*/
public $content = null;
/**
* @var bool
*/
public $showtitle = null;
/**
* @var int
*/
public $menuid = null;
/**
* @var string
*/
public $style = null;
/**
* @inheritDoc
*/
public function __construct($namespace, $module = null)
{
parent::__construct($namespace, 'module');
$this->loadLibrary();
if (is_object($module)) {
$properties = [
'id',
'title',
'module',
'position',
'content',
'showtitle',
'menuid',
'name',
'style',
'params'
];
foreach ($properties as $property) {
if (isset($module->{$property})) {
$this->{$property} = $module->{$property};
}
}
if (!$this->params instanceof Registry) {
$this->params = new Registry($this->params);
}
}
}
/**
* Method to initialize the module
*/
public function init()
{
require ModuleHelper::getLayoutPath('mod_' . $this->element, $this->params->get('layout', 'default'));
}
}

View File

@ -0,0 +1,144 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Extension;
defined('_JEXEC') or die();
use Alledia\Framework\Factory;
use Joomla\CMS\Helper\ModuleHelper;
use Joomla\Registry\Registry;
/**
* @deprecated 1.4.1 Use AbstractFlexibleModule instead. This module doesn't
* work with multiple modules in the same page because of the Singleton pattern.
*
*/
abstract class AbstractModule extends Licensed
{
/**
* @var AbstractModule
*/
protected static $instance;
/**
* @var string
*/
public $title = null;
/**
* @var string
*/
public $module = null;
/**
* @var string
*/
public $position = null;
/**
* @var string
*/
public $content = null;
/**
* @var bool
*/
public $showtitle = null;
/**
* @var int
*/
public $menuid = null;
/**
* @var string
*/
public $style = null;
/**
* @inheritDoc
*/
public function __construct($namespace)
{
parent::__construct($namespace, 'module');
$this->loadLibrary();
}
/**
* Returns the instance of child classes
*
* @param string $namespace
* @param object $module
*
* @return Object
*/
public static function getInstance($namespace = null, $module = null)
{
if (empty(static::$instance)) {
$instance = new static($namespace);
if (is_object($module)) {
$instance->id = $module->id;
$instance->title = $module->title;
$instance->module = $module->module;
$instance->position = $module->position;
$instance->content = $module->content;
$instance->showtitle = $module->showtitle;
$instance->menuid = $module->menuid;
$instance->name = $module->name;
$instance->style = $module->style;
$instance->params = new Registry($module->params);
} else {
// @TODO: Raise warning/Error
}
$instance->loadLanguage();
static::$instance = $instance;
}
return static::$instance;
}
/**
* @return void
*/
public function init()
{
require ModuleHelper::getLayoutPath('mod_' . $this->element, $this->params->get('layout', 'default'));
}
/**
* @return void
*/
public function loadLanguage()
{
$language = Factory::getLanguage();
$language->load($this->module, JPATH_SITE);
}
}

View File

@ -0,0 +1,101 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Extension;
use Alledia\Framework\Factory;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Version;
// phpcs:disable PSR1.Files.SideEffects
defined('_JEXEC') or die();
// phpcs:enable PSR1.Files.SideEffects
abstract class AbstractPlugin extends CMSPlugin
{
/**
* Alledia Extension instance
*
* @var Licensed
*/
protected $extension;
/**
* Library namespace
*
* @var string
*/
protected $namespace;
/**
* Method used to load the extension data. It is not on the constructor
* because this way we can avoid loading the data if the plugin
* will not be used.
*
* @return void
*/
protected function init()
{
$this->loadExtension();
// Load the libraries, if existent
$this->extension->loadLibrary();
$this->loadLanguage();
}
/**
* Method to load the language files
*
* @return void
*/
public function loadLanguage($extension = '', $basePath = JPATH_ADMINISTRATOR)
{
parent::loadLanguage($extension, $basePath);
$systemStrings = 'plg_' . $this->_type . '_' . $this->_name . '.sys';
parent::loadLanguage($systemStrings, $basePath);
}
/**
* Method to load the extension data
*
* @return void
*/
protected function loadExtension()
{
if (!isset($this->extension)) {
$this->extension = Factory::getExtension($this->namespace, 'plugin', $this->_type);
}
}
/**
* Check if this extension is licensed as pro
*
* @return bool True for pro version
*/
protected function isPro()
{
return $this->extension->isPro();
}
}

View File

@ -0,0 +1,74 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Extension;
defined('_JEXEC') or die();
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Controller\BaseController;
class Component extends Licensed
{
/**
* @var BaseController
*/
protected $controller;
/**
* @inheritDoc
*/
public function __construct($namespace)
{
parent::__construct($namespace, 'component');
$this->loadLibrary();
}
/**
* Load the main controller
*
* @return void
* @throws \Exception
*/
public function loadController()
{
if (!isset($this->controller)) {
jimport('legacy.controller.legacy');
$this->controller = BaseController::getInstance($this->namespace);
}
}
/**
* @return void
* @throws \Exception
*/
public function executeTask()
{
$task = Factory::getApplication()->input->getCmd('task');
$this->controller->execute($task);
$this->controller->redirect();
}
}

View File

@ -0,0 +1,515 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Extension;
defined('_JEXEC') or die();
use JFormFieldCustomFooter;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File;
use Joomla\Registry\Registry;
use SimpleXMLElement;
/**
* Generic extension class
*
* @todo : Make this class compatible with non-Alledia extensions
*/
class Generic
{
/**
* The extension namespace
*
* @var string
*/
public $namespace = null;
/**
* The extension type
*
* @var string
*/
public $type = null;
/**
* The extension id
*
* @var int
*/
public $id = null;
/**
* The extension name
*
* @var string
*/
public $name = null;
/**
* The extension params
*
* @var Registry
*/
public $params = null;
/**
* The extension enable state
*
* @var bool
*/
protected $enabled;
/**
* The element of the extension
*
* @var string
*/
protected $element;
/**
* @var string
*/
protected $folder = null;
/**
* Base path
*
* @var string
*/
protected $basePath;
/**
* The manifest information
*
* @var object
*/
public $manifest = null;
/**
* The manifest information as SimpleXMLElement
*
* @var SimpleXMLElement
*/
public $manifestXml = null;
/**
* The config information
*
* @var SimpleXMLElement
*/
public $config = null;
/**
* Class constructor, set the extension type.
*
* @param string $namespace The element of the extension
* @param string $type The type of extension
* @param string $folder The folder for plugins (only)
*/
public function __construct($namespace, $type, $folder = '', $basePath = JPATH_SITE)
{
$this->type = $type;
$this->element = strtolower($namespace);
$this->folder = $folder;
$this->basePath = rtrim($basePath, '/\\');
$this->namespace = $namespace;
$this->getManifest();
$this->getDataFromDatabase();
}
/**
* Get information about this extension from the database
*
* @return void
*/
protected function getDataFromDatabase()
{
$element = $this->getElementToDb();
// Load the extension info from database
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select([
$db->quoteName('extension_id'),
$db->quoteName('name'),
$db->quoteName('enabled'),
$db->quoteName('params')
])
->from('#__extensions')
->where($db->quoteName('type') . ' = ' . $db->quote($this->type))
->where($db->quoteName('element') . ' = ' . $db->quote($element));
if ($this->type === 'plugin') {
$query->where($db->quoteName('folder') . ' = ' . $db->quote($this->folder));
}
$db->setQuery($query);
$row = $db->loadObject();
if (is_object($row)) {
$this->id = $row->extension_id;
$this->name = $row->name;
$this->enabled = (bool)$row->enabled;
$this->params = new Registry($row->params);
} else {
$this->id = null;
$this->name = null;
$this->enabled = false;
$this->params = new Registry();
}
}
/**
* Check if the extension is enabled
*
* @return bool
*/
public function isEnabled()
{
return $this->enabled;
}
/**
* Get the path for the extension
*
* @return string The path
*/
public function getExtensionPath()
{
$folders = [
'component' => 'administrator/components/',
'plugin' => 'plugins/',
'template' => 'templates/',
'library' => 'libraries/',
'cli' => 'cli/',
'module' => 'modules/'
];
$basePath = $this->basePath . '/' . $folders[$this->type];
switch ($this->type) {
case 'plugin':
$basePath .= $this->folder . '/';
break;
case 'module':
if (!preg_match('/^mod_/', $this->element)) {
$basePath .= 'mod_';
}
break;
case 'component':
if (!preg_match('/^com_/', $this->element)) {
$basePath .= 'com_';
}
break;
}
$basePath .= $this->element;
return $basePath;
}
/**
* Get the full element
*
* @return string The full element
*/
public function getFullElement()
{
return Helper::getFullElementFromInfo($this->type, $this->element, $this->folder);
}
/**
* Get the element to match the database records.
* Only components and modules have the prefix.
*
* @return string The element
*/
public function getElementToDb()
{
$prefixes = [
'component' => 'com_',
'module' => 'mod_'
];
$fullElement = '';
if (array_key_exists($this->type, $prefixes)) {
if (!preg_match('/^' . $prefixes[$this->type] . '/', $this->element)) {
$fullElement = $prefixes[$this->type];
}
}
$fullElement .= $this->element;
return $fullElement;
}
/**
* Get manifest path for this extension
*
* @return string
*/
public function getManifestPath()
{
$extensionPath = $this->getExtensionPath();
// Templates or extension?
if ($this->type === 'template') {
$fileName = 'templateDetails.xml';
} else {
$fileName = $this->element . '.xml';
}
$path = $extensionPath . "/{$fileName}";
if (!is_file($path)) {
$path = $extensionPath . "/{$this->getElementToDb()}.xml";
}
return $path;
}
/**
* Get extension manifest as SimpleXMLElement
*
* @param bool $force If true, force to load the manifest, ignoring the cached one
*
* @return SimpleXMLElement
*/
public function getManifestAsSimpleXML($force = false)
{
if (!isset($this->manifestXml) || $force) {
$path = $this->getManifestPath();
if (File::exists($path)) {
$this->manifestXml = simplexml_load_file($path);
} else {
$this->manifestXml = false;
}
}
return $this->manifestXml;
}
/**
* Get extension information
*
* @param bool $force If true, force to load the manifest, ignoring the cached one
*
* @return object
*/
public function getManifest($force = false)
{
if (!isset($this->manifest) || $force) {
$xml = $this->getManifestAsSimpleXML($force);
if (!empty($xml)) {
$this->manifest = (object)json_decode(json_encode($xml));
} else {
$this->manifest = false;
}
}
return $this->manifest;
}
/**
* Get extension config file
*
* @param bool $force Force to reload the config file
*
* @return SimpleXMLElement
*/
public function getConfig($force = false)
{
if (!isset($this->config) || $force) {
$this->config = null;
$path = $this->getExtensionPath() . '/config.xml';
if (file_exists($path)) {
$this->config = simplexml_load_file($path);
}
}
return $this->config;
}
/**
* Returns the update URL from database
*
* @return string
*/
public function getUpdateURL()
{
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select('sites.location')
->from('#__update_sites AS sites')
->leftJoin('#__update_sites_extensions AS extensions ON (sites.update_site_id = extensions.update_site_id)')
->where('extensions.extension_id = ' . $this->id);
return $db->setQuery($query)->loadResult();
}
/**
* Set the update URL
*
* @param string $url
*/
public function setUpdateURL($url)
{
$db = Factory::getDbo();
// Get the update site id
$join = $db->quoteName('#__update_sites_extensions') . ' AS extensions '
. 'ON (sites.update_site_id = extensions.update_site_id)';
$query = $db->getQuery(true)
->select('sites.update_site_id')
->from($db->quoteName('#__update_sites') . ' AS sites')
->leftJoin($join)
->where('extensions.extension_id = ' . $this->id);
$siteId = (int)$db->setQuery($query)->loadResult();
if (!empty($siteId)) {
$query = $db->getQuery(true)
->update($db->quoteName('#__update_sites'))
->set($db->quoteName('location') . ' = ' . $db->quote($url))
->where($db->quoteName('update_site_id') . ' = ' . $siteId);
$db->setQuery($query)->execute();
}
}
/**
* Store the params on the database
*
* @return void
*/
public function storeParams()
{
$db = Factory::getDbo();
$updateObject = (object)[
'params' => $this->params->toString(),
'extension_id' => $this->id
];
$db->updateObject('#__extensions', $updateObject, ['extension_id']);
}
/**
* Get extension name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Get extension id
*
* @return int
*/
public function getId()
{
return (int)$this->id;
}
/**
* @TODO: Move to the licensed class?
*
* @return string
*/
public function getFooterMarkup()
{
$manifest = $this->getManifestAsSimpleXML();
if ($manifest->alledia) {
$configPath = $this->getExtensionPath() . '/config.xml';
if (File::exists($configPath)) {
$config = $this->getConfig();
if (is_object($config)) {
$footerElement = $config->xpath('//field[@type="customfooter"]');
$footerElement = reset($footerElement);
}
}
if (empty($footerElement)) {
if (is_object($manifest)) {
if ($footerElement = $manifest->xpath('//field[@type="customfooter"]')) {
$footerElement = reset($footerElement);
} elseif ($media = (string)$manifest->media['destination']) {
$customField = sprintf(
'<field type="customfooter" name="customfooter" media="%s"/>',
$media
);
$footerElement = new SimpleXMLElement($customField);
}
}
}
if (empty($footerElement) == false) {
if (class_exists('JFormFieldCustomFooter') === false) {
$classPath = $this->getExtensionPath() . '/form/fields/customfooter.php';
if (is_file($classPath)) {
require_once $classPath;
}
}
if (class_exists('JFormFieldCustomFooter')) {
$field = new JFormFieldCustomFooter();
$field->fromInstaller = true;
return $field->getInputUsingCustomElement($footerElement);
}
}
}
return '';
}
/**
* Returns the extension's version collected from the manifest file
*
* @return string The extension's version
*/
public function getVersion()
{
if (!empty($this->manifest->version)) {
return $this->manifest->version;
}
return null;
}
}

View File

@ -0,0 +1,176 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Extension;
use Alledia\Framework\Factory;
defined('_JEXEC') or die();
/**
* Generic extension helper class
*/
abstract class Helper
{
/**
* @var array[]
*/
protected static $extensionInfo = [];
protected static $extensionTypes = [
'com' => 'component',
'plg' => 'plugin',
'mod' => 'module',
'lib' => 'library',
'tpl' => 'template',
'cli' => 'cli'
];
/**
* Build a string representing the element
*
* @param string $type
* @param string $element
* @param string $folder
*
* @return string
*/
public static function getFullElementFromInfo($type, $element, $folder = null)
{
$prefix = array_search($type, static::$extensionTypes);
if ($prefix) {
if (strpos($element, $prefix) === 0) {
$shortElement = substr($element, strlen($prefix) + 1);
}
$parts = [
$prefix,
$type == 'plugin' ? $folder : null,
$shortElement ?? $element
];
return join('_', array_filter($parts));
}
return null;
}
/**
* @param ?string $element
*
* @return ?array
*/
public static function getExtensionInfoFromElement(?string $element): ?array
{
if (isset(static::$extensionInfo[$element]) == false) {
static::$extensionInfo[$element] = false;
$parts = explode('_', $element, 3);
if (count($parts) > 1) {
$prefix = $parts[0];
$name = $parts[2] ?? $parts[1];
$group = empty($parts[2]) ? null : $parts[1];
$types = [
'com' => 'component',
'plg' => 'plugin',
'mod' => 'module',
'lib' => 'library',
'tpl' => 'template',
'cli' => 'cli'
];
if (array_key_exists($prefix, $types)) {
$result = [
'prefix' => $prefix,
'type' => $types[$prefix],
'name' => $name,
'group' => $group,
'namespace' => preg_replace_callback(
'/^(os[a-z])(.*)/i',
function ($matches) {
return strtoupper($matches[1]) . $matches[2];
},
$name
)
];
}
static::$extensionInfo[$element] = $result;
}
}
return static::$extensionInfo[$element] ?: null;
}
/**
* @param string $element
*
* @return bool
*/
public static function loadLibrary($element)
{
$extension = static::getExtensionForElement($element);
if (is_object($extension)) {
return $extension->loadLibrary();
}
return false;
}
/**
* @param string $element
*
* @return string
*/
public static function getFooterMarkup($element)
{
if (is_string($element)) {
$extension = static::getExtensionForElement($element);
} elseif (is_object($element)) {
$extension = $element;
}
if (!empty($extension)) {
return $extension->getFooterMarkup();
}
return '';
}
/**
* @param string $element
*
* @return Licensed
*/
public static function getExtensionForElement($element)
{
$info = static::getExtensionInfoFromElement($element);
if (!empty($info['type']) && !empty($info['namespace'])) {
return Factory::getExtension($info['namespace'], $info['type'], $info['group']);
}
return null;
}
}

View File

@ -0,0 +1,142 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Extension;
defined('_JEXEC') or die();
use Alledia\Framework\AutoLoader;
/**
* Licensed class, for extensions with Free and Pro versions
*/
class Licensed extends Generic
{
/**
* License type: free or pro
*
* @var string
*/
protected $license = null;
/**
* The path for the pro library
*
* @var string
*/
protected $proLibraryPath = null;
/**
* The path for the free library
*
* @var string
*/
protected $libraryPath = null;
/**
* @inheritDoc
*/
public function __construct($namespace, $type, $folder = '', $basePath = JPATH_SITE)
{
parent::__construct($namespace, $type, $folder, $basePath);
$this->license = strtolower($this->manifest->alledia->license ?? '');
$this->namespace = $this->manifest->alledia->namespace ?? '';
$this->getLibraryPath();
$this->getProLibraryPath();
}
/**
* Check if the license is pro
*
* @return bool
*/
public function isPro(): bool
{
return $this->license === 'pro';
}
/**
* Check if the license is free
*
* @return bool
*/
public function isFree(): bool
{
return !$this->isPro();
}
/**
* Get the include path for the free library, based on the extension type
*
* @return string The path for pro
*/
public function getLibraryPath()
{
if ($this->libraryPath === null) {
$basePath = $this->getExtensionPath();
$this->libraryPath = $basePath . '/library';
}
return $this->libraryPath;
}
/**
* Get the include path the pro library, based on the extension type
*
* @return string The path for pro
*/
public function getProLibraryPath()
{
if (empty($this->proLibraryPath)) {
$basePath = $this->getLibraryPath();
$this->proLibraryPath = $basePath . '/Pro';
}
return $this->proLibraryPath;
}
/**
* Loads the library, if existent (including the Pro Library)
*
* @return bool
*/
public function loadLibrary()
{
if ($this->namespace) {
$libraryPath = $this->getLibraryPath();
if (is_dir($libraryPath)) {
AutoLoader::register('Alledia\\' . $this->namespace, $libraryPath);
return true;
}
}
return false;
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2021-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Form\Field;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormHelper;
use Joomla\CMS\Version;
defined('_JEXEC') or die();
if (Version::MAJOR_VERSION < 4) {
class_alias('JFormFieldList', '\\Joomla\\CMS\\Form\\Field\\ListField');
FormHelper::loadFieldClass('List');
}
class ListField extends \Joomla\CMS\Form\Field\ListField
{
use TraitLayouts;
/**
* Set list field layout based on Joomla version
*/
public function setup(\SimpleXMLElement $element, $value, $group = null)
{
$this->setListLayout();
return parent::setup($element, $value, $group);
}
}

View File

@ -0,0 +1,91 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2021-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Form\Field;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\Path;
use Joomla\CMS\Version;
defined('_JEXEC') or die();
/**
* Intended for use by form field classes to
* implement Joomla version targeted layout files
*/
trait TraitLayouts
{
/**
* @inheritDoc
*/
protected function getLayoutPaths()
{
if (is_callable('parent::getLayoutPaths')) {
$paths = parent::getLayoutPaths();
$fieldClass = (new \ReflectionClass($this));
$baseDirectory = dirname($fieldClass->getFileName());
array_unshift($paths, $baseDirectory . '/layouts');
return $paths;
}
return [];
}
/**
* @inheritDoc
*/
protected function getRenderer($layoutId = 'default')
{
if (is_callable('parent::getRenderer')) {
$paths = $this->getLayoutPaths();
if (Version::MAJOR_VERSION < 4) {
if (Path::find($paths, str_replace('.', '/', $layoutId) . '_j3.php')) {
$layoutId .= '_j3';
}
}
$renderer = parent::getRenderer($layoutId);
$renderer->setIncludePaths($paths);
return $renderer;
}
return null;
}
/**
* @return void
* @deprecated v3.3.1
*/
protected function setListLayout()
{
if (Version::MAJOR_VERSION >= 4) {
$this->layout = 'joomla.form.field.list-fancy-select';
}
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Model;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
defined('_JEXEC') or die();
/**
* @deprecated v2.1.0: This is pretty much useless
*/
class Base extends BaseDatabaseModel
{
}

View File

@ -0,0 +1,162 @@
<?php
/**
* @package OSCampus
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2017-2023 Joomlashack.com. All rights reserved
* @license http://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of OSCampus.
*
* OSCampus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* OSCampus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OSCampus. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Model;
use Alledia\Framework\Factory;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\User\User;
defined('_JEXEC') or die();
trait TraitModel
{
/**
* @var CMSApplication
*/
protected $app = null;
/**
* @var string[]
*/
protected $accessList = [];
/**
* @return void
* @throws \Exception
*/
protected function setup()
{
$this->app = Factory::getApplication();
}
/**
* Create a where clause of OR conditions for a text search
* across one or more fields. Optionally accepts a text
* search like 'id: #' if $idField is specified
*
* @param string $text
* @param string|string[] $fields
* @param ?string $idField
*
* @return string
*/
public function whereTextSearch(string $text, $fields, ?string $idField = null): string
{
$text = trim($text);
if ($idField && stripos($text, 'id:') === 0) {
$id = (int)substr($text, 3);
return $idField . ' = ' . $id;
}
if (is_string($fields)) {
$fields = [$fields];
}
$searchText = Factory::getDbo()->quote('%' . $text . '%');
$ors = [];
foreach ($fields as $field) {
$ors[] = $field . ' LIKE ' . $searchText;
}
if (count($ors) > 1) {
return sprintf('(%s)', join(' OR ', $ors));
}
return array_pop($ors);
}
/**
* Provide a generic access search for selected field
*
* @param string $field
* @param ?User $user
*
* @return string
*/
public function whereAccess(string $field, ?User $user = null): string
{
$user = $user ?: Factory::getUser();
if ($user->authorise('core.manage') == false) {
$userId = $user->id;
if (isset($this->accessList[$userId]) == false) {
$this->accessList[$userId] = join(', ', array_unique($user->getAuthorisedViewLevels()));
}
if ($this->accessList[$userId]) {
return sprintf($field . ' IN (%s)', $this->accessList[$userId]);
}
}
return 'TRUE';
}
/**
* @param string $source
* @param string|string[] $relations
*
* @return void
*/
protected function garbageCollect(string $source, $relations)
{
$sourceParts = explode('.', $source);
$sourceField = array_pop($sourceParts);
$sourceTable = array_pop($sourceParts);
if ($sourceTable && $sourceField) {
$db = Factory::getDbo();
if (is_string($relations)) {
$relations = [$relations];
}
foreach ($relations as $target) {
$targetParts = explode('.', $target);
$targetField = array_pop($targetParts);
$targetTable = array_pop($targetParts);
if ($targetTable && $targetField) {
$query = $db->getQuery(true)
->delete($db->quoteName('#__oscampus_' . $targetTable))
->where(
sprintf(
'%s NOT IN (SELECT %s FROM %s)',
$db->quoteName($targetField),
$db->quoteName($sourceField),
$db->quoteName('#__oscampus_' . $sourceTable)
)
);
}
try {
$db->setQuery($query)->execute();
} catch (\Throwable $error) {
$this->app->enqueueMessage($error->getMessage() . '<br>' . $query, 'error');
}
}
}
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Table;
use Alledia\Framework\Joomla\AbstractTable;
defined('_JEXEC') or die();
/**
* @deprecated v3.6.5 - use AbstractTable
*/
abstract class Base extends AbstractTable
{
}

View File

@ -0,0 +1,131 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2022-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\Toolbar;
use Alledia\Framework\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Utility\Utility;
use Joomla\CMS\Version;
defined('_JEXEC') or die();
abstract class ToolbarHelper extends \Joomla\CMS\Toolbar\ToolbarHelper
{
/**
* @var bool
*/
protected static $exportLoaded = false;
/**
* Create a button that links to an external page
*
* @param string $url
* @param string $title
* @param ?string $icon
* @param ?mixed $attributes
*
* @return void
*/
public static function externalLink(string $url, string $title, ?string $icon = null, $attributes = [])
{
if (is_string($attributes)) {
$attributes = Utility::parseAttributes($attributes);
}
$icon = $icon ?: 'link';
$attributes['target'] = $attributes['target'] ?? '_blank';
$attributes['class'] = join(
' ',
array_filter(
array_merge(
explode(' ', $attributes['class'] ?? ''),
[
'btn',
'btn-small'
]
)
)
);
$button = HTMLHelper::_(
'link',
$url,
sprintf('<span class="icon-%s"></span> %s', $icon, $title),
$attributes
);
if (Version::MAJOR_VERSION > 3) {
$button = sprintf('<joomla-toolbar-button>%s</joomla-toolbar-button>', $button);
}
$bar = Toolbar::getInstance();
$bar->appendButton('Custom', $button, $icon);
}
/**
* Create a button that links to documentation
*
* @param string $url
* @param string $title
*
* @return void
*/
public static function shackDocumentation(string $url, string $title)
{
static::externalLink($url, $title, 'support', ['class' => 'btn-info', 'target' => 'shackdocs']);
}
/**
* Export button that ensures the task input field is cleared if
* the export does not return to refresh the page
*
* @param string $task
* @param string $alt
* @param string $icon
*
* @return void
* @throws \Exception
*/
public static function exportView(string $task, string $alt, string $icon = 'download')
{
static::custom($task, $icon, null, $alt, false);
if (static::$exportLoaded == false) {
Factory::getApplication()->getDocument()->addScriptDeclaration(<<<JSCRIPT
Joomla.submitbutton = function(task) {
Joomla.submitform(task);
let taskInput = document.querySelector('input[name="task"]');
if (taskInput) {
taskInput.value = '';
}
};
JSCRIPT
);
static::$exportLoaded = true;
}
}
}

View File

@ -0,0 +1,116 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2021-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla;
use Alledia\Framework\Extension;
use Alledia\Framework\Factory;
use Alledia\Framework\Joomla\Extension\Helper as ExtensionHelper;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Filesystem\Path;
use Joomla\CMS\Version;
defined('_JEXEC') or die();
trait TraitAllediaView
{
/**
* @var CMSApplication
*/
protected $app = null;
/**
* @var Extension
*/
protected $extension = null;
/**
* @var bool
*/
protected $initSuccess = null;
/**
* To be called before class constructor method by inheriting classes
*
* @return void
*/
protected function setup()
{
try {
$this->app = Factory::getApplication();
$this->document = Factory::getDocument();
$this->option = $this->app->input->get('option');
$info = ExtensionHelper::getExtensionInfoFromElement($this->option);
$this->extension = Factory::getExtension($info['namespace'], $info['type']);
$this->extension->loadLibrary();
$this->initSuccess = true;
} catch (\Throwable $error) {
if ($this->app) {
$this->app->enqueueMessage($error->getMessage(), 'error');
} else {
echo '<p>' . $error->getMessage() . '</p>';
}
$this->initSuccess = false;
}
}
/**
* Look for a valid layout file based on Joomla version
*
* @param string $layout
*
* @return string
* @throws \Exception
*/
protected function getVersionedLayoutName(string $layout): string
{
if (is_callable([$this, '_createFileName'])) {
$file = $layout;
if (Version::MAJOR_VERSION < 4) {
$file .= '.j' . Version::MAJOR_VERSION;
}
if ($file != $layout || $file == 'emptystate') {
// Verify layout file exists
$fileName = $this->_createFileName('template', ['name' => $file]);
$path = Path::find($this->_path['template'], $fileName);
if ($path) {
$layout = $file;
} else {
$layout = ($file == 'emptystate') ? 'default' : $layout;
}
}
return $layout;
}
throw new \Exception('TraitAllediaView must apply to a Joomla view', 500);
}
}

View File

@ -0,0 +1,103 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\View;
defined('_JEXEC') or die();
use Alledia\Framework\Factory;
use Alledia\Framework\Joomla\Extension\Helper as ExtensionHelper;
use Alledia\Framework\Joomla\Extension\Licensed;
use Joomla\CMS\Filesystem\File;
use Joomla\CMS\HTML\HTMLHelper;
/**
* @deprecated v2.0.5
*/
class Admin extends Base
{
/**
* @var string
*/
protected $option = null;
/**
* @var Licensed
*/
protected $extension = null;
/**
* @param array $config
*
* @throws \Exception
*/
public function __construct($config = [])
{
parent::__construct($config);
$info = ExtensionHelper::getExtensionInfoFromElement($this->option);
$this->option = Factory::getApplication()->input->get('option');
$this->extension = Factory::getExtension($info['namespace'], $info['type']);
}
public function display($tpl = null)
{
// Add default admin CSS
HTMLHelper::_('stylesheet', $this->option . '/admin-default.css', ['relative' => true]);
parent::display($tpl);
$this->displayFooter();
}
protected function displayFooter()
{
$output = '';
$layoutPath = $this->extension->getExtensionPath() . '/views/footer/tmpl/default.php';
if (!File::exists($layoutPath)) {
$layoutPath = $this->extension->getExtensionPath() . '/alledia_views/footer/tmpl/default.php';
if (!File::exists($layoutPath)) {
$layoutPath = null;
}
}
if (!is_null($layoutPath)) {
// Start capturing output into a buffer
ob_start();
// Include the requested template filename in the local scope
// (this will execute the view logic).
include $layoutPath;
// Done with the requested template; get the buffer and
// clear it.
$output = ob_get_contents();
ob_end_clean();
}
echo $output;
}
}

View File

@ -0,0 +1,86 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2021-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\View\Admin;
use Alledia\Framework\Extension;
use Alledia\Framework\Joomla\AbstractView;
use Joomla\CMS\Filesystem\File;
defined('_JEXEC') or die();
class AbstractBase extends AbstractView
{
/**
* @inheritDoc
*/
protected function displayFooter(?Extension $extension = null)
{
parent::displayFooter();
echo $this->displayAdminFooter($extension);
}
/**
* @param ?Extension $extension
*
* @return string
*/
protected function displayAdminFooter(?Extension $extension = null): string
{
$extension = $extension ?: ($this->extension ?? null);
if ($extension) {
$output = $extension->getFooterMarkup();
if (empty($output)) {
// Use alternative if no custom footer field
$layoutPath = $extension->getExtensionPath() . '/views/footer/tmpl/default.php';
if (!File::exists($layoutPath)) {
$layoutPath = $extension->getExtensionPath() . '/alledia_views/footer/tmpl/default.php';
}
if (File::exists($layoutPath)) {
ob_start();
include $layoutPath;
$output = ob_get_contents();
ob_end_clean();
}
}
}
return $output ?? '';
}
/**
* @inheritDoc
* @throws \Exception
*/
public function setLayout($layout)
{
$layout = $this->getVersionedLayoutName($layout);
return parent::setLayout($layout);
}
}

View File

@ -0,0 +1,70 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2021-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\View\Admin;
use Joomla\CMS\Form\Form;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\Version;
defined('_JEXEC') or die();
class AbstractForm extends AbstractBase
{
/**
* @var Form
*/
protected $form = null;
/**
* @var bool
*/
protected $useCoreUI = true;
/**
* @inheritDoc
*/
protected function setup()
{
parent::setup();
if (Version::MAJOR_VERSION < 4) {
HTMLHelper::_('behavior.tabstate');
}
}
/**
* @inheritDoc
*
*/
public function setModel($model, $default = false)
{
$model = parent::setModel($model, $default);
if ($model instanceof AdminModel && $default) {
$this->form = $model->getForm();
}
return $model;
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2021-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\View\Admin;
defined('_JEXEC') or die();
use Joomla\CMS\Form\Form;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Pagination\Pagination;
use Joomla\CMS\Version;
abstract class AbstractList extends AbstractBase
{
/**
* @var object[]
*/
protected $items = null;
/**
* @var string
*/
protected $sidebar = null;
/**
* @var Pagination
*/
protected $pagination = null;
/**
* @var Form
*/
public $filterForm = null;
/**
* @var string[]
*/
public $activeFilters = null;
/**
* @var bool
*/
protected $isEmptyState = null;
public function display($tpl = null)
{
// Add default admin CSS
HTMLHelper::_('stylesheet', $this->option . '/admin-default.css', ['relative' => true]);
if (
Version::MAJOR_VERSION > 3
&& empty($this->items)
&& ($this->isEmptyState = $this->get('IsEmptyState'))
) {
$this->setLayout('emptystate');
}
parent::display($tpl);
}
}

View File

@ -0,0 +1,36 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\View;
use Joomla\CMS\MVC\View\HtmlView;
defined('_JEXEC') or die();
/**
* @deprecated v2.0.5
*/
class Base extends HtmlView
{
}

View File

@ -0,0 +1,67 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2021-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\View\Site;
use Alledia\Framework\Joomla\AbstractView;
use Joomla\Registry\Registry;
defined('_JEXEC') or die();
class AbstractBase extends AbstractView
{
/**
* @var Registry
*/
protected $params = null;
/**
* @inheritDoc
*/
public function setModel($model, $default = false)
{
$model = parent::setModel($model, $default);
$this->setParams();
return $model;
}
/**
* @return void
*/
protected function setParams()
{
$this->params = new Registry();
// Load component parameters first
$this->params->merge($this->extension->params);
if ($activeMenu = $this->app->getMenu()->getActive()) {
// We're on a menu - add/override its parameters
$this->params->merge($activeMenu->getParams());
$this->params->def('page_heading', $this->params->get('page_title') ?: $activeMenu->title);
}
}
}

View File

@ -0,0 +1,53 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2021-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Joomla\View\Site;
defined('_JEXEC') or die();
use Joomla\CMS\Form\Form;
use Joomla\CMS\Pagination\Pagination;
abstract class AbstractList extends AbstractBase
{
/**
* @var object[]
*/
protected $items = null;
/**
* @var Pagination
*/
protected $pagination = null;
/**
* @var Form
*/
public $filterForm = null;
/**
* @var string[]
*/
public $activeFilters = null;
}

View File

@ -0,0 +1,104 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework;
use Exception;
use Joomla\CMS\Log\Log;
defined('_JEXEC') or die();
abstract class Loader
{
/**
* @var bool
*/
protected static $logRegistered = false;
/**
* Safelly include a PHP file, making sure it exists before import.
*
* This method will register a log message and display a warning for admins
* in case the file is missed.
*
* @param string $path The file path you want to include
*
* @return bool True, if the file exists and was loaded well.
* @throws Exception
*/
public static function includeFile($path)
{
if (!static::$logRegistered) {
Log::addLogger(
['text_file' => 'allediaframework.loader.errors.php'],
Log::ALL,
['allediaframework']
);
static::$logRegistered = true;
}
// Check if the file doesn't exist
if (!is_file($path)) {
$logMsg = 'Required file is missed: ' . $path;
// Generate a backtrace to know from where the request cames
if (version_compare(phpversion(), '5.4', '<')) {
$backtrace = debug_backtrace();
} else {
$backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
}
if (!empty($backtrace)) {
$logMsg .= sprintf(
' (%s:%s)',
$backtrace[0]['file'],
$backtrace[0]['line']
);
}
// Register the log
Log::add($logMsg, Log::ERROR, 'allediaframework');
// Warn admin users
$app = Factory::getApplication();
if ($app->isClient('administrator')) {
$app->enqueueMessage(
'Joomlashack Framework Loader detected that a required file was not found! Please, check the logs.',
'error'
);
}
// Stand up a flag to warn a required file is missed
if (!defined('ALLEDIA_FRAMEWORK_MISSED_FILE')) {
define('ALLEDIA_FRAMEWORK_MISSED_FILE', true);
}
return false;
}
include_once($path);
return true;
}
}

View File

@ -0,0 +1,117 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework\Network;
defined('_JEXEC') or die();
class Request
{
/**
* post
* POST request
*
* @access public
*
* @param string $url
* @param array $data
*
* @return string
*/
public function post($url, $data = [])
{
if ($this->hasCURL()) {
return $this->postCURL($url, $data);
} else {
return $this->postFOpen($url, $data);
}
}
/**
* hasCURL
* Does the server have the curl extension ?
*
* @access protected
* @return bool
*/
protected function hasCURL()
{
return function_exists('curl_init');
}
/**
* postCURL
* POST request with curl
*
* @access protected
*
* @param string $url
* @param array $data
*
* @return string
*/
protected function postCURL($url, $data = [])
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($data));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
curl_close($ch);
return $contents;
}
/**
* postFOpen
* POST request with fopen
*
* @access protected
*
* @param string $url
* @param array $data
*
* @return string
*/
protected function postFOpen($url, $data = [])
{
$stream = fopen($url, 'r', false, stream_context_create([
'http' => [
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query(
$data
)
]
]));
$contents = stream_get_contents($stream);
fclose($stream);
return $contents;
}
}

View File

@ -0,0 +1,144 @@
<?php
/**
* @package AllediaFramework
* @contact www.joomlashack.com, help@joomlashack.com
* @copyright 2016-2023 Joomlashack.com. All rights reserved
* @license https://www.gnu.org/licenses/gpl.html GNU/GPL
*
* This file is part of AllediaFramework.
*
* AllediaFramework is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* AllediaFramework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AllediaFramework. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Alledia\Framework;
defined('_JEXEC') or die();
class Profiler
{
/**
* @var int
*/
protected $startTime = 0;
/**
* @var int
*/
protected $initialMemory = 0;
/**
* @var int
*/
protected $maxLength = 80;
/**
* @var int
*/
protected $lastMemory = 0;
/**
* @return void
*/
public function start()
{
$this->initialMemory = memory_get_usage();
}
/**
* @param string $label
*
* @return void
*/
public function step($label = null)
{
$this->startStep($label);
$this->endStep();
}
/**
* @return void
*/
public function echoData()
{
echo "\n";
$total = memory_get_usage() - $this->initialMemory;
$data = '==== Mem: ' . number_format($total, 0, '.', ',') . ' bytes';
$diff = $total - $this->lastMemory;
$peak = memory_get_peak_usage();
$operator = '';
echo $data;
if ($diff != 0) {
$operator = $diff > 0 ? '+' : '-';
}
echo ' diff: ' . $operator . number_format(abs($diff), 0, '.', ',') . ' bytes'
. ' peak: ' . number_format($peak, '0', '.', ',') . ' bytes';
$this->lastMemory = $total;
echo "\n";
}
/**
* @param string $label
*/
public function startStep($label = null)
{
echo "\n";
$this->printHeader($label);
$this->echoData();
}
/**
* @return void
*/
public function endStep()
{
$this->echoData();
$this->printSeparator();
echo "\n";
}
/**
* @param string $label
* @param int $leftPadding
*
* @return void
*/
protected function printHeader($label = null, $leftPadding = 4)
{
if (!is_null($label)) {
$length = $leftPadding;
echo str_repeat('=', $length);
echo " $label ";
$length += strlen($label) + 2;
echo str_repeat('=', $this->maxLength - $length);
} else {
$this->printSeparator();
}
}
/**
* @return void
*/
protected function printSeparator()
{
echo str_repeat('=', $this->maxLength);
}
}