1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
|
4
|
|
|
use Xmf\Request; |
5
|
|
|
|
6
|
|
|
require_once __DIR__ . '/common/traitversionchecks.php'; |
7
|
|
|
require_once __DIR__ . '/common/traitserverstats.php'; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class MyalbumUtil |
11
|
|
|
*/ |
12
|
|
|
class WfLinksUtility extends XoopsObject |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
use VersionChecks; //checkVerXoops, checkVerPhp Traits |
15
|
|
|
|
16
|
|
|
use ServerStats; // getServerStats Trait |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Function responsible for checking if a directory exists, we can also write in and create an index.html file |
20
|
|
|
* |
21
|
|
|
* @param string $folder The full path of the directory to check |
22
|
|
|
* |
23
|
|
|
* @return void |
24
|
|
|
*/ |
25
|
|
|
public static function createFolder($folder) |
26
|
|
|
{ |
27
|
|
|
// try { |
28
|
|
|
// if (!mkdir($folder) && !is_dir($folder)) { |
|
|
|
|
29
|
|
|
// throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
|
|
|
30
|
|
|
// } else { |
|
|
|
|
31
|
|
|
// file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
|
|
|
32
|
|
|
// } |
33
|
|
|
// } |
34
|
|
|
// catch (Exception $e) { |
|
|
|
|
35
|
|
|
// echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
|
|
|
36
|
|
|
// } |
37
|
|
|
try { |
38
|
|
|
if (!file_exists($folder)) { |
39
|
|
|
if (!mkdir($folder) && !is_dir($folder)) { |
40
|
|
|
throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
catch (Exception $e) { |
47
|
|
|
echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param $file |
53
|
|
|
* @param $folder |
54
|
|
|
* @return bool |
55
|
|
|
*/ |
56
|
|
|
public static function copyFile($file, $folder) |
57
|
|
|
{ |
58
|
|
|
return copy($file, $folder); |
59
|
|
|
// try { |
60
|
|
|
// if (!is_dir($folder)) { |
|
|
|
|
61
|
|
|
// throw new \RuntimeException(sprintf('Unable to copy file as: %s ', $folder)); |
|
|
|
|
62
|
|
|
// } else { |
|
|
|
|
63
|
|
|
// return copy($file, $folder); |
|
|
|
|
64
|
|
|
// } |
65
|
|
|
// } catch (Exception $e) { |
|
|
|
|
66
|
|
|
// echo 'Caught exception: ', $e->getMessage(), "\n", "<br>"; |
|
|
|
|
67
|
|
|
// } |
68
|
|
|
// return false; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param $src |
73
|
|
|
* @param $dst |
74
|
|
|
*/ |
75
|
|
|
public static function recurseCopy($src, $dst) |
76
|
|
|
{ |
77
|
|
|
$dir = opendir($src); |
78
|
|
|
// @mkdir($dst); |
79
|
|
|
while (false !== ($file = readdir($dir))) { |
80
|
|
|
if (($file !== '.') && ($file !== '..')) { |
81
|
|
|
if (is_dir($src . '/' . $file)) { |
82
|
|
|
self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
83
|
|
|
} else { |
84
|
|
|
copy($src . '/' . $file, $dst . '/' . $file); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
closedir($dir); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.