示例#1
0
 /**
  * Demonstrates how to parse RSS feeds by using DOMDocument.
  */
 function rss()
 {
     // Parse an external atom feed
     $feed = feed::parse('feed:http://github.com/feeds/enormego/commits/EightPHP/master');
     // Show debug info
     echo Eight::debug($feed);
     echo Eight::lang('core.stats_footer');
 }
示例#2
0
 /**
  * Generates a new Captcha challenge.
  *
  * @return  string  the challenge answer
  */
 public function generate_challenge()
 {
     // Load riddles from the current language
     $riddles = Eight::lang('captcha.riddles');
     // Pick a random riddle
     $riddle = $riddles[array_rand($riddles)];
     // Store the question for output
     $this->riddle = $riddle[0];
     // Return the answer
     return $riddle[1];
 }
示例#3
0
 /**
  * Generates a new Captcha challenge.
  *
  * @return  string  the challenge answer
  */
 public function generate_challenge()
 {
     // Load words from the current language and randomize them
     $words = Eight::lang('captcha.words');
     shuffle($words);
     // Loop over each word...
     foreach ($words as $word) {
         // ...until we find one of the desired length
         if (abs(Captcha::$config['complexity'] - strlen($word)) < 2) {
             return strtoupper($word);
         }
     }
     // Return any random word as final fallback
     return strtoupper($words[array_rand($words)]);
 }
示例#4
0
 public function assert_not_pattern($value, $regex, $debug = nil)
 {
     if (!is_string($value) or !is_string($regex) or preg_match($regex, $value)) {
         throw new UnitTest_Exception(Eight::lang('unittest.assert_not_pattern', var_export($value, TRUE), var_export($regex, TRUE)), $debug);
     }
     return $this;
 }
示例#5
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);
     }
 }
示例#6
0
<?php

/**
 * PunBB pagination style
 * 
 * @preview  Pages: 1 … 4 5 6 7 8 … 15
 */
?>

<p class="pagination">

	<?php 
echo Eight::lang('pagination.pages');
?>
:

	<?php 
if ($current_page > 3) {
    ?>
		<a href="<?php 
    echo str_replace('{page}', 1, $url);
    ?>
">1</a>
		<?php 
    if ($current_page != 4) {
        echo '&hellip;';
    }
    ?>
	<?php 
}
?>
                ?>

						<td class="k-error">
							<strong><?php 
                echo Eight::lang('unit_test.error');
                ?>
</strong>
							<pre><?php 
                echo html::specialchars($result->getMessage());
                ?>
</pre>
							<?php 
                echo html::specialchars($result->getFile());
                ?>
 (<?php 
                echo Eight::lang('unit_test.line');
                ?>
&nbsp;<?php 
                echo $result->getLine();
                ?>
)
						</td>

					<?php 
            }
            ?>

				</tr>

			<?php 
        }
示例#8
0
 public function process()
 {
     if ($this->test_mode) {
         $this->fields['demo'] = 'y';
     }
     $this->fields['name'] = $this->fields['first_name'] . ' ' . $this->fields['last_name'];
     $this->fields['shipto_name'] = $this->fields['ship_to_first_name'] . ' ' . $this->fields['ship_to_last_name'];
     unset($this->fields['first_name'], $this->fields['last_name'], $this->fields['ship_to_first_name'], $this->fields['ship_to_last_name']);
     // Check for required fields
     if (in_array(FALSE, $this->required_fields)) {
         $fields = array();
         foreach ($this->required_fields as $key => $field) {
             if (!$field) {
                 $fields[] = $key;
             }
         }
         throw new Eight_Exception('payment.required', implode(', ', $fields));
     }
     $result = tclink_send($this->fields);
     // Report status
     if ($result['status'] == 'approved') {
         return TRUE;
     } elseif ($result['status'] == 'decline') {
         return Eight::lang('payment.error', 'payment_Trustcommerce.decline.' . $result[$result['status'] . 'type']);
     } else {
         return Eight::lang('payment.error', Eight::lang('payment_Trustcommerce.' . $result['status'] . '.' . $result['error']));
     }
 }
示例#9
0
 /**
  * Generates nice test results.
  *
  * @param   boolean  hide passed tests from the report
  * @return  string   rendered test results html
  */
 public function report($hide_passed = nil)
 {
     // No tests found
     if (empty($this->results)) {
         return Eight::lang('unittest.no_tests_found');
     }
     // Hide passed tests from the report?
     $hide_passed = (bool) ($hide_passed !== nil ? $hide_passed : Eight::config('unittest.hide_passed', NO, NO));
     // Render unittest report
     return View::factory('eight/unittest', array('results' => $this->results, 'stats' => $this->stats, 'hide_passed' => $hide_passed))->render();
 }
示例#10
0
/**
 * Loads the configured driver and validates it.
 *
 * @param   string  Text to output
 * @param   array   Key/Value pairs of arguments to replace in the string
 * @return  string  Translated text
 */
function __($string, $args = NULL)
{
    $localized_string = Eight::lang($string, $args);
    if (is_array($localized_string)) {
        $localized_string = $string;
    }
    foreach (arr::c($args) as $k => $v) {
        $localized_string = str_replace($k, $v, $localized_string);
    }
    return $localized_string;
}
示例#11
0
echo $current_last_item;
?>
 <?php 
echo Eight::lang('pagination.of');
?>
 <?php 
echo $total_items;
?>

	| <?php 
