|
|
@@ -1,5 +1,6 @@
|
|
|
<?php
|
|
|
App::uses('TextHelper', 'View/Helper');
|
|
|
+App::uses('StringTemplate', 'Tools.View');
|
|
|
|
|
|
/**
|
|
|
* Format helper with basic html snippets
|
|
|
@@ -18,13 +19,38 @@ class FormatHelper extends TextHelper {
|
|
|
*/
|
|
|
public $helpers = array('Html', 'Tools.Numeric');
|
|
|
|
|
|
+ public $template;
|
|
|
+
|
|
|
+ protected $_defaultConfig = array(
|
|
|
+ 'fontIcons' => false
|
|
|
+ );
|
|
|
+
|
|
|
+ public function __construct(View $View, $config = array()) {
|
|
|
+ $config += $this->_defaultConfig;
|
|
|
+
|
|
|
+ if ($config['fontIcons'] === true) {
|
|
|
+ $config['fontIcons'] = (array)Configure::read('Format.fontIcons');
|
|
|
+ }
|
|
|
+
|
|
|
+ $templates = array(
|
|
|
+ 'icon' => '<i class="{{class}}" title="{{title}}" data-placement="bottom" data-toggle="tooltip"></i>',
|
|
|
+ ) + (array)Configure::read('Format.templates');
|
|
|
+ if (!isset($this->template)) {
|
|
|
+ $this->template = new StringTemplate($templates);
|
|
|
+ }
|
|
|
+
|
|
|
+ parent::__construct($View, $config);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* jqueryAccess: {id}Pro, {id}Contra
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
*/
|
|
|
public function thumbs($id, $inactive = false, $inactiveTitle = null) {
|
|
|
$class = 'Active';
|
|
|
- $upTitle = __('Zustimmen');
|
|
|
- $downTitle = __('Dagegen');
|
|
|
+ $upTitle = __('consentThis');
|
|
|
+ $downTitle = __('dissentThis');
|
|
|
if ($inactive === true) {
|
|
|
$class = 'Inactive';
|
|
|
$upTitle = $downTitle = !empty($inactiveTitle) ? $inactiveTitle : __('alreadyVoted');
|
|
|
@@ -46,6 +72,7 @@ class FormatHelper extends TextHelper {
|
|
|
* - name: title name: next{Record} (if none is provided, "record" is used - not translated!)
|
|
|
* - slug: true/false (defaults to false)
|
|
|
* - titleField: field or Model.field
|
|
|
+ * @return string
|
|
|
*/
|
|
|
public function neighbors($neighbors, $field, $options = array()) {
|
|
|
if (mb_strpos($field, '.') !== false) {
|
|
|
@@ -96,7 +123,7 @@ class FormatHelper extends TextHelper {
|
|
|
$titleField = h($titleField);
|
|
|
}
|
|
|
|
|
|
- $ret = '<div class="nextPrevNavi">';
|
|
|
+ $ret = '<div class="next-prev-navi nextPrevNavi">';
|
|
|
if (!empty($neighbors['prev'])) {
|
|
|
$url = array($neighbors['prev'][$alias]['id'], $prevSlug);
|
|
|
if (!empty($options['url'])) {
|
|
|
@@ -106,7 +133,7 @@ class FormatHelper extends TextHelper {
|
|
|
$ret .= $this->Html->link($this->cIcon(ICON_PREV, false) . ' ' . __('prev' . $name), $url, array('escape' => false, 'title' => $neighbors['prev'][$titleAlias][$titleField]));
|
|
|
} else {
|
|
|
$ret .= $this->cIcon(ICON_PREV_DISABLED, __('noPrev' . $name)) . ' ' . __('prev' . $name);
|
|
|
-}
|
|
|
+ }
|
|
|
$ret .= ' ';
|
|
|
if (!empty($neighbors['next'])) {
|
|
|
$url = array($neighbors['next'][$alias]['id'], $prevSlug);
|
|
|
@@ -159,7 +186,10 @@ class FormatHelper extends TextHelper {
|
|
|
/**
|
|
|
* Returns img from customImgFolder
|
|
|
*
|
|
|
- * @param ARRAY options (ending [default: gif])
|
|
|
+ * @param string $folder
|
|
|
+ * @param string $icon
|
|
|
+ * @param bool $checkExists
|
|
|
+ * @param array $options (ending [default: gif])
|
|
|
* @return string
|
|
|
*/
|
|
|
public function customIcon($folder, $icon = null, $checkExist = false, $options = array(), $attr = array()) {
|
|
|
@@ -275,9 +305,9 @@ class FormatHelper extends TextHelper {
|
|
|
*
|
|
|
* @param string|array $icon
|
|
|
* @param array $options
|
|
|
- * @return void
|
|
|
+ * @return string
|
|
|
*/
|
|
|
- public function fontIcon($icon, $options = array()) {
|
|
|
+ public function fontIcon($icon, array $options = array(), array $attributes = array()) {
|
|
|
$icon = (array)$icon;
|
|
|
$class = array();
|
|
|
foreach ($icon as $i) {
|
|
|
@@ -304,7 +334,9 @@ class FormatHelper extends TextHelper {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Quick way of printing default icons (have to be 16px X 16px !!!)
|
|
|
+ * Quick way of printing default icons
|
|
|
+ *
|
|
|
+ * @todo refactor to $type, $options, $attributes
|
|
|
*
|
|
|
* @param type
|
|
|
* @param title
|
|
|
@@ -314,46 +346,40 @@ class FormatHelper extends TextHelper {
|
|
|
* @return string
|
|
|
*/
|
|
|
public function icon($type, $t = null, $a = null, $translate = null, $options = array()) {
|
|
|
- $html = '';
|
|
|
-
|
|
|
if (isset($t) && $t === false) {
|
|
|
$title = '';
|
|
|
- } elseif (empty($t)) {
|
|
|
-
|
|
|
} else {
|
|
|
$title = $t;
|
|
|
}
|
|
|
|
|
|
if (isset($a) && $a === false) {
|
|
|
$alt = '';
|
|
|
- } elseif (empty($a)) {
|
|
|
-
|
|
|
} else {
|
|
|
$alt = $a;
|
|
|
}
|
|
|
|
|
|
- if (array_key_exists($type, $this->icons)) {
|
|
|
- $pic = $this->icons[$type]['pic'];
|
|
|
- $title = (isset($title) ? $title : $this->icons[$type]['title']);
|
|
|
- $alt = (isset($alt) ? $alt : preg_replace('/[^a-zA-Z0-9]/', '', $this->icons[$type]['title']));
|
|
|
- if ($translate !== false) {
|
|
|
- $title = __($title);
|
|
|
- $alt = __($alt);
|
|
|
+ if (!$this->settings['fontIcons'] || !isset($this->settings['fontIcons'][$type])) {
|
|
|
+ if (array_key_exists($type, $this->icons)) {
|
|
|
+ $pic = $this->icons[$type]['pic'];
|
|
|
+ $title = (isset($title) ? $title : $this->icons[$type]['title']);
|
|
|
+ $alt = (isset($alt) ? $alt : preg_replace('/[^a-zA-Z0-9]/', '', $this->icons[$type]['title']));
|
|
|
+ if ($translate !== false) {
|
|
|
+ $title = __($title);
|
|
|
+ $alt = __($alt);
|
|
|
+ }
|
|
|
+ $alt = '[' . $alt . ']';
|
|
|
+ } else {
|
|
|
+ $pic = 'pixelspace.gif';
|
|
|
}
|
|
|
- $alt = '[' . $alt . ']';
|
|
|
- } else {
|
|
|
- $pic = 'pixelspace.gif';
|
|
|
- $title = '';
|
|
|
- $alt = '';
|
|
|
- }
|
|
|
-
|
|
|
- $defaultOptions = array('title' => $title, 'alt' => $alt, 'class' => 'icon');
|
|
|
- //$newOptions['onclick'] = $options['onclick'];
|
|
|
- $newOptions = array_merge($defaultOptions, $options);
|
|
|
+ $defaults = array('title' => $title, 'alt' => $alt, 'class' => 'icon');
|
|
|
+ $newOptions = $options + $defaults;
|
|
|
|
|
|
- $html .= $this->Html->image('icons/' . $pic, $newOptions);
|
|
|
+ return $this->Html->image('icons/' . $pic, $newOptions);
|
|
|
+ }
|
|
|
|
|
|
- return $html;
|
|
|
+ $options['title'] = $title;
|
|
|
+ $options['translate'] = $translate;
|
|
|
+ return $this->_fontIcon($type, $options);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -375,21 +401,53 @@ class FormatHelper extends TextHelper {
|
|
|
$t = isset($t['title']) ? $t['title'] : null; // deprecated
|
|
|
}
|
|
|
|
|
|
- $title = (isset($t) ? $t : ucfirst(extractPathInfo('filename', $icon)));
|
|
|
- //$alt = (isset($a)?$a:preg_replace('/[^a-zA-Z0-9]/', '', $title));
|
|
|
- $alt = (isset($a) ? $a : Inflector::slug($title, '-'));
|
|
|
- if ($translate !== false) {
|
|
|
- $title = __($title);
|
|
|
- $alt = __($alt);
|
|
|
+ $type = extractPathInfo('filename', $icon);
|
|
|
+
|
|
|
+ if (!$this->settings['fontIcons'] || !isset($this->settings['fontIcons'][$type])) {
|
|
|
+ $title = isset($t) ? $t : ucfirst($type);
|
|
|
+ $alt = (isset($a) ? $a : Inflector::slug($title, '-'));
|
|
|
+ if ($translate !== false) {
|
|
|
+ $title = __($title);
|
|
|
+ $alt = __($alt);
|
|
|
+ }
|
|
|
+ $alt = '[' . $alt . ']';
|
|
|
+
|
|
|
+ $defaults = array('title' => $title, 'alt' => $alt, 'class' => 'icon');
|
|
|
+ $options += $defaults;
|
|
|
+ if (substr($icon, 0, 1) !== '/') {
|
|
|
+ $icon = 'icons/' . $icon;
|
|
|
+ }
|
|
|
+ return $this->Html->image($icon, $options);
|
|
|
}
|
|
|
- $alt = '[' . $alt . ']';
|
|
|
|
|
|
- $defaultOptions = array('title' => $title, 'alt' => $alt, 'class' => 'icon');
|
|
|
- $options = array_merge($defaultOptions, $options);
|
|
|
- if (substr($icon, 0, 1) !== '/') {
|
|
|
- $icon = 'icons/' . $icon;
|
|
|
+ $options['title'] = $t;
|
|
|
+ $options['translate'] = $translate;
|
|
|
+ return $this->_fontIcon($type, $options);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * FormatHelper::_fontIcon()
|
|
|
+ *
|
|
|
+ * @param string $type
|
|
|
+ * @param array $options
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ protected function _fontIcon($type, $options) {
|
|
|
+ $iconType = $this->settings['fontIcons'][$type];
|
|
|
+
|
|
|
+ $defaults = array(
|
|
|
+ 'class' => $iconType . ' ' . $type
|
|
|
+ );
|
|
|
+ $options += $defaults;
|
|
|
+
|
|
|
+ if (!isset($options['title'])) {
|
|
|
+ $options['title'] = ucfirst($type);
|
|
|
+ if ($options['translate'] !== false) {
|
|
|
+ $options['title'] = __($options['title']);
|
|
|
+ }
|
|
|
}
|
|
|
- return $this->Html->image($icon, $options);
|
|
|
+
|
|
|
+ return $this->template->format('icon', $options);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -599,11 +657,11 @@ class FormatHelper extends TextHelper {
|
|
|
/**
|
|
|
* Display yes/no symbol.
|
|
|
*
|
|
|
+ * @todo $on=1, $text=false, $ontitle=false,... => in array(OPTIONS) packen
|
|
|
+ *
|
|
|
* @param text: default FALSE; if TRUE, text instead of the image
|
|
|
* @param ontitle: default FALSE; if it is embadded in a link, set to TRUE
|
|
|
* @return image:Yes/No or text:Yes/No
|
|
|
- *
|
|
|
- * @todo $on=1, $text=false, $ontitle=false,... => in array(OPTIONS) packen
|
|
|
*/
|
|
|
public function yesNo($v, $ontitle = null, $offtitle = null, $on = 1, $text = false, $notitle = false) {
|
|
|
$ontitle = (!empty($ontitle) ? $ontitle : __('Ja'));
|
|
|
@@ -633,7 +691,7 @@ class FormatHelper extends TextHelper {
|
|
|
/**
|
|
|
* Get URL of a png img of a website (16x16 pixel).
|
|
|
*
|
|
|
- * @parm string domain
|
|
|
+ * @param string domain
|
|
|
* @return string
|
|
|
*/
|
|
|
public function siteIconUrl($domain) {
|
|
|
@@ -745,7 +803,7 @@ class FormatHelper extends TextHelper {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Generate a pagination count: #1 etc for each pagiation record
|
|
|
+ * Generates a pagination count: #1 etc for each pagination record
|
|
|
* respects order (ASC/DESC)
|
|
|
*
|
|
|
* @param array $paginator
|
|
|
@@ -810,15 +868,29 @@ class FormatHelper extends TextHelper {
|
|
|
$htmlOptions = array_merge($htmlDefaults, $htmlOptions);
|
|
|
//return $this->Html->image('/files/progress_bar/index.php'.$params, $htmlOptions);
|
|
|
|
|
|
- // bug in Html::webroot() ??? ommits ?...
|
|
|
return '<img src="' . $this->Html->url('/files') . '/progress_bar/index.php' . $params . '" title="' . $htmlOptions['title'] . '" class="' .
|
|
|
$htmlOptions['class'] . '" alt="' . $htmlOptions['title'] . '" />';
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * FormatHelper::tip()
|
|
|
+ *
|
|
|
+ * @param mixed $type
|
|
|
+ * @param mixed $file
|
|
|
+ * @param mixed $title
|
|
|
+ * @param mixed $icon
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
public function tip($type, $file, $title, $icon) {
|
|
|
return $this->cIcon($icon, $title, null, null, array('class' => 'tip' . ucfirst($type) . ' hand', 'rel' => $file));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * FormatHelper::tipHelp()
|
|
|
+ *
|
|
|
+ * @param mixed $file
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
public function tipHelp($file) {
|
|
|
return $this->tip('help', $file, 'Hilfe', ICON_HELP);
|
|
|
}
|
|
|
@@ -850,6 +922,8 @@ class FormatHelper extends TextHelper {
|
|
|
|
|
|
/**
|
|
|
* Display traffic light for status etc
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
*/
|
|
|
public function statusLight($color = null, $title = null, $alt = null, $options = array()) {
|
|
|
$icons = array(
|