Exemple #1
0
function nexista_final_notices($cacher = null, $mode)
{
    $server_time = Nexista_Debug::profile();
    $final_notices = "\n<script type=\"text/javascript\">\n    done_loading({$server_time});\n    if (typeof jQuery != 'undefined') {\n        \$(document).ready(function()\n        {\n            done_loading_js();\n        });\n    }\n</script>\n";
    return $final_notices;
}
Exemple #2
0
/**
 * nexista_cache
 *
 * Output buffer utilizing PEAR_Cache
 *
 * @param object $init includes stuff
 *
 * @return boolean
 */
function Nexista_cache($init)
{
    //configuration - move to xml
    $timers = true;
    //necessary stuff no matter what
    $init->process();
    $uid = Nexista_Flow::get('//runtime/user_id');
    $uri = $_SERVER['REQUEST_URI'];
    $cac = NX_PATH_CACHE . 'cache_' . md5($uid) . '_' . md5($uri);
    $exp = $init->getInfo('cacheExpiryTime');
    //first things first - check for if-modified-since
    if ($ims = $_SERVER['HTTP_IF_MODIFIED_SINCE']) {
        if (is_file($cac)) {
            $ims = strtotime($ims);
            $lm = filemtime($cac);
            $etag = md5(file_get_contents($cac));
            //$ctag = $_SERVER['HTTP_IF_NONE_MATCH'];
            if ($lm <= $ims) {
                // Hasn't been modified, is it still fresh?
                $fresh = $lm + $exp - time();
                if ($fresh > 0) {
                    header("HTTP/1.1 304 Not Modified");
                    // If its close to expiring, extend life
                    if ($fresh < $exp / 10) {
                        touch($cac);
                    }
                    exit;
                }
                // if not fresh, it will be rebuilt
            }
        }
    }
    include_once 'Cache/Lite.php';
    /* TODO - Add autocleaning */
    $options = array('cacheDir' => NX_PATH_CACHE, 'caching' => true, 'automaticCleaningFactor' => 0, 'readControl' => false, 'lifeTime' => $exp);
    $cache = new Cache_Lite($options);
    $content_type = $init->getInfo('content_type');
    $cache_control = $init->getInfo('cache_control');
    ob_start();
    ob_start();
    if ($output = $cache->get($uri, $uid)) {
        $cache_type = 'file cache';
        $lm = filemtime($cac);
        header("Last-Modified: " . gmdate('D, d M Y H:i:s', $lm) . " GMT");
    } else {
        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
        $cache_type = "no cache";
        $output = $init->run();
        if ($timers) {
            $server_time = Nexista_Debug::profile();
            if ($content_type == 'text/html') {
                $output = str_replace('</body>', '', $output);
                $output = str_replace('</html>', '', $output);
                $output .= "\n\n<!--\nOriginal request required: {$server_time}! \n-->\n\n";
                $output .= '</body></html>';
            } elseif ($content_type == 'text/css') {
                $output .= "\n/* Original request required: {$server_time}! */";
            }
        }
        if (!is_dir(NX_PATH_CACHE)) {
            @mkdir(NX_PATH_CACHE, 0700, true);
        }
        $cache->save($output, $uri, $uid);
        header("ETag: " . md5($output));
    }
    if ($content_type == 'text/html') {
        $output = str_replace('</body>', '', $output);
        $output = str_replace('</html>', '', $output);
    }
    echo $output;
    if ($timers) {
        $server_time = Nexista_Debug::profile();
        if ($content_type == 'text/html') {
            echo "<!--\n";
            echo "Nexista Cache Information:\n";
            echo "Output generated by {$cache_type} in {$server_time}.\n";
            echo "Output sent with Cache-Control: {$cache_control} headers, which will affect future requests.\n";
            if ($lm > 0) {
                echo " Last modified:  {$lm}. ";
                echo "Cache created: " . gmdate('D, d M Y H:i:s', $lm) . " GMT\n";
            }
            echo "Current time: " . gmdate('D, d M Y H:i:s') . " GMT\n-->\n";
            echo "</body></html>";
        } elseif ($content_type == "text/css") {
            echo "\n/* Output generated by {$cache_type} in {$server_time}. Last modified:  {$lm}. */";
        } elseif ($content_type == "application/javascript") {
            echo "\n// Output generated by {$cache_type} in {$server_time}. Last modified:  {$lm}. ";
        }
    }
    ob_end_flush();
    header('Content-Length: ' . ob_get_length());
    ob_end_flush();
}
Exemple #3
0
 /**
  * Registers current active module
  *
  * This function is used to register the name of the current
  * active module/function in order to help trace debugging and profiling.
  * $type determines the type of message:
  * 'in' - sets function entry
  * 'out' - sets function exit - prints elapsed time
  *
  * @param string $type     type of registration
  * @param string $function module name
  *
  * @return string elapsed time
  */
 public static function register($type, $function)
 {
     switch ($type) {
         case 'in':
             $pos = 0;
             if (isset($GLOBALS['debugTrackModule'])) {
                 $pos = @count($GLOBALS['debugTrackModule']);
             }
             $GLOBALS['debugTrackModule'][$pos]['name'] = $function;
             $GLOBALS['debugTrackModule'][$pos]['startTime'] = microtime();
             $indent = $pos * 6;
             Nexista_Debug::message(str_pad('> ', $indent, '-', STR_PAD_LEFT) . '<b>' . $function . '</b>');
             break;
         case 'out':
             $pos = @count($GLOBALS['debugTrackModule']) - 1;
             $indent = $pos * 6;
             $start_time = $GLOBALS['debugTrackModule'][$pos]['startTime'];
             $GLOBALS['debugTrackModule'][$pos]['elapsedTime'] = Nexista_Debug::profile($start_time);
             Nexista_Debug::message(str_pad('< ', $indent, "-", STR_PAD_LEFT) . '<b>' . $function . ' @ </b>' . $GLOBALS['debugTrackModule'][$pos]['elapsedTime'] . ' seconds');
             unset($GLOBALS['debugTrackModule'][$pos]);
             break;
     }
     // This is for debugging the debug class. Probably don't need this now
     //Nexista_Debug::dump($GLOBALS['debugTrackModule']);
 }
