CommonHelper.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. <?php
  2. App::uses('AppHelper', 'View/Helper');
  3. App::uses('CommonComponent', 'Tools.Controller/Component');
  4. App::uses('Hash', 'Utility');
  5. /**
  6. * All site-wide necessary stuff for the view layer
  7. */
  8. class CommonHelper extends AppHelper {
  9. public $helpers = ['Session', 'Html'];
  10. /**
  11. * Display all flash messages.
  12. *
  13. * TODO: export div wrapping method (for static messaging on a page)
  14. *
  15. * @param array $types Types to output. Defaults to all if none are specified.
  16. * @return string HTML
  17. * @deprecated Use FlashHelper::flash() instead.
  18. */
  19. public function flash(array $types = []) {
  20. // Get the messages from the session
  21. $messages = (array)$this->Session->read('messages');
  22. $cMessages = (array)Configure::read('messages');
  23. if (!empty($cMessages)) {
  24. $messages = (array)Hash::merge($messages, $cMessages);
  25. }
  26. $html = '';
  27. if (!empty($messages)) {
  28. $html = '<div class="flash-messages flashMessages">';
  29. if ($types) {
  30. foreach ($types as $type) {
  31. // Add a div for each message using the type as the class.
  32. foreach ($messages as $messageType => $msgs) {
  33. if ($messageType !== $type) {
  34. continue;
  35. }
  36. foreach ((array)$msgs as $msg) {
  37. $html .= $this->_message($msg, $messageType);
  38. }
  39. }
  40. }
  41. } else {
  42. foreach ($messages as $messageType => $msgs) {
  43. foreach ((array)$msgs as $msg) {
  44. $html .= $this->_message($msg, $messageType);
  45. }
  46. }
  47. }
  48. $html .= '</div>';
  49. if ($types) {
  50. foreach ($types as $type) {
  51. CakeSession::delete('messages.' . $type);
  52. Configure::delete('messages.' . $type);
  53. }
  54. } else {
  55. CakeSession::delete('messages');
  56. Configure::delete('messages');
  57. }
  58. }
  59. return $html;
  60. }
  61. /**
  62. * Outputs a single flashMessage directly.
  63. * Note that this does not use the Session.
  64. *
  65. * @param string $message String to output.
  66. * @param string $type Type (success, warning, error, info)
  67. * @param bool $escape Set to false to disable escaping.
  68. * @return string HTML
  69. * @deprecated Use FlashHelper::flashMessage() instead.
  70. */
  71. public function flashMessage($msg, $type = 'info', $escape = true) {
  72. $html = '<div class="flash-messages flashMessages">';
  73. if ($escape) {
  74. $msg = h($msg);
  75. }
  76. $html .= $this->_message($msg, $type);
  77. $html .= '</div>';
  78. return $html;
  79. }
  80. /**
  81. * Formats a message
  82. *
  83. * @param string $msg Message to output.
  84. * @param string $type Type that will be formatted to a class tag.
  85. * @return string
  86. */
  87. protected function _message($msg, $type) {
  88. if (!empty($msg)) {
  89. return '<div class="message' . (!empty($type) ? ' ' . $type : '') . '">' . $msg . '</div>';
  90. }
  91. return '';
  92. }
  93. /**
  94. * Add a message on the fly
  95. *
  96. * @param string $msg
  97. * @param string $class
  98. * @return void
  99. * @deprecated Use FlashHelper::addTransientMessage() instead.
  100. */
  101. public function addFlashMessage($msg, $class = null) {
  102. CommonComponent::transientFlashMessage($msg, $class);
  103. }
  104. /**
  105. * CommonHelper::transientFlashMessage()
  106. *
  107. * @param mixed $msg
  108. * @param mixed $class
  109. * @return void
  110. * @deprecated Use FlashHelper::addTransientMessage() instead.
  111. */
  112. public function transientFlashMessage($msg, $class = null) {
  113. $this->addFlashMessage($msg, $class);
  114. }
  115. /**
  116. * Escape text with some more automagic
  117. * TODO: move into TextExt?
  118. *
  119. * @param string $text
  120. * @param array $options
  121. * @return string processedText
  122. * - nl2br: true/false (defaults to true)
  123. * - escape: false prevents h() and space transformation (defaults to true)
  124. * - tabsToSpaces: int (defaults to 4)
  125. */
  126. public function esc($text, $options = []) {
  127. if (!isset($options['escape']) || $options['escape'] !== false) {
  128. //$text = str_replace(' ', '&nbsp;', h($text));
  129. $text = h($text);
  130. // try to fix indends made out of spaces
  131. $text = explode("\n", $text);
  132. foreach ($text as $key => $t) {
  133. $i = 0;
  134. while (!empty($t[$i]) && $t[$i] === ' ') {
  135. $i++;
  136. }
  137. if ($i > 0) {
  138. $t = str_repeat('&nbsp;', $i) . substr($t, $i);
  139. $text[$key] = $t;
  140. }
  141. }
  142. $text = implode("\n", $text);
  143. $esc = true;
  144. }
  145. if (!isset($options['nl2br']) || $options['nl2br'] !== false) {
  146. $text = nl2br($text);
  147. }
  148. if (!isset($options['tabsToSpaces'])) {
  149. $options['tabsToSpaces'] = 4;
  150. }
  151. if (!empty($options['tabsToSpaces'])) {
  152. $text = str_replace("\t", str_repeat(!empty($esc) ? '&nbsp;' : ' ', $options['tabsToSpaces']), $text);
  153. }
  154. return $text;
  155. }
  156. /**
  157. * Alternates between two or more strings.
  158. *
  159. * echo CommonHelper::alternate('one', 'two'); // "one"
  160. * echo CommonHelper::alternate('one', 'two'); // "two"
  161. * echo CommonHelper::alternate('one', 'two'); // "one"
  162. *
  163. * Note that using multiple iterations of different strings may produce
  164. * unexpected results.
  165. * TODO: move to booststrap/lib!!!
  166. *
  167. * @param string $string Strings to alternate between
  168. * @return string
  169. */
  170. public static function alternate() {
  171. static $i;
  172. if (func_num_args() === 0) {
  173. $i = 0;
  174. return '';
  175. }
  176. $args = func_get_args();
  177. return $args[($i++ % count($args))];
  178. }
  179. /**
  180. * Auto-pluralizing a word using the Inflection class
  181. * //TODO: move to lib or bootstrap
  182. *
  183. * @param string $singular The string to be pl.
  184. * @param int $count
  185. * @return string "member" or "members" OR "Mitglied"/"Mitglieder" if autoTranslate TRUE
  186. */
  187. public function asp($singular, $count, $autoTranslate = false) {
  188. if ((int)$count !== 1) {
  189. $pural = Inflector::pluralize($singular);
  190. } else {
  191. $pural = null; // No pluralization necessary
  192. }
  193. return $this->sp($singular, $pural, $count, $autoTranslate);
  194. }
  195. /**
  196. * Manual pluralizing a word using the Inflection class
  197. *
  198. * I18n will be done using default domain.
  199. *
  200. * @param string $singular
  201. * @param string $plural
  202. * @param int $count
  203. * @return string result
  204. */
  205. public function sp($singular, $plural, $count, $autoTranslate = false) {
  206. if ((int)$count !== 1) {
  207. $result = $plural;
  208. } else {
  209. $result = $singular;
  210. }
  211. if ($autoTranslate) {
  212. $result = __($result);
  213. }
  214. return $result;
  215. }
  216. /**
  217. * Convenience method for clean ROBOTS allowance
  218. *
  219. * @param string|array $type - private/public or array of (noindex,nofollow,noarchive,...)
  220. * @return string HTML
  221. */
  222. public function metaRobots($type = null) {
  223. if ($type === null && ($meta = Configure::read('Config.robots')) !== null) {
  224. $type = $meta;
  225. }
  226. $content = [];
  227. if ($type === 'public') {
  228. $content['robots'] = ['index', 'follow', 'noarchive'];
  229. } elseif (is_array($type)) {
  230. $content['robots'] = $type;
  231. } else {
  232. $content['robots'] = ['noindex', 'nofollow', 'noarchive'];
  233. }
  234. $return = '<meta name="robots" content="' . implode(',', $content['robots']) . '"/>';
  235. return $return;
  236. }
  237. /**
  238. * Convenience method for clean meta name tags
  239. *
  240. * @param string $name: author, date, generator, revisit-after, language
  241. * @param mixed $content: if array, it will be seperated by commas
  242. * @return string HTML Markup
  243. */
  244. public function metaName($name, $content = null) {
  245. if (empty($name) || empty($content)) {
  246. return '';
  247. }
  248. $content = (array)$content;
  249. $return = '<meta name="' . $name . '" content="' . implode(', ', $content) . '"/>';
  250. return $return;
  251. }
  252. /**
  253. * Convenience method for meta description
  254. *
  255. * @param string $content
  256. * @param string $language (iso2: de, en-us, ...)
  257. * @param array $additionalOptions
  258. * @return string HTML Markup
  259. */
  260. public function metaDescription($content, $language = null, $options = []) {
  261. if (!empty($language)) {
  262. $options['lang'] = mb_strtolower($language);
  263. } elseif ($language !== false) {
  264. $options['lang'] = Configure::read('Config.locale');
  265. }
  266. return $this->Html->meta('description', $content, $options);
  267. }
  268. /**
  269. * Convenience method to output meta keywords
  270. *
  271. * @param string|array $keywords
  272. * @param string $language (iso2: de, en-us, ...)
  273. * @param bool $escape
  274. * @return string HTML Markup
  275. */
  276. public function metaKeywords($keywords = null, $language = null, $escape = true) {
  277. if ($keywords === null) {
  278. $keywords = Configure::read('Config.keywords');
  279. }
  280. if (is_array($keywords)) {
  281. $keywords = implode(', ', $keywords);
  282. }
  283. if ($escape) {
  284. $keywords = h($keywords);
  285. }
  286. if (!empty($language)) {
  287. $options['lang'] = mb_strtolower($language);
  288. } elseif ($language !== false) {
  289. $options['lang'] = Configure::read('Config.locale');
  290. }
  291. return $this->Html->meta('keywords', $keywords, $options);
  292. }
  293. /**
  294. * Convenience function for "canonical" SEO links
  295. *
  296. * @param mixed $url
  297. * @param bool $full
  298. * @return string HTML Markup
  299. */
  300. public function metaCanonical($url = null, $full = false) {
  301. $canonical = $this->Html->url($url, $full);
  302. $options = ['rel' => 'canonical', 'type' => null, 'title' => null];
  303. return $this->Html->meta('canonical', $canonical, $options);
  304. }
  305. /**
  306. * Convenience method for "alternate" SEO links
  307. *
  308. * @param mixed $url
  309. * @param mixed $lang (lang(iso2) or array of langs)
  310. * lang: language (in ISO 6391-1 format) + optionally the region (in ISO 3166-1 Alpha 2 format)
  311. * - de
  312. * - de-ch
  313. * etc
  314. * @return string HTML Markup
  315. */
  316. public function metaAlternate($url, $lang, $full = false) {
  317. //$canonical = $this->Html->url($url, $full);
  318. $url = $this->Html->url($url, $full);
  319. //return $this->Html->meta('canonical', $canonical, array('rel'=>'canonical', 'type'=>null, 'title'=>null));
  320. $lang = (array)$lang;
  321. $res = [];
  322. foreach ($lang as $language => $countries) {
  323. if (is_numeric($language)) {
  324. $language = '';
  325. } else {
  326. $language .= '-';
  327. }
  328. $countries = (array)$countries;
  329. foreach ($countries as $country) {
  330. $l = $language . $country;
  331. $options = ['rel' => 'alternate', 'hreflang' => $l, 'type' => null, 'title' => null];
  332. $res[] = $this->Html->meta('alternate', $url, $options) . PHP_EOL;
  333. }
  334. }
  335. return implode('', $res);
  336. }
  337. /**
  338. * Convenience method for META Tags
  339. *
  340. * @param mixed $url
  341. * @param string $title
  342. * @return string HTML Markup
  343. */
  344. public function metaRss($url, $title = null) {
  345. $tags = [
  346. 'meta' => '<link rel="alternate" type="application/rss+xml" title="%s" href="%s"/>',
  347. ];
  348. if (empty($title)) {
  349. $title = __d('tools', 'Subscribe to this feed');
  350. } else {
  351. $title = h($title);
  352. }
  353. return sprintf($tags['meta'], $title, $this->url($url));
  354. }
  355. /**
  356. * Convenience method for META Tags
  357. *
  358. * @param string $type
  359. * @param string $content
  360. * @return string HTML Markup
  361. */
  362. public function metaEquiv($type, $value, $escape = true) {
  363. $tags = [
  364. 'meta' => '<meta http-equiv="%s"%s/>',
  365. ];
  366. if ($value === null) {
  367. return '';
  368. }
  369. if ($escape) {
  370. $value = h($value);
  371. }
  372. return sprintf($tags['meta'], $type, ' content="' . $value . '"');
  373. }
  374. /**
  375. * (example): array(x, Tools|y, Tools.Jquery|jquery/sub/z)
  376. * => x is in webroot/
  377. * => y is in plugins/tools/webroot/
  378. * => z is in plugins/tools/packages/jquery/files/jquery/sub/
  379. *
  380. * @return string HTML Markup
  381. * @deprecated Use AssetCompress plugin instead
  382. */
  383. public function css($files, array $options = []) {
  384. $files = (array)$files;
  385. $pieces = [];
  386. foreach ($files as $file) {
  387. $pieces[] = 'file=' . $file;
  388. }
  389. if ($v = Configure::read('Config.layout_v')) {
  390. $pieces[] = 'v=' . $v;
  391. }
  392. $string = implode('&', $pieces);
  393. return $this->Html->css('/css.php?' . $string, $options);
  394. }
  395. /**
  396. * (example): array(x, Tools|y, Tools.Jquery|jquery/sub/z)
  397. * => x is in webroot/
  398. * => y is in plugins/tools/webroot/
  399. * => z is in plugins/tools/packages/jquery/files/jquery/sub/
  400. *
  401. * @return string HTML Markup
  402. * @deprecated Use AssetCompress plugin instead
  403. */
  404. public function script($files, array $options = []) {
  405. $files = (array)$files;
  406. foreach ($files as $file) {
  407. $pieces[] = 'file=' . $file;
  408. }
  409. if ($v = Configure::read('Config.layout_v')) {
  410. $pieces[] = 'v=' . $v;
  411. }
  412. $string = implode('&', $pieces);
  413. return $this->Html->script('/js.php?' . $string, $options);
  414. }
  415. /**
  416. * Still necessary?
  417. *
  418. * @param array $fields
  419. * @return string HTML
  420. */
  421. public function displayErrors($fields = []) {
  422. $res = '';
  423. if (!empty($this->validationErrors)) {
  424. if ($fields === null) { # catch ALL
  425. foreach ($this->validationErrors as $alias => $error) {
  426. list($alias, $fieldname) = explode('.', $error);
  427. $this->validationErrors[$alias][$fieldname];
  428. }
  429. } elseif (!empty($fields)) {
  430. foreach ($fields as $field) {
  431. list($alias, $fieldname) = explode('.', $field);
  432. if (!empty($this->validationErrors[$alias][$fieldname])) {
  433. $res .= $this->_renderError($this->validationErrors[$alias][$fieldname]);
  434. }
  435. }
  436. }
  437. }
  438. return $res;
  439. }
  440. protected function _renderError($error, $escape = true) {
  441. if ($escape !== false) {
  442. $error = h($error);
  443. }
  444. return '<div class="error-message">' . $error . '</div>';
  445. }
  446. /**
  447. * Check if session works due to allowed cookies
  448. *
  449. * @param bool Success
  450. */
  451. public function sessionCheck() {
  452. return !CommonComponent::cookiesDisabled();
  453. /*
  454. if (!empty($_COOKIE) && !empty($_COOKIE[Configure::read('Session.cookie')])) {
  455. return true;
  456. }
  457. return false;
  458. */
  459. }
  460. /**
  461. * Display warning if cookies are disallowed (and session won't work)
  462. *
  463. * @return string HTML
  464. */
  465. public function sessionCheckAlert() {
  466. if ($this->sessionCheck()) {
  467. return '';
  468. }
  469. return '<div class="cookieWarning">' . __d('tools', 'Please enable cookies') . '</div>';
  470. }
  471. /**
  472. * Prevents site being opened/included by others/websites inside frames
  473. *
  474. * @return string
  475. */
  476. public function framebuster() {
  477. return $this->Html->scriptBlock('
  478. if (top!=self) top.location.ref=self.location.href;
  479. ');
  480. }
  481. /**
  482. * Currenctly only alerts on IE6/IE7
  483. * options
  484. * - engine (js, jquery)
  485. * - escape
  486. * needs the id element to be a present (div) container in the layout
  487. *
  488. * @return string
  489. */
  490. public function browserAlert($id, $message, $options = []) {
  491. $engine = 'js';
  492. if (!isset($options['escape']) || $options['escape'] !== false) {
  493. $message = h($message);
  494. }
  495. return $this->Html->scriptBlock('
  496. // Returns the version of Internet Explorer or a -1
  497. function getInternetExplorerVersion() {
  498. var rv = -1; // Return value assumes failure.
  499. if (navigator.appName === "Microsoft Internet Explorer") {
  500. var ua = navigator.userAgent;
  501. var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
  502. if (re.exec(ua) != null)
  503. rv = parseFloat( RegExp.$1 );
  504. }
  505. return rv;
  506. }
  507. if ((document.all) && (navigator.appVersion.indexOf("MSIE 7.") != -1) || typeof document.body.style.maxHeight == \'undefined\') {
  508. document.getElementById(\'' . $id . '\').innerHTML = \'' . $message . '\';
  509. }
  510. /*
  511. jQuery(document).ready(function() {
  512. if ($.browser.msie && $.browser.version.substring(0,1) < 8) {
  513. document.getElementById(\'' . $id . '\').innerHTML = \'' . $message . '\';
  514. }
  515. });
  516. */
  517. ');
  518. }
  519. /**
  520. * In noscript tags:
  521. * - link which should not be followed by bots!
  522. * - "pseudo"image which triggers log
  523. *
  524. * @return string
  525. */
  526. public function honeypot($noFollowUrl, $noscriptUrl = []) {
  527. $res = '<div class="invisible" style="display:none"><noscript>';
  528. $res .= $this->Html->defaultLink('Email', $noFollowUrl, ['rel' => 'nofollow']);
  529. if (!empty($noscriptUrl)) {
  530. $res .= BR . $this->Html->image($this->Html->defaultUrl($noscriptUrl, true)); //$this->Html->link($noscriptUrl);
  531. }
  532. $res .= '</noscript></div>';
  533. return $res;
  534. }
  535. /**
  536. * Print js-visit-stats-link to layout
  537. * uses Piwik open source statistics framework
  538. *
  539. * @return string
  540. * @deprecated Use element instead
  541. */
  542. public function visitStats($viewPath = null) {
  543. $res = '';
  544. if (!defined('HTTP_HOST_LIVESERVER')) {
  545. return '';
  546. }
  547. if (HTTP_HOST == HTTP_HOST_LIVESERVER && (int)Configure::read('Config.tracking') === 1) {
  548. $trackingUrl = Configure::read('Config.tracking_url');
  549. if (empty($trackingUrl)) {
  550. $trackingUrl = 'visit_stats';
  551. }
  552. $error = false;
  553. if (!empty($viewPath) && $viewPath === 'errors') {
  554. $error = true;
  555. }
  556. $res .= '
  557. <script type="text/javascript">
  558. var pkBaseURL = (("https:" == document.location.protocol) ? "https://' . HTTP_HOST . '/' . $trackingUrl . '/" : "http://' . HTTP_HOST . '/' . $trackingUrl . '/");
  559. document.write(unescape("%3Cscript src=\'" + pkBaseURL + "piwik.js\' type=\'text/javascript\'%3E%3C/script%3E"));
  560. </script>
  561. <script type="text/javascript">
  562. try {
  563. var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
  564. piwikTracker.trackPageView();
  565. piwikTracker.enableLinkTracking();
  566. ' . ($error ? 'piwikTracker.setDocumentTitle(\'404/URL = \'+encodeURIComponent(document.location.pathname+document.location.search) + \'/From = \' + encodeURIComponent(document.referrer));' : '') . '
  567. } catch( err ) {}
  568. </script>
  569. <noscript><p>' . $this->visitStatsImg() . '</p></noscript>
  570. ';
  571. }
  572. return $res;
  573. }
  574. /**
  575. * Non js browsers
  576. *
  577. * @return string
  578. * @deprecated Use element instead
  579. */
  580. public function visitStatsImg($trackingUrl = null) {
  581. if (empty($trackingUrl)) {
  582. $trackingUrl = Configure::read('Config.tracking_url');
  583. }
  584. if (empty($trackingUrl)) {
  585. $trackingUrl = 'visit_stats';
  586. }
  587. return '<img src="' . Router::url('/', true) . $trackingUrl . '/piwik.php?idsite=1" style="border:0" alt=""/>';
  588. }
  589. /**
  590. * Checks if a role is in the current users session
  591. *
  592. * @param array|null $roles Necessary right(s) as array - or a single one as string possible
  593. * @return array
  594. * @deprecated - use Auth class instead
  595. */
  596. public function roleNames($sessionRoles = null) {
  597. $tmp = [];
  598. if ($sessionRoles === null) {
  599. $sessionRoles = $this->Session->read('Auth.User.Role');
  600. }
  601. $roles = Cache::read('User.Role');
  602. if (empty($roles) || !is_array($roles)) {
  603. $Role = ClassRegistry::init('Role');
  604. $roles = $Role->getActive('list');
  605. Cache::write('User.Role', $roles);
  606. }
  607. if (!empty($sessionRoles)) {
  608. if (is_array($sessionRoles)) {
  609. foreach ($sessionRoles as $sessionRole) {
  610. if (!$sessionRole) {
  611. continue;
  612. }
  613. if (array_key_exists((int)$sessionRole, $roles)) {
  614. $tmp[$sessionRole] = $roles[(int)$sessionRole];
  615. }
  616. }
  617. } else {
  618. if (array_key_exists($sessionRoles, $roles)) {
  619. $tmp[$sessionRoles] = $roles[$sessionRoles];
  620. }
  621. }
  622. }
  623. return $tmp;
  624. }
  625. /**
  626. * Display Roles separated by Commas
  627. *
  628. * @deprecated - use Auth class instead
  629. */
  630. public function displayRoles($sessionRoles = null, $placeHolder = '---') {
  631. $roles = $this->roleNames($sessionRoles);
  632. if (!empty($roles)) {
  633. return implode(', ', $roles);
  634. }
  635. return $placeHolder;
  636. }
  637. /**
  638. * Takes int / array(int) and finds the role name to it
  639. *
  640. * @return array roles
  641. * @deprecated - use Auth class instead
  642. */
  643. public function roleNamesTranslated($value) {
  644. if (empty($value)) {
  645. return [];
  646. }
  647. $ret = [];
  648. $translate = (array)Configure::read('Role');
  649. if (is_array($value)) {
  650. foreach ($value as $k => $v) {
  651. $ret[$v] = __d('tools', $translate[$v]);
  652. }
  653. } else {
  654. $ret[$value] = __d('tools', $translate[$value]);
  655. }
  656. return $ret;
  657. }
  658. }