|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* TDMDownload |
|
4
|
|
|
* |
|
5
|
|
|
* You may not change or alter any portion of this comment or credits |
|
6
|
|
|
* of supporting developers from this source code or any supporting source code |
|
7
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
8
|
|
|
* This program is distributed in the hope that it will be useful, |
|
9
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
11
|
|
|
* |
|
12
|
|
|
* @copyright Gregory Mage (Aka Mage) |
|
13
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
14
|
|
|
* @author Gregory Mage (Aka Mage) |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
//********************************************************************************************************************** |
|
18
|
|
|
// ModuleName_checkModuleAdmin |
|
19
|
|
|
//********************************************************************************************************************** |
|
20
|
|
|
// return true if moduladmin framworks exists. |
|
21
|
|
|
//********************************************************************************************************************** |
|
22
|
|
|
function TDMDownloads_checkModuleAdmin() |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
if ( file_exists($GLOBALS['xoops']->path('/Frameworks/moduleclasses/moduleadmin/moduleadmin.php'))) { |
|
25
|
|
|
include_once $GLOBALS['xoops']->path('/Frameworks/moduleclasses/moduleadmin/moduleadmin.php'); |
|
26
|
|
|
|
|
27
|
|
|
return true; |
|
28
|
|
|
} else { |
|
29
|
|
|
echo xoops_error("Error: You don't use the Frameworks \"admin module\". Please install this Frameworks"); |
|
30
|
|
|
|
|
31
|
|
|
return false; |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
function TDMDownloads_MygetItemIds($permtype,$dirname) |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
|
|
global $xoopsUser; |
|
|
|
|
|
|
38
|
|
|
static $permissions = array(); |
|
39
|
|
|
if (is_array($permissions) && array_key_exists($permtype, $permissions)) { |
|
40
|
|
|
return $permissions[$permtype]; |
|
41
|
|
|
} |
|
42
|
|
|
$module_handler =& xoops_gethandler('module'); |
|
43
|
|
|
$tdmModule =& $module_handler->getByDirname($dirname); |
|
44
|
|
|
$groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
45
|
|
|
$gperm_handler =& xoops_gethandler('groupperm'); |
|
46
|
|
|
$categories = $gperm_handler->getItemIds($permtype, $groups, $tdmModule->getVar('mid')); |
|
47
|
|
|
|
|
48
|
|
|
return $categories; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* retourne le nombre de t�l�chargements dans le cat�gories enfants d'une cat�gorie |
|
53
|
|
|
**/ |
|
54
|
|
|
|
|
55
|
|
|
function TDMDownloads_NumbersOfEntries($mytree, $categories, $entries,$cid) |
|
56
|
|
|
{ |
|
57
|
|
|
$count = 0; |
|
58
|
|
|
$child_arr = array(); |
|
|
|
|
|
|
59
|
|
|
if (in_array($cid, $categories)) { |
|
60
|
|
|
$child = $mytree->getAllChild($cid); |
|
61
|
|
|
foreach (array_keys($entries) as $i) { |
|
62
|
|
|
if ($entries[$i]->getVar('cid') == $cid) { |
|
63
|
|
|
$count++; |
|
64
|
|
|
} |
|
65
|
|
|
foreach (array_keys($child) as $j) { |
|
66
|
|
|
if ($entries[$i]->getVar('cid') == $j) { |
|
67
|
|
|
$count++; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
return $count; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* retourne une image "nouveau" ou "mise � jour" |
|
78
|
|
|
**/ |
|
79
|
|
|
|
|
80
|
|
|
function TDMDownloads_Thumbnail($time, $status) |
|
|
|
|
|
|
81
|
|
|
{ |
|
82
|
|
|
global $xoopsModuleConfig; |
|
|
|
|
|
|
83
|
|
|
$count = 7; |
|
84
|
|
|
$new = ''; |
|
85
|
|
|
$startdate = (time()-(86400 * $count)); |
|
86
|
|
|
if ($xoopsModuleConfig['showupdated'] == 1) { |
|
87
|
|
|
if ($startdate < $time) { |
|
88
|
|
|
$language = $GLOBALS['xoopsConfig']['language']; |
|
89
|
|
|
if ( !is_dir( XOOPS_ROOT_PATH . "/modules/TDMDownloads/language/" . $language . "/" ) ) { |
|
90
|
|
|
$language = 'english'; |
|
91
|
|
|
} |
|
92
|
|
|
$img_path = XOOPS_ROOT_PATH . "/modules/TDMDownloads/language/" . $language . "/"; |
|
93
|
|
|
$img_url = XOOPS_URL . "/modules/TDMDownloads/language/" . $language . "/"; |
|
94
|
|
|
if ($status==1) { |
|
95
|
|
View Code Duplication |
if ( is_readable( $img_path . 'new.png') ) { |
|
|
|
|
|
|
96
|
|
|
$new = ' <img src="' . $img_url . 'new.png" alt="' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . '" title="' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . '"/>'; |
|
97
|
|
|
} else { |
|
98
|
|
|
$new = ' <img src="' . XOOPS_URL . '/modules/TDMDownloads/language/english/new.png" alt="' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . '" title="' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . '"/>'; |
|
99
|
|
|
} |
|
100
|
|
View Code Duplication |
} elseif ($status==2) { |
|
|
|
|
|
|
101
|
|
|
if ( is_readable( $img_path . 'updated.png') ) { |
|
102
|
|
|
$new = ' <img src="' . $img_url . 'updated.png" alt="' . _MD_TDMDOWNLOADS_INDEX_UPTHISWEEK . '" title="' . _MD_TDMDOWNLOADS_INDEX_UPTHISWEEK . '"/>'; |
|
103
|
|
|
} else { |
|
104
|
|
|
$new = ' <img src="' . XOOPS_URL . '/modules/TDMDownloads/language/english/updated.png" alt="' . _MD_TDMDOWNLOADS_INDEX_UPTHISWEEK . '" title="' . _MD_TDMDOWNLOADS_INDEX_UPTHISWEEK . '"/>'; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
return $new; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* retourne une image "populaire" |
|
116
|
|
|
**/ |
|
117
|
|
|
|
|
118
|
|
|
function TDMDownloads_Popular($hits) |
|
|
|
|
|
|
119
|
|
|
{ |
|
120
|
|
|
global $xoopsModuleConfig; |
|
|
|
|
|
|
121
|
|
|
$pop = ''; |
|
122
|
|
|
if ($hits >= $xoopsModuleConfig['popular']) { |
|
123
|
|
|
$language = $GLOBALS['xoopsConfig']['language']; |
|
124
|
|
|
if ( !is_dir( XOOPS_ROOT_PATH . "/modules/TDMDownloads/language/" . $language . "/" ) ) { |
|
125
|
|
|
$language = 'english'; |
|
126
|
|
|
} |
|
127
|
|
|
$img_path = XOOPS_ROOT_PATH . "/modules/TDMDownloads/language/" . $language . "/"; |
|
128
|
|
|
$img_url = XOOPS_URL . "/modules/TDMDownloads/language/" . $language . "/"; |
|
129
|
|
View Code Duplication |
if ( is_readable( $img_path . 'popular.png') ) { |
|
|
|
|
|
|
130
|
|
|
$pop = ' <img src="' . $img_url . 'popular.png" alt="' . _MD_TDMDOWNLOADS_INDEX_POPULAR . '" title="' . _MD_TDMDOWNLOADS_INDEX_POPULAR . '"/>'; |
|
131
|
|
|
} else { |
|
132
|
|
|
$pop = ' <img src ="' . XOOPS_URL . '/modules/TDMDownloads/language/english/popular.png" alt="' . _MD_TDMDOWNLOADS_INDEX_POPULAR . '" title="' . _MD_TDMDOWNLOADS_INDEX_POPULAR . '"/>'; |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
return $pop; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
function trans_size($size) |
|
140
|
|
|
{ |
|
141
|
|
|
if ($size>0) { |
|
142
|
|
|
$mb = 1024*1024; |
|
143
|
|
|
if ($size > $mb) { |
|
144
|
|
|
$mysize = sprintf ("%01.2f",$size/$mb) . " MB"; |
|
145
|
|
|
} elseif ($size >= 1024) { |
|
146
|
|
|
$mysize = sprintf ("%01.2f",$size/1024) . " KB"; |
|
147
|
|
|
} else { |
|
148
|
|
|
$mysize = sprintf(_AM_TDMDOWNLOADS_NUMBYTES,$size); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
return $mysize; |
|
152
|
|
|
} else { |
|
153
|
|
|
return ''; |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
function TDMDownloads_CleanVars( &$global, $key, $default = '', $type = 'int' ) |
|
158
|
|
|
{ |
|
159
|
|
|
switch ($type) { |
|
160
|
|
|
case 'string': |
|
161
|
|
|
$ret = ( isset( $global[$key] ) ) ? filter_var( $global[$key], FILTER_SANITIZE_MAGIC_QUOTES ) : $default; |
|
162
|
|
|
break; |
|
163
|
|
|
case 'int': default: |
|
|
|
|
|
|
164
|
|
|
$ret = ( isset( $global[$key] ) ) ? filter_var( $global[$key], FILTER_SANITIZE_NUMBER_INT ) : $default; |
|
165
|
|
|
break; |
|
166
|
|
|
} |
|
167
|
|
|
if ($ret === false) { |
|
168
|
|
|
return $default; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
return $ret; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
function TDMDownloads_PathTree($mytree, $key, $category_array, $title, $prefix = '' ) |
|
175
|
|
|
{ |
|
176
|
|
|
$category_parent = $mytree->getAllParent($key); |
|
177
|
|
|
$category_parent = array_reverse($category_parent); |
|
178
|
|
|
$Path = ''; |
|
179
|
|
|
foreach (array_keys($category_parent) as $j) { |
|
180
|
|
|
$Path .= $category_parent[$j]->getVar($title) . $prefix; |
|
181
|
|
|
} |
|
182
|
|
View Code Duplication |
if (array_key_exists($key, $category_array)) { |
|
|
|
|
|
|
183
|
|
|
$first_category = $category_array[$key]->getVar($title); |
|
184
|
|
|
} else { |
|
185
|
|
|
$first_category = ''; |
|
186
|
|
|
} |
|
187
|
|
|
$Path .= $first_category; |
|
188
|
|
|
|
|
189
|
|
|
return $Path; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
function TDMDownloads_PathTreeUrl($mytree, $key, $category_array, $title, $prefix = '', $link = false, $order = 'ASC', $lasturl = false) |
|
193
|
|
|
{ |
|
194
|
|
|
global $xoopsModule; |
|
|
|
|
|
|
195
|
|
|
$category_parent = $mytree->getAllParent($key); |
|
196
|
|
|
if ($order == 'ASC') { |
|
197
|
|
|
$category_parent = array_reverse($category_parent); |
|
198
|
|
|
if ($link == true) { |
|
|
|
|
|
|
199
|
|
|
$Path = '<a href="index.php">' . $xoopsModule->name() . '</a>' . $prefix; |
|
200
|
|
|
} else { |
|
201
|
|
|
$Path = $xoopsModule->name() . $prefix; |
|
202
|
|
|
} |
|
203
|
|
|
} else { |
|
204
|
|
View Code Duplication |
if (array_key_exists($key, $category_array)) { |
|
|
|
|
|
|
205
|
|
|
$first_category = $category_array[$key]->getVar($title); |
|
206
|
|
|
} else { |
|
207
|
|
|
$first_category = ''; |
|
208
|
|
|
} |
|
209
|
|
|
$Path = $first_category . $prefix; |
|
210
|
|
|
} |
|
211
|
|
|
foreach (array_keys($category_parent) as $j) { |
|
212
|
|
|
if ($link == true) { |
|
|
|
|
|
|
213
|
|
|
$Path .= '<a href="viewcat.php?cid=' . $category_parent[$j]->getVar('cat_cid') . '">' . $category_parent[$j]->getVar($title) . '</a>' . $prefix; |
|
214
|
|
|
} else { |
|
215
|
|
|
$Path .= $category_parent[$j]->getVar($title) . $prefix; |
|
216
|
|
|
} |
|
217
|
|
|
} |
|
218
|
|
|
if ($order == 'ASC') { |
|
219
|
|
|
if (array_key_exists($key, $category_array)) { |
|
220
|
|
|
if ($lasturl == true) { |
|
|
|
|
|
|
221
|
|
|
$first_category = '<a href="viewcat.php?cid=' . $category_array[$key]->getVar('cat_cid') . '">' . $category_array[$key]->getVar($title) . '</a>'; |
|
222
|
|
|
} else { |
|
223
|
|
|
$first_category = $category_array[$key]->getVar($title); |
|
224
|
|
|
} |
|
225
|
|
|
} else { |
|
226
|
|
|
$first_category = ''; |
|
227
|
|
|
} |
|
228
|
|
|
$Path .= $first_category; |
|
229
|
|
|
} else { |
|
230
|
|
|
if ($link == true) { |
|
|
|
|
|
|
231
|
|
|
$Path .= '<a href="index.php">' . $xoopsModule->name() . '</a>'; |
|
232
|
|
|
} else { |
|
233
|
|
|
$Path .= $xoopsModule->name(); |
|
234
|
|
|
} |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
return $Path; |
|
238
|
|
|
} |
|
239
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: