Improve helpers
This commit is contained in:
@@ -10,6 +10,10 @@ use Parsedown;
|
|||||||
*
|
*
|
||||||
* @package core
|
* @package core
|
||||||
* @author Frederic Guillot
|
* @author Frederic Guillot
|
||||||
|
*
|
||||||
|
* @property \Core\Session $session
|
||||||
|
* @property \Model\Acl $acl
|
||||||
|
* @property \Model\User $user
|
||||||
*/
|
*/
|
||||||
class Helper
|
class Helper
|
||||||
{
|
{
|
||||||
@@ -501,14 +505,17 @@ class Helper
|
|||||||
->text($text);
|
->text($text);
|
||||||
|
|
||||||
// Replace task #123 by a link to the task
|
// Replace task #123 by a link to the task
|
||||||
$html = preg_replace_callback('!#(\d+)!i', function($matches) use ($link) { // TODO: Fix that
|
if (preg_match_all('!#(\d+)!i', $html, $matches, PREG_SET_ORDER)) {
|
||||||
return a(
|
|
||||||
$matches[0],
|
foreach ($matches as $match) {
|
||||||
$link['controller'],
|
|
||||||
$link['action'],
|
$html = str_replace(
|
||||||
$link['params'] + array('task_id' => $matches[1])
|
$match[0],
|
||||||
);
|
$this->a($match[0], $link['controller'], $link['action'], $link['params'] + array('task_id' => $match[1])),
|
||||||
}, $html);
|
$html
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
@@ -536,14 +543,7 @@ class Helper
|
|||||||
*/
|
*/
|
||||||
public function flash($html)
|
public function flash($html)
|
||||||
{
|
{
|
||||||
$data = '';
|
return $this->flashMessage('flash_message', $html);
|
||||||
|
|
||||||
if (isset($_SESSION['flash_message'])) {
|
|
||||||
$data = sprintf($html, $this->e($_SESSION['flash_message']));
|
|
||||||
unset($_SESSION['flash_message']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -553,12 +553,25 @@ class Helper
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function flashError($html)
|
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 = '';
|
$data = '';
|
||||||
|
|
||||||
if (isset($_SESSION['flash_error_message'])) {
|
if (isset($this->session[$name])) {
|
||||||
$data = sprintf($html, $this->e($_SESSION['flash_error_message']));
|
$data = sprintf($html, $this->e($this->session[$name]));
|
||||||
unset($_SESSION['flash_error_message']);
|
unset($this->session[$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
|||||||
Reference in New Issue
Block a user