Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic PHP7 compatibility #89

Open
wants to merge 1 commit into
base: 0.9.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions classes/colorutils.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function hex_rgb( $hex_string )
{
$hex_string = ltrim( $hex_string, '#' );
if ( ! preg_match( '/^[0-9a-f]+$/i', $hex_string ) ) {
return Error::raise( _t( 'Not a valid hex color.' ) );
return HabariError::raise( _t( 'Not a valid hex color.' ) );
}

$normalized = '';
Expand All @@ -54,7 +54,7 @@ public static function hex_rgb( $hex_string )
$normalized = $hex_string . str_repeat( '0', 6 - strlen( $hex_string ) );
break;
default:
return Error::raise( _t( 'Not a valid color format.' ) );
return HabariError::raise( _t( 'Not a valid color format.' ) );
}

return self::rgb_rgbarr(
Expand Down
46 changes: 23 additions & 23 deletions classes/error.php → classes/habarierror.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
* Contains error-related functions and Habari's error handler.
*
**/
class Error extends Exception
class HabariError extends Exception
{
protected $message = '';
protected $is_error = false;

/**
* Constructor for the Error class
* Constructor for the HabariError class
*
* @param string $message Exception to display
* @param integer $code Code of the exception
* @param boolean $is_error true if the exception represents an error handled by the Error class
* @param boolean $is_error true if the exception represents an error handled by the HabariError class
*/
public function __construct( $message = 'Generic Habari Error', $code = 0, $is_error = false )
public function __construct( $message = 'Generic Habari HabariError', $code = 0, $is_error = false )
{
parent::__construct( $message, $code );
$this->is_error = $is_error;
Expand All @@ -29,13 +29,13 @@ public function __construct( $message = 'Generic Habari Error', $code = 0, $is_e
/**
* function handle_errors
*
* Configures the Error class to handle all errors.
* Configures the HabariError class to handle all errors.
*/
public static function handle_errors()
{
set_error_handler( array( 'Error', 'error_handler' ) );
set_exception_handler( array( 'Error', 'exception_handler' ) );
register_shutdown_function( array( 'Error', 'shutdown_handler' ) );
set_error_handler( array( 'HabariError', 'error_handler' ) );
set_exception_handler( array( 'HabariError', 'exception_handler' ) );
register_shutdown_function( array( 'HabariError', 'shutdown_handler' ) );
}

public static function shutdown_handler ( ) {
Expand Down Expand Up @@ -95,7 +95,7 @@ public function humane_error()
}

/**
* Used to handle all PHP errors after Error::handle_errors() is called.
* Used to handle all PHP errors after HabariError::handle_errors() is called.
*/
public static function error_handler( $errno, $errstr, $errfile, $errline, $errcontext )
{
Expand All @@ -113,31 +113,31 @@ function _t( $v )
// Don't be fooled, we can't actually handle most of these.
$error_names = array(
// @locale A fatal PHP error at runtime. Code execution is stopped
E_ERROR => _t( 'Error' ),
E_ERROR => _t( 'HabariError' ),
// @locale A non-fatal PHP error at runtime. Code execution is not stopped
E_WARNING => _t( 'Warning' ),
// @locale A fatal PHP error generated while parsing the PHP
E_PARSE => _t( 'Parse Error' ),
E_PARSE => _t( 'Parse HabariError' ),
// @locale PHP encountered something at runtime that could be an error or intended
E_NOTICE => _t( 'Notice' ),
// @locale A fatal PHP error during PHP startup. Code execution is stopped.
E_CORE_ERROR => _t( 'Core Error' ),
E_CORE_ERROR => _t( 'Core HabariError' ),
// @locale A non-fatal PHP during PHP startup. Code execution is not stopped.
E_CORE_WARNING => _t( 'Core Warning' ),
// @locale A fatal PHP error at runtime. Code execution is stopped.
E_COMPILE_ERROR => _t( 'Compile Error' ),
E_COMPILE_ERROR => _t( 'Compile HabariError' ),
// @locale A non-fatal PHP error at runtime. Code execution is not stopped.
E_COMPILE_WARNING => _t( 'Compile Warning' ),
// @locale A fatal error generated by Habari or an addon. Code execution is stopped.
E_USER_ERROR => _t( 'User Error' ),
E_USER_ERROR => _t( 'User HabariError' ),
// @locale A non-fatal error generated by Habari or an addon. Code execution is not stopped.
E_USER_WARNING => _t( 'User Warning' ),
// @locale PHP encountered something generated by Habari or an addon at runtime that could be an error or intended
E_USER_NOTICE => _t( 'User Notice' ),
// @locale A suggestion from PHP that the code may need updated for interoperability or forward compatibility
E_STRICT => _t( 'Strict Notice' ),
// @locale A fatal PHP error at runtime. An error handler may be able to work around it. If not, code execution stops.
E_RECOVERABLE_ERROR => _t( 'Recoverable Error' ),
E_RECOVERABLE_ERROR => _t( 'Recoverable HabariError' ),
);
if ( version_compare( PHP_VERSION, '5.3.0', '>=' ) ) {
// @locale A notification from PHP that the code is outdated and may not work in the future
Expand All @@ -158,7 +158,7 @@ function _t( $v )
$errline
);
if ( DEBUG ) {
Error::print_backtrace();
HabariError::print_backtrace();
}

if ( Options::get( 'log_backtraces', false ) || DEBUG ) {
Expand All @@ -177,8 +177,8 @@ function _t( $v )
EventLog::log( $errstr . ' in ' . $errfile . ':' . $errline, 'err', 'default', null, $backtrace );
}

// throwing an Error make every error fatal!
//throw new Error($errstr, 0, true);
// throwing an HabariError make every error fatal!
//throw new HabariError($errstr, 0, true);
}

/**
Expand All @@ -203,7 +203,7 @@ private static function print_backtrace( $trace = null )
foreach ( $trace as $n => $a ) {
$a = array_merge( $defaults, $a );

if ( $a['class'] == 'Error' ) {
if ( $a['class'] == 'HabariError' ) {
continue;
}

Expand Down Expand Up @@ -268,21 +268,21 @@ public function get()
/**
* function raise
*
* Convenience method to create and return a new Error object
* Convenience method to create and return a new HabariError object
*/
public static function raise( $error_message, $severity = E_USER_ERROR )
{
return new Error( $error_message, $severity );
return new HabariError( $error_message, $severity );
}

/**
* function is_error
*
* Returns true if the argument is an Error instance
* Returns true if the argument is an HabariError instance
*/
public static function is_error( $obj )
{
return ($obj instanceof Error);
return ($obj instanceof HabariError);
}

}
Expand Down
10 changes: 5 additions & 5 deletions classes/habarilocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ public static function list_all()
private static function load_file( $domain, $file )
{
if ( ! file_exists( $file ) ) {
Error::raise( _t( 'No translations found for locale %s, domain %s!', array( self::$locale, $domain ) ) );
HabariError::raise( _t( 'No translations found for locale %s, domain %s!', array( self::$locale, $domain ) ) );
return false;
}
if ( filesize( $file ) < 24 ) {
Error::raise( _t( 'Invalid .MO file for locale %s, domain %s!', array( self::$locale, $domain ) ) );
HabariError::raise( _t( 'Invalid .MO file for locale %s, domain %s!', array( self::$locale, $domain ) ) );
return false;
}

Expand All @@ -169,13 +169,13 @@ private static function load_file( $domain, $file )
$little_endian = false;
break;
default:
Error::raise( _t( 'Invalid magic number 0x%08x in %s!', array( $magic, $file ) ) );
HabariError::raise( _t( 'Invalid magic number 0x%08x in %s!', array( $magic, $file ) ) );
return false;
}

$revision = substr( $data, 4, 4 );
if ( $revision != 0 ) {
Error::raise( _t( 'Unknown revision number %d in %s!', array( $revision, $file ) ) );
HabariError::raise( _t( 'Unknown revision number %d in %s!', array( $revision, $file ) ) );
return false;
}

Expand All @@ -186,7 +186,7 @@ private static function load_file( $domain, $file )
$header = unpack( "{$l}1msgcount/{$l}1msgblock/{$l}1transblock", $header );

if ( $header['msgblock'] + ($header['msgcount'] - 1 ) * 8 > filesize( $file ) ) {
Error::raise( _t( 'Message count (%d) out of bounds in %s!', array( $header['msgcount'], $file ) ) );
HabariError::raise( _t( 'Message count (%d) out of bounds in %s!', array( $header['msgcount'], $file ) ) );
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion classes/htmltokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function parse()
$this->state = $this->parse_pi();
break;
default:
Error::raise( _t( 'Invalid state %d in %s->parse()', array( $this->state, __CLASS__ ) ) );
HabariError::raise( _t( 'Invalid state %d in %s->parse()', array( $this->state, __CLASS__ ) ) );
$this->state = self::$STATE_FINISHED;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions classes/inforecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function delete_all()
WHERE ' . $this->_key_name . ' = ?',
array( $this->_key_value )
);
if ( Error::is_error( $result ) ) {
if ( HabariError::is_error( $result ) ) {
$result->out();
return false;
}
Expand Down Expand Up @@ -256,7 +256,7 @@ public function commit( $metadata_key = null )
);
}

if ( Error::is_error( $result ) ) {
if ( HabariError::is_error( $result ) ) {
$result->out();
}
$this->__inforecord_array[$name] = array('value'=>$value);
Expand Down
2 changes: 1 addition & 1 deletion classes/inputfilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ private static function check_attr_value( $k, $v, $type )
return preg_match( '/^[0-9]{4}-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9](?:Z|[\+-][0-2][0-9]:[0-5][0-9])$/', $v );
break;
default:
Error::raise( _t( 'Unknown attribute type "%s" in %s', array( $type, __CLASS__ ) ) );
HabariError::raise( _t( 'Unknown attribute type "%s" in %s', array( $type, __CLASS__ ) ) );
return false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions classes/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ public function __set( $name, $value )
}
else {
$result = DB::update( DB::table( 'options' ), array( 'name' => $name, 'value' => $value, 'type' => 0 ), array( 'name' => $name ) );
}
if ( Error::is_error( $result ) ) {
}
if ( HabariError::is_error( $result ) ) {
$result->out();
die();
}
Expand Down
2 changes: 1 addition & 1 deletion classes/rpcclient.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class RPCClient
function __construct( $url, $method, $params )
{
if ( ! function_exists( 'xmlrpc_encode_request' ) ) {
return Error::raise( _t( 'xmlrpc extension not found' ) );
return HabariError::raise( _t( 'xmlrpc extension not found' ) );
}
$this->url = $url;
$this->method = $method;
Expand Down
2 changes: 1 addition & 1 deletion classes/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static function script_name()
self::$scriptname = $_SERVER['PHP_SELF'];
break;
default:
Error::raise( _t( 'Could not determine script name.' ) );
HabariError::raise( _t( 'Could not determine script name.' ) );
die();
}
return self::$scriptname;
Expand Down
8 changes: 4 additions & 4 deletions classes/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public static function crypt( $password, $hash = null )
case 'md5':
return self::$algo( $password, $hash );
default:
Error::raise( _t( 'Unsupported digest algorithm "%s"', array( $algo ) ) );
HabariError::raise( _t( 'Unsupported digest algorithm "%s"', array( $algo ) ) );
return false;
}
}
Expand All @@ -436,7 +436,7 @@ public static function crypt( $password, $hash = null )
}
}
else {
Error::raise( _t( 'Invalid hash' ) );
HabariError::raise( _t( 'Invalid hash' ) );
}
}

