summaryrefslogtreecommitdiff
path: root/app/Core
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-12-28 12:03:11 -0500
committerFrédéric Guillot <fred@kanboard.net>2014-12-28 12:03:11 -0500
commit4678b1a673b9dcbefa7f947798206e8cf99d020e (patch)
treeca65f124c4f4cbe47618ca4ba42ad76240a03ac4 /app/Core
parent34d7450d3c13342715e90ec21bceaa13e1baa876 (diff)
Improve helpers
Diffstat (limited to 'app/Core')
-rw-r--r--app/Core/Helper.php51
1 files changed, 32 insertions, 19 deletions
diff --git a/app/Core/Helper.php b/app/Core/Helper.php
index 86034692..82dd6698 100644
--- a/app/Core/Helper.php
+++ b/app/Core/Helper.php
@@ -10,6 +10,10 @@ use Parsedown;
*
* @package core
* @author Frederic Guillot
+ *
+ * @property \Core\Session $session
+ * @property \Model\Acl $acl
+ * @property \Model\User $user
*/
class Helper
{
@@ -501,14 +505,17 @@ class Helper
->text($text);
// Replace task #123 by a link to the task
- $html = preg_replace_callback('!#(\d+)!i', function($matches) use ($link) { // TODO: Fix that
- return a(
- $matches[0],
- $link['controller'],
- $link['action'],
- $link['params'] + array('task_id' => $matches[1])
- );
- }, $html);
+ if (preg_match_all('!#(\d+)!i', $html, $matches, PREG_SET_ORDER)) {
+
+ foreach ($matches as $match) {
+
+ $html = str_replace(
+ $match[0],
+ $this->a($match[0], $link['controller'], $link['action'], $link['params'] + array('task_id' => $match[1])),
+ $html
+ );
+ }
+ }
return $html;
}
@@ -536,14 +543,7 @@ class Helper
*/
public function flash($html)
{
- $data = '';
-
- if (isset($_SESSION['flash_message'])) {
- $data = sprintf($html, $this->e($_SESSION['flash_message']));
- unset($_SESSION['flash_message']);
- }
-
- return $data;
+ return $this->flashMessage('flash_message', $html);
}
/**
@@ -554,11 +554,24 @@ class Helper
*/
public function flashError($html)
{
+ return $this->flashMessage('flash_error_message', $html);
+ }
+
+ /**
+ * Fetch and remove a flash session message
+ *
+ * @access private
+ * @param string $name Message name
+ * @param string $html HTML wrapper
+ * @return string
+ */
+ private function flashMessage($name, $html)
+ {
$data = '';
- if (isset($_SESSION['flash_error_message'])) {
- $data = sprintf($html, $this->e($_SESSION['flash_error_message']));
- unset($_SESSION['flash_error_message']);
+ if (isset($this->session[$name])) {
+ $data = sprintf($html, $this->e($this->session[$name]));
+ unset($this->session[$name]);
}
return $data;