ohartl пре 9 година
родитељ
комит
7336611dd2

+ 45 - 14
include/php/classes/Message.php

@@ -15,12 +15,41 @@ class Message
 	const TYPE_SUCCESS = 'success';
 	const TYPE_SUCCESS = 'success';
 
 
 
 
+	/**
+	 * @var Message
+	 */
+	protected static $instance;
+
+
 	/**
 	/**
 	 * Holds all messages
 	 * Holds all messages
 	 *
 	 *
 	 * @var array
 	 * @var array
 	 */
 	 */
-	protected static $messages = array();
+	protected $messages = array();
+
+
+	private function __construct()
+	{
+	}
+
+
+	private function __clone()
+	{
+	}
+
+
+	/**
+	 * @return Message
+	 */
+	public static function getInstance()
+	{
+		if(is_null(static::$instance)){
+			static::$instance = new static();
+		}
+
+		return static::$instance;
+	}
 
 
 
 
 	/**
 	/**
@@ -29,13 +58,13 @@ class Message
 	 * @param string $type Supported types: success, fail, info
 	 * @param string $type Supported types: success, fail, info
 	 * @param string $text
 	 * @param string $text
 	 */
 	 */
-	public static function add($type, $text)
+	public function add($type, $text)
 	{
 	{
 		if(!in_array($type, array(static::TYPE_FAIL, static::TYPE_ERROR, static::TYPE_WARNING, static::TYPE_SUCCESS))){
 		if(!in_array($type, array(static::TYPE_FAIL, static::TYPE_ERROR, static::TYPE_WARNING, static::TYPE_SUCCESS))){
 			throw new InvalidArgumentException;
 			throw new InvalidArgumentException;
 		}
 		}
 
 
-		static::$messages[] = array(
+		$this->messages[] = array(
 			'type' => $type,
 			'type' => $type,
 			'message' => $text,
 			'message' => $text,
 		);
 		);
@@ -47,9 +76,9 @@ class Message
 	 *
 	 *
 	 * @param string $text
 	 * @param string $text
 	 */
 	 */
-	public static function fail($text)
+	public function fail($text)
 	{
 	{
-		static::add(static::TYPE_FAIL, $text);
+		$this->add(static::TYPE_FAIL, $text);
 	}
 	}
 
 
 
 
@@ -58,9 +87,9 @@ class Message
 	 *
 	 *
 	 * @param string $text
 	 * @param string $text
 	 */
 	 */
-	public static function error($text)
+	public function error($text)
 	{
 	{
-		static::add(static::TYPE_ERROR, $text);
+		$this->add(static::TYPE_ERROR, $text);
 	}
 	}
 
 
 
 
@@ -69,9 +98,9 @@ class Message
 	 *
 	 *
 	 * @param string $text
 	 * @param string $text
 	 */
 	 */
-	public static function warning($text)
+	public function warning($text)
 	{
 	{
-		static::add(static::TYPE_WARNING, $text);
+		$this->add(static::TYPE_WARNING, $text);
 	}
 	}
 
 
 
 
@@ -80,9 +109,9 @@ class Message
 	 *
 	 *
 	 * @param string $text
 	 * @param string $text
 	 */
 	 */
-	public static function success($text)
+	public function success($text)
 	{
 	{
-		static::add(static::TYPE_SUCCESS, $text);
+		$this->add(static::TYPE_SUCCESS, $text);
 	}
 	}
 
 
 
 
@@ -93,17 +122,19 @@ class Message
 	 *
 	 *
 	 * @return string
 	 * @return string
 	 */
 	 */
-	public static function render($type = null)
+	public function render($type = null)
 	{
 	{
 		$out = '';
 		$out = '';
 
 
-		if(count(static::$messages) > 0){
+		if(count($this->messages) > 0){
 			$out .= '<div class="notifications">';
 			$out .= '<div class="notifications">';
-			foreach(static::$messages as $message){
+
+			foreach($this->messages as $message){
 				if(is_null($type) || $type == $message['type']){
 				if(is_null($type) || $type == $message['type']){
 					$out .= '<div class="notification notification-'.$message['type'].'">'.$message['message'].'</div>';
 					$out .= '<div class="notification notification-'.$message['type'].'">'.$message['message'].'</div>';
 				}
 				}
 			}
 			}
+
 			$out .= '</div>';
 			$out .= '</div>';
 		}
 		}
 
 

+ 3 - 3
include/php/pages/admin/createdomain.php

@@ -23,11 +23,11 @@ if(isset($_POST['domain'])){
 			Router::redirect("admin/listdomains/?created=1");
 			Router::redirect("admin/listdomains/?created=1");
 		}
 		}
 		else{
 		else{
-			Message::fail("Domain already exists in database.");
+			Message::getInstance()->fail("Domain already exists in database.");
 		}
 		}
 	}
 	}
 	else{
 	else{
-		Message::fail("Empty domain couldn't be created.");
+		Message::getInstance()->fail("Empty domain couldn't be created.");
 	}
 	}
 }
 }
 
 
