[ Index ] |
|
Code source de Horde 3.1.3 |
1 #!/usr/bin/php 2 <?php 3 /** 4 * This script does some checking of themes, to make sure images are 5 * synchronised across themes. 6 * 7 * $Horde: horde/scripts/themes_check.php,v 1.3.10.5 2006/04/18 16:26:05 jan Exp $ 8 * 9 * Copyright 2003-2006 The Horde Project (http://www.horde.org/) 10 * 11 * See the enclosed file COPYING for license information (LGPL). If you 12 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 13 * 14 * @author Marko Djukic <marko@oblo.com> 15 * @since Horde 3.0 16 */ 17 18 @define('AUTH_HANDLER', true); 19 @define('HORDE_BASE', dirname(__FILE__) . '/..'); 20 21 /* CLI checks and environment setup first. */ 22 require_once HORDE_BASE . '/lib/core.php'; 23 require_once 'Horde/CLI.php'; 24 25 /* Make sure no one runs this from the web. */ 26 if (!Horde_CLI::runningFromCLI()) { 27 exit("Must be run from the command line\n"); 28 } 29 30 /* Get any options. */ 31 $simple = false; 32 $ignore = array(); 33 if (isset($argv)) { 34 /* Get rid of the first arg which is the script name. */ 35 array_shift($argv); 36 while ($arg = array_shift($argv)) { 37 if ($arg == '--help') { 38 print_usage(); 39 } elseif ($arg == '-s') { 40 $simple = true; 41 } elseif (strpos($arg, '-i') === 0) { 42 list(,$ignore[]) = explode('=', $arg); 43 //$ignore[] = $i; 44 } else { 45 print_usage("Unrecognised option $arg"); 46 } 47 } 48 } 49 50 /* Set up CLI. */ 51 $cli = &new Horde_CLI(); 52 53 /* Check if at least the registry is avaiable. */ 54 if (!@file_exists(HORDE_BASE . '/config/registry.php')) { 55 $cli->writeln($cli->red('No Horde registry file.')); 56 exit; 57 } 58 59 //$cli->writeln($cli->green('Reading...')); 60 require_once HORDE_BASE . '/lib/base.php'; 61 62 /* Get the apps and start doing checks. */ 63 $apps = $registry->listApps(array('hidden', 'notoolbar', 'active', 'admin')); 64 65 /* Get a list of themes. */ 66 $themes = array(); 67 $themes_dir = $registry->get('themesfs', 'horde'); 68 if ($handle = opendir($themes_dir)) { 69 while ($file = readdir($handle)) { 70 if ($file == '.' || $file == '..' || $file == 'CVS' || 71 $file == '.svn' || 72 !@file_exists("$themes_dir/$file/info.php") || 73 !@file_exists("$themes_dir/$file/graphics")) { 74 continue; 75 } 76 77 /* Don't bother checking unless the theme explicitly states that 78 * icons will be replaced for this application. */ 79 include "$themes_dir/$file/info.php"; 80 if (!isset($theme_icons)) { 81 continue; 82 } 83 84 /* Store the apps and their theme directories. */ 85 foreach ($theme_icons as $app) { 86 $app_themes_dir = $registry->get('themesfs', $app); 87 $themes[$app][$file] = "$app_themes_dir/$file/graphics"; 88 } 89 90 /* Unset this, to make sure it is checked the next time around. */ 91 unset($theme_icons); 92 } 93 } 94 95 foreach ($apps as $app) { 96 /* Set up some dirs. */ 97 $themes_dir = $registry->get('themesfs', $app); 98 $horde_theme_dir = $themes_dir . '/horde'; 99 $horde_icon_dir = $horde_theme_dir . '/graphics'; 100 101 /* Sanity check for the directories. */ 102 if (!@file_exists($horde_theme_dir) || !@file_exists($horde_icon_dir)) { 103 continue; 104 } 105 106 /* Get a list of all horde images recursively. */ 107 $horde_icon_list = array(); 108 readDirRecursively($horde_icon_dir, $horde_icon_dir, $horde_icon_list); 109 110 /* Loop through themes that replace icons and check for differences. */ 111 foreach ($themes[$app] as $theme => $theme_icon_dir) { 112 $theme_icon_list = array(); 113 readDirRecursively($theme_icon_dir, $theme_icon_dir, $theme_icon_list); 114 115 /* Check for icons that are in the Horde base theme and not in the 116 * custom theme. */ 117 $diff = array_diff($horde_icon_list, $theme_icon_list); 118 /* Don't bother reporting anything for themes that have all the horde 119 * base icons. */ 120 if (empty($diff)) { 121 continue; 122 } 123 124 $cli->writeln($cli->red(sprintf('[%s] "%s" theme missing these icons:', 125 strtoupper($app), 126 $theme))); 127 foreach ($diff as $icon) { 128 $cli->writeln($icon); 129 } 130 131 /* Check if only doing a Horde base theme to custom theme check. Skip 132 * the reverse checking if true. */ 133 if ($simple) { 134 continue; 135 } 136 137 /* Check for icons that are in the Horde base theme and not in the 138 * custom theme. */ 139 $diff = array_diff($theme_icon_list, $horde_icon_list); 140 /* Don't bother reporting anything for themes that don't have any icons 141 * more than the base theme. */ 142 if (empty($diff)) { 143 continue; 144 } 145 146 $cli->writeln($cli->blue(sprintf('[%s] "%s" theme has these extra icons:', 147 strtoupper($app), 148 $theme))); 149 foreach ($diff as $icon) { 150 $cli->writeln($icon); 151 } 152 } 153 } 154 155 $cli->writeln($cli->green('Done.')); 156 exit; 157 158 /** 159 * Loops through the directory recursively and stores the found graphics into 160 * an array. 161 */ 162 function readDirRecursively($path, $basepath, &$list) 163 { 164 global $ignore; 165 166 if ($handle = opendir($path)) { 167 while ($file = readdir($handle)) { 168 if ($file == '.' || $file == '..' || $file == 'CVS' 169 || $file == '.svn') { 170 continue; 171 } 172 if (is_dir("$path/$file")) { 173 readDirRecursively("$path/$file", $basepath, $list); 174 } else { 175 foreach ($ignore as $pattern) { 176 if (preg_match($pattern, $file)) { 177 continue 2; 178 } 179 } 180 $list[] = substr($path, strlen($basepath)) . "/$file"; 181 } 182 } 183 closedir($handle); 184 } 185 186 } 187 188 function print_usage($message = '') { 189 190 if (!empty($message)) { 191 print "themes_check.php: $message\n\n"; 192 } 193 194 print <<<USAGE 195 Usage: themes_check.php [OPTION] 196 197 Possible options: 198 -s Do only a simple check for any Horde base theme graphics that 199 are missing from the other themes, and no check of the 200 opposite. 201 -i=PATTERN Insert any valid regex pattern to ignore files from being 202 checked. You can enter multiple -i options to include multiple 203 patterns. For example: -i="/xcf$/ to ignore any original 204 GIMP files. 205 206 USAGE; 207 exit; 208 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |