Helper.php
3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* @package AllediaFramework
* @contact www.alledia.com, hello@alledia.com
* @copyright 2016 Alledia.com, All rights reserved
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
namespace Alledia\Framework;
use Alledia\Framework\Joomla\Extension\Helper as ExtensionHelper;
use Alledia\Framework\Factory;
use JLog;
defined('_JEXEC') or die();
abstract class Helper
{
/**
* Return an array of Alledia extensions
*
* @todo Move this method for the class Alledia\Framework\Joomla\Extension\Helper, but keep as deprecated
*
* @param string $license
* @return array
*/
public static function getAllediaExtensions($license = '')
{
// Get the extensions ids
$db = \JFactory::getDbo();
$query = $db->getQuery(true)
->select(
array(
$db->quoteName('extension_id'),
$db->quoteName('type'),
$db->quoteName('element'),
$db->quoteName('folder')
)
)
->from('#__extensions')
->where(
array(
$db->quoteName('custom_data') . " LIKE '%\"author\":\"Alledia\"%'",
$db->quoteName('custom_data') . " LIKE '%\"author\":\"OSTraining\"%'",
$db->quoteName('custom_data') . " LIKE '%\"author\":\"Joomlashack\"%'",
$db->quoteName('manifest_cache') . " LIKE '%\"author\":\"Alledia\"%'",
$db->quoteName('manifest_cache') . " LIKE '%\"author\":\"OSTraining\"%'",
$db->quoteName('manifest_cache') . " LIKE '%\"author\":\"Joomlashack\"%'"
),
'OR'
)
->group($db->quoteName('extension_id'));
$db->setQuery($query);
$rows = $db->loadObjectList();
$extensions = array();
foreach ($rows as $row) {
$fullElement = $row->element;
// Fix the element for plugins
if ($row->type === 'plugin') {
$fullElement = ExtensionHelper::getFullElementFromInfo($row->type, $row->element, $row->folder) ;
}
$extensionInfo = ExtensionHelper::getExtensionInfoFromElement($fullElement);
$extension = new Joomla\Extension\Licensed($extensionInfo['namespace'], $row->type, $row->folder);
if (!empty($license)) {
if ($license === 'pro' && ! $extension->isPro()) {
continue;
} elseif ($license === 'free' && $extension->isPro()) {
continue;
}
}
$extensions[$row->extension_id] = $extension;
}
return $extensions;
}
public static function getJoomlaVersionCssClass()
{
return 'joomla' . (version_compare(JVERSION, '3.0', 'lt') ? '25' : '3x');
}
public static function callMethod($className, $methodName, $params = array())
{
$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(array($instance, $methodName), $params);
}
}
return $result;
}
}