XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
_sample_functions.dist.php
1<?php
12
13
14
15function getLanguage() {
16 $language_array = [
17 'en' => 'english',
18// 'cn' => 'schinese',
19 'cs' => 'czech',
20// 'de' => 'german',
21 'el' => 'greek',
22// 'es' => 'spanish',
23 'fr' => 'french',
24 'ja' => 'japanese',
25 'ko' => 'korean',
26// 'nl' => 'dutch',
27 'pt' => 'pt_utf8',
28 'ru' => 'russian',
29 'zh' => 'schinese',
30
31 ];
32
33 $charset_array = [
34 'Shift_JIS' => 'ja_utf8',
35 ];
36
37 $language = 'english';
38 if ( ! empty( $_POST['lang'] ) ) {
39 $language = $_POST['lang'];
40 } else if ( isset( $_COOKIE['install_lang'] ) ) {
41 $language = $_COOKIE['install_lang'];
42 } else if ( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) {
43 $accept_langs = explode( ',', $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
44 foreach ( $accept_langs as $al ) {
45 $al = strtolower( $al );
46 $al_len = strlen( $al );
47 if ( $al_len > 2 ) {
48 if ( preg_match( '/([a-z]{2});q=[0-9.]+$/', $al, $al_match ) ) {
49 $al = $al_match[1];
50 } else {
51 continue;
52 }
53 }
54 if ( isset( $language_array[ $al ] ) ) {
55 $language = $language_array[ $al ];
56 break;
57 }
58 }
59 if ( file_exists( dirname( __DIR__ ) . '/language/' . $al . '_utf8' ) ) {
60 $language = $al . '_utf8';
61 }
62 } elseif ( isset( $_SERVER['HTTP_ACCEPT_CHARSET'] ) ) {
63 foreach ( $charset_array as $ac => $lg ) {
64 if ( strpos( $_SERVER['HTTP_ACCEPT_CHARSET'], $ac ) !== false ) {
65 $language = $lg;
66 break;
67 }
68 }
69 }
70 if ( ! file_exists( './language/' . $language . '/install.php' ) ) {
71 $language = 'english';
72 }
73 setcookie( 'install_lang', $language, ['expires' => ini_get( 'session.cookie_lifetime' ), 'path' => ini_get( 'session.cookie_path' ), 'domain' => ini_get( 'session.cookie_domain' ), 'secure' => ini_get( 'session.cookie_secure' ), 'httponly' => ini_get( 'session.cookie_httponly' )] );
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 }
149
150 return 'english';
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 if ( ! empty( $_POST['op'] ) ) {
179 $op = $_POST['op'];
180 } elseif ( ! empty( $_GET['op'] ) ) {
181 $op = $_GET['op'];
182 } else {
183 $op = 'langselect';
184 }
185
186 return '<input type="image" src="img/reload.png" class="reload" title="Reload" value="' . _INSTALL_L200 . '" onclick="location.reload();" />';
187}
188
189function b_next( $option = null ) {
190 if ( ! isset( $option ) || ! is_array( $option ) ) {
191 return '';
192 }
193 $content = '';
194 if ( isset( $option[1] ) && '' !== $option[1] ) {
195 $content .= '<span style="font-size:90%;">' . htmlspecialchars( $option[1], ENT_QUOTES | ENT_HTML5 ) . ' &gt;&gt; </span>';
196 }
197 $content .= '<input type="hidden" name="op" value="' . htmlspecialchars( $option[0], ENT_QUOTES | ENT_HTML5 ) . '" />';
198 $content .= '<input type="image" src="img/next.png" class="next" title="' . _INSTALL_L47 . '" name="submit" value="' . _INSTALL_L47 . '" />';
199
200 return $content;
201}