Added the phpseclib librarie for ssh/ftps server protocol as explained in gh-230. Extended the Component Files & Folders concept to allow adding files and folder from anywhere where PHP/Apache has permission to read, resolved gh-231

This commit is contained in:
2018-02-16 23:53:43 +02:00
parent 0c798d9579
commit c7551c6edd
63 changed files with 37151 additions and 166 deletions

View File

@ -676,6 +676,8 @@ class Get
'g.addcustommenus',
'j.addfiles',
'j.addfolders',
'j.addfilesfullpath',
'j.addfoldersfullpath',
'c.addsite_views',
'i.dashboard_tab',
'i.php_dashboard_methods',
@ -690,6 +692,8 @@ class Get
'addcustommenus',
'addfiles',
'addfolders',
'addfilesfullpath',
'addfoldersfullpath',
'addsite_views',
'dashboard_tab',
'php_dashboard_methods',
@ -768,21 +772,28 @@ class Get
// ensure version naming is correct
$this->component_version = preg_replace('/[^0-9.]+/', '', $component->component_version);
// set the addfolders data
$component->addfolders = (isset($component->addfolders) && ComponentbuilderHelper::checkJson($component->addfolders)) ? json_decode($component->addfolders, true) : null;
if (ComponentbuilderHelper::checkArray($component->addfolders))
// set the add targets
$addArrayF = array('files' => 'files', 'folders' => 'folders', 'filesfullpath' => 'files', 'foldersfullpath' => 'folders');
foreach ($addArrayF as $addTarget => $targetHere)
{
$component->folders = array_values($component->addfolders);
// set the add target data
$component->{'add'.$addTarget} = (isset($component->{'add'.$addTarget}) && ComponentbuilderHelper::checkJson($component->{'add'.$addTarget})) ? json_decode($component->{'add'.$addTarget}, true) : null;
if (ComponentbuilderHelper::checkArray($component->{'add'.$addTarget}))
{
if (isset($component->{$targetHere}) && ComponentbuilderHelper::checkArray($component->{$targetHere}))
{
foreach($component->{'add'.$addTarget} as $taget)
{
$component->{$targetHere}[] = $taget;
}
}
else
{
$component->{$targetHere} = array_values($component->{'add'.$addTarget});
}
}
unset($component->{'add'.$addTarget});
}
unset($component->addfolders);
// set the addfiles data
$component->addfiles = (isset($component->addfiles) && ComponentbuilderHelper::checkJson($component->addfiles)) ? json_decode($component->addfiles, true) : null;
if (ComponentbuilderHelper::checkArray($component->addfiles))
{
$component->files = array_values($component->addfiles);
}
unset($component->addfiles);
// set the uikit switch
$this->uikit = $component->adduikit;
@ -3018,6 +3029,8 @@ class Get
'b.addconfig',
'c.addfiles',
'c.addfolders',
'c.addfilesfullpath',
'c.addfoldersfullpath',
'c.addurls',
'a.php_setdocument'
), array(
@ -3029,6 +3042,8 @@ class Get
'addconfig',
'addfiles',
'addfolders',
'addfilesfullpath',
'addfoldersfullpath',
'addurls',
'php_setdocument'
)
@ -3070,23 +3085,27 @@ class Get
// check if this lib has dynamic behaviour
if ($library->how > 0)
{
// set the addfolders data
$library->addfolders = (isset($library->addfolders) && ComponentbuilderHelper::checkJson($library->addfolders)) ? json_decode($library->addfolders, true) : null;
if (ComponentbuilderHelper::checkArray($library->addfolders))
// set the add targets
$addArray = array('files' => 'files', 'folders' => 'folders', 'urls' => 'urls', 'filesfullpath' => 'files', 'foldersfullpath' => 'folders');
foreach ($addArray as $addTarget => $targetHere)
{
$library->folders = array_values($library->addfolders);
}
// set the addfiles data
$library->addfiles = (isset($library->addfiles) && ComponentbuilderHelper::checkJson($library->addfiles)) ? json_decode($library->addfiles, true) : null;
if (ComponentbuilderHelper::checkArray($library->addfiles))
{
$library->files = array_values($library->addfiles);
}
// set the addurls data
$library->addurls = (isset($library->addurls) && ComponentbuilderHelper::checkJson($library->addurls)) ? json_decode($library->addurls, true) : null;
if (ComponentbuilderHelper::checkArray($library->addurls))
{
$library->urls = array_values($library->addurls);
// set the add target data
$library->{'add'.$addTarget} = (isset($library->{'add'.$addTarget}) && ComponentbuilderHelper::checkJson($library->{'add'.$addTarget})) ? json_decode($library->{'add'.$addTarget}, true) : null;
if (ComponentbuilderHelper::checkArray($library->{'add'.$addTarget}))
{
if (isset($library->{$targetHere}) && ComponentbuilderHelper::checkArray($library->{$targetHere}))
{
foreach($library->{'add'.$addTarget} as $taget)
{
$library->{$targetHere}[] = $taget;
}
}
else
{
$library->{$targetHere} = array_values($library->{'add'.$addTarget});
}
}
unset($library->{'add'.$addTarget});
}
// add config fields only if needed
if ($library->how > 1)
@ -3126,9 +3145,6 @@ class Get
unset($library->php_setdocument);
unset($library->addconditions);
unset($library->addconfig);
unset($library->addfolders);
unset($library->addfiles);
unset($library->addurls);
// load to global lib
$this->libraries[$id] = $library;
}

