1: <?php
2:
3: 4: 5:
6: class Quform_Admin_Page_Controller
7: {
8: 9: 10: 11: 12:
13: protected $page;
14:
15: 16: 17:
18: protected $pageFactory;
19:
20: 21: 22:
23: public function __construct(Quform_Admin_Page_Factory $pageFactory)
24: {
25: $this->pageFactory = $pageFactory;
26: }
27:
28: 29: 30: 31: 32:
33: public function process($screen)
34: {
35: if ($this->isCorePage($screen->id)) {
36: $this->page = $this->pageFactory->create($this->screenIdToPageName($screen->id));
37: $this->page->bootstrap()->process();
38: }
39: }
40:
41: 42: 43:
44: public function enqueueAssets()
45: {
46: if ($this->page instanceof Quform_Admin_Page) {
47: $this->page->enqueueAssets();
48: }
49: }
50:
51: 52: 53: 54: 55: 56:
57: public function setAdminTitle($adminTitle)
58: {
59: if ($this->page instanceof Quform_Admin_Page) {
60: return $this->page->setAdminTitle($adminTitle);
61: }
62:
63: return $adminTitle;
64: }
65:
66: 67: 68: 69: 70: 71:
72: public function addBodyClass($classes)
73: {
74: if ($this->page instanceof Quform_Admin_Page) {
75: $classes .= sprintf(' %s', sanitize_title(get_class($this->page)));
76: }
77:
78: return $classes;
79: }
80:
81: 82: 83:
84: public function display()
85: {
86: echo $this->page->display();
87: }
88:
89: 90: 91:
92: public function createMenus()
93: {
94: add_menu_page(
95: __('Dashboard', 'quform'),
96: __('Forms', 'quform'),
97: 'quform_view_dashboard',
98: 'quform.dashboard',
99: array($this, 'display'),
100: $this->getMenuIcon(),
101: '30.249829482347'
102: );
103:
104: do_action('quform_admin_menu', 5);
105:
106: add_submenu_page(
107: 'quform.dashboard',
108: __('Dashboard', 'quform'),
109: __('Dashboard', 'quform'),
110: 'quform_view_dashboard',
111: 'quform.dashboard',
112: array($this, 'display')
113: );
114:
115: do_action('quform_admin_menu', 10);
116:
117: add_submenu_page(
118: 'quform.dashboard',
119: __('Forms', 'quform'),
120: __('Forms', 'quform'),
121: 'quform_list_forms',
122: 'quform.forms',
123: array($this, 'display')
124: );
125:
126: do_action('quform_admin_menu', 15);
127:
128: add_submenu_page(
129: 'quform.dashboard',
130: __('Add New Form', 'quform'),
131: __('Add New', 'quform'),
132: 'quform_add_forms',
133: 'quform.forms&sp=add',
134: array($this, 'display')
135: );
136:
137: do_action('quform_admin_menu', 20);
138:
139: add_submenu_page(
140: 'quform.dashboard',
141: __('Entries', 'quform'),
142: __('Entries', 'quform'),
143: 'quform_view_entries',
144: 'quform.entries',
145: array($this, 'display')
146: );
147:
148: do_action('quform_admin_menu', 25);
149:
150: add_submenu_page(
151: 'quform.dashboard',
152: __('Tools', 'quform'),
153: __('Tools', 'quform'),
154: 'quform_view_tools',
155: 'quform.tools',
156: array($this, 'display')
157: );
158:
159: do_action('quform_admin_menu', 30);
160:
161: add_submenu_page(
162: 'quform.dashboard',
163: __('Settings', 'quform'),
164: __('Settings', 'quform'),
165: 'quform_settings',
166: 'quform.settings',
167: array($this, 'display')
168: );
169:
170: do_action('quform_admin_menu', 35);
171:
172: add_submenu_page(
173: 'quform.dashboard',
174: __('Help', 'quform'),
175: __('Help', 'quform'),
176: 'quform_help',
177: 'quform.help',
178: array($this, 'display')
179: );
180:
181: do_action('quform_admin_menu', 40);
182:
183: add_submenu_page(
184: '',
185: __('Preview', 'quform'),
186: __('Preview', 'quform'),
187: 'quform_edit_forms',
188: 'quform.preview',
189: array($this, 'display')
190: );
191:
192: do_action('quform_admin_menu', 45);
193: }
194:
195: 196: 197: 198: 199:
200: public function addNewFormToAdminBar(WP_Admin_Bar $adminBar)
201: {
202: if (current_user_can('quform_add_forms')) {
203: $adminBar->add_node(array(
204: 'id' => 'quform-add-new-form',
205: 'title' => __('Form', 'quform'),
206: 'href' => admin_url('admin.php?page=quform.forms&sp=add'),
207: 'parent' => 'new-content'
208: ));
209: }
210: }
211:
212: 213: 214: 215: 216:
217: protected function getMenuIcon()
218: {
219: $color = '';
220:
221: if (in_array(Quform::get($_GET, 'page'), array('quform.dashboard', 'quform.forms', 'quform.entries', 'quform.tools', 'quform.settings', 'quform.help'))) {
222: $color = '#ffffff';
223: }
224:
225: $color = apply_filters('quform_admin_menu_icon_color', $color);
226:
227: return Quform::getPluginIcon($color);
228: }
229:
230: 231: 232: 233: 234: 235:
236: protected function screenIdToPageName($id)
237: {
238: $name = preg_replace('/^.+_page_quform\.(.+)$/', '$1', $id);
239:
240: return Quform::studlyCase($name);
241: }
242:
243: 244: 245: 246: 247: 248:
249: protected function isCorePage($id)
250: {
251: return (bool) preg_match('/_page_quform\.(dashboard|forms|entries|tools|settings|help|preview)$/', $id);
252: }
253:
254: 255: 256: 257: 258:
259: protected function getSubpage()
260: {
261: return Quform::get($_GET, 'sp');
262: }
263: }
264: