| 1 |
<?php |
| 2 |
/* |
| 3 |
* Plugin Name: ShiftController |
| 4 |
* Plugin URI: https://www.shiftcontroller.com/ |
| 5 |
* Description: Staff scheduling plugin |
| 6 |
* Version: 4.9.92 |
| 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', 4992 ); |
| 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 |
public function getOurShortcodeAtts() |
| 94 |
{ |
| 95 |
$ret = false; |
| 96 |
|
| 97 |
$currentUrl = $_SERVER['REQUEST_URI']; |
| 98 |
$currentPageId = url_to_postid( $currentUrl ); |
| 99 |
if( $currentPageId ){ |
| 100 |
$shortcode = 'shiftcontroller4'; |
| 101 |
$pages = HC3_Functions::wpGetIdByShortcode( $shortcode ); |
| 102 |
if( isset($pages[$currentPageId]) ){ |
| 103 |
$ret = $pages[ $currentPageId ]; |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
return $ret; |
| 108 |
} |
| 109 |
|
| 110 |
// intercepts if in the front page our slug is given then it's ours |
| 111 |
public function intercept() |
| 112 |
{ |
| 113 |
$shortcodeAtts = null; |
| 114 |
|
| 115 |
// compatibility with WooCommerce Availability Scheduler 12.4 |
| 116 |
global $was_post_remover; |
| 117 |
if( $was_post_remover ){ |
| 118 |
$shortcodeAtts = $this->getOurShortcodeAtts(); |
| 119 |
if( false !== $shortcodeAtts ){ |
| 120 |
remove_action( 'posts_request', array($was_post_remover,'AS_check_if_unhide_products_and_update_cart') ); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
if( ! $this->isIntercepted() ){ |
| 125 |
return; |
| 126 |
} |
| 127 |
|
| 128 |
// it it points to a page with our shortcode then init request with shortcode atts |
| 129 |
$route = ''; |
| 130 |
if( null === $shortcodeAtts ){ |
| 131 |
$shortcodeAtts = $this->getOurShortcodeAtts(); |
| 132 |
if( false !== $shortcodeAtts ){ |
| 133 |
$route = $this->initRequestByAtts( $shortcodeAtts ); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
if( is_admin() ){ |
| 138 |
$actionUrl = get_admin_url() . 'admin.php?page=' . $this->slug; |
| 139 |
$uriAction = $this->dic->make('HC3_UriAction'); |
| 140 |
$uriAction->fromUrl( $actionUrl ); |
| 141 |
} |
| 142 |
|
| 143 |
// HC3_Session::instance(); |
| 144 |
|
| 145 |
$this->actionResult = $this->handleRequest( $route ); |
| 146 |
echo $this->render(); |
| 147 |
exit; |
| 148 |
} |
| 149 |
|
| 150 |
public function startFrontSession() |
| 151 |
{ |
| 152 |
if( is_admin() ) return; |
| 153 |
|
| 154 |
$shortcode = 'shiftcontroller4'; |
| 155 |
$pages = HC3_Functions::wpGetIdByShortcode( $shortcode ); |
| 156 |
if( ! $pages ) return; |
| 157 |
|
| 158 |
$currentPageId = get_queried_object_id(); |
| 159 |
if( ! isset($pages[$currentPageId]) ) return; |
| 160 |
|
| 161 |
HC3_Session::instance(); |
| 162 |
} |
| 163 |
|
| 164 |
public function addRoles() |
| 165 |
{ |
| 166 |
$adminRole = 'sh4_admin'; |
| 167 |
$r = get_role( $adminRole ); |
| 168 |
if( $r ){ |
| 169 |
return; |
| 170 |
} |
| 171 |
|
| 172 |
add_role( |
| 173 |
$adminRole, |
| 174 |
'ShiftController Administrator', |
| 175 |
array( |
| 176 |
'read' => TRUE, |
| 177 |
) |
| 178 |
); |
| 179 |
|
| 180 |
$capabilities = array( |
| 181 |
'manage_sh4', |
| 182 |
); |
| 183 |
|
| 184 |
global $wp_roles; |
| 185 |
foreach( $capabilities as $cap ){ |
| 186 |
$wp_roles->add_cap( $adminRole, $cap ); |
| 187 |
$wp_roles->add_cap( 'editor', $cap ); |
| 188 |
$wp_roles->add_cap( 'administrator', $cap ); |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
public function initRequestByAtts( $atts ) |
| 193 |
{ |
| 194 |
$route = 'schedule'; |
| 195 |
|
| 196 |
$root = $this->root(); |
| 197 |
$request = $root->make('HC3_Request'); |
| 198 |
$slug = $request->getSlug(); |
| 199 |
|
| 200 |
// $processParams = array( 'type', 'groupby', 'start', 'end', 'time', 'pickup', 'conflict' ); |
| 201 |
// if( $slug != 'myschedule' ){ |
| 202 |
// $processParams = array_merge( $processParams, array('calendar', 'employee', 'hideui') ); |
| 203 |
// } |
| 204 |
$processParams = array( 'type', 'groupby', 'start', 'end', 'time', 'pickup', 'conflict', 'hideui', 't1', 't2' ); |
| 205 |
if( $slug != 'myschedule' ){ |
| 206 |
$processParams = array_merge( $processParams, array('calendar', 'employee') ); |
| 207 |
} |
| 208 |
$arrayFor = array( 'calendar', 'employee', 'hideui' ); |
| 209 |
|
| 210 |
$allowedRoutes = array('schedule', 'myschedule'); |
| 211 |
|
| 212 |
foreach( $atts as $k => $v ){ |
| 213 |
if( $k == 'route' ){ |
| 214 |
if( in_array($v, $allowedRoutes) ){ |
| 215 |
$route = $v; |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
if( ! in_array($k, $processParams) ){ |
| 220 |
continue; |
| 221 |
} |
| 222 |
|
| 223 |
if( in_array($k, $arrayFor) ){ |
| 224 |
if( strpos($v, ',') ){ |
| 225 |
$v = explode(',', $v); |
| 226 |
for( $ii = 0; $ii < count($v); $ii++ ){ |
| 227 |
$v[$ii] = trim( $v[$ii] ); |
| 228 |
} |
| 229 |
} |
| 230 |
else { |
| 231 |
$v = array($v); |
| 232 |
} |
| 233 |
} |
| 234 |
$request->initParam( $k, $v ); |
| 235 |
} |
| 236 |
|
| 237 |
if( ('myschedule' == $route) && ('schedule' == $slug) ){ |
| 238 |
$request->setSlug('myschedule'); |
| 239 |
} |
| 240 |
|
| 241 |
return $route; |
| 242 |
} |
| 243 |
|
| 244 |
public function shortcode( $shortcodeAtts ) |
| 245 |
{ |
| 246 |
if( is_admin() OR hc_is_rest() ){ |
| 247 |
$return = 'ShiftController shortcode is rendered in front end only.'; |
| 248 |
return $return; |
| 249 |
} |
| 250 |
|
| 251 |
$route = 'schedule'; |
| 252 |
|
| 253 |
if( $shortcodeAtts && is_array($shortcodeAtts) ){ |
| 254 |
$route = $this->initRequestByAtts( $shortcodeAtts ); |
| 255 |
} |
| 256 |
|
| 257 |
$this->actionResult = $this->handleRequest( $route ); |
| 258 |
|
| 259 |
ob_start(); |
| 260 |
echo $this->render(); |
| 261 |
$return = ob_get_contents(); |
| 262 |
ob_end_clean(); |
| 263 |
return $return; |
| 264 |
} |
| 265 |
|
| 266 |
public function handleRequest( $defaultSlug = '' ) |
| 267 |
{ |
| 268 |
if( ! $defaultSlug ){ |
| 269 |
$defaultSlug = 'schedule'; |
| 270 |
} |
| 271 |
|
| 272 |
$return = parent::handleRequest( $defaultSlug ); |
| 273 |
|
| 274 |
$root = $this->root(); |
| 275 |
$enqueuer = $root->make('HC3_Enqueuer'); |
| 276 |
$enqueuer |
| 277 |
->addScript('sh4', 'sh4/app/assets/js/sh4.js') |
| 278 |
; |
| 279 |
|
| 280 |
return $return; |
| 281 |
} |
| 282 |
} |
| 283 |
|
| 284 |
$hcsh4 = new ShiftController4(); |
| 285 |
|
| 286 |
if (!function_exists('hc_is_rest')) { |
| 287 |
/** |
| 288 |
* Checks if the current request is a WP REST API request. |
| 289 |
* |
| 290 |
* Case #1: After WP_REST_Request initialisation |
| 291 |
* Case #2: Support "plain" permalink settings |
| 292 |
* Case #3: URL Path begins with wp-json/ (your REST prefix) |
| 293 |
* Also supports WP installations in subfolders |
| 294 |
* |
| 295 |
* @returns boolean |
| 296 |
* @author matzeeable |
| 297 |
*/ |
| 298 |
function hc_is_rest() { |
| 299 |
$prefix = rest_get_url_prefix( ); |
| 300 |
if (defined('REST_REQUEST') && REST_REQUEST // (#1) |
| 301 |
|| isset($_GET['rest_route']) // (#2) |
| 302 |
&& strpos( trim( $_GET['rest_route'], '\\/' ), $prefix , 0 ) === 0) |
| 303 |
return true; |
| 304 |
|
| 305 |
// (#3) |
| 306 |
$rest_url = wp_parse_url( site_url( $prefix ) ); |
| 307 |
$current_url = wp_parse_url( add_query_arg( array( ) ) ); |
| 308 |
return strpos( $current_url['path'], $rest_url['path'], 0 ) === 0; |
| 309 |
} |
| 310 |
} |