1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
$Id$ |
4
|
|
|
|
5
|
|
|
osCommerce, Open Source E-Commerce Solutions |
6
|
|
|
http://www.oscommerce.com |
7
|
|
|
|
8
|
|
|
Copyright (c) 2014 osCommerce |
9
|
|
|
|
10
|
|
|
Released under the GNU General Public License |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
use OSC\OM\Cache; |
14
|
|
|
use OSC\OM\DateTime; |
|
|
|
|
15
|
|
|
use OSC\OM\HTML; |
16
|
|
|
use OSC\OM\HTTP; |
17
|
|
|
use OSC\OM\OSCOM; |
18
|
|
|
use OSC\OM\Registry; |
19
|
|
|
|
20
|
|
|
class d_latest_addons { |
21
|
|
|
var $code = 'd_latest_addons'; |
22
|
|
|
var $title; |
23
|
|
|
var $description; |
24
|
|
|
var $sort_order; |
25
|
|
|
var $enabled = false; |
26
|
|
|
|
27
|
|
|
function d_latest_addons() { |
28
|
|
|
$this->title = MODULE_ADMIN_DASHBOARD_LATEST_ADDONS_TITLE; |
29
|
|
|
$this->description = MODULE_ADMIN_DASHBOARD_LATEST_ADDONS_DESCRIPTION; |
30
|
|
|
|
31
|
|
|
if ( defined('MODULE_ADMIN_DASHBOARD_LATEST_ADDONS_STATUS') ) { |
32
|
|
|
$this->sort_order = MODULE_ADMIN_DASHBOARD_LATEST_ADDONS_SORT_ORDER; |
33
|
|
|
$this->enabled = (MODULE_ADMIN_DASHBOARD_LATEST_ADDONS_STATUS == 'True'); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
function getOutput() { |
38
|
|
|
$entries = []; |
39
|
|
|
|
40
|
|
|
$addonsCache = new Cache('oscommerce_website-addons-latest5'); |
41
|
|
|
|
42
|
|
View Code Duplication |
if ($addonsCache->exists(360)) { |
|
|
|
|
43
|
|
|
$entries = $addonsCache->get(); |
44
|
|
|
} else { |
45
|
|
|
$response = HTTP::getResponse(['url' => 'https://www.oscommerce.com/index.php?RPC&GetLatestAddons']); |
46
|
|
|
|
47
|
|
|
if (!empty($response)) { |
48
|
|
|
$response = json_decode($response, true); |
49
|
|
|
|
50
|
|
|
if (is_array($response) && (count($response) === 5)) { |
51
|
|
|
$entries = $response; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$addonsCache->save($entries); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
$output = '<table class="table table-hover"> |
59
|
|
|
<thead> |
60
|
|
|
<tr class="info"> |
61
|
|
|
<th>' . MODULE_ADMIN_DASHBOARD_LATEST_ADDONS_TITLE . '</th> |
62
|
|
|
<th class="text-right">' . MODULE_ADMIN_DASHBOARD_LATEST_ADDONS_DATE . '</th> |
63
|
|
|
</tr> |
64
|
|
|
</thead> |
65
|
|
|
<tbody>'; |
66
|
|
|
|
67
|
|
View Code Duplication |
if (is_array($entries) && (count($entries) === 5)) { |
|
|
|
|
68
|
|
|
foreach ($entries as $item) { |
69
|
|
|
$output .= ' <tr> |
70
|
|
|
<td><a href="' . HTML::outputProtected($item['link']) . '" target="_blank">' . HTML::outputProtected($item['title']) . '</a></td> |
71
|
|
|
<td class="text-right" style="white-space: nowrap;">' . HTML::outputProtected(DateTime::toShort($item['date'])) . '</td> |
72
|
|
|
</tr>'; |
73
|
|
|
} |
74
|
|
|
} else { |
75
|
|
|
$output .= ' <tr> |
76
|
|
|
<td colspan="2">' . MODULE_ADMIN_DASHBOARD_LATEST_ADDONS_FEED_ERROR . '</td> |
77
|
|
|
</tr>'; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$output .= ' <tr> |
81
|
|
|
<td class="text-right" colspan="2"><a href="http://addons.oscommerce.com" target="_blank" title="' . HTML::outputProtected(MODULE_ADMIN_DASHBOARD_LATEST_ADDONS_ICON_SITE) . '"><span class="fa fa-fw fa-home"></span></a></td> |
82
|
|
|
</tr> |
83
|
|
|
</tbody> |
84
|
|
|
</table>'; |
85
|
|
|
|
86
|
|
|
return $output; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
function isEnabled() { |
90
|
|
|
return $this->enabled; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
function check() { |
94
|
|
|
return defined('MODULE_ADMIN_DASHBOARD_LATEST_ADDONS_STATUS'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
function install() { |
98
|
|
|
$OSCOM_Db = Registry::get('Db'); |
99
|
|
|
|
100
|
|
|
$OSCOM_Db->save('configuration', [ |
101
|
|
|
'configuration_title' => 'Enable Latest Add-Ons Module', |
102
|
|
|
'configuration_key' => 'MODULE_ADMIN_DASHBOARD_LATEST_ADDONS_STATUS', |
103
|
|
|
'configuration_value' => 'True', |
104
|
|
|
'configuration_description' => 'Do you want to show the latest osCommerce Add-Ons on the dashboard?', |
105
|
|
|
'configuration_group_id' => '6', |
106
|
|
|
'sort_order' => '1', |
107
|
|
|
'set_function' => 'tep_cfg_select_option(array(\'True\', \'False\'), ', |
108
|
|
|
'date_added' => 'now()' |
109
|
|
|
]); |
110
|
|
|
|
111
|
|
|
$OSCOM_Db->save('configuration', [ |
112
|
|
|
'configuration_title' => 'Sort Order', |
113
|
|
|
'configuration_key' => 'MODULE_ADMIN_DASHBOARD_LATEST_ADDONS_SORT_ORDER', |
114
|
|
|
'configuration_value' => '0', |
115
|
|
|
'configuration_description' => 'Sort order of display. Lowest is displayed first.', |
116
|
|
|
'configuration_group_id' => '6', |
117
|
|
|
'sort_order' => '0', |
118
|
|
|
'date_added' => 'now()' |
119
|
|
|
]); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
function remove() { |
123
|
|
|
return Registry::get('Db')->exec('delete from :table_configuration where configuration_key in ("' . implode('", "', $this->keys()) . '")'); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
function keys() { |
127
|
|
|
return array('MODULE_ADMIN_DASHBOARD_LATEST_ADDONS_STATUS', 'MODULE_ADMIN_DASHBOARD_LATEST_ADDONS_SORT_ORDER'); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
?> |
|
|
|
|
131
|
|
|
|
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: