1 |
1643
|
darkviper
|
<?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$
|
11 |
|
|
* @filesource $HeadURL$
|
12 |
|
|
* @lastmodified $Date$
|
13 |
|
|
*/
|
14 |
|
|
|
15 |
|
|
class CopyThemeHtt {
|
16 |
|
|
|
17 |
|
|
private static $_sSkelPath = '';
|
18 |
|
|
private static $_sThemePath = '';
|
19 |
|
|
private static $_sOs = '';
|
20 |
|
|
private static $_sFileMode = '';
|
21 |
|
|
private static $_aLang = '';
|
22 |
|
|
/**
|
23 |
|
|
* import all needed global constants and variables
|
24 |
|
|
*/
|
25 |
|
|
private static function init()
|
26 |
|
|
{
|
27 |
|
|
// self::$_sSkelPath = ADMIN_PATH.'/themes/templates/';
|
28 |
|
|
self::$_sSkelPath = ADMIN_PATH.'/skel/themes/htt/';
|
29 |
|
|
self::$_sThemePath = THEME_PATH.'/templates/';
|
30 |
|
|
self::$_sOs = OPERATING_SYSTEM;
|
31 |
|
|
self::$_sFileMode = STRING_FILE_MODE;
|
32 |
|
|
self::$_aLang = $GLOBALS['MESSAGE'];
|
33 |
|
|
}
|
34 |
|
|
/**
|
35 |
|
|
* returns the difference between default and current theme
|
36 |
|
|
* @param string $sSourceDir
|
37 |
|
|
* @param string $sDestinationDir
|
38 |
|
|
* @param string $sExtension
|
39 |
|
|
* @return array
|
40 |
|
|
*/
|
41 |
|
|
public static function getDivList($sSourceDir, $sDestinationDir, $sExtension)
|
42 |
|
|
{
|
43 |
|
|
$aDestinationTemplates = self::getFiles($sDestinationDir, $sExtension);
|
44 |
|
|
$aDefaultTemplates = self::getFiles($sSourceDir, $sExtension);
|
45 |
|
|
$aRetval = array_diff($aDefaultTemplates, $aDestinationTemplates);
|
46 |
|
|
return $aRetval;
|
47 |
|
|
}
|
48 |
|
|
/**
|
49 |
|
|
* copy template files from default theme dir into the current theme dir
|
50 |
|
|
* @param array $aFileList
|
51 |
|
|
* @return array|null
|
52 |
|
|
*/
|
53 |
|
|
public static function doImport($aFileList)
|
54 |
|
|
{
|
55 |
|
|
self::init();
|
56 |
|
|
$aErrors = array();
|
57 |
|
|
if(is_array($aFileList)) {
|
58 |
|
|
if(isset($aFileList['none'])) { unset($aFileList['none']); }
|
59 |
|
|
if(sizeof($aFileList) > 0 ) {
|
60 |
|
|
foreach($aFileList as $sFile) {
|
61 |
|
|
$sFile = basename($sFile);
|
62 |
|
|
if(copy(self::$_sSkelPath.$sFile, self::$_sThemePath.$sFile)) {
|
63 |
|
|
if(self::$_sOs == 'linux') {
|
64 |
|
|
chmod(self::$_sThemePath.$sFile, self::$_sFileMode);
|
65 |
|
|
}
|
66 |
|
|
}else {
|
67 |
|
|
$aErrors[] = self::$_aLang['UPLOAD_ERR_CANT_WRITE'].' ['.$sFile.']';
|
68 |
|
|
}
|
69 |
|
|
}
|
70 |
|
|
}
|
71 |
|
|
}
|
72 |
|
|
if(sizeof($aErrors) > 0) {
|
73 |
|
|
return $aErrors;
|
74 |
|
|
}else {
|
75 |
|
|
return null;
|
76 |
|
|
}
|
77 |
|
|
}
|
78 |
|
|
/**
|
79 |
|
|
* generate a filelist containing all files with $sExtension from dir $sDirectory
|
80 |
|
|
* @param string $sDirectory
|
81 |
|
|
* @param string $sExtension
|
82 |
|
|
* @return array
|
83 |
|
|
*/
|
84 |
|
|
private static function getFiles($sDirectory, $sExtension)
|
85 |
|
|
{
|
86 |
|
|
$aRetval = array();
|
87 |
|
|
try {
|
88 |
|
|
$oIterator = new DirectoryIterator($sDirectory);
|
89 |
|
|
foreach ($oIterator as $oFileinfo) {
|
90 |
|
|
if ($oFileinfo->isFile() &&
|
91 |
|
|
(pathinfo($oFileinfo->getFilename(), PATHINFO_EXTENSION) == $sExtension))
|
92 |
|
|
{
|
93 |
|
|
$aRetval[$oFileinfo->getBasename('.'.$sExtension)] = $oFileinfo->getBasename();
|
94 |
|
|
}
|
95 |
|
|
}
|
96 |
|
|
} catch (Exception $e) {
|
97 |
|
|
return array();
|
98 |
|
|
}
|
99 |
|
|
ksort($aRetval);
|
100 |
|
|
return $aRetval;
|
101 |
|
|
}
|
102 |
|
|
}
|