/** * Constructor */ public function __construct() { $this->cache = new Cache(); // application config $this->registry = Registry::getInstance(); // local config $this->config = $this->getConfig(); // cache results based on local config or registry, default true $this->should_cache_results = $this->config->getConfig('CACHE_RESULTS', false, $this->registry->getConfig('CACHE_RESULTS', false, true)); }
/** * Check spelling * * @param QueryTerms[] $query_terms */ public function checkSpelling(array $query_terms) { $registry = Registry::getInstance(); $app_id = $registry->getConfig('BING_ID', true); $suggestion = new Suggestion(); $client = Factory::getHttpClient(); // @todo: see if we can't collapse multiple terms into a single spellcheck query foreach ($query_terms as $term) { $query = $term->phrase; $query = urlencode(trim($query)); $correction = null; // get spell suggestion try { $url = "http://api.search.live.net/xml.aspx?Appid={$app_id}&sources=spell&query={$query}"; $response = $client->getUrl($url); // process it $xml = Parser::convertToDOMDocument($response); // echo header("Content-Type: text/xml"); echo $xml->saveXML(); exit; $suggestion_node = $xml->getElementsByTagName('Value')->item(0); if ($suggestion_node != null) { $correction = $suggestion_node->nodeValue; } } catch (\Exception $e) { trigger_error('Could not process spelling suggestion: ' . $e->getTraceAsString(), E_USER_WARNING); } // got one if ($correction != null) { $term->phrase = $suggestion_node->nodeValue; $suggestion->addTerm($term); } } return $suggestion; }
/** * Initialize the object by picking up and processing the config xml file */ public function init() { parent::init(); // facets $facets = $this->xml->xpath("//config[@name='facet_fields']/facet"); if ($facets !== false) { foreach ($facets as $facet) { $this->facets[(string) $facet["internal"]] = $facet; } } // (fixed) search limits $limits = $this->xml->xpath("//config[@name='limit_search_options']/facet"); if ($limits !== false) { foreach ($limits as $limit) { $this->limits[(string) $limit["internal"]] = $limit; } } // fields $fields = $this->xml->xpath("//config[@name='basic_search_fields']/field"); if ($fields !== false) { foreach ($fields as $field) { $this->fields[(string) $field["internal"]] = (string) $field["public"]; } } }
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_file = "custom/Authentication/{$name}.php"; if (file_exists($local_file)) { require_once $local_file; $class_name = 'Local\\Authentication' . '\\' . ucfirst($name); if (!class_exists($class_name)) { throw new \Exception("the custom authentication scheme '{$name}' should have a class called '{$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 Authentication"); } return $authentication; }
/** * Create new Xerxes Request */ public static function createFromGlobals(ControllerMap $controller_map) { $registry = Registry::getInstance(); // reverse proxy if ($registry->getConfig("REVERSE_PROXIES", false)) { self::$trustProxy = true; self::$trustedProxies = explode(',', $registry->getConfig("REVERSE_PROXIES")); } // request $request = parent::createFromGlobals(); // set cookie path and name $basepath = $request->getBasePath(); $id = strtolower($basepath); $id = preg_replace('/\\//', '_', $id); $id = 'xerxessession_' . $id; $session_options = array('name' => $id, 'cookie_path' => $basepath == '' ? '/' : $basepath); $storage = new NativeSessionStorage($session_options); // session $session = new Session($storage); $session->start(); // register these mo-fo's $request->setRegistry($registry); $request->setSession($session); $request->setControllerMap($controller_map); // do our special mapping $request->extractQueryParams(); return $request; }
public function send($email, $subject, $body) { require_once __DIR__ . '/../../../../../../xerxes/lib/PHPMailer/class.phpmailer.php'; $registry = Registry::getInstance(); $mail = new \PHPMailer(); $mail->IsSMTP(); // telling the class to use SMTP $mail->Host = "coweumx01.calstate.edu:25"; // SMTP server $mail->From = $registry->getConfig("EMAIL_FROM", true); $mail->FromName = $subject; $mail->AddAddress($email); $mail->Subject = $subject; $mail->Body = $body; $mail->WordWrap = 50; if (!$mail->Send()) { throw new \Exception("Could not send message", 2); } /* $message = new Message(); $message->setTo($email); $message->setFrom($this->from); $message->setSubject($subject); $message->setBody($body); $this->transport->send($message); */ }
/** * Create a User * * @param Request $request [optional] create user from existing session */ public function __construct(Request $request = null) { self::$request = $request; if ($request != "") { // user attributes $this->username = $request->getSessionData("username"); $this->role = $request->getSessionData("role"); $this->ip_address = $request->server()->get('REMOTE_ADDR'); // local ip range from config $registry = Registry::getInstance(); $this->ip_range = $registry->getConfig("LOCAL_IP_RANGE", false, null); // temporarily authenticate users if ($this->username == "") { // on campus if ($this->isInLocalIpRange() == true) { $this->username = self::genRandomUsername(self::LOCAL); $this->role = self::LOCAL; } else { $this->username = self::genRandomUsername(self::GUEST); $this->role = self::GUEST; } $request->setSessionData("username", $this->username); $request->setSessionData("role", $this->role); } } }
/** * Create Authentication Scheme * * @param Request $request */ public function __construct(Request $request) { $this->request = $request; $this->registry = Registry::getInstance(); // get the user from the request $this->user = $this->request->getUser(); // send them back here when they are done $this->return_url = $this->request->getParam("return"); // flesh out our return url $base = $this->request->getBaseUrl(); $server = $this->request->getServerUrl(); if ($this->return_url == "") { $this->return_url = $base; // so send them home! } else { if (!strstr($this->return_url, $server)) { $this->return_url = $server . $this->return_url; // make it so @todo: why? } } // we always send the user back on http: since shib and possibly other schemes // will drop the user back in xerxes on https:, which is weird $this->return_url = str_replace("https://", "http://", $this->return_url); // @todo find out if some CAS servers are still tripping up on this $params = array('controller' => 'authenticate', 'action' => 'validate', 'return' => $this->return_url); $this->validate_url = $this->request->url_for($params, true); }
/** * Constructor * * @param Xerxes_Record $record record * @param Config $config local config */ public function __construct(Record $record, Config $config) { $this->xerxes_record = $record; $this->registry = Registry::getInstance(); $this->config = $config; // link resolver stuff $this->link_resolver = $this->config->getConfig("LINK_RESOLVER_ADDRESS", false, $this->registry->getConfig("LINK_RESOLVER_ADDRESS", false)); $this->sid = $this->config->getConfig("APPLICATION_SID", false, $this->registry->getConfig("APPLICATION_SID", false, "calstate.edu:xerxes")); if ($this->link_resolver != null) { $this->url_open = $record->getOpenURL($this->link_resolver, $this->sid); } $this->openurl_kev_co = $record->getOpenURL(null, $this->sid); // holdings $this->holdings = new Holdings(); if ($record->hasPhysicalHoldings() == false) { $this->holdings->checked = true; } // proxy links? $proxy_server = $this->registry->getConfig('PROXY_SERVER', false); $should_proxy_links = $this->config->getConfig('SHOULD_PROXY', false, false); if ($should_proxy_links) { foreach ($this->xerxes_record->getLinks() as $link) { $link->addProxyPrefix($proxy_server); } } }
/** * Constructor */ public function __construct() { // application config $this->registry = Registry::getInstance(); // local config $this->config = $this->getConfig(); }
public function __construct(MvcEvent $e, $id, Engine $engine) { $this->request = $e->getRequest(); $this->registry = Registry::getInstance(); $this->id = $id; $this->query = $engine->getQuery($this->request); $this->config = $engine->getConfig(); }
/** * APC Cache */ public function __construct() { if (!function_exists('apc_store')) { throw new \Exception('You are using the APC cache in Xerxes, but apc is not installed on your system'); } $registry = Registry::getInstance(); $institution = $registry->getConfig('APPLICATION_NAME', false, 'xerxes'); $this->institution = strtolower(preg_replace('/\\W/', '_', $institution)); }
protected function init(MvcEvent $e) { $this->engine = $this->getEngine(); $this->config = $this->engine->getConfig(); $this->registry = Registry::getInstance(); $this->data["config_local"] = $this->config->toXML(); $this->query = $this->engine->getQuery($this->request); $this->helper = new SearchHelper($e, $this->id, $this->engine); }
protected function init(MvcEvent $e) { $this->engine = $this->getEngine(); $this->config = $this->engine->getConfig(); $this->registry = Registry::getInstance(); $this->data = new ViewModel(); $this->data->setVariable('config_local', $this->config->toXML()); $this->query = $this->engine->getQuery($this->request); $this->helper = new SearchHelper($e, $this->id, $this->engine); }
/** * Add reviews from Good Reads */ public function addReviews() { $xerxes_record = $this->getXerxesRecord(); $isbn = $xerxes_record->getISBN(); $key = $this->registry->getConfig("GOOD_READS_API_KEY", false); if ($key != null) { $url = "http://www.goodreads.com/book/isbn?isbn={$isbn}&key={$key}"; $data = Parser::request($url, 5); if ($data != "") { $xml = Parser::convertToDOMDocument($data); $this->reviews = $xml; } } }
/** * Check the spelling of the search terms * * @return null|Suggestion */ public function checkSpelling() { // don't check multiple terms, for now @todo: fix $terms = $this->getQueryTerms(); if (count($terms) > 1) { return null; } $spell_type = $this->registry->getConfig('SPELL_CHECKER'); if ($spell_type != null) { $class_name = 'Application\\Model\\Search\\Spelling\\' . ucfirst($spell_type); $spell_checker = new $class_name(); return $spell_checker->checkSpelling($terms); } }
/** * Initialize the object by picking up and processing the config xml file * * @exception will throw exception if no configuration file can be found */ public function init() { parent::init(); // get group information out of config.xml too // we just store actual simplexml elements in the // $this->usergroups array. $groups = $this->xml->configuration->groups->group; if ($groups != false) { foreach ($groups as $group) { $id = (string) $group["id"]; $this->usergroups[Parser::strtoupper($id)] = $group; //case insensitive } } }
/** * Constructor * * @param Xerxes_Record $record record * @param Config $config local config */ public function __construct(Record $record, Config $config) { $this->xerxes_record = $record; $this->registry = Registry::getInstance(); $this->config = $config; // link resolver stuff $this->link_resolver = $this->config->getConfig("LINK_RESOLVER_ADDRESS", false, $this->registry->getConfig("LINK_RESOLVER_ADDRESS", false)); $this->sid = $this->registry->getConfig("APPLICATION_SID", false, "calstate.edu:xerxes"); if ($this->link_resolver != null) { $this->url_open = $record->getOpenURL($this->link_resolver, $this->sid); } $this->openurl_kev_co = $record->getOpenURL(null, $this->sid); // holdings $this->holdings = new Holdings(); if ($record->hasPhysicalHoldings() == false) { $this->holdings->checked = true; } }
/** * Select the ViewRenderer * * @param ViewEvent $e * @return ViewRenderer */ public function selectRenderer(ViewEvent $e) { if ($this->enhanced == false) { $request = $e->getRequest(); $model = $e->getModel(); // this happens if the route is not matched properly if (!$request instanceof Request) { $request = new Request(); $e->setRequest($request); } // add base elements $model->setVariable("base_url", $request->getServerUrl() . $request->getBaseUrl()); $model->setVariable("request", $request); $model->setVariable("config", Registry::getInstance()); // add navigation $nav = new Navigation($e); $model->setVariable("navbar", $nav->getNavbar()); // show internal xml if ($request->getParam('format') == 'xerxes') { $this->renderer->setFormat('xml'); } else { // determine which view script to use if ($e->getResponse()->getStatusCode() != 200) { $model->setVariable("display_exceptions", true); $model->setTemplate('error/index.phtml'); } else { // determine which view script to use $script = $request->getControllerMap()->getView($request->getParam('format')); // test view chosen // header("Content-type: text/xml"); echo $request->getControllerMap()->saveXML(); echo "<!-- $script -->"; exit; $model->setTemplate($script); } // render it $display_as = "html"; if ($request->getParam('format') == 'json') { $display_as = "json"; } $this->renderer->setFormat($display_as); } $this->enhanced = true; } return $this->renderer; }
/** * Create a new Mvc Event * * This wires-up the various Mvc classes and makes them * available as a convenient package to the application */ public function __construct(Bootstrap $bootstrap) { // $this->stopwatch = new Stopwatch(); // framework config $this->bootstrap = $bootstrap; // path to application root $this->app_dir = $bootstrap->getApplicationDir(); // application config $this->registry = Registry::getInstance(); // controller config $this->controller_map = new ControllerMap($this->app_dir); // incoming request $this->request = Request::createFromGlobals($this->controller_map); // outgoing response $this->response = $this->getNewResponse(); // set default view $controller = $this->request->getControllerName(); $action = $this->request->getParam('action', 'index'); $this->response->setView("{$controller}/{$action}.xsl"); }
/** * Check spelling * * @param QueryTerms[] $query_terms */ public function checkSpelling(array $query_terms) { return null; $registry = Registry::getInstance(); $suggestion = new Suggestion(); $consumer_key = $registry->getConfig('YAHOO_BOSS_CONSUMER_KEY', true); $consumer_secret = $registry->getConfig('YAHOO_BOSS_CONSUMER_SECRET', true); $client = new Client('http://yboss.yahooapis.com/'); $oauth = new OauthPlugin(array('consumer_key' => $consumer_key, 'consumer_secret' => $consumer_secret)); $client->addSubscriber($oauth); // @todo: see if we can't collapse multiple terms into a single spellcheck query foreach ($query_terms as $term) { $query = $term->phrase; $query = trim($query); $escaped_query = urlencode(urlencode($query)); // yes, double-escaped $correction = null; // get spell suggestion try { $response = $client->get('ysearch/spelling?q=' . $escaped_query . ' &format=xml')->send(); // process it $xml = simplexml_load_string($response->getBody()); // echo header("Content-Type: text/xml"); echo $xml->saveXML(); exit; $suggestions = $xml->xpath('//result/suggestion'); if (count($suggestions) > 0) { $correction = (string) $suggestions[0]; $correction = urldecode($correction); $correction = htmlspecialchars_decode($correction, ENT_QUOTES); } } catch (\Exception $e) { trigger_error('Could not process spelling suggestion: ' . $e->getTraceAsString(), E_USER_WARNING); } echo $correction; // got one if ($correction != null) { $term->phrase = $correction; $suggestion->addTerm($term); } } return $suggestion; }
/** * Register the user in session and with the user tables in the database * and then forwards them to the return url * * @param User $user [optional] user object */ public function register(User $user = null) { // if passed in externally if ($user != null) { $this->user = $user; } // data map $datamap_users = new Users(); $datamap_records = new SavedRecords(); // if the user was previously active under a local username // then reassign any saved records to the new username $old_username = $this->request->getSessionData("username"); $old_role = $this->request->getSessionData("role"); if ($old_role == "local") { $datamap_records->reassignRecords($old_username, $this->user->username); } // add or update user in the database // get any values in the db not specified here and populates user $this->user = $datamap_users->touchUser($this->user); // @todo: reconcile this code with User code // should we just save user object in session? // set main properties in session $admins = explode(',', $this->registry->getConfig('ADMIN_USERS')); if (in_array($this->user->username, $admins)) { $this->request->setSessionData("user_admin", true); } $this->request->setSessionData("username", $this->user->username); $this->request->setSessionData("role", $this->role); // store user's additional properties in session, so they can be used by // controller, and included in xml for views. $this->request->setSessionData("user_properties", $this->user->properties()); // groups too empty array not null please. $this->request->setSessionData("user_groups", $this->user->usergroups); // set this object's id in session $this->request->setSessionData("auth", $this->id); // now forward them to the return url return $this->redirectTo($this->return_url); }
/** * Check the spelling of the search terms * * @return Suggestion */ public function checkSpelling() { $registry = Registry::getInstance(); $spell_type = $registry->getConfig('SPELL_CHECKER'); if ($spell_type != null) { $class_name = 'Application\\Model\\Search\\Spelling\\' . ucfirst($spell_type); $spell_checker = new $class_name(); return $spell_checker->checkSpelling($this->getQueryTerms()); } }
public function __construct(ViewEvent $e) { $this->request = $e->getRequest(); $this->registry = Registry::getInstance(); }
/** * Create Request object */ public function __construct() { parent::__construct(); $this->registry = Registry::getInstance(); $this->extractQueryParams(); }
/** * 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, array $params = array()) { $registry = Registry::getInstance(); $import_array = array(); // the xsl lives here $distro_xsl_dir = $this->_script_path . "/"; $local_xsl_dir = realpath(getcwd()) . "/views/"; // language file $request = new Request(); $language = $request->getParam("lang"); if ($language == "") { $language = $registry->defaultLanguage(); } // english file is included by default (as a fallback) array_push($import_array, "labels/eng.xsl"); // 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, $this->format, $params, $import_array); }
public function __construct() { $this->registry = Registry::getInstance(); }
/** * (non-PHPdoc) * @see \Xerxes\Record::map() */ public function map() { $registry = Registry::getInstance(); $xml = simplexml_load_string($this->document->saveXML()); $control_info = $xml->header->controlInfo; $this->database_name = (string) $xml->header["longDbName"]; $this->database_openurl = (string) $xml->header["longDbName"]; $short_db_name = (string) $xml->header["shortDbName"]; $book = $control_info->bkinfo; $journal = $control_info->jinfo; $publication = $control_info->pubinfo; $article = $control_info->artinfo; if (count($book) > 0) { // usually an editor if (count($book->aug) > 0) { if (count($book->aug->au) > 0) { foreach ($book->aug->au as $auth) { $author = new Xerxes\Record\Author((string) $auth, "", "personal"); if ((string) $auth["type"] == "editor") { $this->editor = true; } array_push($this->authors, $author); } } } // isbn if (count($book->isbn) > 0) { foreach ($book->isbn as $isbn) { array_push($this->isbns, $isbn); } } } if (count($journal) > 0) { // journal title $this->journal_title = (string) $journal->jtl; // issn foreach ($journal->issn as $issn) { array_push($this->issns, $issn); } } if (count($publication) > 0) { // year $this->year = (string) $publication->dt["year"]; // volume $this->volume = (string) $publication->vid; // issue $this->issue = (string) $publication->iid; } if (count($article) > 0) { // identifiers foreach ($article->ui as $ui) { $id_number = (string) $ui; if ((string) $ui["type"] == "doi") { // doi $this->doi = $id_number; } elseif ((string) $ui["type"] == "") { // ebsco id $this->record_id = $short_db_name . "-" . $id_number; // eric doc number if ($short_db_name == "eric" && substr($id_number, 0, 2) == "ED") { $this->eric_number = $id_number; $this->issns = array(); } } } // full-text if (count($article->formats->fmt) > 0) { foreach ($article->formats->fmt as $fmt) { $link = ''; $type = ''; if ((string) $fmt["type"] == "T") { $link = $xml->plink; $type = Xerxes\Record\Link::HTML; } elseif ((string) $fmt["type"] == "P") { // pdf link is set only if there is both html and pdf full-text? $link = $xml->pdfLink; if ($link == "") { $link = $xml->plink; } $type = Xerxes\Record\Link::PDF; } $link_obj = new Xerxes\Record\Link($link, $type); $link_obj->addProxyPrefix($registry->getConfig('PROXY_SERVER', false)); $this->links[] = $link_obj; } } // start page $this->start_page = (string) $article->ppf; // extent $this->extent = (string) $article->ppct; // end page $pages = explode('-', (string) $article->pages); if (count($pages) > 1) { $this->end_page = $pages[1]; } // title $this->title = (string) $article->tig->atl; // authors if (count($article->aug->au) > 0) { foreach ($article->aug->au as $auth) { $author = new Xerxes\Record\Author((string) $auth, "", "personal"); array_push($this->authors, $author); } } // subjects foreach ($article->su as $subject) { $subject_object = new Xerxes\Record\Subject(); $subject_object->value = (string) $subject; $subject_object->display = (string) $subject; array_push($this->subjects, $subject_object); } // abstract $this->abstract = (string) $article->ab; $this->summary = $this->abstract; // format $formats = array(); foreach ($article->doctype as $doc_type) { array_push($formats, (string) $doc_type); } foreach ($article->pubtype as $pubtype) { array_push($formats, (string) $pubtype); } $this->notes = array_merge_recursive($this->notes, $formats); // format // @todo map this to internal $this->format->determineFormat($formats); if (count($formats) > 0) { $this->format->setPublicFormat($formats[0]); } // language $this->language = (string) $article->language; } }
public function init(MvcEvent $e) { $this->registry = Registry::getInstance(); $factory = new AuthenticationFactory(); $this->authentication = $factory->getAuthenticationObject($e->getRequest()); }
/** * Select the ViewRenderer * * @param ViewEvent $e * @return ViewRenderer */ public function selectRenderer(ViewEvent $e) { if ($this->enhanced == false) { $request = $e->getRequest(); $model = $e->getModel(); $registry = Registry::getInstance(); // this happens if the route is not matched properly if (!$request instanceof Request) { $request = new Request(); $e->setRequest($request); } // add base elements $model->setVariable("base_url", $request->getServerUrl() . $request->getBaseUrl()); $model->setVariable("request", $request); $model->setVariable("config", $registry); // add navigation $nav = new Navigation($e); $model->setVariable("navbar", $nav->getNavbar()); ### flatten model // @todo this seems really hacky, but our view renderer // has no notion of children, so this makes our lives easier foreach ($model->getChildren() as $child) { // template specified $model->setTemplate($child->getTemplate()); // terminate this? $model->setTerminal($child->terminate()); // options $options = $child->getOptions(); foreach ($options as $id => $value) { $model->setOption($id, $value); } // variables $child_variables = $child->getVariables(); foreach ($child_variables as $id => $value) { $model->setVariable($id, $value); } } // show internal xml if ($request->getParam('format') == 'xerxes') { $this->renderer->setFormat('xml'); } else { // error if ($e->getResponse()->getStatusCode() != 200) { $display_excpetions = false; if ($_SERVER['APPLICATION_ENV'] == 'development' || $registry->getConfig('DISPLAY_ERRORS', false, false) == true) { $display_excpetions = true; } $model->setVariable("display_exceptions", $display_excpetions); if ($e->getResponse()->getStatusCode() == 404) { $model->setTemplate('error/404.phtml'); } else { $model->setTemplate('error/index.phtml'); } } elseif (!strstr($model->getTemplate(), '.')) { $script = $request->getControllerMap()->getView($request->getParam('format')); // test view chosen // header("Content-type: text/xml"); echo $request->getControllerMap()->saveXML(); echo "<!-- $script -->"; exit; $model->setTemplate($script); } // render it $display_as = "html"; if ($request->getParam('format') == 'json') { $display_as = "json"; } $this->renderer->setFormat($display_as); } $this->enhanced = true; } return $this->renderer; }