|
1
|
|
|
<?php |
|
2
|
|
|
// ------------------------------------------------------------------------ // |
|
3
|
|
|
// Copyright (c) 2005-2006 Herve Thouzard // |
|
4
|
|
|
// <http://www.herve-thouzard.com/> // |
|
5
|
|
|
// ------------------------------------------------------------------------- // |
|
6
|
|
|
// This program is free software; you can redistribute it and/or modify // |
|
7
|
|
|
// it under the terms of the GNU General Public License as published by // |
|
8
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
|
9
|
|
|
// (at your option) any later version. // |
|
10
|
|
|
// // |
|
11
|
|
|
// You may not change or alter any portion of this comment or credits // |
|
12
|
|
|
// of supporting developers from this source code or any supporting // |
|
13
|
|
|
// source code which is considered copyrighted (c) material of the // |
|
14
|
|
|
// original comment or credit authors. // |
|
15
|
|
|
// // |
|
16
|
|
|
// This program is distributed in the hope that it will be useful, // |
|
17
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
18
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
19
|
|
|
// GNU General Public License for more details. // |
|
20
|
|
|
// // |
|
21
|
|
|
// You should have received a copy of the GNU General Public License // |
|
22
|
|
|
// along with this program; if not, write to the Free Software // |
|
23
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
|
24
|
|
|
// ------------------------------------------------------------------------ // |
|
25
|
|
|
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Class news_registryfile |
|
29
|
|
|
*/ |
|
30
|
|
|
class news_registryfile |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
public $filename; // filename to manage |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param null $fichier |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct($fichier = null) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->setfile($fichier); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param null $fichier |
|
44
|
|
|
*/ |
|
45
|
|
|
public function setfile($fichier = null) |
|
46
|
|
|
{ |
|
47
|
|
|
if ($fichier) { |
|
48
|
|
|
$this->filename = XOOPS_UPLOAD_PATH . '/' . $fichier; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param null $fichier |
|
54
|
|
|
* |
|
55
|
|
|
* @return bool|string |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getfile($fichier = null) |
|
58
|
|
|
{ |
|
59
|
|
|
$fw = ''; |
|
|
|
|
|
|
60
|
|
View Code Duplication |
if (!$fichier) { |
|
|
|
|
|
|
61
|
|
|
$fw = $this->filename; |
|
62
|
|
|
} else { |
|
63
|
|
|
$fw = XOOPS_UPLOAD_PATH . '/' . $fichier; |
|
64
|
|
|
} |
|
65
|
|
|
if (file_exists($fw)) { |
|
66
|
|
|
return file_get_contents($fw); |
|
67
|
|
|
} else { |
|
68
|
|
|
return ''; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param $content |
|
74
|
|
|
* @param null $fichier |
|
75
|
|
|
* |
|
76
|
|
|
* @return bool |
|
77
|
|
|
*/ |
|
78
|
|
|
public function savefile($content, $fichier = null) |
|
79
|
|
|
{ |
|
80
|
|
|
$fw = ''; |
|
|
|
|
|
|
81
|
|
View Code Duplication |
if (!$fichier) { |
|
|
|
|
|
|
82
|
|
|
$fw = $this->filename; |
|
83
|
|
|
} else { |
|
84
|
|
|
$fw = XOOPS_UPLOAD_PATH . '/' . $fichier; |
|
85
|
|
|
} |
|
86
|
|
|
if (file_exists($fw)) { |
|
87
|
|
|
@unlink($fw); |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
$fp = fopen($fw, 'w') || die(_ERRORS); |
|
|
|
|
|
|
90
|
|
|
fwrite($fp, $content); |
|
91
|
|
|
fclose($fp); |
|
92
|
|
|
|
|
93
|
|
|
return true; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.