developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Ticket #644: jmessage-2.patch

File jmessage-2.patch, 4.1 KB (added by bballizlife, 13 years ago)

Here is a new patch with some modifications in jMessage class (no API change)

  • build/manifests/jelix-lib.mn

     
    239239* jJsonRpc.class.php
    240240  jLog.class.php
    241241  jMailer.class.php
     242  jMessage.class.php
    242243  jSmtp.class.php
    243244  jTcpdf.class.php
    244245* jWiki.class.php
     
    452453  block.swfjs.php
    453454  function.link_to_remote.php
    454455  function.breadcrumb.php
     456  function.jmessage.php
    455457
    456458cd lib/jelix/plugins/tpl/ltx2pdf
    457459  function.jlocale.php
  • lib/jelix/plugins/tpl/html/function.jmessage.php

     
     1<?php
     2/**
     3* @package     Jelix
     4* @subpackage  jtpl_plugin
     5* @author      Loic Mathaud
     6* @copyright   2008 Loic Mathaud
     7* @link        http://www.jelix.org
     8* @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
     9*/
     10
     11/**
     12* function plugin :  Display messages from jMessage
     13*/
     14
     15function jtpl_function_html_jmessage($tpl, $type = '') {
     16    // Get messages
     17    if ($type == '') {
     18        $messages = jMessage::getAll();
     19    } else {
     20        $messages = jMessage::get($type);
     21    }
     22    // Not messages, quit
     23    if (!$messages) {
     24        return;
     25    }
     26
     27    // Display messages
     28    if ($type == '') {
     29        echo '<ul class="jelix-msg">';
     30        foreach ($messages as $types) {
     31            foreach ($types as $type => $msg) {
     32                echo '<li class="jelix-msg-item-'.$type.'">'.htmlspecialchars($msg).'</li>';
     33            }
     34        }
     35    } else {
     36        echo '<ul class="jelix-msg-'. $type .'">';
     37        foreach ($messages as $msg) {
     38            echo '<li class="jelix-msg-item-'.$type.'">'.htmlspecialchars($msg).'</li>';
     39        }
     40    }
     41    echo '</ul>';
     42
     43    if ($type == '') {
     44        jMessage::clearAll();;
     45    } else {
     46        jMessage::clear($type);
     47    }
     48   
     49}
  • lib/jelix/utils/jMessage.class.php

     
     1<?php
     2/**
     3* @package    jelix
     4* @subpackage utils
     5* @author     Loic Mathaud
     6* @copyright  2008 Loic Mathaud
     7* @link       http://www.jelix.org
     8* @licence    GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
     9*/
     10
     11/**
     12* Utility class to log some message in session in order to be displayed in a template
     13* @package    jelix
     14* @subpackage utils
     15* @static
     16*/
     17class jMessage {
     18
     19    protected static $session_name = 'JELIX_MESSAGE';
     20   
     21   
     22    /**
     23    * Add a message
     24    * @param string $message the message
     25    * @param string $type the message type ('default' by default)
     26    */
     27    public static function add($message, $type = 'default') {
     28        $_SESSION[self::$session_name][$type][] = $message;
     29    }
     30   
     31    /**
     32    * Clear messages for the given type
     33    * @param string $type the message type ('default' by default)
     34    */
     35    public static function clear($type = 'default') {
     36        $_SESSION[self::$session_name][$type] = array();
     37    }
     38   
     39    /**
     40    * Clear all messages
     41    */
     42    public static function clearAll() {
     43        $_SESSION[self::$session_name] = array();
     44    }
     45   
     46    /**
     47    * Get messages for the given type
     48    * @param string $type the message type ('default' by default)
     49    * @return mixed array/null
     50    */
     51    public static function get($type = 'default') {
     52        if (isset($_SESSION[self::$session_name][$type])) {
     53            return $_SESSION[self::$session_name][$type];
     54        }
     55       
     56        return null;
     57    }
     58   
     59    /**
     60    * Get all messages
     61    * @return mixed array/null
     62    */
     63    public static function getAll() {
     64        if (isset($_SESSION[self::$session_name])) {
     65            return $_SESSION[self::$session_name];
     66        }
     67       
     68        return null;
     69    }
     70}