Example #1
0
 public function __set($k, $v)
 {
     if (!$v instanceof Scratchpad) {
         return NULL;
     }
     return parent::__set($k, $v);
 }
Example #2
0
 public function __set($k, $v)
 {
     if (!$v instanceof Permission) {
         return;
     }
     return parent::__set($k, $v);
 }
Example #3
0
 public function __construct( $data  = NULL, $options = NULL ){
     $options = new GLU( $options );
     if( $data instanceof iterator ) {
         $str = '';
         foreach($data as $v ) $str .= ' ' . $v;
         $data = $str;
     }
     if( is_array( $data ) ) $data = implode(' ', $data );
     $data = preg_split("/[\s,\.\:\/\\\]+/", trim(preg_replace('/[^a-z0-9\s,\.\:\/\\\]/i', '', strtolower($data))));
     $words = array();
     foreach( $data as $word ){
         if( strpos(self::$stopwords, $word . '|') !== FALSE ) continue;
         if( ! $options->disable_stemmer ) $word = PorterStemmer::stem( $word );
         $len = strlen( $word );
         if( $len < 3 || $len > 30 ) continue;
         if( strpos(self::$stopwords, $word . '|') !== FALSE ) continue;
         if( ! isset( $words[ $word ] ) ) $words[ $word ] = 0;
         $words[$word]++;
         if( $len < 6 || $options->disable_soundex ) continue;
         $word = soundex( $word );
         if( ! isset( $words[ $word ] ) ) $words[ $word ] = 0;
         $words[$word]++;
     }
     parent::__construct( $words );
 }
Example #4
0
 public function __get($k)
 {
     $v = parent::__get($k);
     if ($v instanceof User) {
         return $v;
     }
     return $this->anonymous();
 }
Example #5
0
 public function __construct( $words = NULL ){
     
     
     
     
     
     
     parent::__set($word, $id );
 }
Example #6
0
 public function authenticate($digest = NULL, $request_method = NULL)
 {
     if ($digest === NULL) {
         $digest = isset($_SERVER['PHP_AUTH_DIGEST']) ? $_SERVER['PHP_AUTH_DIGEST'] : '';
     }
     if ($request_method === NULL) {
         $request_method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '';
     }
     if (!preg_match('/username="******"]+)"/', $digest, $username) || !preg_match('/nonce="([^"]+)"/', $digest, $nonce) || !preg_match('/response="([^"]+)"/', $digest, $response) || !preg_match('/opaque="([^"]+)"/', $digest, $opaque) || !preg_match('/uri="([^"]+)"/', $digest, $uri)) {
         return FALSE;
     }
     $username = $username[1];
     $nonce = $nonce[1];
     $response = $response[1];
     $opaque = $opaque[1];
     $uri = $uri[1];
     $htpasswd = new GLU(array('realm' => $this->realm));
     if ($this->htpasswd) {
         $htpasswd->dispatch($this->htpasswd);
     }
     if (!isset($htpasswd->{$username})) {
         return FALSE;
     }
     $password = $htpasswd->{$username};
     $A1 = !$this->isMd5($password) ? $this->hashPassword($username, $password) : $password;
     $A2 = md5($request_method . ':' . $uri);
     if (preg_match('/qop="?([^,\\s"]+)/', $digest, $qop) && preg_match('/nc=([^,\\s"]+)/', $digest, $nc) && preg_match('/cnonce="([^"]+)"/', $digest, $cnonce)) {
         $valid_response = md5($A1 . ':' . $nonce . ':' . $nc[1] . ':' . $cnonce[1] . ':' . $qop[1] . ':' . $A2);
     } else {
         $valid_response = md5($A1 . ':' . $nonce . ':' . $A2);
     }
     if ($response != $valid_response) {
         return FALSE;
     }
     return $username;
 }
