FormatHelper.php 40 KB

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