Example #1
0
 * 
 * Atto::loaderから呼ばれます
 * 
 * @param {string} $class_name 
 */
function app_auto_loder($class_name)
{
}
/**
 * app_session
 * 
 * @staticvar {boolean} $started
 * @param {boolean} $start
 * @return {boolean} 
 */
function app_session($start = true)
{
    static $started = false;
    if ($start && !$started) {
        $started = true;
        if (stristr($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {
            AttoHttpHelper::setHeader('p3p', 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"');
        }
        $current_cookie_params = session_get_cookie_params();
        //		session_set_cookie_params(
        //				$current_cookie_params['lifetime'], $current_cookie_params['path'], '.' . atto::domain()
 /**
  * @Override 
  */
 public function render()
 {
     $file = Atto::makeAccessPath(array(Atto::dir_error(), Atto::dir_atto_error()), array($this->status, 'etc'), array('.html', '.php'));
     $this->error_message = $this->getMessage();
     $this->title = $this->status . '  ' . AttoHttpHelper::getTextByResponseCode($this->status);
     AttoHttpHelper::setResponseCode($this->status);
     include $file;
 }
 /**
  * dispatch
  *
  * @method dispatch
  */
 public function dispatch()
 {
     $pathinfo_blocks = explode('/', ltrim(Atto::uri(), '\\'));
     $i = count($pathinfo_blocks) - 1;
     if ($pathinfo_blocks[$i] === '') {
         $file_names = array('index.html', 'index.php');
     } else {
         $file_names = array($pathinfo_blocks[$i]);
         $pathinfo_blocks[$i] = '';
     }
     $request_dir = implode(DS, $pathinfo_blocks);
     $hook_file = Atto::makeAccessPath(Atto::dir_hook() . $request_dir, $file_names, array('', '.php'));
     $htdocs_file = Atto::makeAccessPath(Atto::dir_htdocs() . $request_dir, $file_names);
     $huck_file = Atto::makeAccessPath(Atto::dir_huck() . $request_dir, $file_names, array('', '.php'));
     $view_file = null;
     if ($hook_file === '' && $htdocs_file === '' && $huck_file === '') {
         // not found
         $view_file = Atto::makeAccessPath(array(Atto::dir_error(), Atto::dir_atto_error()), array(404, 'etc'), array('.html', '.php'));
         $this->title = '404  ' . AttoHttpHelper::getTextByResponseCode(404);
         $this->error_message = '';
         AttoHttpHelper::setResponseCode(404);
         $this->funcs->view = array($this, '___view___');
     } else {
         if ($htdocs_file !== '' && is_dir($htdocs_file)) {
             // access to the directory
             $redirect_URIs = explode('?', Atto::requestUrl());
             $redirect_URIs[0] .= '/';
             AttoHttpHelper::redirect(implode('?', $redirect_URIs), 301);
         }
         if ($htdocs_file && is_file($htdocs_file)) {
             $this->files->view = $htdocs_file;
         }
         if ($hook_file && is_file($hook_file)) {
             $this->files->hook = $hook_file;
         }
         if ($huck_file && is_file($huck_file)) {
             $this->files->huck = $huck_file;
         }
     }
     $this->before();
     $this->hook();
     $content = $this->view();
     $this->render($content);
     $this->huck();
     $this->after();
 }
Example #4
0
    /**
     * cascade
     *
     * @method cascade
     * @param mixed $callback
     * @param array $options
     * @throws Exception 
     */
    public static function cascade($callback, array $options = array())
    {
        // options init
        self::$_options = array_merge(self::$_options, $options);
        $init = create_function('', '
			require Atto::dir_atto_common() . \'init.php\';
			require Atto::dir_common() . \'init.php\';');
        $init();
        if (self::$_options['hide_gate']) {
            if (starts_with(Atto::gateScriptUri(), Atto::requestUri())) {
                AttoHttpHelper::redirect(Atto::uri());
            }
        }
        // timezone
        if (function_exists('date_default_timezone_set')) {
            date_default_timezone_set(self::$_options['admin_teimezone']);
        }
        // error_log
        if (self::$_options['error_log']) {
            self::errorHandlerRegister(array('AttoErrorToLog', 'publish'));
        }
        set_error_handler(create_function('$errno , $errstr, $errfile, $errline, $errcontext', '
				// callback
				foreach ( Atto::errorHandlerRegister() as $callback ) {
					$res = call_user_func( $callback, $errno , $errstr, $errfile, $errline, $errcontext );
					if ( $res === false ) {
						return $res;
					}
				}'));
        if (function_exists('set_exception_handler')) {
            // exception_log
            if (self::$_options['exception_log']) {
                self::exceptionHandlerRegister(array('AttoExceptionToLog', 'publish'));
            }
            set_exception_handler(create_function('$e', '
					// callback
					foreach ( Atto::exceptionHandlerRegister() as $callback ) {
						$res = call_user_func( $callback, $e );
						if ( $res === false ) {
							return $res;
						}
					}'));
        }
        // gzip
        if (function_exists('ob_gzhandler')) {
            self::publishHandlerRegister(create_function('$content, $mode', '
					$zlab_output_compression = ini_get( "zlib.output_compression" );
					if ( !$zlab_output_compression
							|| $zlab_output_compression == "0"
							|| strtolower( $zlab_output_compression ) == "off" ) {

						$content_encoding = Atto::serchHeader( "/^Content-Encoding:/iu" );
						if ( $content_encoding === false && Atto::isGzipContentType() ) {
							return ob_gzhandler( $content, $mode );
						}
					}
					return $content;'));
        }
        set_include_path(get_include_path() . PATH_SEPARATOR . Atto::dir_app());
        // callback
        if (!is_callable($callback)) {
            $callback = array($callback, '__invoke');
            // PHP < 5.3
            if (!is_callable($callback)) {
                throw new Exception('Callees of the callback is unknown');
            }
        }
        // publishHandler
        ob_start(create_function('$content, $mode', '
				// header
				Atto::overrideXpowerdBy();
				if ( Atto::isDebug() ) {
					header( "ElapsedMicrotime: " . Atto::getElapsedMicrotime() );
				}
				if ( class_exists( "AttoHttpHelper", false ) ) {
					AttoHttpHelper::outputHeaders();
				}
				// callback
				foreach ( Atto::publishHandlerRegister() as $callback ) {
					$res = call_user_func( $callback, $content, $mode );
					if ( $res !== false ) {
						$content = $res;
					}
				}
				return $content;'));
        ob_implicit_flush(false);
        try {
            self::_plugsInsertion();
            call_user_func($callback, self::uri());
        } catch (AttoAbstractHasRenderException $e) {
            $content = ob_get_contents();
            if (!$content) {
                $content = '';
            } else {
                ob_clean();
            }
            $e->render($content);
        } catch (Exception $e) {
            $render = array($e, 'render');
            if (is_callable($render)) {
                $content = ob_get_contents();
                if (!$content) {
                    $content = '';
                } else {
                    ob_clean();
                }
                call_user_func($render, $content);
            } else {
                throw $e;
            }
        }
        ob_end_flush();
    }
Example #5
0
 /**
  * isDisapproveFingerprint
  * 
  * @method isDisapproveFingerprint
  * @param string $salt 
  * @return boolean
  */
 public static function isDisapproveFingerprint($salt)
 {
     if (self::isNotExistsForFingerprint()) {
         return true;
     }
     $session_id = session_id();
     $fingerprint = self::_generateFingerprint($salt, $session_id);
     if ($fingerprint !== $_SESSION[self::FINGER_PRINT_KEY]) {
         AttoFilebaseLogger::logging(3, 'session hijack !?', array('host' => AttoHttpHelper::getRemoteHost(), '$_SERVER' => $_SERVER, '$_REQUEST' => $_REQUEST, '$_SESSION' => $_SESSION));
         unset($_SESSION[self::FINGER_PRINT_KEY]);
         return true;
     }
     return false;
 }
Example #6
0
 /**
  * setResponseCode
  * 
  * @method setResponseCode
  * @param {int} $response_code 
  */
 public static function setResponseCode($response_code)
 {
     if (self::$_headers !== null) {
         self::$_headers = array();
     }
     $text = self::getTextByResponseCode($response_code);
     $protocol = $_SERVER['SERVER_PROTOCOL'];
     if ('HTTP/1.1' != $protocol && 'HTTP/1.0' != $protocol) {
         $protocol = 'HTTP/1.1';
     }
     $value = $protocol . ' ' . $response_code . ' ' . $text;
     self::$_headers[] = array('value' => $value, 'response_code' => $response_code);
 }