1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
$Id$ |
4
|
|
|
|
5
|
|
|
osCommerce, Open Source E-Commerce Solutions |
6
|
|
|
http://www.oscommerce.com |
7
|
|
|
|
8
|
|
|
Copyright (c) 2013 osCommerce |
9
|
|
|
|
10
|
|
|
Released under the GNU General Public License |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
use OSC\OM\Cache; |
14
|
|
|
use OSC\OM\FileSystem; |
15
|
|
|
use OSC\OM\HTTP; |
16
|
|
|
use OSC\OM\OSCOM; |
17
|
|
|
use OSC\OM\Registry; |
18
|
|
|
|
19
|
|
|
class d_partner_news { |
20
|
|
|
var $code = 'd_partner_news'; |
21
|
|
|
var $title; |
22
|
|
|
var $description; |
23
|
|
|
var $sort_order; |
24
|
|
|
var $enabled = false; |
25
|
|
|
|
26
|
|
|
function d_partner_news() { |
27
|
|
|
$this->title = MODULE_ADMIN_DASHBOARD_PARTNER_NEWS_TITLE; |
28
|
|
|
$this->description = MODULE_ADMIN_DASHBOARD_PARTNER_NEWS_DESCRIPTION; |
29
|
|
|
|
30
|
|
|
if ( defined('MODULE_ADMIN_DASHBOARD_PARTNER_NEWS_STATUS') ) { |
31
|
|
|
$this->sort_order = MODULE_ADMIN_DASHBOARD_PARTNER_NEWS_SORT_ORDER; |
32
|
|
|
$this->enabled = (MODULE_ADMIN_DASHBOARD_PARTNER_NEWS_STATUS == 'True'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
if ( !function_exists('json_decode') ) { |
36
|
|
|
$this->description .= '<p style="color: #ff0000; font-weight: bold;">' . MODULE_ADMIN_DASHBOARD_PARTNER_NEWS_ERROR_JSON_DECODE . '</p>'; |
37
|
|
|
|
38
|
|
|
$this->enabled = false; |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
function getOutput() { |
43
|
|
|
$result = $this->_getContent(); |
44
|
|
|
|
45
|
|
|
$output = null; |
46
|
|
|
|
47
|
|
|
if (is_array($result) && !empty($result)) { |
48
|
|
|
$output = '<table class="table table-hover"> |
49
|
|
|
<thead> |
50
|
|
|
<tr class="info"> |
51
|
|
|
<th>' . MODULE_ADMIN_DASHBOARD_PARTNER_NEWS_TITLE . '</th> |
52
|
|
|
</tr> |
53
|
|
|
</thead> |
54
|
|
|
<tbody>'; |
55
|
|
|
|
56
|
|
|
foreach ($result as $p) { |
57
|
|
|
$output .= ' <tr> |
58
|
|
|
<td><a href="' . $p['url'] . '" target="_blank"><strong>' . $p['title'] . '</strong></a> <span class="label label-info">' . $p['category_title'] . '</span><br />' . $p['status_update'] . '</td> |
59
|
|
|
</tr>'; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$output .= ' <tr> |
63
|
|
|
<td class="text-right"><a href="https://www.oscommerce.com/Services" target="_blank">' . MODULE_ADMIN_DASHBOARD_PARTNER_NEWS_MORE_TITLE . '</a></td> |
64
|
|
|
</tr> |
65
|
|
|
</tbody> |
66
|
|
|
</table>'; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $output; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
function _getContent() { |
73
|
|
|
$result = null; |
74
|
|
|
|
75
|
|
|
$NewsCache = new Cache('oscommerce_website-partner_news'); |
76
|
|
|
|
77
|
|
|
if ($NewsCache->exists(60)) { |
78
|
|
|
$result = $NewsCache->get(); |
79
|
|
|
} else { |
80
|
|
|
$response = HTTP::getResponse([ |
81
|
|
|
'url' => 'https://www.oscommerce.com/index.php?RPC&Website&Index&GetPartnerStatusUpdates' |
82
|
|
|
]); |
83
|
|
|
|
84
|
|
|
if (!empty($response)) { |
85
|
|
|
$response = json_decode($response, true); |
86
|
|
|
|
87
|
|
|
if (is_array($response) && !empty($response)) { |
88
|
|
|
$result = $response; |
89
|
|
|
|
90
|
|
|
$NewsCache->save($result); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $result; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
function isEnabled() { |
99
|
|
|
return $this->enabled; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
function check() { |
103
|
|
|
return defined('MODULE_ADMIN_DASHBOARD_PARTNER_NEWS_STATUS'); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
function install() { |
107
|
|
|
$OSCOM_Db = Registry::get('Db'); |
108
|
|
|
|
109
|
|
|
$OSCOM_Db->save('configuration', [ |
110
|
|
|
'configuration_title' => 'Enable Partner News Module', |
111
|
|
|
'configuration_key' => 'MODULE_ADMIN_DASHBOARD_PARTNER_NEWS_STATUS', |
112
|
|
|
'configuration_value' => 'True', |
113
|
|
|
'configuration_description' => 'Do you want to show the latest osCommerce Partner News on the dashboard?', |
114
|
|
|
'configuration_group_id' => '6', |
115
|
|
|
'sort_order' => '1', |
116
|
|
|
'set_function' => 'tep_cfg_select_option(array(\'True\', \'False\'), ', |
117
|
|
|
'date_added' => 'now()' |
118
|
|
|
]); |
119
|
|
|
|
120
|
|
|
$OSCOM_Db->save('configuration', [ |
121
|
|
|
'configuration_title' => 'Sort Order', |
122
|
|
|
'configuration_key' => 'MODULE_ADMIN_DASHBOARD_PARTNER_NEWS_SORT_ORDER', |
123
|
|
|
'configuration_value' => '0', |
124
|
|
|
'configuration_description' => 'Sort order of display. Lowest is displayed first.', |
125
|
|
|
'configuration_group_id' => '6', |
126
|
|
|
'sort_order' => '0', |
127
|
|
|
'date_added' => 'now()' |
128
|
|
|
]); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
function remove() { |
132
|
|
|
return Registry::get('Db')->exec('delete from :table_configuration where configuration_key in ("' . implode('", "', $this->keys()) . '")'); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
function keys() { |
136
|
|
|
return array('MODULE_ADMIN_DASHBOARD_PARTNER_NEWS_STATUS', 'MODULE_ADMIN_DASHBOARD_PARTNER_NEWS_SORT_ORDER'); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
?> |
|
|
|
|
140
|
|
|
|
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.