1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits |
4
|
|
|
of supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* oledrion |
14
|
|
|
* |
15
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
16
|
|
|
* @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
17
|
|
|
* @author Hervé Thouzard (http://www.herve-thouzard.com/) |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* A set of useful and common functions |
22
|
|
|
* |
23
|
|
|
* @package oledrion |
24
|
|
|
* @author Hervé Thouzard - Instant Zero (http://xoops.instant-zero.com) |
25
|
|
|
* @copyright (c) Instant Zero |
26
|
|
|
* |
27
|
|
|
* Note: You should be able to use it without the need to instanciate it. |
28
|
|
|
* |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
|
|
|
|
32
|
|
|
|
33
|
|
|
use WideImage\WideImage; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Class OledrionUtility |
37
|
|
|
*/ |
38
|
|
|
class OledrionUtility |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
const MODULE_NAME = 'oledrion'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Access the only instance of this class |
44
|
|
|
* |
45
|
|
|
* @return object |
46
|
|
|
* |
47
|
|
|
* @static |
48
|
|
|
* @staticvar object |
49
|
|
|
*/ |
50
|
|
|
public function getInstance() |
51
|
|
|
{ |
52
|
|
|
static $instance; |
53
|
|
|
if (null === $instance) { |
54
|
|
|
$instance = new static(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $instance; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Returns a module's option (with cache) |
62
|
|
|
* |
63
|
|
|
* @param string $option module option's name |
64
|
|
|
* @param boolean $withCache Do we have to use some cache ? |
65
|
|
|
* @return mixed option's value |
66
|
|
|
*/ |
67
|
|
View Code Duplication |
public static function getModuleOption($option, $withCache = true) |
|
|
|
|
68
|
|
|
{ |
69
|
|
|
global $xoopsModuleConfig, $xoopsModule; |
|
|
|
|
70
|
|
|
$repmodule = static::MODULE_NAME; |
71
|
|
|
static $options = array(); |
72
|
|
|
if (is_array($options) && array_key_exists($option, $options) && $withCache) { |
73
|
|
|
return $options[$option]; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$retval = false; |
77
|
|
|
if (isset($xoopsModuleConfig) |
78
|
|
|
&& (is_object($xoopsModule) && $xoopsModule->getVar('dirname') == $repmodule |
79
|
|
|
&& $xoopsModule->getVar('isactive'))) { |
80
|
|
|
if (isset($xoopsModuleConfig[$option])) { |
81
|
|
|
$retval = $xoopsModuleConfig[$option]; |
82
|
|
|
} |
83
|
|
|
} else { |
84
|
|
|
/** @var XoopsModuleHandler $moduleHandler */ |
85
|
|
|
$moduleHandler = xoops_getHandler('module'); |
86
|
|
|
$module = $moduleHandler->getByDirname($repmodule); |
87
|
|
|
$configHandler = xoops_getHandler('config'); |
88
|
|
|
if ($module) { |
89
|
|
|
$moduleConfig = $configHandler->getConfigsByCat(0, $module->getVar('mid')); |
90
|
|
|
if (isset($moduleConfig[$option])) { |
91
|
|
|
$retval = $moduleConfig[$option]; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
$options[$option] = $retval; |
96
|
|
|
|
97
|
|
|
return $retval; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Is Xoops 2.3.x ? |
102
|
|
|
* |
103
|
|
|
* @return boolean |
104
|
|
|
*/ |
105
|
|
View Code Duplication |
public static function isX23() |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
$x23 = false; |
108
|
|
|
$xv = str_replace('XOOPS ', '', XOOPS_VERSION); |
109
|
|
|
if ((int)substr($xv, 2, 1) >= 3) { |
110
|
|
|
$x23 = true; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
return $x23; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Is Xoops 2.0.x ? |
118
|
|
|
* |
119
|
|
|
* @return boolean |
120
|
|
|
*/ |
121
|
|
View Code Duplication |
public static function isX20() |
|
|
|
|
122
|
|
|
{ |
123
|
|
|
$x20 = false; |
124
|
|
|
$xv = str_replace('XOOPS ', '', XOOPS_VERSION); |
125
|
|
|
if (substr($xv, 2, 1) == '0') { |
126
|
|
|
$x20 = true; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
return $x20; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Retreive an editor according to the module's option "form_options" |
134
|
|
|
* |
135
|
|
|
* @param string $caption Caption to give to the editor |
136
|
|
|
* @param string $name Editor's name |
137
|
|
|
* @param string $value Editor's value |
138
|
|
|
* @param string $width Editor's width |
139
|
|
|
* @param string $height Editor's height |
140
|
|
|
* @param string $supplemental |
141
|
|
|
* @return object The editor to use |
|
|
|
|
142
|
|
|
*/ |
143
|
|
View Code Duplication |
public static function getWysiwygForm( |
|
|
|
|
144
|
|
|
$caption, |
145
|
|
|
$name, |
146
|
|
|
$value = '', |
147
|
|
|
$width = '100%', |
148
|
|
|
$height = '400px', |
149
|
|
|
$supplemental = '') |
150
|
|
|
{ |
151
|
|
|
$editor = false; |
152
|
|
|
$editor_configs = array(); |
153
|
|
|
$editor_configs['name'] = $name; |
154
|
|
|
$editor_configs['value'] = $value; |
155
|
|
|
$editor_configs['rows'] = 35; |
156
|
|
|
$editor_configs['cols'] = 60; |
157
|
|
|
$editor_configs['width'] = '100%'; |
158
|
|
|
$editor_configs['height'] = '400px'; |
159
|
|
|
|
160
|
|
|
$editor_option = strtolower(static::getModuleOption('bl_form_options')); |
161
|
|
|
|
162
|
|
|
if (static::isX23()) { |
163
|
|
|
$editor = new XoopsFormEditor($caption, $editor_option, $editor_configs); |
164
|
|
|
|
165
|
|
|
return $editor; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
// Only for Xoops 2.0.x |
169
|
|
|
switch ($editor_option) { |
170
|
|
|
case 'fckeditor': |
171
|
|
|
if (is_readable(XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php')) { |
172
|
|
|
require_once XOOPS_ROOT_PATH . '/class/fckeditor/formfckeditor.php'; |
173
|
|
|
$editor = new XoopsFormFckeditor($caption, $name, $value); |
174
|
|
|
} |
175
|
|
|
break; |
176
|
|
|
|
177
|
|
|
case 'htmlarea': |
178
|
|
|
if (is_readable(XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php')) { |
179
|
|
|
require_once XOOPS_ROOT_PATH . '/class/htmlarea/formhtmlarea.php'; |
180
|
|
|
$editor = new XoopsFormHtmlarea($caption, $name, $value); |
181
|
|
|
} |
182
|
|
|
break; |
183
|
|
|
|
184
|
|
|
case 'dhtmltextarea': |
185
|
|
|
$editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 10, 50, $supplemental); |
186
|
|
|
break; |
187
|
|
|
|
188
|
|
|
case 'textarea': |
189
|
|
|
$editor = new XoopsFormTextArea($caption, $name, $value); |
190
|
|
|
break; |
191
|
|
|
|
192
|
|
|
case 'tinyeditor': |
193
|
|
|
case 'tinymce': |
194
|
|
|
if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinyeditortextarea.php')) { |
195
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinyeditortextarea.php'; |
196
|
|
|
$editor = new XoopsFormTinyeditorTextArea(array( |
197
|
|
|
'caption' => $caption, |
198
|
|
|
'name' => $name, |
199
|
|
|
'value' => $value, |
200
|
|
|
'width' => '100%', |
201
|
|
|
'height' => '400px' |
202
|
|
|
)); |
203
|
|
|
} |
204
|
|
|
break; |
205
|
|
|
|
206
|
|
|
case 'koivi': |
207
|
|
|
if (is_readable(XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php')) { |
208
|
|
|
require_once XOOPS_ROOT_PATH . '/class/wysiwyg/formwysiwygtextarea.php'; |
209
|
|
|
$editor = new XoopsFormWysiwygTextArea($caption, $name, $value, $width, $height, ''); |
210
|
|
|
} |
211
|
|
|
break; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
return $editor; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* Create (in a link) a javascript confirmation's box |
219
|
|
|
* |
220
|
|
|
* @param string $message Message to display |
221
|
|
|
* @param boolean $form Is this a confirmation for a form ? |
222
|
|
|
* @return string the javascript code to insert in the link (or in the form) |
223
|
|
|
*/ |
224
|
|
View Code Duplication |
public static function javascriptLinkConfirm($message, $form = false) |
|
|
|
|
225
|
|
|
{ |
226
|
|
|
if (!$form) { |
227
|
|
|
return "onclick=\"javascript:return confirm('" . str_replace("'", ' ', $message) . "')\""; |
228
|
|
|
} else { |
229
|
|
|
return "onSubmit=\"javascript:return confirm('" . str_replace("'", ' ', $message) . "')\""; |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Get current user IP |
235
|
|
|
* |
236
|
|
|
* @return string IP address (format Ipv4) |
237
|
|
|
*/ |
238
|
|
View Code Duplication |
public static function IP() |
|
|
|
|
239
|
|
|
{ |
240
|
|
|
$proxy_ip = ''; |
241
|
|
|
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
242
|
|
|
$proxy_ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
243
|
|
|
} elseif (!empty($_SERVER['HTTP_X_FORWARDED'])) { |
244
|
|
|
$proxy_ip = $_SERVER['HTTP_X_FORWARDED']; |
245
|
|
|
} elseif (!empty($_SERVER['HTTP_FORWARDED_FOR'])) { |
246
|
|
|
$proxy_ip = $_SERVER['HTTP_FORWARDED_FOR']; |
247
|
|
|
} elseif (!empty($_SERVER['HTTP_FORWARDED'])) { |
248
|
|
|
$proxy_ip = $_SERVER['HTTP_FORWARDED']; |
249
|
|
|
} elseif (!empty($_SERVER['HTTP_VIA'])) { |
250
|
|
|
$proxy_ip = $_SERVER['HTTP_VIA']; |
251
|
|
|
} elseif (!empty($_SERVER['HTTP_X_COMING_FROM'])) { |
252
|
|
|
$proxy_ip = $_SERVER['HTTP_X_COMING_FROM']; |
253
|
|
|
} elseif (!empty($_SERVER['HTTP_COMING_FROM'])) { |
254
|
|
|
$proxy_ip = $_SERVER['HTTP_COMING_FROM']; |
255
|
|
|
} |
256
|
|
|
$regs = array(); |
257
|
|
|
//if (!empty($proxy_ip) && $is_ip = ereg('^([0-9]{1,3}\.){3,3}[0-9]{1,3}', $proxy_ip, $regs) && count($regs) > 0) { |
|
|
|
|
258
|
|
|
if (!empty($proxy_ip) && filter_var($proxy_ip, FILTER_VALIDATE_IP) && count($regs) > 0) { |
259
|
|
|
$the_IP = $regs[0]; |
260
|
|
|
} else { |
261
|
|
|
$the_IP = $_SERVER['REMOTE_ADDR']; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
return $the_IP; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* Set the page's title, meta description and meta keywords |
269
|
|
|
* Datas are supposed to be sanitized |
270
|
|
|
* |
271
|
|
|
* @param string $pageTitle Page's Title |
272
|
|
|
* @param string $metaDescription Page's meta description |
273
|
|
|
* @param string $metaKeywords Page's meta keywords |
274
|
|
|
* @return void |
275
|
|
|
*/ |
276
|
|
View Code Duplication |
public static function setMetas($pageTitle = '', $metaDescription = '', $metaKeywords = '') |
|
|
|
|
277
|
|
|
{ |
278
|
|
|
global $xoTheme, $xoTheme, $xoopsTpl; |
|
|
|
|
279
|
|
|
$xoopsTpl->assign('xoops_pagetitle', $pageTitle); |
280
|
|
|
if (isset($xoTheme) && is_object($xoTheme)) { |
281
|
|
|
if (!empty($metaKeywords)) { |
282
|
|
|
$xoTheme->addMeta('meta', 'keywords', $metaKeywords); |
283
|
|
|
} |
284
|
|
|
if (!empty($metaDescription)) { |
285
|
|
|
$xoTheme->addMeta('meta', 'description', $metaDescription); |
286
|
|
|
} |
287
|
|
|
} elseif (isset($xoopsTpl) && is_object($xoopsTpl)) { // Compatibility for old Xoops versions |
288
|
|
|
if (!empty($metaKeywords)) { |
289
|
|
|
$xoopsTpl->assign('xoops_meta_keywords', $metaKeywords); |
290
|
|
|
} |
291
|
|
|
if (!empty($metaDescription)) { |
292
|
|
|
$xoopsTpl->assign('xoops_meta_description', $metaDescription); |
293
|
|
|
} |
294
|
|
|
} |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* Send an email from a template to a list of recipients |
299
|
|
|
* |
300
|
|
|
* @param $tplName |
301
|
|
|
* @param array $recipients List of recipients |
302
|
|
|
* @param string $subject Email's subject |
303
|
|
|
* @param array $variables Varirables to give to the template |
304
|
|
|
* @return bool Result of the send |
305
|
|
|
* @internal param string $tpl_name Template's name |
306
|
|
|
*/ |
307
|
|
View Code Duplication |
public static function sendEmailFromTpl($tplName, $recipients, $subject, $variables) |
|
|
|
|
308
|
|
|
{ |
309
|
|
|
global $xoopsConfig; |
|
|
|
|
310
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopsmailer.php'; |
311
|
|
|
if (!is_array($recipients)) { |
312
|
|
|
if (trim($recipients) == '') { |
313
|
|
|
return false; |
314
|
|
|
} |
315
|
|
|
} else { |
316
|
|
|
if (count($recipients) == 0) { |
317
|
|
|
return false; |
318
|
|
|
} |
319
|
|
|
} |
320
|
|
|
if (function_exists('xoops_getMailer')) { |
321
|
|
|
$xoopsMailer = xoops_getMailer(); |
322
|
|
|
} else { |
323
|
|
|
$xoopsMailer = xoops_getMailer(); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
$xoopsMailer->useMail(); |
327
|
|
|
$templateDir = XOOPS_ROOT_PATH . '/modules/' . static::MODULE_NAME . '/language/' . $xoopsConfig['language'] . '/mail_template'; |
328
|
|
|
if (!is_dir($templateDir)) { |
329
|
|
|
$templateDir = XOOPS_ROOT_PATH . '/modules/' . static::MODULE_NAME . '/language/english/mail_template'; |
330
|
|
|
} |
331
|
|
|
$xoopsMailer->setTemplateDir($templateDir); |
332
|
|
|
$xoopsMailer->setTemplate($tplName); |
333
|
|
|
$xoopsMailer->setToEmails($recipients); |
334
|
|
|
// TODO: Change ! |
335
|
|
|
// $xoopsMailer->setFromEmail('[email protected]'); |
|
|
|
|
336
|
|
|
//$xoopsMailer->setFromName('MonSite'); |
|
|
|
|
337
|
|
|
$xoopsMailer->setSubject($subject); |
338
|
|
|
foreach ($variables as $key => $value) { |
339
|
|
|
$xoopsMailer->assign($key, $value); |
340
|
|
|
} |
341
|
|
|
$res = $xoopsMailer->send(); |
342
|
|
|
unset($xoopsMailer); |
343
|
|
|
// B.R. $filename = XOOPS_UPLOAD_PATH . '/logmail_' . static::MODULE_NAME . '.php'; |
344
|
|
|
$filename = OLEDRION_UPLOAD_PATH . '/logmail_' . static::MODULE_NAME . '.php'; |
345
|
|
|
if (!file_exists($filename)) { |
346
|
|
|
$fp = @fopen($filename, 'a'); |
347
|
|
|
if ($fp) { |
348
|
|
|
fwrite($fp, "<?php exit(); ?>\n"); |
349
|
|
|
fclose($fp); |
350
|
|
|
} |
351
|
|
|
} |
352
|
|
|
$fp = @fopen($filename, 'a'); |
353
|
|
|
|
354
|
|
|
if ($fp) { |
355
|
|
|
fwrite($fp, str_repeat('-', 120) . "\n"); |
356
|
|
|
fwrite($fp, date('d/m/Y H:i:s') . "\n"); |
357
|
|
|
fwrite($fp, 'Template name : ' . $tplName . "\n"); |
358
|
|
|
fwrite($fp, 'Email subject : ' . $subject . "\n"); |
359
|
|
|
if (is_array($recipients)) { |
360
|
|
|
fwrite($fp, 'Recipient(s) : ' . implode(',', $recipients) . "\n"); |
361
|
|
|
} else { |
362
|
|
|
fwrite($fp, 'Recipient(s) : ' . $recipients . "\n"); |
363
|
|
|
} |
364
|
|
|
fwrite($fp, 'Transmited variables : ' . implode(',', $variables) . "\n"); |
365
|
|
|
fclose($fp); |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
return $res; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* Remove module's cache |
373
|
|
|
*/ |
374
|
|
View Code Duplication |
public static function updateCache() |
|
|
|
|
375
|
|
|
{ |
376
|
|
|
global $xoopsModule; |
|
|
|
|
377
|
|
|
$folder = $xoopsModule->getVar('dirname'); |
378
|
|
|
$tpllist = array(); |
|
|
|
|
379
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopsblock.php'; |
380
|
|
|
require_once XOOPS_ROOT_PATH . '/class/template.php'; |
381
|
|
|
$tplfileHandler = xoops_getHandler('tplfile'); |
382
|
|
|
$tpllist = $tplfileHandler->find(null, null, null, $folder); |
383
|
|
|
xoops_template_clear_module_cache($xoopsModule->getVar('mid')); // Clear module's blocks cache |
384
|
|
|
|
385
|
|
|
foreach ($tpllist as $onetemplate) { // Remove cache for each page. |
386
|
|
|
if ($onetemplate->getVar('tpl_type') === 'module') { |
387
|
|
|
// Note, I've been testing all the other methods (like the one of Smarty) and none of them run, that's why I have used this code |
388
|
|
|
$files_del = array(); |
|
|
|
|
389
|
|
|
$files_del = glob(XOOPS_CACHE_PATH . '/*' . $onetemplate->getVar('tpl_file') . '*'); |
390
|
|
|
if (count($files_del) > 0 && is_array($files_del)) { |
391
|
|
|
foreach ($files_del as $one_file) { |
392
|
|
|
if (is_file($one_file)) { |
393
|
|
|
unlink($one_file); |
394
|
|
|
} |
395
|
|
|
} |
396
|
|
|
} |
397
|
|
|
} |
398
|
|
|
} |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* Redirect user with a message |
403
|
|
|
* |
404
|
|
|
* @param string $message message to display |
405
|
|
|
* @param string $url The place where to go |
406
|
|
|
* @param integer timeout Time to wait before to redirect |
407
|
|
|
*/ |
408
|
|
|
public static function redirect($message = '', $url = 'index.php', $time = 2) |
409
|
|
|
{ |
410
|
|
|
redirect_header($url, $time, $message); |
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
/** |
414
|
|
|
* Internal function used to get the handler of the current module |
415
|
|
|
* |
416
|
|
|
* @return object The module |
417
|
|
|
*/ |
418
|
|
View Code Duplication |
protected static function _getModule() |
|
|
|
|
419
|
|
|
{ |
420
|
|
|
static $mymodule; |
421
|
|
|
if (!isset($mymodule)) { |
422
|
|
|
global $xoopsModule; |
|
|
|
|
423
|
|
|
if (isset($xoopsModule) && is_object($xoopsModule) && $xoopsModule->getVar('dirname') == OLEDRION_DIRNAME) { |
424
|
|
|
$mymodule = $xoopsModule; |
425
|
|
|
} else { |
426
|
|
|
$hModule = xoops_getHandler('module'); |
427
|
|
|
$mymodule = $hModule->getByDirname(OLEDRION_DIRNAME); |
428
|
|
|
} |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
return $mymodule; |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* Returns the module's name (as defined by the user in the module manager) with cache |
436
|
|
|
* @return string Module's name |
437
|
|
|
*/ |
438
|
|
View Code Duplication |
public static function getModuleName() |
|
|
|
|
439
|
|
|
{ |
440
|
|
|
static $moduleName; |
441
|
|
|
if (!isset($moduleName)) { |
442
|
|
|
$mymodule = static::_getModule(); |
443
|
|
|
$moduleName = $mymodule->getVar('name'); |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
return $moduleName; |
447
|
|
|
} |
448
|
|
|
|
449
|
|
|
/** |
450
|
|
|
* Create a title for the href tags inside html links |
451
|
|
|
* |
452
|
|
|
* @param string $title Text to use |
453
|
|
|
* @return string Formated text |
454
|
|
|
*/ |
455
|
|
|
public static function makeHrefTitle($title) |
456
|
|
|
{ |
457
|
|
|
$s = "\"'"; |
458
|
|
|
$r = ' '; |
459
|
|
|
|
460
|
|
|
return strtr($title, $s, $r); |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* Retourne la liste des utilisateurs appartenants à un groupe |
465
|
|
|
* |
466
|
|
|
* @param int $groupId Searched group |
467
|
|
|
* @return array Array of XoopsUsers |
468
|
|
|
*/ |
469
|
|
View Code Duplication |
public static function getUsersFromGroup($groupId) |
|
|
|
|
470
|
|
|
{ |
471
|
|
|
$users = array(); |
|
|
|
|
472
|
|
|
$memberHandler = xoops_getHandler('member'); |
473
|
|
|
$users = $memberHandler->getUsersByGroup($groupId, true); |
474
|
|
|
|
475
|
|
|
return $users; |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* Retourne la liste des emails des utilisateurs membres d'un groupe |
480
|
|
|
* |
481
|
|
|
* @param $groupId |
482
|
|
|
* @return array Emails list |
483
|
|
|
* @internal param int $group_id Group's number |
484
|
|
|
*/ |
485
|
|
View Code Duplication |
public static function getEmailsFromGroup($groupId) |
|
|
|
|
486
|
|
|
{ |
487
|
|
|
$ret = array(); |
488
|
|
|
$users = static::getUsersFromGroup($groupId); |
489
|
|
|
foreach ($users as $user) { |
490
|
|
|
$ret[] = $user->getVar('email'); |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
return $ret; |
494
|
|
|
} |
495
|
|
|
|
496
|
|
|
/** |
497
|
|
|
* Vérifie que l'utilisateur courant fait partie du groupe des administrateurs |
498
|
|
|
* |
499
|
|
|
* @return booleean Admin or not |
|
|
|
|
500
|
|
|
*/ |
501
|
|
View Code Duplication |
public static function isAdmin() |
|
|
|
|
502
|
|
|
{ |
503
|
|
|
global $xoopsUser, $xoopsModule; |
|
|
|
|
504
|
|
|
if (is_object($xoopsUser)) { |
505
|
|
|
if (in_array(XOOPS_GROUP_ADMIN, $xoopsUser->getGroups())) { |
506
|
|
|
return true; |
507
|
|
|
} elseif (isset($xoopsModule) && $xoopsUser->isAdmin($xoopsModule->getVar('mid'))) { |
508
|
|
|
return true; |
509
|
|
|
} |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
return false; |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
/** |
516
|
|
|
* Returns the current date in the Mysql format |
517
|
|
|
* |
518
|
|
|
* @return string Date in the Mysql format |
519
|
|
|
*/ |
520
|
|
|
public static function getCurrentSQLDate() |
521
|
|
|
{ |
522
|
|
|
return date('Y-m-d'); // 2007-05-02 |
|
|
|
|
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
/** |
526
|
|
|
* @return bool|string |
527
|
|
|
*/ |
528
|
|
|
public function getCurrentSQLDateTime() |
529
|
|
|
{ |
530
|
|
|
return date('Y-m-d H:i:s'); // 2007-05-02 |
|
|
|
|
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
/** |
534
|
|
|
* Convert a Mysql date to the human's format |
535
|
|
|
* |
536
|
|
|
* @param string $date The date to convert |
537
|
|
|
* @param string $format |
538
|
|
|
* @return string The date in a human form |
539
|
|
|
*/ |
540
|
|
View Code Duplication |
public function SQLDateToHuman($date, $format = 'l') |
|
|
|
|
541
|
|
|
{ |
542
|
|
|
if ($date != '0000-00-00' && xoops_trim($date) != '') { |
543
|
|
|
return formatTimestamp(strtotime($date), $format); |
544
|
|
|
} else { |
545
|
|
|
return ''; |
546
|
|
|
} |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
/** |
550
|
|
|
* Convert a timestamp to a Mysql date |
551
|
|
|
* |
552
|
|
|
* @param integer $timestamp The timestamp to use |
553
|
|
|
* @return string The date in the Mysql format |
554
|
|
|
*/ |
555
|
|
|
public function timestampToMysqlDate($timestamp) |
556
|
|
|
{ |
557
|
|
|
return date('Y-m-d', (int)$timestamp); |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
/** |
561
|
|
|
* Conversion d'un dateTime Mysql en date lisible en français |
562
|
|
|
* @param $dateTime |
563
|
|
|
* @return bool|string |
564
|
|
|
*/ |
565
|
|
|
public function sqlDateTimeToFrench($dateTime) |
566
|
|
|
{ |
567
|
|
|
return date('d/m/Y H:i:s', strtotime($dateTime)); |
568
|
|
|
} |
569
|
|
|
|
570
|
|
|
/** |
571
|
|
|
* Convert a timestamp to a Mysql datetime form |
572
|
|
|
* @param integer $timestamp The timestamp to use |
573
|
|
|
* @return string The date and time in the Mysql format |
574
|
|
|
*/ |
575
|
|
|
public function timestampToMysqlDateTime($timestamp) |
576
|
|
|
{ |
577
|
|
|
return date('Y-m-d H:i:s', $timestamp); |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
/** |
581
|
|
|
* This function indicates if the current Xoops version needs to add asterisks to required fields in forms |
582
|
|
|
* |
583
|
|
|
* @return boolean Yes = we need to add them, false = no |
584
|
|
|
*/ |
585
|
|
View Code Duplication |
public static function needsAsterisk() |
|
|
|
|
586
|
|
|
{ |
587
|
|
|
if (static::isX23()) { |
588
|
|
|
return false; |
589
|
|
|
} |
590
|
|
|
if (strpos(strtolower(XOOPS_VERSION), 'impresscms') !== false) { |
591
|
|
|
return false; |
592
|
|
|
} |
593
|
|
|
if (strpos(strtolower(XOOPS_VERSION), 'legacy') === false) { |
594
|
|
|
$xv = xoops_trim(str_replace('XOOPS ', '', XOOPS_VERSION)); |
595
|
|
|
if ((int)substr($xv, 4, 2) >= 17) { |
596
|
|
|
return false; |
597
|
|
|
} |
598
|
|
|
} |
599
|
|
|
|
600
|
|
|
return true; |
601
|
|
|
} |
602
|
|
|
|
603
|
|
|
/** |
604
|
|
|
* Mark the mandatory fields of a form with a star |
605
|
|
|
* |
606
|
|
|
* @param object $sform The form to modify |
607
|
|
|
* @return object The modified form |
608
|
|
|
* @internal param string $caracter The character to use to mark fields |
609
|
|
|
*/ |
610
|
|
View Code Duplication |
public static function formMarkRequiredFields($sform) |
|
|
|
|
611
|
|
|
{ |
612
|
|
|
if (static::needsAsterisk()) { |
613
|
|
|
$required = array(); |
614
|
|
|
foreach ($sform->getRequired() as $item) { |
615
|
|
|
$required[] = $item->_name; |
616
|
|
|
} |
617
|
|
|
$elements = array(); |
|
|
|
|
618
|
|
|
$elements = $sform->getElements(); |
619
|
|
|
$cnt = count($elements); |
620
|
|
|
for ($i = 0; $i < $cnt; ++$i) { |
621
|
|
|
if (is_object($elements[$i]) && in_array($elements[$i]->_name, $required)) { |
622
|
|
|
$elements[$i]->_caption .= ' *'; |
623
|
|
|
} |
624
|
|
|
} |
625
|
|
|
} |
626
|
|
|
|
627
|
|
|
return $sform; |
628
|
|
|
} |
629
|
|
|
|
630
|
|
|
/** |
631
|
|
|
* Create an html heading (from h1 to h6) |
632
|
|
|
* |
633
|
|
|
* @param string $title The text to use |
634
|
|
|
* @param integer $level Level to return |
635
|
|
|
* @return string The heading |
|
|
|
|
636
|
|
|
*/ |
637
|
|
|
public static function htitle($title = '', $level = 1) |
638
|
|
|
{ |
639
|
|
|
printf('<h%01d>%s</h%01d>', $level, $title, $level); |
640
|
|
|
} |
641
|
|
|
|
642
|
|
|
/** |
643
|
|
|
* Create a unique upload filename |
644
|
|
|
* |
645
|
|
|
* @param string $folder The folder where the file will be saved |
646
|
|
|
* @param string $fileName Original filename (coming from the user) |
647
|
|
|
* @param boolean $trimName Do we need to create a "short" unique name ? |
648
|
|
|
* @return string The unique filename to use (with its extension) |
649
|
|
|
*/ |
650
|
|
View Code Duplication |
public static function createUploadName($folder, $fileName, $trimName = false) |
|
|
|
|
651
|
|
|
{ |
652
|
|
|
$workingfolder = $folder; |
653
|
|
|
if (xoops_substr($workingfolder, strlen($workingfolder) - 1, 1) !== '/') { |
654
|
|
|
$workingfolder .= '/'; |
655
|
|
|
} |
656
|
|
|
$ext = basename($fileName); |
657
|
|
|
$ext = explode('.', $ext); |
658
|
|
|
$ext = '.' . $ext[count($ext) - 1]; |
659
|
|
|
$true = true; |
660
|
|
|
while ($true) { |
661
|
|
|
$ipbits = explode('.', $_SERVER['REMOTE_ADDR']); |
662
|
|
|
list($usec, $sec) = explode(' ', microtime()); |
663
|
|
|
$usec = (integer)($usec * 65536); |
664
|
|
|
$sec = ((integer)$sec) & 0xFFFF; |
665
|
|
|
|
666
|
|
|
if ($trimName) { |
667
|
|
|
$uid = sprintf('%06x%04x%04x', ($ipbits[0] << 24) | ($ipbits[1] << 16) | ($ipbits[2] << 8) | $ipbits[3], $sec, $usec); |
668
|
|
|
} else { |
669
|
|
|
$uid = sprintf('%08x-%04x-%04x', ($ipbits[0] << 24) | ($ipbits[1] << 16) | ($ipbits[2] << 8) | $ipbits[3], $sec, $usec); |
670
|
|
|
} |
671
|
|
|
if (!file_exists($workingfolder . $uid . $ext)) { |
672
|
|
|
$true = false; |
673
|
|
|
} |
674
|
|
|
} |
675
|
|
|
|
676
|
|
|
return $uid . $ext; |
|
|
|
|
677
|
|
|
} |
678
|
|
|
|
679
|
|
|
/** |
680
|
|
|
* Replace html entities with their ASCII equivalent |
681
|
|
|
* |
682
|
|
|
* @param string $chaine The string undecode |
683
|
|
|
* @return string The undecoded string |
684
|
|
|
*/ |
685
|
|
View Code Duplication |
public static function unhtml($chaine) |
|
|
|
|
686
|
|
|
{ |
687
|
|
|
$search = $replace = array(); |
688
|
|
|
$chaine = html_entity_decode($chaine); |
689
|
|
|
|
690
|
|
|
for ($i = 0; $i <= 255; ++$i) { |
691
|
|
|
$search[] = '&#' . $i . ';'; |
692
|
|
|
$replace[] = chr($i); |
693
|
|
|
} |
694
|
|
|
$replace[] = '...'; |
695
|
|
|
$search[] = '
'; |
696
|
|
|
$replace[] = "'"; |
697
|
|
|
$search[] = ''; |
698
|
|
|
$replace[] = "'"; |
699
|
|
|
$search[] = ''; |
700
|
|
|
$replace[] = '-'; |
701
|
|
|
$search[] = '•'; // $replace[] = ''; |
|
|
|
|
702
|
|
|
$replace[] = ''; |
703
|
|
|
$search[] = '—'; |
704
|
|
|
$replace[] = '-'; |
705
|
|
|
$search[] = '–'; |
706
|
|
|
$replace[] = '-'; |
707
|
|
|
$search[] = '­'; |
708
|
|
|
$replace[] = '"'; |
709
|
|
|
$search[] = '"'; |
710
|
|
|
$replace[] = '&'; |
711
|
|
|
$search[] = '&'; |
712
|
|
|
$replace[] = ''; |
713
|
|
|
$search[] = 'ˆ'; |
714
|
|
|
$replace[] = '¡'; |
715
|
|
|
$search[] = '¡'; |
716
|
|
|
$replace[] = '¦'; |
717
|
|
|
$search[] = '¦'; |
718
|
|
|
$replace[] = '¨'; |
719
|
|
|
$search[] = '¨'; |
720
|
|
|
$replace[] = '¯'; |
721
|
|
|
$search[] = '¯'; |
722
|
|
|
$replace[] = '´'; |
723
|
|
|
$search[] = '´'; |
724
|
|
|
$replace[] = '¸'; |
725
|
|
|
$search[] = '¸'; |
726
|
|
|
$replace[] = '¿'; |
727
|
|
|
$search[] = '¿'; |
728
|
|
|
$replace[] = ''; |
729
|
|
|
$search[] = '˜'; |
730
|
|
|
$replace[] = "'"; |
731
|
|
|
$search[] = '‘'; // $replace[]=''; |
|
|
|
|
732
|
|
|
$replace[] = "'"; |
733
|
|
|
$search[] = '’'; // $replace[]=''; |
|
|
|
|
734
|
|
|
$replace[] = ''; |
735
|
|
|
$search[] = '‚'; |
736
|
|
|
$replace[] = "'"; |
737
|
|
|
$search[] = '“'; // $replace[]=''; |
|
|
|
|
738
|
|
|
$replace[] = "'"; |
739
|
|
|
$search[] = '”'; // $replace[]=''; |
|
|
|
|
740
|
|
|
$replace[] = ''; |
741
|
|
|
$search[] = '„'; |
742
|
|
|
$replace[] = ''; |
743
|
|
|
$search[] = '‹'; |
744
|
|
|
$replace[] = ''; |
745
|
|
|
$search[] = '›'; |
746
|
|
|
$replace[] = '<'; |
747
|
|
|
$search[] = '<'; |
748
|
|
|
$replace[] = '>'; |
749
|
|
|
$search[] = '>'; |
750
|
|
|
$replace[] = '±'; |
751
|
|
|
$search[] = '±'; |
752
|
|
|
$replace[] = '«'; |
753
|
|
|
$search[] = '«'; |
754
|
|
|
$replace[] = '»'; |
755
|
|
|
$search[] = '»'; |
756
|
|
|
$replace[] = '×'; |
757
|
|
|
$search[] = '×'; |
758
|
|
|
$replace[] = '÷'; |
759
|
|
|
$search[] = '÷'; |
760
|
|
|
$replace[] = '¢'; |
761
|
|
|
$search[] = '¢'; |
762
|
|
|
$replace[] = '£'; |
763
|
|
|
$search[] = '£'; |
764
|
|
|
$replace[] = '¤'; |
765
|
|
|
$search[] = '¤'; |
766
|
|
|
$replace[] = '¥'; |
767
|
|
|
$search[] = '¥'; |
768
|
|
|
$replace[] = '§'; |
769
|
|
|
$search[] = '§'; |
770
|
|
|
$replace[] = '©'; |
771
|
|
|
$search[] = '©'; |
772
|
|
|
$replace[] = '¬'; |
773
|
|
|
$search[] = '¬'; |
774
|
|
|
$replace[] = '®'; |
775
|
|
|
$search[] = '®'; |
776
|
|
|
$replace[] = '°'; |
777
|
|
|
$search[] = '°'; |
778
|
|
|
$replace[] = 'µ'; |
779
|
|
|
$search[] = 'µ'; |
780
|
|
|
$replace[] = '¶'; |
781
|
|
|
$search[] = '¶'; |
782
|
|
|
$replace[] = '·'; |
783
|
|
|
$search[] = '·'; |
784
|
|
|
$replace[] = ''; |
785
|
|
|
$search[] = '†'; |
786
|
|
|
$replace[] = ''; |
787
|
|
|
$search[] = '‡'; |
788
|
|
|
$replace[] = ''; |
789
|
|
|
$search[] = '‰'; |
790
|
|
|
$replace[] = 'Euro'; |
791
|
|
|
$search[] = '€'; // $replace[]='' |
|
|
|
|
792
|
|
|
$replace[] = '¼'; |
793
|
|
|
$search[] = '¼'; |
794
|
|
|
$replace[] = '½'; |
795
|
|
|
$search[] = '½'; |
796
|
|
|
$replace[] = '¾'; |
797
|
|
|
$search[] = '¾'; |
798
|
|
|
$replace[] = '¹'; |
799
|
|
|
$search[] = '¹'; |
800
|
|
|
$replace[] = '²'; |
801
|
|
|
$search[] = '²'; |
802
|
|
|
$replace[] = '³'; |
803
|
|
|
$search[] = '³'; |
804
|
|
|
$replace[] = 'á'; |
805
|
|
|
$search[] = 'á'; |
806
|
|
|
$replace[] = 'Á'; |
807
|
|
|
$search[] = 'Á'; |
808
|
|
|
$replace[] = 'â'; |
809
|
|
|
$search[] = 'â'; |
810
|
|
|
$replace[] = 'Â'; |
811
|
|
|
$search[] = 'Â'; |
812
|
|
|
$replace[] = 'à'; |
813
|
|
|
$search[] = 'à'; |
814
|
|
|
$replace[] = 'À'; |
815
|
|
|
$search[] = 'À'; |
816
|
|
|
$replace[] = 'å'; |
817
|
|
|
$search[] = 'å'; |
818
|
|
|
$replace[] = 'Å'; |
819
|
|
|
$search[] = 'Å'; |
820
|
|
|
$replace[] = 'ã'; |
821
|
|
|
$search[] = 'ã'; |
822
|
|
|
$replace[] = 'Ã'; |
823
|
|
|
$search[] = 'Ã'; |
824
|
|
|
$replace[] = 'ä'; |
825
|
|
|
$search[] = 'ä'; |
826
|
|
|
$replace[] = 'Ä'; |
827
|
|
|
$search[] = 'Ä'; |
828
|
|
|
$replace[] = 'ª'; |
829
|
|
|
$search[] = 'ª'; |
830
|
|
|
$replace[] = 'æ'; |
831
|
|
|
$search[] = 'æ'; |
832
|
|
|
$replace[] = 'Æ'; |
833
|
|
|
$search[] = 'Æ'; |
834
|
|
|
$replace[] = 'ç'; |
835
|
|
|
$search[] = 'ç'; |
836
|
|
|
$replace[] = 'Ç'; |
837
|
|
|
$search[] = 'Ç'; |
838
|
|
|
$replace[] = 'ð'; |
839
|
|
|
$search[] = 'ð'; |
840
|
|
|
$replace[] = 'Ð'; |
841
|
|
|
$search[] = 'Ð'; |
842
|
|
|
$replace[] = 'é'; |
843
|
|
|
$search[] = 'é'; |
844
|
|
|
$replace[] = 'É'; |
845
|
|
|
$search[] = 'É'; |
846
|
|
|
$replace[] = 'ê'; |
847
|
|
|
$search[] = 'ê'; |
848
|
|
|
$replace[] = 'Ê'; |
849
|
|
|
$search[] = 'Ê'; |
850
|
|
|
$replace[] = 'è'; |
851
|
|
|
$search[] = 'è'; |
852
|
|
|
$replace[] = 'È'; |
853
|
|
|
$search[] = 'È'; |
854
|
|
|
$replace[] = 'ë'; |
855
|
|
|
$search[] = 'ë'; |
856
|
|
|
$replace[] = 'Ë'; |
857
|
|
|
$search[] = 'Ë'; |
858
|
|
|
$replace[] = ''; |
859
|
|
|
$search[] = 'ƒ'; |
860
|
|
|
$replace[] = 'í'; |
861
|
|
|
$search[] = 'í'; |
862
|
|
|
$replace[] = 'Í'; |
863
|
|
|
$search[] = 'Í'; |
864
|
|
|
$replace[] = 'î'; |
865
|
|
|
$search[] = 'î'; |
866
|
|
|
$replace[] = 'Î'; |
867
|
|
|
$search[] = 'Î'; |
868
|
|
|
$replace[] = 'ì'; |
869
|
|
|
$search[] = 'ì'; |
870
|
|
|
$replace[] = 'Ì'; |
871
|
|
|
$search[] = 'Ì'; |
872
|
|
|
$replace[] = 'ï'; |
873
|
|
|
$search[] = 'ï'; |
874
|
|
|
$replace[] = 'Ï'; |
875
|
|
|
$search[] = 'Ï'; |
876
|
|
|
$replace[] = 'ñ'; |
877
|
|
|
$search[] = 'ñ'; |
878
|
|
|
$replace[] = 'Ñ'; |
879
|
|
|
$search[] = 'Ñ'; |
880
|
|
|
$replace[] = 'ó'; |
881
|
|
|
$search[] = 'ó'; |
882
|
|
|
$replace[] = 'Ó'; |
883
|
|
|
$search[] = 'Ó'; |
884
|
|
|
$replace[] = 'ô'; |
885
|
|
|
$search[] = 'ô'; |
886
|
|
|
$replace[] = 'Ô'; |
887
|
|
|
$search[] = 'Ô'; |
888
|
|
|
$replace[] = 'ò'; |
889
|
|
|
$search[] = 'ò'; |
890
|
|
|
$replace[] = 'Ò'; |
891
|
|
|
$search[] = 'Ò'; |
892
|
|
|
$replace[] = 'º'; |
893
|
|
|
$search[] = 'º'; |
894
|
|
|
$replace[] = 'ø'; |
895
|
|
|
$search[] = 'ø'; |
896
|
|
|
$replace[] = 'Ø'; |
897
|
|
|
$search[] = 'Ø'; |
898
|
|
|
$replace[] = 'õ'; |
899
|
|
|
$search[] = 'õ'; |
900
|
|
|
$replace[] = 'Õ'; |
901
|
|
|
$search[] = 'Õ'; |
902
|
|
|
$replace[] = 'ö'; |
903
|
|
|
$search[] = 'ö'; |
904
|
|
|
$replace[] = 'Ö'; |
905
|
|
|
$search[] = 'Ö'; |
906
|
|
|
$replace[] = ''; |
907
|
|
|
$search[] = 'œ'; |
908
|
|
|
$replace[] = ''; |
909
|
|
|
$search[] = 'Œ'; |
910
|
|
|
$replace[] = ''; |
911
|
|
|
$search[] = 'š'; |
912
|
|
|
$replace[] = ''; |
913
|
|
|
$search[] = 'Š'; |
914
|
|
|
$replace[] = 'ß'; |
915
|
|
|
$search[] = 'ß'; |
916
|
|
|
$replace[] = 'þ'; |
917
|
|
|
$search[] = 'þ'; |
918
|
|
|
$replace[] = 'Þ'; |
919
|
|
|
$search[] = 'Þ'; |
920
|
|
|
$replace[] = 'ú'; |
921
|
|
|
$search[] = 'ú'; |
922
|
|
|
$replace[] = 'Ú'; |
923
|
|
|
$search[] = 'Ú'; |
924
|
|
|
$replace[] = 'û'; |
925
|
|
|
$search[] = 'û'; |
926
|
|
|
$replace[] = 'Û'; |
927
|
|
|
$search[] = 'Û'; |
928
|
|
|
$replace[] = 'ù'; |
929
|
|
|
$search[] = 'ù'; |
930
|
|
|
$replace[] = 'Ù'; |
931
|
|
|
$search[] = 'Ù'; |
932
|
|
|
$replace[] = 'ü'; |
933
|
|
|
$search[] = 'ü'; |
934
|
|
|
$replace[] = 'Ü'; |
935
|
|
|
$search[] = 'Ü'; |
936
|
|
|
$replace[] = 'ý'; |
937
|
|
|
$search[] = 'ý'; |
938
|
|
|
$replace[] = 'Ý'; |
939
|
|
|
$search[] = 'Ý'; |
940
|
|
|
$replace[] = 'ÿ'; |
941
|
|
|
$search[] = 'ÿ'; |
942
|
|
|
$replace[] = ''; |
943
|
|
|
$search[] = 'Ÿ'; |
944
|
|
|
$chaine = str_replace($search, $replace, $chaine); |
945
|
|
|
|
946
|
|
|
return $chaine; |
947
|
|
|
} |
948
|
|
|
|
949
|
|
|
/** |
950
|
|
|
* Création d'une titre pour être utilisé par l'url rewriting |
951
|
|
|
* |
952
|
|
|
* @param string $content Le texte à utiliser pour créer l'url |
953
|
|
|
* @param integer $urw La limite basse pour créer les mots |
954
|
|
|
* @return string Le texte à utiliser pour l'url |
955
|
|
|
* Note, some parts are from Solo's code |
956
|
|
|
*/ |
957
|
|
View Code Duplication |
public static function makeSeoUrl($content, $urw = 1) |
|
|
|
|
958
|
|
|
{ |
959
|
|
|
$s = "ÀÁÂÃÄÅÒÓÔÕÖØÈÉÊËÇÌÍÎÏÙÚÛÜÑàáâãäåòóôõöøèéêëçìíîïùúûüÿñ '()"; |
960
|
|
|
$r = 'AAAAAAOOOOOOEEEECIIIIUUUUYNaaaaaaooooooeeeeciiiiuuuuyn----'; |
961
|
|
|
$content = static::unhtml($content); // First, remove html entities |
962
|
|
|
$content = strtr($content, $s, $r); |
963
|
|
|
$content = strip_tags($content); |
964
|
|
|
$content = strtolower($content); |
965
|
|
|
$content = htmlentities($content); // TODO: Vérifier |
966
|
|
|
$content = preg_replace('/&([a-zA-Z])(uml|acute|grave|circ|tilde);/', '$1', $content); |
967
|
|
|
$content = html_entity_decode($content); |
968
|
|
|
$content = preg_replace('/quot/i', ' ', $content); |
969
|
|
|
$content = preg_replace("/'/i", ' ', $content); |
970
|
|
|
$content = preg_replace('/-/i', ' ', $content); |
971
|
|
|
$content = preg_replace('/[[:punct:]]/i', '', $content); |
972
|
|
|
|
973
|
|
|
// Selon option mais attention au fichier .htaccess ! |
974
|
|
|
// $content = eregi_replace('[[:digit:]]','', $content); |
|
|
|
|
975
|
|
|
$content = preg_replace('/[^a-z|A-Z|0-9]/', '-', $content); |
976
|
|
|
|
977
|
|
|
$words = explode(' ', $content); |
978
|
|
|
$keywords = ''; |
979
|
|
|
foreach ($words as $word) { |
980
|
|
|
if (strlen($word) >= $urw) { |
981
|
|
|
$keywords .= '-' . trim($word); |
982
|
|
|
} |
983
|
|
|
} |
984
|
|
|
if (!$keywords) { |
985
|
|
|
$keywords = '-'; |
986
|
|
|
} |
987
|
|
|
// Supprime les tirets en double |
988
|
|
|
$keywords = str_replace('---', '-', $keywords); |
989
|
|
|
$keywords = str_replace('--', '-', $keywords); |
990
|
|
|
// Supprime un éventuel tiret à la fin de la chaine |
991
|
|
|
if (substr($keywords, strlen($keywords) - 1, 1) == '-') { |
992
|
|
|
$keywords = substr($keywords, 0, strlen($keywords) - 1); |
993
|
|
|
} |
994
|
|
|
|
995
|
|
|
return $keywords; |
996
|
|
|
} |
997
|
|
|
|
998
|
|
|
/** |
999
|
|
|
* Create the meta keywords based on the content |
1000
|
|
|
* |
1001
|
|
|
* @param string $content Content from which we have to create metakeywords |
1002
|
|
|
* @return string The list of meta keywords |
1003
|
|
|
*/ |
1004
|
|
View Code Duplication |
public static function createMetaKeywords($content) |
|
|
|
|
1005
|
|
|
{ |
1006
|
|
|
$keywordscount = static::getModuleOption('metagen_maxwords'); |
1007
|
|
|
$keywordsorder = static::getModuleOption('metagen_order'); |
1008
|
|
|
|
1009
|
|
|
$tmp = array(); |
1010
|
|
|
// Search for the "Minimum keyword length" |
1011
|
|
|
if (isset($_SESSION['oledrion_keywords_limit'])) { |
1012
|
|
|
$limit = $_SESSION['oledrion_keywords_limit']; |
1013
|
|
|
} else { |
1014
|
|
|
$configHandler = xoops_getHandler('config'); |
1015
|
|
|
$xoopsConfigSearch = $configHandler->getConfigsByCat(XOOPS_CONF_SEARCH); |
1016
|
|
|
$limit = $xoopsConfigSearch['keyword_min']; |
1017
|
|
|
$_SESSION['oledrion_keywords_limit'] = $limit; |
1018
|
|
|
} |
1019
|
|
|
$myts = MyTextSanitizer::getInstance(); |
1020
|
|
|
$content = str_replace('<br>', ' ', $content); |
1021
|
|
|
$content = $myts->undoHtmlSpecialChars($content); |
1022
|
|
|
$content = strip_tags($content); |
1023
|
|
|
$content = strtolower($content); |
1024
|
|
|
$search_pattern = array( |
1025
|
|
|
' ', |
1026
|
|
|
"\t", |
1027
|
|
|
"\r\n", |
1028
|
|
|
"\r", |
1029
|
|
|
"\n", |
1030
|
|
|
',', |
1031
|
|
|
'.', |
1032
|
|
|
"'", |
1033
|
|
|
';', |
1034
|
|
|
':', |
1035
|
|
|
')', |
1036
|
|
|
'(', |
1037
|
|
|
'"', |
1038
|
|
|
'?', |
1039
|
|
|
'!', |
1040
|
|
|
'{', |
1041
|
|
|
'}', |
1042
|
|
|
'[', |
1043
|
|
|
']', |
1044
|
|
|
'<', |
1045
|
|
|
'>', |
1046
|
|
|
'/', |
1047
|
|
|
'+', |
1048
|
|
|
'-', |
1049
|
|
|
'_', |
1050
|
|
|
'\\', |
1051
|
|
|
'*' |
1052
|
|
|
); |
1053
|
|
|
$replace_pattern = array( |
1054
|
|
|
' ', |
1055
|
|
|
' ', |
1056
|
|
|
' ', |
1057
|
|
|
' ', |
1058
|
|
|
' ', |
1059
|
|
|
' ', |
1060
|
|
|
' ', |
1061
|
|
|
' ', |
1062
|
|
|
'', |
1063
|
|
|
'', |
1064
|
|
|
'', |
1065
|
|
|
'', |
1066
|
|
|
'', |
1067
|
|
|
'', |
1068
|
|
|
'', |
1069
|
|
|
'', |
1070
|
|
|
'', |
1071
|
|
|
'', |
1072
|
|
|
'', |
1073
|
|
|
'', |
1074
|
|
|
'', |
1075
|
|
|
'', |
1076
|
|
|
'', |
1077
|
|
|
'', |
1078
|
|
|
'', |
1079
|
|
|
'', |
1080
|
|
|
'' |
1081
|
|
|
); |
1082
|
|
|
$content = str_replace($search_pattern, $replace_pattern, $content); |
1083
|
|
|
$keywords = explode(' ', $content); |
1084
|
|
|
switch ($keywordsorder) { |
1085
|
|
|
case 0: // Ordre d'apparition dans le texte |
1086
|
|
|
$keywords = array_unique($keywords); |
1087
|
|
|
break; |
1088
|
|
|
case 1: // Ordre de fréquence des mots |
1089
|
|
|
$keywords = array_count_values($keywords); |
1090
|
|
|
asort($keywords); |
1091
|
|
|
$keywords = array_keys($keywords); |
1092
|
|
|
break; |
1093
|
|
|
case 2: // Ordre inverse de la fréquence des mots |
1094
|
|
|
$keywords = array_count_values($keywords); |
1095
|
|
|
arsort($keywords); |
1096
|
|
|
$keywords = array_keys($keywords); |
1097
|
|
|
break; |
1098
|
|
|
} |
1099
|
|
|
// Remove black listed words |
1100
|
|
|
if (xoops_trim(static::getModuleOption('metagen_blacklist')) != '') { |
1101
|
|
|
$metagen_blacklist = str_replace("\r", '', static::getModuleOption('metagen_blacklist')); |
1102
|
|
|
$metablack = explode("\n", $metagen_blacklist); |
1103
|
|
|
array_walk($metablack, 'trim'); |
1104
|
|
|
$keywords = array_diff($keywords, $metablack); |
1105
|
|
|
} |
1106
|
|
|
|
1107
|
|
|
foreach ($keywords as $keyword) { |
1108
|
|
|
if (strlen($keyword) >= $limit && !is_numeric($keyword)) { |
1109
|
|
|
$tmp[] = $keyword; |
1110
|
|
|
} |
1111
|
|
|
} |
1112
|
|
|
$tmp = array_slice($tmp, 0, $keywordscount); |
1113
|
|
|
if (count($tmp) > 0) { |
1114
|
|
|
return implode(',', $tmp); |
1115
|
|
|
} else { |
1116
|
|
|
if (!isset($configHandler) || !is_object($configHandler)) { |
1117
|
|
|
$configHandler = xoops_getHandler('config'); |
1118
|
|
|
} |
1119
|
|
|
$xoopsConfigMetaFooter = $configHandler->getConfigsByCat(XOOPS_CONF_METAFOOTER); |
1120
|
|
|
if (isset($xoopsConfigMetaFooter['meta_keywords'])) { |
1121
|
|
|
return $xoopsConfigMetaFooter['meta_keywords']; |
1122
|
|
|
} else { |
1123
|
|
|
return ''; |
1124
|
|
|
} |
1125
|
|
|
} |
1126
|
|
|
} |
1127
|
|
|
|
1128
|
|
|
/** |
1129
|
|
|
* Fonction chargée de gérer l'upload |
1130
|
|
|
* |
1131
|
|
|
* @param integer $indice L'indice du fichier à télécharger |
1132
|
|
|
* @param string $dstpath |
1133
|
|
|
* @param null $mimeTypes |
1134
|
|
|
* @param null $uploadMaxSize |
1135
|
|
|
* @param null $maxWidth |
1136
|
|
|
* @param null $maxHeight |
1137
|
|
|
* @return mixed True si l'upload s'est bien déroulé sinon le message d'erreur correspondant |
1138
|
|
|
*/ |
1139
|
|
View Code Duplication |
public static function uploadFile( |
|
|
|
|
1140
|
|
|
$indice, |
1141
|
|
|
$dstpath = XOOPS_UPLOAD_PATH, |
1142
|
|
|
$mimeTypes = null, |
1143
|
|
|
$uploadMaxSize = null, |
1144
|
|
|
$maxWidth = null, |
1145
|
|
|
$maxHeight = null) |
1146
|
|
|
{ |
1147
|
|
|
require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
1148
|
|
|
global $destname; |
|
|
|
|
1149
|
|
|
if (isset($_POST['xoops_upload_file'])) { |
1150
|
|
|
require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
1151
|
|
|
$fldname = ''; |
|
|
|
|
1152
|
|
|
$fldname = $_FILES[$_POST['xoops_upload_file'][$indice]]; |
1153
|
|
|
$fldname = get_magic_quotes_gpc() ? stripslashes($fldname['name']) : $fldname['name']; |
1154
|
|
|
if (xoops_trim($fldname != '')) { |
1155
|
|
|
$destname = static::createUploadName($dstpath, $fldname, true); |
1156
|
|
|
if ($mimeTypes === null) { |
1157
|
|
|
$permittedtypes = explode("\n", str_replace("\r", '', static::getModuleOption('mimetypes'))); |
1158
|
|
|
array_walk($permittedtypes, 'trim'); |
1159
|
|
|
} else { |
1160
|
|
|
$permittedtypes = $mimeTypes; |
1161
|
|
|
} |
1162
|
|
|
if ($uploadMaxSize === null) { |
1163
|
|
|
$uploadSize = static::getModuleOption('maxuploadsize'); |
1164
|
|
|
} else { |
1165
|
|
|
$uploadSize = $uploadMaxSize; |
1166
|
|
|
} |
1167
|
|
|
$uploader = new XoopsMediaUploader($dstpath, $permittedtypes, $uploadSize, $maxWidth, $maxHeight); |
1168
|
|
|
//$uploader->allowUnknownTypes = true; |
|
|
|
|
1169
|
|
|
$uploader->setTargetFileName($destname); |
1170
|
|
|
if ($uploader->fetchMedia($_POST['xoops_upload_file'][$indice])) { |
1171
|
|
|
if ($uploader->upload()) { |
1172
|
|
|
return true; |
1173
|
|
|
} else { |
1174
|
|
|
return _ERRORS . ' ' . htmlentities($uploader->getErrors()); |
1175
|
|
|
} |
1176
|
|
|
} else { |
1177
|
|
|
return htmlentities($uploader->getErrors()); |
1178
|
|
|
} |
1179
|
|
|
} else { |
1180
|
|
|
return false; |
1181
|
|
|
} |
1182
|
|
|
} else { |
1183
|
|
|
return false; |
1184
|
|
|
} |
1185
|
|
|
} |
1186
|
|
|
|
1187
|
|
|
/** |
1188
|
|
|
* Resize a Picture to some given dimensions (using the wideImage library) |
1189
|
|
|
* |
1190
|
|
|
* @param string $src_path Picture's source |
1191
|
|
|
* @param string $dst_path Picture's destination |
1192
|
|
|
* @param integer $param_width Maximum picture's width |
1193
|
|
|
* @param integer $param_height Maximum picture's height |
1194
|
|
|
* @param boolean $keep_original Do we have to keep the original picture ? |
1195
|
|
|
* @param string $fit Resize mode (see the wideImage library for more information) |
1196
|
|
|
* @return bool |
1197
|
|
|
*/ |
1198
|
|
View Code Duplication |
public function resizePicture( |
|
|
|
|
1199
|
|
|
$src_path, |
1200
|
|
|
$dst_path, |
1201
|
|
|
$param_width, |
1202
|
|
|
$param_height, |
1203
|
|
|
$keep_original = false, |
1204
|
|
|
$fit = 'inside') |
1205
|
|
|
{ |
1206
|
|
|
// require_once OLEDRION_PATH . 'class/wideimage/WideImage.inc.php'; |
1207
|
|
|
$resize = true; |
1208
|
|
|
if (OLEDRION_DONT_RESIZE_IF_SMALLER) { |
1209
|
|
|
$pictureDimensions = getimagesize($src_path); |
1210
|
|
|
if (is_array($pictureDimensions)) { |
1211
|
|
|
$width = $pictureDimensions[0]; |
1212
|
|
|
$height = $pictureDimensions[1]; |
1213
|
|
|
if ($width < $param_width && $height < $param_height) { |
1214
|
|
|
$resize = false; |
1215
|
|
|
} |
1216
|
|
|
} |
1217
|
|
|
} |
1218
|
|
|
|
1219
|
|
|
$img = WideImage::load($src_path); |
1220
|
|
|
if ($resize) { |
1221
|
|
|
$result = $img->resize($param_width, $param_height, $fit); |
1222
|
|
|
$result->saveToFile($dst_path); |
1223
|
|
|
} else { |
1224
|
|
|
@copy($src_path, $dst_path); |
|
|
|
|
1225
|
|
|
} |
1226
|
|
|
|
1227
|
|
|
if (!$keep_original) { |
1228
|
|
|
@unlink($src_path); |
|
|
|
|
1229
|
|
|
} |
1230
|
|
|
|
1231
|
|
|
return true; |
1232
|
|
|
} |
1233
|
|
|
|
1234
|
|
|
/** |
1235
|
|
|
* Déclenchement d'une alerte Xoops suite à un évènement |
1236
|
|
|
* |
1237
|
|
|
* @param string $category La catégorie de l'évènement |
1238
|
|
|
* @param integer $itemId L'ID de l'élément (trop général pour être décris précisément) |
1239
|
|
|
* @param unknown_type $event L'évènement qui est déclencé |
1240
|
|
|
* @param unknown_type $tags Les variables à passer au template |
1241
|
|
|
*/ |
1242
|
|
|
public function notify($category, $itemId, $event, $tags) |
1243
|
|
|
{ |
1244
|
|
|
$notificationHandler = xoops_getHandler('notification'); |
1245
|
|
|
$tags['X_MODULE_URL'] = OLEDRION_URL; |
1246
|
|
|
$notificationHandler->triggerEvent($category, $itemId, $event, $tags); |
1247
|
|
|
} |
1248
|
|
|
|
1249
|
|
|
/** |
1250
|
|
|
* Ajoute des jours à une date et retourne la nouvelle date au format Date de Mysql |
1251
|
|
|
* |
1252
|
|
|
* @param int $duration |
1253
|
|
|
* @param integer $startingDate Date de départ (timestamp) |
1254
|
|
|
* @return bool|string |
1255
|
|
|
* @internal param int $durations Durée en jours |
1256
|
|
|
*/ |
1257
|
|
View Code Duplication |
public function addDaysToDate($duration = 1, $startingDate = 0) |
|
|
|
|
1258
|
|
|
{ |
1259
|
|
|
if ($startingDate == 0) { |
1260
|
|
|
$startingDate = time(); |
1261
|
|
|
} |
1262
|
|
|
$endingDate = $startingDate + ($duration * 86400); |
1263
|
|
|
|
1264
|
|
|
return date('Y-m-d', $endingDate); |
1265
|
|
|
} |
1266
|
|
|
|
1267
|
|
|
/** |
1268
|
|
|
* Retourne un breadcrumb en fonction des paramètres passés et en partant (d'office) de la racine du module |
1269
|
|
|
* |
1270
|
|
|
* @param array $path Le chemin complet (excepté la racine) du breadcrumb sous la forme clé=url valeur=titre |
1271
|
|
|
* @param string $raquo Le séparateur par défaut à utiliser |
1272
|
|
|
* @return string le breadcrumb |
1273
|
|
|
*/ |
1274
|
|
View Code Duplication |
public static function breadcrumb($path, $raquo = ' » ') |
|
|
|
|
1275
|
|
|
{ |
1276
|
|
|
$breadcrumb = ''; |
1277
|
|
|
$workingBreadcrumb = array(); |
1278
|
|
|
if (is_array($path)) { |
1279
|
|
|
$moduleName = static::getModuleName(); |
1280
|
|
|
$workingBreadcrumb[] = "<a href='" . OLEDRION_URL . "' title='" . static::makeHrefTitle($moduleName) . "'>" . $moduleName . '</a>'; |
1281
|
|
|
foreach ($path as $url => $title) { |
1282
|
|
|
$workingBreadcrumb[] = "<a href='" . $url . "'>" . $title . '</a>'; |
1283
|
|
|
} |
1284
|
|
|
$cnt = count($workingBreadcrumb); |
1285
|
|
|
for ($i = 0; $i < $cnt; ++$i) { |
1286
|
|
|
if ($i == $cnt - 1) { |
1287
|
|
|
$workingBreadcrumb[$i] = strip_tags($workingBreadcrumb[$i]); |
1288
|
|
|
} |
1289
|
|
|
} |
1290
|
|
|
$breadcrumb = implode($raquo, $workingBreadcrumb); |
1291
|
|
|
} |
1292
|
|
|
|
1293
|
|
|
return $breadcrumb; |
1294
|
|
|
} |
1295
|
|
|
|
1296
|
|
|
/** |
1297
|
|
|
* @param $string |
1298
|
|
|
* @return string |
1299
|
|
|
*/ |
1300
|
|
View Code Duplication |
public static function close_tags($string) |
|
|
|
|
1301
|
|
|
{ |
1302
|
|
|
// match opened tags |
1303
|
|
|
if (preg_match_all('/<([a-z\:\-]+)[^\/]>/', $string, $start_tags)) { |
1304
|
|
|
$start_tags = $start_tags[1]; |
1305
|
|
|
|
1306
|
|
|
// match closed tags |
1307
|
|
|
if (preg_match_all('/<\/([a-z]+)>/', $string, $end_tags)) { |
1308
|
|
|
$complete_tags = array(); |
1309
|
|
|
$end_tags = $end_tags[1]; |
1310
|
|
|
|
1311
|
|
|
foreach ($start_tags as $key => $val) { |
1312
|
|
|
$posb = array_search($val, $end_tags); |
1313
|
|
|
if (is_int($posb)) { |
1314
|
|
|
unset($end_tags[$posb]); |
1315
|
|
|
} else { |
1316
|
|
|
$complete_tags[] = $val; |
1317
|
|
|
} |
1318
|
|
|
} |
1319
|
|
|
} else { |
1320
|
|
|
$complete_tags = $start_tags; |
1321
|
|
|
} |
1322
|
|
|
|
1323
|
|
|
$complete_tags = array_reverse($complete_tags); |
1324
|
|
|
for ($i = 0, $iMax = count($complete_tags); $i < $iMax; ++$i) { |
1325
|
|
|
$string .= '</' . $complete_tags[$i] . '>'; |
1326
|
|
|
} |
1327
|
|
|
} |
1328
|
|
|
|
1329
|
|
|
return $string; |
1330
|
|
|
} |
1331
|
|
|
|
1332
|
|
|
/** |
1333
|
|
|
* @param $string |
1334
|
|
|
* @param int $length |
1335
|
|
|
* @param string $etc |
1336
|
|
|
* @param bool $break_words |
1337
|
|
|
* @return mixed|string |
1338
|
|
|
*/ |
1339
|
|
View Code Duplication |
public static function truncate_tagsafe($string, $length = 80, $etc = '...', $break_words = false) |
|
|
|
|
1340
|
|
|
{ |
1341
|
|
|
if ($length == 0) { |
1342
|
|
|
return ''; |
1343
|
|
|
} |
1344
|
|
|
|
1345
|
|
|
if (strlen($string) > $length) { |
1346
|
|
|
$length -= strlen($etc); |
1347
|
|
|
if (!$break_words) { |
1348
|
|
|
$string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length + 1)); |
1349
|
|
|
$string = preg_replace('/<[^>]*$/', '', $string); |
1350
|
|
|
$string = static::close_tags($string); |
1351
|
|
|
} |
1352
|
|
|
|
1353
|
|
|
return $string . $etc; |
1354
|
|
|
} else { |
1355
|
|
|
return $string; |
1356
|
|
|
} |
1357
|
|
|
} |
1358
|
|
|
|
1359
|
|
|
/** |
1360
|
|
|
* Create an infotip |
1361
|
|
|
* @param $text |
1362
|
|
|
* @return string |
1363
|
|
|
*/ |
1364
|
|
View Code Duplication |
public static function makeInfotips($text) |
|
|
|
|
1365
|
|
|
{ |
1366
|
|
|
$ret = ''; |
1367
|
|
|
$infotips = static::getModuleOption('infotips'); |
1368
|
|
|
if ($infotips > 0) { |
1369
|
|
|
$myts = MyTextSanitizer::getInstance(); |
1370
|
|
|
$ret = $myts->htmlSpecialChars(xoops_substr(strip_tags($text), 0, $infotips)); |
1371
|
|
|
} |
1372
|
|
|
|
1373
|
|
|
return $ret; |
1374
|
|
|
} |
1375
|
|
|
|
1376
|
|
|
/** |
1377
|
|
|
* Mise en place de l'appel à la feuille de style du module dans le template |
1378
|
|
|
* @param string $url |
1379
|
|
|
*/ |
1380
|
|
View Code Duplication |
public static function setCSS($url = '') |
|
|
|
|
1381
|
|
|
{ |
1382
|
|
|
global $xoopsTpl, $xoTheme; |
|
|
|
|
1383
|
|
|
if ($url == '') { |
1384
|
|
|
$url = OLEDRION_URL . 'assets/css/oledrion.css'; |
1385
|
|
|
} |
1386
|
|
|
|
1387
|
|
|
if (!is_object($xoTheme)) { |
1388
|
|
|
$xoopsTpl->assign('xoops_module_header', $xoopsTpl->get_template_vars('xoops_module_header') . "<link rel=\"stylesheet\" type=\"text/css\" href=\"$url\">"); |
1389
|
|
|
} else { |
1390
|
|
|
$xoTheme->addStylesheet($url); |
1391
|
|
|
} |
1392
|
|
|
} |
1393
|
|
|
|
1394
|
|
|
/** |
1395
|
|
|
* Mise en place de l'appel à la feuille de style du module dans le template |
1396
|
|
|
* @param string $language |
1397
|
|
|
*/ |
1398
|
|
View Code Duplication |
public static function setLocalCSS($language = 'english') |
|
|
|
|
1399
|
|
|
{ |
1400
|
|
|
global $xoopsTpl, $xoTheme; |
|
|
|
|
1401
|
|
|
|
1402
|
|
|
$localcss = OLEDRION_URL . 'language/' . $language . '/style.css'; |
1403
|
|
|
|
1404
|
|
|
if (!is_object($xoTheme)) { |
1405
|
|
|
$xoopsTpl->assign('xoops_module_header', $xoopsTpl->get_template_vars('xoops_module_header') . "<link rel=\"stylesheet\" type=\"text/css\" href=\"$localcss\">"); |
1406
|
|
|
} else { |
1407
|
|
|
$xoTheme->addStylesheet($localcss); |
1408
|
|
|
} |
1409
|
|
|
} |
1410
|
|
|
|
1411
|
|
|
/** |
1412
|
|
|
* Calcul du TTC à partir du HT et de la TVA |
1413
|
|
|
* |
1414
|
|
|
* @param float $ht Montant HT |
1415
|
|
|
* @param float $vat Taux de TVA |
1416
|
|
|
* @param boolean $edit Si faux alors le montant est formaté pour affichage sinon il reste tel quel |
1417
|
|
|
* @param string $format Format d'affichage du résultat (long ou court) |
1418
|
|
|
* @return mixed Soit une chaine soit un flottant |
1419
|
|
|
*/ |
1420
|
|
View Code Duplication |
public static function getTTC($ht, $vat, $edit = false, $format = 's') |
|
|
|
|
1421
|
|
|
{ |
1422
|
|
|
$oledrion_Currency = Oledrion_Currency::getInstance(); |
1423
|
|
|
$ttc = $ht * (1 + ($vat / 100)); |
1424
|
|
|
if (!$edit) { |
1425
|
|
|
return $oledrion_Currency->amountForDisplay($ttc, $format); |
1426
|
|
|
} else { |
1427
|
|
|
return $ttc; |
1428
|
|
|
} |
1429
|
|
|
} |
1430
|
|
|
|
1431
|
|
|
/** |
1432
|
|
|
* Renvoie le montant de la tva à partir du montant HT |
1433
|
|
|
* @param $ht |
1434
|
|
|
* @param $vat |
1435
|
|
|
* @return float |
1436
|
|
|
*/ |
1437
|
|
|
public function getVAT($ht, $vat) |
1438
|
|
|
{ |
1439
|
|
|
return (float)(($ht * $vat) / 100); |
1440
|
|
|
} |
1441
|
|
|
|
1442
|
|
|
/** |
1443
|
|
|
* Retourne le montant TTC |
1444
|
|
|
* |
1445
|
|
|
* @param floatval $product_price Le montant du produit |
1446
|
|
|
* @param integer $vat_id Le numéro de TVA |
1447
|
|
|
* @return floatval Le montant TTC si on a trouvé sa TVA sinon |
1448
|
|
|
*/ |
1449
|
|
View Code Duplication |
public static function getAmountWithVat($product_price, $vat_id) |
|
|
|
|
1450
|
|
|
{ |
1451
|
|
|
static $vats = array(); |
1452
|
|
|
$vat_rate = null; |
1453
|
|
|
if (is_array($vats) && in_array($vat_id, $vats)) { |
1454
|
|
|
$vat_rate = $vats[$vat_id]; |
1455
|
|
|
} else { |
1456
|
|
|
$handlers = OledrionHandler::getInstance(); |
1457
|
|
|
$vat = null; |
|
|
|
|
1458
|
|
|
$vat = $handlers->h_oledrion_vat->get($vat_id); |
|
|
|
|
1459
|
|
|
if (is_object($vat)) { |
1460
|
|
|
$vat_rate = $vat->getVar('vat_rate', 'e'); |
1461
|
|
|
$vats[$vat_id] = $vat_rate; |
1462
|
|
|
} |
1463
|
|
|
} |
1464
|
|
|
|
1465
|
|
|
if (null !== $vat_rate) { |
1466
|
|
|
return ((float)$product_price * (float)$vat_rate / 100) + (float)$product_price; |
1467
|
|
|
} else { |
1468
|
|
|
return $product_price; |
1469
|
|
|
} |
1470
|
|
|
} |
1471
|
|
|
|
1472
|
|
|
/** |
1473
|
|
|
* @param $datastream |
1474
|
|
|
* @param $url |
1475
|
|
|
* @return string |
1476
|
|
|
*/ |
1477
|
|
View Code Duplication |
public function postIt($datastream, $url) |
|
|
|
|
1478
|
|
|
{ |
1479
|
|
|
$url = preg_replace('@^http://@i', '', $url); |
1480
|
|
|
$host = substr($url, 0, strpos($url, '/')); |
1481
|
|
|
$uri = strstr($url, '/'); |
1482
|
|
|
$reqbody = ''; |
1483
|
|
|
foreach ($datastream as $key => $val) { |
1484
|
|
|
if (!empty($reqbody)) { |
1485
|
|
|
$reqbody .= '&'; |
1486
|
|
|
} |
1487
|
|
|
$reqbody .= $key . '=' . urlencode($val); |
1488
|
|
|
} |
1489
|
|
|
$contentlength = strlen($reqbody); |
1490
|
|
|
$reqheader = "POST $uri HTTP/1.1\r\n" . "Host: $host\n" . "Content-Type: application/x-www-form-urlencoded\r\n" . "Content-Length: $contentlength\r\n\r\n" . "$reqbody\r\n"; |
1491
|
|
|
|
1492
|
|
|
return $reqheader; |
1493
|
|
|
} |
1494
|
|
|
|
1495
|
|
|
/** |
1496
|
|
|
* Retourne le type Mime d'un fichier en utilisant d'abord finfo puis mime_content |
1497
|
|
|
* |
1498
|
|
|
* @param string $filename Le fichier (avec son chemin d'accès complet) dont on veut connaître le type mime |
1499
|
|
|
* @return string |
1500
|
|
|
*/ |
1501
|
|
View Code Duplication |
public static function getMimeType($filename) |
|
|
|
|
1502
|
|
|
{ |
1503
|
|
|
if (function_exists('finfo_open')) { |
1504
|
|
|
$finfo = finfo_open(); |
1505
|
|
|
$mimetype = finfo_file($finfo, $filename, FILEINFO_MIME_TYPE); |
1506
|
|
|
finfo_close($finfo); |
1507
|
|
|
|
1508
|
|
|
return $mimetype; |
1509
|
|
|
} else { |
1510
|
|
|
if (function_exists('mime_content_type')) { |
1511
|
|
|
return mime_content_type($filename); |
1512
|
|
|
} else { |
1513
|
|
|
return ''; |
1514
|
|
|
} |
1515
|
|
|
} |
1516
|
|
|
} |
1517
|
|
|
|
1518
|
|
|
/** |
1519
|
|
|
* Retourne un criteria compo qui permet de filtrer les produits sur le mois courant |
1520
|
|
|
* |
1521
|
|
|
* @return object |
1522
|
|
|
*/ |
1523
|
|
View Code Duplication |
public function getThisMonthCriteria() |
|
|
|
|
1524
|
|
|
{ |
1525
|
|
|
$start = mktime(0, 1, 0, date('n'), date('j'), date('Y')); |
1526
|
|
|
$end = mktime(0, 0, 0, date('n'), date('t'), date('Y')); |
1527
|
|
|
$criteriaThisMonth = new CriteriaCompo(); |
1528
|
|
|
$criteriaThisMonth->add(new Criteria('product_submitted', $start, '>=')); |
1529
|
|
|
$criteriaThisMonth->add(new Criteria('product_submitted', $end, '<=')); |
1530
|
|
|
|
1531
|
|
|
return $criteriaThisMonth; |
1532
|
|
|
} |
1533
|
|
|
|
1534
|
|
|
/** |
1535
|
|
|
* Retourne une liste d'objets XoopsUsers à partir d'une liste d'identifiants |
1536
|
|
|
* |
1537
|
|
|
* @param array $xoopsUsersIDs La liste des ID |
1538
|
|
|
* @return array Les objets XoopsUsers |
1539
|
|
|
*/ |
1540
|
|
View Code Duplication |
public static function getUsersFromIds($xoopsUsersIDs) |
|
|
|
|
1541
|
|
|
{ |
1542
|
|
|
$users = array(); |
1543
|
|
|
if (is_array($xoopsUsersIDs) && count($xoopsUsersIDs) > 0) { |
1544
|
|
|
$xoopsUsersIDs = array_unique($xoopsUsersIDs); |
1545
|
|
|
sort($xoopsUsersIDs); |
1546
|
|
|
if (count($xoopsUsersIDs) > 0) { |
1547
|
|
|
$memberHandler = xoops_getHandler('user'); |
1548
|
|
|
$criteria = new Criteria('uid', '(' . implode(',', $xoopsUsersIDs) . ')', 'IN'); |
1549
|
|
|
$criteria->setSort('uid'); |
1550
|
|
|
$users = $memberHandler->getObjects($criteria, true); |
1551
|
|
|
} |
1552
|
|
|
} |
1553
|
|
|
|
1554
|
|
|
return $users; |
1555
|
|
|
} |
1556
|
|
|
|
1557
|
|
|
/** |
1558
|
|
|
* Retourne l'ID de l'utilisateur courant (s'il est connecté) |
1559
|
|
|
* @return integer L'uid ou 0 |
1560
|
|
|
*/ |
1561
|
|
|
public static function getCurrentUserID() |
1562
|
|
|
{ |
1563
|
|
|
global $xoopsUser; |
|
|
|
|
1564
|
|
|
$uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : 0; |
1565
|
|
|
|
1566
|
|
|
return $uid; |
1567
|
|
|
} |
1568
|
|
|
|
1569
|
|
|
/** |
1570
|
|
|
* Retourne la liste des groupes de l'utilisateur courant (avec cache) |
1571
|
|
|
* @param int $uid |
1572
|
|
|
* @return array Les ID des groupes auquel l'utilisateur courant appartient |
1573
|
|
|
*/ |
1574
|
|
View Code Duplication |
public function getMemberGroups($uid = 0) |
|
|
|
|
1575
|
|
|
{ |
1576
|
|
|
static $buffer = array(); |
1577
|
|
|
if ($uid == 0) { |
1578
|
|
|
$uid = static::getCurrentUserID(); |
1579
|
|
|
} |
1580
|
|
|
|
1581
|
|
|
if (is_array($buffer) && count($buffer) > 0 && isset($buffer[$uid])) { |
1582
|
|
|
return $buffer[$uid]; |
1583
|
|
|
} else { |
1584
|
|
|
if ($uid > 0) { |
1585
|
|
|
$memberHandler = xoops_getHandler('member'); |
1586
|
|
|
$buffer[$uid] = $memberHandler->getGroupsByUser($uid, false); // Renvoie un tableau d'ID (de groupes) |
1587
|
|
|
} else { |
1588
|
|
|
$buffer[$uid] = array(XOOPS_GROUP_ANONYMOUS); |
1589
|
|
|
} |
1590
|
|
|
} |
1591
|
|
|
|
1592
|
|
|
return $buffer[$uid]; |
1593
|
|
|
} |
1594
|
|
|
|
1595
|
|
|
/** |
1596
|
|
|
* Indique si l'utilisateur courant fait partie d'une groupe donné (avec gestion de cache) |
1597
|
|
|
* |
1598
|
|
|
* @param integer $group Groupe recherché |
1599
|
|
|
* @param int $uid |
1600
|
|
|
* @return bool vrai si l'utilisateur fait partie du groupe, faux sinon |
1601
|
|
|
*/ |
1602
|
|
View Code Duplication |
public static function isMemberOfGroup($group = 0, $uid = 0) |
|
|
|
|
1603
|
|
|
{ |
1604
|
|
|
static $buffer = array(); |
1605
|
|
|
$retval = false; |
|
|
|
|
1606
|
|
|
if ($uid == 0) { |
1607
|
|
|
$uid = static::getCurrentUserID(); |
1608
|
|
|
} |
1609
|
|
|
if (is_array($buffer) && array_key_exists($group, $buffer)) { |
|
|
|
|
1610
|
|
|
$retval = $buffer[$group]; |
1611
|
|
|
} else { |
1612
|
|
|
$memberHandler = xoops_getHandler('member'); |
1613
|
|
|
$groups = $memberHandler->getGroupsByUser($uid, false); // Renvoie un tableau d'ID (de groupes) |
1614
|
|
|
$retval = in_array($group, $groups); |
1615
|
|
|
$buffer[$group] = $retval; |
1616
|
|
|
} |
1617
|
|
|
|
1618
|
|
|
return $retval; |
1619
|
|
|
} |
1620
|
|
|
|
1621
|
|
|
/** |
1622
|
|
|
* Fonction chargée de vérifier qu'un répertoire existe, qu'on peut écrire dedans et création d'un fichier index.html |
1623
|
|
|
* |
1624
|
|
|
* @param string $folder Le chemin complet du répertoire à vérifier |
1625
|
|
|
* @return void |
1626
|
|
|
*/ |
1627
|
|
View Code Duplication |
public static function prepareFolder($folder) |
|
|
|
|
1628
|
|
|
{ |
1629
|
|
|
if (!is_dir($folder)) { |
1630
|
|
|
mkdir($folder, 0777); |
1631
|
|
|
file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
1632
|
|
|
} |
1633
|
|
|
chmod($folder, 0777); |
1634
|
|
|
} |
1635
|
|
|
|
1636
|
|
|
/** |
1637
|
|
|
* Duplicate a file in local |
1638
|
|
|
* |
1639
|
|
|
* @param string $path The file's path |
1640
|
|
|
* @param string $filename The filename |
1641
|
|
|
* @return mixed If the copy succeed, the new filename else false |
1642
|
|
|
* @since 2.1 |
1643
|
|
|
*/ |
1644
|
|
View Code Duplication |
public function duplicateFile($path, $filename) |
|
|
|
|
1645
|
|
|
{ |
1646
|
|
|
$newName = static::createUploadName($path, $filename); |
1647
|
|
|
if (copy($path . '/' . $filename, $path . '/' . $newName)) { |
1648
|
|
|
return $newName; |
1649
|
|
|
} else { |
1650
|
|
|
return false; |
1651
|
|
|
} |
1652
|
|
|
} |
1653
|
|
|
|
1654
|
|
|
/** |
1655
|
|
|
* Load a language file |
1656
|
|
|
* |
1657
|
|
|
* @param string $languageFile The required language file |
1658
|
|
|
* @param string $defaultExtension Default extension to use |
1659
|
|
|
* @since 2.2.2009.02.13 |
1660
|
|
|
*/ |
1661
|
|
View Code Duplication |
public static function loadLanguageFile($languageFile, $defaultExtension = '.php') |
|
|
|
|
1662
|
|
|
{ |
1663
|
|
|
global $xoopsConfig; |
|
|
|
|
1664
|
|
|
$root = OLEDRION_PATH; |
1665
|
|
|
if (false === strpos($languageFile, $defaultExtension)) { |
1666
|
|
|
$languageFile .= $defaultExtension; |
1667
|
|
|
} |
1668
|
|
|
if (file_exists($root . 'language/' . $xoopsConfig['language'] . '/' . $languageFile)) { |
1669
|
|
|
require_once $root . 'language/' . $xoopsConfig['language'] . '/' . $languageFile; |
1670
|
|
|
} else { // Fallback |
1671
|
|
|
require_once $root . 'language/english' . '/' . $languageFile; |
1672
|
|
|
} |
1673
|
|
|
} |
1674
|
|
|
|
1675
|
|
|
/** |
1676
|
|
|
* Formatage d'un floattant pour la base de données |
1677
|
|
|
* |
1678
|
|
|
* @param float Le montant à formater |
1679
|
|
|
* @return string le montant formaté |
1680
|
|
|
* @since 2.2.2009.02.25 |
1681
|
|
|
*/ |
1682
|
|
|
public static function formatFloatForDB($amount) |
1683
|
|
|
{ |
1684
|
|
|
return number_format($amount, 2, '.', ''); |
1685
|
|
|
} |
1686
|
|
|
|
1687
|
|
|
/** |
1688
|
|
|
* Appelle un fichier Javascript à la manière de Xoops |
1689
|
|
|
* |
1690
|
|
|
* @note, l'url complète ne doit pas être fournie, la méthode se charge d'ajouter |
1691
|
|
|
* le chemin vers le répertoire js en fonction de la requête, c'est à dire que si |
1692
|
|
|
* on appelle un fichier de langue, la méthode ajoute l'url vers le répertoire de |
1693
|
|
|
* langue, dans le cas contraire on ajoute l'url vers le répertoire JS du module. |
1694
|
|
|
* |
1695
|
|
|
* @param string $javascriptFile |
1696
|
|
|
* @param bool $inLanguageFolder |
1697
|
|
|
* @param bool $oldWay |
1698
|
|
|
* @since 2.3.2009.03.14 |
1699
|
|
|
*/ |
1700
|
|
View Code Duplication |
public static function callJavascriptFile($javascriptFile, $inLanguageFolder = false, $oldWay = false) |
|
|
|
|
1701
|
|
|
{ |
1702
|
|
|
global $xoopsConfig, $xoTheme; |
|
|
|
|
1703
|
|
|
$fileToCall = $javascriptFile; |
|
|
|
|
1704
|
|
|
if ($inLanguageFolder) { |
1705
|
|
|
$root = OLEDRION_PATH; |
1706
|
|
|
$rootUrl = OLEDRION_URL; |
1707
|
|
|
if (file_exists($root . 'language/' . $xoopsConfig['language'] . '/' . $javascriptFile)) { |
1708
|
|
|
$fileToCall = $rootUrl . 'language/' . $xoopsConfig['language'] . '/' . $javascriptFile; |
1709
|
|
|
} else { // Fallback |
1710
|
|
|
$fileToCall = $rootUrl . 'language/english/' . $javascriptFile; |
1711
|
|
|
} |
1712
|
|
|
} else { |
1713
|
|
|
$fileToCall = OLEDRION_JS_URL . $javascriptFile; |
1714
|
|
|
} |
1715
|
|
|
|
1716
|
|
|
$xoTheme->addScript('browse.php?Frameworks/jquery/jquery.js'); |
1717
|
|
|
$xoTheme->addScript($fileToCall); |
1718
|
|
|
} |
1719
|
|
|
|
1720
|
|
|
/** |
1721
|
|
|
* Create the <option> of an html select |
1722
|
|
|
* |
1723
|
|
|
* @param array $array Array of index and labels |
1724
|
|
|
* @param mixed $default the default value |
1725
|
|
|
* @param bool $withNull |
1726
|
|
|
* @return string |
1727
|
|
|
* @since 2.3.2009.03.13 |
1728
|
|
|
*/ |
1729
|
|
View Code Duplication |
public static function htmlSelectOptions($array, $default = 0, $withNull = true) |
|
|
|
|
1730
|
|
|
{ |
1731
|
|
|
$ret = array(); |
1732
|
|
|
$selected = ''; |
1733
|
|
|
if ($withNull) { |
1734
|
|
|
if ($default === 0) { |
1735
|
|
|
$selected = " selected = 'selected'"; |
1736
|
|
|
} |
1737
|
|
|
$ret[] = '<option value=0' . $selected . '>---</option>'; |
1738
|
|
|
} |
1739
|
|
|
|
1740
|
|
|
foreach ($array as $index => $label) { |
1741
|
|
|
$selected = ''; |
1742
|
|
|
if ($index == $default) { |
1743
|
|
|
$selected = " selected = 'selected'"; |
1744
|
|
|
} |
1745
|
|
|
$ret[] = "<option value=\"" . $index . "\"" . $selected . '>' . $label . '</option>'; |
1746
|
|
|
} |
1747
|
|
|
|
1748
|
|
|
return implode("\n", $ret); |
1749
|
|
|
} |
1750
|
|
|
|
1751
|
|
|
/** |
1752
|
|
|
* Creates an html select |
1753
|
|
|
* |
1754
|
|
|
* @param string $selectName Selector's name |
1755
|
|
|
* @param array $array Options |
1756
|
|
|
* @param mixed $default Default's value |
1757
|
|
|
* @param boolean $withNull Do we include a null option ? |
1758
|
|
|
* @return string |
1759
|
|
|
* @since 2.3.2009.03.13 |
1760
|
|
|
*/ |
1761
|
|
View Code Duplication |
public static function htmlSelect($selectName, $array, $default, $withNull = true) |
|
|
|
|
1762
|
|
|
{ |
1763
|
|
|
$ret = ''; |
1764
|
|
|
$ret .= "<select name='" . $selectName . "' id='" . $selectName . "'>\n"; |
1765
|
|
|
$ret .= static::htmlSelectOptions($array, $default, $withNull); |
1766
|
|
|
$ret .= "</select>\n"; |
1767
|
|
|
|
1768
|
|
|
return $ret; |
1769
|
|
|
} |
1770
|
|
|
|
1771
|
|
|
/** |
1772
|
|
|
* Extrait l'id d'une chaine formatée sous la forme xxxx-99 (duquel on récupère 99) |
1773
|
|
|
* |
1774
|
|
|
* @note: utilisé par les attributs produits |
1775
|
|
|
* @param string $string La chaine de travail |
1776
|
|
|
* @param string $separator Le séparateur |
1777
|
|
|
* @return string |
|
|
|
|
1778
|
|
|
*/ |
1779
|
|
View Code Duplication |
public function getId($string, $separator = '_') |
|
|
|
|
1780
|
|
|
{ |
1781
|
|
|
$pos = strrpos($string, $separator); |
1782
|
|
|
if ($pos === false) { |
1783
|
|
|
return $string; |
1784
|
|
|
} else { |
1785
|
|
|
return (int)substr($string, $pos + 1); |
1786
|
|
|
} |
1787
|
|
|
} |
1788
|
|
|
|
1789
|
|
|
/** |
1790
|
|
|
* Fonction "inverse" de getId (depuis xxxx-99 on récupère xxxx) |
1791
|
|
|
* |
1792
|
|
|
* @note: utilisé par les attributs produits |
1793
|
|
|
* @param string $string La chaine de travail |
1794
|
|
|
* @param string $separator Le séparateur |
1795
|
|
|
* @return string |
1796
|
|
|
*/ |
1797
|
|
View Code Duplication |
public function getName($string, $separator = '_') |
|
|
|
|
1798
|
|
|
{ |
1799
|
|
|
$pos = strrpos($string, $separator); |
1800
|
|
|
if ($pos === false) { |
1801
|
|
|
return $string; |
1802
|
|
|
} else { |
1803
|
|
|
return substr($string, 0, $pos); |
1804
|
|
|
} |
1805
|
|
|
} |
1806
|
|
|
|
1807
|
|
|
/** |
1808
|
|
|
* Renvoie un montant nul si le montant est négatif |
1809
|
|
|
* |
1810
|
|
|
* @param float $amount |
1811
|
|
|
* @return float |
|
|
|
|
1812
|
|
|
*/ |
1813
|
|
|
public static function doNotAcceptNegativeAmounts(&$amount) |
1814
|
|
|
{ |
1815
|
|
|
if ($amount < 0) { |
1816
|
|
|
$amount = 0; |
1817
|
|
|
} |
1818
|
|
|
} |
1819
|
|
|
|
1820
|
|
|
/** |
1821
|
|
|
* Returns a string from the request |
1822
|
|
|
* |
1823
|
|
|
* @param string $valueName Name of the parameter you want to get |
1824
|
|
|
* @param mixed $defaultValue Default value to return if the parameter is not set in the request |
1825
|
|
|
* @return mixed |
1826
|
|
|
*/ |
1827
|
|
|
public function getFromRequest($valueName, $defaultValue = '') |
|
|
|
|
1828
|
|
|
{ |
1829
|
|
|
return isset($_REQUEST[$valueName]) ? $_REQUEST[$valueName] : $defaultValue; |
1830
|
|
|
} |
1831
|
|
|
|
1832
|
|
|
/** |
1833
|
|
|
* Verify that a mysql table exists |
1834
|
|
|
* |
1835
|
|
|
* @package Oledrion |
1836
|
|
|
* @author Instant Zero (http://xoops.instant-zero.com) |
1837
|
|
|
* @copyright (c) Instant Zero |
1838
|
|
|
* @param $tablename |
1839
|
|
|
* @return bool |
1840
|
|
|
*/ |
1841
|
|
|
public static function tableExists($tablename) |
1842
|
|
|
{ |
1843
|
|
|
global $xoopsDB; |
|
|
|
|
1844
|
|
|
$result = $xoopsDB->queryF("SHOW TABLES LIKE '$tablename'"); |
1845
|
|
|
|
1846
|
|
|
return ($xoopsDB->getRowsNum($result) > 0); |
1847
|
|
|
} |
1848
|
|
|
|
1849
|
|
|
/** |
1850
|
|
|
* Verify that a field exists inside a mysql table |
1851
|
|
|
* |
1852
|
|
|
* @package Oledrion |
1853
|
|
|
* @author Instant Zero (http://xoops.instant-zero.com) |
1854
|
|
|
* @copyright (c) Instant Zero |
1855
|
|
|
* @param $fieldname |
1856
|
|
|
* @param $table |
1857
|
|
|
* @return bool |
1858
|
|
|
*/ |
1859
|
|
|
public static function fieldExists($fieldname, $table) |
1860
|
|
|
{ |
1861
|
|
|
global $xoopsDB; |
|
|
|
|
1862
|
|
|
$result = $xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); |
1863
|
|
|
|
1864
|
|
|
return ($xoopsDB->getRowsNum($result) > 0); |
1865
|
|
|
} |
1866
|
|
|
|
1867
|
|
|
/** |
1868
|
|
|
* Retourne la définition d'un champ |
1869
|
|
|
* |
1870
|
|
|
* @param string $fieldname |
1871
|
|
|
* @param string $table |
1872
|
|
|
* @return array |
1873
|
|
|
*/ |
1874
|
|
View Code Duplication |
public function getFieldDefinition($fieldname, $table) |
|
|
|
|
1875
|
|
|
{ |
1876
|
|
|
global $xoopsDB; |
|
|
|
|
1877
|
|
|
$result = $xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); |
1878
|
|
|
if ($result) { |
1879
|
|
|
return $xoopsDB->fetchArray($result); |
1880
|
|
|
} |
1881
|
|
|
|
1882
|
|
|
return ''; |
1883
|
|
|
} |
1884
|
|
|
|
1885
|
|
|
/** |
1886
|
|
|
* Add a field to a mysql table |
1887
|
|
|
* |
1888
|
|
|
* @package Oledrion |
1889
|
|
|
* @author Instant Zero (http://xoops.instant-zero.com) |
1890
|
|
|
* @copyright (c) Instant Zero |
1891
|
|
|
* @param $field |
1892
|
|
|
* @param $table |
1893
|
|
|
* @return |
1894
|
|
|
*/ |
1895
|
|
|
public static function addField($field, $table) |
|
|
|
|
1896
|
|
|
{ |
1897
|
|
|
global $xoopsDB; |
|
|
|
|
1898
|
|
|
$result = $xoopsDB->queryF("ALTER TABLE $table ADD $field;"); |
1899
|
|
|
|
1900
|
|
|
return $result; |
1901
|
|
|
} |
1902
|
|
|
|
1903
|
|
|
/** |
1904
|
|
|
* @param $info |
1905
|
|
|
* @return string |
1906
|
|
|
*/ |
1907
|
|
View Code Duplication |
public function packingHtmlSelect($info) |
|
|
|
|
1908
|
|
|
{ |
1909
|
|
|
$ret = ''; |
1910
|
|
|
$ret .= '<div class="oledrion_htmlform">'; |
1911
|
|
|
$ret .= '<img class="oledrion_htmlimage" src="' . $info['packing_image_url'] . '" alt="' . $info['packing_title'] . '">'; |
1912
|
|
|
$ret .= '<h3>' . $info['packing_title'] . '</h3>'; |
1913
|
|
|
if ($info['packing_price'] > 0) { |
1914
|
|
|
$ret .= '<p><span class="bold">' . _OLEDRION_PRICE . '</span> : ' . $info['packing_price_fordisplay'] . '</p>'; |
1915
|
|
|
} else { |
1916
|
|
|
$ret .= '<p><span class="bold">' . _OLEDRION_PRICE . '</span> : ' . _OLEDRION_FREE . '</p>'; |
1917
|
|
|
} |
1918
|
|
|
$ret .= '<p>' . $info['packing_description'] . '</p>'; |
1919
|
|
|
$ret .= '</div>'; |
1920
|
|
|
|
1921
|
|
|
return $ret; |
1922
|
|
|
} |
1923
|
|
|
|
1924
|
|
|
/** |
1925
|
|
|
* @param $info |
1926
|
|
|
* @return string |
1927
|
|
|
*/ |
1928
|
|
View Code Duplication |
public function deliveryHtmlSelect($info) |
|
|
|
|
1929
|
|
|
{ |
1930
|
|
|
$ret = ''; |
1931
|
|
|
$ret .= '<div class="oledrion_htmlform">'; |
1932
|
|
|
$ret .= '<img class="oledrion_htmlimage" src="' . $info['delivery_image_url'] . '" alt="' . $info['delivery_title'] . '">'; |
1933
|
|
|
$ret .= '<h3>' . $info['delivery_title'] . '</h3>'; |
1934
|
|
|
if ($info['delivery_price'] > 0) { |
1935
|
|
|
$ret .= '<p><span class="bold">' . _OLEDRION_PRICE . '</span> : ' . $info['delivery_price_fordisplay'] . '</p>'; |
1936
|
|
|
} else { |
1937
|
|
|
$ret .= '<p><span class="bold">' . _OLEDRION_PRICE . '</span> : ' . _OLEDRION_FREE . '</p>'; |
1938
|
|
|
} |
1939
|
|
|
$ret .= '<p><span class="bold">' . _OLEDRION_DELIVERY_TIME . '</span> : ' . $info['delivery_time'] . _OLEDRION_DELIVERY_DAY . '</p>'; |
1940
|
|
|
$ret .= '<p>' . $info['delivery_description'] . '</p>'; |
1941
|
|
|
$ret .= '</div>'; |
1942
|
|
|
|
1943
|
|
|
return $ret; |
1944
|
|
|
} |
1945
|
|
|
|
1946
|
|
|
/** |
1947
|
|
|
* @param $info |
1948
|
|
|
* @return string |
1949
|
|
|
*/ |
1950
|
|
View Code Duplication |
public function paymentHtmlSelect($info) |
|
|
|
|
1951
|
|
|
{ |
1952
|
|
|
$ret = ''; |
1953
|
|
|
$ret .= '<div class="oledrion_htmlform">'; |
1954
|
|
|
$ret .= '<img class="oledrion_htmlimage" src="' . $info['payment_image_url'] . '" alt="' . $info['payment_title'] . '">'; |
1955
|
|
|
$ret .= '<h3>' . $info['payment_title'] . '</h3>'; |
1956
|
|
|
$ret .= '<p>' . $info['payment_description'] . '</p>'; |
1957
|
|
|
$ret .= '</div>'; |
1958
|
|
|
|
1959
|
|
|
return $ret; |
1960
|
|
|
} |
1961
|
|
|
|
1962
|
|
|
/** |
1963
|
|
|
* @return array |
1964
|
|
|
*/ |
1965
|
|
|
public function getCountriesList() |
1966
|
|
|
{ |
1967
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
1968
|
|
|
|
1969
|
|
|
return XoopsLists::getCountryList(); |
1970
|
|
|
} |
1971
|
|
|
} |
1972
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.