Added owner and key control to export & import of components, also added buy and package link building to global options gh-53

This commit is contained in:
2017-03-30 23:19:12 +02:00
parent f61bb46073
commit cca07258d6
196 changed files with 811 additions and 278 deletions

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage ajax.php

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage componentbuilder.php

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage adminviewfolderlist.php

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage adminviews.php

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage articles.php

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage component.php

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage customadminviews.php

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage customfilelist.php

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage customfolderlist.php

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage customgets.php

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage dbtables.php

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage dynamicgets.php

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage fields.php

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage fieldsmulti.php

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage fieldtypes.php

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage maingets.php

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage siteviewfolderlist.php

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage siteviews.php

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage snippets.php

View File

@ -9,8 +9,8 @@
|_|
/-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 214 of this MVC
@build 28th March, 2017
@version @update number 266 of this MVC
@build 30th March, 2017
@created 6th May, 2015
@package Component Builder
@subpackage joomla_component.js

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage import.php

View File

@ -11,7 +11,7 @@
/-------------------------------------------------------------------------------------------------------------------------------/
@version 2.3.9
@build 28th March, 2017
@build 30th March, 2017
@created 30th April, 2015
@package Component Builder
@subpackage import_joomla_components.php
@ -136,6 +136,7 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$session->clear('package');
$session->clear('dataType');
$session->clear('hasPackage');
$session->clear('smart_package_info');
break;
default:
@ -157,13 +158,20 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
}
// first link data to table headers
if(!$continue){
if(!$continue)
{
// check if this a smart package, if true then get info
if ($this->dataType === 'smart_package')
{
$this->getInfo($package, $session);
}
$package = json_encode($package);
$session->set('package', $package);
$session->set('dataType', $this->dataType);
$session->set('hasPackage', true);
return true;
}
// set the data
if ('continue-basic' == $this->getType)
{
@ -213,6 +221,48 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$this->remove($package['packagename']);
$session->clear($this->getType.'_VDM_IMPORTHEADERS');
return $result;
}
protected function getInfo(&$package, &$session)
{
// set the data
if(isset($package['dir']))
{
// set auto loader
ComponentbuilderHelper::autoLoader('smart');
// extract the package
if (JFile::exists($package['dir']))
{
// get the zip adapter
$zip = JArchive::getAdapter('zip');
// set the directory name
$dir = JFile::stripExt($package['dir']);
// unzip the package
$zip->extract($package['dir'], $dir);
// check for database file
$infoFile = $dir . '/info.vdm';
if (JFile::exists($infoFile))
{
// load the data
if ($info = @file_get_contents($infoFile))
{
// remove all line breaks
$info = str_replace("\n", '', $info);
// make sure we have base64
if ($info === base64_encode(base64_decode($info, true)))
{
// Get the encryption object.
$opener = new FOFEncryptAes('V4stD3vel0pmEntMethOd@YoUrS3rv!s', 128);
$info = rtrim($opener->decryptString($info), "\0");
$session->set('smart_package_info', $info);
return true;
}
}
}
ComponentbuilderHelper::removeFolder($dir);
}
}
return false;
}
/**
@ -493,14 +543,18 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
// extract the package
if (JFile::exists($package['dir']))
{
// get the zip adapter
$zip = JArchive::getAdapter('zip');
// set the directory name
$dir = JFile::stripExt($package['dir']);
// unzip the package
$zip->extract($package['dir'], $dir);
// check for database file
$dbFile = $dir . '/db.vdm';
if (!JFile::exists($dbFile))
{
// get the zip adapter
$zip = JArchive::getAdapter('zip');
// unzip the package
$zip->extract($package['dir'], $dir);
}
// check again
if (JFile::exists($dbFile))
{
// load the data
@ -544,20 +598,15 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
if ($data === base64_encode(base64_decode($data, true)))
{
// open the data
if($this->hasKey == 1 && ComponentbuilderHelper::checkString($this->sleutle) && strlen($this->sleutle) == 32)
if(ComponentbuilderHelper::checkString($this->sleutle) && strlen($this->sleutle) == 32)
{
// Get the encryption object.
$opener = new FOFEncryptAes($this->sleutle, 128);
$data = rtrim($opener->decryptString($data), "\0");
}
elseif($this->hasKey == 0)
{
$data = base64_decode($data);
}
else
{
$this->app->enqueueMessage(JText::_('COM_COMPONENTBUILDER_HTWOKEY_ERRORHTWOPLEASE_PROVIDE_THE_CORRECT_KEY_TO_IMPORT_THIS_PACKAGE'), 'error');
return false;
$data = base64_decode($data);
}
// final check if we have success
$data = @unserialize($data);
@ -822,6 +871,10 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$join_view_table = json_decode($item->join_view_table, true);
foreach ($join_view_table['view_table'] as $nr => $id)
{
if (!is_numeric($id))
{
continue;
}
// update the join_view_table
if (isset($this->newID['admin_view'][$id]))
{
@ -850,6 +903,7 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
}
else
{
$this->app->enqueueMessage(JText::sprintf('COM_COMPONENTBUILDER_BDYNAMIC_GETB_IDS_MISMATCH_IN_BSB', $item->dynamic_get, ComponentbuilderHelper::safeString($type, 'w').':'.$item->id), 'warning');
unset($item->dynamic_get);
}
break;
@ -872,6 +926,7 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
}
else
{
$this->app->enqueueMessage(JText::sprintf('COM_COMPONENTBUILDER_BDYNAMIC_GETB_IDS_MISMATCH_IN_BSB', $item->dynamic_get, ComponentbuilderHelper::safeString($type, 'w').':'.$item->id), 'warning');
unset($item->dynamic_get);
}
// update the custom_get
@ -880,6 +935,10 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$custom_get = json_decode($item->custom_get, true);
foreach ($custom_get as $nr => $get)
{
if (!is_numeric($get))
{
continue;
}
// update the custom_get
if (isset($this->newID['dynamic_get'][$get]))
{
@ -917,6 +976,10 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$addfields = json_decode($item->addfields, true);
foreach ($addfields['field'] as $nr => $id)
{
if (!is_numeric($id))
{
continue;
}
// update the addfields
if (isset($this->newID['field'][$id]))
{
@ -949,6 +1012,7 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
else
{
// this is painful but true...
$this->app->enqueueMessage(JText::sprintf('COM_COMPONENTBUILDER_BLINKED_ADMIN_VIEW_IN_SB_HAS_ID_MISMATCH_OF_SELECTED_BADMIN_VIEWB_SO_THE_IDS_WAS_NOT_UPDATED', '('.ComponentbuilderHelper::safeString($type, 'w').':'.$item->id.')', $id), 'warning');
$this->updateAfter = true;
}
}
@ -975,6 +1039,10 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
}
foreach ($ids as $id)
{
if (!is_numeric($id))
{
continue;
}
if (isset($this->newID['field'][$id]))
{
$addconditions[$target][$nr] = $this->newID['field'][$id];
@ -1002,6 +1070,10 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$addconfig = json_decode($item->addconfig, true);
foreach ($addconfig['field'] as $nr => $id)
{
if (!is_numeric($id))
{
continue;
}
// update the addconfig
if (isset($this->newID['field'][$id]))
{
@ -1022,6 +1094,10 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$addadmin_views = json_decode($item->addadmin_views, true);
foreach ($addadmin_views['adminview'] as $nr => $id)
{
if (!is_numeric($id))
{
continue;
}
// update the addadmin_views
if (isset($this->newID['admin_view'][$id]))
{
@ -1046,6 +1122,10 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$addcustom_admin_views = json_decode($item->addcustom_admin_views, true);
foreach ($addcustom_admin_views['customadminview'] as $nr => $id)
{
if (!is_numeric($id))
{
continue;
}
// update the addcustom_admin_views
if (isset($this->newID['custom_admin_view'][$id]))
{
@ -1066,6 +1146,10 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
$addsite_views = json_decode($item->addsite_views, true);
foreach ($addsite_views['siteview'] as $nr => $id)
{
if (!is_numeric($id))
{
continue;
}
// update the addsite_views
if (isset($this->newID['site_view'][$id]))
{
@ -1091,6 +1175,7 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
}
else
{
$this->app->enqueueMessage(JText::sprintf('COM_COMPONENTBUILDER_BCOMPONENT_IN_SB_HAS_ID_MISMATCH_OF_SELECTED_BCOMPONENTB_SO_THE_IDS_WAS_REMOVED', '('.ComponentbuilderHelper::safeString($type, 'w').':'.$item->id.')', $item->component), 'warning');
unset($item->component);
}
}

View File

@ -10,8 +10,8 @@
|_|
/-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 214 of this MVC
@build 28th March, 2017
@version @update number 266 of this MVC
@build 30th March, 2017
@created 6th May, 2015
@package Component Builder
@subpackage joomla_component.php

View File

@ -10,8 +10,8 @@
|_|
/-------------------------------------------------------------------------------------------------------------------------------/
@version @update number 214 of this MVC
@build 28th March, 2017
@version @update number 266 of this MVC
@build 30th March, 2017
@created 6th May, 2015
@package Component Builder
@subpackage joomla_components.php
@ -57,8 +57,21 @@ class ComponentbuilderModelJoomla_components extends JModelList
}
public $packagePath = false;
public $packageName = false;
public $zipPath = false;
public $key = array();
public $info = array(
'name' => array(),
'short_description' => array(),
'component_version' => array(),
'companyname' => array(),
'author' => array(),
'email' => array(),
'website' => array(),
'license' => array(),
'copyright' => array(),
'getKeyFrom' => null
);
protected $params;
protected $tempPath;
@ -115,7 +128,20 @@ class ComponentbuilderModelJoomla_components extends JModelList
// set the paths
$comConfig = JFactory::getConfig();
$this->tempPath = $comConfig->get('tmp_path');
$this->packagePath = $this->tempPath . '/JCB_smartPackage';
// set params
$this->params = JComponentHelper::getParams('com_componentbuilder');
// set custom folder path
$this->customPath = $this->params->get('custom_folder_path', JPATH_COMPONENT_ADMINISTRATOR.'/custom');
// set the package path
if (count($items) == 1)
{
$this->packageName = 'JCB_' . $this->getPackageName($items);
}
else
{
$this->packageName = 'JCB_smartPackage';
}
$this->packagePath = $this->tempPath . '/' . $this->packageName;
$this->zipPath = $this->packagePath .'.zip';
if (JFolder::exists($this->packagePath))
{
@ -124,10 +150,6 @@ class ComponentbuilderModelJoomla_components extends JModelList
}
// create the folders
JFolder::create($this->packagePath);
// set params
$this->params = JComponentHelper::getParams('com_componentbuilder');
// set custom folder path
$this->customPath = $this->params->get('custom_folder_path', JPATH_COMPONENT_ADMINISTRATOR.'/custom');
// Get the basic encription.
$basickey = ComponentbuilderHelper::getCryptKey('basic');
// Get the encription object.
@ -141,20 +163,37 @@ class ComponentbuilderModelJoomla_components extends JModelList
$this->smartExport['joomla_component'] = array();
foreach ($items as $nr => &$item)
{
// check if user has access
$access = ($user->authorise('joomla_component.access', 'com_componentbuilder.joomla_component.' . (int) $item->id) && $user->authorise('joomla_component.access', 'com_componentbuilder'));
if (!$access)
{
unset($items[$nr]);
continue;
}
// build information data set
$this->info['name'][$item->id] = $item->name;
$this->info['short_description'][$item->id] = $item->short_description;
$this->info['component_version'][$item->id] = $item->component_version;
$this->info['companyname'][$item->id] = $item->companyname;
$this->info['author'][$item->id] = $item->author;
$this->info['email'][$item->id] = $item->email;
$this->info['website'][$item->id] = $item->website;
$this->info['license'][$item->id] = $item->license;
$this->info['copyright'][$item->id] = $item->copyright;
// set the keys
if (isset($item->export_key) && ComponentbuilderHelper::checkString($item->export_key))
{
// keep the key locked for exported data set
$export_key = $item->export_key;
if ($basickey && !is_numeric($item->export_key) && $item->export_key === base64_encode(base64_decode($item->export_key, true)))
{
$item->export_key = rtrim($basic->decryptString($item->export_key), "\0");
$export_key = rtrim($basic->decryptString($item->export_key), "\0");
}
// make sure we have a string
if (strlen($export_key) > 4 )
{
$this->key[$item->id] = $export_key;
}
$this->key[$item->id] = $item->export_key;
}
// build files
$this->moveIt($item->addfiles, 'file');
@ -209,30 +248,49 @@ class ComponentbuilderModelJoomla_components extends JModelList
*/
protected function smartExportBuilder()
{
// set db data
$data = serialize($this->smartExport);
// lock the data if set
if (ComponentbuilderHelper::checkArray($this->key))
{
// lock the data
$this->key = md5(implode('', $this->key));
$locker = new FOFEncryptAes($this->key, 128);
$data = $locker->encryptString($data);
$data = $locker->encryptString($data);
// Set the key owner information
$this->info['getKeyFrom'] = array();
$this->info['getKeyFrom']['company'] = $this->params->get('export_company', null);
$this->info['getKeyFrom']['owner'] = $this->params->get('export_owner', null);
$this->info['getKeyFrom']['email'] = $this->params->get('export_email', null);
$this->info['getKeyFrom']['website'] = $this->params->get('export_website', null);
$this->info['getKeyFrom']['license'] = $this->params->get('export_license', null);
$this->info['getKeyFrom']['copyright'] = $this->params->get('export_copyright', null);
$this->info['getKeyFrom']['buy_link'] = ($buy_link = $this->params->get('export_buy_link', null)) ? $buy_link . $this->params->get('export_buy_query', '&package=') . $this->packageName : null;
$this->info['getKeyFrom']['package_link'] = ($package_link = $this->params->get('export_package_link', null)) ? $package_link . $this->params->get('export_package_query', '&package=') . $this->packageName : null;
}
else
{
// Set the owner information
$data = base64_encode($data);
}
// set the path
$dbPath = $this->packagePath . '/db.vdm';
if (JFile::exists($dbPath))
{
// remove file if found
JFile::delete($dbPath);
}
// write the db data to file in package
if (!ComponentbuilderHelper::writeFile($dbPath, wordwrap($data, 128, "\n", true)))
{
return false;
}
// set info data
$locker = new FOFEncryptAes('V4stD3vel0pmEntMethOd@YoUrS3rv!s', 128);
$info = $locker->encryptString(json_encode($this->info));
// set the path
$infoPath = $this->packagePath . '/info.vdm';
// write the db data to file in package
if (!ComponentbuilderHelper::writeFile($infoPath, wordwrap($info, 128, "\n", true)))
{
return false;
}
// remove old zip files with the same name
if (JFile::exists($this->zipPath))
{
// remove file if found
@ -631,6 +689,22 @@ class ComponentbuilderModelJoomla_components extends JModelList
}
}
/**
* Get the package name
*
* @param array $items of all components
*
* @return string The package name
*
*/
protected function getPackageName(&$items)
{
foreach ($items as $item)
{
return ComponentbuilderHelper::safeString($item->name_code);
}
}
/**
* Get the keys of the values to search custom code in
*