PluginProbe
User Access Manager / 2.1.0
User Access Manager v2.1.0
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 / Controller / Controller.php

Controller.php in User Access Manager 2.1.0, at src/Controller/Controller.php

162 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Controller.php
4 *
5 * The Controller 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\Controller;
16
17 use UserAccessManager\Config\WordpressConfig;
18 use UserAccessManager\Wrapper\Php;
19 use UserAccessManager\Wrapper\Wordpress;
20
21 /**
22 * Class Controller
23 *
24 * @package UserAccessManager\Controller
25 */
26 abstract class Controller
27 {
28 use BaseControllerTrait {
29 render as traitRender;
30 }
31
32 const ACTION_PARAMETER = 'uam_action';
33 const ACTION_SUFFIX = 'Action';
34
35 /**
36 * @var Php
37 */
38 protected $php;
39
40 /**
41 * @var Wordpress
42 */
43 protected $wordpress;
44
45 /**
46 * @var WordpressConfig
47 */
48 protected $wordpressConfig;
49
50 /**
51 * @var string
52 */
53 protected $updateMessage = null;
54
55 /**
56 * Controller constructor.
57 *
58 * @param Php $php
59 * @param Wordpress $wordpress
60 * @param WordpressConfig $wordpressConfig
61 */
62 public function __construct(Php $php, Wordpress $wordpress, WordpressConfig $wordpressConfig)
63 {
64 $this->php = $php;
65 $this->wordpress = $wordpress;
66 $this->wordpressConfig = $wordpressConfig;
67 }
68
69 /**
70 * Returns the nonce field.
71 *
72 * @param string $name
73 *
74 * @return string
75 */
76 public function createNonceField($name)
77 {
78 return $this->wordpress->getNonceField($name, $name.'Nonce');
79 }
80
81 /**
82 * Returns the nonce.
83 *
84 * @param string $name
85 *
86 * @return string
87 */
88 public function getNonce($name)
89 {
90 return $this->wordpress->createNonce($name);
91 }
92
93 /**
94 * Verifies the nonce and terminates the application if the nonce is wrong.
95 *
96 * @param string $name
97 */
98 protected function verifyNonce($name)
99 {
100 $nonce = $this->getRequestParameter($name.'Nonce');
101
102 if ($this->wordpress->verifyNonce($nonce, $name) === false) {
103 $this->wordpress->wpDie(TXT_UAM_NONCE_FAILURE_MESSAGE, TXT_UAM_NONCE_FAILURE_TITLE, ['response' => 401]);
104 }
105 }
106
107 /**
108 * Sets the update message.
109 *
110 * @param string $message
111 */
112 protected function setUpdateMessage($message)
113 {
114 $this->updateMessage = $message;
115 }
116
117 /**
118 * Returns the update message.
119 *
120 * @return string
121 */
122 public function getUpdateMessage()
123 {
124 return $this->updateMessage;
125 }
126
127 /**
128 * Returns true if a update message is set.
129 *
130 * @return bool
131 */
132 public function hasUpdateMessage()
133 {
134 return $this->updateMessage !== null;
135 }
136
137 /**
138 * Process the action.
139 */
140 protected function processAction()
141 {
142 $postAction = $this->getRequestParameter(self::ACTION_PARAMETER);
143 $postActionSplit = explode('_', $postAction);
144 $postAction = array_shift($postActionSplit);
145 $postAction .= implode('', array_map('ucfirst', $postActionSplit));
146 $actionMethod = $postAction.self::ACTION_SUFFIX;
147
148 if (method_exists($this, $actionMethod) === true) {
149 $this->{$actionMethod}();
150 }
151 }
152
153 /**
154 * Renders the given template
155 */
156 public function render()
157 {
158 $this->processAction();
159 $this->traitRender();
160 }
161 }
162