Add namespace.
This commit is contained in:
50
View/Helpers/BreadcrumbViewHelper.php
Normal file
50
View/Helpers/BreadcrumbViewHelper.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php namespace Majestic\View\Helpers;
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage View
|
||||
* @since 2010-03-16
|
||||
*/
|
||||
|
||||
class BreadcrumbViewHelper extends ViewHelper
|
||||
{
|
||||
|
||||
protected $separator = ' > ';
|
||||
|
||||
public function breadcrumb($text = false, $href = false)
|
||||
{
|
||||
if ($text) {
|
||||
$this->append($text, $href);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function prepend($text, $href)
|
||||
{
|
||||
\Majestic\Registry::set(__CLASS__, array($text => $href) + \Majestic\Registry::get(__CLASS__, array()));
|
||||
}
|
||||
|
||||
public function append($text, $href)
|
||||
{
|
||||
\Majestic\Registry::set(__CLASS__, \Majestic\Registry::get(__CLASS__, array()) + array($text => $href));
|
||||
}
|
||||
|
||||
public function setSeparator($sep)
|
||||
{
|
||||
$this->separator = $sep;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$data = array();
|
||||
foreach (\Majestic\Registry::get(__CLASS__, array()) as $text => $href) {
|
||||
if ($href) {
|
||||
$data[] = '<a href="' . $this->view->escape($href) . '">' . $this->view->escape($text) . '</a>';
|
||||
} else {
|
||||
$data[] = $this->view->escape($text);
|
||||
}
|
||||
}
|
||||
return implode($this->separator, $data);
|
||||
}
|
||||
}
|
55
View/Helpers/GetViewHelper.php
Normal file
55
View/Helpers/GetViewHelper.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php namespace Majestic\View\Helpers;
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage View
|
||||
* @since 2010-03-09
|
||||
*/
|
||||
|
||||
class GetViewHelper extends ViewHelper
|
||||
{
|
||||
|
||||
protected $get;
|
||||
|
||||
public function get($replace)
|
||||
{
|
||||
$get = $this->getSanitizedRequest();
|
||||
if (!is_array($replace)) {
|
||||
$replace = array($replace);
|
||||
}
|
||||
foreach ($replace as $key => $value) {
|
||||
if (is_int($key)) {
|
||||
unset($get[$value]);
|
||||
} else {
|
||||
$get[$key] = $this->impl($key, $value);
|
||||
}
|
||||
}
|
||||
return '?' . $this->view->escape(implode('&', $get));
|
||||
}
|
||||
|
||||
protected function getSanitizedRequest()
|
||||
{
|
||||
if ($this->get === null) {
|
||||
$get = \Majestic\Env\Env::Get();
|
||||
foreach ($get as $key => $value) {
|
||||
$this->get[$key] = $this->impl($key, $value);
|
||||
}
|
||||
}
|
||||
return $this->get;
|
||||
}
|
||||
|
||||
protected function impl($name, $value)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
$result = array();
|
||||
foreach ($value as $key => $val) {
|
||||
$result[] = $name . '[' . $key . ']=' . urlencode($val);
|
||||
}
|
||||
$result = implode('&', $result);
|
||||
} else {
|
||||
$result = $name . '=' . urlencode($value);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
27
View/Helpers/HeadViewHelper.php
Normal file
27
View/Helpers/HeadViewHelper.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php namespace Majestic\View\Helpers;
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage View
|
||||
* @since 2010-03-16
|
||||
*/
|
||||
|
||||
class HeadViewHelper extends ViewHelper
|
||||
{
|
||||
|
||||
public function head($string = false)
|
||||
{
|
||||
if ($string) {
|
||||
$data = \Majestic\Registry::get(__CLASS__, array());
|
||||
$data[] = $string;
|
||||
\Majestic\Registry::set(__CLASS__, $data);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return implode("\n ", \Majestic\Registry::get(__CLASS__, array())) . "\n";
|
||||
}
|
||||
}
|
95
View/Helpers/MsgViewHelper.php
Normal file
95
View/Helpers/MsgViewHelper.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php namespace Majestic\View\Helpers;
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage View
|
||||
* @since 2010-03-09
|
||||
*/
|
||||
|
||||
class MsgViewHelper extends ViewHelper
|
||||
{
|
||||
|
||||
const SUCCESS = 'success';
|
||||
|
||||
const ERROR = 'error';
|
||||
|
||||
const INFO = 'info';
|
||||
|
||||
const WARNING = 'warning';
|
||||
|
||||
protected $use_as_html = false;
|
||||
|
||||
private static $type_to_class = array(
|
||||
self::SUCCESS => 'success',
|
||||
self::ERROR => 'error',
|
||||
self::INFO => 'info',
|
||||
self::WARNING => 'warning',
|
||||
);
|
||||
|
||||
protected $css_prefix = '';
|
||||
|
||||
public function msg($msg = null, $type = null)
|
||||
{
|
||||
if ($msg && $type) {
|
||||
if (!in_array($type, array(self::SUCCESS, self::ERROR, self::INFO, self::WARNING))) {
|
||||
throw new \Majestic\Exception\GeneralException('Unknown message type: "' . $type . '"');
|
||||
}
|
||||
$this->set($msg, $type);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function success($msg)
|
||||
{
|
||||
$this->set($msg, self::SUCCESS);
|
||||
}
|
||||
|
||||
public function error($msg)
|
||||
{
|
||||
$this->set($msg, self::ERROR);
|
||||
}
|
||||
|
||||
public function info($msg)
|
||||
{
|
||||
$this->set($msg, self::INFO);
|
||||
}
|
||||
|
||||
public function warning($msg)
|
||||
{
|
||||
$this->set($msg, self::WARNING);
|
||||
}
|
||||
|
||||
protected function set($msg, $type)
|
||||
{
|
||||
\Majestic\Session\Session::set(__CLASS__, array('message' => $msg, 'type' => $type));
|
||||
}
|
||||
|
||||
public static function getType()
|
||||
{
|
||||
$msg = \Majestic\Session\Session::get(__CLASS__, false);
|
||||
return $msg ? $msg['type'] : '';
|
||||
}
|
||||
|
||||
public function withPrefix($css_prefix)
|
||||
{
|
||||
$this->css_prefix = $css_prefix;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$msg = \Majestic\Session\Session::get(__CLASS__, false);
|
||||
if ($msg) {
|
||||
\Majestic\Session\Session::del(__CLASS__);
|
||||
$type_to_class = static::getTypeToClass();
|
||||
return '<div class="' . $this->css_prefix . $type_to_class[$msg['type']] . '">' . (($this->use_as_html)?$msg['message']:$this->view->escape($msg['message'])) . '</div>';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
protected static function getTypeToClass()
|
||||
{
|
||||
return self::$type_to_class;
|
||||
}
|
||||
}
|
34
View/Helpers/TitleViewHelper.php
Normal file
34
View/Helpers/TitleViewHelper.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php namespace Majestic\View\Helpers;
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage View
|
||||
* @since 2010-03-16
|
||||
*/
|
||||
|
||||
class TitleViewHelper extends ViewHelper
|
||||
{
|
||||
|
||||
protected $separator = ' - ';
|
||||
|
||||
public function title($string = false)
|
||||
{
|
||||
if ($string) {
|
||||
$data = \Majestic\Registry::get(__CLASS__, array());
|
||||
$data[] = $string;
|
||||
\Majestic\Registry::set(__CLASS__, $data);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setSeparator($sep)
|
||||
{
|
||||
$this->separator = $sep;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return implode($this->separator, \Majestic\Registry::get(__CLASS__, array()));
|
||||
}
|
||||
}
|
22
View/Helpers/ViewHelper.php
Normal file
22
View/Helpers/ViewHelper.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php namespace Majestic\View\Helpers;
|
||||
/**
|
||||
* @copyright NetMonsters <team@netmonsters.ru>
|
||||
* @link http://netmonsters.ru
|
||||
* @package Majestic
|
||||
* @subpackage View
|
||||
* @since 2010-03-09
|
||||
*/
|
||||
|
||||
abstract class ViewHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \Majestic\View\PHPView
|
||||
*/
|
||||
protected $view = null;
|
||||
|
||||
public function __construct($view)
|
||||
{
|
||||
$this->view = $view;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user