Moved the composer vendor folder to libraries and removed it from the admin/helpers folder. Improved the dynamic folder include concept.

This commit is contained in:
2018-02-28 04:27:03 +02:00
parent 1b86f1539a
commit 7f3dae297a
59 changed files with 470 additions and 2108 deletions

View File

@ -306,12 +306,69 @@ class Structure extends Get
*/
public $addCheckin = false;
/**
* The Move Folders Switch
*
* @var boolean
*/
public $setMoveFolders = false;
/**
* The array of last modified dates
*
* @var array
*/
protected $lastModifiedDate = array();
/**
* The array of dynamic paths
*
* JPATH_SITE is meant to represent the root path of the JSite application, just as JPATH_ADMINISTRATOR is mean to represent the root path of the JAdministrator application.
*
* JPATH_BASE is the root path for the current requested application.... so if you are in the administrator application:
*
* JPATH_BASE == JPATH_ADMINISTRATOR
*
* If you are in the site application:
*
* JPATH_BASE == JPATH_SITE
*
* If you are in the installation application:
*
* JPATH_BASE == JPATH_INSTALLATION.
*
* JPATH_ROOT is the root path for the Joomla install and does not depend upon any application.
*
* @var array
*/
protected $constantPaths = array(
// The path to the administrator folder.
'JPATH_ADMINISTRATOR' => JPATH_ADMINISTRATOR,
// The path to the installed Joomla! site, or JPATH_ROOT/administrator if executed from the backend.
'JPATH_BASE' => JPATH_BASE,
// The path to the cache folder.
'JPATH_CACHE' => JPATH_CACHE,
// The path to the administration folder of the current component being executed.
'JPATH_COMPONENT_ADMINISTRATOR' => JPATH_COMPONENT_ADMINISTRATOR,
// The path to the site folder of the current component being executed.
'JPATH_COMPONENT_SITE' => JPATH_COMPONENT_SITE,
// The path to the current component being executed.
'JPATH_COMPONENT' => JPATH_COMPONENT,
// The path to folder containing the configuration.php file.
'JPATH_CONFIGURATION' => JPATH_CONFIGURATION,
// The path to the installation folder.
'JPATH_INSTALLATION' => JPATH_INSTALLATION,
// The path to the libraries folder.
'JPATH_LIBRARIES' => JPATH_LIBRARIES,
// The path to the plugins folder.
'JPATH_PLUGINS' => JPATH_PLUGINS,
// The path to the installed Joomla! site.
'JPATH_ROOT' => JPATH_ROOT,
// The path to the installed Joomla! site.
'JPATH_SITE' => JPATH_SITE,
// The path to the templates folder.
'JPATH_THEMES' => JPATH_THEMES
);
/**
* Constructor
@ -718,40 +775,58 @@ class Structure extends Get
$path = str_replace('c0mp0n3nt/', $this->componentPath . '/', $details->path);
// set the template folder path
$templatePath = (isset($details->custom) && $details->custom) ? (($details->custom !== 'full') ? $this->templatePathCustom.'/':'') : $this->templatePath.'/';
// now mov the file
// set the final paths
$currentFullPath = str_replace('//', '/', $templatePath.'/'.$item);
$packageFullPath = str_replace('//', '/', $path.'/'.$new);
$zipFullPath = str_replace('//', '/', $zipPath.'/'.$new);
// now move the file
if ($details->type === 'file')
{
if (!JFile::exists($templatePath . $item))
if (!JFile::exists($currentFullPath))
{
$this->app->enqueueMessage(JText::sprintf('The file path: <b>%s</b> does not exist, and was not added!', $templatePath . $item), 'Error');
$this->app->enqueueMessage(JText::sprintf('The file path: <b>%s</b> does not exist, and was not added!', $currentFullPath), 'Error');
}
else
{
// move the file to its place
JFile::copy($templatePath . $item, $path . '/' . $new);
JFile::copy($currentFullPath, $packageFullPath);
// 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);
$this->newFiles['static'][] = array('path' => $packageFullPath, 'name' => $new, 'zip' => $zipFullPath);
}
}
}
elseif ($details->type === 'folder')
{
if (!JFolder::exists($templatePath . $item))
if (!JFolder::exists($currentFullPath))
{
$this->app->enqueueMessage(JText::sprintf('The folder path: <b>%s</b> does not exist, and was not added!', $templatePath . $item), 'Error');
$this->app->enqueueMessage(JText::sprintf('The folder path: <b>%s</b> does not exist, and was not added!', $currentFullPath), 'Error');
}
else
{
// move the folder to its place
JFolder::copy($templatePath . $item, $path . '/' . $new);
JFolder::copy($currentFullPath, $packageFullPath);
// count the folder created
$this->folderCount++;
}
}
// check if we should add the dynamic folder moving script to the installer script
if (!$this->setMoveFolders)
{
$checker = explode('/',$zipFullPath);
// TODO <-- this may not be the best way, will keep an eye on this.
// We basicly only want to check if a folder is added that is not in the stdFolders array
if (isset($checker[0]) && ComponentbuilderHelper::checkString($checker[0]) && !in_array($checker[0], $stdFolders))
{
// add the setDynamicF0ld3rs() method to the install scipt.php file
$this->setMoveFolders = true;
// set message that this was done (will still add a tutorial link later)
$this->app->enqueueMessage(JText::sprintf('<p><b>Dynamic folder/s were detected.</b><br />A method (setDynamicF0ld3rs) was added to the install <b>script.php</b> of this package to insure that the folder/s are copied into the correct place when this componet is installed!</p>'), 'Notice');
}
}
}
return true;
}
@ -1128,6 +1203,8 @@ class Structure extends Get
if(!isset($custom['folder']) && isset($custom['folderpath']))
{
$custom['folder'] = '/'.trim($custom['folderpath'], '/');
// update the dynamic path
$custom['folder'] = $this->updateDynamicPath($custom['folder']);
// remove the file path
unset($custom['folderpath']);
// triget fullpath
@ -1237,6 +1314,8 @@ class Structure extends Get
if(!isset($custom['file']) && isset($custom['filepath']))
{
$custom['file'] = '/'.trim($custom['filepath'], '/');
// update the dynamic path
$custom['file'] = $this->updateDynamicPath($custom['file']);
// remove the file path
unset($custom['filepath']);
// triget fullpath
@ -1312,6 +1391,19 @@ class Structure extends Get
}
}
/**
* Update paths with real value
*
* @param string $path The full path
*
* @return string The updated path
*
*/
protected function updateDynamicPath($path)
{
return $this->setPlaceholders($path, $this->constantPaths);
}
/**
* Remove folders with files
*

View File

@ -4682,6 +4682,66 @@ class Interpretation extends Fields
return $script;
}
public function setMoveFolderScript()
{
if ($this->setMoveFolders)
{
// reset script
$script = array();
$script[] = "\t\t//" . $this->setLine(__LINE__) . " We check if we have dynamic folders to copy";
$script[] = "\t\t\$this->setDynamicF0ld3rs(\$app, \$parent);";
// done
return PHP_EOL.implode(PHP_EOL, $script);
}
return '';
}
public function setMoveFolderMethod()
{
if ($this->setMoveFolders)
{
// reset script
$script = array();
$script[] = "\t/**";
$script[] = "\t * Method to set/copy dynamic folders into place (use with caution)";
$script[] = "\t *";
$script[] = "\t * @return void";
$script[] = "\t */";
$script[] = "\tprotected function setDynamicF0ld3rs(\$app, \$parent)";
$script[] = "\t{";
$script[] = "\t\t//" . $this->setLine(__LINE__) . " get the instalation path";
$script[] = "\t\t\$installer = \$parent->getParent();";
$script[] = "\t\t\$installPath = \$installer->getPath('source');";
$script[] = "\t\t//" . $this->setLine(__LINE__) . " get all the folders";
$script[] = "\t\t\$folders = JFolder::folders(\$installPath);";
$script[] = "\t\t//" . $this->setLine(__LINE__) . " check if we have folders we may want to copy";
$script[] = "\t\t\$doNotCopy = array('media','admin','site'); // Joomla already deals with these";
$script[] = "\t\tif (count(\$folders) > 1)";
$script[] = "\t\t{";
$script[] = "\t\t\tforeach (\$folders as \$folder)";
$script[] = "\t\t\t{";
$script[] = "\t\t\t\t//" . $this->setLine(__LINE__) . " Only copy if not a standard folders";
$script[] = "\t\t\t\tif (!in_array(\$folder, \$doNotCopy))";
$script[] = "\t\t\t\t{";
$script[] = "\t\t\t\t\t//" . $this->setLine(__LINE__) . " set the source path";
$script[] = "\t\t\t\t\t\$src = \$installPath.'/'.\$folder;";
$script[] = "\t\t\t\t\t//" . $this->setLine(__LINE__) . " set the destination path";
$script[] = "\t\t\t\t\t\$dest = JPATH_ROOT.'/'.\$folder;";
$script[] = "\t\t\t\t\t//" . $this->setLine(__LINE__) . " now try to copy the folder";
$script[] = "\t\t\t\t\tif (!JFolder::copy(\$src, \$dest, '', true))";
$script[] = "\t\t\t\t\t{";
$script[] = "\t\t\t\t\t\t\$app->enqueueMessage('Could not copy '.\$folder.' folder into place, please make sure destination is writable!', 'error');";
$script[] = "\t\t\t\t\t}";
$script[] = "\t\t\t\t}";
$script[] = "\t\t\t}";
$script[] = "\t\t}";
$script[] = "\t}";
// done
return PHP_EOL.PHP_EOL.implode(PHP_EOL, $script);
}
return '';
}
public function getContentType($view, $component)
{
// add if history is to be kept or if tags is added

View File

@ -1026,6 +1026,12 @@ class Infusion extends Interpretation
// ###UNINSTALLSCRIPT###
$this->fileContentStatic['###UNINSTALLSCRIPT###'] = $this->setUninstallScript();
// ###MOVEFOLDERSSCRIPT###
$this->fileContentStatic['###MOVEFOLDERSSCRIPT###'] = $this->setMoveFolderScript();
// ###MOVEFOLDERSMETHOD###
$this->fileContentStatic['###MOVEFOLDERSMETHOD###'] = $this->setMoveFolderMethod();
// ###HELPER_UIKIT###
$this->fileContentStatic['###HELPER_UIKIT###'] = $this->setUikitHelperMethods();