public function doExecute() { //Cancel? $arrDefaultReturn = array("base" => "collections", "action" => "edit_form", "subject" => $this->request->getProperty("subject"), "subcategory" => $this->request->getProperty("subcategory"), "username" => $this->request->getProperty("username")); if ($this->request->getProperty("cancel")) { $this->returnWithMessage($this->getLabel("text_collections_cancelled"), $arrDefaultReturn); return 1; } $strSubject = $this->request->getProperty("subject"); $strSubcatID = $this->request->getProperty("subcategory"); $strUsername = $this->request->getProperty("username"); $strNewName = $this->request->getProperty("new_name"); if (empty($strNewName)) { $this->returnWithMessage($this->getLabel("text_collections_blank_name"), $arrDefaultReturn); return 1; } // make sure they are logged in as the user they are trying to save as. $this->ensureSpecifiedUser(); $objData = new Xerxes_DataMap(); $category = $objData->getSubject($strSubject, null, Xerxes_DataMap::userCreatedMode, $strUsername); if (!empty($strSubcatID)) { // rename a subcategory $subcat = $this->getSubcategory($category, $strSubcatID); $subcat->name = $strNewName; $objData->updateUserSubcategoryProperties($subcat); } else { // rename category $category->name = $strNewName; $objData->updateUserCategoryProperties($category); } // new name if it's been changed! $arrDefaultReturn["subject"] = $category->normalized; $this->returnWithMessage($this->getLabel("text_collections_renamed"), $arrDefaultReturn); return 1; }
/** * Return top level Metalib KB categories as XML * * @param Xerxes_Framework_Request $objRequest * @param Xerxes_Framework_Registry $objRegistry * @return int status */ public function doExecute() { $objXml = new DOMDOcument(); $objData = new Xerxes_DataMap(); $lang = $this->request->getProperty("lang"); $arrResults = $objData->getCategories($lang); $x = 1; if (count($arrResults) > 0) { $objXml->loadXML("<categories />"); foreach ($arrResults as $objCategoryData) { $objCategory = $objXml->createElement("category"); $objCategory->setAttribute("position", $x); foreach ($objCategoryData->properties() as $key => $value) { if ($value != null) { $objElement = $objXml->createElement("{$key}", Xerxes_Framework_Parser::escapeXml($value)); $objCategory->appendChild($objElement); } } // add the 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); $objCategory->appendChild($objElement); $objXml->documentElement->appendChild($objCategory); $x++; } } $this->request->addDocument($objXml); return 1; }
public function doExecute() { $strUsername = $this->request->getProperty("username"); if (empty($strUsername)) { //default to logged in user $strUsername = $this->request->getSession("username"); } $objData = new Xerxes_DataMap(); $existingCategoryNames = $this->request->getData('/*/userCategories/category/normalized', null, 'ARRAY'); if (count($existingCategoryNames) <= 1) { if (count($existingCategoryNames) == 1) { $normalized_name = $existingCategoryNames[0]; } else { // create a new one $strNewSubject = $this->registry->getConfig("default_collection_name", false, "My Saved Databases"); $strNormalizedSubject = Xerxes_Data_Category::normalize($strNewSubject); $newCategory = new Xerxes_Data_Category(); $newCategory->name = $strNewSubject; $newCategory->username = $strUsername; $newCategory->normalized = $strNormalizedSubject; $newCategory->published = 0; $newCategory = $objData->addUserCreatedCategory($newCategory); $normalized_name = $newCategory->normalized; } // redirect past the category selection page $fixedUrl = $this->request->url_for(array("base" => "collections", "action" => "save_choose_subheading", "subject" => $normalized_name, "id" => $this->request->getProperty("id"), "username" => $strUsername, "return" => $this->request->getProperty("return")), true); // force full url for redirect $this->request->setRedirect($fixedUrl); } return 1; }
public function doExecute() { $strSubjectSelection = $this->request->getProperty("subject"); $strUsername = $this->request->getProperty("username"); if (empty($strUsername)) { $strUsername = $this->request->getSession("username"); } // make sure they are logged in as the user they are trying to save as $this->ensureSpecifiedUser(); $objData = new Xerxes_DataMap(); $existingSubject = $objData->getSubject($strSubjectSelection, null, Xerxes_DataMap::userCreatedMode, $strUsername); $subcats = $existingSubject->subcategories; if (count($subcats) <= 1) { if (count($subcats) == 1) { $subcat_id = $subcats[0]->id; } else { //create one $new_subcat = new Xerxes_Data_Subcategory(); $new_subcat->sequence = 1; $new_subcat->category_id = $existingSubject->id; $new_subcat->name = $this->registry->getConfig("default_collection_section_name", false, "Databases"); $new_subcat = $objData->addUserCreatedSubcategory($new_subcat); $subcat_id = $new_subcat->id; } $fixedUrl = $this->request->url_for(array("base" => "collections", "action" => "save_complete", "subject" => $existingSubject->normalized, "subcategory" => $subcat_id, "id" => $this->request->getProperty("id"), "username" => $strUsername, "return" => $this->request->getProperty("return")), true); // force full url for redirect $this->request->setRedirect($fixedUrl); } return 1; }
public function doExecute() { $strUsername = $this->request->getSession("username"); $arrSessionArray = array(); if ($strUsername != "") { ### FORMATS / TYPES $objData = new Xerxes_DataMap(); $arrResults = $objData->getRecordFormats($strUsername); // transform them to XML $objXml = new DOMDocument(); $objXml->loadXML("<format_facets />"); foreach ($arrResults as $objFacet) { $objFacetNode = $objXml->createElement("facet", $objFacet->total); $objFacetNode->setAttribute("name", $objFacet->format); $arrParams = array("base" => "folder", "action" => "home", "username" => $this->request->getProperty("username"), "type" => $objFacet->format); $objFacetNode->setAttribute("url", $this->request->url_for($arrParams)); $objXml->documentElement->appendChild($objFacetNode); } $this->request->addDocument($objXml); ### TAGS // we'll store the tags summary in session so that edits can be // done without round-tripping to the database; xslt can display // the summary by getting it from the request xml $arrResults = $objData->getRecordTags($strUsername); foreach ($arrResults as $objTag) { $arrSessionArray[$objTag->label] = $objTag->total; } $this->setTagsCache($arrSessionArray); } return 1; }
public function getTotal($strUsername, $strLabel, $strType) { if ($this->iTotal == null) { $objData = new Xerxes_DataMap(); $this->iTotal = $objData->totalRecords($strUsername, $strLabel, $strType); } return $this->iTotal; }
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; } } }
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; }
public function doExecute() { // get properties from request $strUsername = $this->request->getSession("username"); $strGroup = $this->request->getProperty("group"); $strResultSet = $this->request->getProperty("resultSet"); $iStartRecord = $this->request->getProperty("startRecord"); // get the search start date $objSearchXml = $this->getCache($strGroup, "search", "SimpleXML"); $strDate = (string) $objSearchXml->date; // construct a fully unique id for metalib record based on // date, resultset, and startrecord numbers $strID = ""; $strID = $strDate . ":"; $strID .= $strResultSet . ":"; $strID .= str_pad($iStartRecord, 6, "0", STR_PAD_LEFT); // the save and delete action come in on the same onClick event from the search results page, // so we have to check here to see if it is a delete or save based on the session. This is a // bit dangerous, since maybe the session got out of sync? Oh well, it'll do for now, since // that's what was done with the previous cookie implementation. $objData = new Xerxes_DataMap(); $bolAdd = !$this->isMarkedSaved($strResultSet, $iStartRecord); $strInsertedId = null; if ($bolAdd == true) { // add command // get record from metalib result set $objXerxesRecord = new Xerxes_MetalibRecord(); $objXerxesRecord->loadXML($this->getRecord()); // add to database $objData->addRecord($strUsername, "metalib", $strID, $objXerxesRecord); $strInsertedId = $objXerxesRecord->id; // mark saved for feedback on search results $this->markSaved($objXerxesRecord); } else { // delete command $objData->deleteRecordBySource($strUsername, "metalib", $strID); $this->unmarkSaved($strResultSet, $iStartRecord); } // build a response $objXml = new DOMDocument(); $objXml->loadXML("<results />"); if ($bolAdd == false) { // flag this as being a delete comand in the view, in the event // user has javascript turned off and we need to show them an actual page $objDelete = $objXml->createElement("delete", "1"); $objXml->documentElement->appendChild($objDelete); } else { // add inserted id for ajax response $objInsertedId = $objXml->createElement("savedRecordID", $strInsertedId); $objXml->documentElement->appendChild($objInsertedId); } $this->request->addDocument($objXml); return 1; }
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() { // if supplied in url, use that (for future API use) $username = $this->request->getProperty("username"); if (!$username) { // default to logged in user $username = $this->request->getSession("username"); } // default names for if we have to create a new category. // can be sent with HTTP request, otherwise we have hard coded defaults. $strNewSubject = $this->registry->getConfig("default_collection_name", false, "My Saved Databases"); $strNormalizedSubject = Xerxes_Data_Category::normalize($strNewSubject); // we can only do this if we have a real user (not temp user) if ($username == null || !Xerxes_Framework_Restrict::isAuthenticatedUser($this->request)) { throw new Xerxes_Exception_AccessDenied("text_collections_error_not_logged_in"); } $objData = new Xerxes_DataMap(); //$arrResults = $objData->getUserCreatedCategories($username, "id"); $arrResults = $objData->getUserCreatedCategories($username); // find the default one, if present. $redirectCategory = null; for ($i = 0; $i < count($arrResults); $i++) { $iCat = $arrResults[$i]; if ($iCat->normalized == $strNormalizedSubject) { $redirectCategory = $iCat; break; } } // Couldn't find it? Have to make one. if (empty($redirectCategory)) { //Create one $redirectCategory = $this->addDefaultCollection($objData, $username); } /* This doesn't work right yet, although it's a nice idea. else { // Okay, let's make sure our default category has at least one // section, which it always ought to, but data corruption sometimes, // and we can fix it up. Got to refetch it to get it's subcategories. $redirectCategory = $objData->getSubject( $redirectCategory->normalized, null, Xerxes_DataMap::userCreatedMode, $redirectCategory->username); if ( count($redirectCategory->subcategories) == 0) { // add the default one $this->addDefaultSubcategory($objData, $redirectCategory); } }*/ // and redirect $url = $this->request->url_for(array('base' => 'collections', 'action' => 'subject', 'username' => $username, 'subject' => $redirectCategory->normalized)); $this->request->setRedirect($url); return 1; }
public function doExecute() { $bolFullText = false; $issn = $this->request->getProperty("issn"); $year = $this->request->getProperty("year"); $configBaseUrl = $this->request->getConfig("BASE_URL"); if ($issn != null && $issn != "") { // convert year to int if ($year != null && $year != "") { $year = (int) $year; } // run the query $objData = new Xerxes_DataMap(); $arrResults = $objData->getFullText($issn); foreach ($arrResults as $objFulltext) { // in case the database values are null, we'll assign the // initial years as unreachable $iStart = 9999; $iEnd = 0; if ($objFulltext->startdate != null) { $iStart = (int) $objFulltext->startdate; } if ($objFulltext->enddate != null) { $iEnd = (int) $objFulltext->enddate; } if ($objFulltext->embargo != null && (int) $objFulltext->embargo != 0) { // convert embargo to years, we'll overcompensate here by rounding // up, still showing 'check for availability' but no guarantee of full-text $iEmbargoDays = (int) $objFulltext->embargo; $iEmbargoYears = (int) ceil($iEmbargoDays / 365); // embargo of a year or more needs to go back to start of year, so increment // date plus an extra year if ($iEmbargoYears >= 1) { $iEmbargoYears++; } $iEnd = (int) date("Y"); $iEnd = $iEnd - $iEmbargoYears; } if ($year >= $iStart && $year <= $iEnd) { $bolFullText = true; } } } // redirect the browser to the correct image if ($bolFullText == true) { $this->request->setRedirect($configBaseUrl . "/images/dynamic-full.png"); } else { $this->request->setRedirect($configBaseUrl . "/images/dynamic-sfx.png"); } return 1; }
public function doExecute() { // get request parameters and configuration settings $strID = $this->request->getProperty("id"); $strType = $this->request->getProperty("type"); $doNotRedirect = $this->request->getProperty("printRedirect"); $configLinkResolver = $this->registry->getConfig("LINK_RESOLVER_ADDRESS", true); $configSID = $this->registry->getConfig("APPLICATION_SID", false, "calstate.edu:xerxes"); $configBaseUrl = $this->registry->getConfig("BASE_URL", true); // get the record from database $objData = new Xerxes_DataMap(); $objDataRecord = $objData->getRecordByID($strID); if ($objDataRecord == null) { throw new Exception("cannot find record"); } $objRecord = $objDataRecord->xerxes_record; // redirect to the resource based on type if ($strType == "openurl") { $this->request->setRedirect($objRecord->getOpenURL($configLinkResolver, $configSID)); } else { $strUrl = $configBaseUrl . "/?base=databases&action=proxy"; if ($strType == "html" || $strType == "pdf" || $strType == "online" || $strType == "construct") { $link = $objRecord->getFullText(true); foreach ($link as $arrLink) { if ($arrLink[2] == $strType) { // see if this is a construct link, in which case pass it back thru // proxy for construction if (is_array($arrLink[1])) { foreach ($arrLink[1] as $strField => $strValue) { $strUrl .= "¶m={$strField}={$strValue}"; } } else { $strUrl .= "&url=" . urlencode($arrLink[1]); } if (method_exists($objRecord, "getMetalibID")) { $strUrl .= "&database=" . $objRecord->getMetalibID(); } } } } else { throw new Exception("unsupported redirect type"); } $this->request->setRedirect($strUrl); } if ($doNotRedirect == true) { echo $this->request->getRedirect(); exit; } return 1; }
public function doExecute() { $strNormalizedSubject = $this->request->getProperty("subject"); $strUsername = $this->request->getProperty("username"); // Make sure they are logged in as the user they are trying to save as. $this->ensureSpecifiedUser(); $objData = new Xerxes_DataMap(); // Find the category $category = $objData->getSubject($strNormalizedSubject, null, Xerxes_DataMap::userCreatedMode, $strUsername); $objData->deleteUserCreatedCategory($category); // Send them back where they came from, with a message. $this->returnWithMessage($this->getLabel("text_collections_deleted_category", $category->name), array("base" => "collections", "action" => "list", "username" => $strUsername)); return 1; }
public function doExecute() { // cancel? $arrDefaultReturn = array("base" => "collections", "action" => "edit_form", "subject" => $this->request->getProperty("subject"), "subcategory" => $this->request->getProperty("subcategory"), "username" => $this->request->getProperty("username")); if ($this->request->getProperty("cancel")) { $this->returnWithMessage($this->getLabel("text_collections_cancelled"), $arrDefaultReturn); return 1; } $strSubject = $this->request->getProperty("subject"); $strSubcatID = $this->request->getProperty("subcategory"); $strPublished = $this->request->getProperty("published"); $strUsername = $this->request->getProperty("username"); $strNewName = $this->request->getProperty("new_name"); // Make sure they are logged in as the user they are trying to save as. $this->ensureSpecifiedUser(); $objData = new Xerxes_DataMap(); $category = $objData->getSubject($strSubject, null, Xerxes_DataMap::userCreatedMode, $strUsername); $message = ""; if (!empty($strSubcatID)) { // edit a subcategory, rename $subcat = $this->getSubcategory($category, $strSubcatID); if (!empty($strNewName)) { $message .= "Section name changed. "; $subcat->name = $strNewName; $objData->updateUserSubcategoryProperties($subcat); } } else { // edit a category: rename/publish if (!empty($strNewName)) { $category->name = $strNewName; $message .= $this->getLabel("text_collections_name_changed"); } if (!empty($strPublished)) { $boolPublished = (int) ($strPublished == "true"); $category->published = $boolPublished; if ($boolPublished) { $message .= $this->getLabel("text_collections_made_published"); } else { $message .= $this->getLabel("text_collections_made_private"); } } $objData->updateUserCategoryProperties($category); } // new name if it's been changed! $arrDefaultReturn["subject"] = $category->normalized; $this->returnWithMessage($message, $arrDefaultReturn); return 1; }
public function doExecute() { $username = $this->request->getProperty("username"); $password = $this->request->getProperty("password"); if ($username == null) { throw new Exception("you must supply username paramater"); } if ($password == null) { throw new Exception("you must supply a password paramater"); } echo "\n\nUPGRADE DATABASE \n\n"; echo " Executing KB upgrade . . . "; $data = new Xerxes_DataMap(null, $username, $password); $data->upgradeKB(); echo "done!\n"; }
public function doExecute() { $arrDefaultReturn = array("base" => "collections", "action" => "edit_form", "subject" => $this->request->getProperty("subject"), "subcategory" => $this->request->getProperty("subcategory"), "username" => $this->request->getProperty("username")); $strSubject = $this->request->getProperty("subject"); $strUsername = $this->request->getProperty("username"); // make sure they are logged in as the user they are trying to save as. $this->ensureSpecifiedUser(); $objData = new Xerxes_DataMap(); $category = $objData->getSubject($strSubject, null, Xerxes_DataMap::userCreatedMode, $strUsername); // find any new assigned numbers, and reorder. $orderedSubcats = $category->subcategories; // we need to through the assignments in sorted order by sequence choice, // for this to work right. $sortedProperties = $this->request->getAllProperties(); asort($sortedProperties); foreach ($sortedProperties as $name => $new_sequence) { $matches = array(); if (!empty($new_sequence) && preg_match('/^subcat_seq_(\\d+)$/', $name, $matches)) { $subcatID = $matches[1]; $old_index = null; $subcategory = null; for ($i = 0; $i < count($orderedSubcats); $i++) { $candidate = $orderedSubcats[$i]; if ($candidate->id == $subcatID) { $old_index = $i; $subcategory = $candidate; } } // if we found it. if ($subcategory) { // remove it from the array, then add it back in array_splice($orderedSubcats, $old_index, 1); array_splice($orderedSubcats, $new_sequence - 1, 0, array($subcategory)); } } } // okay, we've re-ordered $orderedSubcats, now update the sequence #s for ($i = 0; $i < count($orderedSubcats); $i++) { $subcategory = $orderedSubcats[$i]; $subcategory->sequence = $i + 1; $objData->updateUserSubcategoryProperties($subcategory); } $this->returnWithMessage($this->getLabel("text_collections_section_order_changed"), $arrDefaultReturn); return 1; }
public function doExecute() { $strNormalizedSubject = $this->request->getProperty("subject"); $strUsername = $this->request->getProperty("username"); $strDatabaseID = $this->request->getProperty("id"); $strSubcatID = $this->request->getProperty("subcategory"); // Make sure they are logged in as the user they are trying to save as. $this->ensureSpecifiedUser(); $objData = new Xerxes_DataMap(); $subcategory = null; // Find the category $category = $objData->getSubject($strNormalizedSubject, null, Xerxes_DataMap::userCreatedMode, $strUsername); $subcategory = $this->getSubcategory($category, $strSubcatID); $objData->removeDatabaseFromUserCreatedSubcategory($strDatabaseID, $subcategory); // Send them back where they came from, with a message. $this->returnWithMessage($this->getLabel("text_collections_removed_database")); return 1; }
public function doExecute() { $strNewSubject = $this->request->getProperty("new_subject_name"); if (empty($strNewSubject)) { $strNewSubject = $this->registry->getConfig("default_collection_name", false, "My Saved Databases"); } $strUsername = $this->request->getProperty("username"); $strNewSubcategory = $this->request->getProperty("new_subcategory_name"); if ($this->request->getProperty("action") == "save_complete") { // Nevermind, don't do it. $strNewSubcategory = null; } // Make sure they are logged in as the user they are trying to save as. $this->ensureSpecifiedUser(); $objData = new Xerxes_DataMap(); $existingSubject = null; // Make sure it's truly new and has a unique normalized form, else // reuse existing. This takes care of browser-refresh, or typing in the identical // name of an already existing one. $strNormalizedSubject = Xerxes_Data_Category::normalize($strNewSubject); $existingSubject = $objData->getSubject($strNormalizedSubject, null, Xerxes_DataMap::userCreatedMode, $strUsername); // if we found a dupe, we'll use that, otherwise create one. if (!$existingSubject) { $objDataCategory = new Xerxes_Data_Category(); $objDataCategory->name = $strNewSubject; $objDataCategory->username = $strUsername; $objDataCategory->normalized = $strNormalizedSubject; $objDataCategory->published = 0; $existingSubject = $objData->addUserCreatedCategory($objDataCategory); } // and create an initial section, please. if ($strNewSubcategory && !$this->request->getProperty("format") == "json") { $subcategory = new Xerxes_Data_Subcategory(); $subcategory->name = $strNewSubcategory; $subcategory->category_id = $existingSubject->id; $subcategory->sequence = 1; $subcategory = $objData->addUserCreatedSubcategory($subcategory); } // send them off to the edit_mode of their new category. $newUrl = $this->request->url_for(array("base" => "collections", "action" => "subject", "username" => $this->request->getProperty("username"), "subject" => $existingSubject->normalized), true); // force full url for redirect $this->request->setRedirect($newUrl); return 1; }
public function doExecute() { // get all of the issns $arrIssn = $this->request->getData("//issn", null, "array"); if (count($arrIssn) > 0) { // execute this in a single query $objData = new Xerxes_DataMap(); $arrResults = $objData->getRefereed($arrIssn); // add the data back to the request $objXml = new DOMDocument(); $objXml->loadXML("<refereed />"); foreach ($arrResults as $objPeer) { $objIssn = $objXml->createElement("issn", $objPeer->issn); $objXml->documentElement->appendChild($objIssn); } $this->request->addDocument($objXml); } return 1; }
protected function addAlphaList() { // check for letters in session $alpha_list = $this->request->getSession("alpha_list"); if ($alpha_list == "") { $objDataMap = new Xerxes_DataMap(); // check database cache $arrCache = $objDataMap->getCache("dblist", "az"); if (count($arrCache) > 0) { $objCache = $arrCache[0]; $alpha_list = $objCache->data; } else { // so create it $alpha_list_array = $objDataMap->getDatabaseAlpha(); $alpha_list = implode(',', $alpha_list_array); // and cache it in the database $objCache = new Xerxes_Data_Cache(); $objCache->source = "dblist"; $objCache->id = "az"; $objCache->data = $alpha_list; $objCache->expiry = time() + 60 * 60; // for one hour $objDataMap->setCache($objCache); } // cache it in session too! $this->request->setSession("alpha_list", $alpha_list); } // add it to the interface $objAlpha = new DOMDocument(); $objAlpha->loadXML("<alpha />"); foreach (explode(',', $alpha_list) as $letter) { $objEntry = $objAlpha->createElement("entry"); $objAlpha->documentElement->appendChild($objEntry); $objLetter = $objAlpha->createElement("letter", $letter); $objEntry->appendChild($objLetter); $params = array("base" => "databases", "action" => "alphabetical", "alpha" => $letter); $link = $this->request->url_for($params); $objLink = $objAlpha->createElement("link", Xerxes_Framework_Parser::escapeXML($link)); $objEntry->appendChild($objLink); } $this->request->addDocument($objAlpha); }
public function doExecute() { // If supplied in URL, use that (for future API use). // Nevermind, this is a privacy problem until we right access // controls for that future API use. //$username = $this->request->getProperty("username"); //if ( ! $username ) { // default to logged in user $username = $this->request->getSession("username"); //} // we can only do this if we have a real user (not temp user), otherwise // just add no XML. if ($username == null || !Xerxes_Framework_Restrict::isAuthenticatedUser($this->request)) { return 0; } $objXml = new DOMDOcument(); $objData = new Xerxes_DataMap(); $arrResults = $objData->getUserCreatedCategories($username); $x = 1; if (count($arrResults) > 0) { $objXml->loadXML("<userCategories />"); foreach ($arrResults as $objCategoryData) { $objCategory = $objXml->createElement("category"); $objCategory->setAttribute("position", $x); foreach ($objCategoryData->properties() as $key => $value) { if ($value != null) { $objElement = $objXml->createElement("{$key}", Xerxes_Framework_Parser::escapeXml($value)); $objCategory->appendChild($objElement); } } // add the url for the category $arrParams = array("base" => "collections", "action" => "subject", "username" => $username, "subject" => $objCategoryData->normalized); $url = Xerxes_Framework_Parser::escapeXml($this->request->url_for($arrParams)); $objElement = $objXml->createElement("url", $url); $objCategory->appendChild($objElement); $objXml->documentElement->appendChild($objCategory); $x++; } } $this->request->addDocument($objXml); return 1; }
public function doExecute() { $bolRefereed = false; $issn = $this->request->getProperty("issn"); $configBaseUrl = $this->request->getConfig("BASE_URL"); if ($issn != null && $issn != "") { // run the query $objData = new Xerxes_DataMap(); $arrResults = $objData->getRefereed($issn); // if we got a hit, then we're good if (count($arrResults) > 0) { $bolRefereed = true; } } // redirect the browser to the correct image if ($bolRefereed == true) { $this->request->setRedirect($configBaseUrl . "/images/refereed.png"); } else { $this->request->setRedirect($configBaseUrl . "/images/empty.png"); } return 1; }
public function doExecute() { $configMemory = $this->registry->getConfig("HARVEST_MEMORY_LIMIT", false, "500M"); ini_set("memory_limit", $configMemory); echo "\n\nPEER REVIEWED DATA POPULATION \n\n"; $objData = new Xerxes_DataMap(); $file = $this->registry->getConfig("PATH_PARENT_DIRECTORY") . "/lib/data/refereed.txt"; ### dump // this is a dump, really only used by david to // generate the file to begin with if ($this->request->getProperty("dump") != null) { echo "Dumping peer reviewed data . . . "; $data = $objData->getAllRefereed(); $output = ""; foreach ($data as $title) { $output .= "\n" . $title->issn . "\t" . $title->title . "\t" . $title->timestamp; } file_put_contents($file, $output); echo "done.\n"; return 1; } ### load echo "Getting data from refereed file . . . "; $file_data = file_get_contents($file); if ($file_data === false) { throw new Exception("Could not find a refereed data file at {$file}"); } echo "done.\n"; $objData->beginTransaction(); if ($this->request->getProperty("no-flush") == null) { echo "Flushing old refereed data . . . "; $objData->flushRefereed(); echo "done.\n"; } echo "Adding new refereed data . . . "; $titles = explode("\n", $file_data); $x = 0; foreach ($titles as $title) { $arrTitle = explode("\t", $title); if (count($arrTitle) == 3) { $object = new Xerxes_Data_Refereed(); $object->issn = trim($arrTitle[0]); // $object->title = trim($arrTitle[1]); $object->timestamp = trim($arrTitle[2]); $x++; $objData->addRefereed($object); } } echo "done.\n"; echo "Added {$x} titles.\n"; echo "Committing changes . . . "; $objData->commit(); echo "done.\n"; return 1; }
public function doExecute() { // in case this is being called from the web, plaintext if ($this->request->isCommandLine() == false) { header("Content-type: text/plain"); } // set a higher than normal memory limit to account for // pulling down large knowledgebases $configMemory = $this->registry->getConfig("HARVEST_MEMORY_LIMIT", false, "500M"); ini_set("memory_limit", $configMemory); echo "\n\nMETALIB KNOWLEDGEBASE PULL \n\n"; // get configuration settings $this->configInstitute = $this->registry->getConfig("METALIB_INSTITUTE", true); $this->configPortal = $this->registry->getConfig("METALIB_PORTAL", false, $this->configInstitute); $this->configLanguages = $this->registry->getConfig("LANGUAGES", false); $this->configChunk = $this->registry->getConfig("CHUNK_KB_PULL", false, false); $configMetalibAddress = $this->registry->getConfig("METALIB_ADDRESS", true); $configMetalibUsername = $this->registry->getConfig("METALIB_USERNAME", true); $configMetalibPassword = $this->registry->getConfig("METALIB_PASSWORD", true); // metalib search object $this->objSearch = new Xerxes_MetaSearch($configMetalibAddress, $configMetalibUsername, $configMetalibPassword); // data map $objData = new Xerxes_DataMap(); // clear the cache, while we're at it echo " Pruning cache table . . . "; $status = $objData->pruneCache(); if ($status != 1) { throw new Exception("could not prune cache"); } else { echo "done\n"; } // now the real kb stuff $objData->beginTransaction(); $arrSubjects = array(); // array of category and subcategory value objects $arrTypes = array(); // array of type value objects $arrDatabases = array(); // array of datatbase value objects echo " Flushing KB tables . . . "; $objData->clearKB(); echo "done\n"; echo " Fetching types . . . "; $arrTypes = $this->types(); foreach ($arrTypes as $objType) { $objData->addType($objType); } echo "done\n"; echo " Fetching databases . . . "; $arrDatabases = $this->databases(); foreach ($arrDatabases as $objDatabase) { $objData->addDatabase($objDatabase); } echo "done\n"; echo " Fetching categories and assigning databases . . . "; $languages = array(array("code" => "eng", "locale" => "C")); if ($this->configLanguages != null) { $languages = $this->configLanguages->language; } foreach ($languages as $language) { $locale = (string) $language["locale"]; $code = (string) $language["code"]; $oldlocale = setlocale(LC_CTYPE, 0); setlocale(LC_CTYPE, $locale); // this influences the iconv() call with 'ASCII//TRANSLIT' target $arrSubjects = $this->subjects($arrDatabases, $code); foreach ($arrSubjects as $objCategory) { $objData->addCategory($objCategory); } setlocale(LC_CTYPE, $oldlocale); } echo "done\n"; echo " Synching user saved databases . . . "; $objData->synchUserDatabases(); echo "done\n"; echo " Committing changes . . . "; $objData->commit(); echo "done\n"; return 1; }
public function doExecute() { $arrFullText = array(); // list of records with full text $arrPairs = array(); // issn-year combo array $arrIssn = array(); // just the issns // get all of the records that have an issn and a year // as well as no native full-text link already $strXpath = "//xerxes_record[not(links/link[@type = 'pdf' or @type = 'html' or @type = 'online']) and standard_numbers/issn and year]"; $objSimple = simplexml_import_dom($this->request->getData()); $arrRecords = $objSimple->xpath($strXpath); // pair-up the issn-year into a simple array here foreach ($arrRecords as $xerxes_record) { $issn = (string) $xerxes_record->standard_numbers->issn; $year = (string) $xerxes_record->year; // add the pairs to a master list, and then also just the issn for // efficiency of the query array_push($arrPairs, array($issn, $year)); array_push($arrIssn, $issn); } if (count($arrPairs) > 0) { // execute this in a single query // reduce to just the unique ISSNs $arrIssn = array_unique($arrIssn); $objData = new Xerxes_DataMap(); $arrResults = $objData->getFullText($arrIssn); // we'll now go back over the record issn => year pairs, looking to see // if one the results of our query matches it foreach ($arrPairs as $arrValues) { $strRecordIssn = $arrValues[0]; $strRecordYear = $arrValues[1]; foreach ($arrResults as $objFulltext) { // convert query issn back to dash if ($strRecordIssn == $objFulltext->issn) { // in case the database values are null, we'll assign the // initial years as unreachable $iStart = 9999; $iEnd = 0; if ($objFulltext->startdate != null) { $iStart = (int) $objFulltext->startdate; } if ($objFulltext->enddate != null) { $iEnd = (int) $objFulltext->enddate; } if ($objFulltext->embargo != null && (int) $objFulltext->embargo != 0) { // convert embargo to years, we'll overcompensate here by rounding // up, still showing 'check for availability' but no guarantee of full-text $iEmbargoDays = (int) $objFulltext->embargo; $iEmbargoYears = (int) ceil($iEmbargoDays / 365); // embargo of a year or more needs to go back to start of year, so increment // date plus an extra year if ($iEmbargoYears >= 1) { $iEmbargoYears++; } $iEnd = (int) date("Y"); $iEnd = $iEnd - $iEmbargoYears; } // if it falls within our range, add it to final array if ($strRecordYear >= $iStart && $strRecordYear <= $iEnd) { array_push($arrFullText, array($strRecordIssn, $strRecordYear)); } } } } // add the data back to the request $objXml = new DOMDocument(); $objXml->loadXML("<fulltext />"); foreach ($arrFullText as $arrValues) { $objIssn = $objXml->createElement("issn", $arrValues[0]); $objIssn->setAttribute("year", $arrValues[1]); $objXml->documentElement->appendChild($objIssn); } $this->request->addDocument($objXml); } return 1; }
public function doExecute() { $this->add_export_options(); // get request paramaters $strUsername = $this->request->getSession("username"); $strOrder = $this->request->getProperty("sortKeys"); $iStart = $this->request->getProperty("startRecord"); $strReturn = $this->request->getProperty("return"); $strLabel = $this->request->getProperty("label"); $strType = $this->request->getProperty("type"); $strView = $this->request->getProperty("view"); // id numbers can come in the form of multiple 'record' params or a single // 'records' param, with the ids comma separated $arrID = $this->request->getProperty("record", true); $strIDs = $this->request->getProperty("records"); if ($strIDs != null) { $arrID = explode(",", $strIDs); } // these are typically set in actions.xml $strLimit = $this->request->getProperty("limit"); $strLoginOverride = $this->request->getProperty("doNotEnforceLogin"); // configuration settings // default records per page is either set explicitly in saved_record_per_page in config // or is the main (metasearch) defaul_records_per_page or 20 which is the const $defaultMax = $this->registry->getConfig("DEFAULT_RECORDS_PER_PAGE", false, self::DEFAULT_RECORDS_PER_PAGE); $iCount = $this->registry->getConfig("SAVED_RECORDS_PER_PAGE", false, $defaultMax); $iCountExport = $this->registry->getConfig("MAXIMUM_RECORD_EXPORT_LIMIT", false, 1000); $configMarcBrief = $this->registry->getConfig("XERXES_BRIEF_INCLUDE_MARC", false, false); $configMarcFull = $this->registry->getConfig("XERXES_FULL_INCLUDE_MARC", false, false); // brief records and export actions should be set to export limit if ($strLimit == null) { $iCount = $iCountExport; } // save the return url back to metasearch page if specified if ($strReturn != "") { $this->request->setSession("SAVED_RETURN", $strReturn); } ### access control // can only override login if username is *NOT* supplied in the paramaters, // this prevents people from manually attempting this; 'doNotEnforceLogin' // must then only be used in conjunction with specific id numbers if ($this->request->getProperty("username") != null && $strLoginOverride != null) { throw new Exception("access denied"); } // ensure this is the same user, unless 'doNotEnforceLogin' overrides this, // such as with RefWorks or other third-party export if ($strLoginOverride == null) { $strRedirect = $this->enforceUsername(); if ($strRedirect != null) { $this->request->setRedirect($strRedirect); return 1; } } ### records // get the total number of records $iTotal = $this->getTotal($strUsername, $strLabel, $strType); // fetch result(s) from the database $objData = new Xerxes_DataMap(); $arrResults = array(); if ($arrID != "") { $arrResults = $objData->getRecordsByID($arrID); } elseif ($strLabel != "") { $arrResults = $objData->getRecordsByLabel($strUsername, $strLabel, $strOrder, $iStart, $iCount); } elseif ($strType != "") { $arrResults = $objData->getRecordsByFormat($strUsername, $strType, $strOrder, $iStart, $iCount); } else { $arrResults = $objData->getRecords($strUsername, $strView, $strOrder, $iStart, $iCount); } // create master results xml doc $objXml = new DOMDocument(); $objXml->recover = true; $objXml->loadXML("<results />"); if (count($arrResults) > 0) { $objRecords = $objXml->createElement("records"); $objXml->documentElement->appendChild($objRecords); // @todo move this to point of save for search arch /* enhance records with links generated from metalib templates, and get a list of databases too. We need to get the Xerxes_Records out of our list of Xerxes_Data_Records first. */ $xerxes_records = array(); $database_links_dom = ""; foreach ($arrResults as $objDataRecord) { if ($objDataRecord->xerxes_record instanceof Xerxes_MetalibRecord) { array_push($xerxes_records, $objDataRecord->xerxes_record); } } if (count($xerxes_records) > 0) { Xerxes_MetalibRecord::completeUrlTemplates($xerxes_records, $this->request, $this->registry, $database_links_dom); $database_links = $objXml->importNode($database_links_dom->documentElement, true); $objXml->documentElement->appendChild($database_links); } /* Add the records */ foreach ($arrResults as $objDataRecord) { // create a new record $objRecord = $objXml->createElement("record"); $objRecords->appendChild($objRecord); // full record url $arrParams = array("base" => "folder", "action" => "full", "username" => $strUsername, "record" => $objDataRecord->id); $url = $this->request->url_for($arrParams); $objUrlFull = $objXml->createElement("url_full", $url); $objRecord->appendChild($objUrlFull); // delete url $arrParams = array("base" => "folder", "action" => "delete", "username" => $strUsername, "source" => $objDataRecord->source, "id" => $objDataRecord->original_id, "type" => $strType, "label" => $strLabel, "startRecord" => $iStart, "total" => $iTotal, "sortKeys" => $strOrder, "recordsPerPage" => $iCount); $url = $this->request->url_for($arrParams); $objUrlDelete = $objXml->createElement("url_delete", $url); $objRecord->appendChild($objUrlDelete); // openurl link $arrParams = array("base" => "folder", "action" => "redirect", "type" => "openurl", "id" => $objDataRecord->id); $configLinkResolver = $this->registry->getConfig("LINK_RESOLVER_ADDRESS", true); $configSID = $this->registry->getConfig("APPLICATION_SID", false, "calstate.edu:xerxes"); foreach ($objDataRecord->properties() as $key => $value) { if ($key == "username" && $strLoginOverride != null) { // exclude the username if login overridden, for privacy } elseif ($key == "xerxes_record" && $value != null) { // import the xerxes record $objXerxesRecord = $value; $objBibRecord = new DOMDocument(); $objBibRecord = $objXerxesRecord->toXML(); // import it $objImportNode = $objXml->importNode($objBibRecord->documentElement, true); $objRecord->appendChild($objImportNode); // and openurl kev context object from record $kev = Xerxes_Framework_Parser::escapeXml($objXerxesRecord->getOpenURL(null, $configSID)); $objOpenUrl = $objXml->createElement("openurl_kev_co", $kev); $objRecord->appendChild($objOpenUrl); // full open url $url = Xerxes_Framework_Parser::escapeXml($objXerxesRecord->getOpenURL($configLinkResolver, $configSID)); $objUrlOpen = $objXml->createElement("url_open", $url); $objRecord->appendChild($objUrlOpen); // import the marc record, but only if configured to do so; since both brief // and full record display come in on the same command, we'll use the record count // here as an approximate for the brief versus full view -- hacky, hacky $iNumRecords = count($arrID); if ($strView != "brief" && $configMarcFull == true && $iNumRecords == 1 || $strView != "brief" && $configMarcBrief == true && $iNumRecords != 1) { $objOriginalXml = $objXerxesRecord->getOriginalXML(); $objImportNode = $objXml->importNode($objOriginalXml->documentElement, true); $objRecord->appendChild($objImportNode); } } else { $objElement = $objXml->createElement($key, Xerxes_Framework_Parser::escapeXml($value)); $objRecord->appendChild($objElement); } } $arrMulti = array("tags"); foreach ($arrMulti as $multi) { foreach ($objDataRecord->{$multi} as $value) { // remove the trailing 's' $single = substr($multi, 0, strlen($multi) - 1); if ($value != null) { $objElement = $objXml->createElement($single, Xerxes_Framework_Parser::escapeXml($value)); $objRecord->appendChild($objElement); } } } } } $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)); } } } } }
public function doExecute() { $configMemory = $this->registry->getConfig("HARVEST_MEMORY_LIMIT", false, "500M"); ini_set("memory_limit", $configMemory); echo "\n\nSFX INSTITUTIONAL HOLDINGS POPULATION \n\n"; // You can define the export file on sfx as having an instance extension, so // give the client the opportunity to define that here $strInstance = $this->request->getProperty("instance"); if ($strInstance != "") { $strInstance = "-" . $strInstance; } // construct the address to Google Scholar institutional // holdings file on SFX. Either SFX specific config, or // general link resolver config. $configSfx = $this->registry->getConfig("ALTERNATE_FULLTEXT_HARVEST_ADDRESS", false, $this->registry->getConfig("LINK_RESOLVER_ADDRESS", false)); if (!$configSfx) { throw new Exception("Can not run populate action, no link resolver address configured. " . "Need config ALTERNATE_FULLTEXT_HARVEST_ADDRESS or LINK_RESOLVER_ADDRESS."); } // fire-up a transaction with the database $objData = new Xerxes_DataMap(); $objData->beginTransaction(); // clear old data echo " Flushing SFX fulltext table . . . "; $objData->clearFullText(); echo "done.\n"; // try to get the data from sfx $done = false; $x = 0; while ($done == false) { $x++; $strUrl = $configSfx . "/cgi/public/get_file.cgi?file=institutional_holding" . $strInstance . '-.prt' . str_pad($x, 2, '0', STR_PAD_LEFT) . ".xml"; echo " Pulling down SFX inst holding file ({$x}) . . . "; try { $strResponse = Xerxes_Framework_Parser::request($strUrl); $objXml = new SimpleXMLElement($strResponse); } catch (Exception $e) { if ($x == 1) { throw new Exception("cannot get institutional holding file from sfx: '{$strUrl}'. " . "If this is the correct SFX server address, make sure your SFX allows access to " . "institutional holding file from this IP address in config/get_file_restriction.config " . "on SFX server."); } $done = true; } echo "done.\n"; if (!$done) { echo " Processing file . . . "; $objItems = $objXml->xpath("//item[@type != 'other']"); if ($objItems == false) { throw new Exception("could not find items in inst holding file."); } echo "done.\n"; echo " Adding to database . . . "; foreach ($objItems as $objItem) { foreach ($objItem->coverage as $objCoverage) { $objFullText = new Xerxes_Data_Fulltext(); $objFullText->issn = (string) $objItem->issn; $objFullText->issn = str_replace("-", "", $objFullText->issn); $objFullText->title = (string) $objItem->title; $objFullText->title = urlencode($objFullText->title); $objFullText->title = substr(Xerxes_Framework_Parser::strtolower($objFullText->title), 0, 100); $objFullText->startdate = (int) $objCoverage->from->year; $objFullText->enddate = (int) $objCoverage->to->year; if ($objFullText->enddate == 0) { $objFullText->enddate = 9999; } $objFullText->embargo = (int) $objCoverage->embargo->days_not_available; $objFullText->updated = date("YmdHis"); // add it to the database $objData->addFulltext($objFullText); } } echo "done.\n"; } } echo " Commiting changes . . . "; $objData->commit(); echo "done.\n"; return 1; }
public function doExecute() { $bolProxy = false; // whether to proxy or not $strFinal = ""; // final link to send back $strConstructPattern = ""; // construct link pattern // values from the url request $strMetalibID = $this->request->getProperty("database"); // metalib id $strUrl = $this->request->getProperty("url"); // a direct url to a site, typically to full text $arrParams = $this->request->getProperty("param", true); // a series of paramaters that we'll use to constuct a full-text linke // configuration settings $strProxyServer = $this->registry->getConfig("PROXY_SERVER", false); // if the database id is included, this could have come in off the // metasearch page, so we need to see if it should be proxied or not // based on database subscription info if ($strMetalibID != null) { $objDatabase = new Xerxes_DataMap(); $objDatabaseData = $objDatabase->getDatabase($strMetalibID); if ($objDatabaseData == null) { throw new Exception("Couldn't find database '{$strMetalibID}'"); } // databases marked as subscription should be proxied if ($objDatabaseData->subscription == "1") { $bolProxy = true; } // override the behavior if proxy flag specifically set if ($objDatabaseData->proxy != null) { if ($objDatabaseData->proxy == 1) { $bolProxy = true; } elseif ($objDatabaseData->proxy == 0) { $bolProxy = false; } } $strConstructPattern = $objDatabaseData->link_native_record; // if no url or construct paramaters were supplied, then this came // from the databases page as a 'short' url (the preferred now) // and so we'll just take the database's native link if ($arrParams == null && $strUrl == null) { $strUrl = $objDatabaseData->link_native_home; } } else { // the request is to proxy this no matter what; this is largely deprecated // in the system as of 1.3, but could be resurrected for some purpose? $bolProxy = true; } // if this is a construct request, we will use the metalib link_native_holding // pattern to create the link if ($arrParams != null) { if ($strMetalibID == null) { throw new Exception("Construct links require a Metalib ID"); } elseif ($strConstructPattern == null) { throw new Exception("Could not construct link to full-text"); } else { // paramaters come in a series of key=value pairs, so need to split them // out and run the field key against the pattern and replace it with value $strUrl = $strConstructPattern; foreach ($arrParams as $strParam) { $arrParamElements = explode("=", $strParam); if (count($arrParamElements) == 2) { $strUrl = str_replace("\$" . $arrParamElements[0], $arrParamElements[1], $strUrl); } } } } // make sure the link doesn't include the proxy // server prefix already if (preg_match('/http:\\/\\/[0-9]{1,3}-.*/', $strUrl) != 0) { // WAM proxy: this is kind of a rough estimate of a WAM-style // proxy link, but I think sufficient for our purposes? $bolProxy = false; } elseif (stristr($strUrl, $strProxyServer)) { // EZProxy $bolProxy = false; } // finally, if the proxy server entry is blank, then no proxy available if ($strProxyServer == "") { $bolProxy = false; } // if we need to proxy, prefix the proxy server url to the full-text // or database link and be done with it! if ($bolProxy == true) { // if WAM proxy, take the base url and port out and 'prefix'; // otherwise we only support EZPRoxy, so cool to take as else ? if (strstr($strProxyServer, '{WAM}')) { $arrMatch = array(); if (preg_match('/http[s]{0,1}:\\/\\/([^\\/]*)\\/{0,1}(.*)/', $strUrl, $arrMatch) != 0) { $strPort = "0"; $arrPort = array(); // port specifically included if (preg_match("/:([0-9]{2,5})/", $arrMatch[1], $arrPort) != 0) { if ($arrPort[1] != "80") { $strPort = $arrPort[1]; } $arrMatch[1] = str_replace($arrPort[0], "", $arrMatch[1]); } $strBase = str_replace("{WAM}", $strPort . "-" . $arrMatch[1], $strProxyServer); $strFinal = $strBase . "/" . $arrMatch[2]; $strFinal = str_replace("..", ".", $strFinal); } else { throw new Exception("could not construct WAM link"); } } else { // check if this is using EZProxy qurl param, in which case urlencode that mo-fo if (strstr($strProxyServer, "qurl=")) { $strUrl = urlencode($strUrl); } $strFinal = $strProxyServer . $strUrl; } } else { // just send it along straight-up $strFinal = $strUrl; } $this->request->setRedirect($strFinal); return 1; }