mirror of
https://github.com/wallabag/wallabag.git
synced 2025-02-18 11:45:14 +00:00
replace flash messages library
This commit is contained in:
parent
adf17b677e
commit
a20f96b76d
4 changed files with 57 additions and 236 deletions
|
@ -22,12 +22,19 @@
|
||||||
"email": "hello@wallabag.org",
|
"email": "hello@wallabag.org",
|
||||||
"issues": "https://github.com/wallabag/wallabag/issues"
|
"issues": "https://github.com/wallabag/wallabag/issues"
|
||||||
},
|
},
|
||||||
|
"repositories": [
|
||||||
|
{
|
||||||
|
"type": "vcs",
|
||||||
|
"url": "https://github.com/wallabag/PHP-Flash-Messages"
|
||||||
|
}
|
||||||
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"twig/twig": "1.*",
|
"twig/twig": "1.*",
|
||||||
"twig/extensions": "1.0.*",
|
"twig/extensions": "1.0.*",
|
||||||
"umpirsky/twig-gettext-extractor": "1.1.*",
|
"umpirsky/twig-gettext-extractor": "1.1.*",
|
||||||
"fabpot/goutte": "2.0.*@dev",
|
"fabpot/goutte": "2.0.*@dev",
|
||||||
"ezyang/htmlpurifier": "dev-master",
|
"ezyang/htmlpurifier": "dev-master",
|
||||||
"mgargano/simplehtmldom": "dev-master"
|
"mgargano/simplehtmldom": "dev-master",
|
||||||
|
"wallabag/PHP-Flash-Messages": "dev-master"
|
||||||
}
|
}
|
||||||
}
|
}
|
51
composer.lock
generated
51
composer.lock
generated
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"hash": "67435ca652abe6c90bdd29701ecd679a",
|
"hash": "f5e69c21a929d0997c771526484a9d7e",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "ezyang/htmlpurifier",
|
"name": "ezyang/htmlpurifier",
|
||||||
|
@ -1335,6 +1335,52 @@
|
||||||
],
|
],
|
||||||
"description": "The Twig Gettext Extractor is Poedit friendly tool which extracts translations from twig templates.",
|
"description": "The Twig Gettext Extractor is Poedit friendly tool which extracts translations from twig templates.",
|
||||||
"time": "2013-02-14 16:41:48"
|
"time": "2013-02-14 16:41:48"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "wallabag/php-flash-messages",
|
||||||
|
"version": "dev-master",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/wallabag/PHP-Flash-Messages.git",
|
||||||
|
"reference": "ea68eb768f32156baa15f7a3cd880ba8ff5af6ab"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/wallabag/PHP-Flash-Messages/zipball/ea68eb768f32156baa15f7a3cd880ba8ff5af6ab",
|
||||||
|
"reference": "ea68eb768f32156baa15f7a3cd880ba8ff5af6ab",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.3.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"files": [
|
||||||
|
"class.messages.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"license": [
|
||||||
|
"Apache"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Nicolas Lœuillet",
|
||||||
|
"email": "nicolas@loeuillet.org",
|
||||||
|
"homepage": "http://www.cdetc.fr"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Session-based Flash Messages class for PHP",
|
||||||
|
"homepage": "https://github.com/wallabag/PHP-Flash-Messages",
|
||||||
|
"keywords": [
|
||||||
|
"flash",
|
||||||
|
"messages",
|
||||||
|
"php-flash-messages",
|
||||||
|
"sessions"
|
||||||
|
],
|
||||||
|
"support": {
|
||||||
|
"source": "https://github.com/wallabag/PHP-Flash-Messages/tree/master"
|
||||||
|
},
|
||||||
|
"time": "2015-01-18 19:51:55"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"packages-dev": [],
|
"packages-dev": [],
|
||||||
|
@ -1343,7 +1389,8 @@
|
||||||
"stability-flags": {
|
"stability-flags": {
|
||||||
"fabpot/goutte": 20,
|
"fabpot/goutte": 20,
|
||||||
"ezyang/htmlpurifier": 20,
|
"ezyang/htmlpurifier": 20,
|
||||||
"mgargano/simplehtmldom": 20
|
"mgargano/simplehtmldom": 20,
|
||||||
|
"wallabag/php-flash-messages": 20
|
||||||
},
|
},
|
||||||
"prefer-stable": false,
|
"prefer-stable": false,
|
||||||
"prefer-lowest": false,
|
"prefer-lowest": false,
|
||||||
|
|
232
inc/3rdparty/class.messages.php
vendored
232
inc/3rdparty/class.messages.php
vendored
|
@ -1,232 +0,0 @@
|
||||||
<?php
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
// Session-Based Flash Messages v1.0
|
|
||||||
// Copyright 2012 Mike Everhart (http://mikeeverhart.net)
|
|
||||||
//
|
|
||||||
// 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.
|
|
||||||
//
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// Description:
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Stores messages in Session data to be easily retrieved later on.
|
|
||||||
// This class includes four different types of messages:
|
|
||||||
// - Success
|
|
||||||
// - Error
|
|
||||||
// - Warning
|
|
||||||
// - Information
|
|
||||||
//
|
|
||||||
// See README for basic usage instructions, or see samples/index.php for more advanced samples
|
|
||||||
//
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
// Changelog
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// 2011-05-15 - v1.0 - Initial Version
|
|
||||||
//
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
class Messages {
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------
|
|
||||||
// Class Variables
|
|
||||||
//-----------------------------------------------------------------------------------------------
|
|
||||||
var $msgId;
|
|
||||||
var $msgTypes = array( 'help', 'info', 'warning', 'success', 'error' );
|
|
||||||
var $msgClass = 'messages';
|
|
||||||
var $msgWrapper = "<div class='%s %s'><a href='#' class='closeMessage'>×</a>\n%s</div>\n";
|
|
||||||
var $msgBefore = '<p>';
|
|
||||||
var $msgAfter = "</p>\n";
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
* @author Mike Everhart
|
|
||||||
*/
|
|
||||||
public function __construct() {
|
|
||||||
|
|
||||||
// Generate a unique ID for this user and session
|
|
||||||
$this->msgId = md5(uniqid());
|
|
||||||
|
|
||||||
// Create the session array if it doesnt already exist
|
|
||||||
settype($_SESSION, 'array');
|
|
||||||
if( !array_key_exists('flash_messages', $_SESSION) ) $_SESSION['flash_messages'] = array();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a message to the queue
|
|
||||||
*
|
|
||||||
* @author Mike Everhart
|
|
||||||
*
|
|
||||||
* @param string $type The type of message to add
|
|
||||||
* @param string $message The message
|
|
||||||
* @param string $redirect_to (optional) If set, the user will be redirected to this URL
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function add($type, $message, $redirect_to=null) {
|
|
||||||
|
|
||||||
if( !isset($_SESSION['flash_messages']) ) return false;
|
|
||||||
|
|
||||||
if( !isset($type) || !isset($message[0]) ) return false;
|
|
||||||
|
|
||||||
// Replace any shorthand codes with their full version
|
|
||||||
if( strlen(trim($type)) == 1 ) {
|
|
||||||
$type = str_replace( array('h', 'i', 'w', 'e', 's'), array('help', 'info', 'warning', 'error', 'success'), $type );
|
|
||||||
|
|
||||||
// Backwards compatibility...
|
|
||||||
} elseif( $type == 'information' ) {
|
|
||||||
$type = 'info';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure it's a valid message type
|
|
||||||
if( !in_array($type, $this->msgTypes) ) die('"' . strip_tags($type) . '" is not a valid message type!' );
|
|
||||||
|
|
||||||
// If the session array doesn't exist, create it
|
|
||||||
if( !array_key_exists( $type, $_SESSION['flash_messages'] ) ) $_SESSION['flash_messages'][$type] = array();
|
|
||||||
|
|
||||||
$_SESSION['flash_messages'][$type][] = $message;
|
|
||||||
|
|
||||||
if( !is_null($redirect_to) ) {
|
|
||||||
header("Location: $redirect_to");
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------
|
|
||||||
// display()
|
|
||||||
// print queued messages to the screen
|
|
||||||
//-----------------------------------------------------------------------------------------------
|
|
||||||
/**
|
|
||||||
* Display the queued messages
|
|
||||||
*
|
|
||||||
* @author Mike Everhart
|
|
||||||
*
|
|
||||||
* @param string $type Which messages to display
|
|
||||||
* @param bool $print True = print the messages on the screen
|
|
||||||
* @return mixed
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function display($type='all', $print=true) {
|
|
||||||
$messages = '';
|
|
||||||
$data = '';
|
|
||||||
|
|
||||||
if( !isset($_SESSION['flash_messages']) ) return false;
|
|
||||||
|
|
||||||
if( $type == 'g' || $type == 'growl' ) {
|
|
||||||
$this->displayGrowlMessages();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print a certain type of message?
|
|
||||||
if( in_array($type, $this->msgTypes) ) {
|
|
||||||
foreach( $_SESSION['flash_messages'][$type] as $msg ) {
|
|
||||||
$messages .= $this->msgBefore . $msg . $this->msgAfter;
|
|
||||||
}
|
|
||||||
|
|
||||||
$data .= sprintf($this->msgWrapper, $this->msgClass, $type, $messages);
|
|
||||||
|
|
||||||
// Clear the viewed messages
|
|
||||||
$this->clear($type);
|
|
||||||
|
|
||||||
// Print ALL queued messages
|
|
||||||
} elseif( $type == 'all' ) {
|
|
||||||
foreach( $_SESSION['flash_messages'] as $type => $msgArray ) {
|
|
||||||
$messages = '';
|
|
||||||
foreach( $msgArray as $msg ) {
|
|
||||||
$messages .= $this->msgBefore . $msg . $this->msgAfter;
|
|
||||||
}
|
|
||||||
$data .= sprintf($this->msgWrapper, $this->msgClass, $type, $messages);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear ALL of the messages
|
|
||||||
$this->clear();
|
|
||||||
|
|
||||||
// Invalid Message Type?
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print everything to the screen or return the data
|
|
||||||
if( $print ) {
|
|
||||||
echo $data;
|
|
||||||
} else {
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check to see if there are any queued error messages
|
|
||||||
*
|
|
||||||
* @author Mike Everhart
|
|
||||||
*
|
|
||||||
* @return bool true = There ARE error messages
|
|
||||||
* false = There are NOT any error messages
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function hasErrors() {
|
|
||||||
return empty($_SESSION['flash_messages']['error']) ? false : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check to see if there are any ($type) messages queued
|
|
||||||
*
|
|
||||||
* @author Mike Everhart
|
|
||||||
*
|
|
||||||
* @param string $type The type of messages to check for
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function hasMessages($type=null) {
|
|
||||||
if( !is_null($type) ) {
|
|
||||||
if( !empty($_SESSION['flash_messages'][$type]) ) return $_SESSION['flash_messages'][$type];
|
|
||||||
} else {
|
|
||||||
foreach( $this->msgTypes as $type ) {
|
|
||||||
if( !empty($_SESSION['flash_messages']) ) return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear messages from the session data
|
|
||||||
*
|
|
||||||
* @author Mike Everhart
|
|
||||||
*
|
|
||||||
* @param string $type The type of messages to clear
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function clear($type='all') {
|
|
||||||
if( $type == 'all' ) {
|
|
||||||
unset($_SESSION['flash_messages']);
|
|
||||||
} else {
|
|
||||||
unset($_SESSION['flash_messages'][$type]);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __toString() { return $this->hasMessages(); }
|
|
||||||
|
|
||||||
public function __destruct() {
|
|
||||||
//$this->clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} // end class
|
|
||||||
?>
|
|
|
@ -17,7 +17,6 @@ define('ROOT', INCLUDES . '/..');
|
||||||
require_once INCLUDES . '/poche/Tools.class.php';
|
require_once INCLUDES . '/poche/Tools.class.php';
|
||||||
require_once INCLUDES . '/poche/User.class.php';
|
require_once INCLUDES . '/poche/User.class.php';
|
||||||
require_once INCLUDES . '/poche/Url.class.php';
|
require_once INCLUDES . '/poche/Url.class.php';
|
||||||
require_once INCLUDES . '/3rdparty/class.messages.php';
|
|
||||||
require_once ROOT . '/vendor/autoload.php';
|
require_once ROOT . '/vendor/autoload.php';
|
||||||
require_once INCLUDES . '/poche/Template.class.php';
|
require_once INCLUDES . '/poche/Template.class.php';
|
||||||
require_once INCLUDES . '/poche/Language.class.php';
|
require_once INCLUDES . '/poche/Language.class.php';
|
||||||
|
|
Loading…
Reference in a new issue