2024.8.23
Loading...
Searching...
No Matches
wb_generic.inc.php File Reference

Go to the source code of this file.

Functions

 generate_ini ($data, $comments="")
 
if(PHP_VERSION< "5.0.0") get_folder_files ($path, $subdirs=false, $fullname=true, $mask="", $forcelowercase=TRUE)
 
 parse_ini ($initext, $changecase=TRUE, $convertwords=TRUE)
 

Function Documentation

◆ generate_ini()

generate_ini ( $data,
$comments = "" )

Definition at line 83 of file wb_generic.inc.php.

84{
85 if(!is_array($data)) {
86 trigger_error(__FUNCTION__ . ": Cannot save INI file.");
87 return null;
88 }
89 $text = $comments;
90 foreach($data as $name=>$section) {
91 $text .= "\r\n[$name]\r\n";
92
93 foreach($section as $key=>$value) {
94 $value = trim($value);
95 if((string)((int)$value) == (string)$value) // Integer: does nothing
96 ;
97 elseif((string)((float)$value) == (string)$value) // Floating point: does nothing
98 ;
99 elseif($value === "") // Empty string
100 $value = '""';
101 elseif(strstr($value, '"')) // Escape double-quotes
102 $value = '"' . str_replace('"', '\"', $value) . '"';
103 else
104 $value = '"' . $value . '"';
105
106 $text .= "$key = " . $value . "\r\n";
107 }
108 }
109 return $text;
110}
if(in_array($proc, $procs)) else
Definition ajax.php:58

◆ get_folder_files()

if(PHP_VERSION< "5.0.0") get_folder_files ( $path,
$subdirs = false,
$fullname = true,
$mask = "",
$forcelowercase = TRUE )

Definition at line 46 of file wb_generic.inc.php.

47{
48 // Correct path name, if needed
49
50 $path = str_replace('/', '\\', $path);
51 if(substr($path, -1) != '\\')
52 $path .= "\\";
53 if(!$path || !@is_dir($path))
54 return array();
55
56 // Browse the subdiretory list recursively
57
58 $dir = array();
59 if($handle = opendir($path)) {
60 while(($file = readdir($handle)) !== false) {
61 if(!is_dir($path.$file)) { // No directories / subdirectories
62 if($forcelowercase)
63 $file = strtolower($file);
64 if(!$mask) {
65 $dir[] = $fullname ? $path.$file : $file;
66 } else if($mask && preg_match($mask, $file)) {
67 $dir[] = $fullname ? $path.$file : $file;
68 }
69 } else if($subdirs && $file[0] != ".") { // Exclude "." and ".."
70 $dir = array_merge($dir, get_folder_files($path.$file, $subdirs, $fullname, $mask));
71 }
72 }
73 }
74 closedir($handle);
75 return $dir;
76}
if(PHP_VERSION< "5.0.0") get_folder_files($path, $subdirs=false, $fullname=true, $mask="", $forcelowercase=TRUE)

References get_folder_files().

Referenced by get_folder_files().

+ Here is the caller graph for this function:

◆ parse_ini()

parse_ini ( $initext,
$changecase = TRUE,
$convertwords = TRUE )

Definition at line 119 of file wb_generic.inc.php.

120{
121 $ini = preg_split("/\r\n|\n/", $initext);
122 $secpattern = "/^\[(.[^\]]*)\]/i";
123// $entrypattern = "/^([a-z_0-9]*)\s*=\s*\"?([^\"]*)?\"?" . '$' . "/i";
124// $strpattern = "/^\"?(.[^\"]*)\"?" . '$' . "/i";
125 $entrypattern = "/^([a-z_0-9]*)\s*=\s*\"?([^\"]*)?\"?\$/i";
126 $strpattern = "/^\"?(.[^\"]*)\"?\$/i";
127
128 $section = array();
129 $sec = "";
130
131 // Predefined words
132
133 static $words = array("yes", "on", "true", "no", "off", "false", "null");
134 static $values = array( 1, 1, 1, 0, 0, 0, null);
135
136 // Lines loop
137
138 for($i = 0; $i < count($ini); $i++) {
139
140 $line = trim($ini[$i]);
141
142 // Replaces escaped double-quotes (\") with special signal /%quote%/
143
144 if(strstr($line, '\"'))
145 $line = str_replace('\"', '/%quote%/', $line);
146
147 // Skips blank lines and comments
148
149 if($line == "" || preg_match("/^;/i", $line))
150 continue;
151
152 if(preg_match($secpattern, $line, $matches)) {
153
154 // It's a section
155
156 $sec = $matches[1];
157
158 if($changecase)
159 $sec = ucfirst(strtolower($sec));
160
161 $section[$sec] = array();
162
163 } elseif(preg_match($entrypattern, $line, $matches)) {
164
165 // It's an entry
166
167 $entry = $matches[1];
168
169 if($changecase)
170 $entry = strtolower($entry);
171
172 $value = preg_replace($entrypattern, "\\2", $line);
173
174 // Restores double-quotes (")
175
176 $value = str_replace('/%quote%/', '"', $value);
177
178 // Convert some special words to their respective values
179
180 if($convertwords) {
181 $index = array_search(strtolower($value), $words);
182 if($index !== false)
183 $value = $values[$index];
184 }
185
186 $section[$sec][$entry] = $value;
187
188 } else {
189
190 // It's a normal string
191
192 $section[$sec][] = preg_replace($strpattern, "\\1", $line);
193
194 }
195 }
196 return $section;
197}