copySkinFolder(G::ExpandPath("skinEngine").'uxmodern'.PATH_SEP, PATH_CUSTOM_SKINS.$skinFolder, array("config.xml" )); $pathBase = G::ExpandPath("skinEngine").'base'.PATH_SEP; break; case 'classic': //Special Copy of this dir + xmlreplace $this->copySkinFolder(G::ExpandPath("skinEngine").'base'.PATH_SEP, PATH_CUSTOM_SKINS.$skinFolder, array("config.xml", "baseCss" )); $pathBase = G::ExpandPath("skinEngine").'base'.PATH_SEP; break; case 'neoclassic': //Special Copy of this dir + xmlreplace $this->copySkinFolder(G::ExpandPath("skinEngine").'neoclassic'.PATH_SEP, PATH_CUSTOM_SKINS.$skinFolder, array("config.xml", "baseCss" )); $pathBase = G::ExpandPath("skinEngine").'neoclassic'.PATH_SEP; break; default: //Commmon copy/paste of a folder + xmlrepalce $this->copySkinFolder(PATH_CUSTOM_SKINS.$skinBase, PATH_CUSTOM_SKINS.$skinFolder, array("config.xml" )); $pathBase = PATH_CUSTOM_SKINS.$skinBase.PATH_SEP; break; } //@todo Improve this pre_replace lines $configFileOriginal = $pathBase."config.xml"; $configFileFinal = PATH_CUSTOM_SKINS.$skinFolder.PATH_SEP.'config.xml'; $xmlConfiguration = file_get_contents($configFileOriginal); $workspace = ($skinWorkspace == 'global') ? '' : config("system.workspace"); $xmlConfigurationObj = G::xmlParser($xmlConfiguration); $skinInformationArray = $xmlConfigurationObj->result["skinConfiguration"]["__CONTENT__"]["information"]["__CONTENT__"]; $xmlConfiguration = preg_replace('/()(.+?)(<\/id>)/i', ''.G::generateUniqueID().'', $xmlConfiguration); if (isset($skinInformationArray["workspace"]["__VALUE__"])) { $workspace = ($workspace != "" && !empty($skinInformationArray["workspace"]["__VALUE__"])) ? $skinInformationArray["workspace"]["__VALUE__"]."|".$workspace : $workspace; $xmlConfiguration = preg_replace("/()(.*)(<\/workspace>)/i", "".$workspace."", $xmlConfiguration); $xmlConfiguration = preg_replace("/()(.*)(<\/name>)/i", "".$skinName."", $xmlConfiguration); } else { $xmlConfiguration = preg_replace("/()(.*)(<\/name>)/i", "".$skinName."\n".$workspace."", $xmlConfiguration); } $xmlConfiguration = preg_replace("/()(.+?)(<\/description>)/i", "".$skinDescription."", $xmlConfiguration); $xmlConfiguration = preg_replace("/()(.+?)(<\/author>)/i", "".$skinAuthor."", $xmlConfiguration); $xmlConfiguration = preg_replace("/()(.+?)(<\/createDate>)/i", "".date("Y-m-d H:i:s")."", $xmlConfiguration); $xmlConfiguration = preg_replace("/()(.+?)(<\/modifiedDate>)/i", "".date("Y-m-d H:i:s")."", $xmlConfiguration); file_put_contents($configFileFinal, $xmlConfiguration); $response['success'] = true; $response['message'] = G::LoadTranslation('ID_SKIN_SUCCESS_CREATE'); G::auditLog("CreateSkin", "Skin Name: ".$skinName); return $response; } catch (Exception $e) { $response['success'] = false; $response['message'] = $e->getMessage(); $response['error'] = $e->getMessage(); return $response; } } private function copySkinFolder($path, $dest, $exclude = array()) { $defaultExcluded = array(".", ".."); $excludedItems = array_merge($defaultExcluded, $exclude); if (is_dir($path)) { mkdir($dest); $objects = scandir($path); if (sizeof($objects) > 0) { foreach ($objects as $file) { if (in_array($file, $excludedItems)) { continue; } if (is_dir($path.PATH_SEP.$file)) { $this->copySkinFolder($path.PATH_SEP.$file, $dest.PATH_SEP.$file, $exclude); } else { copy($path.PATH_SEP.$file, $dest.PATH_SEP.$file); } } } return true; } elseif (is_file($path)) { return copy($path, $dest); } else { return false; } } }