BUG 9297 Al crear un nuevo skin y seleccionar el uxmodern despliega... SOLVED

- validating standard code
This commit is contained in:
Marco Antonio Nina
2012-07-06 11:22:39 -04:00
parent dab8440ac8
commit 16196798b2

View File

@@ -24,12 +24,12 @@ if (in_array($_REQUEST ['action'],$restrictedFunctions)) {
$functionName = $_REQUEST ['action']; $functionName = $_REQUEST ['action'];
//echo $_REQUEST ['action'];
$functionParams = isset($_REQUEST ['params']) ? $_REQUEST ['params'] : array(); $functionParams = isset($_REQUEST ['params']) ? $_REQUEST ['params'] : array();
$functionName(); $functionName();
function updatePageSize() { function updatePageSize()
{
G::LoadClass('configuration'); G::LoadClass('configuration');
$c = new Configurations(); $c = new Configurations();
$arr['pageSize'] = $_REQUEST['size']; $arr['pageSize'] = $_REQUEST['size'];
@@ -41,22 +41,21 @@ function updatePageSize() {
echo '{success: true}'; echo '{success: true}';
} }
function skinList() { function skinList()
{
G::loadClass('system'); G::loadClass('system');
$skinListArray = System::getSkingList(); $skinListArray = System::getSkingList();
echo G::json_encode($skinListArray); echo G::json_encode($skinListArray);
} }
function newSkin($baseSkin='classic') { function newSkin($baseSkin='classic')
//G::pr($_REQUEST); {
$skinBase = $baseSkin != "" ? strtolower($baseSkin) : 'classic'; $skinBase = $baseSkin != "" ? strtolower($baseSkin) : 'classic';
if ((isset($_REQUEST['skinBase'])) && ($_REQUEST['skinBase'] != "")) { if ((isset($_REQUEST['skinBase'])) && ($_REQUEST['skinBase'] != "")) {
$skinBase = strtolower($_REQUEST['skinBase']); $skinBase = strtolower($_REQUEST['skinBase']);
} }
try { try {
if (!(isset($_REQUEST['skinName']))) { if (!(isset($_REQUEST['skinName']))) {
throw ( new Exception(G::LoadTranslation('ID_SKIN_NAME_REQUIRED')) ); throw ( new Exception(G::LoadTranslation('ID_SKIN_NAME_REQUIRED')) );
@@ -67,8 +66,6 @@ function newSkin($baseSkin='classic') {
//Should validate skin folder name here //Should validate skin folder name here
//if.... //if....
$skinName = $_REQUEST['skinName']; $skinName = $_REQUEST['skinName'];
$skinFolder = $_REQUEST['skinFolder']; $skinFolder = $_REQUEST['skinFolder'];
$skinDescription = isset($_REQUEST['skinDescription']) ? $_REQUEST['skinDescription'] : ''; $skinDescription = isset($_REQUEST['skinDescription']) ? $_REQUEST['skinDescription'] : '';
@@ -83,13 +80,16 @@ function newSkin($baseSkin='classic') {
//All validations OK then create skin //All validations OK then create skin
switch ($skinBase) { switch ($skinBase) {
//Validate skin base
case 'uxmodern': case 'uxmodern':
copy_skin_folder(G::ExpandPath("skinEngine") . 'uxmodern' . PATH_SEP, PATH_CUSTOM_SKINS . $skinFolder,array("config.xml")); copy_skin_folder(G::ExpandPath("skinEngine") . 'uxmodern' . PATH_SEP, PATH_CUSTOM_SKINS .
$skinFolder,array("config.xml"));
$pathBase=G::ExpandPath("skinEngine") . 'base' . PATH_SEP; $pathBase=G::ExpandPath("skinEngine") . 'base' . PATH_SEP;
break; break;
case 'classic': case 'classic':
//Special Copy of this dir + xmlreplace //Special Copy of this dir + xmlreplace
copy_skin_folder(G::ExpandPath("skinEngine") . 'base' . PATH_SEP, PATH_CUSTOM_SKINS . $skinFolder,array("config.xml","baseCss")); copy_skin_folder(G::ExpandPath("skinEngine") . 'base' . PATH_SEP, PATH_CUSTOM_SKINS .
$skinFolder,array("config.xml","baseCss"));
$pathBase=G::ExpandPath("skinEngine") . 'base' . PATH_SEP; $pathBase=G::ExpandPath("skinEngine") . 'base' . PATH_SEP;
break; break;
default: default:
@@ -103,18 +103,20 @@ function newSkin($baseSkin='classic') {
$configFileOriginal = $pathBase . PATH_SEP . 'config.xml'; $configFileOriginal = $pathBase . PATH_SEP . 'config.xml';
$configFileFinal = PATH_CUSTOM_SKINS . $skinFolder . PATH_SEP . 'config.xml'; $configFileFinal = PATH_CUSTOM_SKINS . $skinFolder . PATH_SEP . 'config.xml';
$xmlConfiguration = file_get_contents($configFileOriginal); $xmlConfiguration = file_get_contents($configFileOriginal);
$xmlConfiguration = preg_replace('/(<id>)(.+?)(<\/id>)/i', '<id>' . G::generateUniqueID() . '</id><!-- $2 -->', $xmlConfiguration); $xmlConfiguration = preg_replace('/(<id>)(.+?)(<\/id>)/i', '<id>' . G::generateUniqueID() .
$xmlConfiguration = preg_replace("/(<name>)(.+?)(<\/name>)/i", "<name>" . $skinName . "</name><!-- $2 -->", $xmlConfiguration); '</id><!-- $2 -->', $xmlConfiguration);
$xmlConfiguration = preg_replace("/(<description>)(.+?)(<\/description>)/i", "<description>" . $skinDescription . "</description><!-- $2 -->", $xmlConfiguration); $xmlConfiguration = preg_replace("/(<name>)(.+?)(<\/name>)/i", "<name>" . $skinName .
$xmlConfiguration = preg_replace("/(<author>)(.+?)(<\/author>)/i", "<author>" . $skinAuthor . "</author><!-- $2 -->", $xmlConfiguration); "</name><!-- $2 -->", $xmlConfiguration);
$xmlConfiguration = preg_replace("/(<createDate>)(.+?)(<\/createDate>)/i", "<createDate>" . date("Y-m-d H:i:s") . "</createDate><!-- $2 -->", $xmlConfiguration); $xmlConfiguration = preg_replace("/(<description>)(.+?)(<\/description>)/i", "<description>" .
$xmlConfiguration = preg_replace("/(<modifiedDate>)(.+?)(<\/modifiedDate>)/i", "<modifiedDate>" . date("Y-m-d H:i:s") . "</modifiedDate><!-- $2 -->", $xmlConfiguration); $skinDescription . "</description><!-- $2 -->", $xmlConfiguration);
$xmlConfiguration = preg_replace("/(<author>)(.+?)(<\/author>)/i", "<author>" . $skinAuthor .
"</author><!-- $2 -->", $xmlConfiguration);
$xmlConfiguration = preg_replace("/(<createDate>)(.+?)(<\/createDate>)/i", "<createDate>" .
date("Y-m-d H:i:s") . "</createDate><!-- $2 -->", $xmlConfiguration);
$xmlConfiguration = preg_replace("/(<modifiedDate>)(.+?)(<\/modifiedDate>)/i", "<modifiedDate>" .
date("Y-m-d H:i:s") . "</modifiedDate><!-- $2 -->", $xmlConfiguration);
file_put_contents($configFileFinal, $xmlConfiguration); file_put_contents($configFileFinal, $xmlConfiguration);
$response['success'] = true; $response['success'] = true;
$response['message'] = G::LoadTranslation('ID_SKIN_SUCCESS_CREATE'); $response['message'] = G::LoadTranslation('ID_SKIN_SUCCESS_CREATE');
print_r(G::json_encode($response)); print_r(G::json_encode($response));
@@ -126,7 +128,8 @@ function newSkin($baseSkin='classic') {
} }
} }
function importSkin() { function importSkin()
{
try { try {
if (!isset($_FILES['uploadedFile'])) { if (!isset($_FILES['uploadedFile'])) {
throw ( new Exception(G::LoadTranslation('ID_SKIN_FILE_REQUIRED')) ); throw ( new Exception(G::LoadTranslation('ID_SKIN_FILE_REQUIRED')) );
@@ -136,40 +139,39 @@ function importSkin() {
$sw_error_exists = isset($_FILES['uploadedFile']['error']); $sw_error_exists = isset($_FILES['uploadedFile']['error']);
$emptyInstances = 0; $emptyInstances = 0;
$quequeUpload = array(); $quequeUpload = array();
// upload files & check for errors
// upload files & check for errors
$tmp = $_FILES['uploadedFile']['tmp_name']; $tmp = $_FILES['uploadedFile']['tmp_name'];
$items = stripslashes($_FILES['uploadedFile']['name']); $items = stripslashes($_FILES['uploadedFile']['name']);
if ($sw_error_exists) if ($sw_error_exists) {
$up_err = $_FILES['uploadedFile']['error']; $up_err = $_FILES['uploadedFile']['error'];
else } else {
$up_err= ( file_exists($tmp) ? 0 : 4); $up_err= ( file_exists($tmp) ? 0 : 4);
}
if ($items == "" || $up_err == 4) { if ($items == "" || $up_err == 4) {
throw ( new Exception(G::LoadTranslation('ID_SKIN_FILE_REQUIRED')) ); throw ( new Exception(G::LoadTranslation('ID_SKIN_FILE_REQUIRED')));
} }
if ($up_err == 1 || $up_err == 2) { if ($up_err == 1 || $up_err == 2) {
throw ( new Exception(G::LoadTranslation('ID_FILE_TOO_BIG')) ); throw ( new Exception(G::LoadTranslation('ID_FILE_TOO_BIG')));
//$errors[$i]='miscfilesize'; //$errors[$i]='miscfilesize';
} }
if ($up_err == 3) { if ($up_err == 3) {
throw ( new Exception(G::LoadTranslation('ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR')) ); throw ( new Exception(G::LoadTranslation('ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR')));
//$errors[$i]='miscfilepart'; //$errors[$i]='miscfilepart';
} }
if (!@is_uploaded_file($tmp)) { if (!@is_uploaded_file($tmp)) {
throw ( new Exception(G::LoadTranslation('ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR')) ); throw ( new Exception(G::LoadTranslation('ID_ERROR_UPLOAD_FILE_CONTACT_ADMINISTRATOR')));
//$errors[$i]='uploadfile'; //$errors[$i]='uploadfile';
} }
$fileInfo = pathinfo($items); $fileInfo = pathinfo($items);
$validType = array('tar', 'gz'); $validType = array('tar', 'gz');
if (!in_array($fileInfo['extension'], $validType)) { if (!in_array($fileInfo['extension'], $validType)) {
throw ( new Exception(G::LoadTranslation('ID_FILE_UPLOAD_INCORRECT_EXTENSION')) ); throw ( new Exception(G::LoadTranslation('ID_FILE_UPLOAD_INCORRECT_EXTENSION')));
//$errors[$i]='wrongtype'; //$errors[$i]='wrongtype';
} }
$filename = $items; $filename = $items;
$tempPath = PATH_CUSTOM_SKINS . '.tmp' . PATH_SEP; $tempPath = PATH_CUSTOM_SKINS . '.tmp' . PATH_SEP;
G::verifyPath($tempPath, true); G::verifyPath($tempPath, true);
@@ -192,21 +194,21 @@ function importSkin() {
if (!$swConfigFile) { if (!$swConfigFile) {
@unlink(PATH_CUSTOM_SKINS . '.tmp' . PATH_SEP . $filename); @unlink(PATH_CUSTOM_SKINS . '.tmp' . PATH_SEP . $filename);
throw ( new Exception(G::LoadTranslation('ID_SKIN_CONFIGURATION_MISSING')) ); throw ( new Exception(G::LoadTranslation('ID_SKIN_CONFIGURATION_MISSING')));
} }
if (is_dir(PATH_CUSTOM_SKINS . $skinName)) { if (is_dir(PATH_CUSTOM_SKINS . $skinName)) {
if ((isset($_REQUEST['overwrite_files'])) && ($_REQUEST['overwrite_files'] == 'on')) { if ((isset($_REQUEST['overwrite_files'])) && ($_REQUEST['overwrite_files'] == 'on')) {
G::rm_dir(PATH_CUSTOM_SKINS . $skinName, false); G::rm_dir(PATH_CUSTOM_SKINS . $skinName, false);
} else { } else {
throw ( new Exception(G::LoadTranslation('ID_SKIN_ALREADY_EXISTS')) ); throw ( new Exception(G::LoadTranslation('ID_SKIN_ALREADY_EXISTS')));
} }
} }
$res = $tar->extract(PATH_CUSTOM_SKINS); $res = $tar->extract(PATH_CUSTOM_SKINS);
if (!$res) { if (!$res) {
throw ( new Exception(G::LoadTranslation('ID_SKIN_ERROR_EXTRACTING')) ); throw ( new Exception(G::LoadTranslation('ID_SKIN_ERROR_EXTRACTING')));
} }
//Delete Temporal //Delete Temporal
@unlink(PATH_CUSTOM_SKINS . '.tmp' . PATH_SEP . $filename); @unlink(PATH_CUSTOM_SKINS . '.tmp' . PATH_SEP . $filename);
$response['success'] = true; $response['success'] = true;
@@ -220,7 +222,8 @@ function importSkin() {
} }
} }
function exportSkin($skinToExport="") { function exportSkin($skinToExport="")
{
try { try {
if (!isset($_REQUEST['SKIN_FOLDER_ID'])) { if (!isset($_REQUEST['SKIN_FOLDER_ID'])) {
throw ( new Exception(G::LoadTranslation('ID_SKIN_NAME_REQUIRED')) ); throw ( new Exception(G::LoadTranslation('ID_SKIN_NAME_REQUIRED')) );
@@ -246,7 +249,6 @@ function exportSkin($skinToExport="") {
} }
//Try to generate tar file //Try to generate tar file
G::LoadThirdParty('pear/Archive', 'Tar'); G::LoadThirdParty('pear/Archive', 'Tar');
$tar = new Archive_Tar($skinTar); $tar = new Archive_Tar($skinTar);
$tar->_compress = false; $tar->_compress = false;
@@ -256,7 +258,6 @@ function exportSkin($skinToExport="") {
$response['success'] = true; $response['success'] = true;
$response['message'] = $skinTar; $response['message'] = $skinTar;
print_r(G::json_encode($response)); print_r(G::json_encode($response));
} catch (Exception $e) { } catch (Exception $e) {
$response['success'] = false; $response['success'] = false;
@@ -264,17 +265,18 @@ function exportSkin($skinToExport="") {
print_r(G::json_encode($response)); print_r(G::json_encode($response));
} }
} }
function deleteSkin(){ function deleteSkin()
try{ {
if(!(isset($_REQUEST['SKIN_FOLDER_ID']))){ try {
throw ( new Exception(G::LoadTranslation('ID_SKIN_FOLDER_REQUIRED')) ); if (!(isset($_REQUEST['SKIN_FOLDER_ID']))) {
throw (new Exception(G::LoadTranslation('ID_SKIN_FOLDER_REQUIRED')));
} }
if(($_REQUEST['SKIN_FOLDER_ID'])=="classic"){ if (($_REQUEST['SKIN_FOLDER_ID'])=="classic") {
throw ( new Exception(G::LoadTranslation('ID_SKIN_FOLDER_NOT_DELETEABLE')) ); throw (new Exception(G::LoadTranslation('ID_SKIN_FOLDER_NOT_DELETEABLE')));
} }
$folderId=$_REQUEST['SKIN_FOLDER_ID']; $folderId=$_REQUEST['SKIN_FOLDER_ID'];
if(!is_dir(PATH_CUSTOM_SKINS.$folderId)){ if (!is_dir(PATH_CUSTOM_SKINS.$folderId)) {
throw ( new Exception(G::LoadTranslation('ID_SKIN_NOT_EXISTS')) ); throw (new Exception(G::LoadTranslation('ID_SKIN_NOT_EXISTS')));
} }
//Delete //Delete
G::rm_dir(PATH_CUSTOM_SKINS.$folderId); G::rm_dir(PATH_CUSTOM_SKINS.$folderId);
@@ -286,17 +288,20 @@ function deleteSkin(){
print_r(G::json_encode($response)); print_r(G::json_encode($response));
} }
} }
function streamSkin() { function streamSkin()
{
$skinTar = $_REQUEST['file']; $skinTar = $_REQUEST['file'];
$bDownload = true; $bDownload = true;
G::streamFile($skinTar, $bDownload, basename($skinTar)); G::streamFile($skinTar, $bDownload, basename($skinTar));
@unlink($fileTar); @unlink($fileTar);
} }
function addTarFolder($tar, $pathBase, $pluginHome) { function addTarFolder($tar, $pathBase, $pluginHome)
{
$aux = explode(PATH_SEP, $pathBase); $aux = explode(PATH_SEP, $pathBase);
if ($aux[count($aux) - 2] == '.svn') if ($aux[count($aux) - 2] == '.svn') {
return; return;
}
if ($handle = opendir($pathBase)) { if ($handle = opendir($pathBase)) {
while (false !== ($file = readdir($handle))) { while (false !== ($file = readdir($handle))) {
@@ -313,7 +318,8 @@ function addTarFolder($tar, $pathBase, $pluginHome) {
} }
} }
function copy_skin_folder($path, $dest, $exclude=array()) { function copy_skin_folder($path, $dest, $exclude=array())
{
$defaultExcluded=array(".",".."); $defaultExcluded=array(".","..");
$excludedItems=array_merge($defaultExcluded,$exclude); $excludedItems=array_merge($defaultExcluded,$exclude);
if (is_dir($path)) { if (is_dir($path)) {
@@ -321,8 +327,9 @@ function copy_skin_folder($path, $dest, $exclude=array()) {
$objects = scandir($path); $objects = scandir($path);
if (sizeof($objects) > 0) { if (sizeof($objects) > 0) {
foreach ($objects as $file) { foreach ($objects as $file) {
if(in_array($file,$excludedItems)) if (in_array($file,$excludedItems)) {
continue; continue;
}
// go on // go on
if (is_dir($path . PATH_SEP . $file)) { if (is_dir($path . PATH_SEP . $file)) {
copy_skin_folder($path . PATH_SEP . $file, $dest . PATH_SEP . $file,$exclude); copy_skin_folder($path . PATH_SEP . $file, $dest . PATH_SEP . $file,$exclude);
@@ -338,3 +345,4 @@ function copy_skin_folder($path, $dest, $exclude=array()) {
return false; return false;
} }
} }