Example #7
0
 public function __set($k, $v)
 {
     switch ($k) {
         case 'session_id':
             $v = intval($v);
             if ($v < 1) {
                 return NULL;
             }
             break;
         case 'token':
             $v = strval($v);
             if (!preg_match('#^[a-z0-9]{32}$#', $v)) {
                 return NULL;
             }
             break;
         case 'created':
             if (preg_match("#^[0-9]+\$#", $v)) {
                 $v = date('Y/m/d H:i:s', $v);
             }
             $v = strtotime($v);
             if (!$v) {
                 return NULL;
             }
         case 'modified':
             if (preg_match("#^[0-9]+\$#", $v)) {
                 $v = date('Y/m/d H:i:s', $v);
             }
             $v = strtotime($v);
             if (!$v) {
                 return NULL;
             }
         default:
             if (!preg_match('#[a-z][a-z0-9_]+$#', $k)) {
                 return NULL;
             }
             $v = substr(strval($v), 0, 500);
             break;
     }
     return parent::__set($k, $v);
 }
Example #8
0
<?php

// Example of a view-first controller
//find the current dir
$cwd = dirname(__FILE__);
// let's start timing so that later we can display how long it took to run our app.
// this will include the amount of time it took to include the glu framework.
$start = microtime(TRUE);
// include an auto-load function for classes, so that we can
// put all of our related classes into this directory and they
// will be automagically included for us.
include $cwd . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . '__autoload.php';
// We are making a view-first controller, so let's determine our view, shall we? I am calling
// a short snippet that tells me what the name of my view is based on the current url.
$view = GLU::instance($_SERVER)->dispatch(dir::lib . 'extract_view.php');
// set up some arguments
$args = array('view' => $view, 'start' => $start, 'request' => $_REQUEST);
// kick off the app.
// since glu is in the directory (as a symlink), when we start using the glu class here, the main
// glu file is automatically included. later, when we call other classes in our mvc, those classes
// will be automatically included for us as well on the fly.
GLU::instance($args)->dispatch(dir::app . 'main.php');
// EOF
Example #9
0
<?php

include dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . '__autoload.php';
$vars = array('view' => $view, 'start' => $start = microtime(TRUE), 'request' => $input);
ob_start();
GLU::instance($vars)->dispatch(dirname(dirname(__FILE__)) . '/app/main.php');
$output = trim(ob_get_clean());
$dom = new DOMDocument();
$dom->loadHTML($output);
// EOF
Example #10
0
<?php

// This demo shows how to build a very simple html template
//find the current dir
$cwd = dirname(__FILE__);
// include the glu class
include $cwd . DIRECTORY_SEPARATOR . 'glu.php';
// kick off the main glu.
GLU::instance()->dispatch($cwd . '/lib/main.php');
// EOF
Example #11
0
<?php

use Gaia\Glu;
include __DIR__ . '/../../../common.php';
include __DIR__ . '/../../../../tests/assert/dom_installed.php';
if (!isset($input)) {
    $input = NULL;
}
$vars = array('route' => $route, 'start' => $start = microtime(TRUE), 'request' => $input);
ob_start();
GLU::instance($vars)->dispatch(__DIR__ . '/../app/main.php');
$output = trim(ob_get_clean());
$dom = new DOMDocument();
$dom->loadHTML($output);
// EOF
Example #12
0
 public function __set( $k, $v ){
     $k = $this->normalizePath( $k );
     if( ! $k ) return;
     $actions = array();
     if( ! is_array($v) && ! $v instanceof iterator ) return array();
     foreach( $v as $a ){
         $a = $this->normalizeAction($a);
         $actions[] = $a;
     }
     if( count( $actions ) < 1 ) {
         $this->__unset( $this->normalizePath($k) );
         return;
     }
     return parent::__set( $this->normalizePath($k), $actions);
 }
Example #13
0
<?php

