Ejemplo n.º 1
0
 /**
  *  Take a Xerxes data object representing a database, output
  *  a DOMDocument nodeset representing that database, for including
  *  in an XML response. Used by some Databases controllers. 
  *
  *  To actually include the returned value, you will need to import it into
  *  your DOMDocument of choice first. Example:
  *        $objDatabase = self::databaseToNodeset($objDatabaseData, $objRequest);
  *        $objDatabase = $objXml->importNode( $objDatabase, true );
  *        $objXml->documentElement->appendChild($objDatabase);
  *
  *
  * @param Xerxes_Data_Database $objDatabaseData
  * @param Xerxes_Framework_Request $objRequest  need the Xerxes request object to create urls for us. 
  * @param Xerxes_Framework_Registry $objRegistry need a registry object too, sorry. 
  * @param &$index = null  sometimes we want to append a count index to the xml. Pass in a counter variable, and it will be included AND incremented (passed by reference).
  * @return DOMNode
  */
 public static function databaseToNodeset(Xerxes_Data_Database $objDatabaseData, Xerxes_Framework_Request $objRequest, Xerxes_Framework_Registry $objRegistry, &$index = null)
 {
     $xml = $objDatabaseData->xml;
     //PHP 5.1.6 simplexml bug, 'for' iteration over ->searchable will create
     //it already if it doesn't exist, which we don't want, so
     //we have to wrap 'for' in 'if'.
     if (count($xml->searchable)) {
         foreach ($xml->searchable as $searchable) {
             // sometimes we're asked to track and record index.
             if ((string) $searchable == "1") {
                 $searchable["count"] = $index;
                 $index++;
             }
         }
     }
     // display name for group restrictions
     // bug in PGP 5.1.6 SimpleXML, if we do the foreach WITHOUT wrapping
     // it in this if testing count first,
     // it'll add on an empty <group_restriction/> to the xml
     // graph even if none were there previously. That's bad.
     if (count($xml->group_restriction) > 0) {
         foreach ($xml->group_restriction as $group_restriction) {
             $group_restriction->addAttribute("display_name", $objRegistry->getGroupDisplayName((string) $group_restriction));
         }
     }
     $multilingual = $objRegistry->getConfig("db_description_multilingual", false, "");
     // XML object
     $lang = $objRequest->getProperty("lang");
     if ($lang == "") {
         $lang = "eng";
     }
     // build a list of configured description languages
     if ($multilingual != "") {
         $order = 0;
         foreach ($multilingual->language as $language) {
             $order++;
             $code = NULL;
             foreach ($language->attributes() as $name => $val) {
                 if ($name == "code") {
                     $code = (string) $val;
                 }
             }
             $db_languages_order[$code] = $order;
             $db_languages_code[$order] = $code;
         }
     }
     $notes = array("description", "search_hints");
     foreach ($notes as $note_field_name) {
         $node_queue = array();
         // nodes to add when done looping to prevent looping over nodes added inside the loop
         foreach ($xml->{$note_field_name} as $note_field_xml) {
             $note_field = (string) $note_field_xml;
             // strip out "##" chars, not just singular "#" to allow # in markup
             // or other places.
             $pos = strpos($note_field, '######');
             if ($multilingual == false or $pos === false) {
                 $note_field = str_replace('######', '\\n\\n\\n', $note_field);
             } else {
                 $descriptions = explode('######', $note_field);
                 $i = 1;
                 foreach ($descriptions as $description) {
                     $description = self::embedNoteField($description);
                     $node_queue[] = array('note_field_name' => $note_field_name, 'description' => $description, 'code' => $db_languages_code[$i++]);
                 }
             }
             $note_field = self::embedNoteField($note_field);
             $xml->{$note_field_name} = $note_field;
             $xml->{$note_field_name}->addAttribute('lang', 'ALL');
         }
         foreach ($node_queue as $node) {
             $descNode = $xml->addChild($node['note_field_name'], $node['description']);
             $descNode->addAttribute('lang', $node['code']);
         }
     }
     $objDom = new DOMDocument();
     $objDom->loadXML($xml->asXML());
     $objDatabase = $objDom->documentElement;
     $objDatabase->setAttribute("metalib_id", $objDatabaseData->metalib_id);
     // is the particular user allowed to search this?
     $objElement = $objDom->createElement("searchable_by_user", self::dbSearchableForUser($objDatabaseData, $objRequest, $objRegistry));
     $objDatabase->appendChild($objElement);
     //add an element for url to xerxes detail page for this db
     $objElement = $objDom->createElement("url", $objRequest->url_for(array("base" => "databases", "action" => "database", "id" => htmlentities($objDatabaseData->metalib_id))));
     $objDatabase->appendChild($objElement);
     // The 'add to personal collection' url for logged in user--if no
     // logged in user, generate link anyway, but it's going to have
     // an empty user. User should be required to log in before continuing
     // with action.
     $url = $objRequest->url_for(array("base" => "collections", "action" => "save_choose_collection", "id" => $objDatabaseData->metalib_id, "username" => $objRequest->getSession("username"), "return" => $objRequest->getServer('REQUEST_URI')));
     $objElement = $objDom->createElement("add_to_collection_url", $url);
     $objDatabase->appendChild($objElement);
     //add an element for url to xerxes-mediated direct link to db.
     $objElement = $objDom->createElement("xerxes_native_link_url", $objRequest->url_for(array("base" => "databases", "action" => "proxy", "database" => htmlentities($objDatabaseData->metalib_id))));
     $objDatabase->appendChild($objElement);
     return $objDatabase;
 }
