Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
message.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Document
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * JDocument system message renderer
14  *
15  * @package Joomla.Platform
16  * @subpackage Document
17  * @since 11.1
18  */
20 {
21  /**
22  * Renders the error stack and returns the results as a string
23  *
24  * @param string $name Not used.
25  * @param array $params Associative array of values
26  * @param string $content Not used.
27  *
28  * @return string The output of the script
29  *
30  * @since 11.1
31  */
32  public function render($name, $params = array (), $content = null)
33  {
34  $msgList = $this->getData();
35  $buffer = null;
36  $app = JFactory::getApplication();
37  $chromePath = JPATH_THEMES . '/' . $app->getTemplate() . '/html/message.php';
38  $itemOverride = false;
39 
40  if (file_exists($chromePath))
41  {
42  include_once $chromePath;
43  if (function_exists('renderMessage'))
44  {
45  $itemOverride = true;
46  }
47  }
48 
49  $buffer = ($itemOverride) ? renderMessage($msgList) : $this->renderDefaultMessage($msgList);
50 
51  return $buffer;
52  }
53 
54  /**
55  * Get and prepare system message data for output
56  *
57  * @return array An array contains system message
58  *
59  * @since 12.2
60  */
61  private function getData()
62  {
63  // Initialise variables.
64  $lists = array();
65 
66  // Get the message queue
67  $messages = JFactory::getApplication()->getMessageQueue();
68 
69  // Build the sorted message list
70  if (is_array($messages) && !empty($messages))
71  {
72  foreach ($messages as $msg)
73  {
74  if (isset($msg['type']) && isset($msg['message']))
75  {
76  $lists[$msg['type']][] = $msg['message'];
77  }
78  }
79  }
80 
81  return $lists;
82  }
83 
84  /**
85  * Render the system message if no message template file found
86  *
87  * @param array $msgList An array contains system message
88  *
89  * @return string System message markup
90  *
91  * @since 12.2
92  */
93  private function renderDefaultMessage($msgList)
94  {
95  // Build the return string
96  $buffer = '';
97  $buffer .= "\n<div id=\"system-message-container\">";
98 
99  // If messages exist render them
100  if (is_array($msgList))
101  {
102  $buffer .= "\n<div id=\"system-message\">";
103  foreach ($msgList as $type => $msgs)
104  {
105  $buffer .= "\n<div class=\"alert alert-" . $type . "\">";
106 
107  // This requires JS so we should add it trough JS. Progressive enhancement and stuff.
108  $buffer .= "<a class=\"close\" data-dismiss=\"alert\">×</a>";
109 
110  if (count($msgs))
111  {
112  $buffer .= "\n<h4 class=\"alert-heading\">" . JText::_($type) . "</h4>";
113  $buffer .= "\n<div>";
114  foreach ($msgs as $msg)
115  {
116  $buffer .= "\n\t\t<p>" . $msg . "</p>";
117  }
118  $buffer .= "\n</div>";
119  }
120  $buffer .= "\n</div>";
121  }
122  $buffer .= "\n</div>";
123  }
124 
125  $buffer .= "\n</div>";
126 
127  return $buffer;
128  }
129 }