PluginProbe
ShiftController Employee Shift Scheduling / 4.9.97
ShiftController Employee Shift Scheduling v4.9.97
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / shiftcontroller4.php

shiftcontroller4.php in ShiftController Employee Shift Scheduling 4.9.97, at shiftcontroller4.php

313 lines 7.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugin Name: ShiftController
4 * Plugin URI: https://www.shiftcontroller.com/
5 * Description: Staff scheduling plugin
6 * Version: 4.9.97
7 * Author: plainware.com
8 * Author URI: https://www.shiftcontroller.com/
9 * Text Domain: shiftcontroller
10 * Domain Path: /languages/
11 */
12
13 if (!defined('SH4_VERSION')) {
14 define( 'SH4_VERSION', 4997 );
15 }
16
17 if (! defined('ABSPATH')) exit; // Exit if accessed directly
18
19 if ( version_compare( PHP_VERSION, '5.3', '<' ) ) {
20 add_action( 'admin_notices',
21 create_function( '',
22 "echo '<div class=\"error\"><p>" .
23 __('ShiftController requires PHP 5.3 to function properly. Please upgrade PHP or deactivate ShiftController.', 'shiftcontroller') ."</p></div>';"
24 )
25 );
26 return;
27 }
28
29 if( file_exists(dirname(__FILE__) . '/config.php') ){
30 $conf = include( dirname(__FILE__) . '/config.php' );
31 }
32
33 $hc3path = defined('HC3_DEV_INSTALL') ? HC3_DEV_INSTALL : dirname(__FILE__) . '/hc3';
34 $hc3path = dirname(__FILE__) . '/hc3';
35 include_once( $hc3path . '/_wordpress/abstract/plugin.php' );
36
37 class ShiftController4 extends HC3_Abstract_Plugin
38 {
39 public function __construct()
40 {
41 // $this->slug = 'shiftcontroller';
42 $this->translate = 'shiftcontroller';
43 $this->slug = 'shiftcontroller4';
44 $this->label = 'Shift Controller';
45 $this->prfx = 'sh4';
46 $this->menuIcon = 'dashicons-calendar';
47 // $this->requireCap = 'manage_options';
48
49 $this->modules = array(
50 'conf',
51 'schedule',
52 'employees',
53 'calendars',
54 'shifttypes',
55 'shifts',
56 'conflicts',
57 'new',
58 'users',
59 'notifications',
60 'ical',
61 'feed',
62 'app',
63 // 'upgrade3',
64 'platform',
65 'api',
66 'reminders',
67 'promo',
68
69 // 'repeat',
70 // 'bulk'
71 // 'pickup'
72 );
73
74 if( defined('HC3_DEV_INSTALL') ){
75 $this->modules[] = 'demo';
76 }
77
78 parent::__construct( __FILE__ );
79
80 add_action( 'init', array($this, 'addRoles') );
81 add_shortcode( 'shiftcontroller4', array($this, 'shortcode') );
82 add_action( 'template_redirect', array($this, 'startFrontSession') );
83 }
84
85 public function adminInit()
86 {
87 if( is_admin() ){
88 $actionUrl = get_admin_url() . 'admin.php?page=' . $this->slug;
89 $uriAction = $this->dic->make('HC3_UriAction');
90 $uriAction->fromUrl( $actionUrl );
91 }
92
93 parent::adminInit();
94 }
95
96 public function getOurShortcodeAtts()
97 {
98 $ret = false;
99
100 $currentUrl = $_SERVER['REQUEST_URI'];
101 $currentPageId = url_to_postid( $currentUrl );
102 if( $currentPageId ){
103 $shortcode = 'shiftcontroller4';
104 $pages = HC3_Functions::wpGetIdByShortcode( $shortcode );
105 if( isset($pages[$currentPageId]) ){
106 $ret = $pages[ $currentPageId ];
107 }
108 }
109
110 return $ret;
111 }
112
113 // intercepts if in the front page our slug is given then it's ours
114 public function intercept()
115 {
116 $shortcodeAtts = null;
117
118 // compatibility with WooCommerce Availability Scheduler 12.4
119 global $was_post_remover;
120 if( $was_post_remover ){
121 $shortcodeAtts = $this->getOurShortcodeAtts();
122 if( false !== $shortcodeAtts ){
123 remove_action( 'posts_request', array($was_post_remover,'AS_check_if_unhide_products_and_update_cart') );
124 }
125 }
126
127 if( ! $this->isIntercepted() ){
128 return;
129 }
130
131 // it it points to a page with our shortcode then init request with shortcode atts
132 $route = '';
133 if( null === $shortcodeAtts ){
134 $shortcodeAtts = $this->getOurShortcodeAtts();
135 if( false !== $shortcodeAtts ){
136 $route = $this->initRequestByAtts( $shortcodeAtts );
137 }
138 }
139
140 if( is_admin() ){
141 $actionUrl = get_admin_url() . 'admin.php?page=' . $this->slug;
142 $uriAction = $this->dic->make('HC3_UriAction');
143 $uriAction->fromUrl( $actionUrl );
144 }
145
146 // HC3_Session::instance();
147
148 $this->actionResult = $this->handleRequest( $route );
149 echo $this->render();
150 exit;
151 }
152
153 public function startFrontSession()
154 {
155 if( is_admin() ) return;
156
157 $shortcode = 'shiftcontroller4';
158 $pages = HC3_Functions::wpGetIdByShortcode( $shortcode );
159 if( ! $pages ) return;
160
161 $currentPageId = get_queried_object_id();
162 if( ! isset($pages[$currentPageId]) ) return;
163
164 HC3_Session::instance();
165 }
166
167 public function addRoles()
168 {
169 $adminRole = 'sh4_admin';
170 $r = get_role( $adminRole );
171 if( $r ){
172 return;
173 }
174
175 add_role(
176 $adminRole,
177 'ShiftController Administrator',
178 array(
179 'read' => TRUE,
180 )
181 );
182
183 $capabilities = array(
184 'manage_sh4',
185 );
186
187 global $wp_roles;
188 foreach( $capabilities as $cap ){
189 $wp_roles->add_cap( $adminRole, $cap );
190 $wp_roles->add_cap( 'editor', $cap );
191 $wp_roles->add_cap( 'administrator', $cap );
192 }
193 }
194
195 public function initRequestByAtts( $atts )
196 {
197 $route = 'schedule';
198
199 $root = $this->root();
200 $request = $root->make('HC3_Request');
201 $slug = $request->getSlug();
202
203 // $processParams = array( 'type', 'groupby', 'start', 'end', 'time', 'pickup', 'conflict' );
204 // if( $slug != 'myschedule' ){
205 // $processParams = array_merge( $processParams, array('calendar', 'employee', 'hideui') );
206 // }
207 $processParams = array( 'type', 'groupby', 'start', 'end', 'time', 'pickup', 'conflict', 'hideui', 't1', 't2' );
208 if( $slug != 'myschedule' ){
209 $processParams = array_merge( $processParams, array('calendar', 'employee') );
210 }
211 $arrayFor = array( 'calendar', 'employee', 'hideui' );
212
213 $allowedRoutes = array('schedule', 'myschedule');
214
215 foreach( $atts as $k => $v ){
216 if( $k == 'route' ){
217 if( in_array($v, $allowedRoutes) ){
218 $route = $v;
219 }
220 }
221
222 if( ! in_array($k, $processParams) ){
223 continue;
224 }
225
226 if( in_array($k, $arrayFor) ){
227 if( strpos($v, ',') ){
228 $v = explode(',', $v);
229 for( $ii = 0; $ii < count($v); $ii++ ){
230 $v[$ii] = trim( $v[$ii] );
231 }
232 }
233 else {
234 $v = array($v);
235 }
236 }
237 $request->initParam( $k, $v );
238 }
239
240 if( ('myschedule' == $route) && ('schedule' == $slug) ){
241 $request->setSlug('myschedule');
242 }
243
244 return $route;
245 }
246
247 public function shortcode( $shortcodeAtts )
248 {
249 if( is_admin() OR hc_is_rest() ){
250 $return = 'ShiftController shortcode is rendered in front end only.';
251 return $return;
252 }
253
254 $route = 'schedule';
255
256 if( $shortcodeAtts && is_array($shortcodeAtts) ){
257 $route = $this->initRequestByAtts( $shortcodeAtts );
258 }
259
260 $this->actionResult = $this->handleRequest( $route );
261
262 ob_start();
263 echo $this->render();
264 $return = ob_get_contents();
265 ob_end_clean();
266 return $return;
267 }
268
269 public function handleRequest( $defaultSlug = '' )
270 {
271 if( ! $defaultSlug ){
272 $defaultSlug = 'schedule';
273 }
274
275 $return = parent::handleRequest( $defaultSlug );
276
277 $root = $this->root();
278 $enqueuer = $root->make('HC3_Enqueuer');
279 $enqueuer
280 ->addScript('sh4', 'sh4/app/assets/js/sh4.js')
281 ;
282
283 return $return;
284 }
285 }
286
287 $hcsh4 = new ShiftController4();
288
289 if (!function_exists('hc_is_rest')) {
290 /**
291 * Checks if the current request is a WP REST API request.
292 *
293 * Case #1: After WP_REST_Request initialisation
294 * Case #2: Support "plain" permalink settings
295 * Case #3: URL Path begins with wp-json/ (your REST prefix)
296 * Also supports WP installations in subfolders
297 *
298 * @returns boolean
299 * @author matzeeable
300 */
301 function hc_is_rest() {
302 $prefix = rest_get_url_prefix( );
303 if (defined('REST_REQUEST') && REST_REQUEST // (#1)
304 || isset($_GET['rest_route']) // (#2)
305 && strpos( trim( $_GET['rest_route'], '\\/' ), $prefix , 0 ) === 0)
306 return true;
307
308 // (#3)
309 $rest_url = wp_parse_url( site_url( $prefix ) );
310 $current_url = wp_parse_url( add_query_arg( array( ) ) );
311 return strpos( $current_url['path'], $rest_url['path'], 0 ) === 0;
312 }
313 }