Esempio n. 1
0
 public function ensureSpecifiedUser()
 {
     $strUsername = $this->request->getProperty("username");
     $labels = Xerxes_Framework_Labels::getInstance();
     $error = $labels->getLabel("text_collections_error_private_collection_save");
     $error = sprintf($error, $strUsername);
     Xerxes_Helper::ensureSpecifiedUser($strUsername, $this->request, $this->registry, $error);
 }
 public function doExecute()
 {
     $arrSaved = array();
     $arrMatch = array();
     $objData = new Xerxes_DataMap();
     // find all of the xerxes records
     $objRecords = $this->request->getData("//xerxes_record", null, "DOMNodeList");
     if ($objRecords->length > 0) {
         foreach ($objRecords as $objXerxesRecord) {
             $strResultSet = "";
             $strRecordNumber = "";
             $objResultSet = $objXerxesRecord->getElementsByTagName("result_set")->item(0);
             $objRecordNumber = $objXerxesRecord->getElementsByTagName("record_number")->item(0);
             if ($objResultSet != null) {
                 $strResultSet = $objResultSet->nodeValue;
             }
             if ($objRecordNumber != null) {
                 $strRecordNumber = $objRecordNumber->nodeValue;
             }
             if ($strRecordNumber != "" && $strResultSet != "") {
                 // see if it's listed in session as being saved
                 if (Xerxes_Helper::isMarkedSaved($strResultSet, $strRecordNumber)) {
                     $key = Xerxes_Helper::savedRecordKey($strResultSet, $strRecordNumber);
                     $id = $_SESSION['resultsSaved'][$key]['xerxes_record_id'];
                     array_push($arrSaved, $id);
                     $arrMatch[$id] = $strResultSet . ":" . $strRecordNumber;
                 }
             }
         }
         if (count($arrSaved) == 0) {
             return 0;
         }
         // fetch all the saved records on this page in one query to the database
         $arrResults = $objData->getRecordsByID($arrSaved);
         if (count($arrResults) == 0) {
             return 0;
         } else {
             $objXml = new DOMDocument();
             $objXml->loadXML("<saved_records />");
             foreach ($arrResults as $objSavedRecord) {
                 // id
                 $objSavedRecordXml = $objXml->createElement("saved");
                 $objSavedRecordXml->setAttribute("id", $arrMatch[$objSavedRecord->id]);
                 $objIDXml = $objXml->createElement("id", $objSavedRecord->id);
                 $objSavedRecordXml->appendChild($objIDXml);
                 // labels
                 foreach ($objSavedRecord->tags as $tag) {
                     $objTagXml = $objXml->createElement("tag", Xerxes_Framework_Parser::escapeXml($tag));
                     $objSavedRecordXml->appendChild($objTagXml);
                 }
                 $objXml->documentElement->appendChild($objSavedRecordXml);
             }
             $this->request->addDocument($objXml);
             return 1;
         }
     }
 }
Esempio n. 3
0
 public function doExecute()
 {
     $lang = $this->request->getProperty("lang");
     // main list of subcategories and databases
     $objXml = new DOMDocument();
     $objXml->loadXML("<category />");
     // list of subcategories that should go in the sidebar
     $objSidebar = new DOMDocument();
     $objSidebar->loadXML("<sidebar />");
     $strOld = $this->request->getProperty("category");
     $strSubject = $this->request->getProperty("subject");
     $configSidebar = $this->registry->getConfig("SUBCATEGORIES_SIDEBAR", false, null, $lang);
     $arrSidebar = explode(",", $configSidebar);
     // look up home page default subject from config if no subject was specified, and we were
     // instructed to look it up with use_categories_quicksearch=true
     if ($strSubject == "" && $this->request->getProperty("use_categories_quicksearch") == "true") {
         $strSubject = $this->registry->getConfig("categories_quicksearch", false, "quick-search", $lang);
     }
     $objData = new Xerxes_DataMap();
     $objCategoryData = $objData->getSubject($strSubject, $strOld, "metalib", null, $lang);
     $y = 1;
     if ($objCategoryData != null) {
         $objXml->documentElement->setAttribute("name", $objCategoryData->name);
         $objXml->documentElement->setAttribute("normalized", $objCategoryData->normalized);
         // standard url for the category
         $arrParams = array("base" => "databases", "action" => "subject", "subject" => $objCategoryData->normalized);
         $url = Xerxes_Framework_Parser::escapeXml($this->request->url_for($arrParams));
         $objElement = $objXml->createElement("url", $url);
         $objXml->documentElement->appendChild($objElement);
         // the attributes of the subcategories
         $db_list_index = 1;
         foreach ($objCategoryData->subcategories as $objSubData) {
             $objSubCategory = $objXml->createElement("subcategory");
             $objSubCategory->setAttribute("name", $objSubData->name);
             $objSubCategory->setAttribute("position", $y);
             $objSubCategory->setAttribute("id", $objSubData->id);
             $y++;
             // the database information
             foreach ($objSubData->databases as $objDatabaseData) {
                 $objDatabase = Xerxes_Helper::databaseToNodeset($objDatabaseData, $this->request, $this->registry, $db_list_index);
                 $objDatabase = $objXml->importNode($objDatabase, true);
                 $objSubCategory->appendChild($objDatabase);
             }
             // if marked for the sidebar, put it there
             if (in_array($objSubData->name, $arrSidebar)) {
                 $objImport = $objSidebar->importNode($objSubCategory, true);
                 $objSidebar->documentElement->appendChild($objImport);
             } else {
                 $objXml->documentElement->appendChild($objSubCategory);
             }
         }
     }
     $this->request->addDocument($objXml);
     $this->request->addDocument($objSidebar);
     return 1;
 }
