/** * Applies action * * @return boolean success */ protected function main() { $mode = 0775; //see if a path is given. we default to Nexista temp dir if (!($dest = Nexista_Path::get($this->params['dest'], 'flow'))) { $dest = empty($this->params['dest']) ? NX_PATH_TMP : trim($this->params['dest'], '/') . '/'; } //websvn: stream wrapper if (strpos($dest, "websvn")) { require 'HTTP/WebDAV/Client.php'; } if (!empty($_FILES[$this->params['file']]['tmp_name'])) { $name = $_FILES[$this->params['file']]['name']; $prefix = Nexista_Path::get($this->params['prefix'], "flow"); if ($prefix != '') { $unique_id = $prefix; $name = $unique_id . "_" . $name; } if (!is_dir($dest)) { mkdir($dest, $mode, TRUE); } if (!move_uploaded_file($_FILES[$this->params['file']]['tmp_name'], $dest . $name)) { Nexista_Error::init('Upload action was unable to move uploaded file: ' . $name . '. Check ' . $dest . ' permissions', NX_ERROR_WARNING); return false; } //assign full destination path to flow as it can be useful $res = Nexista_Flow::find('//_files/file'); if ($res->length === 1) { Nexista_Flow::add('new_dir', $dest, $res->item(0)); Nexista_Flow::add('new_name', $dest . $name, $res->item(0)); } //chmod($dest.$name,0644); } return true; }
/** * Applies action * * @return boolean success */ protected function main() { $flow = Nexista_Flow::Singleton('Nexista_Flow'); $file_path = Nexista_Path::parseInlineFlow($this->params['xsl']); $xslfile = NX_PATH_APPS . $file_path; if (!is_file($xslfile)) { Nexista_Error::init('XSL Action - file unavailable: ' . $xslfile, NX_ERROR_FATAL); } $xsl = new DomDocument('1.0', 'UTF-8'); $xsl->substituteEntities = false; $xsl->resolveExternals = false; $xslfilecontents .= file_get_contents($xslfile); $xsl->loadXML($xslfilecontents); $xsl->documentURI = $xslfile; $use_xslt_cache = "yes"; if ($use_xslt_cache != "yes" || !class_exists('xsltCache')) { $xslHandler = new XsltProcessor(); } else { $xslHandler = new xsltCache(); } $xslHandler->importStyleSheet($xsl); $my_output = $xslHandler->transformToXML($flow->flowDocument); if ($my_output === false) { Nexista_Error::init('XSL Action - Error processing XSL file: ' . $xslfile, NX_ERROR_FATAL); return false; } $new_node = $this->params['new_node']; Nexista_Flow::add($new_node, $my_output); return true; }
/** * Returns code for this tag. * * @return string Final code to insert in gate * @see Nexista_Builder::getCode() */ public function getCodeStart() { //block name to insert $blockName = $this->action->getAttribute('name'); //get instance of Application $application = Nexista_Foundry::singleton('Nexista_Foundry'); //get all blocks $x = new DOMXPath($application->sitemapDocument); $blocks = $x->query('//map:block'); //find the one with correct name $found = false; foreach ($blocks as $block) { $name = $block->getAttribute('name'); if ($name == $blockName) { /*insert block section in here. Easiest is to insert with map:block tag and remove the name attribute to prevent parsing of this tag for later inserts*/ $clone = $block->cloneNode(1); $new = $application->sitemapDocument->importNode($clone, 1); $this->action->parentNode->insertBefore($new, $this->action->nextSibling); $found = true; break; } } //nothing found - let's send a warning and return gracefully if (!$found) { Nexista_Error::init('A matching map:block of name: ' . $blockName . ' was not found in sitemap', NX_ERROR_WARNING); return null; } return null; }
/** * process xsl template with Flow xml * * @param string xsl source file * @return string xsl transformation output */ public function process($xslfile) { $flow = Nexista_Flow::Singleton('Nexista_Flow'); // The following can be used with the NYT xslt cache. $use_xslt_cache = "yes"; if (!is_file($xslfile)) { Nexista_Error::init('XSL Handler - Error processing XSL file, it is unavailable: ' . $xslfile, NX_ERROR_FATAL); } if ($use_xslt_cache != "yes" || !class_exists('xsltCache')) { $xsl = new DomDocument('1.0', 'UTF-8'); $xsl->substituteEntities = false; $xsl->resolveExternals = false; $xslfilecontents .= file_get_contents($xslfile); $xsl->loadXML($xslfilecontents); $xsl->documentURI = $xslfile; $xslHandler = new XsltProcessor(); $xslHandler->importStyleSheet($xsl); if (4 == 3 && function_exists('setProfiling')) { $xslHandler->setProfiling("/tmp/xslt-profiling.txt"); } } else { $xslHandler = new xsltCache(); $xslHandler->importStyleSheet($xslfile); } $output = $xslHandler->transformToXML($flow->flowDocument); if ($output === false) { Nexista_Error::init('XSL Handler - Error processing XSL file: ' . $xslfile, NX_ERROR_FATAL); } return $output; }
/** * Loads class parameters * * This function will check if the required parameters * for this class are supplied and will load them into * $this->params array * * @param array &$params class parameters * * @return boolean success */ protected function applyParams(&$params) { $cnt = 0; foreach ($this->params as $key => $val) { if (empty($params[$cnt])) { if ($val == 'required') { Nexista_Error::init('Class ' . get_class($this) . ' does not have the required number of parameters', NX_ERROR_FATAL); } $this->params[$key] = false; } else { $this->params[$key] = $params[$cnt]; } $cnt++; } return true; }
/** * Retrieves a config section * * Retrieves an array of values for a config section. If a mode is set * it will attempt to get the value for these variable in the preferred mode. * If nothing is found, it will then attempt to retrieve the default value in * local config file and will finally look for the default master value. * * @param string $name section path * @param string $id section id for multiple sections with same name * @param string $subsection sub * * @return array empty if nothing found */ public static function getSection($name, $id = false, $subsection = '') { if ($id) { $res = self::$xml->xpath('//config/' . $subsection . $name . '[@id="' . $id . '"]'); $obj = $res[0]; } else { $res = self::$xml->xpath('//config/' . $subsection . $name . '[not(@id)]'); $obj = $res[0]; } $result = array(); if (is_object($obj)) { foreach ($obj->children() as $k => $v) { if (is_null(self::$mode) and (!$v['mode'] or (string) $v['mode'] == $mode)) { $result[$k] = (string) $v; } else { //if child has mode match we use it if ((string) $v['mode'] === self::$mode) { $result[$k] = (string) $v; } elseif (!isset($result[$k])) { //get default value unless a moded one is already in $result[$k] = (string) $v; } } } } else { Nexista_Error::init('The "' . $name . '" section with id ' . $id . ' does not exist in the configuration', NX_ERROR_NOTICE); return false; } return $result; }
/** * Registers session functions * * @param mixed $handler function or an array of class=>method * * @return null */ public static function registerSessionStartHandler($handler) { if (is_callable($handler)) { self::$_sessionStartHandler = $handler; } else { Nexista_Error::init('Session Start Handler is not callable!'); } }
/** * Registers a function to be called on auth session timeout * This function will be called when the user's session times out from * inactivity. It might be used to reshow a login screen. * * @param mixed $handler function or an array of class=>method * * @return null */ public static function registerTimeoutHandler($handler) { if (is_callable($handler)) { self::$_timeoutHandler = $handler; } else { Nexista_Error::init('Auth Timeout Handler Error', NX_ERROR_FATAL); } }
} } if (!empty($x_array)) { // this could be slow, might want to have a setting to turn on / off foreach ($x_array as $value) { if (eregi($value, $_GET['nid'])) { unset($tidy_it); } } } /* END EXCLUSIONS */ if ($tidy_it === true) { Nexista_Init::registerOutputHandler('tidy_output'); } if (!function_exists('tidy_output')) { Nexista_Error::addObserver('display', 'tidy_output'); /** * Error... * * @param object $e error object * * @return null */ function Nexista_builderError($e) { if ($e->getCode() == NX_ERROR_FATAL || $e->getCode() == NX_ERROR_WARNING) { $use_xslt_cache = 'yes'; if ($use_xslt_cache != 'yes' || !class_exists('xsltCache')) { $exceptionXsl = new XsltProcessor(); } else { $exceptionXsl = new xsltCache();
/** * Parses a prepared query for general query type (select,insert,etc...) and * * This method calls MDB2 prepareQuery(), sets the variable types * (see MDB2 docs) and parses a query to determine its type (select,insert.etc...) * and updates $this->queryType with this info. It also looks for * special keyword and replaces them with values accordingly. * This function returns a prepared query handler resource by reference * * @param integer returning prepared query handler * @param integer current loop count * @return boolean success */ private function prepareQuery(&$sql, $loop) { //see if it is a select if (!isset($this->queryType)) { if (eregi("^[[:space:]]*[select|show]", $this->query['sql'])) { $this->queryType = 'select'; } } $count = 1; if (isset($this->query['params'])) { foreach ($this->query['params'] as $val) { $found = true; $path = new Nexista_Flow(); if (!empty($val['name'])) { $value = $path->getByPath($val['name']); if (is_null($value) && $val['type'] == 'integer') { $found = false; } } elseif (!empty($val['array'])) { $array = $path->getByPath($val['array']); if (!is_array($array)) { $array = array($array); } $value = $array[$loop]; } elseif (!empty($val['node-name-array'])) { $array = $path->getByPath($val['node-name-array'], 'ASSOC'); if (!is_array($array)) { $array = array($array); } $key = array_keys($array[$loop]); $value = $key[0]; } else { $found = false; } if ((!$found || $value === 'NaN' || $value === '' || $value == '') && $value !== '0') { $value = $val['default']; } if ($value !== 'NULL') { $type = $val['type']; } if ($value == 'NULL') { $value = NULL; $type = NULL; } if ($value || $value == 0) { $types[] = $type; $data[] = $value; } $count++; } $prep = $this->db->prepare($this->query['sql'], $types); if (PEAR::isError($prep)) { Nexista_Error::init($result->getMessage() . "\n " . $this->queryName, NX_ERROR_FATAL); } $result = $prep->execute($data); $prep->free(); } else { $prep = $this->db->prepare($this->query['sql'], $types); $result = $prep->execute(); $prep->free(); } if (PEAR::isError($result)) { $my_debug_result = ''; //serialize($result); Nexista_Error::init($result->getMessage() . ' in query named ' . $this->queryName . $my_debug_result, NX_ERROR_FATAL); } if ($this->queryType == 'select') { return $result->fetchAll(MDB2_FETCHMODE_ASSOC); } else { return true; } }
<?php /* Plugin Name: Development Output Buffer Plugin URI: Description: Version: 0.1 Copyright: Savonix Corporation Author: Albert Lash License: LGPL */ $development_console = 0; Nexista_Error::addObserver('display', 'Nexista_generalError'); /** * Error... * * @param object $e error object * * @return null */ function Nexista_generalError($e) { if ($e->getCode() == NX_ERROR_FATAL || $e->getCode() == NX_ERROR_WARNING) { $use_xslt_cache = "yes"; if ($use_xslt_cache != "yes" || !class_exists('xsltCache')) { $exceptionXsl = new XsltProcessor(); } else { $exceptionXsl = new xsltCache(); } $xsl = new DomDocument(); $my_xsl_file = NX_PATH_BASE . 'extensions/nexista_error/s/xsl/exception.xsl';
/** * Registers a function to be called if no custom handlers are defined * * This method allows a callable function to be called for standard errors * (i.e. NX_ERROR_FATAL, NX_ERROR_WARNING) to override the default actions. * Note that if a custom handler for an error is defined in the Error:init() * arguments, this function will never be called. * This function should accept 1 argument: reference to the current Error * * @param mixed $_handler a function or an array of class=>method * * @return null */ public static function registerDefaultHandler($_handler) { if (is_callable($_handler)) { self::$_defaultHandler = $_handler; } else { Nexista_Error::init("Error Default Handler is not callable!"); } }
/** * Retrieves database info from global.xml file based * on query type * * @param string datasource name - must match one on global.xml * @param array database parameters (username, host, password, etc) */ private function getDatasource($name, &$datasource) { $datasource = Nexista_Config::getSection('datasource', $name); //Caution: this will output the password as well. //Nexista_Debug::dump($datasource); //Developer note: This is where you set what Datasource handler you would //like to use based on type (<type> in global.xml) switch ($datasource['type']) { case 'mysql': case 'mysqli': case 'sqlite': case 'pgsql': $this->datasourceHandler = 'mdb2sql'; //metabase break; case 'ldap': $this->datasourceHandler = 'ldap'; //ldap break; default: Nexista_Error::init($type . ' datasource type is not supported', NX_ERROR_WARNING); return false; break; } return true; }
$last_visit = gmdate('Y-m-d H:i:s', $user_last_visit); // Remove duplicate roles if (is_array($roles)) { $tmparr = array_unique($roles); $i = 0; foreach ($tmparr as $v) { $newarr[$i] = $v; $i++; } } else { $newarr = $roles; } $newarr = array('phunky_user', 'phunky_admin'); $auth =& new Nexista_Auth(); if (!$auth->registerUser($newarr)) { trigger_error(Nexista_Error::getError() . ' in login.php', WARNING); } $auth->setSessionData('user_id', $user_id); $auth->setSessionData('group_id', $group_id); $auth->setSessionData('username', $username); $auth->setSessionData('last_visit', $last_visit); $auth->setSessionData('last_visit_timestamp', $user_last_visit); //go back where we were called from $redirect = Nexista_Path::get('//_post/redirect', 'flow'); if (isset($_SESSION['NX_AUTH']['requestedUrl']) && !$_SESSION['NX_AUTH']['requestedUrl'] == "") { $redirect = $_SESSION['NX_AUTH']['requestedUrl']; } else { $redirect = Nexista_Config::get('//build/default'); } if ($_GET['nid'] == 'x-login') { echo '<result>Success</result>';
/** * Compiles the final sitemap file * * @param string &$gate xml array path to the gate info * @param string $filename filename of gate for the sitemap file * * @return null */ private function _buildConditions(&$gate, $filename) { if (!$gate->hasAttribute('name')) { Nexista_Error::init('No name for gate', NX_ERROR_FATAL); } //http method $http_method = 'get'; if ($gate->hasAttribute('http_method')) { $http_method = $gate->getAttribute('http_method'); } //cache time $cache = -1; if ($gate->hasAttribute('cache')) { $cache = $gate->getAttribute('cache'); } //cache_control $cache_control = -1; if ($gate->hasAttribute('cache_control')) { $cache_control = $gate->getAttribute('cache_control'); } //content_type $content_type = -1; if ($gate->hasAttribute('content_type')) { $content_type = $gate->getAttribute('content_type'); } //role required $role = -1; if ($gate->hasAttribute('role')) { $role = $gate->getAttribute('role'); } if (preg_match('~^regex:(.*)$~', $gate->getAttribute('name'), $m)) { $match = 'regex'; $name = $m[1]; } else { $match = 'exact'; $name = $gate->getAttribute('name'); } if ($this->debug) { echo "<a href='?nid=" . $name . "'>" . $name . "</a>...<br/>\n"; } $this->sitemap[$match][$http_method . ':' . $name] = array('uri' => $filename, 'role' => $role, 'http_method' => $http_method, 'cache' => $cache, 'cache_control' => $cache_control, 'content_type' => $content_type); $this->sitemap['deprecated'][$name] = array('uri' => $filename, 'role' => $role, 'http_method' => $http_method, 'cache' => $cache, 'cache_control' => $cache_control, 'content_type' => $content_type); }
unset($development_console); } else { // this could be slow, might want to have a setting to turn on / off foreach ($x_array as $value) { if (eregi($value, $_GET['nid'])) { unset($development_console); } } } } /* END EXCLUSIONS */ if ($development_console === true) { Nexista_Init::registerOutputHandler('nexista_devBuffer'); } if (!function_exists('nexista_buildererror')) { Nexista_Error::addObserver('display', 'Nexista_builderError'); /** * Error... * * @param object $e error object * * @return null */ function Nexista_builderError($e) { if ($e->getCode() == NX_ERROR_FATAL || $e->getCode() == NX_ERROR_WARNING) { $use_xslt_cache = 'yes'; if ($use_xslt_cache != 'yes' || !class_exists('xsltCache')) { $exceptionXsl = new XsltProcessor(); } else { $exceptionXsl = new xsltCache();
/** * Registers a function to be called on output * * This function can be used to manipulate the final output before it is * displayed. It can be used to create a caching system, compress output * * The handler should be a callable function or array of object/method as * defined in is_callable php function. It should accept 1 arguments: * 1. The reference to the init class instance * * Note that the Nexista_Init::$_info property contains the current cache value * from the sitemap if set. * * This function should call: * $output = Nexista_Init::run(); * to get the final output. The function is responsible for displaying it. * * @param mixed $handler a function or an array of class=>method * * @return null */ public static function registerOutputHandler($handler) { if (is_callable($handler)) { self::$_outputHandler = $handler; } else { Nexista_Error::init('Init Output Handler is not callable!'); } }
/** * Registers a function to be called on init * * This function will be called when Flow inits and imports * things such as the $_GET, $_POST datasets. This permits the developer * to perform actions before assignement to flow such as stripping tags, etc * This method will be given an array and needs to return an array. * * @param mixed $handler a function or an array of class=>method * * @return null */ public static function registerImportHandler($handler) { if (is_callable($handler)) { self::$_importHandler = $handler; } else { Nexista_Error::init('Flow Import Handler is not callable!'); } }