* @link https://www.fireplugins.com * @copyright Copyright © 2021 FirePlugins All Rights Reserved * @license GNU GPLv3 or later */ namespace FireBox\Core\FB; if (!defined('ABSPATH')) { exit; // Exit if accessed directly. } use FPFramework\Libs\Registry; class Assignments { /** * Box * * @var Box */ private $box; /** * Box Settings * * @var object */ private $boxSettings; /** * Factory * * @var object */ protected $factory; /** * Local assignments list * * @var array */ private $assignments = [ 'cookietype|local', ]; /** * Class Constructor * * @param object $item The object to be checked */ public function __construct($box, $factory = null) { if (!$box) { return; } $this->box = $box; $this->boxSettings = $this->box->getBoxSettings(); if (!$factory) { $factory = new \FPFramework\Base\Factory(); } $this->factory = $factory; } /** * Pass all checks * * @return boolean Returns true if all assignments pass */ public function passAll() { $pass = true; foreach ($this->assignments as $key => $assignment) { // Break if not passed if (!$pass) { break; } $assignmentData = explode('|', $assignment); $assignment = $assignmentData[0]; $type = isset($assignmentData[1]) ? $assignmentData[1] : ''; $method = 'pass' . $assignment; // Skip item if there is no assosiated method if (!method_exists($this, $method)) { continue; } $prefix = empty($type) ? 'assignments.' : ''; $assign = $prefix . 'assign_' . $assignment; // Skip item if assignment is missing if (!$this->boxSettings->params->exists($assign) && !$this->boxSettings->params->exists($assign . '_param_type')) { continue; } $pass = $this->$method(); } return $pass; } /** * Pass Check for Box Cookie * * @return bool */ private function passCookieType() { // Skip if assignment is disabled if ($this->boxSettings->params->get('assign_cookietype') == 'never') { return true; } // Skip if box is on Test Mode and a Super User is logged in if ($this->boxSettings->params->get('testmode') && is_user_logged_in() && current_user_can('manage_options')) { return true; } $cookie = $this->box->getCookie($this->boxSettings->ID); return !$cookie->exist(); } }