Expand Down Expand Up @@ -497,7 +497,7 @@ public static function ssha( $password, $hash = null )
else { // verify
// is this a SSHA hash?
if ( ! substr( $hash, 0, strlen( $marker ) ) == $marker ) {
Error::raise( _t( 'Invalid hash' ) );
HabariError::raise( _t( 'Invalid hash' ) );
return false;
}
// cut off {SSHA} marker
Expand Down Expand Up @@ -536,7 +536,7 @@ public static function ssha512( $password, $hash = null )
}
else { // verify
if ( ! substr( $hash, 0, strlen( $marker ) ) == $marker ) {
Error::raise( _t( 'Invalid hash' ) );
HabariError::raise( _t( 'Invalid hash' ) );
return false;
}
$hash = substr( $hash, strlen( $marker ) );
Expand Down
4 changes: 2 additions & 2 deletions handlers/userthemehandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function act( $action )
$this->theme->$action_method();
}
}
catch( Error $e ) {
catch( HabariError $e ) {
EventLog::log( $e->humane_error(), 'error', 'theme', 'habari', print_r( $e, 1 ) );
Session::error( $e->humane_error() ); //Should we display any error here?
if ( DEBUG ) {
Expand Down Expand Up @@ -73,7 +73,7 @@ protected function display( $template_name )
try {
$this->theme->display( $template_name );
}
catch( Error $e ) {
catch( HabariError $e ) {
EventLog::log( $e->humane_error(), 'error', 'theme', 'habari', print_r( $e, 1 ) );
}
}
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

// Use our own error reporting class.
if ( !defined( 'SUPPRESS_ERROR_HANDLER' ) ) {
Error::handle_errors();
HabariError::handle_errors();
}

/**
Expand Down
Loading