/** * 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; }
/** * This static method has most of the actual logic for a snippet generator page. * This mainly entails constructing and adding some URLs in an <embed> block * used for pointing to various types of snippet inclusion. Subclass defines * the starting url properties (base, action, anything else neccesary for a * snippet display), and calls this. * * @param array $url_params * @param array $direct_url_params * @return unknown */ protected function doExecuteHelper(array $url_params, array $direct_url_params = null) { // default embed css to false, because it's awful. if ($this->request->getProperty("disp_embed_css") == "") { $this->request->setProperty("disp_embed_css", "false"); } $objXml = new DOMDOcument(); $objXml->loadXML("<embed_info />"); $properties = array_keys($this->request->getAllProperties()); $display_properties = array(); foreach ($properties as $p) { if (substr($p, 0, 5) == 'disp_') { array_push($display_properties, $p); } } // direct to resource non-embedded action url if ($direct_url_params) { $direct_url = $this->request->url_for($direct_url_params, true); $objXml->documentElement->appendChild($objXml->createElement("direct_url", $direct_url)); } // embedded urls $url_params["gen_full_urls"] = "true"; // base embedded action url $raw_embedded_action_url = $this->request->url_for($url_params, true); if (strpos($raw_embedded_action_url, '?') == 0) { $raw_embedded_action_url .= "?"; } $objXml->documentElement->appendChild($objXml->createElement("raw_embedded_action_url", $raw_embedded_action_url)); // direct embed url $url_params["disp_embed"] = "true"; foreach ($display_properties as $p) { $url_params[$p] = $this->request->getProperty($p); } $embed_ssi_url = $this->request->url_for($url_params, true); $objXml->documentElement->appendChild($objXml->createElement("embed_direct_url", $embed_ssi_url)); // now the js snippet url $url_params["format"] = "embed_html_js"; $embed_js_call_url = $this->request->url_for($url_params, true); $objXml->documentElement->appendChild($objXml->createElement("embed_js_call_url", $embed_js_call_url)); $this->request->addDocument($objXml); return 1; }
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() { $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; }
/** * Creates XML structure with all modules wich can respond to "p_id" parameter in _GET (such as content and menus in catalog mode) * * @param array $options XML options: * root (string) : root node name * use (array) : modules to scan (items or "*") * skip (array) : filter array with modules names to use * @return DOMDocument */ function aliasCatchersAsXML($options = array('root' => 'alias-catchers', 'use' => array('*'), 'skip' => array())) { $xml = new DOMDOcument('1.0', 'utf-8'); $root_node_name = get_array_value($options, 'root', 'alias-catchers'); $xml->appendChild($root_node = $xml->createElement($root_node_name)); $skip_modules = get_array_value($options, 'skip', array()); $use_modules = get_array_value($options, 'skip', array('*')); // content module if ((in_array('*', $use_modules) || in_array('content', $use_modules)) && !in_array('content', $skip_modules)) { if (($content_config_ok = module_get_config('content', $content_config)) && ($pages_table = get_array_value($content_config['config'], 'table', false, REGEXP_IDENTIFIER)) != false) { $root_node->appendChild($module_node = $xml->createElement('module'))->setAttribute('name', 'Страницы'); $query = CMS::$DB->query("select alias, title from `{$pages_table}` order by title"); while ($row = $query->fetch(PDO::FETCH_ASSOC)) { $module_node->appendChild($catcher_node = $xml->createElement('catcher')); $catcher_node->appendChild($xml->createElement('title'))->nodeValue = $row['title']; $catcher_node->appendChild($xml->createElement('alias'))->nodeValue = $row['alias']; } } } // menu module if ((in_array('*', $use_modules) || in_array('menu', $use_modules)) && !in_array('menu', $skip_modules)) { if ($menu_config_ok = module_get_config('menu', $menu_config)) { $root_node->appendChild($module_node = $xml->createElement('module'))->setAttribute('name', 'Каталоги'); if (($menu_table = get_array_value($menu_config['config'], 'table_menu', false, REGEXP_IDENTIFIER)) != false) { $query = CMS::$DB->query("select alias, caption from `{$menu_table}` where alias > ''order by caption"); while ($row = $query->fetch(PDO::FETCH_ASSOC)) { $module_node->appendChild($catcher_node = $xml->createElement('catcher')); $catcher_node->appendChild($xml->createElement('title'))->nodeValue = $row['caption']; $catcher_node->appendChild($xml->createElement('alias'))->nodeValue = $row['alias']; } } } } return $xml; }
/** * Converts records from marc to xerxes_record and adds them to the master xml response * Also adds info on whether the record has already been saved this session. * * @param DOMDOcument $objXml master xml document * @param array $arrRecords an array of marc records * @param bool $configMarcResults whether to append the original marc records to the response * @return DOMDOcument master xml response updated with record data */ protected function addRecords($objXml, $arrRecords, $configMarcResults) { $objRecords = $objXml->createElement("records"); $arrXerxesRecords = array(); foreach ($arrRecords as $objRecord) { $objXerxesRecord = new Xerxes_MetalibRecord(); $objXerxesRecord->loadXml($objRecord); array_push($arrXerxesRecords, $objXerxesRecord); } // enhance with links computed from metalib templates. Xerxes_MetalibRecord::completeUrlTemplates($arrXerxesRecords, $this->request, $this->registry); $position = $this->request->getProperty("startRecord"); if ($position == "") { $position = 1; } foreach ($arrXerxesRecords as $objXerxesRecord) { $objRecordContainer = $objXml->createElement("record"); $objRecords->appendChild($objRecordContainer); // basis for most of the links below $arrParams = array("base" => "metasearch", "group" => $this->request->getProperty("group"), "resultSet" => $objXerxesRecord->getResultSet(), "startRecord" => $objXerxesRecord->getRecordNumber()); // full-text link $arrFullText = $arrParams; $arrFullText["action"] = "record"; if ($this->request->getProperty("facet") != "") { // append this so the full record page knows how to get back $arrFullText["return"] = Xerxes_Framework_Parser::escapeXml($this->request->getServer("REQUEST_URI")); } else { // this is a regular (non-facet) result // we keep current resultset and position (rather than original resultset // and recordNumber) for the benefit of the merged set where these are different $arrFullText["resultSet"] = $this->request->getProperty("resultSet"); $arrFullText["startRecord"] = $position; } $url = $this->request->url_for($arrFullText); $objUrlFull = $objXml->createElement("url_full", $url); $objRecordContainer->appendChild($objUrlFull); // save-delete link $arrSave = $arrParams; $arrSave["action"] = "save-delete"; $url = $this->request->url_for($arrSave); $objUrlSave = $objXml->createElement("url_save_delete", $url); $objRecordContainer->appendChild($objUrlSave); // openurl redirect link $arrOpen = $arrParams; $arrOpen["action"] = "sfx"; $url = $this->request->url_for($arrOpen); $objOpenUrl = $objXml->createElement("url_open", $url); $objRecordContainer->appendChild($objOpenUrl); // openurl kev context object please $configSID = $this->registry->getConfig("APPLICATION_SID", false, "calstate.edu:xerxes"); $kev = Xerxes_Framework_Parser::escapeXml($objXerxesRecord->getOpenURL(null, $configSID)); $objOpenUrl = $objXml->createElement("openurl_kev_co", $kev); $objRecordContainer->appendChild($objOpenUrl); // import xerxes xml $objXerxesXml = $objXerxesRecord->toXML(); $objImportRecord = $objXml->importNode($objXerxesXml->documentElement, true); $objRecordContainer->appendChild($objImportRecord); // optionally import marc-xml if ($configMarcResults == true) { $objMarcRecord = $objXerxesRecord->getMarcXML(); $objImportRecord = $objXml->importNode($objMarcRecord->getElementsByTagName("record")->item(0), true); $objRecordContainer->appendChild($objImportRecord); } $position++; } $objXml->documentElement->appendChild($objRecords); return $objXml; }