PageRenderTime 49ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/system/expressionengine/core/EE_Lang.php

https://bitbucket.org/tdevonshire/hoolux
PHP | 229 lines | 131 code | 39 blank | 59 comment | 31 complexity | e20fdc0b878cbbe55d2114b544a3dbe5 MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * ExpressionEngine - by EllisLab
  4. *
  5. * @package ExpressionEngine
  6. * @author EllisLab Dev Team
  7. * @copyright Copyright (c) 2003 - 2012, EllisLab, Inc.
  8. * @license http://ellislab.com/expressionengine/user-guide/license.html
  9. * @link http://ellislab.com
  10. * @since Version 2.0
  11. * @filesource
  12. */
  13. // ------------------------------------------------------------------------
  14. /**
  15. * ExpressionEngine Core Language Class
  16. *
  17. * @package ExpressionEngine
  18. * @subpackage Core
  19. * @category Core
  20. * @author EllisLab Dev Team
  21. * @link http://ellislab.com
  22. */
  23. class EE_Lang extends CI_Lang {
  24. var $user_lang = '';
  25. // --------------------------------------------------------------------
  26. /**
  27. * Add a language file to the main language array
  28. *
  29. * @access public
  30. * @param string
  31. * @return void
  32. */
  33. function loadfile($which = '', $package = '', $show_errors = TRUE)
  34. {
  35. if ($which == '')
  36. {
  37. return;
  38. }
  39. $EE =& get_instance();
  40. if (isset($EE->session->userdata['language']) && $EE->session->userdata['language'] != '')
  41. {
  42. $this->user_lang = $EE->session->userdata['language'];
  43. }
  44. else
  45. {
  46. if ($EE->input->cookie('language'))
  47. {
  48. $this->user_lang = $EE->input->cookie('language');
  49. }
  50. elseif ($EE->config->item('deft_lang') != '')
  51. {
  52. $this->user_lang = $EE->config->item('deft_lang');
  53. }
  54. else
  55. {
  56. $this->user_lang = 'english';
  57. }
  58. }
  59. $deft_lang = ( ! $EE->config->item('language')) ? 'english' : $EE->config->item('language');
  60. // Sec.ur.ity code. ::sigh::
  61. $package = ($package == '') ? $EE->security->sanitize_filename(str_replace(array('lang.', '.php'), '', $which)) : $EE->security->sanitize_filename($package);
  62. $which = str_replace('lang.', '', $which);
  63. $this->user_lang = $EE->security->sanitize_filename($this->user_lang);
  64. if ($which == 'sites_cp')
  65. {
  66. $phrase = 'base'.'6'.'4_d'.'ecode';
  67. eval($phrase(preg_replace("|\s+|is", '', "JEVFLT5sb2FkLT5saWJyYXJ5KCJzaXRlcyIpOyRFRV9TaXRlcyA9IG5ldyB
  68. FRV9TaXRlcygpOyAkc3RyaW5nID0gYmFzZTY0X2RlY29kZSgkRUVfU2l0ZXMtPnRoZV9zaXRlc19hbGxvd2VkLiRFRV9TaXRlcy0
  69. +bnVtX3NpdGVzX2FsbG93ZWQuJEVFX1NpdGVzLT5zaXRlc19hbGxvd2VkX251bSk7ICRoYXNoID0gbWQ1KCJNU00gQnkgRWxsaXN
  70. MYWIiKTsgZm9yICgkaSA9IDAsICRzdHIgPSAiIjsgJGkgPCBzdHJsZW4oJHN0cmluZyk7ICRpKyspIHsgJHN0ciAuPSBzdWJzdHI
  71. oJHN0cmluZywgJGksIDEpIF4gc3Vic3RyKCRoYXNoLCAoJGkgJSBzdHJsZW4oJGhhc2gpKSwgMSk7IH0gJHN0cmluZyA9ICRzdHI
  72. 7IGZvciAoJGkgPSAwLCAkZGVjID0gIiI7ICRpIDwgc3RybGVuKCRzdHJpbmcpOyAkaSsrKSB7ICRkZWMgLj0gKHN1YnN0cigkc3R
  73. yaW5nLCAkaSsrLCAxKSBeIHN1YnN0cigkc3RyaW5nLCAkaSwgMSkpOyB9ICRhbGxvd2VkID0gc3Vic3RyKGJhc2U2NF9kZWNvZGU
  74. oc3Vic3RyKGJhc2U2NF9kZWNvZGUoc3Vic3RyKGJhc2U2NF9kZWNvZGUoc3Vic3RyKCRkZWMsMikpLDUpKSw0KSksMik7ICRxdWV
  75. yeSA9ICRFRS0+ZGItPnF1ZXJ5KCJTRUxFQ1QgQ09VTlQoKikgQVMgY291bnQgRlJPTSBleHBfc2l0ZXMiKTsgaWYgKCAhIGlzX25
  76. 1bWVyaWMoJGFsbG93ZWQpIE9SICRxdWVyeS0+cm93KCJjb3VudCIpID49ICRhbGxvd2VkKSB7ICR0aGlzLT5sYW5ndWFnZVsiY3J
  77. lYXRlX25ld19zaXRlIl0gPSAiIjsgaWYgKGlzc2V0KCRfR0VUWyJNIl0pICYmIGluX2FycmF5KCRfR0VUWyJNIl0sIGFycmF5KCJ
  78. hZGRfZWRpdF9zaXRlIiwgInVwZGF0ZV9zaXRlIikpICYmICEgJEVFLT5pbnB1dC0+Z2V0X3Bvc3QoInNpdGVfaWQiKSkgeyBkaWU
  79. oIk11bHRpcGxlIFNpdGUgTWFuYWdlciBFcnJvciAtIFNpdGUgTGltaXQgUmVhY2hlZCIpOyB9IH0="))); return;
  80. }
  81. $this->load($which, $this->user_lang, FALSE, TRUE, PATH_THIRD.$package.'/', $show_errors);
  82. }
  83. // --------------------------------------------------------------------
  84. /**
  85. * Load a language file
  86. *
  87. * Differs from CI's Lang::load() in that it checks each file for a default language version
  88. * as a backup. Not sure this is appropriate for CI at large.
  89. *
  90. * @access public
  91. * @param mixed the name of the language file to be loaded. Can be an array
  92. * @param string the language (english, etc.)
  93. * @return mixed
  94. */
  95. function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '', $show_errors = TRUE)
  96. {
  97. static $deft_lang;
  98. $langfile = str_replace('.php', '', $langfile);
  99. if ($add_suffix == TRUE)
  100. {
  101. $langfile = str_replace('_lang.', '', $langfile).'_lang';
  102. }
  103. $langfile .= '.php';
  104. if (in_array($langfile, $this->is_loaded, TRUE))
  105. {
  106. return;
  107. }
  108. if ( ! isset($deft_lang))
  109. {
  110. $config =& get_config();
  111. $deft_lang = ( ! isset($config['language'])) ? 'english' : $config['language'];
  112. }
  113. if ($idiom == '')
  114. {
  115. $idiom = ($this->user_lang == '') ? 'english' : $this->user_lang;
  116. }
  117. // figure out where the lang file is, checking for the requested
  118. // idiom first, then falling back on the default language
  119. $paths = array(
  120. APPPATH.'language/'.$idiom.'/'.$langfile,
  121. APPPATH.'language/'.$deft_lang.'/'.$langfile,
  122. BASEPATH.'language/'.$idiom.'/'.$langfile,
  123. BASEPATH.'language/'.$deft_lang.'/'.$langfile
  124. );
  125. // if it's in an alternate location, such as a package, check there first
  126. if ($alt_path != '')
  127. {
  128. // Temporary! Rename your language files!
  129. $third_party_old = 'lang.'.str_replace('_lang.', '.', $langfile);
  130. array_unshift($paths, $alt_path.'language/'.$deft_lang.'/'.$third_party_old);
  131. array_unshift($paths, $alt_path.'language/'.$idiom.'/'.$third_party_old);
  132. array_unshift($paths, $alt_path.'language/'.$deft_lang.'/'.$langfile);
  133. array_unshift($paths, $alt_path.'language/'.$idiom.'/'.$langfile);
  134. }
  135. // if idiom and deft_lang are the same, don't check those paths twice
  136. $paths = array_unique($paths);
  137. $success = FALSE;
  138. foreach($paths as $path)
  139. {
  140. if (file_exists($path) && include $path)
  141. {
  142. $success = TRUE;
  143. break;
  144. }
  145. }
  146. if ($show_errors && $success !== TRUE)
  147. {
  148. show_error('Unable to load the requested language file: language/'.$idiom.'/'.$langfile);
  149. }
  150. if ( ! isset($lang))
  151. {
  152. log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile);
  153. return;
  154. }
  155. if ($return == TRUE)
  156. {
  157. return $lang;
  158. }
  159. $this->is_loaded[] = $langfile;
  160. $this->language = array_merge($this->language, $lang);
  161. unset($lang);
  162. log_message('debug', 'Language file loaded: language/'.$idiom.'/'.$langfile);
  163. return TRUE;
  164. }
  165. // --------------------------------------------------------------------
  166. /**
  167. * Fetch a specific line of text
  168. *
  169. * @access public
  170. * @param string
  171. * @param string
  172. * @return string
  173. */
  174. function line($which = '', $label = '')
  175. {
  176. if ($which != '')
  177. {
  178. $EE =& get_instance();
  179. $line = ( ! isset($this->language[$which])) ? $which : $this->language[$which];
  180. if ($label != '')
  181. {
  182. $line = '<label for="'.$label.'">'.$line."</label>";
  183. }
  184. return stripslashes($line);
  185. }
  186. }
  187. }
  188. // END CLASS
  189. /* End of file EE_Lang.php */
  190. /* Location: ./system/expressionengine/libraries/EE_Lang.php */