@@ -35,7 +35,7 @@ if(isset($_POST['domain'])){
 
 
 <h1>Create new domain</h1>
 <h1>Create new domain</h1>
 
 
-<?php echo Message::render(); ?>
+<?php echo Message::getInstance()->render(); ?>
 
 
 <div class="buttons">
 <div class="buttons">
 	<a class="button" href="<?php echo Router::url('admin/listdomains'); ?>">&#10092; Back to domain list</a>
 	<a class="button" href="<?php echo Router::url('admin/listdomains'); ?>">&#10092; Back to domain list</a>

+ 6 - 6
include/php/pages/admin/editredirect.php

@@ -65,7 +65,7 @@ if(isset($_POST['savemode'])){
 
 
 
 
 	if(count($emailErrors) > 0){
 	if(count($emailErrors) > 0){
-		Message::fail(implode("<br>", $emailErrors));
+		Message::getInstance()->fail(implode("<br>", $emailErrors));
 	}
 	}
 	else{
 	else{
 		if(count($emailErrors) === 0 && $savemode === "edit" && !is_null($redirect)){
 		if(count($emailErrors) === 0 && $savemode === "edit" && !is_null($redirect)){
@@ -111,7 +111,7 @@ if(isset($_POST['savemode'])){
 						}
 						}
 					}
 					}
 
 
-					Message::fail(implode("<br>", $errorMessages));
+					Message::getInstance()->fail(implode("<br>", $errorMessages));
 				}
 				}
 				else{
 				else{
 					// multi source handling
 					// multi source handling
@@ -161,7 +161,7 @@ if(isset($_POST['savemode'])){
 				}
 				}
 			}
 			}
 			else{
 			else{
-				Message::fail("Redirect couldn't be edited. Fill out all fields.");
+				Message::getInstance()->fail("Redirect couldn't be edited. Fill out all fields.");
 			}
 			}
 		}
 		}
 
 
@@ -179,7 +179,7 @@ if(isset($_POST['savemode'])){
 						$errorMessages[] = "Source address \"{$existingRedirect->getSource()}\" is already redirected to some destination.";
 						$errorMessages[] = "Source address \"{$existingRedirect->getSource()}\" is already redirected to some destination.";
 					}
 					}
 
 
-					Message::fail(implode("<br>", $errorMessages));
+					Message::getInstance()->fail(implode("<br>", $errorMessages));
 				}
 				}
 				else{
 				else{
 					$inputDestination = emailsToString($inputDestinations);
 					$inputDestination = emailsToString($inputDestinations);
@@ -209,7 +209,7 @@ if(isset($_POST['savemode'])){
 				}
 				}
 			}
 			}
 			else{
 			else{
-				Message::fail("Redirect couldn't be created. Fill out all fields.");
+				Message::getInstance()->fail("Redirect couldn't be created. Fill out all fields.");
 			}
 			}
 		}
 		}
 	}
 	}
@@ -236,7 +236,7 @@ $domains = Domain::getByLimitedDomains();
 	So make sure you don't accidentally override a mailbox with a redirect.
 	So make sure you don't accidentally override a mailbox with a redirect.
 </div>
 </div>
 
 