Esempio n. 4
0
 public function doExecute()
 {
     // ensure this is the same user
     $strRedirect = $this->enforceUsername();
     if ($strRedirect != null) {
         $this->request->setRedirect($strRedirect);
         return 1;
     }
     // get request parameters and configuration settings
     $strUsername = $this->request->getSession("username");
     $strSource = $this->request->getProperty("source");
     $strID = $this->request->getProperty("id");
     // params for deciding where to send the user back
     $strType = $this->request->getProperty("type");
     $strLabel = $this->request->getProperty("label");
     $iStart = $this->request->getProperty("startRecord");
     $iTotal = $this->request->getProperty("total");
     $iCount = $this->request->getProperty("recordsPerPage");
     $strSort = $this->request->getProperty("sortKeys");
     // ensure we send user back to a page with actual results!
     if ($iTotal == 1 && ($strLabel != "" || $strType != "")) {
         // if this is the last result in a tag or format grouping, then
         // simply redirect back to the folder home page
         $arrParams = array("base" => "folder", "action" => "home", "sortKeys" => $strSort, "username" => $this->request->getSession("username"));
     } else {
         // if the last record in the results is also the last one on
         // the page (of 10 or whatever), send the user back to an
         // earlier page with results on it
         if ($iStart > $iCount && $iStart == $iTotal) {
             $iStart = $iStart - $iCount;
         }
         $arrParams = array("base" => "folder", "action" => "home", "username" => $this->request->getSession("username"), "type" => $strType, "label" => $strLabel, "sortKeys" => $strSort, "startRecord" => $iStart);
     }
     $strReturn = $this->request->url_for($arrParams);
     // delete the record from the database
     $objData = new Xerxes_DataMap();
     $objData->deleteRecordBySource($strUsername, $strSource, $strID);
     // update the session
     // Sorry this gets a bit confusing, the api hasn't stayed entirely consistent.
     $resultSet = "";
     $recordNumber = $strID;
     $id = explode(':', $strID);
     // metalib
     if (count($id) > 1) {
         $resultSet = $id[1];
         $recordNumber = $id[2];
     }
     Xerxes_Helper::unmarkSaved($resultSet, $recordNumber);
     // send the user back out, so they don't step on this again
     $this->request->setRedirect($strReturn);
     return 1;
 }
 public function doExecute()
 {
     $objXml = new DOMDOcument();
     $objXml->loadXML("<databases />");
     $strID = $this->request->getProperty("id");
     $strQuery = $this->request->getProperty("query");
     $alpha = $this->request->getProperty("alpha");
     $objDataMap = new Xerxes_DataMap();
     $arrResults = array();
     if ($strID) {
         $arrResults = $objDataMap->getDatabases($strID);
         if (count($arrResults) == 0) {
             throw new Xerxes_Exception_NotFound("Can not find database with id {$strID}");
         }
     } elseif ($alpha != "") {
         $this->addAlphaList();
         $arrResults = $objDataMap->getDatabasesStartingWith($alpha);
     } elseif ($strQuery) {
         $arrResults = $objDataMap->getDatabases(null, $strQuery);
     } elseif ($this->request->getProperty("suppress_full_db_list") != "true") {
         $this->addAlphaList();
         // only show single letters, please
         if ($this->registry->getConfig("DATABASE_LIST_SINGLE_LETTER_DISPAY", false, false) && $this->request->getProperty("action") == "alphabetical") {
             $params = array("base" => "databases", "action" => "alphabetical", "alpha" => "A");
             $link = $this->request->url_for($params);
             $this->request->setRedirect($link);
             return 0;
         }
         // all database
         $arrResults = $objDataMap->getDatabases();
     }
     foreach ($arrResults as $objDatabaseData) {
         $objDatabase = Xerxes_Helper::databaseToNodeset($objDatabaseData, $this->request, $this->registry);
         $objDatabase = $objXml->importNode($objDatabase, true);
         $objXml->documentElement->appendChild($objDatabase);
     }
     $this->request->addDocument($objXml);
     return 1;
 }
 public static function completeUrlTemplates($records, $objRequest, $objRegistry, &$database_links_dom = null)
 {
     // If we weren't passed in a cached DOMDocument with a database_links
     // section, create one. Note that the var was passed by reference,
     // so this is available to the caller.
     if ($database_links_dom == null) {
         $metalib_ids = array();
         foreach ($records as $r) {
             array_push($metalib_ids, $r->getMetalibID());
         }
         $objData = new Xerxes_DataMap();
         $databases = $objData->getDatabases($metalib_ids);
         $database_links_dom = new DOMDocument();
         $database_links_dom->loadXML("<database_links/>");
         foreach ($databases as $db) {
             $objNodeDatabase = Xerxes_Helper::databaseToLinksNodeset($db, $objRequest, $objRegistry);
             $objNodeDatabase = $database_links_dom->importNode($objNodeDatabase, true);
             $database_links_dom->documentElement->appendChild($objNodeDatabase);
         }
     }
     // Pick out the templates into a convenient structure
     $linkTemplates = self::getLinkTemplates($database_links_dom);
     ### Add link to native record and to external holdings URL too, if
     # available from metalib template.
     foreach ($records as $r) {
         if ($r->getMetalibID() && array_key_exists($r->getMetalibID(), $linkTemplates)) {
             $arrTemplates = $linkTemplates[$r->getMetalibID()];
             foreach ($arrTemplates as $type => $template) {
                 $filled_in_link = $r->resolveUrlTemplate($template);
                 if (!empty($filled_in_link)) {
                     array_push($r->links, array(null, $filled_in_link, $type));
                 }
             }
         }
     }
 }
