示例#1
0
 /**
  * Get styles for table.
  *
  * @return  string
  */
 public function styles()
 {
     static $styles_output;
     if (!$styles_output) {
         $styles_output = YES;
         return file_get_contents(Eight::find_file('views', 'profiler/table', NO, 'css'));
     }
     return '';
 }
示例#2
0
 /**
  * Sets the view filename.
  *
  * @chainable
  * @param   string  view filename
  * @param   string  view file type
  * @return  object
  */
 public function set_filename($name, $type = nil)
 {
     if ($type === nil) {
         // Load the filename and set the content type
         $this->eight_filename = Eight::find_file('views', $name, YES);
         $this->eight_filetype = EXT;
     } else {
         // Load the filename and set the content type
         $this->eight_filename = Eight::find_file('views', $name, YES, $type);
         $this->eight_filetype = Eight::config('mimes.' . $type);
         if ($this->eight_filetype === nil) {
             // Use the specified type
             $this->eight_filetype = $type;
         }
     }
     return $this;
 }
示例#3
0
 public static function factory($controller)
 {
     $controller_file = strtolower($controller);
     // Set controller class name
     $controller = 'Controller_' . ucfirst($controller);
     if (!class_exists($controller, FALSE)) {
         // If the file doesn't exist, just return
         if (($filepath = Eight::find_file('classes/controllers', $controller_file)) === FALSE) {
             return FALSE;
         }
         // Include the Controller file
         require_once $filepath;
     }
     // Run system.pre_controller
     Event::run('dispatch.pre_controller');
     // Initialize the controller
     $controller = new $controller();
     // Run system.post_controller_constructor
     Event::run('dispatch.post_controller_constructor');
     return new Dispatch($controller);
 }
示例#4
0
?>
 &mdash; <?php 
