PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/html/install/include/functions.php

http://xoopscube-modules.googlecode.com/
PHP | 197 lines | 151 code | 11 blank | 35 comment | 48 complexity | 488b7a3f8dad2fbda66f20d0bd1726f7 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. // $Id: functions.php,v 1.4 2008/08/28 14:43:24 minahito Exp $
  3. // ------------------------------------------------------------------------ //
  4. // XOOPS - PHP Content Management System //
  5. // Copyright (c) 2000 XOOPS.org //
  6. // <http://www.xoops.org/> //
  7. // ------------------------------------------------------------------------ //
  8. // This program is free software; you can redistribute it and/or modify //
  9. // it under the terms of the GNU General Public License as published by //
  10. // the Free Software Foundation; either version 2 of the License, or //
  11. // (at your option) any later version. //
  12. // //
  13. // You may not change or alter any portion of this comment or credits //
  14. // of supporting developers from this source code or any supporting //
  15. // source code which is considered copyrighted (c) material of the //
  16. // original comment or credit authors. //
  17. // //
  18. // This program is distributed in the hope that it will be useful, //
  19. // but WITHOUT ANY WARRANTY; without even the implied warranty of //
  20. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
  21. // GNU General Public License for more details. //
  22. // //
  23. // You should have received a copy of the GNU General Public License //
  24. // along with this program; if not, write to the Free Software //
  25. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
  26. // ------------------------------------------------------------------------ //
  27. function getLanguage() {
  28. $language_array = array(
  29. 'en' => 'english',
  30. // 'cn' => 'schinese',
  31. 'cs' => 'czech',
  32. // 'de' => 'german',
  33. 'el' => 'greek',
  34. // 'es' => 'spanish',
  35. 'fr' => 'french',
  36. 'ja' => 'japanese',
  37. 'ko' => 'korean',
  38. // 'nl' => 'dutch',
  39. 'pt' => 'portuguese',
  40. 'ru' => 'russian',
  41. 'zh' => 'schinese',
  42. );
  43. $charset_array = array(
  44. 'Shift_JIS' => 'ja_utf8',
  45. );
  46. $language = 'english';
  47. if ( !empty($_POST['lang']) ) {
  48. $language = $_POST['lang'];
  49. } else {
  50. if (isset($_COOKIE['install_lang'])) {
  51. $language = $_COOKIE['install_lang'];
  52. } else {
  53. if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  54. $accept_langs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
  55. foreach ($accept_langs as $al) {
  56. $al = strtolower($al);
  57. $al_len = strlen($al);
  58. if ($al_len > 2) {
  59. if (preg_match('/([a-z]{2});q=[0-9.]+$/', $al, $al_match)) {
  60. $al = $al_match[1];
  61. } else {
  62. continue;
  63. }
  64. }
  65. if (isset($language_array[$al])) {
  66. $language = $language_array[$al];
  67. break;
  68. }
  69. }
  70. } else if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) {
  71. foreach ($charset_array as $ac => $lg) {
  72. if (strstr($_SERVER['HTTP_ACCEPT_CHARSET'],$ac)) {
  73. $language = $lg ;
  74. break ;
  75. }
  76. }
  77. }
  78. }
  79. }
  80. if ( !file_exists('./language/'.$language.'/install.php') ) {
  81. $language = 'english';
  82. }
  83. setcookie('install_lang', $language);
  84. return $language;
  85. }
  86. /*
  87. * gets list of name of directories inside a directory
  88. */
  89. function getDirList($dirname)
  90. {
  91. $dirlist = array();
  92. if (is_dir($dirname) && $handle = opendir($dirname)) {
  93. while (false !== ($file = readdir($handle))) {
  94. if ( !preg_match('/^[.]{1,2}$/',$file) ) {
  95. if (strtolower($file) != 'cvs' && is_dir($dirname.$file) ) {
  96. $dirlist[$file]=$file;
  97. }
  98. }
  99. }
  100. closedir($handle);
  101. asort($dirlist);
  102. reset($dirlist);
  103. }
  104. return $dirlist;
  105. }
  106. /*
  107. * gets list of name of files within a directory
  108. */
  109. function getImageFileList($dirname)
  110. {
  111. $filelist = array();
  112. if (is_dir($dirname) && $handle = opendir($dirname)) {
  113. while (false !== ($file = readdir($handle))) {
  114. if (!preg_match('/^[.]{1,2}$/', $file) && preg_match('/[.gif|.jpg|.png]$/i', $file) ) {
  115. $filelist[$file]=$file;
  116. }
  117. }
  118. closedir($handle);
  119. asort($filelist);
  120. reset($filelist);
  121. }
  122. return $filelist;
  123. }
  124. function &xoops_module_gettemplate($dirname, $template, $block=false)
  125. {
  126. if ($block) {
  127. $path = XOOPS_ROOT_PATH.'/modules/'.$dirname.'/templates/blocks/'.$template;
  128. } else {
  129. $path = XOOPS_ROOT_PATH.'/modules/'.$dirname.'/templates/'.$template;
  130. }
  131. if (!file_exists($path)) {
  132. $ret = false;
  133. return $ret;
  134. } else {
  135. $lines = file($path);
  136. }
  137. if (!$lines) {
  138. $ret = false;
  139. return $ret;
  140. }
  141. $ret = '';
  142. $count = count($lines);
  143. for ($i = 0; $i < $count; $i++) {
  144. $ret .= str_replace("\n", "\r\n", str_replace("\r\n", "\n", $lines[$i]));
  145. }
  146. return $ret;
  147. }
  148. function check_language($language){
  149. if ( file_exists('./language/'.$language.'/install.php') ) {
  150. return $language;
  151. } else {
  152. return 'english';
  153. }
  154. }
  155. function b_back($option = null)
  156. {
  157. if(!isset($option) || !is_array($option)) return '';
  158. $content = '';
  159. if(isset($option[0]) && $option[0] != ''){
  160. $content .= '<a href="javascript:void(0);" onclick=\'location.href="index.php?op='.htmlspecialchars($option[0]).'"\' class="back" style="display:inline-block;vertical-align:top;"><img src="img/back.png" alt="'._INSTALL_L42.'"></a>';
  161. }else{
  162. $content .= '<a href="javascript:history.back();" class="back" style="display:inline-block;vertical-align:top;"><img src="img/back.png" alt="'._INSTALL_L42.'" /></a>';
  163. }
  164. if(isset($option[1]) && $option[1] != ''){
  165. $content .= '<span style="font-size:90%;"> &lt;&lt; '.htmlspecialchars($option[1]).'</span>';
  166. }
  167. return $content;
  168. }
  169. function b_reload($option=''){
  170. if(empty($option)) return '';
  171. if (!defined('_INSTALL_L200')) {
  172. define('_INSTALL_L200', 'Reload');
  173. }
  174. return '<input type="image" src="img/reload.png" class="reload" title="Reload" value="'._INSTALL_L200.'" onclick="location.reload();" />';
  175. }
  176. function b_next($option=null){
  177. if(!isset($option) || !is_array($option)) return '';
  178. $content = '';
  179. if(isset($option[1]) && $option[1] != ''){
  180. $content .= '<span style="font-size:90%;">'.htmlspecialchars($option[1]).' &gt;&gt; </span>';
  181. }
  182. $content .= '<input type="hidden" name="op" value="'.htmlspecialchars($option[0]).'" />';
  183. $content .= '<input type="image" src="img/next.png" class="next" title="'._INSTALL_L47.'" name="submit" value="'._INSTALL_L47.'" />';
  184. return $content;
  185. }
  186. ?>