- Timestamp:
- Jun 30, 2014, 9:02:54 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/plugin_lang_analysis/include/functions.inc.php
r28862 r28876 3 3 4 4 /** 5 * list files of a plugin 6 * @param: string $id, plugin id 7 * @return: array of paths relative to plugin root 5 * List files of a plugin 6 * @param string $id, plugin id 7 * @return nested array of paths relative to plugin root 8 * Keys are numeric for files or directory name 9 * Values are file name or array of more entries 8 10 */ 9 11 function list_plugin_files($id, $path=null) … … 16 18 if ($path == '/language/') 17 19 { 18 return array();20 return null; 19 21 } 20 22 21 23 if (strlen($path)-strrpos($path, '_data/') == 6) 22 24 { 23 return array();25 return null; 24 26 } 25 27 26 28 if (($handle = @opendir(PHPWG_PLUGINS_PATH.$id.$path)) === false) 27 29 { 28 return array();30 return null; 29 31 } 30 32 … … 37 39 if (is_dir(PHPWG_PLUGINS_PATH.$id.$path.$entry)) 38 40 { 39 $data = array_merge($data, list_plugin_files($id, $path.$entry.'/'));41 $data[$entry.'/'] = list_plugin_files($id, $path.$entry.'/'); 40 42 } 41 43 else … … 44 46 if (in_array($ext, array('php', 'tpl'))) 45 47 { 46 $data[] = $ path.$entry;48 $data[] = $entry; 47 49 } 48 50 } … … 51 53 closedir($handle); 52 54 53 return $data; 55 uksort($data, 'custom_folder_sort'); 56 57 return array_filter($data); 58 } 59 60 /** 61 * Merges the result of *list_plugin_files* and data from cache 62 * Needs the result of *list_plugin_languages_files* and *get_loaded_in_main* in global scope 63 * 64 * @param array &$files 65 * @param array $saved_files 66 * @return nested array of files with metadata 67 * Keys are numeric for files or directory name 68 * Values are file metadata (filename, is_admin, ignore, lang_files) or array of more entries 69 */ 70 function populate_plugin_files(&$files, $saved_files, $root='/', $is_admin=false) 71 { 72 global $language_files, $default_lang_files; 73 74 foreach ($files as $id => &$file) 75 { 76 if (is_array($file)) 77 { 78 populate_plugin_files($file, 79 isset($saved_files[$id]) ? $saved_files[$id] : array(), 80 $root.$id, 81 strpos($id, 'admin') !== false || $is_admin 82 ); 83 } 84 else if (isset($saved_files[ $file ])) 85 { 86 $id = $file; 87 $file = $saved_files[ $id ]; 88 $file['filename'] = $id; 89 $file['lang_files'] = array_intersect($file['lang_files'], array_keys($language_files)); 90 } 91 else 92 { 93 $id = $file; 94 $file = array( 95 'filename' => $id, 96 'is_admin' => strpos($id, 'admin') !== false || $is_admin, 97 'ignore' => false, 98 'lang_files' => $default_lang_files, 99 ); 100 } 101 } 102 unset($file); 103 } 104 105 /** 106 * Sanitize the result of config form for direct usage and cache 107 * @param array &$files 108 * @return nested array of files with metadata 109 * Keys are file name or directory name 110 * Values are file metadata (is_admin, ignore, lang_files) or array of more entries 111 */ 112 function clean_files_from_config(&$files) 113 { 114 foreach ($files as $id => &$file) 115 { 116 if (!isset($file['ignore'])) 117 { 118 clean_files_from_config($file); 119 } 120 // security against max_input_vars overflow 121 else if (isset($file['is_admin']) && isset($file['ignore']) && isset($file['lang_files'])) 122 { 123 $file['is_admin'] = get_boolean($file['is_admin']); 124 $file['ignore'] = get_boolean($file['ignore']); 125 $file['lang_files'] = array_keys(array_filter($file['lang_files'], 'get_boolean')); 126 } 127 } 128 unset($file); 129 } 130 131 /** 132 * Custom sort callback for files and directories 133 * Alphabetic order with files before directories 134 */ 135 function custom_folder_sort($a, $b) 136 { 137 if (is_int($a) && is_int($b)) 138 { 139 return $a-$b; 140 } 141 else if (is_string($a) && is_string($b)) 142 { 143 return strnatcasecmp($a, $b); 144 } 145 else if (is_string($a) && is_int($b)) 146 { 147 return 1; 148 } 149 else 150 { 151 return -1; 152 } 54 153 } 55 154 … … 76 175 if (!is_dir(PHPWG_PLUGINS_PATH.$id.$path.$entry)) 77 176 { 78 $ext = strtolower(get_extension($entry)); 79 if ($ext == 'php') 177 if (get_extension($entry) == 'php') 80 178 { 81 179 $data[ basename($entry, '.php') ] = $path.$entry; … … 87 185 88 186 return $data; 187 } 188 189 /** 190 * Construct the list of all used strings in the plugin files 191 * @param string $plugin 192 * @param array $files 193 * @return array multidimensional 194 */ 195 function analyze_files($plugin, $files, &$strings = array(), $path='') 196 { 197 foreach ($files as $id => $file) 198 { 199 if (!isset($file['ignore'])) 200 { 201 analyze_files($plugin, $file, $strings, $path.$id); 202 } 203 else 204 { 205 if ($file['ignore']) continue; 206 207 $file_strings = analyze_file($plugin.'/'.$path.$id); 208 209 foreach ($file_strings as $string => $lines) 210 { 211 $strings[ $string ]['files'][ $path.$id ] = $file + array('lines' => $lines); 212 } 213 } 214 } 215 216 return $strings; 89 217 } 90 218 … … 111 239 } 112 240 // translate 113 if (preg_match_all('#\\{\\\\ {0,1}["\']{1}(.*?)\\\\{0,1}["\']{1}\\|@?translate#', $line, $matches))241 if (preg_match_all('#\\{\\\\?["\']{1}(.*?)\\\\?["\']{1}\\|@?translate#', $line, $matches)) 114 242 { 115 243 for ($j=0; $j<count($matches[1]); ++$j) … … 119 247 } 120 248 // translate_dec 121 if (preg_match_all('#translate_dec:\\\\ {0,1}["\']{1}(.*?)\\\\{0,1}["\']{1}:\\\\{0,1}["\']{1}(.*?)\\\\{0,1}["\']{1}}#', $line, $matches))249 if (preg_match_all('#translate_dec:\\\\?["\']{1}(.*?)\\\\?["\']{1}:\\\\?["\']{1}(.*?)\\\\?["\']{1}}#', $line, $matches)) 122 250 { 123 251 for ($j=0; $j<count($matches[1]); ++$j) … … 179 307 $files = array(); 180 308 181 if (preg_match_all('#load_language\ ((?:\s*)(?:["\']{1})(.*?)(?:["\']{1})#', $content, $matches))309 if (preg_match_all('#load_language\\(\s*["\']{1}(.*?)["\']{1}#', $content, $matches)) 182 310 { 183 311 $files = $matches[1]; … … 196 324 return $lang; 197 325 } 198 199 ?>
Note: See TracChangeset
for help on using the changeset viewer.