PluginProbe
User Access Manager / 2.1.5
User Access Manager v2.1.5
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.1.5, at src/Config/WordpressConfig.php

147 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 namespace UserAccessManager\Config;
16
17 use UserAccessManager\Wrapper\Wordpress;
18
19 /**
20 * Class WordpressConfig
21 *
22 * @package UserAccessManager\Config
23 */
24 class WordpressConfig
25 {
26 /**
27 * @var Wordpress
28 */
29 private $wordpress;
30
31 /**
32 * @var string
33 */
34 private $baseFile;
35
36 /**
37 * @var null|bool
38 */
39 private $isPermalinksActive = null;
40
41 /**
42 * @var null|array
43 */
44 private $mimeTypes = null;
45
46 /**
47 * WordpressClass constructor.
48 *
49 * @param Wordpress $wordpress
50 * @param string $baseFile
51 */
52 public function __construct(Wordpress $wordpress, $baseFile)
53 {
54 $this->wordpress = $wordpress;
55 $this->baseFile = $baseFile;
56 }
57
58 /**
59 * Returns true if a user is at the admin panel.
60 *
61 * @return bool
62 */
63 public function atAdminPanel()
64 {
65 return $this->wordpress->isAdmin();
66 }
67
68 /**
69 * Returns true if permalinks are active otherwise false.
70 *
71 * @return bool
72 */
73 public function isPermalinksActive()
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 *
86 * @return null|string
87 */
88 public function getUploadDirectory()
89 {
90 $wordpressUploadDir = $this->wordpress->getUploadDir();
91
92 if (empty($wordpressUploadDir['error'])) {
93 return $wordpressUploadDir['basedir'].DIRECTORY_SEPARATOR;
94 }
95
96 return null;
97 }
98
99 /**
100 * Returns the full supported mine types.
101 *
102 * @return array
103 */
104 public function getMimeTypes()
105 {
106 if ($this->mimeTypes === null) {
107 $mimeTypes = $this->wordpress->getAllowedMimeTypes();
108 $fullMimeTypes = [];
109
110 foreach ($mimeTypes as $extensions => $mineType) {
111 $extensions = explode('|', $extensions);
112
113 foreach ($extensions as $extension) {
114 $fullMimeTypes[$extension] = $mineType;
115 }
116 }
117
118 $this->mimeTypes = $fullMimeTypes;
119 }
120
121 return $this->mimeTypes;
122 }
123
124 /**
125 * Returns the module url path.
126 *
127 * @return string
128 */
129 public function getUrlPath()
130 {
131 return $this->wordpress->pluginsUrl('', $this->baseFile).'/';
132 }
133
134 /**
135 * Returns the module real path.
136 *
137 * @return string
138 */
139 public function getRealPath()
140 {
141 $dirName = dirname($this->baseFile);
142
143 return $this->wordpress->getPluginDir().DIRECTORY_SEPARATOR
144 .$this->wordpress->pluginBasename($dirName).DIRECTORY_SEPARATOR;
145 }
146 }
147