-<?php echo Message::render(); ?>
+<?php echo Message::getInstance()->render(); ?>
 
 
 <?php if(defined('VALIDATE_ALIASES_SOURCE_DOMAIN_ENABLED') && Auth::getUser()->isDomainLimited() && $domains->count() === 0): ?>
 <?php if(defined('VALIDATE_ALIASES_SOURCE_DOMAIN_ENABLED') && Auth::getUser()->isDomainLimited() && $domains->count() === 0): ?>
 	<div class="notification notification-fail">
 	<div class="notification notification-fail">

+ 6 - 6
include/php/pages/admin/edituser.php

@@ -53,7 +53,7 @@ if(!is_null($saveMode)){
 				$userToEdit->changePassword($inputPassword, $inputPasswordRepeated);
 				$userToEdit->changePassword($inputPassword, $inputPasswordRepeated);
 			}
 			}
 			catch(Exception $passwordInvalidException){
 			catch(Exception $passwordInvalidException){
-				Message::fail($passwordInvalidException->getMessage());
+				Message::getInstance()->fail($passwordInvalidException->getMessage());
 				$passwordError = true;
 				$passwordError = true;
 			}
 			}
 		}
 		}
@@ -119,21 +119,21 @@ if(!is_null($saveMode)){
 						Router::redirect("admin/listusers/?created=1");
 						Router::redirect("admin/listusers/?created=1");
 					}
 					}
 					catch(Exception $passwordInvalidException){
 					catch(Exception $passwordInvalidException){
-						Message::fail($passwordInvalidException->getMessage());
+						Message::getInstance()->fail($passwordInvalidException->getMessage());
 					}
 					}
 				}
 				}
 				else{
 				else{
-					Message::fail("User already exists in database.");
+					Message::getInstance()->fail("User already exists in database.");
 				}
 				}
 			}
 			}
 			else{
 			else{
-				Message::fail("The selected domain doesn't exist.");
+				Message::getInstance()->fail("The selected domain doesn't exist.");
 			}
 			}
 		}
 		}
 		else{
 		else{
 			var_dump($_POST);
 			var_dump($_POST);
 			// Fields missing
 			// Fields missing
-			Message::fail("Not all fields were filled out.");
+			Message::getInstance()->fail("Not all fields were filled out.");
 		}
 		}
 	}
 	}
 }
 }
@@ -171,7 +171,7 @@ if(isset($_GET['id'])){
 		<input type="hidden" name="id" value="<?php echo $user->getId(); ?>"/>
 		<input type="hidden" name="id" value="<?php echo $user->getId(); ?>"/>
 	<?php endif; ?>
 	<?php endif; ?>
 
 
-	<?php echo Message::render(); ?>
+	<?php echo Message::getInstance()->render(); ?>
 
 
 	<?php if($mode === "edit"): ?>
 	<?php if($mode === "edit"): ?>
 		<div class="input-group">
 		<div class="input-group">

+ 5 - 5
include/php/pages/admin/listdomains.php

@@ -5,16 +5,16 @@ if(Auth::getUser()->isDomainLimited()){
 }
 }
 
 
 if(isset($_GET['deleted']) && $_GET['deleted'] == "1"){
 if(isset($_GET['deleted']) && $_GET['deleted'] == "1"){
-	Message::success("Domain deleted successfully.");
+	Message::getInstance()->success("Domain deleted successfully.");
 }
 }
 else if(isset($_GET['created']) && $_GET['created'] == "1"){
 else if(isset($_GET['created']) && $_GET['created'] == "1"){
-	Message::success("Domain created successfully.");
+	Message::getInstance()->success("Domain created successfully.");
 }
 }
 else if(isset($_GET['adm_del']) && $_GET['adm_del'] == "1"){
 else if(isset($_GET['adm_del']) && $_GET['adm_del'] == "1"){
-	Message::fail("Domain couldn't be deleted because admin account would be affected.");
+	Message::getInstance()->fail("Domain couldn't be deleted because admin account would be affected.");
 }
 }
 else if(isset($_GET['missing-permission']) && $_GET['missing-permission'] == "1"){
 else if(isset($_GET['missing-permission']) && $_GET['missing-permission'] == "1"){
-	Message::fail("You don't have the permission to delete that domain.");
+	Message::getInstance()->fail("You don't have the permission to delete that domain.");
 }
 }
 
 
 $domains = Domain::findAll();
 $domains = Domain::findAll();