if ($next_page) {
    ?>
		<a href="<?php 
    echo str_replace('{page}', $next_page, $url);
    ?>
"><?php 
    echo Eight::lang('pagination.next');
    ?>
&nbsp;&raquo;</a>
	<?php 
} else {
    ?>
		<?php 
    echo Eight::lang('pagination.next');
    ?>
&nbsp;&raquo;
	<?php 
}
?>

</p>
示例#12
0
 public function process()
 {
     // Check for required fields
     if (in_array(FALSE, $this->required_fields)) {
         $fields = array();
         foreach ($this->required_fields as $key => $field) {
             if (!$field) {
                 $fields[] = $key;
             }
         }
         throw new Eight_Exception('payment.required', implode(', ', $fields));
     }
     $fields = '';
     foreach ($this->fields as $key => $value) {
         $fields .= $key . '=' . urlencode($value) . '&';
     }
     $post_url = $this->test_mode ? 'https://test.merchante-solutions.com/mes-api/tridentApi' : 'https://api.merchante-solutions.com/mes-api/tridentApi';
     // Live URL
     $ch = curl_init($post_url);
     // Set custom curl options
     curl_setopt_array($ch, $this->curl_config);
     // Set the curl POST fields
     curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim($fields, "& "));
     // Execute post and get results
     $response = curl_exec($ch);
     curl_close($ch);
     if (!$response) {
         throw new Eight_Exception('payment.gateway_connection_error');
     }
     $response = explode('&', $response);
     foreach ($response as $code) {
         $temp = explode('=', $code);
         $response[$temp[0]] = $temp[1];
     }
     return $response['error_code'] == '000' ? TRUE : Eight::lang('payment.error', Eight::lang('payment_Trident.' . $response['error_code']));
 }
示例#13
0
	<?php 
}
?>


	<?php 
if ($next_page) {
    ?>
		<a href="<?php 
    echo str_replace('{page}', $next_page, $url);
    ?>
">&gt;</a>
	<?php 
}
?>

	<?php 
if ($last_page) {
    ?>
		<a href="<?php 
    echo str_replace('{page}', $last_page, $url);
    ?>
"><?php 
    echo Eight::lang('pagination.last');
    ?>
&nbsp;&rsaquo;</a>
	<?php 
}
?>

</p>
示例#14
0
 /**
  * Return the errors array.
  *
  * @param   boolean  load errors from a lang file
  * @return  array
  */
 public function errors($file = nil, $seperator = false)
 {
     if ($file === nil) {
         return $this->errors;
     } else {
         $errors = array();
         foreach ($this->errors as $input => $error) {
             // Key for this input error
             $key = "{$file}.{$input}.{$error}";
             if (($errors[$input] = Eight::lang($key)) === $key) {
                 // Get the default error message
                 $errors[$input] = Eight::lang("{$file}.{$input}.default");
             }
         }
         if (!$seperator) {
             return $errors;
         } else {
             $string = '';
             $seperator = is_bool($seperator) ? "<br />\n" : $seperator . "\n";
             foreach (arr::c($errors) as $error) {
                 $string .= $error . $seperator;
             }
             return $string;
         }
     }
 }
示例#15
0
 /**
  * Set or return the error messages.
  *
  * @chainable
  * @param   string|array  failed validation function, or an array of messages
  * @param   string        error message
  * @return  object|array
  */
 public function error_messages($func = nil, $message = nil)
 {
     // Set custom error messages
     if (!empty($func)) {
         if (is_array($func)) {
             // Replace all
             $this->error_messages = $func;
         } else {
             if (empty($message)) {
                 // Single error, replaces all others
                 $this->error_messages = $func;
             } else {
                 // Add custom error
                 $this->error_messages[$func] = $message;
             }
         }
         return $this;
     }
     if (!$this->formation->submitted()) {
         return array();
     }
     // Make sure validation runs
     is_null($this->is_valid) and $this->validate();
     // Return single error
     if (!is_array($this->error_messages) and !empty($this->errors)) {
         return array($this->error_messages);
     }
     $messages = array();
     foreach ($this->errors as $func => $args) {
         if (is_string($args)) {
             $error = $args;
         } else {
             // Force args to be an array
             $args = is_array($args) ? $args : array();
             // Add the label or name to the beginning of the args
             array_unshift($args, $this->label ? utf8::strtolower($this->label) : $this->name);
             if (isset($this->error_messages[$func])) {
                 // Use custom error message
                 $error = vsprintf($this->error_messages[$func], $args);
             } else {
                 // Get the proper i18n entry, very hacky but it works
                 switch ($func) {
                     case 'valid_url':
                     case 'valid_email':
                     case 'valid_ip':
                         // Fetch an i18n error message
                         $error = Eight::lang('validation.' . $func, $args);
                         break;
                     case substr($func, 0, 6) === 'valid_':
                         // Strip 'valid_' from func name
                         $func = substr($func, 0, 6) === 'valid_' ? substr($func, 6) : $func;
                     case 'alpha':
                     case 'alpha_dash':
                     case 'digit':
                     case 'numeric':
                         // i18n strings have to be inserted into valid_type
                         $args[] = Eight::lang('validation.' . $func);
                         $error = Eight::lang('validation.valid_type', $args);
                         break;
                     default:
                         $error = Eight::lang('validation.' . $func, $args);
                 }
             }
         }
         // Add error to list
         $messages[] = $error;
     }
     return $messages;
 }