Esempio n. 7
0
 public function doExecute()
 {
     $objSearch = $this->getSearchObject();
     // metalib search object
     $bolRedirect = false;
     // final determination to redirect on merge
     $objStatus = new DOMDocument();
     // search status
     $objMerge = new DOMDocument();
     // merge information
     $iProgress = null;
     // number of times metalib status polled
     // params from the request
     $id = $this->request->getProperty("group");
     $strGroup = $this->getGroupNumber();
     $strMergeRedirect = $this->request->getProperty("mergeRedirect");
     // configuration options
     $configShowMergedResults = $this->registry->getConfig("IMMEDIATELY_SHOW_MERGED_RESULTS", false, true);
     $configApplication = $this->registry->getConfig("APPLICATION_SID", false, "calstate.edu:xerxes");
     $configFacets = $this->registry->getConfig("FACETS", false, false);
     $configRecordsPerPage = $this->registry->getConfig("RECORDS_PER_PAGE", false, 10);
     $iRefreshSeconds = $this->registry->getConfig("SEARCH_PROGRESS_CAP", false, 35);
     $configHitsCap = (string) $iRefreshSeconds / 5;
     $configSortPrimary = $this->registry->getConfig("SORT_ORDER_PRIMARY", false, "rank");
     $configSortSecondary = $this->registry->getConfig("SORT_ORDER_SECONDARY", false, "year");
     // access control
     $objSearchXml = $this->getCache($id, "search", "DOMDocument");
     Xerxes_Helper::checkDbListSearchableByUser($objSearchXml, $this->request, $this->registry);
     // redirect link base
     $arrParams = array("base" => "metasearch", "action" => "results", "group" => $id);
     // determine if redirect after merge
     if ($configShowMergedResults == true) {
         $bolRedirect = true;
     }
     if ($strMergeRedirect == "false") {
         $bolRedirect = false;
     } else {
         if ($strMergeRedirect == "true") {
             $bolRedirect = true;
         }
     }
     // get status of the search and cache result
     $objStatus = $objSearch->searchStatus($strGroup);
     $this->setCache($id, "group", $objStatus);
     // cap the number of refreshes
     if ($this->request->getSession("refresh-{$strGroup}") != null) {
         // get refresh count
         $iProgress = (int) $this->request->getSession("refresh-{$strGroup}");
         // if we hit limit, set metalib finish flag to true
         if ($iProgress >= (int) $configHitsCap) {
             $objSearch->setFinished(true);
         } else {
             $iProgress++;
             $this->request->setSession("refresh-{$strGroup}", $iProgress);
         }
     } else {
         $this->request->setSession("refresh-{$strGroup}", 1);
     }
     // if done see if there are results and merge and redirect,
     // otherwise this will fall thru and continue with auto refreshing
     if ($objSearch->getFinished() == true) {
         $this->request->setSession("refresh-{$strGroup}", 10);
         // check to see if there are any documents to merge, and then merge
         // and create facets
         $iGroupTotal = 0;
         // total number of hits in the group
         $arrDatabaseHits = array();
         // total number of databases with hits
         $objSimpleXml = simplexml_import_dom($objStatus->documentElement);
         $bolSearchLinkHit = false;
         $strSearchLinkSet = "";
         foreach ($objSimpleXml->xpath("//base_info") as $objBase) {
             if ((string) $objBase->no_of_documents == "888888888") {
                 $bolSearchLinkHit = true;
                 $strSearchLinkSet = (string) $objBase->set_number;
             } elseif ((int) $objBase->no_of_documents > 0) {
                 // we'll only count the databases with hits
                 $iGroupTotal += (int) $objBase->no_of_documents;
                 array_push($arrDatabaseHits, (string) $objBase->set_number);
             }
         }
         // only got a search-and-link database
         if ($iGroupTotal == 0 && $bolSearchLinkHit == true) {
             $arrParams["resultSet"] = $strSearchLinkSet;
             $this->request->setRedirect($this->request->url_for($arrParams));
             return 1;
         }
         // got hits
         if ($iGroupTotal > 0) {
             // we'll only issue the merge command if there is more than one database
             // with hits, otherwise there's no point
             if (count($arrDatabaseHits) == 1) {
                 $strSetNumber = $arrDatabaseHits[0];
                 // redirect to results page
                 $arrParams["resultSet"] = $strSetNumber;
                 $this->cache->save();
                 $this->request->setRedirect($this->request->url_for($arrParams));
                 return 1;
             } else {
                 $strMergeSet = "";
                 // merge set identifier
                 $iMergeCount = 0;
                 // count of documents in the merge set
                 // merge the top results
                 $objMerge = $objSearch->merge($strGroup, $configSortPrimary, $configSortSecondary);
                 // get the newly updated status that resulted from that merge
                 // operation and cache
                 $objStatus = $objSearch->searchStatus($strGroup);
                 $this->setCache($id, "group", $objStatus);
                 $objXPath = new DOMXPath($objMerge);
                 // extract new merge set number and total hits for merge set
                 if ($objXPath->query("//new_set_number")->item(0) != null) {
                     $strMergeSet = $objXPath->query("//new_set_number")->item(0)->nodeValue;
                 }
                 if ($objXPath->query("//no_of_documents")->item(0) != null) {
                     $iMergeCount = (int) $objXPath->query("//no_of_documents")->item(0)->nodeValue;
                 }
                 if ($strMergeSet == "") {
                     //throw new Exception( "Result from Metalib returned no set number" );
                 }
                 // cache the facets response, but only if there are more results than a single page
                 // and facets have been turned on
                 if ($iMergeCount > $configRecordsPerPage && $configFacets == true) {
                     $objFacetXml = $objSearch->facets($strMergeSet, "all", $configApplication);
                     $this->setCache($id, "facets", $objFacetXml);
                     // cache a slimmed down version of the facets as well
                     // to ease the load on the interface
                     $strFacetSlim = Xerxes_Framework_Parser::transform($objFacetXml, "xsl/utility/facets-slim.xsl");
                     $this->setCache($id, "facets_slim", $strFacetSlim);
                 }
             }
             // redirect to results page with merge set
             if ($bolRedirect == true) {
                 // catch no hits
                 if ($iMergeCount == 0) {
                     // check to see if any of the individual dbs had a search-and-link with
                     // a 'results found' indicator
                     $bolIndividual = false;
                     $strIndividualSet = "";
                     foreach ($objStatus->getElementsByTagName("base_info") as $objDb) {
                         foreach ($objDb->getElementsByTagName("no_of_documents") as $objDocs) {
                             if ((int) $objDocs->nodeValue > 0) {
                                 $bolIndividual = true;
                                 if ($objDb->getElementsByTagName("set_number")->item(0) != null) {
                                     $strIndividualSet = $objDb->getElementsByTagName("set_number")->item(0)->nodeValue;
                                     break 2;
                                 }
                             }
                         }
                     }
                     if ($bolIndividual == true) {
                         // redirect to individual results page
                         $arrParams["resultSet"] = $strIndividualSet;
                         $this->cache->save();
                         $this->request->setRedirect($this->request->url_for($arrParams));
                         return 1;
                     }
                 } else {
                     // redirect to merged results page
                     $arrParams["resultSet"] = $strMergeSet;
                     $this->cache->save();
                     $this->request->setRedirect($this->request->url_for($arrParams));
                     return 1;
                 }
             }
         }
     }
     // build the response from previous cached data
     $objXml = new DOMDocument();
     $objXml = $this->documentElement();
     $objXml = $this->addSearchInfo($objXml, $id);
     $objXml = $this->addStatus($objXml, $id);
     $objXml = $this->addProgress($objXml, $this->request->getSession("refresh-{$strGroup}"));
     $this->request->addDocument($objXml);
     $this->saveCache();
     return 1;
 }
 public function doExecute()
 {
     $start = microtime(true);
     $arrFields = array();
     // fields to return in response
     $iMaximumRecords = 10;
     // maximum number of records to return
     $iTotalHits = 0;
     // total number of hits in response
     $arrResults = array();
     // holds results returned
     // metalib search object
     $objSearch = $this->getSearchObject();
     // parameters from request
     $id = $this->request->getProperty("group");
     $strGroup = $this->getGroupNumber();
     $strResultSet = $this->request->getProperty("resultSet");
     $iStartRecord = (int) $this->request->getProperty("startRecord");
     // access control
     $objSearchXml = $this->getCache($id, "search", "DOMDocument");
     Xerxes_Helper::checkDbListSearchableByUser($objSearchXml, $this->request, $this->registry);
     // marc fields to return from metalib; we specify these here in order to keep
     // the response size as small (and thus as fast) as possible
     $strMarcFields = self::MARC_FIELDS_BRIEF;
     // $strMarcFields = "#####, OPURL";
     // configuration options
     $configRecordPerPage = $this->registry->getConfig("RECORDS_PER_PAGE", false, self::DEFAULT_RECORDS_PER_PAGE);
     $configMarcFields = $this->registry->getConfig("MARC_FIELDS_BRIEF", false);
     $configIncludeMarcRecord = $this->registry->getConfig("XERXES_BRIEF_INCLUDE_MARC", false, false);
     $configFacets = $this->registry->getConfig("FACETS", false, false);
     // add additional marc fields specified in the config file
     if ($configMarcFields != null) {
         $configMarcFields .= ", " . $strMarcFields;
     } else {
         $configMarcFields = $strMarcFields;
     }
     // empty querystring values will return as 0, so fix here in case
     if ($iStartRecord == 0) {
         $iStartRecord = 1;
     }
     $iMaximumRecords = (int) $configRecordPerPage;
     // extract total hits from this result set
     $objXml = $this->getCache($id, "group", "SimpleXML");
     foreach ($objXml->xpath("//base_info") as $base_info) {
         if ($base_info->set_number == $strResultSet) {
             $strTotalHits = $base_info->no_of_documents;
             if ($strTotalHits == "888888888") {
                 $iTotalHits = 1;
             } else {
                 $iTotalHits = (int) $strTotalHits;
             }
         }
     }
     // set marc fields to return in response
     $arrFields = explode(",", $configMarcFields);
     // get results from metalib
     $objResultsXml = $objSearch->retrieve($strResultSet, $iStartRecord, $iMaximumRecords, $iTotalHits, "customize", $arrFields);
     // build the response, including previous cached data
     $objXml = new DOMDocument();
     $objXml = $this->documentElement();
     $objXml = $this->addSearchInfo($objXml, $id);
     $objXml = $this->addStatus($objXml, $id, $strResultSet, $iTotalHits);
     $objXml = $this->addProgress($objXml, $this->request->getSession("refresh-{$strGroup}"));
     // if this is a search-and-link resource add the original xml that contains the link
     if ($objResultsXml->getElementsByTagName("search_and_link")->item(0) != null) {
         $objImport = $objXml->importNode($objResultsXml->documentElement, true);
         $objXml->documentElement->appendChild($objImport);
         // this is a http post submission, so we need to see if we have added the post
         // data to the alternate record link in the IRD, since X-Server bug prevents this
         // from coming through in the response
         $objSearchType = $objResultsXml->getElementsByTagName("search_and_link_type")->item(0);
         if ($objSearchType != null) {
             if ($objSearchType->nodeValue == "POST") {
                 $objSearchXml = $this->getCache($id, "search", "SimpleXML");
                 $objGroupXml = $this->getCache($id, "group", "SimpleXML");
                 $databases_id = $objGroupXml->xpath("//base_info[set_number = '{$strResultSet}']/base_001");
                 if (count($databases_id) != 1) {
                     throw new Exception("cannot find search-and-link database in group cache");
                 }
                 $metalib_id = (string) $databases_id[0];
                 $databases = $objSearchXml->xpath("//database[@metalib_id='{$metalib_id}']");
                 if (count($databases) != 1) {
                     throw new Exception("cannot find database '{$metalib_id}' in search cache");
                 }
                 $database = $databases[0];
                 // the form action
                 $post = (string) $database->link_search_post;
                 // the data to be posted
                 $data = (string) $database->link_native_record_alternative;
                 if ($post == "" || $data == "") {
                     throw new Exception("cannot create http post elements for search-and-link database");
                 }
                 // xml close to what we need in html, just to make this easy
                 $objPostXML = $objXml->createElement("post");
                 $objXml->documentElement->appendChild($objPostXML);
                 $objForm = $objXml->createElement("form");
                 $objForm->setAttribute("action", Xerxes_Framework_Parser::escapeXml($post));
                 $objPostXML->appendChild($objForm);
                 foreach (explode("&", $data) as $pair) {
                     $arrKeys = explode("=", $pair);
                     $key = $arrKeys[0];
                     $value = $arrKeys[1];
                     // metalib docs say only TERM1 is used in the 'URL mask',
                     if ($value == "TERM1") {
                         $value = (string) $objSearchXml->pair[0]->query;
                     }
                     $objInput = $objXml->createElement("input");
                     $objInput->setAttribute("name", $key);
                     $objInput->setAttribute("value", $value);
                     $objForm->appendChild($objInput);
                 }
             }
         }
     } else {
         // add the records themselves
         foreach ($objResultsXml->getElementsByTagName("record") as $objRecord) {
             array_push($arrResults, $objRecord);
         }
         // this will also convert the marc-xml to xerxes_record, and check for an already
         // saved record
         $objXml = $this->addRecords($objXml, $arrResults, $configIncludeMarcRecord);
     }
     $objXml = $this->addFacets($objXml, $id, $configFacets);
     $this->request->addDocument($objXml);
     // echo time(true) - $start . "<br>";
     return 1;
 }
 public function doExecute()
 {
     $objXml = new DOMDOcument();
     $objXml->loadXML("<category />");
     $strSubject = $this->request->getProperty("subject");
     $strUser = $this->request->getProperty("username");
     $objData = new Xerxes_DataMap();
     $objCategoryData = null;
     //  only fetch if we actually have params, avoid the fetch-everything phenomena
     if ($strSubject && $strUser) {
         $objCategoryData = $objData->getSubject($strSubject, null, Xerxes_DataMap::userCreatedMode, $strUser);
     }
     // if there hasn't
     if (!$objCategoryData) {
         if ($this->request->getRedirect()) {
             // nevermind, we're in the creation process, already redirected,
             // just end now.
             return 1;
         } else {
             throw new Xerxes_Exception_NotFound("text_collections_error_personal_collection_not_found");
         }
     }
     // make sure they have access
     if (!$objCategoryData->published) {
         Xerxes_Helper::ensureSpecifiedUser($objCategoryData->owned_by_user, $this->request, $this->registry, "text_collections_error_private_collection");
     }
     $y = 1;
     if ($objCategoryData != null) {
         $objXml->documentElement->setAttribute("name", $objCategoryData->name);
         $objXml->documentElement->setAttribute("normalized", $objCategoryData->normalized);
         $objXml->documentElement->setAttribute("owned_by_user", $objCategoryData->owned_by_user);
         $objXml->documentElement->setAttribute("published", $objCategoryData->published);
         // we treat the 'default' collection (usually 'My Saved Records') special
         // giving it less flexibility for simplicity, in the XSL/javascript.
         if ($this->isDefaultCollection($objCategoryData)) {
             $objXml->documentElement->setAttribute("is_default_collection", "yes");
         }
         // standard url for the category
         $arrParams = array("base" => "collections", "action" => "subject", "username" => $strUser, "subject" => $objCategoryData->normalized);
         $url = Xerxes_Framework_Parser::escapeXml($this->request->url_for($arrParams));
         $objElement = $objXml->createElement("url", $url);
         $objXml->documentElement->appendChild($objElement);
         //edit url for the user-created category
         $arrParams = array("base" => "collections", "action" => "edit_form", "username" => $strUser, "subject" => $objCategoryData->normalized);
         $url = Xerxes_Framework_Parser::escapeXml($this->request->url_for($arrParams));
         $objElement = $objXml->createElement("edit_url", $url);
         $objXml->documentElement->appendChild($objElement);
         // the attributes of the subcategories
         $db_list_index = 1;
         foreach ($objCategoryData->subcategories as $objSubData) {
             $objSubCategory = $objXml->createElement("subcategory");
             $objSubCategory->setAttribute("name", $objSubData->name);
             $objSubCategory->setAttribute("position", $y);
             $objSubCategory->setAttribute("id", $objSubData->id);
             $y++;
             // the database information
             foreach ($objSubData->databases as $objDatabaseData) {
                 $objDatabase = Xerxes_Helper::databaseToNodeset($objDatabaseData, $this->request, $this->registry, $db_list_index);
                 $objDatabase = $objXml->importNode($objDatabase, true);
                 $objSubCategory->appendChild($objDatabase);
             }
             $objXml->documentElement->appendChild($objSubCategory);
         }
     }
     $this->request->addDocument($objXml);
     return 1;
 }
