1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
class GeneralMethods extends Object |
|
|
|
|
5
|
|
|
{ |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* opens a location with curl to see if it exists. |
10
|
|
|
* |
11
|
|
|
* @param string $url |
12
|
|
|
* |
13
|
|
|
* @return boolean |
14
|
|
|
*/ |
15
|
|
|
public static function check_location($url) |
16
|
|
|
{ |
17
|
|
|
$handle = curl_init($url); |
18
|
|
|
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); |
19
|
|
|
curl_setopt($handle, CURLOPT_CONNECTTIMEOUT, true); |
20
|
|
|
$response = curl_exec($handle); |
|
|
|
|
21
|
|
|
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); |
22
|
|
|
$outcome = $httpCode == 200; |
23
|
|
|
curl_close($handle); |
24
|
|
|
return $outcome; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* |
31
|
|
|
* @use |
32
|
|
|
* ``` |
33
|
|
|
* GeneralMethods::output_to_screen('asdf', 'created') |
34
|
|
|
* ``` |
35
|
|
|
* @see DB::alteration_message for types... |
36
|
|
|
* |
37
|
|
|
* @param string $message |
38
|
|
|
* @param string $type |
39
|
|
|
*/ |
40
|
|
|
public static function output_to_screen($message, $type = "") |
41
|
|
|
{ |
42
|
|
|
if(Director::is_cli()) { |
43
|
|
|
DB::alteration_message($message, $type); |
44
|
|
|
} else { |
45
|
|
|
echo "<br />"; |
46
|
|
|
flush(); |
47
|
|
|
ob_end_flush(); |
48
|
|
|
DB::alteration_message($message, $type); |
49
|
|
|
ob_start(); |
50
|
|
|
|
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/* |
55
|
|
|
* Recursively removes a directory |
56
|
|
|
* |
57
|
|
|
* @param string $path |
58
|
|
|
*/ |
59
|
|
|
|
60
|
|
|
public static function removeDirectory($path) |
61
|
|
|
{ |
62
|
|
|
FileSystem::removeFolder($path); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/* |
66
|
|
|
* Replaces all instances of a string in a file, and rewrites the file |
67
|
|
|
* |
68
|
|
|
* @param string $fileName |
69
|
|
|
* @param string $search |
70
|
|
|
* @param string $replacement |
71
|
|
|
* |
72
|
|
|
**/ |
73
|
|
|
public static function replaceInFile($fileName, $search, $replacement) |
74
|
|
|
{ |
75
|
|
|
$file = fopen($fileName, 'r'); |
76
|
|
|
if ($file) { |
77
|
|
|
$content = fread($file, filesize($fileName) * 2); |
78
|
|
|
$newContent = str_replace($search, $replacement, $content); |
79
|
|
|
fclose($file); |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
$file = fopen($fileName, 'w'); |
83
|
|
|
if ($file) { |
84
|
|
|
fwrite($file, $newContent); |
85
|
|
|
fclose($file); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
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.