_session_id = e107::getPref('cookie_name', 'e107').'_system_messages'; //clean up old not used sessions $tmp = array_keys($_SESSION); foreach ($tmp as $key) { if($key != $this->_session_id && strpos($key, '_system_messages')) { unset($_SESSION[$key]); } } unset($tmp); if(!isset($_SESSION[$this->_session_id])) { $_SESSION[$this->_session_id] = array(); } $this->reset()->mergeWithSession(); } /** * Cloning is not allowed * */ private function __clone() { } /** * Get singleton instance (php4 no more supported) * * @return eMessage */ public static function getInstance() { if(null == self::$_instance) { self::$_instance = new self(); } return self::$_instance; } /** * Set message session id * @param string $name * @return */ public function setSessionId($name) { $this->_session_id = $name.'_system_messages'; return $this; } /** * Add message to a type stack and default message stack * If $message is array, $message[0] will be the message stack and * $message[1] the message itself * * @param string|array $message * @param string $type * @param boolean $session * @return eMessage */ public function add($message, $type = E_MESSAGE_INFO, $session = false) { if(empty($message)) return $this; $mstack = 'default'; $msg = $message; if(is_array($message)) { $mstack = $message[1]; $msg = $message[0]; } if(!$session) { if($this->isType($type)) $this->_sysmsg[$type][$mstack][] = $msg; return $this; } $this->addSession($message, $type); return $this; } /** * Alias of {@link add()}. * Should be used for dealing with messages with custom message stacks. * Supports message arrays. * * @param string|array $message message(s) * @param string $mstack defaults to 'default' * @param string $type [optional] * @param boolean $sesion [optional] * @return eMessage */ public function addStack($message, $mstack = 'default', $type = E_MESSAGE_INFO, $sesion = false) { if(!is_array($message)) { $message = array($message); } foreach ($message as $m) { $this->add(array($m, $mstack), $type, $sesion); } return $this; } /** * Add message to a _SESSION type stack * If $message is array, $message[0] will be the message stack and * $message[1] the message itself * * @param string|array $message * @param string $type * @return eMessage */ public function addSession($message, $type = E_MESSAGE_INFO) { if(empty($message)) return $this; $mstack = 'default'; if(is_array($message)) { $mstack = $message[1]; $message = $message[0]; } if($this->isType($type)) $_SESSION[$this->_session_id][$type][$mstack][] = $message; return $this; } /** * Alias of {@link addSession()}. * Should be used for dealing with messages with custom message stacks. * Supports message arrays. * * @param string|array $message message(s) * @param string $mstack defaults to 'default' * @param string $type [optional] * @param boolean $sesion [optional] * @return eMessage */ public function addSessionStack($message, $mstack = 'default', $type = E_MESSAGE_INFO) { if(!is_array($message)) { $message = array($message); } foreach ($message as $m) { $this->addSession(array($m, $mstack), $type); } return $this; } /** * Get type title (multi-language) * * @param string $type * @param string $message_stack * @return string title */ public static function getTitle($type, $message_stack = 'default') { if($message_stack && $message_stack != 'default' && defined('EMESSLAN_TITLE_'.strtoupper($type.'_'.$message_stack))) { return constant('EMESSLAN_TITLE_'.strtoupper($type.'_'.$message_stack)); } return defsettrue('EMESSLAN_TITLE_'.strtoupper($type), ''); } /** * Message getter * * @param string $type valid type * @param string $mstack message stack name * @param bool $raw force array return * @param bool $reset reset message type stack * @return string|array message */ public function get($type, $mstack = 'default', $raw = false, $reset = true) { $message = isset($this->_sysmsg[$type][$mstack]) ? $this->_sysmsg[$type][$mstack] : ''; if($reset) $this->reset($type, $mstack, false); return (true === $raw ? $message : self::formatMessage($mstack, $type, $message)); } /** * Get all messages for a stack * * @param string $mstack message stack name * @param bool $raw force array return * @param bool $reset reset message type stack * @return array messages */ public function getAll($mstack = 'default', $raw = false, $reset = true) { $ret = array(); foreach ($this->_get_types() as $type) { $message = $this->get($type, $mstack, $raw, $reset); if(!empty($message)) { $ret[$type] = $message; } } return $ret; } /** * Session message getter * * @param string $type valid type * @param string $mstack message stack * @param bool $raw force array return * @param bool $reset reset session message type stack * @return string|array session message */ public function getSession($type, $mstack = 'default', $raw = false, $reset = true) { $message = isset($_SESSION[$this->_session_id][$type][$mstack]) ? $_SESSION[$this->_session_id][$type][$mstack] : ''; if($reset) $this->resetSession($type, $mstack); return (true === $raw ? $message : self::formatMessage($mstack, $type, $message)); } /** * Get all session messages for a stack * * @param string $mstack message stack name * @param bool $raw force array return * @param bool $reset reset message type stack * @return array session messages */ public function getAllSession($mstack = 'default', $raw = false, $reset = true) { $ret = array(); foreach ($this->_get_types() as $type) { $message = $this->getSession($type, $mstack, $raw, $reset); if(!empty($message)) { $ret[$type] = $message; } } return $ret; } /** * Output all accumulated messages * * @param string $mstack message stack name * @param bool $session merge with session messages * @param bool $reset reset all messages * @param bool $raw force return type array * @return array|string messages */ public function render($mstack = 'default', $session = false, $reset = true, $raw = false) { if($session) { $this->mergeWithSession(true, $mstack); } $ret = array(); foreach ($this->_get_types() as $type) { if(E_MESSAGE_DEBUG === $type && !deftrue('E107_DEBUG_LEVEL')) { continue; } $message = $this->get($type, $mstack, $raw); if(!empty($message)) { $ret[$type] = $message; } } if($reset) $this->reset(false, $mstack); if(true === $raw || empty($ret)) return ($raw ? $ret : ''); //changed to class return "
"; } /** * Create message block markup based on its type. * * @param string $mstack * @param string $type * @param array|string $message * @return string */ public static function formatMessage($mstack, $type, $message) { if (empty($message)) return ''; elseif (is_array($message)) { $message = " \n "; } return "
* e107::getMessage()->success('Success', false);
* //calls internal $this->addStack('Success', E_MESSAGE_SUCCESS, false);
*
* @param string $method valid message type
* @param array $arguments array(0 => (string) message, [optional] 1 =>(boolean) session, [optional] 2=> message stack )
* @return eMessage
* @throws Exception
*/
function __call($method, $arguments) {
if($this->isType($method))
{
$this->addStack($arguments[0], vartrue($arguments[2], 'default'), $method, (isset($arguments[1]) && !empty($arguments[1])));
return $this;
}
throw new Exception('Method eMessage::'.$method.' does not exist!');//FIXME - e107Exception handler
}
}
function show_emessage($mode, $message, $line = 0, $file = "") {
global $tp;
if(is_numeric($message))
{
include_lan(e_LANGUAGEDIR.e_LANGUAGE."/lan_error.php");
$emessage[1] = "".LAN_ERROR_25."";
$emessage[2] = "".LAN_ERROR_26."";
$emessage[3] = "".LAN_ERROR_27."";
$emessage[4] = "".LAN_ERROR_28."";
$emessage[5] = LAN_ERROR_29;
$emessage[6] = "".LAN_ERROR_30."";
$emessage[7] = "".LAN_ERROR_31."";
$emessage[8] = "
".$message." |