forked from MarkDHamill/digests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathext.php
More file actions
executable file
·113 lines (93 loc) · 2.74 KB
/
ext.php
File metadata and controls
executable file
·113 lines (93 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
*
* @package phpBB Extension - Digests
* @copyright (c) 2017 Mark D. Hamill (mark@phpbbservices.com)
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
namespace phpbbservices\digests;
/**
* @ignore
*/
class ext extends \phpbb\extension\base
{
public function is_enableable()
{
$config = $this->container->get('config');
// phpBB 3.2 is supported. phpBB 3.1 is not due to changes in TWIG.
return ( phpbb_version_compare($config['version'], '3.2.0', '>=') || (phpbb_version_compare($config['version'], '3.3', '<')) );
}
public function enable_step($old_state)
{
// Connect with some necessary services
$request = $this->container->get('request');
// Add language strings needed
switch ($old_state)
{
case '': // Empty means nothing has run yet
// Create the cache/phpbbservices/digests folder
umask(0);
$made_directories = false;
$digests_cache_path = './../cache/phpbbservices/digests/'; // Installer should be in the adm folder
$ptr = strpos($digests_cache_path, '/', 5);
while ($ptr !== false)
{
$current_path = substr($digests_cache_path, 0, $ptr);
$ptr = strpos($digests_cache_path, '/', $ptr + 1);
if (!is_dir($current_path))
{
@mkdir($current_path, 0777);
}
$made_directories = true;
}
if ($made_directories)
{
// For Apache-based systems, the digest cache directory requires a .htaccess file with Allow from All permissions so a browser can read files.
$server_software = $request->server('SERVER_SOFTWARE');
if (stristr($server_software, 'Apache'))
{
$handle = @fopen($digests_cache_path . '.htaccess', 'w');
$data = "<Files *>\n\tOrder Allow,Deny\n\tAllow from All\n</Files>\n";
@fwrite($handle, $data);
@fclose($handle);
}
}
return 'directories';
break;
default:
// Run parent enable step method
return parent::enable_step($old_state);
break;
}
}
public function disable_step($old_state)
{
switch ($old_state)
{
case '': // Empty means nothing has run yet
// Recursively delete the /cache/phpbbservices directory
$this->remove_directory('./../cache/phpbbservices');
return 'directories';
break;
default:
// Run parent disable step method
return parent::disable_step($old_state);
break;
}
}
private function remove_directory($path)
{
$files = glob(preg_replace('/(\*|\?|\[)/', '[$1]', $path).'/{,.}*', GLOB_BRACE); // Include .htaccess and hidden files
foreach ($files as $file)
{
if ($file == $path . '/.' || $file == $path . '/..')
{
continue; // skip special directories
}
is_dir($file) ? $this->remove_directory($file) : unlink($file);
}
rmdir($path);
return;
}
}