CommonHelper.php 19 KB

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