View File

@ -717,26 +717,40 @@ class Structure extends Get
$zipPath = str_replace('c0mp0n3nt/', '', $details->path);
$path = str_replace('c0mp0n3nt/', $this->componentPath . '/', $details->path);
// set the template folder path
$templatePath = (isset($details->custom) && $details->custom) ? $this->templatePathCustom : $this->templatePath;
$templatePath = (isset($details->custom)) ? (($details->custom === 'custom') ? $this->templatePathCustom.'/' : '') : $this->templatePath.'/';
// now mov the file
if ($details->type === 'file')
{
// move the file to its place
JFile::copy($templatePath . '/' . $item, $path . '/' . $new);
// count the file created
$this->fileCount++;
// store the new files
if (!in_array($ftem, $this->notNew))
if (!JFile::exists($templatePath . $item))
{
$this->newFiles['static'][] = array('path' => $path . '/' . $new, 'name' => $new, 'zip' => $zipPath . '/' . $new);
$this->app->enqueueMessage(JText::sprintf('The file path: <b>%s</b> does not exist, and was not added!', $templatePath . $item), 'Error');
}
else
{
// move the file to its place
JFile::copy($templatePath . $item, $path . '/' . $new);
// count the file created
$this->fileCount++;
// store the new files
if (!in_array($ftem, $this->notNew))
{
$this->newFiles['static'][] = array('path' => $path . '/' . $new, 'name' => $new, 'zip' => $zipPath . '/' . $new);
}
}
}
elseif ($details->type === 'folder')
{
// move the folder to its place
JFolder::copy($templatePath . '/' . $item, $path . '/' . $new);
// count the folder created
$this->folderCount++;
if (!JFolder::exists($templatePath . $item))
{
$this->app->enqueueMessage(JText::sprintf('The folder path: <b>%s</b> does not exist, and was not added!', $templatePath . $item), 'Error');
}
else
{
// move the folder to its place
JFolder::copy($templatePath . $item, $path . '/' . $new);
// count the folder created
$this->folderCount++;
}
}
}
return true;
@ -1103,9 +1117,22 @@ class Structure extends Get
$pointer_tracker = 'h';
foreach ($this->componentData->folders as $custom)
{
// fix path
$custom['path'] = rtrim($custom['path'], '/');
$custom['path'] = ltrim($custom['path'], '/');
// by default custom path is true
$customPath = 'custom';
// fix custom path
if (isset($custom['path']) && ComponentbuilderHelper::checkString($custom['path']))
{
$custom['path'] = trim($custom['path'], '/');
}
// set full path if this is a full path folder
if(!isset($custom['folder']) && isset($custom['folderpath']))
{
$custom['folder'] = '/'.trim($custom['folderpath'], '/');
// remove the file path
unset($custom['folderpath']);
// triget fullpath
$customPath = 'full';
}
// make sure we use the correct name
$pathArray = (array) explode('/', $custom['path']);
$firstFolder = array_values($pathArray)[0];
@ -1121,6 +1148,14 @@ class Structure extends Get
unset($pathArray[$tkey]);
}
}
elseif ('full' === $customPath)
{
// make sure we use the correct name
$folderArray = (array) explode('/', $custom['folder']);
$lastFolder = end($folderArray);
$rename = 'new';
$newname = $lastFolder;
}
else
{
$lastFolder = $custom['folder'];
@ -1164,7 +1199,7 @@ class Structure extends Get
$versionData->move->static->$key_pointer->rename = $rename;
$versionData->move->static->$key_pointer->newName = $newname;
$versionData->move->static->$key_pointer->type = 'folder';
$versionData->move->static->$key_pointer->custom = true;
$versionData->move->static->$key_pointer->custom = $customPath;
}
unset($this->componentData->folders);
unset($custom);
@ -1191,6 +1226,16 @@ class Structure extends Get
$pointer_tracker = 'h';
foreach ($this->componentData->files as $custom)
{
$customPath = 'custom';
// set full path if this is a full path file
if(!isset($custom['file']) && isset($custom['filepath']))
{
$custom['file'] = '/'.trim($custom['filepath'], '/');
// remove the file path
unset($custom['filepath']);
// triget fullpath
$customPath = 'full';
}
// make we have not duplicates
$key_pointer = ComponentbuilderHelper::safeString($custom['file']) . '_g' . $pointer_tracker;
$pointer_tracker++;
@ -1201,22 +1246,27 @@ class Structure extends Get
$pathInfo = pathinfo($custom['path']);
if (isset($pathInfo['extension']) && $pathInfo['extension'])
{
$pathInfo['dirname'] = rtrim($pathInfo['dirname'], '/');
$pathInfo['dirname'] = ltrim($pathInfo['dirname'], '/');
$pathInfo['dirname'] = trim($pathInfo['dirname'], '/');
// set the info
$versionData->move->static->$key_pointer->path = 'c0mp0n3nt/' . $pathInfo['dirname'];
$versionData->move->static->$key_pointer->rename = 'new';
$versionData->move->static->$key_pointer->newName = $pathInfo['basename'];
// set the name
$name = $pathInfo['basename'];
}
elseif ('full' === $customPath)
{
$fileArray = explode('/', $custom['file']);
// set the info
$versionData->move->static->$key_pointer->path = 'c0mp0n3nt/' . $custom['path'];
$versionData->move->static->$key_pointer->rename = 'new';
$versionData->move->static->$key_pointer->newName = end($fileArray);
}
else
{
$custom['path'] = rtrim($custom['path'], '/');
$custom['path'] = ltrim($custom['path'], '/');
// fix custom path
$custom['path'] = trim($custom['path'], '/');
// set the info
$versionData->move->static->$key_pointer->path = 'c0mp0n3nt/' . $custom['path'];
$versionData->move->static->$key_pointer->rename = false;
// set the name
$name = $custom['file'];
}
// check if file should be updated
if (!isset($custom['notnew']) || $custom['notnew'] == 0 || $custom['notnew'] != 1)
@ -1224,7 +1274,7 @@ class Structure extends Get
$this->notNew[] = $key_pointer;
}
$versionData->move->static->$key_pointer->type = 'file';
$versionData->move->static->$key_pointer->custom = true;
$versionData->move->static->$key_pointer->custom = $customPath;
}
unset($this->componentData->files);
unset($custom);