Esempio n. 10
0
 /**
  * Do something with uncaught errors
  */
 public static function handle($e, Xerxes_Framework_Request $objRequest, Xerxes_Framework_Registry $objRegistry)
 {
     if ($objRegistry->getConfig("DISPLAY_ERRORS", false, false)) {
         throw $e;
     }
     // flag certain exception types for special handling in the xslt
     $strErrorType = get_class($e);
     // might be a sub-class, reset so view will catch.
     if ($e instanceof PDOException) {
         $strErrorType = "PDOException";
     }
     // if this is the command line, just rethrow the error so we can see it; might
     // make this a little better formatted in the future
     if ($objRequest->isCommandLine()) {
         throw $e;
     } else {
         // translate heading and message
         $labels = Xerxes_Framework_Labels::getInstance();
         if ($e instanceof Xerxes_Exception) {
             $heading = $e->heading();
         } else {
             $heading = "text_error";
         }
         $heading = $labels->getLabel($heading);
         $message = $labels->getLabel($e->getMessage());
         // first output to apache error log
         error_log("Xerxes error: " . $message . ": " . $e->getTraceAsString());
         //set proper http response code
         $resultStatus = 500;
         if ($e instanceof Xerxes_Exception_AccessDenied) {
             $resultStatus = 403;
         } else {
             if ($e instanceof Xerxes_Exception_NotFound) {
                 $resultStatus = 404;
             }
         }
         header(' ', true, $resultStatus);
         // send back http status as internal server error or other specified status
         // for the web, we'll convert the error message to xml along with the type
         // of exception and hand display off to the error.xsl file
         $objError = new DOMDocument();
         $objError->loadXML("<error />");
         $objMessage = $objError->createElement("message", $message);
         $objMessage->setAttribute("type", $strErrorType);
         $objError->documentElement->appendChild($objMessage);
         $objHeading = $objError->createElement("heading", $heading);
         $objError->documentElement->appendChild($objHeading);
         // make sure we're showing the main error file
         $objRegistry->setConfig("XSL_PARENT_DIRECTORY", null);
         // set the base url for the error.xsl file's benefit; don't want to assume that
         // the earlier code to this effect was executed before an exception, so this is redundant
         $base_path = $objRegistry->getConfig('BASE_WEB_PATH', false, "");
         $this_server_name = $objRequest->getServer('SERVER_NAME');
         // check for a non-standard port
         $port = $objRequest->getServer('SERVER_PORT');
         if ($port == 80 || $port == 443) {
             $port = "";
         } else {
             $port = ":" . $port;
         }
         $protocol = "http://";
         if ($objRequest->getServer("HTTPS")) {
             $protocol = "https://";
         }
         $web = $protocol . $this_server_name . $port . $base_path;
         $objBaseURL = $objError->createElement("base_url", $web);
         $objError->documentElement->appendChild($objBaseURL);
         // if it's a db denied exception, include info on dbs.
         if ($e instanceof Xerxes_Exception_DatabasesDenied) {
             $excluded_xml = $objError->createElement("excluded_dbs");
             $objError->documentElement->appendChild($excluded_xml);
             foreach ($e->deniedDatabases() as $db) {
                 $element = Xerxes_Helper::databaseToNodeset($db, $objRequest, $objRegistry);
                 $element = $objError->importNode($element, true);
                 $excluded_xml->appendChild($element);
             }
         }
         // add in the request object's stuff
         $request_xml = $objRequest->toXML();
         $imported = $objError->importNode($request_xml->documentElement, true);
         foreach ($imported->childNodes as $childNode) {
             $objError->documentElement->appendChild($childNode);
         }
         if ($objRequest->getProperty("format") == "xerxes") {
             header('Content-type: text/xml');
             echo $objError->saveXML();
         } else {
             // display it to the user. Transform will pick up local
             // xsl for error page too, great.
             echo Xerxes_Framework_Parser::transform($objError, "xsl/error.xsl");
         }
     }
     // need to incorporate methods for doing additional actions based on the type
     // of error -- probably a config option
 }
