CommonHelper.php 18 KB

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