/** * Get an instance of the file; Singleton to ensure correct data * * @return Xerxes_Framework_Request */ public static function getInstance() { if (empty(self::$instance)) { self::$instance = new Xerxes_Framework_Request(); } return self::$instance; }
/** * Initialize the object by picking up and processing the ISO 639 xml file * * @exception will throw exception if no file can be found */ public function init() { // first, see if Getttext functions are installed if (function_exists('bindtextdomain')) { $this->gettext = true; } // set full path to local copy $this->languages_file_xerxes = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . $this->languages_file_xerxes); $this->gettext_domain_xerxes = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . $this->gettext_domain_xerxes); // if the iso-codes is not installed, use our copy $file = ""; if (file_exists($this->languages_file_system)) { $file = $this->languages_file_system; } elseif (file_exists($this->languages_file_xerxes)) { $file = $this->languages_file_xerxes; } else { throw new Exception("could not find file with the ISO 639 language list"); } // load the languages file $xml = new DOMDocument(); $xml->load($file); $this->xpath = new DOMXPath($xml); unset($xml); // which language shall we display? $objRegistry = Xerxes_Framework_Registry::getInstance(); $objRequest = Xerxes_Framework_Request::getInstance(); $lang = $objRequest->getProperty("lang"); if ($lang == null) { $lang = $objRegistry->defaultLanguage(); } $this->locale = $objRegistry->getLocale($lang); // bindings if ($this->gettext == true) { $gettext_domain_path = ""; if (file_exists($this->gettext_domain_xerxes)) { $gettext_domain_path = $this->gettext_domain_xerxes; } elseif (file_exists($this->gettext_domain_system)) { $gettext_domain_path = $this->gettext_domain_system; } bindtextdomain($this->domain, $gettext_domain_path); // this works on windows too? bind_textdomain_codeset($this->domain, 'UTF-8'); // assume UTF-8, all the .po files in iso_639 use it textdomain($this->domain); } }
public static function execute() { // calculate current file, this directory $this_directory = dirname(__FILE__); // calculate root directory of the app ../../ from here $path_to_parent = $this_directory; $path_to_parent = str_replace("\\", "/", $path_to_parent); $arrPath = explode("/", $path_to_parent); array_pop($arrPath); array_pop($arrPath); $path_to_parent = implode("/", $arrPath); // here so other framework files can reference it self::$parent_directory = $path_to_parent; // register framework any main xerxes class files self::registerClasses("{$path_to_parent}/lib/framework", "Xerxes_Framework"); // initialize the configuration setting (Registry), // command-view mapping (ControllerMap), and // language translation (Languages) objects $objRegistry = Xerxes_Framework_Registry::getInstance(); $objRegistry->init(); $objControllerMap = Xerxes_Framework_ControllerMap::getInstance(); $objControllerMap->init(); // set the version number, for interface or other places $objRegistry->setConfig("XERXES_VERSION", $objControllerMap->getVersion(), true); // dynamically set the web path, if config says so, // doesn't work on all webserver/php set-ups, so an // explicit web path from config is preferred if ($objRegistry->getConfig("base_web_path", false) == '{dynamic}') { if (isset($_SERVER)) { $script_name = $_SERVER['SCRIPT_NAME']; $script_name = str_replace("/index.php", "", $script_name); $objRegistry->setConfig("base_web_path", $script_name); } } // give our session a name to keep sessions distinct between multiple // instances of xerxes on one server. use base_path (preferably) or // application_name config directives. $path_base = $objRegistry->getConfig("base_web_path", false); $path_key = preg_replace('/\\W/', '_', $path_base); $session_name = "xerxessession_" . $path_key; if ($path_base == "") { $path_base = "/"; } $session_path = $objRegistry->getConfig("session_path", false, $path_base); $session_domain = $objRegistry->getConfig("session_domain", false, null); session_name($session_name); session_set_cookie_params(0, $session_path, $session_domain); session_start(); // processes the incoming request $objRequest = Xerxes_Framework_Request::getInstance(); $objRequest->init(); // utility classes // assists with basic paging/navigation elements for the view $objPage = new Xerxes_Framework_Page($objRequest, $objRegistry); // functions for special logging or handling of errors $objError = new Xerxes_Framework_Error(); // language names $objLanguage = Xerxes_Framework_Languages::getInstance(); $objLanguage->init(); // we'll put the remaining code in a try-catch block in order to show friendly error page // for any uncaught exceptions try { #################### # DISPLAY ERRORS # #################### if ($objRegistry->getConfig("DISPLAY_ERRORS") == true) { error_reporting(E_ALL); ini_set('display_errors', '1'); } #################### # DEFAULTS # #################### // labels $objLabels = Xerxes_Framework_Labels::getInstance(); $lang = $objRequest->getProperty("lang"); $objLabels->init($lang); // make sure application_name is passthrough, and has a value. $objRegistry->setConfig("application_name", $objRegistry->getConfig("APPLICATION_NAME", false, "Xerxes", $lang), true); #################### # SET PATHS # #################### ### reverse proxy // check to see if xerxes is running behind a reverse proxy and swap // host and remote ip here with their http_x_forwarded counterparts; // but only if configured for this, since client can spoof the header // if xerxes is not, in fact, behind a reverse proxy if ($objRegistry->getConfig("REVERSE_PROXY", false, false) == true) { $forward_host = $objRequest->getServer('HTTP_X_FORWARDED_HOST'); $forward_address = $objRequest->getServer('HTTP_X_FORWARDED_FOR'); if ($forward_host != "") { $objRequest->setServer('SERVER_NAME', $forward_host); } // last ip address is the user's if ($forward_address != "") { $arrIP = explode(",", $forward_address); $objRequest->setServer('REMOTE_ADDR', trim(array_pop($arrIP))); } } // the working directory is the instance, so any relative paths will // be executed in relation to the root directory of the instance $working_dir = getcwd(); $working_dir = str_replace("\\", "/", $working_dir); // full web path // // NOTE :if you change this code make sure you make a corresponding // change in lib/framework/Error.php, since there is redundant code // there in case something goes horribly wrong and we need to set the // web path for proper display of a (friendly) error page $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; // register these values $objRegistry->setConfig("SERVER_URL", $web); $objRegistry->setConfig("PATH_PARENT_DIRECTORY", $path_to_parent); $objRegistry->setConfig("APP_DIRECTORY", $working_dir); $objRegistry->setConfig("BASE_URL", $web . $base_path, true); #################### # INSTRUCTIONS # #################### // ControllerMap contains instructions for commands and views // based on the url parameters 'base' and 'action' $strBase = $objRequest->getProperty("base"); $strAction = $objRequest->getProperty("action"); $objControllerMap->setAction($strBase, $strAction, $objRequest); #################### # ACCESS CONTROL # #################### // if this part of the application is restricted to a local ip range, or requires a named login, then the // Restrict class will check the user's ip address or if they have logged in; failure stops the flow // and redirects user to a login page with the current request passed as 'return' paramater in the url $objRestrict = new Xerxes_Framework_Restrict($objRequest); // command line scripts will ignore access rules if ($objRequest->isCommandLine() != true) { if ($objControllerMap->isRestricted() == true) { if ($objControllerMap->requiresLogin() == true) { // resource requires a valid named username $objRestrict->checkLogin(); } else { // resource is resricted, but local ip range is okay $objRestrict->checkIP(); } } else { // go ahead and register local users, but don't prompt for login $objRestrict->checkIP(false); } } // if this action is set to only be run via the command line, in order to prevent // web execution of potentially long-running tasks, then restrict it here if (!$objRequest->isCommandLine() && $objControllerMap->restrictToCLI()) { throw new Exception("cannot run command from web"); } #################### # INCLUDES # #################### // files and directories that have been set to be included by the config file foreach ($objControllerMap->getIncludes() as $path_to_include) { self::registerClasses($path_to_parent . "/{$path_to_include}"); } #################### # DATA # #################### // set-up the data by defining the root element $strDocumentElement = $objControllerMap->getDocumentElement(); $objRequest->setDocumentElement($strDocumentElement); // pass config values that should be made available to the XSLT $objRequest->addDocument($objRegistry->publicXML()); // the data will be built-up by calling one or more command classes // which will fetch their data based on other parameters supplied in // the request; returning that data as xml to a master xml dom document // inside the Xerxes_Framework_Request class, or in some cases specififying // a url to redirect the user out $commands = $objControllerMap->getCommands(); foreach ($commands as $arrCommand) { $strDirectory = $arrCommand[0]; // directory where the command class is located $strNamespace = $arrCommand[1]; // prefix namespace of the command class $strClassFile = $arrCommand[2]; // suffix name of the command class // directory where commands live $command_path = "{$path_to_parent}/commands/{$strDirectory}"; // allow for a local override, even $local_command_path = "commands/{$strDirectory}"; // echo "<h3>$strClassFile</h3>"; // first, include any parent class, assuming that the parent class will // follow the naming convention of having the same name as the directory $strParentClass = Xerxes_Framework_Parser::strtoupper(substr($strDirectory, 0, 1)) . substr($strDirectory, 1); if (file_exists("{$local_command_path}/{$strParentClass}.php")) { require_once "{$local_command_path}/{$strParentClass}.php"; } elseif (file_exists("{$command_path}/{$strParentClass}.php")) { require_once "{$command_path}/{$strParentClass}.php"; } // if the specified command class exists in the distro or local commands folder, then // instantiate an object and execute it $strClass = $strNamespace . "_Command_" . $strClassFile; $local_command = file_exists("{$local_command_path}/{$strClassFile}.php"); if (file_exists("{$command_path}/{$strClassFile}.php") || $local_command) { // if the instance has a local version, take it! if ($local_command) { require_once "{$local_command_path}/{$strClassFile}.php"; } else { require_once "{$command_path}/{$strClassFile}.php"; } // instantiate the command class and execute it, but only // if it extends xerxes_framework_command $objCommand = new $strClass(); if ($objCommand instanceof Xerxes_Framework_Command) { $objCommand->execute($objRequest, $objRegistry); } else { throw new Exception("command classes must be instance of Xerxes_Framework_Command"); } } else { // if no command but a view was specified, then go ahead and show the view // minus any data, since the view is doin' its own thang if (!file_exists($objControllerMap->getView())) { throw new Exception("invalid command {$strClass}"); } } } #################### # COOKIES # #################### // any cookies specified in the reuqest object? if so, set em now. $cookieSetParams = $objRequest->cookieSetParams(); foreach ($cookieSetParams as $cookieParams) { set_cookie($cookieParams[0], $cookieParams[1], $cookieParams[2], $cookieParams[3], $cookieParams[4], $cookieParams[5]); } #################### # REDIRECT # #################### // if the result of the command is a redirect, we will stop the // flow and redirect the user out, unless overridden by the noRedirect // directive if ($objRequest->getRedirect() != null) { if ($objRequest->getProperty("noRedirect") == null) { header("Location: " . $objRequest->getRedirect()); exit; } else { // include in the resposne what the redirect would have been $objRequest->setProperty("redirect", $objRequest->getRedirect()); } } #################### # VIEW # #################### // SET THE HTTP HEADER // // we'll set the content-type, and potentially other header elements, based on the paramater 'format'; // format must correspond to one of the pre-defined format content-types in setHeader() or can be a user- // defined format set in action.xml $format = $objRequest->getProperty("format"); if ($objControllerMap->getFormat($format) != null) { header($objControllerMap->getFormat($format)); } else { self::setHeader($format); } // get the xml from the request object, but exclude any server information // from being included if format=source $bolShowServer = true; if ($format == "xerxes") { $bolShowServer = false; } $objXml = new DOMDocument(); $objXml = $objRequest->toXML($bolShowServer); // RAW XML DISPLAY // // you can append 'format=xerxes' to the querystring to have this controller spit back // the response in plain xml, which can be useful in some cases, like maybe AJAX? if ($format == "xerxes") { echo $objXml->saveXML(); } else { // VIEW CODE // // ControllerMap contains instructions on what file to include for the view; typically // this will be an xslt file, but could be a php file if the xslt does not // provide enough flexibility; php page will inherit the xml dom document and // can go from there if ($objControllerMap->getView() == "") { // No view specified, no view will be executed. return; } // PHP CODE if ($objControllerMap->getViewType() != "xsl" && $objControllerMap->getViewType() != null) { $file = $objControllerMap->getView(); $distro_file = $objRegistry->getConfig("PATH_PARENT_DIRECTORY", true) . "/lib/{$file}"; if (file_exists($file)) { require_once $file; } elseif (file_exists($distro_file)) { require_once $distro_file; } else { throw new Exception("Could not find non-xsl view specified to include: {$file}"); } } else { // XSLT CODE $output = $objPage->transform($objXml, $objControllerMap->getView(), null); // EMBEDED JAVASCRIPT DISPLAY // // you can append 'format=embed_html_js' to the querystring to output // the content as a javascript source document with everything wrapped in // document.write() statements if ($format == "embed_html_js") { // first escape any single quotes $output = str_replace("'", "\\'", $output); // now break the html into lines and output with document.write('') $lines = explode("\n", $output); $new_lines = array("// Javascript output. "); foreach ($lines as $line) { array_push($new_lines, "document.write('" . $line . "');"); } $output = implode("\n", $new_lines); } echo $output; } //remove the flash message, intended for one display only. $objRequest->setSession("flash_message", null); } } catch (Exception $e) { $objError->handle($e, $objRequest, $objRegistry); } }
/** * Take a Xerxes data object representing a database, output * a DOMDocument nodeset representing that database, for including * in an XML response. Used by some Databases controllers. * * To actually include the returned value, you will need to import it into * your DOMDocument of choice first. Example: * $objDatabase = self::databaseToNodeset($objDatabaseData, $objRequest); * $objDatabase = $objXml->importNode( $objDatabase, true ); * $objXml->documentElement->appendChild($objDatabase); * * * @param Xerxes_Data_Database $objDatabaseData * @param Xerxes_Framework_Request $objRequest need the Xerxes request object to create urls for us. * @param Xerxes_Framework_Registry $objRegistry need a registry object too, sorry. * @param &$index = null sometimes we want to append a count index to the xml. Pass in a counter variable, and it will be included AND incremented (passed by reference). * @return DOMNode */ public static function databaseToNodeset(Xerxes_Data_Database $objDatabaseData, Xerxes_Framework_Request $objRequest, Xerxes_Framework_Registry $objRegistry, &$index = null) { $xml = $objDatabaseData->xml; //PHP 5.1.6 simplexml bug, 'for' iteration over ->searchable will create //it already if it doesn't exist, which we don't want, so //we have to wrap 'for' in 'if'. if (count($xml->searchable)) { foreach ($xml->searchable as $searchable) { // sometimes we're asked to track and record index. if ((string) $searchable == "1") { $searchable["count"] = $index; $index++; } } } // display name for group restrictions // bug in PGP 5.1.6 SimpleXML, if we do the foreach WITHOUT wrapping // it in this if testing count first, // it'll add on an empty <group_restriction/> to the xml // graph even if none were there previously. That's bad. if (count($xml->group_restriction) > 0) { foreach ($xml->group_restriction as $group_restriction) { $group_restriction->addAttribute("display_name", $objRegistry->getGroupDisplayName((string) $group_restriction)); } } $multilingual = $objRegistry->getConfig("db_description_multilingual", false, ""); // XML object $lang = $objRequest->getProperty("lang"); if ($lang == "") { $lang = "eng"; } // build a list of configured description languages if ($multilingual != "") { $order = 0; foreach ($multilingual->language as $language) { $order++; $code = NULL; foreach ($language->attributes() as $name => $val) { if ($name == "code") { $code = (string) $val; } } $db_languages_order[$code] = $order; $db_languages_code[$order] = $code; } } $notes = array("description", "search_hints"); foreach ($notes as $note_field_name) { $node_queue = array(); // nodes to add when done looping to prevent looping over nodes added inside the loop foreach ($xml->{$note_field_name} as $note_field_xml) { $note_field = (string) $note_field_xml; // strip out "##" chars, not just singular "#" to allow # in markup // or other places. $pos = strpos($note_field, '######'); if ($multilingual == false or $pos === false) { $note_field = str_replace('######', '\\n\\n\\n', $note_field); } else { $descriptions = explode('######', $note_field); $i = 1; foreach ($descriptions as $description) { $description = self::embedNoteField($description); $node_queue[] = array('note_field_name' => $note_field_name, 'description' => $description, 'code' => $db_languages_code[$i++]); } } $note_field = self::embedNoteField($note_field); $xml->{$note_field_name} = $note_field; $xml->{$note_field_name}->addAttribute('lang', 'ALL'); } foreach ($node_queue as $node) { $descNode = $xml->addChild($node['note_field_name'], $node['description']); $descNode->addAttribute('lang', $node['code']); } } $objDom = new DOMDocument(); $objDom->loadXML($xml->asXML()); $objDatabase = $objDom->documentElement; $objDatabase->setAttribute("metalib_id", $objDatabaseData->metalib_id); // is the particular user allowed to search this? $objElement = $objDom->createElement("searchable_by_user", self::dbSearchableForUser($objDatabaseData, $objRequest, $objRegistry)); $objDatabase->appendChild($objElement); //add an element for url to xerxes detail page for this db $objElement = $objDom->createElement("url", $objRequest->url_for(array("base" => "databases", "action" => "database", "id" => htmlentities($objDatabaseData->metalib_id)))); $objDatabase->appendChild($objElement); // The 'add to personal collection' url for logged in user--if no // logged in user, generate link anyway, but it's going to have // an empty user. User should be required to log in before continuing // with action. $url = $objRequest->url_for(array("base" => "collections", "action" => "save_choose_collection", "id" => $objDatabaseData->metalib_id, "username" => $objRequest->getSession("username"), "return" => $objRequest->getServer('REQUEST_URI'))); $objElement = $objDom->createElement("add_to_collection_url", $url); $objDatabase->appendChild($objElement); //add an element for url to xerxes-mediated direct link to db. $objElement = $objDom->createElement("xerxes_native_link_url", $objRequest->url_for(array("base" => "databases", "action" => "proxy", "database" => htmlentities($objDatabaseData->metalib_id)))); $objDatabase->appendChild($objElement); return $objDatabase; }
public function execute(Xerxes_Framework_Request $objRequest, Xerxes_Framework_Registry $objRegistry) { // if the authentication_source is set in the request, then it takes precedence $override = $objRequest->getProperty("authentication_source"); if ($override == null) { // otherwise, see if one has been set in session from a previous login $session_auth = $objRequest->getSession("auth"); if ($session_auth != "") { $override = $session_auth; } } // make sure it's in our list, or if blank still, we get the default $configAuth = $objRegistry->getAuthenticationSource($override); // now make it! switch ($configAuth) { case "ldap": $this->authentication = new Xerxes_LDAP($objRequest, $objRegistry); break; case "innovative": $iii_file = "config/authentication/innovative.php"; if (file_exists($iii_file)) { require_once $iii_file; $this->authentication = new Xerxes_InnovativePatron_Local($objRequest, $objRegistry); } else { $this->authentication = new Xerxes_InnovativePatron($objRequest, $objRegistry); } break; case "cas": $this->authentication = new Xerxes_CAS($objRequest, $objRegistry); break; case "guest": $this->authentication = new Xerxes_GuestAuthentication($objRequest, $objRegistry); break; case "demo": $this->authentication = new Xerxes_DemoAuthentication($objRequest, $objRegistry); break; case "pds": $this->authentication = new Xerxes_PDS($objRequest, $objRegistry); break; case "shibboleth": $shib_file = "config/authentication/shibboleth.php"; if (file_exists($shib_file)) { require_once $shib_file; $this->authentication = new Xerxes_Shibboleth_Local($objRequest, $objRegistry); } else { $this->authentication = new Xerxes_Shibboleth($objRequest, $objRegistry); } break; case "custom": require_once "config/authentication/custom.php"; $this->authentication = new Xerxes_CustomAuth($objRequest, $objRegistry); break; default: // check to see if a file exists with an authentication class that extends the framework, // if so, then use it; this supports multiple custom schemes $local_file = "config/authentication/{$configAuth}.php"; $class_name = "Xerxes_CustomAuth_" . Xerxes_Framework_Parser::strtoupper(substr($configAuth, 0, 1)) . substr($configAuth, 1); if (file_exists($local_file)) { require_once $local_file; if (!class_exists($class_name)) { throw new Exception("the custom authentication scheme '{$configAuth}' should have a class called '{$class_name}'"); } $this->authentication = new $class_name($objRequest, $objRegistry); if (!$this->authentication instanceof Xerxes_Framework_Authenticate) { throw new Exception("class '{$class_name}' for the '{$configAuth}' authentication scheme must extend Xerxes_Framework_Authenticate"); } } else { throw new Exception("unsupported authentication type"); } } // we set this so we can keep track of the authentication type // through various requests $this->authentication->id = $configAuth; parent::execute($objRequest, $objRegistry); }
/** * Dynamically create our 'base' stylesheet, combining distro and local * stylesheets, as available, using includes and imports into our * 'base'. Base uses the distro file xsl/dynamic_skeleton.xsl to * begin with. * * @param string $strXsltRelPath Relative path to a stylesheet, generally beginning with "xsl/". * Stylesheet may exist in library location, app location, or both. * @param array $arrInclude [optional] additional stylesheets that should be included in the request * @return DomDocument A DomDocument holding the generated XSLT stylesheet. * @static */ public static function generateBaseXsl($strXsltRelPath, $arrInclude = array()) { $arrImports = array(); // files to be imported $objRegistry = Xerxes_Framework_Registry::getInstance(); ### first, set up the paths to the distro and local directories // the 'local' xsl lives here $local_xsl_dir = $objRegistry->getConfig("APP_DIRECTORY", true) . "/"; $local_path = $local_xsl_dir . $strXsltRelPath; // the 'distro' xsl lives here $distro_xsl_dir = $objRegistry->getConfig("PATH_PARENT_DIRECTORY", true) . '/lib/'; $distro_path = $distro_xsl_dir . $strXsltRelPath; ### check to make sure at least one of the files exists $distro_exists = file_exists($distro_path); $local_exists = file_exists($local_path); // if we don't have either a local or a distro copy, that's a problem. if (!($local_exists || $distro_exists)) { // throw new Exception("No xsl stylesheet found: $local_path || $distro_path"); throw new Exception("No xsl stylesheet found: {$strXsltRelPath}"); } ### now create the skeleton XSLT file that will hold references to both ### the distro and the local files $generated_xsl = new DOMDocument(); $generated_xsl->load($distro_xsl_dir . "xsl/dynamic_skeleton.xsl"); // prepend imports to this, to put them at the top of the file. $importInsertionPoint = $generated_xsl->documentElement->firstChild; ### add a reference to the distro file if ($distro_exists == true) { array_push($arrImports, $distro_path); } else { // if no distro, need to directly import (distro) includes.xsl, since we're not // importing a file that will reference it array_push($arrImports, $distro_xsl_dir . "xsl/includes.xsl"); } ### language file $request = Xerxes_Framework_Request::getInstance(); $language = $request->getProperty("lang"); if ($language == "") { $language = $objRegistry->defaultLanguage(); } // english file is included by default (as a fallback) array_push($arrInclude, "xsl/labels/eng.xsl"); // if language is set to something other than english // then include that file to override the english labels if ($language != "eng") { array_push($arrInclude, "xsl/labels/{$language}.xsl"); } ### add a refence for files programatically added (including the language file above) if ($arrInclude != null) { foreach ($arrInclude as $strInclude) { // but only if a distro copy exists if (file_exists($distro_xsl_dir . $strInclude)) { array_push($arrImports, $distro_xsl_dir . $strInclude); } // see if there is a local version, and include it too if (file_exists($local_xsl_dir . $strInclude)) { array_push($arrImports, $local_xsl_dir . $strInclude); } } } ### add a refence to the local file if ($local_exists) { self::addIncludeReference($generated_xsl, $local_path); } ### if the distro file xsl:includes or xsl:imports other files ### check if there is a corresponding local file, and import it too // We import instead of include in case the local stylesheet does erroneously // 'include', to avoid a conflict. We import LAST to make sure it takes // precedence over distro. if ($distro_exists) { $distroXml = simplexml_load_file($distro_path); $distroXml->registerXPathNamespace('xsl', 'http://www.w3.org/1999/XSL/Transform'); // find anything include'd or import'ed in original base file $array_merged = array_merge($distroXml->xpath("//xsl:include"), $distroXml->xpath("//xsl:import")); foreach ($array_merged as $extra) { // path to local copy $local_candidate = $local_xsl_dir . dirname($strXsltRelPath) . '/' . $extra['href']; // path to distro copy as a check $distro_check = $distro_xsl_dir . dirname($strXsltRelPath) . '/' . $extra['href']; // make sure local copy exists, and they are both not pointing at the same file if (file_exists($local_candidate) && realpath($distro_check) != realpath($local_candidate)) { array_push($arrImports, $local_candidate); } } } ### make sure we've got a reference to the local includes too array_push($arrImports, $local_xsl_dir . "xsl/includes.xsl"); // now make sure no dupes $arrImports = array_unique($arrImports); ### now the actual mechanics of the import foreach ($arrImports as $import) { self::addImportReference($generated_xsl, $import, $importInsertionPoint); } // header("Content-type: text/xml"); echo $generated_xsl->saveXML(); exit; return $generated_xsl; }
/** * 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 }
public static function isAuthenticatedUser(Xerxes_Framework_Request $objRequest) { return $objRequest->getSession("username") != null && $objRequest->getSession("role") != "local" && $objRequest->getSession("role") != "guest"; }