PluginProbe
User Access Manager / 2.1.4
User Access Manager v2.1.4
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.4, at src/Controller/Controller.php

152 lines 3.4 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 Wordpress
37 */
38 protected $wordpress;
39
40 /**
41 * @var string
42 */
43 protected $updateMessage = null;
44
45 /**
46 * Controller constructor.
47 *
48 * @param Php $php
49 * @param Wordpress $wordpress
50 * @param WordpressConfig $wordpressConfig
51 */
52 public function __construct(Php $php, Wordpress $wordpress, WordpressConfig $wordpressConfig)
53 {
54 $this->php = $php;
55 $this->wordpress = $wordpress;
56 $this->wordpressConfig = $wordpressConfig;
57 }
58
59 /**
60 * Returns the nonce field.
61 *
62 * @param string $name
63 *
64 * @return string
65 */
66 public function createNonceField($name)
67 {
68 return $this->wordpress->getNonceField($name, $name.'Nonce');
69 }
70
71 /**
72 * Returns the nonce.
73 *
74 * @param string $name
75 *
76 * @return string
77 */
78 public function getNonce($name)
79 {
80 return $this->wordpress->createNonce($name);
81 }
82
83 /**
84 * Verifies the nonce and terminates the application if the nonce is wrong.
85 *
86 * @param string $name
87 */
88 protected function verifyNonce($name)
89 {
90 $nonce = $this->getRequestParameter($name.'Nonce');
91
92 if ($this->wordpress->verifyNonce($nonce, $name) === false) {
93 $this->wordpress->wpDie(TXT_UAM_NONCE_FAILURE_MESSAGE, TXT_UAM_NONCE_FAILURE_TITLE, ['response' => 401]);
94 }
95 }
96
97 /**
98 * Sets the update message.
99 *
100 * @param string $message
101 */
102 protected function setUpdateMessage($message)
103 {
104 $this->updateMessage = $message;
105 }
106
107 /**
108 * Returns the update message.
109 *
110 * @return string
111 */
112 public function getUpdateMessage()
113 {
114 return $this->updateMessage;
115 }
116
117 /**
118 * Returns true if a update message is set.
119 *
120 * @return bool
121 */
122 public function hasUpdateMessage()
123 {
124 return $this->updateMessage !== null;
125 }
126
127 /**
128 * Process the action.
129 */
130 protected function processAction()
131 {
132 $postAction = $this->getRequestParameter(self::ACTION_PARAMETER);
133 $postActionSplit = explode('_', $postAction);
134 $postAction = array_shift($postActionSplit);
135 $postAction .= implode('', array_map('ucfirst', $postActionSplit));
136 $actionMethod = $postAction.self::ACTION_SUFFIX;
137
138 if (method_exists($this, $actionMethod) === true) {
139 $this->{$actionMethod}();
140 }
141 }
142
143 /**
144 * Renders the given template
145 */
146 public function render()
147 {
148 $this->processAction();
149 $this->traitRender();
150 }
151 }
152