Ejemplo n.º 2
0
 public function execute(Xerxes_Framework_Request $objRequest, Xerxes_Framework_Registry $objRegistry)
 {
     // if the authentication_source is set in the request, then it takes precedence
     $override = $objRequest->getProperty("authentication_source");
     if ($override == null) {
         // otherwise, see if one has been set in session from a previous login
         $session_auth = $objRequest->getSession("auth");
         if ($session_auth != "") {
             $override = $session_auth;
         }
     }
     // make sure it's in our list, or if blank still, we get the default
     $configAuth = $objRegistry->getAuthenticationSource($override);
     // now make it!
     switch ($configAuth) {
         case "ldap":
             $this->authentication = new Xerxes_LDAP($objRequest, $objRegistry);
             break;
         case "innovative":
             $iii_file = "config/authentication/innovative.php";
             if (file_exists($iii_file)) {
                 require_once $iii_file;
                 $this->authentication = new Xerxes_InnovativePatron_Local($objRequest, $objRegistry);
             } else {
                 $this->authentication = new Xerxes_InnovativePatron($objRequest, $objRegistry);
             }
             break;
         case "cas":
             $this->authentication = new Xerxes_CAS($objRequest, $objRegistry);
             break;
         case "guest":
             $this->authentication = new Xerxes_GuestAuthentication($objRequest, $objRegistry);
             break;
         case "demo":
             $this->authentication = new Xerxes_DemoAuthentication($objRequest, $objRegistry);
             break;
         case "pds":
             $this->authentication = new Xerxes_PDS($objRequest, $objRegistry);
             break;
         case "shibboleth":
             $shib_file = "config/authentication/shibboleth.php";
             if (file_exists($shib_file)) {
                 require_once $shib_file;
                 $this->authentication = new Xerxes_Shibboleth_Local($objRequest, $objRegistry);
             } else {
                 $this->authentication = new Xerxes_Shibboleth($objRequest, $objRegistry);
             }
             break;
         case "custom":
             require_once "config/authentication/custom.php";
             $this->authentication = new Xerxes_CustomAuth($objRequest, $objRegistry);
             break;
         default:
             // check to see if a file exists with an authentication class that extends the framework,
             // if so, then use it; this supports multiple custom schemes
             $local_file = "config/authentication/{$configAuth}.php";
             $class_name = "Xerxes_CustomAuth_" . Xerxes_Framework_Parser::strtoupper(substr($configAuth, 0, 1)) . substr($configAuth, 1);
             if (file_exists($local_file)) {
                 require_once $local_file;
                 if (!class_exists($class_name)) {
                     throw new Exception("the custom authentication scheme '{$configAuth}' should have a class called '{$class_name}'");
                 }
                 $this->authentication = new $class_name($objRequest, $objRegistry);
                 if (!$this->authentication instanceof Xerxes_Framework_Authenticate) {
                     throw new Exception("class '{$class_name}' for the '{$configAuth}' authentication scheme must extend Xerxes_Framework_Authenticate");
                 }
             } else {
                 throw new Exception("unsupported authentication type");
             }
     }
     // we set this so we can keep track of the authentication type
     // through various requests
     $this->authentication->id = $configAuth;
     parent::execute($objRequest, $objRegistry);
 }