1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Oledrion; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
You may not change or alter any portion of this comment or credits |
7
|
|
|
of supporting developers from this source code or any supporting source code |
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
9
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* oledrion |
17
|
|
|
* |
18
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
19
|
|
|
* @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
20
|
|
|
* @author Hervé Thouzard (http://www.herve-thouzard.com/) |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
use XoopsModules\Oledrion; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Management of text files used to display messages to users on certain pages |
27
|
|
|
*/ |
28
|
|
|
class Registryfile |
29
|
|
|
{ |
30
|
|
|
public $filename; // File name to process |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Access the only instance of this class |
34
|
|
|
* |
35
|
|
|
* @return Registryfile |
36
|
|
|
*/ |
37
|
|
|
public static function getInstance() |
38
|
|
|
{ |
39
|
|
|
static $instance; |
40
|
|
|
if (null === $instance) { |
41
|
|
|
$instance = new static(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $instance; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Registryfile constructor. |
49
|
|
|
* @param null $fichier |
|
|
|
|
50
|
|
|
*/ |
51
|
|
|
public function __construct($fichier = null) |
52
|
|
|
{ |
53
|
|
|
$this->setfile($fichier); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param null $fichier |
|
|
|
|
58
|
|
|
*/ |
59
|
|
|
public function setfile($fichier = null) |
60
|
|
|
{ |
61
|
|
|
if ($fichier) { |
62
|
|
|
$this->filename = OLEDRION_TEXT_PATH . $fichier; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param null $fichier |
|
|
|
|
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
|
|
public function getfile($fichier = null) |
71
|
|
|
{ |
72
|
|
|
$fw = ''; |
73
|
|
|
if (!$fichier) { |
74
|
|
|
$fw = $this->filename; |
75
|
|
|
} else { |
76
|
|
|
$fw = OLEDRION_TEXT_PATH . $fichier; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if (file_exists($fw)) { |
80
|
|
|
return file_get_contents($fw); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return ''; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param $content |
88
|
|
|
* @param null $fichier |
|
|
|
|
89
|
|
|
* @return bool |
90
|
|
|
*/ |
91
|
|
|
public function savefile($content, $fichier = null) |
92
|
|
|
{ |
93
|
|
|
$fw = ''; |
94
|
|
|
if (!$fichier) { |
95
|
|
|
$fw = $this->filename; |
96
|
|
|
} else { |
97
|
|
|
$fw = OLEDRION_TEXT_PATH . $fichier; |
98
|
|
|
} |
99
|
|
|
if (file_exists($fw)) { |
100
|
|
|
if (false === @unlink($fw)) { |
101
|
|
|
throw new \RuntimeException('The file ' . $fw . ' could not be deleted.'); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
$fp = fopen($fw, 'wb') || die('Error, impossible to create the file ' . $this->filename); |
105
|
|
|
fwrite($fp, $content); |
|
|
|
|
106
|
|
|
fclose($fp); |
|
|
|
|
107
|
|
|
|
108
|
|
|
return true; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|