FormatHelper.php 40 KB

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