Expande the compiler to fully build and zip plugins linked to components. Added plugin_updates area. Fixed gh-454 to insure placeholders are build even if no local db placeholders are found. Fixed gh-453 to prevent count error with null return value.

This commit is contained in:
2019-08-08 17:35:58 +02:00
parent 7d2cc2c9f0
commit ed43b00862
87 changed files with 7569 additions and 3584 deletions

View File

@ -18,6 +18,13 @@ defined('_JEXEC') or die('Restricted access');
class Get
{
/**
* The Joomla Version
*
* @var string
*/
public $joomlaVersion;
/**
* The hash placeholder
*
@ -769,6 +776,8 @@ class Get
}
}
}
// set the Joomla version
$this->joomlaVersion = $config['version'];
// set the minfy switch of the JavaScript
$this->minify = (isset($config['minify']) && $config['minify'] != 2) ? $config['minify'] : $this->params->get('minify', 0);
// set the global language
@ -950,24 +959,24 @@ class Get
{
$code = base64_decode($code);
}
// set component place holders
$bucket[$this->hhh . 'component' . $this->hhh] = $this->componentCodeName;
$bucket[$this->hhh . 'Component' . $this->hhh] = ComponentbuilderHelper::safeString($this->componentCodeName, 'F');
$bucket[$this->hhh . 'COMPONENT' . $this->hhh] = ComponentbuilderHelper::safeString($this->componentCodeName, 'U');
$bucket[$this->bbb . 'component' . $this->ddd] = $bucket[$this->hhh . 'component' . $this->hhh];
$bucket[$this->bbb . 'Component' . $this->ddd] = $bucket[$this->hhh . 'Component' . $this->hhh];
$bucket[$this->bbb . 'COMPONENT' . $this->ddd] = $bucket[$this->hhh . 'COMPONENT' . $this->hhh];
// get the current components overides
if (($_placeholders = ComponentbuilderHelper::getVar('component_placeholders', $this->componentID, 'joomla_component', 'addplaceholders')) !== false
&& ComponentbuilderHelper::checkJson($_placeholders))
}
// set component place holders
$bucket[$this->hhh . 'component' . $this->hhh] = $this->componentCodeName;
$bucket[$this->hhh . 'Component' . $this->hhh] = ComponentbuilderHelper::safeString($this->componentCodeName, 'F');
$bucket[$this->hhh . 'COMPONENT' . $this->hhh] = ComponentbuilderHelper::safeString($this->componentCodeName, 'U');
$bucket[$this->bbb . 'component' . $this->ddd] = $bucket[$this->hhh . 'component' . $this->hhh];
$bucket[$this->bbb . 'Component' . $this->ddd] = $bucket[$this->hhh . 'Component' . $this->hhh];
$bucket[$this->bbb . 'COMPONENT' . $this->ddd] = $bucket[$this->hhh . 'COMPONENT' . $this->hhh];
// get the current components overides
if (($_placeholders = ComponentbuilderHelper::getVar('component_placeholders', $this->componentID, 'joomla_component', 'addplaceholders')) !== false
&& ComponentbuilderHelper::checkJson($_placeholders))
{
$_placeholders = json_decode($_placeholders, true);
if (ComponentbuilderHelper::checkArray($_placeholders))
{
$_placeholders = json_decode($_placeholders, true);
if (ComponentbuilderHelper::checkArray($_placeholders))
foreach($_placeholders as $row)
{
foreach($_placeholders as $row)
{
$bucket[$row['target']] = $row['value'];
}
$bucket[$row['target']] = $row['value'];
}
}
}
@ -6165,25 +6174,32 @@ class Get
$query->select(
$this->db->quoteName(
array(
'g.name',
'e.name',
'e.head',
'e.comment',
'e.id',
'j.addfiles',
'j.addfolders',
'j.addfilesfullpath',
'j.addfoldersfullpath'
'g.name',
'e.name',
'e.head',
'e.comment',
'e.id',
'f.addfiles',
'f.addfolders',
'f.addfilesfullpath',
'f.addfoldersfullpath',
'f.addurls',
'u.version_update',
'u.id'
), array(
'group',
'extends',
'class_head',
'comment',
'class_id',
'addfiles',
'addfolders',
'addfilesfullpath',
'addfoldersfullpath'
'group',
'extends',
'class_head',
'comment',
'class_id',
'addfiles',
'addfolders',
'addfilesfullpath',
'addfoldersfullpath',
'addurls',
'version_update',
'version_update_id'
)
)
);
@ -6191,7 +6207,8 @@ class Get
$query->from('#__componentbuilder_joomla_plugin AS a');
$query->join('LEFT', $this->db->quoteName('#__componentbuilder_joomla_plugin_group', 'g') . ' ON (' . $this->db->quoteName('a.joomla_plugin_group') . ' = ' . $this->db->quoteName('g.id') . ')');
$query->join('LEFT', $this->db->quoteName('#__componentbuilder_class_extends', 'e') . ' ON (' . $this->db->quoteName('a.class_extends') . ' = ' . $this->db->quoteName('e.id') . ')');
$query->join('LEFT', $this->db->quoteName('#__componentbuilder_joomla_plugin_files_folders_urls', 'j') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('j.joomla_plugin') . ')');
$query->join('LEFT', $this->db->quoteName('#__componentbuilder_joomla_plugin_updates', 'u') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('u.joomla_plugin') . ')');
$query->join('LEFT', $this->db->quoteName('#__componentbuilder_joomla_plugin_files_folders_urls', 'f') . ' ON (' . $this->db->quoteName('a.id') . ' = ' . $this->db->quoteName('f.joomla_plugin') . ')');
$query->where($this->db->quoteName('a.id') . ' = ' . (int) $id);
$query->where($this->db->quoteName('a.published') . ' >= 1');
$this->db->setQuery($query);
@ -6210,8 +6227,11 @@ class Get
// update to point to plugin
$this->target = $plugin->key;
$this->lang = $plugin->key;
// set version
$plugin->version = '1.0.' . (int) $plugin->version; // (TODO) add versioning to plugin
// set version if not set
if (empty($plugin->plugin_version))
{
$plugin->plugin_version = '1.0.0';
}
// set GUI mapper
$guiMapper = array( 'table' => 'joomla_plugin', 'id' => (int) $id, 'type' => 'php');
// update the name if it has dynamic values
@ -6228,6 +6248,8 @@ class Get
$plugin->installer_class_name = 'plg' . ucfirst($plugin->group) . ucfirst($plugin->name) . 'InstallerScript';
// set plugin folder name
$plugin->folder_name = 'plg_' . strtolower($plugin->group) . '_' . strtolower($plugin->name);
// set the zip name
$plugin->zip_name = $plugin->folder_name . '_v' . str_replace('.', '_', $plugin->plugin_version). '__J' . $this->joomlaVersion;
// set plugin file name
$plugin->file_name = strtolower($plugin->name);
// set official_name lang strings
@ -6242,7 +6264,7 @@ class Get
$this->setLangContent($plugin->key, $plugin->lang_prefix . '_DESCRIPTION', $plugin->description);
$plugin->description = '<p>' . $plugin->description . '</p>';
}
$plugin->xml_description = "<h1>" . $plugin->official_name . " (v." . $plugin->version . ")</h1> <div style='clear: both;'></div>" . $plugin->description . "<p>Created by <a href='" . trim($component->website) . "' target='_blank'>" . trim(JFilterOutput::cleanText($component->author)) . "</a><br /><small>Development started " . JFactory::getDate($plugin->created)->format("jS F, Y") . "</small></p>";
$plugin->xml_description = "<h1>" . $plugin->official_name . " (v." . $plugin->plugin_version . ")</h1> <div style='clear: both;'></div>" . $plugin->description . "<p>Created by <a href='" . trim($component->website) . "' target='_blank'>" . trim(JFilterOutput::cleanText($component->author)) . "</a><br /><small>Development started " . JFactory::getDate($plugin->created)->format("jS F, Y") . "</small></p>";
// set xml discription
$this->setLangContent($plugin->key, $plugin->lang_prefix . '_XML_DESCRIPTION', $plugin->xml_description);
// update the readme if set
@ -6307,14 +6329,15 @@ class Get
$plugin->fields = (isset($plugin->fields) && ComponentbuilderHelper::checkJson($plugin->fields)) ? json_decode($plugin->fields, true) : null;
if (ComponentbuilderHelper::checkArray($plugin->fields))
{
$plugin->config_fields = array_map(function($field) use ($id){
$key = $plugin->key;
$plugin->config_fields = array_map(function($field) use ($key){
// make sure the alias and title is 0
$field['alias'] = 0;
$field['title'] = 0;
// set the field details
$this->setFieldDetails($field, '_plugin_' . $id);
$this->setFieldDetails($field, $key);
// set unique name counter
$this->setUniqueNameCounter($field['base_name'], '_plugins_' . $id);
$this->setUniqueNameCounter($field['base_name'], $key);
// return field
return $field;
}, array_values($plugin->fields));
@ -6323,7 +6346,7 @@ class Get
foreach ($plugin->config_fields as $field)
{
// so first we lock the field name in
$this->getFieldName($field, '_plugins_' . $id);
$this->getFieldName($field, $plugin->key);
}
// unset original value
unset($plugin->fields);
@ -6420,6 +6443,10 @@ class Get
$plugin->{$server . '_protocol'} = 0;
}
}
// set the update server stuff (TODO)
// update_server_xml_path
// update_server_xml_file_name
// rest globals
$this->target = $_backup_target;
$this->lang = $_backup_lang;
@ -6447,10 +6474,11 @@ class Get
$xml .= PHP_EOL . $this->_t(1) . '<authorUrl>' . $this->hhh . 'AUTHORWEBSITE' . $this->hhh . '</authorUrl>';
$xml .= PHP_EOL . $this->_t(1) . '<copyright>' . $this->hhh . 'COPYRIGHT' . $this->hhh . '</copyright>';
$xml .= PHP_EOL . $this->_t(1) . '<license>' . $this->hhh . 'LICENSE' . $this->hhh . '</license>';
$xml .= PHP_EOL . $this->_t(1) . '<version>' . $plugin->version . '</version>';
$xml .= PHP_EOL . $this->_t(1) . '<version>' . $plugin->plugin_version . '</version>';
$xml .= PHP_EOL . $this->_t(1) . '<description>' . $plugin->lang_prefix . '_XML_DESCRIPTION</description>';
$xml .= $this->hhh . 'MAINXML' . $this->hhh;
$xml .= PHP_EOL . '</extension>';
$dates = array();
return $xml;
}

View File

@ -200,13 +200,6 @@ class Structure extends Get
*/
public $projectMonthTime = 0;
/**
* The Joomla Version
*
* @var string
*/
public $joomlaVersion;
/**
* The template path
*
@ -242,6 +235,13 @@ class Structure extends Get
*/
public $stdFolders = array('site', 'admin', 'media');
/**
* The standard root files
*
* @var array
*/
public $stdRootFiles = array('access.xml', 'config.xml', 'controller.php', 'index.html', 'README.txt');
/**
* Dynamic File Content
*
@ -341,6 +341,8 @@ class Structure extends Get
// first we run the perent constructor
if (parent::__construct($config))
{
// set the standard admin file
$this->stdRootFiles[] = $this->componentData->name_code . '.php';
// set incase no extra admin folder are loaded
$this->fileContentStatic[$this->hhh . 'EXSTRA_ADMIN_FOLDERS' . $this->hhh] = '';
// set incase no extra site folder are loaded
@ -355,8 +357,6 @@ class Structure extends Get
$this->fileContentStatic[$this->hhh . 'EXSTRA_MEDIA_FILES' . $this->hhh] = '';
// run global updater
ComponentbuilderHelper::runGlobalUpdater();
// set the Joomla version
$this->joomlaVersion = $config['version'];
// set the template path
$this->templatePath = $this->compilerPath . '/joomla_' . $config['version'];
// set some default names
@ -430,7 +430,8 @@ class Structure extends Get
$this->triggerEvent('jcb_ce_onBeforeSetPlugins', array(&$this->componentContext, &$this->componentData->joomla_plugins));
foreach ($this->componentData->joomla_plugins as $plugin)
{
if (ComponentbuilderHelper::checkObject($plugin) && isset($plugin->folder_name) && ComponentbuilderHelper::checkString($plugin->folder_name))
if (ComponentbuilderHelper::checkObject($plugin) && isset($plugin->folder_name)
&& ComponentbuilderHelper::checkString($plugin->folder_name))
{
// plugin path
$plugin->folder_path = $this->compilerPath . '/' . $plugin->folder_name;
@ -447,13 +448,20 @@ class Structure extends Get
$this->indexHTML($plugin->folder_name, $this->compilerPath);
}
// set main class file
$fileDetails = array('path' => $plugin->folder_path . '/' . $plugin->file_name . '.php', 'name' => $plugin->file_name . '.php', 'zip' => $plugin->file_name . '.php');
$this->writeFile($fileDetails['path'], '<?php' . PHP_EOL . '// Plugin main class template' . PHP_EOL . $this->hhh . 'BOM' . $this->hhh . PHP_EOL . $this->hhh . 'MAINCLASS' . $this->hhh);
$fileDetails = array('path' => $plugin->folder_path . '/' . $plugin->file_name . '.php',
'name' => $plugin->file_name . '.php', 'zip' => $plugin->file_name . '.php');
$this->writeFile($fileDetails['path'],
'<?php' . PHP_EOL . '// Plugin main class template' .
PHP_EOL . $this->hhh . 'BOM' . $this->hhh . PHP_EOL .
PHP_EOL . '// No direct access to this file' . PHP_EOL .
"defined('_JEXEC') or die('Restricted access');" . PHP_EOL .
$this->hhh . 'MAINCLASS' . $this->hhh);
$this->newFiles[$plugin->key][] = $fileDetails;
// count the file created
$this->fileCount++;
// set main xml file
$fileDetails = array('path' => $plugin->folder_path . '/' . $plugin->file_name . '.xml', 'name' => $plugin->file_name . '.xml', 'zip' => $plugin->file_name . '.xml');
$fileDetails = array('path' => $plugin->folder_path . '/' . $plugin->file_name . '.xml',
'name' => $plugin->file_name . '.xml', 'zip' => $plugin->file_name . '.xml');
$this->writeFile($fileDetails['path'], $this->getPluginXMLTemplate($plugin));
$this->newFiles[$plugin->key][] = $fileDetails;
// count the file created
@ -461,8 +469,14 @@ class Structure extends Get
// set install script if needed
if ($plugin->add_install_script)
{
$fileDetails = array('path' => $plugin->folder_path . '/script.php', 'name' => 'script.php', 'zip' => 'script.php');
$this->writeFile($fileDetails['path'], '<?php' . PHP_EOL . '// Script template' . PHP_EOL . $this->hhh . 'BOM' . $this->hhh . PHP_EOL . $this->hhh . 'INSTALLCLASS' . $this->hhh);
$fileDetails = array('path' => $plugin->folder_path . '/script.php',
'name' => 'script.php', 'zip' => 'script.php');
$this->writeFile($fileDetails['path'],
'<?php' . PHP_EOL . '// Script template' .
PHP_EOL . $this->hhh . 'BOM' . $this->hhh . PHP_EOL .
PHP_EOL . '// No direct access to this file' . PHP_EOL .
"defined('_JEXEC') or die('Restricted access');" . PHP_EOL .
$this->hhh . 'INSTALLCLASS' . $this->hhh);
$this->newFiles[$plugin->key][] = $fileDetails;
// count the file created
$this->fileCount++;
@ -470,7 +484,8 @@ class Structure extends Get
// set readme if found
if ($plugin->addreadme)
{
$fileDetails = array('path' => $plugin->folder_path . '/README.md', 'name' => 'README.md', 'zip' => 'README.md');
$fileDetails = array('path' => $plugin->folder_path . '/README.md',
'name' => 'README.md', 'zip' => 'README.md');
$this->writeFile($fileDetails['path'], $plugin->readme);
$this->newFiles[$plugin->key][] = $fileDetails;
// count the file created
@ -555,7 +570,8 @@ class Structure extends Get
foreach ($plugin->urls as $n => &$url)
{
// should we add the local folder
if (isset($url['type']) && $url['type'] > 1 && isset($url['url']) && ComponentbuilderHelper::checkString($url['url']))
if (isset($url['type']) && $url['type'] > 1 && isset($url['url'])
&& ComponentbuilderHelper::checkString($url['url']))
{
// set file name
$fileName = basename($url['url']);
@ -1016,7 +1032,7 @@ class Structure extends Get
{
continue;
}
// check if we have a target value set
// check if we have a target value
if (isset($details->_target))
{
// set destination path
@ -1094,14 +1110,15 @@ class Structure extends Get
$this->folderCount++;
}
}
// only add if no target found
// only add if no target found since those belong to plugins and modules
if (!isset($details->_target))
{
// check if we should add the dynamic folder moving script to the installer script
$checker = array_values((array) 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], $this->stdFolders))
if (isset($checker[0]) && ComponentbuilderHelper::checkString($checker[0])
&& !in_array($checker[0], $this->stdFolders))
{
// check if we should add the dynamic folder moving script to the installer script
if (!$this->setMoveFolders)
@ -1113,24 +1130,41 @@ class Structure extends Get
$this->app->enqueueMessage(JText::sprintf('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!'), 'Notice');
}
}
elseif (count($checker) == 2 && ComponentbuilderHelper::checkString($checker[0]) && in_array($checker[0], $this->stdFolders))
elseif (count($checker) == 2 && ComponentbuilderHelper::checkString($checker[0]))
{
$add_to_extra = false;
// set the target
$eNAME = 'FILES';
$ename = 'filename';
// this should not happen and must have been caught by the above if statment
if ($details->type === 'folder')
{
$eNAME = 'FOLDERS';
$ename = 'folder';
// only folders outside the standard folder are added
if (!in_array($checker[0], $this->stdFolders))
{
$eNAME = 'FOLDERS';
$ename = 'folder';
$add_to_extra = true;
}
}
// set the tab
$eTab = $this->_t(2);
if ('admin' === $checker[0])
// if this is a file, it can only be added to the admin/site/media folders
// all other folders are moved as a whole so their files do not need to be declared
elseif (in_array($checker[0], $this->stdFolders) && !in_array($checker[1], $this->stdRootFiles))
{
$eTab = $this->_t(3);
$add_to_extra = true;
}
// add if valid folder/file
if ($add_to_extra)
{
// set the tab
$eTab = $this->_t(2);
if ('admin' === $checker[0])
{
$eTab = $this->_t(3);
}
// set the xml file
$this->fileContentStatic[$this->hhh . 'EXSTRA_' . ComponentbuilderHelper::safeString($checker[0], 'U') . '_' . $eNAME . $this->hhh] .= PHP_EOL . $eTab . "<" . $ename . ">" . $checker[1] . "</" . $ename . ">";
}
// set the xml file
$this->fileContentStatic[$this->hhh . 'EXSTRA_' . ComponentbuilderHelper::safeString($checker[0], 'U') . '_' . $eNAME . $this->hhh] .= PHP_EOL . $eTab . "<" . $ename . ">" . $checker[1] . "</" . $ename . ">";
}
}
}

View File

@ -5218,7 +5218,7 @@ class Interpretation extends Fields
$script[] = $this->_t(2) . "\$folders = JFolder::folders(\$installPath);";
$script[] = $this->_t(2) . "//" . $this->setLine(__LINE__) . " check if we have folders we may want to copy";
$script[] = $this->_t(2) . "\$doNotCopy = array('media','admin','site'); // Joomla already deals with these";
$script[] = $this->_t(2) . "if (count(\$folders) > 1)";
$script[] = $this->_t(2) . "if (count((array) \$folders) > 1)";
$script[] = $this->_t(2) . "{";
$script[] = $this->_t(3) . "foreach (\$folders as \$folder)";
$script[] = $this->_t(3) . "{";
@ -10807,7 +10807,7 @@ class Interpretation extends Fields
$function[] = $this->_t(2) . "\$query->from(\$db->quoteName('" . $filter['custom']['table'] . "', 'a'));";
$function[] = $this->_t(2) . "//" . $this->setLine(__LINE__) . " get the targeted groups";
$function[] = $this->_t(2) . "\$groups= JComponentHelper::getParams('com_" . $component . "')->get('" . $filter['type'] . "');";
$function[] = $this->_t(2) . "if (count(\$groups) > 0)";
$function[] = $this->_t(2) . "if (!empty(\$groups) && count((array) \$groups) > 0)";
$function[] = $this->_t(2) . "{";
$function[] = $this->_t(3) . "\$query->join('LEFT', \$db->quoteName('#__user_usergroup_map', 'group') . ' ON (' . \$db->quoteName('group.user_id') . ' = ' . \$db->quoteName('a.id') . ')');";
$function[] = $this->_t(3) . "\$query->where('group.group_id IN (' . implode(',', \$groups) . ')');";
@ -16321,28 +16321,31 @@ function vdm_dkim() {
$xml = '';
// build the config fields
$config_field = '';
foreach ($plugin->config_fields as $field)
if (isset($plugin->config_fields) && ComponentbuilderHelper::checkArray($plugin->config_fields))
{
// check the field builder type
if ($this->fieldBuilderType == 1)
foreach ($plugin->config_fields as $field)
{
// string manipulation
$xmlField = $this->setDynamicField($field, $view, $viewType, $plugin->lang_prefix, $plugin->key, $plugin->key, $this->globalPlaceholders, $dbkey, false);
}
else
{
// simpleXMLElement class
$newxmlField = $this->setDynamicField($field, $view, $viewType, $plugin->lang_prefix, $plugin->key, $plugin->key, $this->globalPlaceholders, $dbkey, false);
if (isset($newxmlField->fieldXML))
// check the field builder type
if ($this->fieldBuilderType == 1)
{
$xmlField = dom_import_simplexml($newxmlField->fieldXML);
$xmlField = PHP_EOL . $this->_t(2) . "<!--" . $this->setLine(__LINE__) . " " . $newxmlField->comment . ' -->' . PHP_EOL . $this->_t(1) . $this->xmlPrettyPrint($xmlField, 'field');
// string manipulation
$xmlField = $this->setDynamicField($field, $view, $viewType, $plugin->lang_prefix, $plugin->key, $plugin->key, $this->globalPlaceholders, $dbkey, false);
}
else
{
// simpleXMLElement class
$newxmlField = $this->setDynamicField($field, $view, $viewType, $plugin->lang_prefix, $plugin->key, $plugin->key, $this->globalPlaceholders, $dbkey, false);
if (isset($newxmlField->fieldXML))
{
$xmlField = dom_import_simplexml($newxmlField->fieldXML);
$xmlField = PHP_EOL . $this->_t(2) . "<!--" . $this->setLine(__LINE__) . " " . $newxmlField->comment . ' -->' . PHP_EOL . $this->_t(1) . $this->xmlPrettyPrint($xmlField, 'field');
}
}
// make sure the xml is set and a string
if (isset($xmlField) && ComponentbuilderHelper::checkString($xmlField))
{
$config_field .= $xmlField;
}
}
// make sure the xml is set and a string
if (isset($xmlField) && ComponentbuilderHelper::checkString($xmlField))
{
$config_field .= $xmlField;
}
}
// switch to add the xml
@ -16474,27 +16477,167 @@ function vdm_dkim() {
{
// yes we are adding it
$script = PHP_EOL . '/**';
$script .= PHP_EOL . ' * ' . $plugin->name . ' script file.';
$script .= PHP_EOL . ' * ' . $plugin->official_name . ' script file.';
$script .= PHP_EOL . ' *';
$script .= PHP_EOL . ' * @package ' . $plugin->class_name;
$script .= PHP_EOL . ' */';
$script .= PHP_EOL . 'class ' . $plugin->installer_class_name;
$script .= PHP_EOL . '{';
// set constructor
if (isset($plugin->add_php_script_construct)
&& $plugin->add_php_script_construct == 1
&& ComponentbuilderHelper::checkString($plugin->php_script_construct))
{
$script .= $this->setInstallMethodScript('construct', $plugin->php_script_construct);
}
// add PHP in plugin install
$addScriptMethods = array('php_preflight', 'php_postflight', 'php_method');
$addScriptTypes = array('install', 'update', 'uninstall');
$addScriptTypes = array('install', 'update', 'uninstall', 'discover_install');
// set some buckets for sorting
$function_install = array();
$function_update = array();
$function_uninstall = array();
$has_php_preflight = false;
$function_php_preflight = array('install' => array(), 'uninstall' => array(), 'discover_install' => array(), 'update' => array());
$has_php_postflight = false;
$function_php_postflight = array('install' => array(), 'uninstall' => array(), 'discover_install' => array(), 'update' => array());
// the function sorter
foreach ($addScriptMethods as $scriptMethod)
{
foreach ($addScriptTypes as $scriptType)
{
if (isset($plugin->{'add_' . $scriptMethod . '_' . $scriptType}) && $plugin->{'add_' . $scriptMethod . '_' . $scriptType} == 1 && ComponentbuilderHelper::checkString($plugin->{$scriptMethod . '_' . $scriptType}))
if (isset($plugin->{'add_' . $scriptMethod . '_' . $scriptType})
&& $plugin->{'add_' . $scriptMethod . '_' . $scriptType} == 1
&& ComponentbuilderHelper::checkString($plugin->{$scriptMethod . '_' . $scriptType}))
{
// (TODO) must still finish
$script .= PHP_EOL . '//' . $this->setLine(__LINE__) . ' This part of the new plugin area is not ready yet, soon!';
// add to the main methods
if ('php_method' === $scriptMethod)
{
${'function_' . $scriptType}[] = $plugin->{$scriptMethod . '_' . $scriptType};
}
else
{
${'function_' . $scriptMethod}[$scriptType][] = $plugin->{$scriptMethod . '_' . $scriptType};
${'has_' . $scriptMethod} = true;
}
}
}
}
// now add the install script.
if (ComponentbuilderHelper::checkArray($function_install))
{
$script .= $this->setInstallMethodScript('install', $function_install);
}
// now add the update script.
if (ComponentbuilderHelper::checkArray($function_update))
{
$script .= $this->setInstallMethodScript('update', $function_update);
}
// now add the uninstall script.
if (ComponentbuilderHelper::checkArray($function_uninstall))
{
$script .= $this->setInstallMethodScript('uninstall', $function_uninstall);
}
// now add the preflight script.
if ($has_php_preflight)
{
$script .= $this->setInstallMethodScript('preflight', $function_php_preflight);
}
// now add the postflight script.
if ($has_php_postflight)
{
$script .= $this->setInstallMethodScript('postflight', $function_php_postflight);
}
$script .= PHP_EOL . '}' . PHP_EOL;
return $script;
}
protected function setInstallMethodScript($function_name, &$scripts)
{
$script = '';
// build function
switch($function_name)
{
case 'install':
case 'update':
case 'uninstall':
// the main function types
$script = PHP_EOL . PHP_EOL . $this->_t(1) .'/**';
$script .= PHP_EOL . $this->_t(1) .' * Called on ' . $function_name;
$script .= PHP_EOL . $this->_t(1) .' *';
$script .= PHP_EOL . $this->_t(1) .' * @param JAdapterInstance $adapter The object responsible for running this script';
$script .= PHP_EOL . $this->_t(1) .' *';
$script .= PHP_EOL . $this->_t(1) .' * @return boolean True on success';
$script .= PHP_EOL . $this->_t(1) .' */';
$script .= PHP_EOL . $this->_t(1) .'public function ' . $function_name . '(JAdapterInstance $adapter)';
$script .= PHP_EOL . $this->_t(1) .'{';
$script .= PHP_EOL . implode(PHP_EOL . PHP_EOL, $scripts);
// return true
if ('uninstall' !== $function_name)
{
$script .= PHP_EOL . $this->_t(2) . 'return true;';
}
break;
case 'preflight':
case 'postflight':
// the pre/post function types
$script = PHP_EOL . PHP_EOL . $this->_t(1) .'/**';
$script .= PHP_EOL . $this->_t(1) .' * Called before any type of action';
$script .= PHP_EOL . $this->_t(1) .' *';
$script .= PHP_EOL . $this->_t(1) .' * @param string $route Which action is happening (install|uninstall|discover_install|update)';
$script .= PHP_EOL . $this->_t(1) .' * @param JAdapterInstance $adapter The object responsible for running this script';
$script .= PHP_EOL . $this->_t(1) .' *';
$script .= PHP_EOL . $this->_t(1) .' * @return boolean True on success';
$script .= PHP_EOL . $this->_t(1) .' */';
$script .= PHP_EOL . $this->_t(1) .'public function ' . $function_name . '($route, JAdapterInstance $adapter)';
$script .= PHP_EOL . $this->_t(1) .'{';
$script .= PHP_EOL . $this->_t(2) . '//' . $this->setLine(__LINE__) . ' get application';
$script .= PHP_EOL . $this->_t(2) . '$app = JFactory::getApplication();' . PHP_EOL;
// add the default version check (TODO) must make this dynamic
if ('preflight' === $function_name)
{
$script .= PHP_EOL . $this->_t(2) . '//' . $this->setLine(__LINE__) . ' the default for both install and update';
$script .= PHP_EOL . $this->_t(2) . '$jversion = new JVersion();';
$script .= PHP_EOL . $this->_t(2) . "if (!\$jversion->isCompatible('3.8.0'))";
$script .= PHP_EOL . $this->_t(2) . '{';
$script .= PHP_EOL . $this->_t(3) . "\$app->enqueueMessage('Please upgrade to at least Joomla! 3.8.0 before continuing!', 'error');";
$script .= PHP_EOL . $this->_t(3) . 'return false;';
$script .= PHP_EOL . $this->_t(2) . '}' . PHP_EOL;
}
// now add the scripts
foreach ($scripts as $route => $_script)
{
if (ComponentbuilderHelper::checkArray($_script))
{
// set the if and script
$script .= PHP_EOL . $this->_t(2) . "if ('" . $route . "' === \$route)";
$script .= PHP_EOL . $this->_t(2) . '{';
$script .= PHP_EOL . implode(PHP_EOL . PHP_EOL, $_script);
$script .= PHP_EOL . $this->_t(2) . '}' . PHP_EOL;
}
}
// return true
$script .= PHP_EOL . $this->_t(2) . 'return true;';
break;
case 'construct':
// the __construct script
$script = PHP_EOL . PHP_EOL . $this->_t(1) .'/**';
$script .= PHP_EOL . $this->_t(1) .' * Constructor';
$script .= PHP_EOL . $this->_t(1) .' *';
$script .= PHP_EOL . $this->_t(1) .' * @param JAdapterInstance $adapter The object responsible for running this script';
$script .= PHP_EOL . $this->_t(1) .' */';
$script .= PHP_EOL . $this->_t(1) .'public function __construct(JAdapterInstance $adapter)';
$script .= PHP_EOL . $this->_t(1) .'{';
$script .= PHP_EOL . $scripts;
break;
default:
// oops error
return '';
}
// close the function
$script .= PHP_EOL . $this->_t(1) . '}';
return $script;
}

View File

@ -1032,9 +1032,6 @@ class Infusion extends Interpretation
$this->fileContentStatic[$this->hhh . 'README' . $this->hhh] = $this->componentData->readme;
}
// Trigger Event: jcb_ce_onAfterBuildFilesContent
$this->triggerEvent('jcb_ce_onAfterBuildFilesContent', array(&$this->componentContext, &$this->componentData, &$this->fileContentStatic, &$this->fileContentDynamic, &$this->placeholders, &$this->hhh));// Trigger Event: jcb_ce_onBeforeSetPlugins
// infuze plugin data if set
if (ComponentbuilderHelper::checkArray($this->componentData->joomla_plugins))
{
@ -1056,6 +1053,9 @@ class Infusion extends Interpretation
}
}
// Trigger Event: jcb_ce_onAfterBuildFilesContent
$this->triggerEvent('jcb_ce_onAfterBuildFilesContent', array(&$this->componentContext, &$this->componentData, &$this->fileContentStatic, &$this->fileContentDynamic, &$this->placeholders, &$this->hhh));
return true;
}
return false;