@@ -29,7 +29,7 @@ $domains = Domain::findAll();
 	</div>
 	</div>
 <?php endif; ?>
 <?php endif; ?>
 
 
-<?php echo Message::render(); ?>
+<?php echo Message::getInstance()->render(); ?>
 
 
 <?php if($domains->count() > 0): ?>
 <?php if($domains->count() > 0): ?>
 	<table class="table">
 	<table class="table">

+ 5 - 5
include/php/pages/admin/listredirects.php

@@ -1,16 +1,16 @@
 <?php
 <?php
 
 
 if(isset($_GET['deleted']) && $_GET['deleted'] == "1"){
 if(isset($_GET['deleted']) && $_GET['deleted'] == "1"){
-	Message::success("Redirect deleted successfully.");
+	Message::getInstance()->success("Redirect deleted successfully.");
 }
 }
 else if(isset($_GET['created']) && $_GET['created'] == "1"){
 else if(isset($_GET['created']) && $_GET['created'] == "1"){
-	Message::success("Redirect created successfully.");
+	Message::getInstance()->success("Redirect created successfully.");
 }
 }
 else if(isset($_GET['edited']) && $_GET['edited'] == "1"){
 else if(isset($_GET['edited']) && $_GET['edited'] == "1"){
-	Message::success("Redirect edited successfully.");
+	Message::getInstance()->success("Redirect edited successfully.");
 }
 }
 else if(isset($_GET['missing-permission']) && $_GET['missing-permission'] == "1"){
 else if(isset($_GET['missing-permission']) && $_GET['missing-permission'] == "1"){
-	Message::fail("You don't have the permission to edit/delete redirects of that domain.");
+	Message::getInstance()->fail("You don't have the permission to edit/delete redirects of that domain.");
 }
 }
 
 
 $redirects = AbstractRedirect::getMultiByLimitedDomains();
 $redirects = AbstractRedirect::getMultiByLimitedDomains();
@@ -29,7 +29,7 @@ $redirects = AbstractRedirect::getMultiByLimitedDomains();
 	</div>
 	</div>
 <?php endif; ?>
 <?php endif; ?>
 
 
-<?php echo Message::render(); ?>
+<?php echo Message::getInstance()->render(); ?>
 
 
 <?php if($redirects->count() > 0): ?>
 <?php if($redirects->count() > 0): ?>
 	<table class="table">
 	<table class="table">

+ 6 - 6
include/php/pages/admin/listusers.php

@@ -1,19 +1,19 @@
 <?php
 <?php
 
 
 if(isset($_GET['deleted']) && $_GET['deleted'] == "1"){
 if(isset($_GET['deleted']) && $_GET['deleted'] == "1"){
-	Message::success("User deleted successfully.");
+	Message::getInstance()->success("User deleted successfully.");
 }
 }
 else if(isset($_GET['created']) && $_GET['created'] == "1"){
 else if(isset($_GET['created']) && $_GET['created'] == "1"){
-	Message::success("User created successfully.");
+	Message::getInstance()->success("User created successfully.");
 }
 }
 else if(isset($_GET['edited']) && $_GET['edited'] == "1"){
 else if(isset($_GET['edited']) && $_GET['edited'] == "1"){
-	Message::success("User edited successfully.");
+	Message::getInstance()->success("User edited successfully.");
 }
 }
 else if(isset($_GET['adm_del']) && $_GET['adm_del'] == "1"){
 else if(isset($_GET['adm_del']) && $_GET['adm_del'] == "1"){
-	Message::fail("Admin user cannot be deleted.");
+	Message::getInstance()->fail("Admin user cannot be deleted.");
 }
 }
 else if(isset($_GET['missing-permission']) && $_GET['missing-permission'] == "1"){
 else if(isset($_GET['missing-permission']) && $_GET['missing-permission'] == "1"){
-	Message::fail("You don't have the permission to edit/delete users of that domain.");
+	Message::getInstance()->fail("You don't have the permission to edit/delete users of that domain.");
 }
 }
 
 
 $users = User::getByLimitedDomains();
 $users = User::getByLimitedDomains();