use Gaia\Glu;
// Example of a view-first controller
// let's start timing so that later we can display how long it took to run our app.
// this will include the amount of time it took to include the glu framework.
$start = microtime(TRUE);
// include an auto-load function for classes, so that we can
// put all of our related classes into this directory and they
// will be automagically included for us.
include __DIR__ . '/../../common.php';
// We are making a view-first controller, so let's determine our view, shall we? I am calling
// a short snippet that tells me what the name of my view is based on the current url.
$view = GLU::instance($_SERVER)->dispatch(__DIR__ . '/app/lib/extract_view.php');
// set up some arguments
$args = array('view' => $view, 'start' => $start, 'request' => $_REQUEST);
// kick off the app.
// since glu is in the directory (as a symlink), when we start using the glu class here, the main
// glu file is automatically included. later, when we call other classes in our mvc, those classes
// will be automatically included for us as well on the fly.
GLU::instance($args)->dispatch(__DIR__ . '/app/main.php');
// EOF
Example #14
0
<?php

$DIR = realpath(dirname(__FILE__) . '/../../') . DIRECTORY_SEPARATOR;
include_once $DIR . 'glu.php';
include_once $DIR . 'tests/' . DIRECTORY_SEPARATOR . 'taptest.php';
$glu = $message = $code = $result = NULL;
$glu = GLU::instance();
if ($message === NULL) {
    $result = GLU::instance()->exception();
} elseif ($code === NULL) {
    $result = GLU::instance()->exception($message);
} else {
    $result = GLU::instance()->exception($message, $code);
}
Example #15
0
<?php

use Gaia\Glu;
include __DIR__ . '/../../common.php';
$export = $glu = $result_dispatch = $result_export_after_dispatch = $result_export_after_dispatch = $exception = $exception_message = NULL;
try {
    $glu = GLU::instance($arg);
    $export = array();
    foreach ($glu as $k => $v) {
        $export[$k] = $v;
    }
    $result_export_before_dispatch = $export;
    $result_dispatch = $glu->dispatch(__DIR__ . '/lib/string.php');
    $export = array();
    foreach ($glu as $k => $v) {
        $export[$k] = $v;
    }
    $result_export_after_dispatch = $export;
} catch (\Exception $e) {
    $exception = $e;
    $exception_message = $e->getMessage();
}
// EOF
Example #16
0
 public function __get($k)
 {
     return $k == 'title' ? self::pathToName($this->path) : parent::__get($k);
 }
Example #17
0
<?php

// Example of a front-end controller
// let's start timing so that later we can display how long it took to run our app.
// this will include the amount of time it took to include the glu framework.
$start = microtime(TRUE);
// include an auto-load function for classes, so that we can
// put all of our related classes into this directory and they
// will be automagically included for us.
include 'class' . DIRECTORY_SEPARATOR . '__autoload.php';
// determine which controller to call.
$route = GLU::instance($_SERVER)->dispatch(Dir::util . 'extract_route.php');
// kick off the app.
// since glu is in the directory (as a symlink), when we start using the glu class here, the main
// glu file is automatically included. later, when we call other classes in our mvc, those classes
// will be automatically included for us as well on the fly.
GLU::instance(array('start' => $start, 'route' => $route, 'request' => $_REQUEST))->dispatch(Dir::app . 'main.php');
// EOF
Example #18
0
<?php

use Gaia\Glu;
include __DIR__ . '/../../common.php';
// Example of a front-end controller
// let's start timing so that later we can display how long it took to run our app.
// this will include the amount of time it took to include the glu framework.
$start = microtime(TRUE);
// determine which controller to call.
$route = GLU::instance($_SERVER)->dispatch(__DIR__ . '/app/util/extract_route.php');
// kick off the app.
// since glu is in the directory (as a symlink), when we start using the glu class here, the main
// glu file is automatically included. later, when we call other classes in our mvc, those classes
// will be automatically included for us as well on the fly.
GLU::instance(array('start' => $start, 'route' => $route, 'request' => $_REQUEST))->dispatch(__DIR__ . '/app/main.php');
// EOF
Example #19
0
 public function __set($k, $v)
 {
     $v = trim(substr(strval($v), 0, 500));
     switch ($k) {
         case 'user_id':
             if (!$this->isUserId($v)) {
                 return NULL;
             }
             $v = intval($v);
             break;
         case 'nickname':
             if (!$this->isNickname($v)) {
                 return NULL;
             }
             break;
         case 'email':
             if (!$this->isEmail($v)) {
                 return NULL;
             }
             break;
         case 'passhash':
             if (!$this->isPassHash($v)) {
                 return NULL;
             }
             break;
         case 'created':
             if (preg_match("#^[0-9]+\$#", $v)) {
                 $v = date('Y/m/d H:i:s', $v);
             }
             $v = strtotime($v);
             if (!$v) {
                 return NULL;
             }
         case 'modified':
             if (preg_match("#^[0-9]+\$#", $v)) {
                 $v = date('Y/m/d H:i:s', $v);
             }
             $v = strtotime($v);
             if (!$v) {
                 return NULL;
             }
         default:
             if (!preg_match('#[a-z][a-z0-9_]+$#', $k)) {
                 return NULL;
             }
             break;
     }
     return parent::__set($k, $v);
 }
