/** * Creat an authentication object * * @param Request $request * @return Scheme */ public function getAuthenticationObject(Request $request) { $registry = Registry::getInstance(); // if the authentication_source is set in the request, then it takes precedence $override = $request->getParam("authentication_source"); if ($override == null) { // otherwise, see if one has been set in session from a previous login $session_auth = $request->getSessionData("auth"); if ($session_auth != "") { $override = $session_auth; } } // make sure it's in our list, or if blank still, we get the default $name = $registry->getAuthenticationSource($override); // sanitize $name = preg_replace('/\\W/', '', $name); // main class $class_name = 'Application\\Model\\Authentication' . '\\' . ucfirst($name); // local custom version $local_class_name = 'Local\\Authentication' . '\\' . ucfirst($name); if (class_exists($local_class_name)) { $class_name = $local_class_name; } // make it $authentication = new $class_name($request); if (!$authentication instanceof Scheme) { throw new \Exception("class '{$class_name}' for the '{$name}' authentication scheme must extend Scheme"); } return $authentication; }
/** * Parameters to construct the url on the search redirect * * @return array */ public function searchRedirectParams() { $params['controller'] = $this->request->getParam('controller'); $params['action'] = "results"; $params['sort'] = $this->request->getParam('sort'); return $params; }
/** * Transform XML to HTML * * @param mixed $xml XML-like data * @param string $path_to_xsl * @param array $params */ protected function transform($xml, $path_to_xsl, $format, array $params = array()) { $import_array = array(); // the xsl lives here $distro_xsl_dir = $this->_view_dir; $local_xsl_dir = realpath(getcwd()) . "/views/"; // language // english file is included by default (as a fallback) array_push($import_array, "labels/eng.xsl"); $language = $this->request->getParam("lang"); $registry = Registry::getInstance(); if ($language == "") { $language = $registry->defaultLanguage(); } // if language is set to something other than english // then include that file to override the english labels if ($language != "eng" && $language != '') { array_push($import_array, "labels/{$language}.xsl"); } // make sure we've got a reference to the local includes too array_push($import_array, "includes.xsl"); // transform $xsl = new Xsl($distro_xsl_dir, $local_xsl_dir); return $xsl->transformToXml($xml, $path_to_xsl, $format, $params, $import_array); }
/** * Get the User performing this search * * @return Xerxes\Utility\User */ public function getUser() { if ($this->request instanceof Request) { return $this->request->getUser(); } else { return new User(); } }
/** * Redirect to a new URL * * @param array|string $location location to redirect to */ protected function redirectTo($location) { $url = $location; if (is_array($location)) { $url = $this->request->url_for($location, true); } return new RedirectResponse($url); }
/** * @return Labels */ public function getLabels() { if (!$this->labels instanceof Labels) { $path = $this->getBootstrap()->getApplicationDir(); $this->labels = new Labels($path); // @todo need a proper language grabber // $lang = $this->registry->defaultLanguage(); $lang = $this->request->getParam("lang"); $this->labels->setLanguage($lang); } return $this->labels; }
/** * Add links for Category, Database, and Librarian * * @param mixed $object array|Category|Database * @param bool $deep whether to go deep if a Category is supplied */ public function injectDataLinks($object, $deep = true) { if ($object == null) { return null; } // array if (is_array($object) || $object instanceof \ArrayIterator) { foreach ($object as $item) { $this->injectDataLinks($item, $deep); } return null; } // not an object and not an array, so what is it? if (!is_object($object)) { throw new \DomainException('Param must be of type array, Category or Database'); } // Database if ($object instanceof Database) { // record url $params = array('controller' => $this->request->getParam('controller'), 'action' => 'database', 'id' => $object->getId()); $object->url = $this->request->url_for($params, true); // proxy url $params['action'] = 'proxy'; $object->url_proxy = $this->request->url_for($params, true); } elseif ($object instanceof Category) { // category link $params = array('controller' => 'databases', 'action' => 'subject', 'subject' => $object->getNormalized()); $object->url = $this->request->url_for($params, true); // embed link $params = array('controller' => 'embed', 'action' => 'gen-subject', 'subject' => $object->getNormalized()); $object->url_embed = $this->request->url_for($params, true); // embed link $params = array('controller' => 'embed', 'action' => 'gen-subject', 'subject' => $object->getNormalized()); $object->url_embed = $this->request->url_for($params); // only continue if we are going deep if ($deep == true) { // Librarian foreach ($object->getLibrarians() as $librarian) { $params = array('controller' => 'databases', 'action' => 'librarian', 'id' => $librarian->getId()); } // Databases foreach ($object->getSubcategories() as $subcategory) { foreach ($subcategory->getDatabases() as $database_sequence) { $this->injectDataLinks($database_sequence->getDatabase(), $deep); } } } } }
/** * Generate a random username * * Used for local and guest users * * @param string $prefix local or guest * @return string */ public static function genRandomUsername($prefix) { $string = ""; // take value from session id if (self::$request instanceof Request) { $session_id = self::$request->getSession()->getId(); if ($session_id != "") { $string = $session_id; } } else { $length = 10; $characters = '0123456789abcdefghijklmnopqrstuvwxyz'; $string = ""; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters) - 1)]; } } return $prefix . '@' . $string; }
/** * Redirect user to login page */ public function redirectToLogin() { $params = array('controller' => 'authenticate', 'action' => 'login', 'return' => $this->request->getRequestUri()); return $this->redirectTo($params); }