Exemple #4
0
 /**
  * Shutdown and cleanup
  *
  * This method is responsible for shutting down the
  * current request. It will clean up variables,
  * send ob to ouput, etc..
  *
  * @return null
  */
 public function stop()
 {
     Nexista_Debug::register('out', 'total');
     exit;
 }
 /**
  * Accepts an xml file list of items and validates them according
  * to passed criteria.
  *
  * This function will check a number of fields based on criterias
  * passed along with each, such as required, validation type, etc..
  * It will return false if any fails and detailed results including
  * custom error messages are placed in a ValidationHandlerData object,
  * parts of which will be rendered into xmlStream for access from xsl
  *
  *
  * @param   string      the name of the xml data file
  * @param   boolean     (referece) result
  * @return  boolean     success
  */
 public function process($src, &$result)
 {
     //create a validator data object to hold procedure result
     require_once NX_PATH_HANDLERS . 'validatorhandlerdata.php';
     $validatorData = new Nexista_ValidatorHandlerData();
     //load validator file
     $xml = simplexml_load_file($src);
     //get the validator name as specified in xml file. this is used to name array in flow
     $validator_name = (string) $xml['name'];
     if (empty($validator_name)) {
         $validator_name = 'validator';
     }
     //load base validator class
     require_once NX_PATH_CORE . "validator.php";
     foreach ($xml->children() as $param) {
         //get the name of variable to set with good/bad result
         $result_name = (string) $param['name'];
         //process validators for this item
         foreach ($param->children() as $val) {
             $result = true;
             //get type of validator
             $type = (string) $val['type'];
             $required = (string) $val['required'];
             if (empty($required)) {
                 $required = 'false';
             }
             //and its parameters
             $args = preg_split('~(\\040)*,(\\040)*~', (string) $val['params']);
             //load the validator module file based on $type
             require_once NX_PATH_VALIDATORS . trim(strtolower($type)) . ".validator.php";
             //build the class name to load
             $class = 'Nexista_' . trim(ucfirst($type)) . "Validator";
             $validator =& new $class();
             if (!$validator->process($args, $required, $result)) {
                 return false;
             }
             //get any message from the validator
             if ($validator->isEmpty() && $validator->isRequired()) {
                 $text = $validator->getMessage();
             } else {
                 $text = (string) $val['text'];
                 //if no custom message we use default
                 if (empty($text)) {
                     $text = $validator->getMessage();
                 }
             }
             if (!$result) {
                 $validatorData->itemFail($result_name, trim(strtolower($type)), $text);
             }
             unset($validator);
         }
         $result_text = (string) $param['text'];
         if (!empty($result_text) && isset($validatorData->validatorData[$result_name])) {
             $validatorData->itemMessage($result_name, $result_text);
         }
     }
     if ((string) $xml['debug'] === 'true') {
         Nexista_Debug::dump($validatorData->validatorData, $validator_name . ' (validation data) ');
     }
     $result = $validatorData->getResult();
     //1 = valid data
     if (!$result) {
         //assign validator data to Flow
         Nexista_Flow::add($validator_name, $validatorData->validatorData);
     }
     //clean up
     unset($validatorData);
     return true;
 }