FormatHelper.php 40 KB

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