FormatHelper.php 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469
  1. <?php
  2. App::uses('TextHelper', 'View/Helper');
  3. App::uses('StringTemplate', 'Tools.View');
  4. /**
  5. * Format helper with basic html snippets
  6. *
  7. * TODO: make snippets more "css and background image" (instead of inline img links)
  8. *
  9. * @author Mark Scherer
  10. * @license MIT
  11. */
  12. class FormatHelper extends TextHelper {
  13. /**
  14. * Other helpers used by FormHelper
  15. *
  16. * @var array
  17. */
  18. public $helpers = array('Html', 'Tools.Numeric');
  19. public $template;
  20. protected $_defaultConfig = array(
  21. 'fontIcons' => false
  22. );
  23. public function __construct(View $View, $config = array()) {
  24. $config += $this->_defaultConfig;
  25. if ($config['fontIcons'] === true) {
  26. $config['fontIcons'] = (array)Configure::read('Format.fontIcons');
  27. }
  28. $templates = array(
  29. 'icon' => '<i class="{{class}}" title="{{title}}" data-placement="bottom" data-toggle="tooltip"></i>',
  30. ) + (array)Configure::read('Format.templates');
  31. if (!isset($this->template)) {
  32. $this->template = new StringTemplate($templates);
  33. }
  34. parent::__construct($View, $config);
  35. }
  36. /**
  37. * jqueryAccess: {id}Pro, {id}Contra
  38. *
  39. * @return string
  40. */
  41. public function thumbs($id, $inactive = false, $inactiveTitle = null) {
  42. $class = 'Active';
  43. $upTitle = __('consentThis');
  44. $downTitle = __('dissentThis');
  45. if ($inactive === true) {
  46. $class = 'Inactive';
  47. $upTitle = $downTitle = !empty($inactiveTitle) ? $inactiveTitle : __('alreadyVoted');
  48. }
  49. $ret = '<div class="thumbsUpDown">';
  50. $ret .= '<div id="' . $id . 'Pro' . $class . '" rel="' . $id . '" class="thumbUp up' . $class . '" title="' . $upTitle . '"></div>';
  51. $ret .= '<div id="' . $id . 'Contra' . $class . '" rel="' . $id . '" class="thumbDown down' . $class . '" title="' . $downTitle . '"></div>';
  52. $ret .= '<br class="clear"/>';
  53. $ret .= '</div>';
  54. return $ret;
  55. }
  56. /**
  57. * Display neighbor quicklinks
  58. *
  59. * @param array $neighbors (containing prev and next)
  60. * @param string $field: just field or Model.field syntax
  61. * @param array $options:
  62. * - name: title name: next{Record} (if none is provided, "record" is used - not translated!)
  63. * - slug: true/false (defaults to false)
  64. * - titleField: field or Model.field
  65. * @return string
  66. */
  67. public function neighbors($neighbors, $field, $options = array()) {
  68. if (mb_strpos($field, '.') !== false) {
  69. $fieldArray = explode('.', $field, 2);
  70. $alias = $fieldArray[0];
  71. $field = $fieldArray[1];
  72. }
  73. if (empty($alias)) {
  74. if (!empty($neighbors['prev'])) {
  75. $modelNames = array_keys($neighbors['prev']);
  76. $alias = $modelNames[0];
  77. } elseif (!empty($neighbors['next'])) {
  78. $modelNames = array_keys($neighbors['next']);
  79. $alias = $modelNames[0];
  80. }
  81. }
  82. if (empty($field)) {
  83. }
  84. $name = 'Record'; // Translation further down!
  85. if (!empty($options['name'])) {
  86. $name = ucfirst($options['name']);
  87. }
  88. $prevSlug = $nextSlug = null;
  89. if (!empty($options['slug'])) {
  90. if (!empty($neighbors['prev'])) {
  91. $prevSlug = slug($neighbors['prev'][$alias][$field]);
  92. }
  93. if (!empty($neighbors['next'])) {
  94. $nextSlug = slug($neighbors['next'][$alias][$field]);
  95. }
  96. }
  97. $titleAlias = $alias;
  98. $titleField = $field;
  99. if (!empty($options['titleField'])) {
  100. if (mb_strpos($options['titleField'], '.') !== false) {
  101. $fieldArray = explode('.', $options['titleField'], 2);
  102. $titleAlias = $fieldArray[0];
  103. $titleField = $fieldArray[1];
  104. } else {
  105. $titleField = $options['titleField'];
  106. }
  107. }
  108. if (!isset($options['escape']) || $options['escape'] === false) {
  109. $titleField = h($titleField);
  110. }
  111. $ret = '<div class="next-prev-navi nextPrevNavi">';
  112. if (!empty($neighbors['prev'])) {
  113. $url = array($neighbors['prev'][$alias]['id'], $prevSlug);
  114. if (!empty($options['url'])) {
  115. $url += $options['url'];
  116. }
  117. $ret .= $this->Html->link($this->cIcon(ICON_PREV, false) . '&nbsp;' . __('prev' . $name), $url, array('escape' => false, 'title' => $neighbors['prev'][$titleAlias][$titleField]));
  118. } else {
  119. $ret .= $this->cIcon(ICON_PREV_DISABLED, __('noPrev' . $name)) . '&nbsp;' . __('prev' . $name);
  120. }
  121. $ret .= '&nbsp;&nbsp;';
  122. if (!empty($neighbors['next'])) {
  123. $url = array($neighbors['next'][$alias]['id'], $prevSlug);
  124. if (!empty($options['url'])) {
  125. $url += $options['url'];
  126. }
  127. $ret .= $this->Html->link($this->cIcon(ICON_NEXT, false) . '&nbsp;' . __('next' . $name), $url, array('escape' => false, 'title' => $neighbors['next'][$titleAlias][$titleField]));
  128. } else {
  129. $ret .= $this->cIcon(ICON_NEXT_DISABLED, __('noNext' . $name)) . '&nbsp;' . __('next' . $name);
  130. }
  131. $ret .= '</div>';
  132. return $ret;
  133. }
  134. /**
  135. * Allows icons to be added on the fly
  136. * NOTE: overriding not allowed by default
  137. *
  138. * @return void
  139. */
  140. public function addIcon($name = null, $pic = null, $title = null, $allowOverride = false) {
  141. if ($allowOverride === true || ($allowOverride !== true && !array_key_exists($name, $this->icons))) {
  142. if (!empty($name) && !empty($pic)) {
  143. $this->icons[$name] = array('pic' => strtolower($pic), 'title' => (!empty($title) ? $title : ''));
  144. }
  145. }
  146. }
  147. const GENDER_FEMALE = 2;
  148. const GENDER_MALE = 1;
  149. /**
  150. * Displays gender icon
  151. *
  152. * @return string
  153. */
  154. public function genderIcon($value = null, $type = null) {
  155. $value = (int)$value;
  156. if ($value == self::GENDER_FEMALE) {
  157. $icon = $this->icon('genderFemale', null, null, null, array('class' => 'gender'));
  158. } elseif ($value == self::GENDER_MALE) {
  159. $icon = $this->icon('genderMale', null, null, null, array('class' => 'gender'));
  160. } else {
  161. $icon = $this->icon('genderUnknown', null, null, null, array('class' => 'gender'));
  162. }
  163. return $icon;
  164. }
  165. /**
  166. * Returns img from customImgFolder
  167. *
  168. * @param string $folder
  169. * @param string $icon
  170. * @param bool $checkExists
  171. * @param array $options (ending [default: gif])
  172. * @return string
  173. */
  174. public function customIcon($folder, $icon = null, $checkExist = false, $options = array(), $attr = array()) {
  175. $attachment = 'default';
  176. $ending = 'gif';
  177. $image = null;
  178. if (!empty($options)) {
  179. if (!empty($options['ending'])) {
  180. $ending = $options['ending'];
  181. }
  182. if (!empty($options['backend'])) {
  183. $attachment = 'backend';
  184. }
  185. }
  186. if (empty($icon)) {
  187. } elseif ($checkExist === true && !file_exists(PATH_CONTENT . $folder . DS . $icon . '.' . $ending)) {
  188. } else {
  189. $image = $icon;
  190. }
  191. if ($image === null) {
  192. return $this->Html->image(IMG_ICONS . 'custom' . '/' . $folder . '_' . $attachment . '.' . $ending, $attr);
  193. }
  194. return $this->Html->image(IMG_CONTENT . $folder . '/' . $image . '.' . $ending, $attr);
  195. }
  196. /**
  197. * @return string
  198. */
  199. public function importantIcon($icon, $value) {
  200. $ending = 'gif';
  201. $image = 'default';
  202. if (!empty($value)) {
  203. $image = 'important';
  204. }
  205. return $this->Html->image(IMG_ICONS . $icon . '_' . $image . '.' . $ending);
  206. }
  207. /**
  208. * @param value
  209. * @param array $options
  210. * - max (3/5, defaults to 5)
  211. * - normal: display an icon for normal as well (defaults to false)
  212. * - map: array (manually map values, if you use 1 based values no need for that)
  213. * - title, alt, ...
  214. * @return string html
  215. */
  216. public function priorityIcon($value, $options = array()) {
  217. $defaults = array(
  218. 'max' => 5,
  219. 'normal' => false,
  220. 'map' => array(),
  221. 'css' => true,
  222. );
  223. $options = array_merge($defaults, $options);
  224. extract($options);
  225. $matching = array(
  226. 1 => 'low',
  227. 2 => 'lower',
  228. 3 => 'normal',
  229. 4 => 'higher',
  230. 5 => 'high'
  231. );
  232. if (!empty($map)) {
  233. $value = $map[$value];
  234. }
  235. if (!$normal && $value == ($max + 1) / 2) {
  236. return '';
  237. }
  238. if ($max != 5) {
  239. if ($value == 2) {
  240. $value = 3;
  241. } elseif ($value == 3) {
  242. $value = 5;
  243. }
  244. }
  245. $attr = array(
  246. 'class' => 'prio-' . $matching[$value],
  247. 'title' => __('prio' . ucfirst($matching[$value])),
  248. );
  249. if (!$css) {
  250. $attr['alt'] = $matching[$value];
  251. }
  252. $attr = array_merge($attr, array_diff_key($options, $defaults));
  253. if ($css) {
  254. $html = $this->Html->tag('div', '&nbsp;', $attr);
  255. } else {
  256. $icon = 'priority_' . $matching[$value] . '.gif';
  257. $html = $this->Html->image('icons/' . $icon, $attr);
  258. }
  259. return $html;
  260. }
  261. /**
  262. * Display a font icon (fast and resource-efficient).
  263. * Uses http://fontawesome.io/icons/
  264. *
  265. * Options:
  266. * - size (int|string: 1...5 or large)
  267. * - rotate (integer: 90, 270, ...)
  268. * - spin (booelan: true/false)
  269. * - extra (array: muted, light, dark, border)
  270. * - pull (string: left, right)
  271. *
  272. * @param string|array $icon
  273. * @param array $options
  274. * @return string
  275. */
  276. public function fontIcon($icon, array $options = array(), array $attributes = array()) {
  277. $icon = (array)$icon;
  278. $class = array();
  279. foreach ($icon as $i) {
  280. $class[] = 'icon-' . $i;
  281. }
  282. if (!empty($options['extra'])) {
  283. foreach ($options['extra'] as $i) {
  284. $class[] = 'icon-' . $i;
  285. }
  286. }
  287. if (!empty($options['size'])) {
  288. $class[] = 'icon-' . ($options['size'] === 'large' ? 'large' : $options['size'] . 'x');
  289. }
  290. if (!empty($options['pull'])) {
  291. $class[] = 'pull-' . $options['pull'];
  292. }
  293. if (!empty($options['rotate'])) {
  294. $class[] = 'icon-rotate-' . (int)$options['rotate'];
  295. }
  296. if (!empty($options['spin'])) {
  297. $class[] = 'icon-spin';
  298. }
  299. return '<i class="' . implode(' ', $class) . '"></i>';
  300. }
  301. /**
  302. * Quick way of printing default icons
  303. *
  304. * @param type
  305. * @param title
  306. * @param alt (set to FALSE if no alt is supposed to be shown)
  307. * @param bool automagic i18n translate [default true = __('xyz')]
  308. * @param options array ('class'=>'','width/height'=>'','onclick=>'') etc
  309. * @return string
  310. */
  311. public function icon($type, $t = null, $a = null, $translate = null, $options = array()) {
  312. if (isset($t) && $t === false) {
  313. $title = '';
  314. } elseif (empty($t)) {
  315. } else {
  316. $title = $t;
  317. }
  318. if (isset($a) && $a === false) {
  319. $alt = '';
  320. } elseif (empty($a)) {
  321. } else {
  322. $alt = $a;
  323. }
  324. if (array_key_exists($type, $this->icons)) {
  325. $pic = $this->icons[$type]['pic'];
  326. $title = (isset($title) ? $title : $this->icons[$type]['title']);
  327. $alt = (isset($alt) ? $alt : preg_replace('/[^a-zA-Z0-9]/', '', $this->icons[$type]['title']));
  328. if ($translate !== false) {
  329. $title = __($title);
  330. $alt = __($alt);
  331. }
  332. $alt = '[' . $alt . ']';
  333. } else {
  334. $pic = 'pixelspace.gif';
  335. $title = '';
  336. $alt = '';
  337. }
  338. if (!$this->settings['fontIcons'] || !isset($this->settings['fontIcons'][$type])) {
  339. $defaults = array('title' => $title, 'alt' => $alt, 'class' => 'icon');
  340. $newOptions = $options + $defaults;
  341. return $this->Html->image('icons/' . $pic, $newOptions);
  342. }
  343. $options['title'] = $title;
  344. $options['translate'] = $translate;
  345. return $this->_fontIcon($type, $options);
  346. }
  347. /**
  348. * Custom Icons
  349. *
  350. * @param string $icon (constant or filename)
  351. * @param array $options:
  352. * - translate, ...
  353. * @param array $attributes:
  354. * - title, alt, ...
  355. * THE REST IS DEPRECATED
  356. * @return string
  357. */
  358. public function cIcon($icon, $t = null, $a = null, $translate = true, $options = array()) {
  359. if (is_array($t)) {
  360. $translate = isset($t['translate']) ? $t['translate'] : true;
  361. $options = (array)$a;
  362. $a = isset($t['alt']) ? $t['alt'] : null; // deprecated
  363. $t = isset($t['title']) ? $t['title'] : null; // deprecated
  364. }
  365. $type = extractPathInfo('filename', $icon);
  366. $title = isset($t) ? $t : ucfirst($type);
  367. $alt = (isset($a) ? $a : Inflector::slug($title, '-'));
  368. if ($translate !== false) {
  369. $title = __($title);
  370. $alt = __($alt);
  371. }
  372. $alt = '[' . $alt . ']';
  373. if (!$this->settings['fontIcons'] || !isset($this->settings['fontIcons'][$type])) {
  374. $defaults = array('title' => $title, 'alt' => $alt, 'class' => 'icon');
  375. $options += $defaults;
  376. if (substr($icon, 0, 1) !== '/') {
  377. $icon = 'icons/' . $icon;
  378. }
  379. return $this->Html->image($icon, $options);
  380. }
  381. $options['title'] = $title;
  382. $options['translate'] = $translate;
  383. return $this->_fontIcon($type, $options);
  384. }
  385. /**
  386. * FormatHelper::_fontIcon()
  387. *
  388. * @param string $type
  389. * @param array $options
  390. * @return string
  391. */
  392. protected function _fontIcon($type, $options) {
  393. $iconType = $this->settings['fontIcons'][$type];
  394. $defaults = array(
  395. 'class' => $iconType . ' ' . $type
  396. );
  397. $options += $defaults;
  398. if (!isset($options['title'])) {
  399. $options['title'] = ucfirst($options['title']);
  400. if ($options['translate'] !== false) {
  401. $options['title'] = __($options['title']);
  402. }
  403. }
  404. return $this->template->format('icon', $options);
  405. }
  406. /**
  407. * Print Star Bar
  408. * //TODO: 0.5 steps!
  409. *
  410. * array $options: steps=1/0.5 [default:1]), show_zero=true/false [default:false], title=false/true [default:false]
  411. * array $attr: string 'title' (both single and span title empty => 'x of x' for span)
  412. * @return string
  413. * @deprecated use RatingHelper::stars() instead
  414. */
  415. public function showStars($current = null, $max = null, $options = array(), $attr = array()) {
  416. $res = '---';
  417. if (!empty($options['steps']) && $options['steps'] == 0.5) {
  418. $steps = 0.5;
  419. $current = ((int)(2 * $current) / 2);
  420. } else {
  421. $steps = 1;
  422. $current = (int)$current;
  423. }
  424. $min = (int)$current;
  425. $max = (int)$max;
  426. if ((!empty($current) || (!empty($options['show_zero']) && $current == 0)) && (!empty($max)) && $current <= $max) {
  427. if (!empty($options) && is_array($options)) {
  428. }
  429. $text = '';
  430. for ($i = 0;$i < $min;$i++) {
  431. $attributes = array('alt' => '#', 'class' => 'full');
  432. if (!empty($options['title'])) { $attributes['title'] = ($i + 1) . '/' . $max; } // ?
  433. $text .= $this->Html->image('icons/star_icon2.gif', $attributes);
  434. }
  435. for ($i = $min;$i < $max;$i++) {
  436. $attributes = array('alt' => '-', 'class' => 'empty');
  437. if (!empty($options['title'])) { $attributes['title'] = ($i + 1) . '/' . $max; } // ?
  438. if ($steps == 0.5 && $current == $i + 0.5) {
  439. $text .= $this->Html->image('icons/star_icon2_half.gif', $attributes);
  440. } else {
  441. $text .= $this->Html->image('icons/star_icon2_empty.gif', $attributes);
  442. }
  443. }
  444. $attributes = array('class' => 'starBar');
  445. $attributes = array_merge($attributes, $attr);
  446. if (empty($attributes['title']) && empty($options['title'])) {
  447. $attributes['title'] = ($current) . ' ' . __('of') . ' ' . $max;
  448. }
  449. $res = $this->Html->tag('span', $text, $attributes);
  450. //$res='<span title="ss" class="starBar">'.$text.'</span>';
  451. } else {
  452. if ($max > 3) {
  453. for ($i = 0; $i < $max - 3; $i++) {
  454. $res .= '-';
  455. }
  456. }
  457. }
  458. return $res;
  459. }
  460. /**
  461. * Display language flags
  462. *
  463. * @return string HTML
  464. */
  465. public function languageFlags() {
  466. $langs = Configure::read('LanguagesAvailable');
  467. $supportedLangs = array(
  468. 'de' => array('title' => 'Deutsch'),
  469. 'en' => array('title' => 'English'),
  470. 'it' => array('title' => 'Italiano'),
  471. );
  472. $languageChange = __('Language') . ': ';
  473. $languages = array();
  474. foreach ($langs as $lang) {
  475. $languages[$lang] = $supportedLangs[$lang];
  476. }
  477. if ($sLang = (string)CakeSession::read('Config.language')) {
  478. $lang = $sLang;
  479. } else {
  480. $lang = '';
  481. }
  482. echo '<span class="country">';
  483. foreach ($languages as $code => $la) {
  484. if ($lang == $code) {
  485. $languageChange .= $this->Html->image('language_flags/' . $code . '.gif', array('alt' => $code, 'title' => $la['title'] . ' (' . __('active') . ')', 'class' => 'country_flag active')) . '';
  486. } else {
  487. $languageChange .= $this->Html->link($this->Html->image('language_flags/' . $code . '.gif', array('alt' => $code, 'title' => $la['title'], 'class' => 'country_flag')), '/lang/' . $code, array('escape' => false)) . '';
  488. }
  489. }
  490. $languageChange .= '</span>'; //.__('(Translation not complete yet)');
  491. return $languageChange;
  492. }
  493. /**
  494. * It is still believed that encoding will stop spam-bots being able to find your email address.
  495. * Nevertheless, encoded email address harvester are on the way (http://www.dreamweaverfever.com/experiments/spam/).
  496. *
  497. * //TODO: move to TextExt?
  498. * Helper Function to Obfuscate Email by inserting a span tag (not more! not very secure on its own...)
  499. * each part of this mail now does not make sense anymore on its own
  500. * (striptags will not work either)
  501. *
  502. * @param string email: necessary (and valid - containing one @)
  503. * @return string
  504. */
  505. public function encodeEmail($mail) {
  506. list($mail1, $mail2) = explode('@', $mail);
  507. $encMail = $this->encodeText($mail1) . '<span>@</span>' . $this->encodeText($mail2);
  508. return $encMail;
  509. }
  510. /**
  511. * //TODO: move to TextExt?
  512. * Obfuscates Email (works without JS!) to avoid spam bots to get it
  513. *
  514. * @param string mail: email to encode
  515. * @param string text: optional (if none is given, email will be text as well)
  516. * @param array attributes: html tag attributes
  517. * @param array params: ?subject=y&body=y to be attached to "mailto:xyz"
  518. * @return string Save string with JS generated link around email (and non JS fallback)
  519. */
  520. public function encodeEmailUrl($mail, $text = null, $params = array(), $attr = array()) {
  521. if (empty($class)) { $class = 'email';}
  522. $defaults = array(
  523. 'title' => __('for use in an external mail client'),
  524. 'class' => 'email',
  525. 'escape' => false
  526. );
  527. if (empty($text)) {
  528. $text = $this->encodeEmail($mail);
  529. }
  530. $encMail = 'mailto:' . $mail;
  531. // additionally there could be a span tag in between: email<span syle="display:none"></span>@web.de
  532. $querystring = '';
  533. foreach ($params as $key => $val) {
  534. if ($querystring) {
  535. $querystring .= "&$key=" . rawurlencode($val);
  536. } else {
  537. $querystring = "?$key=" . rawurlencode($val);
  538. }
  539. }
  540. $attr = array_merge($defaults, $attr);
  541. $xmail = $this->Html->link('', $encMail . $querystring, $attr);
  542. $xmail1 = mb_substr($xmail, 0, count($xmail) - 5);
  543. $xmail2 = mb_substr($xmail, -4, 4);
  544. $len = mb_strlen($xmail1);
  545. $i = 0;
  546. while ($i < $len) {
  547. $c = mt_rand(2, 6);
  548. $par[] = (mb_substr($xmail1, $i, $c));
  549. $i += $c;
  550. }
  551. $join = implode('\'+ \'', $par);
  552. return '<script language=javascript><!--
  553. document.write(\'' . $join . '\');
  554. //--></script>
  555. ' . $text . '
  556. <script language=javascript><!--
  557. document.write(\'' . $xmail2 . '\');
  558. //--></script>';
  559. }
  560. /**
  561. * //TODO: move to TextExt?
  562. * Encodes Piece of Text (without usage of JS!) to avoid spam bots to get it
  563. *
  564. * @param STRING text to encode
  565. * @return string (randomly encoded)
  566. */
  567. public function encodeText($text) {
  568. $encmail = '';
  569. for ($i = 0; $i < mb_strlen($text); $i++) {
  570. $encMod = mt_rand(0, 2);
  571. switch ($encMod) {
  572. case 0: // None
  573. $encmail .= mb_substr($text, $i, 1);
  574. break;
  575. case 1: // Decimal
  576. $encmail .= "&#" . ord(mb_substr($text, $i, 1)) . ';';
  577. break;
  578. case 2: // Hexadecimal
  579. $encmail .= "&#x" . dechex(ord(mb_substr($text, $i, 1))) . ';';
  580. break;
  581. }
  582. }
  583. return $encmail;
  584. }
  585. /**
  586. * Display yes/no symbol.
  587. *
  588. * @todo $on=1, $text=false, $ontitle=false,... => in array(OPTIONS) packen
  589. *
  590. * @param text: default FALSE; if TRUE, text instead of the image
  591. * @param ontitle: default FALSE; if it is embadded in a link, set to TRUE
  592. * @return image:Yes/No or text:Yes/No
  593. */
  594. public function yesNo($v, $ontitle = null, $offtitle = null, $on = 1, $text = false, $notitle = false) {
  595. $ontitle = (!empty($ontitle) ? $ontitle : __('Ja'));
  596. $offtitle = (!empty($offtitle) ? $offtitle : __('Nein'));
  597. $sbez = array('0' => @substr($offtitle, 0, 1), '1' => @substr($ontitle, 0, 1));
  598. $bez = array('0' => $offtitle, '1' => $ontitle);
  599. if ($v == $on) {
  600. $icon = ICON_YES;
  601. $value = 1;
  602. } else {
  603. $icon = ICON_NO;
  604. $value = 0;
  605. }
  606. if ($text !== false) {
  607. $light = $bez[$value];
  608. } else {
  609. //$light='<img src="images/icons/'.$icon.'" alt="'.$sbez[$value].'" '.($notitle!==false?'title="'.$bez[$value].'"':'').'/>';
  610. //$light=$this->Html->image('',)<img src="images/icons/'.$icon.'" alt="'.$sbez[$value].'" '.($notitle!==false?'title="'.$bez[$value].'"':'').'/>';
  611. $options = array('title' => ($ontitle === false ? '' : $bez[$value]), 'alt' => $sbez[$value], 'class' => 'icon');
  612. $light = $this->Html->image('icons/' . $icon, $options);
  613. }
  614. return $light;
  615. }
  616. /**
  617. * Get URL of a png img of a website (16x16 pixel).
  618. *
  619. * @param string domain
  620. * @return string
  621. */
  622. public function siteIconUrl($domain) {
  623. if (strpos($domain, 'http') === 0) {
  624. // Strip protocol
  625. $pieces = parse_url($domain);
  626. $domain = $pieces['host'];
  627. }
  628. return 'http://www.google.com/s2/favicons?domain=' . $domain;
  629. }
  630. /**
  631. * Display a png img of a website (16x16 pixel)
  632. * if not available, will return a fallback image (a globe)
  633. *
  634. * @param domain (preferably without protocol, e.g. "www.site.com")
  635. * @return string
  636. */
  637. public function siteIcon($domain, $options = array()) {
  638. $url = $this->siteIconUrl($domain);
  639. $options['width'] = 16;
  640. $options['height'] = 16;
  641. if (!isset($options['alt'])) {
  642. $options['alt'] = $domain;
  643. }
  644. if (!isset($options['title'])) {
  645. $options['title'] = $domain;
  646. }
  647. return $this->Html->image($url, $options);
  648. }
  649. /**
  650. * Display text as image
  651. * //TODO: move to own helper
  652. *
  653. * @param string $text
  654. * @param array $options (for generation):
  655. * - inline, font, size, background (optional)
  656. * @param array $tagAttributes (for image)
  657. * @return string result - as image
  658. */
  659. public function textAsImage($text, $options = array(), $attr = array()) {
  660. /*
  661. $image = new Imagick();
  662. //$image->newImage(218, 46, new ImagickPixel('white'));
  663. $image->setImageCompression(10); // Keine Auswirkung auf Dicke
  664. $draw = new ImagickDraw();
  665. $draw->setFont($font);
  666. $draw->setFontSize(22.0); // Keine Auswirkung auf Dicke
  667. $draw->setFontWeight(100); // 0-999 Keine Auswirkung auf Dicke
  668. $draw->annotation(5, 20, $text);
  669. $image->drawImage($draw);
  670. $image->setImageResolution(1200, 1200); // Keine Auswirkung auf Dicke
  671. $image->setImageFormat('gif');
  672. $image->writeImage(TMP.'x.gif');
  673. $image->trim($mw,0);
  674. */
  675. $defaults = array('alt' => $text);
  676. $attr = array_merge($defaults, $attr);
  677. return $this->_textAsImage($text, $options, $attr);
  678. }
  679. /**
  680. * @return string htmlImage tag (or empty string on failure)
  681. */
  682. public function _textAsImage($text, $options = array(), $attr = array()) {
  683. $defaults = array('inline' => true, 'font' => FILES . 'linotype.ttf', 'size' => 18, 'color' => '#7A7166');
  684. $options = array_merge($defaults, $options);
  685. if ($options['inline']) { // Inline base 64 encoded
  686. $folder = CACHE . 'imagick';
  687. } else {
  688. $folder = WWW_ROOT . 'img' . DS . 'content' . DS . 'imagick';
  689. }
  690. $file = sha1($text . serialize($options)) . '.' . ($options['inline'] || !empty($options['background']) ? 'png' : 'gif');
  691. if (!file_exists($folder)) {
  692. mkdir($folder, 0755);
  693. }
  694. if (!file_exists($folder . DS . $file)) {
  695. $command = 'convert -background ' . (!empty($options['background']) ? '"' . $options['background'] . '"' : 'transparent') . ' -font ' . $options['font'] . ' -fill ' . (!empty($options['color']) ? '"' . $options['color'] . '"' : 'transparent') . ' -pointsize ' . $options['size'] . ' label:"' . $text . '" ' . $folder . DS . $file;
  696. exec($command, $a, $r);
  697. if ($r !== 0) {
  698. return '';
  699. }
  700. }
  701. if ($options['inline']) {
  702. $res = file_get_contents($folder . DS . $file);
  703. $out = $this->Html->imageFromBlob($res, $attr);
  704. } else {
  705. $out = $this->Html->image($this->Html->url('/img/content/imagick/', true) . $file, $attr);
  706. }
  707. return $out;
  708. }
  709. /**
  710. * Display a disabled link tag
  711. *
  712. * @param string $text
  713. * @param array $options
  714. * @return string
  715. */
  716. public function disabledLink($text, $options = array()) {
  717. $defaults = array('class' => 'disabledLink', 'title' => __('notAvailable'));
  718. $options = array_merge($defaults, $options);
  719. return $this->Html->tag('span', $text, $options);
  720. }
  721. /**
  722. * Generates a pagination count: #1 etc for each pagination record
  723. * respects order (ASC/DESC)
  724. *
  725. * @param array $paginator
  726. * @param int $count (current post count on this page)
  727. * @param string $dir (ASC/DESC)
  728. * @return int
  729. */
  730. public function absolutePaginateCount($paginator, $count, $dir = null) {
  731. if ($dir === null) {
  732. $dir = 'ASC';
  733. }
  734. $currentPage = $paginator['page'];
  735. $pageCount = $paginator['pageCount'];
  736. $totalCount = $paginator['count'];
  737. $limit = $paginator['limit'];
  738. $step = 1; //$paginator['step'];
  739. //pr($paginator);
  740. if ($dir === 'DESC') {
  741. $currentCount = $count + ($pageCount - $currentPage) * $limit * $step;
  742. if ($currentPage != $pageCount && $pageCount > 1) {
  743. $currentCount -= $pageCount * $limit * $step - $totalCount;
  744. }
  745. } else {
  746. $currentCount = $count + ($currentPage - 1) * $limit * $step;
  747. }
  748. return $currentCount;
  749. }
  750. /**
  751. * @param float progress
  752. * @param array options:
  753. * - min, max
  754. * - steps
  755. * - decimals (how precise should the result be displayed)
  756. * @return string HTML
  757. */
  758. public function progressBar($progress, $options = array(), $htmlOptions = array()) {
  759. $defaults = array(
  760. 'min' => 0,
  761. 'max' => 100,
  762. 'steps' => 15,
  763. 'decimals' => 1 // TODO: rename to places!!!
  764. );
  765. $options = array_merge($defaults, $options);
  766. $current = (((float)$progress / $options['max']) - $options['min']);
  767. $percent = $current * 100;
  768. $current *= $options['steps'];
  769. $options['progress'] = number_format($current, $options['decimals'], null, '');
  770. $params = Router::queryString($options, array(), true);
  771. $htmlDefaults = array('title' => $this->Numeric->format($percent, $options['decimals']) . ' ' . __('Percent'), 'class' => 'help');
  772. $htmlDefaults['alt'] = $htmlDefaults['title'];
  773. $htmlOptions = array_merge($htmlDefaults, $htmlOptions);
  774. //return $this->Html->image('/files/progress_bar/index.php'.$params, $htmlOptions);
  775. return '<img src="' . $this->Html->url('/files') . '/progress_bar/index.php' . $params . '" title="' . $htmlOptions['title'] . '" class="' .
  776. $htmlOptions['class'] . '" alt="' . $htmlOptions['title'] . '" />';
  777. }
  778. /**
  779. * FormatHelper::tip()
  780. *
  781. * @param mixed $type
  782. * @param mixed $file
  783. * @param mixed $title
  784. * @param mixed $icon
  785. * @return string
  786. */
  787. public function tip($type, $file, $title, $icon) {
  788. return $this->cIcon($icon, $title, null, null, array('class' => 'tip' . ucfirst($type) . ' hand', 'rel' => $file));
  789. }
  790. /**
  791. * FormatHelper::tipHelp()
  792. *
  793. * @param mixed $file
  794. * @return string
  795. */
  796. public function tipHelp($file) {
  797. return $this->tip('help', $file, 'Hilfe', ICON_HELP);
  798. }
  799. /**
  800. * Fixes utf8 problems of native php str_pad function
  801. * //TODO: move to textext helper?
  802. *
  803. * @param string $input
  804. * @param int $padLength
  805. * @param string $padString
  806. * @param mixed $padType
  807. * @return string input
  808. */
  809. public function pad($input, $padLength, $padString, $padType = STR_PAD_RIGHT) {
  810. $length = mb_strlen($input);
  811. if ($padLength - $length > 0) {
  812. switch ($padType) {
  813. case STR_PAD_LEFT:
  814. $input = str_repeat($padString, $padLength - $length) . $input;
  815. break;
  816. case STR_PAD_RIGHT:
  817. $input .= str_repeat($padString, $padLength - $length);
  818. break;
  819. }
  820. }
  821. return $input;
  822. }
  823. /**
  824. * Display traffic light for status etc
  825. *
  826. * @return void
  827. */
  828. public function statusLight($color = null, $title = null, $alt = null, $options = array()) {
  829. $icons = array(
  830. 'green', 'yellow', 'red', 'blue'
  831. /*
  832. 'red' => array(
  833. 'title'=>'',
  834. 'alt'=>''
  835. ),
  836. */
  837. );
  838. $icon = (in_array($color, $icons) ? $color : 'blank');
  839. $defaultOptions = array('title' => (!empty($title) ? $title : ucfirst(__('color' . ucfirst($color)))), 'alt' => (!empty($alt) ? $alt :
  840. __('color' . ucfirst($color))), 'class' => 'icon help');
  841. $options = array_merge($defaultOptions, $options);
  842. return $this->Html->image('icons/status_light_' . $icon . '.gif', $options);
  843. }
  844. /**
  845. * FormatHelper::onlineIcon()
  846. *
  847. * @param mixed $modified
  848. * @param mixed $options
  849. * @return string
  850. */
  851. public function onlineIcon($modified = null, $options = array()) {
  852. // from low (off) to high (on)
  853. $icons = array('healthbar0.gif', 'healthbar1.gif', 'healthbar1b.gif', 'healthbar2.gif', 'healthbar3.gif', 'healthbar4.gif', 'healthbar5.gif');
  854. // default = offline
  855. $res = $icons[0]; // inactive
  856. $time = strtotime($modified);
  857. $timeAgo = time() - $time; // in seconds
  858. if ($timeAgo < 180) { // 3min // active
  859. $res = $icons[6];
  860. } elseif ($timeAgo < 360) { // 6min
  861. $res = $icons[5];
  862. } elseif ($timeAgo < 540) { // 9min
  863. $res = $icons[4];
  864. } elseif ($timeAgo < 720) { // 12min
  865. $res = $icons[3];
  866. } elseif ($timeAgo < 900) { // 15min
  867. $res = $icons[2];
  868. } elseif ($timeAgo < 1080) { // 18min
  869. $res = $icons[1];
  870. }
  871. return $this->Html->image('misc/' . $res, array('style' => 'width: 60px; height: 16px'));
  872. }
  873. /**
  874. * Returns red colored if not ok
  875. *
  876. * @param string $value
  877. * @param $okValue
  878. * @return string Value in HTML tags
  879. */
  880. public function warning($value, $ok = false) {
  881. if ($ok !== true) {
  882. return $this->ok($value, false);
  883. }
  884. return $value;
  885. }
  886. /**
  887. * Returns green on ok, red otherwise
  888. *
  889. * @param mixed $currentValue
  890. * @param bool $ok: true/false (defaults to false)
  891. * //@param string $comparizonType
  892. * //@param mixed $okValue
  893. * @return string newValue nicely formatted/colored
  894. */
  895. public function ok($value, $ok = false) {
  896. if ($ok === true) {
  897. $value = '<span class="green" style="color:green">' . $value . '</span>';
  898. } else {
  899. $value = '<span class="red" style="color:red">' . $value . '</span>';
  900. }
  901. return $value;
  902. }
  903. /**
  904. * test@test.de becomes t..t@t..t.de
  905. *
  906. * @param string $email: valid(!) email address
  907. * @return string
  908. */
  909. public static function hideEmail($mail) {
  910. $mailParts = explode('@', $mail, 2);
  911. $domainParts = explode('.', $mailParts[1], 2);
  912. $email = mb_substr($mailParts[0], 0, 1) . '..' . mb_substr($mailParts[0], -1, 1) . '@' . mb_substr($domainParts[0], 0, 1) . '..' . mb_substr($domainParts[0],
  913. -1, 1) . '.' . $domainParts[1];
  914. return $email;
  915. }
  916. /**
  917. * (Intelligent) Shortening of a text string
  918. *
  919. * @param STRING textstring
  920. * @param int chars = max-length
  921. * For options array:
  922. * @param bool strict (default: FALSE = intelligent shortening, cutting only between whole words)
  923. * @param STRING ending (default: '...' no leading whitespace)
  924. * @param bool remain_lf (default: false = \n to ' ')
  925. * Note: ONLY If intelligent:
  926. * - the word supposed to be cut is removed completely (instead of remaining as last one)
  927. * - Looses line breaks (for textarea content to work with this)!
  928. * @deprecated use truncate instead
  929. */
  930. public function shortenText($textstring, $chars, $options = array()) {
  931. $chars++; // add +1 for correct cut
  932. $needsEnding = false;
  933. #Options
  934. $strict = false;
  935. $ending = CHAR_HELLIP; //'...';
  936. $remainLf = false; // not implemented: choose if LF transformed to ' '
  937. $class = 'help';
  938. $escape = true;
  939. $title = '';
  940. if (!empty($options) && is_array($options)) {
  941. if (!empty($options['strict']) && ($options['strict'] === true || $options['strict'] === false)) {
  942. $strict = $options['strict'];
  943. }
  944. if (!empty($options['remain_lf']) && ($options['remain_lf'] === true || $options['remain_lf'] === false)) {
  945. $remainLf = $options['remain_lf'];
  946. }
  947. if (isset($options['title'])) {
  948. $title = $options['title'];
  949. if ($options['title'] === true) {
  950. $title = $textstring;
  951. }
  952. }
  953. if (isset($options['class']) && $options['class'] === false) {
  954. $class = '';
  955. }
  956. if (isset($options['ending'])) {
  957. $ending = (string)$options['ending'];
  958. }
  959. if (isset($options['escape'])) {
  960. $escape = (bool)$options['escape'];
  961. }
  962. }
  963. $textstring = trim($textstring);
  964. // cut only between whole words
  965. if ($strict !== true) {
  966. $completeWordText = $textstring . ' ';
  967. // transform line breaks to whitespaces (for textarea content etc.)
  968. $completeWordTextLf = str_replace(LF, ' ', $completeWordText);
  969. $completeWordText = $completeWordTextLf;
  970. $completeWordText = substr($completeWordTextLf, 0, $chars);
  971. // round the text to the previous entire word instead of cutting off part way through a word
  972. $completeWordText = substr($completeWordText, 0, strrpos($completeWordText, ' '));
  973. }
  974. $textEnding = '';
  975. if ($strict !== true && strlen($completeWordText) > 1) {
  976. $text = trim($completeWordText);
  977. // add ending only if result is shorter then original
  978. if (strlen($text) < strlen(trim($completeWordTextLf))) {
  979. $textEnding = ' ' . $ending; // additional whitespace as there is a new word added
  980. }
  981. } else {
  982. $text = trim(substr($textstring, 0, $chars));
  983. // add ending only if result is shorter then original
  984. if (strlen($text) < strlen($textstring)) {
  985. $textEnding = $ending;
  986. }
  987. }
  988. if ($escape) {
  989. $text = h($text);
  990. $title = h($title);
  991. }
  992. $text .= $textEnding;
  993. #TitleIfTooLong
  994. if (!empty($title)) {
  995. $text = '<span ' . (!empty($class) ? 'class="' . $class . '" ' : '') . 'title="' . $title . '">' . $text . '</span>';
  996. }
  997. return $text;
  998. }
  999. /**
  1000. * Useful for displaying tabbed (code) content when the default of 8 spaces
  1001. * inside <pre> is too much. This converts it to spaces for better output.
  1002. *
  1003. * Inspired by the tab2space function found at:
  1004. * @see http://aidan.dotgeek.org/lib/?file=function.tab2space.php
  1005. * @param string $text
  1006. * @param int $spaces
  1007. * @return string
  1008. */
  1009. public function tab2space($text, $spaces = 4) {
  1010. $spaces = str_repeat(" ", $spaces);
  1011. $text = preg_split("/\r\n|\r|\n/", trim($text));
  1012. $wordLengths = array();
  1013. $wArray = array();
  1014. // Store word lengths
  1015. foreach ($text as $line) {
  1016. $words = preg_split("/(\t+)/", $line, -1, PREG_SPLIT_DELIM_CAPTURE);
  1017. foreach (array_keys($words) as $i) {
  1018. $strlen = strlen($words[$i]);
  1019. $add = isset($wordLengths[$i]) && ($wordLengths[$i] < $strlen);
  1020. if ($add || !isset($wordLengths[$i])) {
  1021. $wordLengths[$i] = $strlen;
  1022. }
  1023. }
  1024. $wArray[] = $words;
  1025. }
  1026. // Clear $text
  1027. $text = '';
  1028. // Apply padding when appropriate and rebuild the string
  1029. foreach (array_keys($wArray) as $i) {
  1030. foreach (array_keys($wArray[$i]) as $ii) {
  1031. if (preg_match("/^\t+$/", $wArray[$i][$ii])) {
  1032. $wArray[$i][$ii] = str_pad($wArray[$i][$ii], $wordLengths[$ii], "\t");
  1033. } else {
  1034. $wArray[$i][$ii] = str_pad($wArray[$i][$ii], $wordLengths[$ii]);
  1035. }
  1036. }
  1037. $text .= str_replace("\t", $spaces, implode("", $wArray[$i])) . "\n";
  1038. }
  1039. // Finished
  1040. return $text;
  1041. }
  1042. /**
  1043. * Word Censoring Function
  1044. *
  1045. * Supply a string and an array of disallowed words and any
  1046. * matched words will be converted to #### or to the replacement
  1047. * word you've submitted.
  1048. *
  1049. * @param string the text string
  1050. * @param string the array of censoered words
  1051. * @param string the optional replacement value
  1052. * @return string
  1053. */
  1054. public function wordCensor($str, $censored, $replacement = null) {
  1055. if (empty($censored)) {
  1056. return $str;
  1057. }
  1058. $str = ' ' . $str . ' ';
  1059. // \w, \b and a few others do not match on a unicode character
  1060. // set for performance reasons. As a result words like ..ber
  1061. // will not match on a word boundary. Instead, we'll assume that
  1062. // a bad word will be bookended by any of these characters.
  1063. $delim = '[-_\'\"`() {}<>\[\]|!?@#%&,.:;^~*+=\/ 0-9\n\r\t]';
  1064. foreach ($censored as $badword) {
  1065. if ($replacement !== null) {
  1066. $str = preg_replace("/({$delim})(" . str_replace('\*', '\w*?', preg_quote($badword, '/')) . ")({$delim})/i", "\\1{$replacement}\\3", $str);
  1067. } else {
  1068. $str = preg_replace("/({$delim})(" . str_replace('\*', '\w*?', preg_quote($badword, '/')) . ")({$delim})/ie", "'\\1'.str_repeat('#', strlen('\\2')).'\\3'",
  1069. $str);
  1070. }
  1071. }
  1072. return trim($str);
  1073. }
  1074. /**
  1075. * Translate a result array into a HTML table
  1076. *
  1077. * @author Aidan Lister <aidan@php.net>
  1078. * @version 1.3.2
  1079. * @link http://aidanlister.com/2004/04/converting-arrays-to-human-readable-tables/
  1080. * @param array $array The result (numericaly keyed, associative inner) array.
  1081. * @param bool $recursive Recursively generate tables for multi-dimensional arrays
  1082. * @param string $null String to output for blank cells
  1083. */
  1084. public function array2table($array, $options = array()) {
  1085. $defaults = array(
  1086. 'null' => '&nbsp;',
  1087. 'recursive' => false,
  1088. 'heading' => true,
  1089. 'escape' => true
  1090. );
  1091. $options = array_merge($defaults, $options);
  1092. // Sanity check
  1093. if (empty($array) || !is_array($array)) {
  1094. return false;
  1095. }
  1096. if (!isset($array[0]) || !is_array($array[0])) {
  1097. $array = array($array);
  1098. }
  1099. // Start the table
  1100. $table = "<table>\n";
  1101. if ($options['heading']) {
  1102. // The header
  1103. $table .= "\t<tr>";
  1104. // Take the keys from the first row as the headings
  1105. foreach (array_keys($array[0]) as $heading) {
  1106. $table .= '<th>' . ($options['escape'] ? h($heading) : $heading) . '</th>';
  1107. }
  1108. $table .= "</tr>\n";
  1109. }
  1110. // The body
  1111. foreach ($array as $row) {
  1112. $table .= "\t<tr>";
  1113. foreach ($row as $cell) {
  1114. $table .= '<td>';
  1115. // Cast objects
  1116. if (is_object($cell)) {
  1117. $cell = (array)$cell;
  1118. }
  1119. if ($options['recursive'] && is_array($cell) && !empty($cell)) {
  1120. // Recursive mode
  1121. $table .= "\n" . self::array2table($cell, $options) . "\n";
  1122. } else {
  1123. $table .= (!is_array($cell) && strlen($cell) > 0) ? ($options['escape'] ? h($cell) : $cell) : $options['null'];
  1124. }
  1125. $table .= '</td>';
  1126. }
  1127. $table .= "</tr>\n";
  1128. }
  1129. $table .= '</table>';
  1130. return $table;
  1131. }
  1132. public $icons = array(
  1133. 'up' => array(
  1134. 'pic' => ICON_UP,
  1135. 'title' => 'Up',
  1136. ),
  1137. 'down' => array(
  1138. 'pic' => ICON_DOWN,
  1139. 'title' => 'Down',
  1140. ),
  1141. 'edit' => array(
  1142. 'pic' => ICON_EDIT,
  1143. 'title' => 'Edit',
  1144. ),
  1145. 'view' => array(
  1146. 'pic' => ICON_VIEW,
  1147. 'title' => 'View',
  1148. ),
  1149. 'delete' => array(
  1150. 'pic' => ICON_DELETE,
  1151. 'title' => 'Delete',
  1152. ),
  1153. 'reset' => array(
  1154. 'pic' => ICON_RESET,
  1155. 'title' => 'Reset',
  1156. ),
  1157. 'help' => array(
  1158. 'pic' => ICON_HELP,
  1159. 'title' => 'Help',
  1160. ),
  1161. 'loader' => array(
  1162. 'pic' => 'loader.white.gif',
  1163. 'title' => 'Loading...',
  1164. ),
  1165. 'loader-alt' => array(
  1166. 'pic' => 'loader.black.gif',
  1167. 'title' => 'Loading...',
  1168. ),
  1169. 'details' => array(
  1170. 'pic' => ICON_DETAILS,
  1171. 'title' => 'Details',
  1172. ),
  1173. 'use' => array(
  1174. 'pic' => ICON_USE,
  1175. 'title' => 'Use',
  1176. ),
  1177. 'yes' => array(
  1178. 'pic' => ICON_YES,
  1179. 'title' => 'Yes',
  1180. ),
  1181. 'no' => array(
  1182. 'pic' => ICON_NO,
  1183. 'title' => 'No',
  1184. ),
  1185. // deprecated from here down
  1186. 'close' => array(
  1187. 'pic' => ICON_CLOCK,
  1188. 'title' => 'Close',
  1189. ),
  1190. 'reply' => array(
  1191. 'pic' => ICON_REPLY,
  1192. 'title' => 'Reply',
  1193. ),
  1194. 'time' => array(
  1195. 'pic' => ICON_CLOCK,
  1196. 'title' => 'Time',
  1197. ),
  1198. 'check' => array(
  1199. 'pic' => ICON_CHECK,
  1200. 'title' => 'Check',
  1201. ),
  1202. 'role' => array(
  1203. 'pic' => ICON_ROLE,
  1204. 'title' => 'Role',
  1205. ),
  1206. 'add' => array(
  1207. 'pic' => ICON_ADD,
  1208. 'title' => 'Add',
  1209. ),
  1210. 'remove' => array(
  1211. 'pic' => ICON_REMOVE,
  1212. 'title' => 'Remove',
  1213. ),
  1214. 'email' => array(
  1215. 'pic' => ICON_EMAIL,
  1216. 'title' => 'Email',
  1217. ),
  1218. 'options' => array(
  1219. 'pic' => ICON_SETTINGS,
  1220. 'title' => 'Options',
  1221. ),
  1222. 'lock' => array(
  1223. 'pic' => ICON_LOCK,
  1224. 'title' => 'Locked',
  1225. ),
  1226. 'warning' => array(
  1227. 'pic' => ICON_WARNING,
  1228. 'title' => 'Warning',
  1229. ),
  1230. 'genderUnknown' => array(
  1231. 'pic' => 'gender_icon.gif',
  1232. 'title' => 'genderUnknown',
  1233. ),
  1234. 'genderMale' => array(
  1235. 'pic' => 'gender_icon_m.gif',
  1236. 'title' => 'genderMale',
  1237. ),
  1238. 'genderFemale' => array(
  1239. 'pic' => 'gender_icon_f.gif',
  1240. 'title' => 'genderFemale',
  1241. ),
  1242. );
  1243. }
  1244. // Default icons
  1245. if (!defined('ICON_UP')) {
  1246. define('ICON_UP', 'up.gif');
  1247. }
  1248. if (!defined('ICON_DOWN')) {
  1249. define('ICON_DOWN', 'down.gif');
  1250. }
  1251. if (!defined('ICON_EDIT')) {
  1252. define('ICON_EDIT', 'edit.gif');
  1253. }
  1254. if (!defined('ICON_VIEW')) {
  1255. define('ICON_VIEW', 'see.gif');
  1256. }
  1257. if (!defined('ICON_DELETE')) {
  1258. define('ICON_DELETE', 'delete.gif');
  1259. }
  1260. if (!defined('ICON_DETAILS')) {
  1261. define('ICON_DETAILS', 'loupe.gif');
  1262. }
  1263. if (!defined('ICON_OPTIONS')) {
  1264. define('ICON_OPTIONS', 'options.gif');
  1265. }
  1266. if (!defined('ICON_SETTINGS')) {
  1267. define('ICON_SETTINGS', 'options.gif');
  1268. }
  1269. if (!defined('ICON_USE')) {
  1270. define('ICON_USE', 'use.gif');
  1271. }
  1272. if (!defined('ICON_CLOSE')) {
  1273. define('ICON_CLOSE', 'close.gif');
  1274. }
  1275. if (!defined('ICON_REPLY')) {
  1276. define('ICON_REPLY', 'reply.gif');
  1277. }
  1278. if (!defined('ICON_RESET')) {
  1279. define('ICON_RESET', 'reset.gif');
  1280. }
  1281. if (!defined('ICON_HELP')) {
  1282. define('ICON_HELP', 'help.gif');
  1283. }
  1284. if (!defined('ICON_YES')) {
  1285. define('ICON_YES', 'yes.gif');
  1286. }
  1287. if (!defined('ICON_NO')) {
  1288. define('ICON_NO', 'no.gif');
  1289. }
  1290. if (!defined('ICON_CLOCK')) {
  1291. define('ICON_CLOCK', 'clock.gif');
  1292. }
  1293. if (!defined('ICON_CHECK')) {
  1294. define('ICON_CHECK', 'check.gif');
  1295. }
  1296. if (!defined('ICON_ROLE')) {
  1297. define('ICON_ROLE', 'role.gif');
  1298. }
  1299. if (!defined('ICON_ADD')) {
  1300. define('ICON_ADD', 'add.gif');
  1301. }
  1302. if (!defined('ICON_REMOVE')) {
  1303. define('ICON_REMOVE', 'remove.gif');
  1304. }
  1305. if (!defined('ICON_EMAIL')) {
  1306. define('ICON_EMAIL', 'email.gif');
  1307. }
  1308. if (!defined('ICON_LOCK')) {
  1309. define('ICON_LOCK', 'lock.gif');
  1310. }
  1311. if (!defined('ICON_WARNING')) {
  1312. define('ICON_WARNING', 'warning.png');
  1313. }
  1314. if (!defined('ICON_MAP')) {
  1315. define('ICON_MAP', 'map.gif');
  1316. }