PluginProbe
ShiftController Employee Shift Scheduling / 4.9.26
ShiftController Employee Shift Scheduling v4.9.26
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.26, at shiftcontroller4.php

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