| 1 | <?php
 | 
  
    | 2 | /**
 | 
  
    | 3 |  *
 | 
  
    | 4 |  * @category        WBCore
 | 
  
    | 5 |  * @package         WBCore_addons
 | 
  
    | 6 |  * @author          Werner v.d.Decken
 | 
  
    | 7 |  * @copyright       Website Baker Org. e.V.
 | 
  
    | 8 |  * @link			http://www.websitebaker2.org/
 | 
  
    | 9 |  * @license         http://www.gnu.org/licenses/gpl.html
 | 
  
    | 10 |  * @revision        $Revision: 1651 $
 | 
  
    | 11 |  * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/admin/addons/CopyThemeHtt.php $
 | 
  
    | 12 |  * @lastmodified    $Date: 2012-03-26 16:18:12 +0200 (Mon, 26 Mar 2012) $
 | 
  
    | 13 |  */
 | 
  
    | 14 | 
 | 
  
    | 15 | class CopyThemeHtt {
 | 
  
    | 16 | 
 | 
  
    | 17 | 	private static $_sSkelPath  = ''; 
 | 
  
    | 18 | 	private static $_sThemePath = '';
 | 
  
    | 19 | 	private static $_IsLinux    = '';
 | 
  
    | 20 | 	private static $_sFileMode  = '';
 | 
  
    | 21 | 	private static $_aLang      = '';
 | 
  
    | 22 | 	private static $_bDebug     = false;
 | 
  
    | 23 | /**
 | 
  
    | 24 |  * import all needed global constants and variables
 | 
  
    | 25 |  */
 | 
  
    | 26 | 	private static function init()
 | 
  
    | 27 | 	{
 | 
  
    | 28 | //		self::$_sSkelPath  = ADMIN_PATH.'/themes/templates/';
 | 
  
    | 29 | 		self::$_sSkelPath  = ADMIN_PATH.'/skel/themes/htt/';
 | 
  
    | 30 | 		self::$_sThemePath = THEME_PATH.'/templates/';
 | 
  
    | 31 | 		self::$_IsLinux    = ((substr(__FILE__, 0, 1)) == '/');
 | 
  
    | 32 | 		self::$_sFileMode  = octdec(STRING_FILE_MODE);
 | 
  
    | 33 | 		self::$_bDebug      = (defined('DEBUG') && DEBUG === true);
 | 
  
    | 34 | 
 | 
  
    | 35 | 		self::$_aLang      = $GLOBALS['MESSAGE'];
 | 
  
    | 36 | 	}
 | 
  
    | 37 | /**
 | 
  
    | 38 |  * returns the difference between default and current theme
 | 
  
    | 39 |  * @param string $sSourceDir
 | 
  
    | 40 |  * @param string $sDestinationDir
 | 
  
    | 41 |  * @param string $sExtension
 | 
  
    | 42 |  * @return array
 | 
  
    | 43 |  */
 | 
  
    | 44 | 	public static function getDivList($sSourceDir, $sDestinationDir, $sExtension)
 | 
  
    | 45 | 	{
 | 
  
    | 46 | 		$aDestinationTemplates = self::getFiles($sDestinationDir, $sExtension);
 | 
  
    | 47 | 		$aDefaultTemplates = self::getFiles($sSourceDir, $sExtension);
 | 
  
    | 48 | 		$aRetval = array_diff($aDefaultTemplates, $aDestinationTemplates);
 | 
  
    | 49 | 		return $aRetval;
 | 
  
    | 50 | 	}
 | 
  
    | 51 | /**
 | 
  
    | 52 |  * copy template files from default theme dir into the current theme dir
 | 
  
    | 53 |  * @param array $aFileList
 | 
  
    | 54 |  * @return array|null
 | 
  
    | 55 |  */
 | 
  
    | 56 | 	public static function doImport($aFileList)
 | 
  
    | 57 | 	{
 | 
  
    | 58 | 		self::init();
 | 
  
    | 59 | 		$aErrors = array();
 | 
  
    | 60 | 		if(is_array($aFileList)) {
 | 
  
    | 61 | 			if(isset($aFileList['none'])) { unset($aFileList['none']); }
 | 
  
    | 62 | 			if(sizeof($aFileList) > 0 ) {
 | 
  
    | 63 | 				foreach($aFileList as $sFile) {
 | 
  
    | 64 | 					$sFile = basename($sFile);
 | 
  
    | 65 | 					if(is_writable(self::$_sThemePath) &&
 | 
  
    | 66 | 					   copy(self::$_sSkelPath.$sFile, self::$_sThemePath.$sFile))
 | 
  
    | 67 | 					{
 | 
  
    | 68 | 						if(self::$_IsLinux) {
 | 
  
    | 69 | 							if(!chmod(self::$_sThemePath.$sFile, self::$_sFileMode)) {
 | 
  
    | 70 | 								$msg = self::$_aLang['UPLOAD_ERR_CANT_WRITE'].' ['.$sFile.']';
 | 
  
    | 71 | 								if(self::$_bDebug) {
 | 
  
    | 72 | 									$msg .= __CLASS__.'::'.__METHOD__.'::'
 | 
  
    | 73 | 									     . 'chmod(\'self::'.$_sThemePath.$sFile.'\', '
 | 
  
    | 74 | 									     . decoct(self::$_sFileMode).')';
 | 
  
    | 75 | 								}
 | 
  
    | 76 | 								$aErrors[] = $msg;
 | 
  
    | 77 | 							}
 | 
  
    | 78 | 						}
 | 
  
    | 79 | 					}else {
 | 
  
    | 80 | 						$msg = self::$_aLang['UPLOAD_ERR_CANT_WRITE'].' ['.$sFile.']';
 | 
  
    | 81 | 						if(self::$_bDebug) {
 | 
  
    | 82 | 							$msg .= __CLASS__.'::'.__METHOD__.'::'
 | 
  
    | 83 | 							     . 'copy(\''.self::$_sSkelPath.$sFile.'\', '
 | 
  
    | 84 | 							     . '\''.self::$_sThemePath.$sFile.'\')';
 | 
  
    | 85 | 						}
 | 
  
    | 86 | 						$aErrors[] = $msg;
 | 
  
    | 87 | 					}
 | 
  
    | 88 | 				}
 | 
  
    | 89 | 			}
 | 
  
    | 90 | 		}
 | 
  
    | 91 | 		if(sizeof($aErrors) > 0) {
 | 
  
    | 92 | 			return $aErrors;
 | 
  
    | 93 | 		}else {
 | 
  
    | 94 | 			return null;
 | 
  
    | 95 | 		}
 | 
  
    | 96 | 	}
 | 
  
    | 97 | /**
 | 
  
    | 98 |  * generate a filelist containing all files with $sExtension from dir $sDirectory
 | 
  
    | 99 |  * @param string $sDirectory
 | 
  
    | 100 |  * @param string $sExtension
 | 
  
    | 101 |  * @return array
 | 
  
    | 102 |  */
 | 
  
    | 103 | 	private static function getFiles($sDirectory, $sExtension)
 | 
  
    | 104 | 	{
 | 
  
    | 105 | 		$aRetval = array();
 | 
  
    | 106 | 		try {
 | 
  
    | 107 | 			$oIterator = new DirectoryIterator($sDirectory);
 | 
  
    | 108 | 			foreach ($oIterator as $oFileinfo) {
 | 
  
    | 109 | 				if ($oFileinfo->isFile() && 
 | 
  
    | 110 | 				   (pathinfo($oFileinfo->getFilename(), PATHINFO_EXTENSION) == $sExtension))
 | 
  
    | 111 | 				{
 | 
  
    | 112 | 					$aRetval[$oFileinfo->getBasename('.'.$sExtension)] = $oFileinfo->getBasename();
 | 
  
    | 113 | 				}
 | 
  
    | 114 | 			}
 | 
  
    | 115 | 		} catch (Exception $e) {
 | 
  
    | 116 | 			return array();
 | 
  
    | 117 | 		}
 | 
  
    | 118 | 		ksort($aRetval);
 | 
  
    | 119 | 		return $aRetval;
 | 
  
    | 120 | 	}
 | 
  
    | 121 | }
 |