Esempio n. 11
0
 public function doExecute()
 {
     $objXml = new DOMDocument();
     $objXml->loadXML("<navbar />");
     ### saved records link
     $arrLink = array("base" => "folder");
     // make sure there is no return if coming from login to prevent a spider
     // from thinking this is a different page
     if ($this->request->getProperty("base") != "authenticate") {
         $arrLink["return"] = $this->request->getServer("REQUEST_URI");
     }
     $savedRecordsLink = $this->addNavbarElement($objXml, "saved_records", $arrLink);
     // add numSavedRecords  and sessionSavedRecords for proper icon display
     $objData = new Xerxes_DataMap();
     $num = $objData->totalRecords($this->request->getSession("username"));
     $savedRecordsLink->setAttribute("numSavedRecords", (string) $num);
     $savedRecordsLink->setAttribute("numSessionSavedRecords", Xerxes_Helper::numMarkedSaved());
     ### my collections (i.e., databases)
     $arrCollectionUrl = array("base" => "collections", "action" => "list");
     if (Xerxes_Framework_Restrict::isAuthenticatedUser($this->request)) {
         $arrCollectionUrl["username"] = $this->request->getSession("username");
     }
     $this->addNavbarElement($objXml, "saved_collections", $arrCollectionUrl);
     ### authentication
     // tell it to force an https url if so configured.
     $force_secure_login = false;
     if ($this->registry->getConfig("secure_login", false) == "true") {
         $force_secure_login = true;
     }
     // login
     $this->addNavbarElement($objXml, "login", array("base" => "authenticate", "action" => "login", "return" => $this->request->getServer("REQUEST_URI")), $force_secure_login);
     // logout
     $this->addNavbarElement($objXml, "logout", array("base" => "authenticate", "action" => "logout", "return" => $this->request->getServer("REQUEST_URI")));
     ### db alphabetical list
     $this->addNavbarElement($objXml, "database_list", array("base" => "databases", "action" => "alphabetical"));
     ### languages
     $languages = $this->registry->getConfig("LANGUAGES", false);
     if ($languages != null) {
         // map locales to language codes
         foreach ($languages as $language) {
             $order = NULL;
             $code = NULL;
             foreach ($language->attributes() as $name => $val) {
                 if ($name == "code") {
                     $code = (string) $val;
                 }
                 if ($name == "locale") {
                     $locale = (string) $val;
                     if ($locale == '') {
                         $locale = 'C';
                     }
                 }
             }
             $locales[$code] = $locale;
         }
         $languages_xml = $objXml->createElement("languages");
         $objXml->documentElement->appendChild($languages_xml);
         $language_names = Xerxes_Framework_Languages::getInstance();
         foreach ($languages->language as $language) {
             $code = (string) $language["code"];
             $readable_name = $language_names->getNameFromCode("iso_639_2B_code", $code, $locales[$code]);
             $native_name = $language_names->getNameFromCode("iso_639_2B_code", $code);
             $language_node = $objXml->createElement("language");
             $languages_xml->appendChild($language_node);
             $language_node->setAttribute("code", $code);
             $language_node->setAttribute("name", $readable_name);
             $language_node->setAttribute("native_name", $native_name);
             $language_node->setAttribute("locale", $locales[$code]);
             // link back to home page
             $current_params = $this->request->getURIProperties();
             // this page
             // this is necessary on the home page
             if (!array_key_exists("base", $current_params)) {
                 $current_params["base"] = "";
             }
             // subject pages can't support a swap, so send user back to home page
             if (($current_params["base"] == "databases" || $current_params["base"] == "embed") && array_key_exists("subject", $current_params)) {
                 $current_params = array();
                 $current_params["base"] = "";
             }
             // add the languages
             $current_params["lang"] = $code;
             // with language set
             $url = $this->request->url_for($current_params);
             $language_node->setAttribute("url", $url);
         }
     }
     $this->request->addDocument($objXml);
     return 1;
 }
