예제 #1
0
<?php

/*
Extension Name: google_adsense_plugin.php
Extension URI: http://www.nexista.org/
Description: Ads Google Adsense Code
Version:
Copyright: Savonix Corporation
Author: Albert Lash
License: LGPL
*/
/* TODO - Get this from the database. */
$adsense_account = Nexista_Config::get('./extensions/google_adsense_account/code');
$adsense_xpath = Nexista_Config::get('./extensions/google_adsense_account/xpath');
if ($adsense_xpath) {
    $adsense_account = Nexista_Flow::get($adsense_xpath);
}
if (!($priority = Nexista_Config::get('./extensions/google_adsense_account/priority'))) {
    $priority = 10;
}
$google_adsense_code = <<<EOS
<div style="position: absolute; top: 18px; right: 25px;">
<script type="text/javascript"><!--
google_ad_client = "{$adsense_account}";
google_alternate_color = "FFFFFF"
google_ad_width = 234;
google_ad_height = 60;
google_ad_format = "234x60_as";
google_ad_type = "text";
//2007-10-29: Technology
google_ad_channel = "6222844825";
예제 #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();
}
예제 #3
0
파일: flow.php 프로젝트: savonix/nexista
 /**
  * Returns the value of a flow variable
  *
  * If the value of a variable is CDATA, it will return this. If the 
  * variable contains children nodes, it will return a recursive array
  *
  * @param object $node       a valid DOMElement reference
  * @param string $array_type for single values: associative or numeric array
  *
  * @return mixed string or array of variable contents
  */
 public static function get($node, $array_type = null)
 {
     //see if a text node with no children
     if ($node->childNodes->length == 1 and get_class($node->childNodes->item(0)) == 'DOMText' and !is_null($node->nodeValue)) {
         if ($array_type == 'ASSOC') {
             $nodeName = $node->nodeName;
             $nodeValue = $node->nodeValue;
             $result[$nodeName] = $nodeValue;
             return $result;
         } else {
             return $node->nodeValue;
         }
     } elseif ($node->childNodes->length > 0) {
         $result = array();
         foreach ($node->childNodes as $kid) {
             if ($kid->childNodes->length == 1 and get_class($kid->childNodes->item(0)) == 'DOMText' and !is_null($kid->nodeValue)) {
                 $result[$kid->nodeName] = $kid->nodeValue;
             } else {
                 $result[$kid->nodeName] = Nexista_Flow::get($kid);
             }
         }
         return $result;
     }
     return null;
 }