echo $code;
?>
</title>
<base href="http://php.net/" />
</head>
<body>
<div id="framework_error" style="width:900px;margin:20px auto;">
<?php 
// Unique error identifier
$error_id = uniqid('error');
?>
<style type="text/css">
<?php 
include Eight::find_file('views', 'eight/errors', FALSE, 'css');
?>
</style>
<script type="text/javascript">
	document.write('<style type="text/css"> .collapsed { display: none; } </style>');
	function eight_toggle(elem)
	{
		elem = document.getElementById(elem);
		
		if (elem.style && elem.style['display']) 
			// Only works with the "style" attr
			var disp = elem.style['display'];
		else 
			if (elem.currentStyle) 
				// For MSIE, naturally
				var disp = elem.currentStyle['display'];
示例#5
0
 /**
  * Converts markdown syntax to html.
  *
  * @param   string  markdown string
  * @return  string
  */
 public static function markdown2html($str)
 {
     require_once Eight::find_file('vendor', 'Markdown');
     return Markdown($str);
 }
示例#6
0
<?php

echo form::open($action, $attributes);
?>

<?php 
include Eight::find_file('views', 'eight/form_errors');
?>

<fieldset>
<?php 
foreach ($inputs as $title => $input) {
    ?>
<label><span><?php 
    echo $title;
    ?>
</span><?php 
    echo form::input($input);
    ?>
</label>
<?php 
}
?>
</fieldset>

<fieldset class="submit"><?php 
echo html::anchor($cancel, 'Cancel'), ' ', form::button(nil, 'Save');
?>
</fieldset>

<?php 
示例#7
0
 /**
  * exception handler, displays the error message, source of the
  * exception, and the stack trace of the error.
  *
  * @uses    Eight::lang()
  * @uses    Eight_Exception::text()
  * @param   object   exception object
  * @return  void
  */
 public static function handle(Exception $e)
 {
     try {
         // Get the exception information
         $type = get_class($e);
         $code = $e->getCode();
         $message = $e->getMessage();
         // Create a text version of the exception
         $error = Eight_Exception::text($e);
         // Add this exception to the log
         Eight::log('error', $error);
         // Manually save logs after exceptions
         Eight::log_save();
         if (Eight::config('core.display_errors') === FALSE && Eight::$force_show_errors !== YES) {
             // Do not show the details
             $file = $line = NULL;
             $trace = array();
             $template = '_disabled';
         } else {
             $file = $e->getFile();
             $line = $e->getLine();
             $trace = $e->getTrace();
             $template = Eight::$server_api == 'cli' ? '_cli' : '';
         }
         if (Eight::$server_api != 'cli') {
             header("Content-Type: text/html;charset=utf-8");
         }
         if ($e instanceof Eight_Exception) {
             $template = $e->getTemplate() . $template;
             if (!headers_sent()) {
                 $e->sendHeaders();
             }
             // Use the human-readable error name
             $code = Eight::lang('4' . $code);
         } else {
             $template = Eight_Exception::$template . $template;
             if (!headers_sent()) {
                 header('HTTP/1.1 500 Internal Server Error');
             }
             if ($e instanceof ErrorException) {
                 // Use the human-readable error name
                 $code = Eight::lang('4' . $e->getSeverity());
                 if (version_compare(PHP_VERSION, '5.3', '<')) {
                     // Workaround for a bug in ErrorException::getTrace() that exists in
                     // all PHP 5.2 versions. @see http://bugs.php.net/45895
                     for ($i = count($trace) - 1; $i > 0; --$i) {
                         if (isset($trace[$i - 1]['args'])) {
                             // Re-position the arguments
                             $trace[$i]['args'] = $trace[$i - 1]['args'];
                             unset($trace[$i - 1]['args']);
                         }
                     }
                 }
             }
         }
         // Clean the output buffer if one exists
         ob_get_level() and ob_clean();
         if ($template = Eight::find_file('views', $template)) {
             include $template;
         }
     } catch (Exception $e) {
         // Clean the output buffer if one exists
         ob_get_level() and ob_clean();
         // Display the exception text
         echo Eight_Exception::text($e), "\n";
         // Exit with an error code
         exit(1);
     }
 }
示例#8
0
 /**
  * Attempts to autoload tests
  */
 public function __autoload($class)
 {
     if (!str::starts_with($class, 'test_')) {
         return FALSE;
     }
     if (class_exists($class, FALSE)) {
         return TRUE;
     }
     $filename = str_replace('test/', 'tests/', str_replace('_', '/', strtolower($class)));
     if (!($path = Eight::find_file('classes', $filename, FALSE))) {
         return FALSE;
     }
     require $path;
     return TRUE;
 }
示例#9
0
文件: fb.php 项目: enormego/EightPHP
<?php

/**
 * Eight compatible library wrapped around the Facebook library
 *
 * @package		Modules
 * @subpackage	Facebook
 * @author		EightPHP Development Team
 * @copyright	(c) 2009-2010 EightPHP
 * @license		http://license.eightphp.com
 */
// Include Facebook Vendor Files
include Eight::find_file('vendor/facebook', 'facebook', TRUE);
class Fb_Core extends Facebook
{
    public function __construct()
    {
        parent::__construct(Eight::config('facebook.api_key'), Eight::config('facebook.secret'));
    }
    /**
     * Method: user
     * 		Provides an easy way to get information about the current user.
     * 		A single field can be passed as a string or multiple fields via an array 
     */
    public function user($info = array())
    {
        if (!is_array($info)) {
            $info = array($info);
        }
        // Use the API client to fetch info about the current user
        return $this->api_client->users_getInfo($this->user, $info);
示例#10
0
 /**
  * Quick debugging of any variable.
  *
  * @return  NULL
  */
 public static function debug($var)
 {
     require_once Eight::find_file('vendor', 'dBug');
     new dBug($var, NULL, TRUE);
 }
示例#11
0
 /**
  * Clean cross site scripting exploits from string.
  * HTMLPurifier may be used if installed, otherwise defaults to built in method.
  * Note - This function should only be used to deal with data upon submission.
  * It's not something that should be used for general runtime processing
  * since it requires a fair amount of processing overhead.
  *
  * @param   string  data to clean
  * @param   string  xss_clean method to use ('htmlpurifier' or defaults to built-in method)
  * @return  string
  */
 public function xss_clean($data, $tool = nil)
 {
     if ($tool === nil) {
         // Use the default tool
         $tool = Eight::config('core.global_xss_filtering');
     }
     if (is_array($data)) {
         foreach ($data as $key => $val) {
             $data[$key] = $this->xss_clean($val, $tool);
         }
         return $data;
     }
     // Do not clean empty strings
     if (trim($data) === '') {
         return $data;
     }
     if ($tool === YES) {
         // NOTE: This is necessary because switch is NOT type-sensative!
         $tool = 'default';
     }
     switch ($tool) {
         case 'htmlpurifier':
             /**
              * @todo License should go here, http://htmlpurifier.org/
              */
             if (!class_exists('HTMLPurifier_Config', NO)) {
                 // Load HTMLPurifier
                 require Eight::find_file('vendor', 'htmlpurifier/HTMLPurifier.auto', YES);
                 require 'HTMLPurifier.func.php';
             }
             // Set configuration
             $config = HTMLPurifier_Config::createDefault();
             $config->set('HTML', 'TidyLevel', 'none');
             // Only XSS cleaning now
             // Run HTMLPurifier
             $data = HTMLPurifier($data, $config);
             break;
         default:
             // http://svn.bitflux.ch/repos/public/popoon/trunk/classes/externalinput.php
             // +----------------------------------------------------------------------+
             // | Copyright (c) 2001-2006 Bitflux GmbH                                 |
             // +----------------------------------------------------------------------+
             // | Licensed under the Apache License, Version 2.0 (the "License");      |
             // | you may not use this file except in compliance with the License.     |
             // | You may obtain a copy of the License at                              |
             // | http://www.apache.org/licenses/LICENSE-2.0                           |
             // | Unless required by applicable law or agreed to in writing, software  |
             // | distributed under the License is distributed on an "AS IS" BASIS,    |
             // | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or      |
             // | implied. See the License for the specific language governing         |
             // | permissions and limitations under the License.                       |
             // +----------------------------------------------------------------------+
             // | Author: Christian Stocker <*****@*****.**>                        |
             // +----------------------------------------------------------------------+
             //
             // Eight Modifications:
             // * Changed double quotes to single quotes, changed indenting and spacing
             // * Removed magic_quotes stuff
             // * Increased regex readability:
             //   * Used delimeters that aren't found in the pattern
             //   * Removed all unneeded escapes
             //   * Deleted U modifiers and swapped greediness where needed
             // * Increased regex speed:
             //   * Made capturing parentheses non-capturing where possible
             //   * Removed parentheses where possible
             //   * Split up alternation alternatives
             //   * Made some quantifiers possessive
             // Fix &entity\n;
             $data = str_replace(array('&amp;', '&lt;', '&gt;'), array('&amp;amp;', '&amp;lt;', '&amp;gt;'), $data);
             $data = preg_replace('/(&#*\\w+)[\\x00-\\x20]+;/u', '$1;', $data);
             $data = preg_replace('/(&#x*[0-9A-F]+);*/iu', '$1;', $data);
             $data = html_entity_decode($data, ENT_COMPAT, 'UTF-8');
             // Remove any attribute starting with "on" or xmlns
             $data = preg_replace('#(<[^>]+?[\\x00-\\x20"\'])(?:on|xmlns)[^>]*+>#iu', '$1>', $data);
             // Remove javascript: and vbscript: protocols
             $data = preg_replace('#([a-z]*)[\\x00-\\x20]*=[\\x00-\\x20]*([`\'"]*)[\\x00-\\x20]*j[\\x00-\\x20]*a[\\x00-\\x20]*v[\\x00-\\x20]*a[\\x00-\\x20]*s[\\x00-\\x20]*c[\\x00-\\x20]*r[\\x00-\\x20]*i[\\x00-\\x20]*p[\\x00-\\x20]*t[\\x00-\\x20]*:#iu', '$1=$2nojavascript...', $data);
             $data = preg_replace('#([a-z]*)[\\x00-\\x20]*=([\'"]*)[\\x00-\\x20]*v[\\x00-\\x20]*b[\\x00-\\x20]*s[\\x00-\\x20]*c[\\x00-\\x20]*r[\\x00-\\x20]*i[\\x00-\\x20]*p[\\x00-\\x20]*t[\\x00-\\x20]*:#iu', '$1=$2novbscript...', $data);
             $data = preg_replace('#([a-z]*)[\\x00-\\x20]*=([\'"]*)[\\x00-\\x20]*-moz-binding[\\x00-\\x20]*:#u', '$1=$2nomozbinding...', $data);
             // Only works in IE: <span style="width: expression(alert('Ping!'));"></span>
             $data = preg_replace('#(<[^>]+?)style[\\x00-\\x20]*=[\\x00-\\x20]*[`\'"]*.*?expression[\\x00-\\x20]*\\([^>]*+>#i', '$1>', $data);
             $data = preg_replace('#(<[^>]+?)style[\\x00-\\x20]*=[\\x00-\\x20]*[`\'"]*.*?behaviour[\\x00-\\x20]*\\([^>]*+>#i', '$1>', $data);
             $data = preg_replace('#(<[^>]+?)style[\\x00-\\x20]*=[\\x00-\\x20]*[`\'"]*.*?s[\\x00-\\x20]*c[\\x00-\\x20]*r[\\x00-\\x20]*i[\\x00-\\x20]*p[\\x00-\\x20]*t[\\x00-\\x20]*:*[^>]*+>#iu', '$1>', $data);
             // Remove namespaced elements (we do not need them)
             $data = preg_replace('#</*\\w+:\\w[^>]*+>#i', '', $data);
             do {
                 // Remove really unwanted tags
                 $old_data = $data;
                 $data = preg_replace('#</*(?:applet|b(?:ase|gsound|link)|embed|frame(?:set)?|i(?:frame|layer)|l(?:ayer|ink)|meta|object|s(?:cript|tyle)|title|xml)[^>]*+>#i', '', $data);
             } while ($old_data !== $data);
             break;
     }
     return $data;
 }
示例#12
0
 /**
  * Demonstrates how to use vendor software with Eight.
  */
 function vendor()
 {
     // Let's do a little Markdown shall we.
     $br = "\n\n";
     $output = '#Marked Down!#' . $br;
     $output .= 'This **_markup_** is created *on-the-fly*, by ';
     $output .= '[php-markdown-extra](http://michelf.com/projects/php-markdown/extra)' . $br;
     $output .= 'It\'s *great* for user <input> & writing about `<HTML>`' . $br;
     $output .= 'It\'s also good at footnotes :-) [^1]' . $br;
     $output .= '[^1]: A footnote.';
     // looks in system/vendor for Markdown.php
     require Eight::find_file('vendor', 'Markdown');
     echo Markdown($output);
     echo 'done in {execution_time} seconds';
 }
示例#13
0
 /**
  * Sets the view filename.
  *
  *     $view->set_filename($file);
  *
  * @param   string  view filename
  * @return  View
  * @throws  Eight_View_Exception
  */
 public function set_filename($file)
 {
     if (($path = Eight::find_file('views', $file)) === FALSE) {
         throw new Eight_Exception('The requested view: ' . $file . ', could not be found');
     }
     // Store the file path locally
     $this->_file = $path;
     return $this;
 }
示例#14
0
 /**
  * Quick debugging of any variable.
  *
  * @return  NULL
  */
 public static function debug($var)
 {
     if (self::$server_api == 'cli') {
         var_dump($var);
     } else {
         require_once Eight::find_file('vendor', 'dBug');
         new dBug($var, NULL, TRUE);
     }
 }
示例#15
0
 /**
  * Creates a SwiftMailer instance.
  *
  * @param   string  DSN connection string
  * @return  object  Swift object
  */
 public static function connect($config = nil)
 {
     if (!class_exists('Swift', NO)) {
         // Load SwiftMailer
         require Eight::find_file('vendor', 'swift/Swift');
         // Register the Swift ClassLoader as an autoload
         spl_autoload_register(array('Swift_ClassLoader', 'load'));
     }
     // Load default configuration
     $config === nil and $config = Eight::config('email');
     switch ($config['driver']) {
         case 'smtp':
             // Set port
             $port = empty($config['options']['port']) ? nil : (int) $config['options']['port'];
             if (empty($config['options']['encryption'])) {
                 // No encryption
                 $encryption = Swift_Connection_SMTP::ENC_OFF;
             } else {
                 // Set encryption
                 switch (strtolower($config['options']['encryption'])) {
                     case 'tls':
                         $encryption = Swift_Connection_SMTP::ENC_TLS;
                         break;
                     case 'ssl':
                         $encryption = Swift_Connection_SMTP::ENC_SSL;
                         break;
                 }
             }
             // Create a SMTP connection
             $connection = new Swift_Connection_SMTP($config['options']['hostname'], $port, $encryption);
             // Do authentication, if part of the DSN
             empty($config['options']['username']) or $connection->setUsername($config['options']['username']);
             empty($config['options']['password']) or $connection->setPassword($config['options']['password']);
             if (!empty($config['options']['auth'])) {
                 // Get the class name and params
                 list($class, $params) = arr::callback_string($config['options']['auth']);
                 if ($class === 'PopB4Smtp') {
                     // Load the PopB4Smtp class manually, due to its odd filename
                     require Eight::find_file('vendor', 'swift/Swift/Authenticator/$PopB4Smtp$');
                 }
                 // Prepare the class name for auto-loading
                 $class = 'Swift_Authenticator_' . $class;
                 // Attach the authenticator
                 $connection->attachAuthenticator($params === nil ? new $class() : new $class($params[0]));
             }
             // Set the timeout to 5 seconds
             $connection->setTimeout(empty($config['options']['timeout']) ? 5 : (int) $config['options']['timeout']);
             break;
         case 'sendmail':
             // Create a sendmail connection
             $connection = new Swift_Connection_Sendmail(empty($config['options']) ? Swift_Connection_Sendmail::AUTO_DETECT : $config['options']);
             // Set the timeout to 5 seconds
             $connection->setTimeout(5);
             break;
         default:
             // Use the native connection
             $connection = new Swift_Connection_NativeMail($config['options']);
             break;
     }
     // Create the SwiftMailer instance
     return email::$mail = new Swift($connection);
 }
示例#16
0
<!-- Profiler Starts -->
<style type="text/css">
<?php 
echo file_get_contents(Eight::find_file('views', 'profiler/profiler', NO, 'css'));
echo $styles;
?>
</style>

<?
$style='';
$x = 0 + Eight::config('profiler.offset.x');
$y = 0 + Eight::config('profiler.offset.y');

switch(Eight::config('profiler.position')) {
	case 'top_left':
		$style .= 'top: '.$y.'px; left: '.$x.'px;';
		break;
	case 'top_right':
		$style .= 'top: '.$y.'px; right: '.$x.'px;';
		break;
	case 'btm_left':
		$style .= 'bottom: '.$y.'px; left: '.$x.'px;';
		break;
	case 'btm_right':
		$style .= 'bottom: '.$y.'px; right: '.$x.'px;';
		break;
}

$style = 'style="'.$style.'"';

?>