@@ -32,7 +32,7 @@ $users = User::getByLimitedDomains();
 	</div>
 	</div>
 <?php endif; ?>
 <?php endif; ?>
 
 
-<?php echo Message::render(); ?>
+<?php echo Message::getInstance()->render(); ?>
 
 
 <?php if($users->count() > 0): ?>
 <?php if($users->count() > 0): ?>
 	<table class="table">
 	<table class="table">

+ 3 - 3
include/php/pages/login.php

@@ -7,7 +7,7 @@ if(Auth::isLoggedIn()){
 
 
 if(isset($_POST['email']) && isset($_POST['password'])){
 if(isset($_POST['email']) && isset($_POST['password'])){
 	if(empty($_POST['email']) || empty($_POST['password'])){
 	if(empty($_POST['email']) || empty($_POST['password'])){
-		Message::fail('Please fill out both email and password fields.');
+		Message::getInstance()->fail('Please fill out both email and password fields.');
 	}
 	}
 	else {
 	else {
 		// Start login
 		// Start login
@@ -18,7 +18,7 @@ if(isset($_POST['email']) && isset($_POST['password'])){
 		else{
 		else{
 			//Log error message
 			//Log error message
 			writeLog("WebMUM login failed for IP ".$_SERVER['REMOTE_ADDR']);
 			writeLog("WebMUM login failed for IP ".$_SERVER['REMOTE_ADDR']);
-			Message::fail("Sorry, but we cannot log you in with this combination of email and password, there might be a typo.");
+			Message::getInstance()->fail("Sorry, but we cannot log you in with this combination of email and password, there might be a typo.");
 		}
 		}
 	}
 	}
 }
 }
@@ -27,7 +27,7 @@ if(isset($_POST['email']) && isset($_POST['password'])){
 
 
 <h1>Login</h1>
 <h1>Login</h1>
 
 
-<?php echo Message::render(); ?>
+<?php echo Message::getInstance()->render(); ?>
 
 
 <form class="form" action="" method="post">
 <form class="form" action="" method="post">
 	<div class="input-group">
 	<div class="input-group">

+ 3 - 3
include/php/pages/private/changepass.php

@@ -4,10 +4,10 @@ if(isset($_POST['password']) && isset($_POST['password_repeat'])){
 	try {
 	try {
 		Auth::getUser()->changePassword($_POST['password'], $_POST['password_repeat']);
 		Auth::getUser()->changePassword($_POST['password'], $_POST['password_repeat']);
 
 
-		Message::success("Password changed successfully!");
+		Message::getInstance()->success("Password changed successfully!");
 	}
 	}
 	catch(Exception $passwordInvalidException){
 	catch(Exception $passwordInvalidException){
-		Message::fail($passwordInvalidException->getMessage());
+		Message::getInstance()->fail($passwordInvalidException->getMessage());
 	}
 	}
 }
 }
 
 
@@ -19,7 +19,7 @@ if(isset($_POST['password']) && isset($_POST['password_repeat'])){
 	<a class="button" href="<?php echo Router::url('private'); ?>">&#10092; Back to personal dashboard</a>
 	<a class="button" href="<?php echo Router::url('private'); ?>">&#10092; Back to personal dashboard</a>
 </div>
 </div>
 
 
-<?php echo Message::render(); ?>
+<?php echo Message::getInstance()->render(); ?>
 
 
 <form class="form" action="" method="post" autocomplete="off">
 <form class="form" action="" method="post" autocomplete="off">
 	<div class="input-group">
 	<div class="input-group">

+ 1 - 1
include/php/pages/private/yourredirects.php

@@ -10,7 +10,7 @@ $redirects = Auth::getUser()->getAnonymizedRedirects();
 		<a class="button" href="<?php echo Router::url('private'); ?>">&#10092; Back to personal dashboard</a>
 		<a class="button" href="<?php echo Router::url('private'); ?>">&#10092; Back to personal dashboard</a>
 	</div>
 	</div>
 
 
-<?php echo Message::render(); ?>
+<?php echo Message::getInstance()->render(); ?>
 
 
 <?php if($redirects->count() > 0): ?>
 <?php if($redirects->count() > 0): ?>
 	<table class="table">
 	<table class="table">