PluginProbe
User Access Manager / 2.2.18
User Access Manager v2.2.18
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
user-access-manager / src / Config / WordpressConfig.php

WordpressConfig.php in User Access Manager 2.2.18, at src/Config/WordpressConfig.php

143 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WordpressConfig.php
4 *
5 * The WordpressConfig class file.
6 *
7 * PHP versions 5
8 *
9 * @author Alexander Schneider <alexanderschneider85@gmail.com>
10 * @copyright 2008-2017 Alexander Schneider
11 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 * @version SVN: $id$
13 * @link http://wordpress.org/extend/plugins/user-access-manager/
14 */
15
16 declare(strict_types=1);
17
18 namespace UserAccessManager\Config;
19
20 use UserAccessManager\Wrapper\Wordpress;
21
22 /**
23 * Class WordpressConfig
24 *
25 * @package UserAccessManager\Config
26 */
27 class WordpressConfig
28 {
29 /**
30 * @var Wordpress
31 */
32 private $wordpress;
33
34 /**
35 * @var string
36 */
37 private $baseFile;
38
39 /**
40 * @var null|bool
41 */
42 private $isPermalinksActive = null;
43
44 /**
45 * @var null|array
46 */
47 private $mimeTypes = null;
48
49 /**
50 * WordpressClass constructor.
51 * @param Wordpress $wordpress
52 * @param string $baseFile
53 */
54 public function __construct(Wordpress $wordpress, string $baseFile)
55 {
56 $this->wordpress = $wordpress;
57 $this->baseFile = $baseFile;
58 }
59
60 /**
61 * Returns true if a user is at the admin panel.
62 * @return bool
63 */
64 public function atAdminPanel(): bool
65 {
66 return $this->wordpress->isAdmin();
67 }
68
69 /**
70 * Returns true if permalinks are active otherwise false.
71 * @return bool
72 */
73 public function isPermalinksActive(): ?bool
74 {
75 if ($this->isPermalinksActive === null) {
76 $permalinkStructure = $this->wordpress->getOption('permalink_structure');
77 $this->isPermalinksActive = (empty($permalinkStructure) === false);
78 }
79
80 return $this->isPermalinksActive;
81 }
82
83 /**
84 * Returns the upload directory.
85 * @return null|string
86 */
87 public function getUploadDirectory(): ?string
88 {
89 $wordpressUploadDir = $this->wordpress->getUploadDir();
90
91 if (empty($wordpressUploadDir['error'])) {
92 return $wordpressUploadDir['basedir'] . DIRECTORY_SEPARATOR;
93 }
94
95 return null;
96 }
97
98 /**
99 * Returns the full supported mine types.
100 * @return array
101 */
102 public function getMimeTypes(): ?array
103 {
104 if ($this->mimeTypes === null) {
105 $mimeTypes = $this->wordpress->getAllowedMimeTypes();
106 $fullMimeTypes = [];
107
108 foreach ($mimeTypes as $extensions => $mineType) {
109 $extensions = explode('|', $extensions);
110
111 foreach ($extensions as $extension) {
112 $fullMimeTypes[$extension] = $mineType;
113 }
114 }
115
116 $this->mimeTypes = $fullMimeTypes;
117 }
118
119 return $this->mimeTypes;
120 }
121
122 /**
123 * Returns the module url path.
124 * @return string
125 */
126 public function getUrlPath(): string
127 {
128 return $this->wordpress->pluginsUrl('', $this->baseFile) . '/';
129 }
130
131 /**
132 * Returns the module real path.
133 * @return string
134 */
135 public function getRealPath(): string
136 {
137 $dirName = dirname($this->baseFile);
138
139 return $this->wordpress->getPluginDir() . DIRECTORY_SEPARATOR
140 . $this->wordpress->pluginBasename($dirName) . DIRECTORY_SEPARATOR;
141 }
142 }
143