Helper.php
3.1 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/**
* @package AllediaInstaller
* @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\Joomla\Extension;
use Alledia\Framework\Factory;
defined('_JEXEC') or die();
/**
* Generic extension helper class
*/
abstract class Helper
{
/**
* Build a string representing the element
*/
public static function getFullElementFromInfo($type, $element, $folder = null)
{
$prefixes = array(
'component' => 'com',
'plugin' => 'plg',
'template' => 'tpl',
'library' => 'lib',
'cli' => 'cli',
'module' => 'mod'
);
$fullElement = $prefixes[$type];
if ($type === 'plugin') {
$fullElement .= '_' . $folder;
}
$fullElement .= '_' . $element;
return $fullElement;
}
public static function getExtensionInfoFromElement($element)
{
$result = array(
'type' => null,
'name' => null,
'group' => null,
'prefix' => null,
'namespace' => null
);
$types = array(
'com' => 'component',
'plg' => 'plugin',
'mod' => 'module',
'lib' => 'library',
'tpl' => 'template',
'cli' => 'cli'
);
$element = explode('_', $element);
$result['prefix'] = $element[0];
if (array_key_exists($result['prefix'], $types)) {
$result['type'] = $types[$result['prefix']];
if ($result['prefix'] === 'plg') {
$result['group'] = $element[1];
$result['name'] = $element[2];
} else {
$result['name'] = $element[1];
$result['group'] = null;
}
}
$result['namespace'] = preg_replace_callback(
'/^(os[a-z])(.*)/i',
function($matches) {
return strtoupper($matches[1]) . $matches[2];
},
$result['name']
);
return $result;
}
public static function loadLibrary($element)
{
$extension = static::getExtensionForElement($element);
if (is_object($extension)) {
return $extension->loadLibrary();
}
return null;
}
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 '';
}
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;
}
}