XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
_sample_functions.org.php
1<?php
12
13
14function getLanguage() {
15 $language_array = [
16 'en' => 'english',
17// 'cn' => 'schinese',
18 'cs' => 'czech',
19// 'de' => 'german',
20 'el' => 'greek',
21// 'es' => 'spanish',
22 'fr' => 'french',
23 'ja' => 'japanese',
24 'ko' => 'korean',
25// 'nl' => 'dutch',
26 'pt' => 'pt_utf8',
27 'ru' => 'russian',
28 'zh' => 'schinese',
29
30 ];
31
32 $charset_array = [
33 'Shift_JIS' => 'ja_utf8',
34 ];
35
36 $language = 'english';
37 if ( ! empty( $_POST['lang'] ) ) {
38 $language = $_POST['lang'];
39 } else {
40 if ( isset( $_COOKIE['install_lang'] ) ) {
41 $language = $_COOKIE['install_lang'];
42 } else {
43 if ( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) {
44 $accept_langs = explode( ',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
45 foreach ( $accept_langs as $al ) {
46 $al = strtolower( $al );
47 $al_len = strlen( $al );
48 if ( $al_len > 2 ) {
49 if ( preg_match( '/([a-z]{2});q=[0-9.]+$/', $al, $al_match ) ) {
50 $al = $al_match[1];
51 } else {
52 continue;
53 }
54 }
55 if ( isset( $language_array[ $al ] ) ) {
56 $language = $language_array[ $al ];
57 break;
58 }
59 }
60 } elseif ( isset( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
61 foreach ( $charset_array as $ac => $lg ) {
62 if ( strstr( $_SERVER['HTTP_ACCEPT_CHARSET'], $ac ) ) {
63 $language = $lg;
64 break;
65 }
66 }
67 }
68 }
69 }
70 if ( ! file_exists( './language/' . $language . '/install.php' ) ) {
71 $language = 'english';
72 }
73 setcookie( 'install_lang', $language );
74
75 return $language;
76}
77
78/*
79 * gets list of name of directories inside a directory
80 */
81function getDirList( $dirname ) {
82 $dirlist = [];
83 if ( is_dir( $dirname ) && $handle = opendir( $dirname ) ) {
84 while ( false !== ( $file = readdir( $handle ) ) ) {
85 if ( ! preg_match( '/^[.]{1,2}$/', $file ) ) {
86 if ( 'cvs' != strtolower( $file ) && is_dir( $dirname . $file ) ) {
87 $dirlist[ $file ] = $file;
88 }
89 }
90 }
91 closedir( $handle );
92 asort( $dirlist );
93 reset( $dirlist );
94 }
95
96 return $dirlist;
97}
98
99/*
100 * gets list of name of files within a directory
101 */
102function getImageFileList( $dirname ) {
103 $filelist = [];
104 if ( is_dir( $dirname ) && $handle = opendir( $dirname ) ) {
105 while ( false !== ( $file = readdir( $handle ) ) ) {
106 if ( ! preg_match( '/^[.]{1,2}$/', $file ) && preg_match( '/[.gif|.jpg|.png]$/i', $file ) ) {
107 $filelist[ $file ] = $file;
108 }
109 }
110 closedir( $handle );
111 asort( $filelist );
112 reset( $filelist );
113 }
114
115 return $filelist;
116}
117
118function &xoops_module_gettemplate( $dirname, $template, $block = false ) {
119 if ( $block ) {
120 $path = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/templates/blocks/' . $template;
121 } else {
122 $path = XOOPS_ROOT_PATH . '/modules/' . $dirname . '/templates/' . $template;
123 }
124 if ( ! file_exists( $path ) ) {
125 $ret = false;
126
127 return $ret;
128 } else {
129 $lines = file( $path );
130 }
131 if ( ! $lines ) {
132 $ret = false;
133
134 return $ret;
135 }
136 $ret = '';
137 $count = count( $lines );
138 for ( $i = 0; $i < $count; $i ++ ) {
139 $ret .= str_replace( "\n", "\r\n", str_replace( "\r\n", "\n", $lines[ $i ] ) );
140 }
141
142 return $ret;
143}
144
145function check_language( $language ) {
146 if ( file_exists( './language/' . $language . '/install.php' ) ) {
147 return $language;
148 } else {
149 return 'english';
150 }
151}
152
153function b_back( $option = null ) {
154 if ( ! isset( $option ) || ! is_array( $option ) ) {
155 return '';
156 }
157 $content = '';
158 if ( isset( $option[0] ) && '' != $option[0] ) {
159 $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>';
160 } else {
161 $content .= '<a href="javascript:history.back();" class="back" style="display:inline-block;vertical-align:top;"><img src="img/back.png" alt="' . _INSTALL_L42 . '"></a>';
162 }
163 if ( isset( $option[1] ) && '' != $option[1] ) {
164 $content .= '<span style="font-size:90%;"> &lt;&lt; ' . htmlspecialchars( $option[1] ) . '</span>';
165 }
166
167 return $content;
168}
169
170function b_reload( $option = '' ) {
171 if ( empty( $option ) ) {
172 return '';
173 }
174 if ( ! defined( '_INSTALL_L200' ) ) {
175 define( '_INSTALL_L200', 'Reload' );
176 }
177
178 return '<input type="image" src="img/reload.png" class="reload" title="Reload" value="' . _INSTALL_L200 . '" onclick="location.reload();">';
179}
180
181function b_next( $option = null ) {
182 if ( ! isset( $option ) || ! is_array( $option ) ) {
183 return '';
184 }
185 $content = '';
186 if ( isset( $option[1] ) && '' != $option[1] ) {
187 $content .= '<span style="font-size:90%;">' . htmlspecialchars( $option[1] ) . ' &gt;&gt; </span>';
188 }
189 $content .= '<input type="hidden" name="op" value="' . htmlspecialchars( $option[0] ) . '">';
190 $content .= '<input type="image" src="img/next.png" class="next" title="' . _INSTALL_L47 . '" name="submit" value="' . _INSTALL_L47 . '">';
191
192 return $content;
193}