/** * Check if the plugin can render for the provided browser * * @return boolean */ protected function canRender() { $browser = new \Hubzero\Browser\Detector(); if ($allowed = trim($this->params->get('browsers'))) { $browsers = array(); $allowed = str_replace("\r", '', $allowed); $allowed = str_replace('\\n', "\n", $allowed); $allowed = explode("\n", $allowed); foreach ($allowed as $allow) { $allow = trim($allow); if (preg_match('/(.+?),\\s+([^\\s]+)\\s+(\\d+)\\.(\\d+)/i', $allow, $matches)) { $req = new stdClass(); $req->name = strtolower(trim($matches[2])); $req->major = intval($matches[3]); $req->minor = intval($matches[4]); $req->os = strtolower(trim($matches[1])); $browsers[] = $req; } } $matched = false; foreach ($browsers as $minimum) { if ($minimum->os != '*' && $minimum->os != strtolower($browser->platform())) { continue; } if ($minimum->name != strtolower($browser->name())) { continue; } // If we get to here, we have a matching OS and browser if ($minimum->major > $browser->major()) { return false; } if ($minimum->major == $browser->major() && $minimum->minor > $browser->minor()) { return false; } $matched = true; } if (!$matched) { return false; } } if ($regexes = trim($this->params->get('regexes'))) { $regexes = str_replace("\r", '', $regexes); $regexes = str_replace('\\n', "\n", $regexes); $regexes = explode("\n", $regexes); foreach ($regexes as $disallow) { $disallow = trim($disallow); if (preg_match("/{$disallow}/i", $browser->agent(), $matches)) { return false; } } } return true; }