Esempio n. 12
0
 public function doExecute()
 {
     // metalib search object
     $objSearch = $this->getSearchObject();
     // params from the request
     $strQuery = $this->request->getProperty("query");
     $strQuery2 = $this->request->getProperty("query2");
     $strField = $this->request->getProperty("field");
     $strField2 = $this->request->getProperty("field2");
     $strFindOperator = $this->request->getProperty("find_operator1");
     $arrDatabases = $this->request->getProperty("database", true);
     $strSubject = $this->request->getProperty("subject");
     $strSpell = $this->request->getProperty("spell");
     $strContext = $this->request->getProperty("context");
     $strContextUrl = $this->request->getProperty("context_url");
     // configuration options
     $configNormalize = $this->registry->getConfig("NORMALIZE_QUERY", false, false);
     $configBaseUrl = $this->registry->getConfig("BASE_URL", true);
     $configYahooID = $this->registry->getConfig("YAHOO_ID", false, "calstate");
     $configSearchLimit = $this->registry->getConfig("SEARCH_LIMIT", true);
     $configContextUrl = $this->registry->getConfig("LIMIT_CONTEXT_URL", false);
     //  if so configured, ensure that context_url is limited to certain domain(s)
     if ($configContextUrl != null) {
         $bolPassed = Xerxes_Framework_Parser::withinDomain($strContextUrl, $configContextUrl);
         if ($bolPassed == false) {
             throw new Exception("context_url only allowed for specified domains");
         }
     }
     // database communications object
     $objData = new Xerxes_DataMap();
     // if subject is given but not databases, automatically find
     // databases for subject, from first sub-category.
     if ($strSubject != null && count($arrDatabases) == 0) {
         $search_limit = $this->registry->getConfig("SEARCH_LIMIT", true);
         $arrDatabases = array();
         $objSubject = $objData->getSubject(strtolower($strSubject), null, "metalib", null, $this->request->getProperty("lang"));
         // did we find a subject that has subcategories?
         if ($objSubject != null && $objSubject->subcategories != null && count($objSubject->subcategories) > 0) {
             $subs = $objSubject->subcategories;
             $objSubcategory = $subs[0];
             $index = 0;
             // get databases up to search limit from first subcat,
             // add to $arrdatabases.
             foreach ($objSubcategory->databases as $objDatabaseData) {
                 if ($objDatabaseData->searchable == 1) {
                     array_push($arrDatabases, $objDatabaseData->metalib_id);
                     $index++;
                 }
                 if ($index >= $search_limit) {
                     break;
                 }
             }
         }
     }
     // if we have a subject, but no context/contexturl, look
     // them up for the subject. Allows convenient defaults
     // for direct-linking into search results.
     if ($strContext == "" && $strSubject != "") {
         // look up the subject if we haven't already, to get the name.
         if (!isset($objSubject)) {
             $objSubject = $objData->getSubject($strSubject);
         }
         $strContext = $objSubject->name;
     }
     if ($strContextUrl == "" && $strSubject != "") {
         $strContextUrl = $this->request->url_for(array("base" => "databases", "action" => "subject", "subject" => $strSubject));
     }
     // ensure a query and field
     if ($strQuery == "") {
         throw new Exception("text_metasearch_error_no_search_terms");
     }
     if ($strField == "") {
         $strField = "WRD";
     }
     if ($strField2 == "") {
         $strField2 = "WRD";
     }
     if ($strFindOperator == "") {
         $strFindOperator = "AND";
     }
     // get databases
     $arrDB = $objData->getDatabases($arrDatabases);
     // start out database information xml object.
     $objXml = new DOMDocument();
     $objXml->loadXML("<search />");
     // access control for databases
     $excludedDbs = array();
     $excludedIDs = array();
     foreach ($arrDB as $db) {
         if (!Xerxes_Helper::dbSearchableForUser($db, $this->request, $this->registry)) {
             $excludedDbs[] = $db;
             $excludedIDs[] = (string) $db->metalib_id;
         }
     }
     if (count($excludedDbs) > 0) {
         // remove excluded dbs from our db lists. what a pain in php, sorry.
         foreach ($arrDB as $key => $db) {
             if (in_array((string) $db->metalib_id, $excludedIDs)) {
                 unset($arrDB[$key]);
             }
         }
         foreach ($arrDatabases as $key => $id) {
             if (in_array($id, $excludedIDs)) {
                 unset($arrDatabases[$key]);
             }
         }
         // and make a note of the excluded dbs please.
         $excluded_xml = $objXml->createElement("excluded_dbs");
         $objXml->documentElement->appendChild($excluded_xml);
         foreach ($excludedDbs as $db) {
             $element = Xerxes_Helper::databaseToNodeset($db, $this->request, $this->registry);
             $element = $objXml->importNode($element, true);
             $excluded_xml->appendChild($element);
         }
     }
     // ensure correct number of databases selected
     if (count($arrDatabases) < 1 && count($excludedDbs) > 0) {
         $e = new Xerxes_Exception_DatabasesDenied("text_metasearch_error_not_authorized");
         $e->setDeniedDatabases($excludedDbs);
         throw $e;
     } elseif (count($arrDatabases) < 1) {
         throw new Exception("text_metasearch_error_no_databases");
     }
     if (count($arrDatabases) > $configSearchLimit) {
         $labels = Xerxes_Framework_Labels::getInstance();
         $error = $labels->getLabel("text_metasearch_error_too_many_databases");
         $error = sprintf($error, $configSearchLimit);
         throw new Exception($error);
     }
     $strSpellCorrect = "";
     // spelling correction
     $strSpellUrl = "";
     // return url for spelling change
     $strGroup = "";
     // group id number
     $strNormalizedQuery = "";
     // normalized query
     // query parser provides normalization and spell check
     $objQueryParser = new Xerxes_QueryParser();
     // normalize query option is still experimental (2009-04-16)
     $strFullQuery = $objQueryParser->normalizeMetalibQuery($strField, $strQuery, $strFindOperator, $strField2, $strQuery2, $configNormalize);
     // initiate search with Metalib
     $strGroup = $objSearch->search($strFullQuery, $arrDatabases);
     // something went wrong, yo!
     if ($strGroup == "") {
         throw new Exception("Could not initiate search with Metalib server");
     }
     // check spelling unless this is a return submission from a previous spell correction
     $strSpellSuggestions = null;
     if ($strSpell == null) {
         // check spelling
         $strAltYahoo = $this->registry->getConfig("ALTERNATE_YAHOO_LOCATION", false);
         $strSpellCorrect = $objQueryParser->checkSpelling($strQuery, $configYahooID, $strAltYahoo);
         $strSpellCorrect2 = null;
         if ($strQuery2) {
             $strSpellCorrect2 = $objQueryParser->checkSpelling($strQuery2, $configYahooID);
         }
         if ($strSpellCorrect != "" || $strSpellCorrect2 != "") {
             // construct spell check return url with spelling suggestion
             // If both search fields were used (advanced search), spell corrections
             // may be in first, second, or both.
             $strNewQuery = $strQuery;
             $arrSuggestions = array();
             if ($strSpellCorrect) {
                 $strNewQuery = $strSpellCorrect;
                 array_push($arrSuggestions, $strSpellCorrect);
             }
             $strNewQuery2 = $strQuery2;
             if ($strSpellCorrect2) {
                 $strNewQuery2 = $strSpellCorrect2;
                 array_push($arrSuggestions, $strSpellCorrect2);
             }
             $strSpellSuggestions = join(" ", $arrSuggestions);
             $strSpellUrl = "./?base=metasearch&action=search&spell=1&query=" . urlencode($strNewQuery) . "&field=" . $strField;
             if ($strNewQuery2) {
                 $strSpellUrl .= "&query2=" . urlencode($strNewQuery2) . "&field2=" . $strField2;
             }
             $strSpellUrl .= "&context=" . urlencode($strContext);
             $strSpellUrl .= "&context_url=" . urlencode($strContextUrl);
             foreach ($arrDatabases as $strDatabase) {
                 if ($strDatabase != null) {
                     $strSpellUrl .= "&database=" . $strDatabase;
                 }
             }
         }
     }
     // create search information xml
     $arrSearch = array();
     $arrSearch["date"] = date("Y-m-d");
     $arrSearch["spelling"] = $strSpellSuggestions;
     $arrSearch["spelling_url"] = $strSpellUrl;
     $arrSearch["context"] = $strContext;
     $arrSearch["context_url"] = $strContextUrl;
     foreach ($arrSearch as $key => $value) {
         $objElement = $objXml->createElement($key, Xerxes_Framework_Parser::escapeXml($value));
         $objXml->documentElement->appendChild($objElement);
     }
     $objPair = $objXml->createElement("pair");
     $objPair->setAttribute("position", 1);
     $objXml->documentElement->appendChild($objPair);
     $arrQuery = array();
     $arrQuery["query"] = $strQuery;
     $arrQuery["field"] = $strField;
     $arrQuery["normalized"] = $strFullQuery;
     foreach ($arrQuery as $key => $value) {
         $objElement = $objXml->createElement($key, Xerxes_Framework_Parser::escapeXml($value));
         $objPair->appendChild($objElement);
     }
     // add second pair if present.
     if ($strQuery2) {
         $objOperator = $objXml->createElement("operator", $strFindOperator);
         $objOperator->setAttribute("position", 1);
         $objXml->documentElement->appendChild($objOperator);
         $objPair = $objXml->createElement("pair");
         $objPair->setAttribute("position", 2);
         $objXml->documentElement->appendChild($objPair);
         $arrQuery = array();
         $arrQuery["query"] = $strQuery2;
         $arrQuery["field"] = $strField2;
         foreach ($arrQuery as $key => $value) {
             $objElement = $objXml->createElement($key, Xerxes_Framework_Parser::escapeXml($value));
             $objPair->appendChild($objElement);
         }
     }
     // get links from ird records for those databases that have been included in the search and
     // store it here so we can get at this information easily on any subsequent page without having
     // to go back to the database
     $objDatabaseLinks = $objXml->createElement("database_links");
     $objXml->documentElement->appendChild($objDatabaseLinks);
     foreach ($arrDB as $objDatabase) {
         // create a database node and append to database_links
         $objNodeDatabase = Xerxes_Helper::databaseToLinksNodeset($objDatabase, $this->request, $this->registry);
         $objNodeDatabase = $objXml->importNode($objNodeDatabase, true);
         $objDatabaseLinks->appendChild($objNodeDatabase);
     }
     // add any warnings from metalib
     $objWarnings = $objSearch->getWarnings();
     if ($objWarnings != null) {
         $objImport = $objXml->importNode($objWarnings->documentElement, true);
         $objXml->documentElement->appendChild($objImport);
     }
     $strGroup = $this->getSearchDate() . "-" . $strGroup;
     // save this information in the cache
     $this->setCache($strGroup, "search", $objXml);
     // redirect to hits page
     $arrParams = array("base" => "metasearch", "action" => "hits", "group" => $strGroup);
     $this->saveCache();
     $this->request->setRedirect($this->request->url_for($arrParams));
     return 1;
 }
Esempio n. 13
0
 protected function isMarkedSaved($strResultSet, $strRecordNumber)
 {
     return Xerxes_Helper::isMarkedSaved($strResultSet, $strRecordNumber);
 }