Example #20
0
<?php

// an example of a CLI app.
//find the current dir
$cwd = dirname(__FILE__) . DIRECTORY_SEPARATOR;
// make sure we are running from cli.
if (!is_resource(STDIN)) {
    // exit with an error message for the web browser.
    die('<h1>Please run this from CLI.</h1><h2>Does not work in browser.</h2>');
}
// include glu
include $cwd . 'glu.php';
// kick it off, reading from STDIN
GLU::instance(array('STDIN' => STDIN))->dispatch($cwd . 'app/main.php');
// EOF
Example #21
0
<?php

use Gaia\Glu;
include __DIR__ . '/../../common.php';
$glu = GLU::instance();
foreach (array('result_set', 'result_get', 'result_isset', 'result_unset') as $key) {
    ${$key} = array();
}
if (!isset($input) || !is_array($input)) {
    $input = array();
}
foreach ($input as $k => $v) {
    $result_set[$k] = $glu->{$k} = $v;
    $result_isset[$k] = isset($glu->{$k});
    $result_get[$k] = $glu->{$k};
    unset($glu->{$k});
    $result_unset[$k] = $glu->{$k};
}
 public function __set($k, $v)
 {
     switch ($k) {
         case 'pad':
             if (!$v instanceof Scratchpad) {
                 return NULL;
             }
             break;
         case 'comment':
             if (!$v instanceof Scratchpad) {
                 return NULL;
             }
             break;
         case 'request':
             if (!$v instanceof GLU) {
                 return NULL;
             }
             break;
         case 'server':
             if (!$v instanceof GLU) {
                 return NULL;
             }
             break;
         case 'session':
             if (!$v instanceof Session) {
                 return NULL;
             }
             break;
         case 'user':
             if (!$v instanceof User) {
                 return NULL;
             }
             break;
         case 'author':
             if (!$v instanceof User) {
                 return NULL;
             }
             break;
         case 'permission':
             if (!$v instanceof Permission) {
                 return NULL;
             }
             break;
         case 'NEW':
             if (!$v instanceof Instantiator) {
                 return NULL;
             }
             break;
         case 'headers':
             if (!$v instanceof GLU) {
                 return NULL;
             }
             break;
         case 'dir':
             if (!$v instanceof Dir) {
                 return NULL;
             }
             break;
         case 'list':
             if (!$v instanceof GLU) {
                 return NULL;
             }
             break;
         case 'path':
             $v = '/' . trim(preg_replace('/[^a-z0-9\\/\\_\\-\\.]/', '', strval($v)), ' /');
             break;
         case 'route':
             $v = preg_replace('/[^a-z0-9_\\-]/', '', strval($v));
             break;
         case 'baseurl':
             $v = preg_replace('/[^a-z0-9\\/\\_\\-\\.]/i', '', strval($v));
             break;
         case 'selfurl':
             $v = preg_replace('/[^a-z0-9\\/\\_\\-\\.]/i', '', strval($v));
             break;
         case 'title':
             $v = preg_replace('/[^a-z0-9_\\-\\. ]/i', '', strval($v));
             break;
         case 'START_TIME':
             if (!is_numeric($v)) {
                 return NULL;
             }
             break;
             //default:        print '<pre>' . $k . '</pre>';
     }
     return parent::__set($k, $v);
 }