From 952d26f1f8f0246b5c3ae53675ca71f00086d55a Mon Sep 17 00:00:00 2001 From: dev Date: Sat, 18 Mar 2017 22:17:15 +0200 Subject: [PATCH] added the getData method of the component smart export feature --- README.md | 2 +- admin/README.txt | 2 +- admin/assets/css/joomla_component.css | 2 +- admin/assets/css/joomla_components.css | 2 +- admin/controllers/joomla_component.php | 2 +- admin/controllers/joomla_components.php | 11 +- admin/models/forms/joomla_component.js | 2 +- admin/models/joomla_component.php | 2 +- admin/models/joomla_components.php | 266 +++++++++++++++++- admin/tables/joomla_component.php | 2 +- admin/views/joomla_component/submitbutton.js | 2 +- admin/views/joomla_component/tmpl/edit.php | 2 +- admin/views/joomla_component/view.html.php | 2 +- .../views/joomla_components/tmpl/default.php | 2 +- .../tmpl/default_batch_body.php | 2 +- .../tmpl/default_batch_footer.php | 2 +- .../joomla_components/tmpl/default_body.php | 2 +- .../joomla_components/tmpl/default_foot.php | 2 +- .../joomla_components/tmpl/default_head.php | 2 +- .../tmpl/default_toolbar.php | 2 +- admin/views/joomla_components/view.html.php | 4 +- 21 files changed, 285 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 0c0573152..85a5fef93 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ Component Builder is mapped as a component in itself on my local development env + *Version*: 2.3.7 + *Copyright*: Copyright (C) 2015. All Rights Reserved + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html -+ *Line count*: **92987** ++ *Line count*: **93240** + *File count*: **602** + *Folder count*: **105** diff --git a/admin/README.txt b/admin/README.txt index 0c0573152..85a5fef93 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -108,7 +108,7 @@ Component Builder is mapped as a component in itself on my local development env + *Version*: 2.3.7 + *Copyright*: Copyright (C) 2015. All Rights Reserved + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html -+ *Line count*: **92987** ++ *Line count*: **93240** + *File count*: **602** + *Folder count*: **105** diff --git a/admin/assets/css/joomla_component.css b/admin/assets/css/joomla_component.css index 4d8c6f0dc..ff824f488 100644 --- a/admin/assets/css/joomla_component.css +++ b/admin/assets/css/joomla_component.css @@ -9,7 +9,7 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 101 of this MVC + @version @update number 112 of this MVC @build 18th March, 2017 @created 6th May, 2015 @package Component Builder diff --git a/admin/assets/css/joomla_components.css b/admin/assets/css/joomla_components.css index 931759369..30f9e684b 100644 --- a/admin/assets/css/joomla_components.css +++ b/admin/assets/css/joomla_components.css @@ -9,7 +9,7 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 101 of this MVC + @version @update number 112 of this MVC @build 18th March, 2017 @created 6th May, 2015 @package Component Builder diff --git a/admin/controllers/joomla_component.php b/admin/controllers/joomla_component.php index a8c5e9fa1..64325a639 100644 --- a/admin/controllers/joomla_component.php +++ b/admin/controllers/joomla_component.php @@ -10,7 +10,7 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 101 of this MVC + @version @update number 112 of this MVC @build 18th March, 2017 @created 6th May, 2015 @package Component Builder diff --git a/admin/controllers/joomla_components.php b/admin/controllers/joomla_components.php index 48d8a9442..2b213d156 100644 --- a/admin/controllers/joomla_components.php +++ b/admin/controllers/joomla_components.php @@ -10,7 +10,7 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 101 of this MVC + @version @update number 112 of this MVC @build 18th March, 2017 @created 6th May, 2015 @package Component Builder @@ -109,13 +109,13 @@ class ComponentbuilderControllerJoomla_components extends JControllerAdmin return; } - public function exportComponent() + public function smartExport() { // Check for request forgeries JSession::checkToken() or die(JText::_('JINVALID_TOKEN')); // check if export is allowed for this user. $user = JFactory::getUser(); - if ($user->authorise('[[[view]]].export', 'com_componentbuilder') && $user->authorise('core.export', 'com_componentbuilder')) + if ($user->authorise('joomla_component.export', 'com_componentbuilder') && $user->authorise('core.export', 'com_componentbuilder')) { // Get the input $input = JFactory::getApplication()->input; @@ -125,11 +125,10 @@ class ComponentbuilderControllerJoomla_components extends JControllerAdmin // Get the model $model = $this->getModel('Joomla_components'); // get the data to export - $data = $model->getSmartExport($pks); - if (ComponentbuilderHelper::checkArray($data)) + if ($model->getSmartExport($pks)) { // now lets look at what was build - var_dump($data); jexit(); + var_dump($model->smartExport); jexit(); } } // Redirect to the list screen with error. diff --git a/admin/models/forms/joomla_component.js b/admin/models/forms/joomla_component.js index 30a107f53..83ee45d3a 100644 --- a/admin/models/forms/joomla_component.js +++ b/admin/models/forms/joomla_component.js @@ -9,7 +9,7 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 101 of this MVC + @version @update number 112 of this MVC @build 18th March, 2017 @created 6th May, 2015 @package Component Builder diff --git a/admin/models/joomla_component.php b/admin/models/joomla_component.php index 5eb02344f..aba943a8a 100644 --- a/admin/models/joomla_component.php +++ b/admin/models/joomla_component.php @@ -10,7 +10,7 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 101 of this MVC + @version @update number 112 of this MVC @build 18th March, 2017 @created 6th May, 2015 @package Component Builder diff --git a/admin/models/joomla_components.php b/admin/models/joomla_components.php index 558907584..f881dd54c 100644 --- a/admin/models/joomla_components.php +++ b/admin/models/joomla_components.php @@ -10,7 +10,7 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 101 of this MVC + @version @update number 112 of this MVC @build 18th March, 2017 @created 6th May, 2015 @package Component Builder @@ -56,6 +56,10 @@ class ComponentbuilderModelJoomla_components extends JModelList parent::__construct($config); } + public $smartExport = array(); + protected $templateIds = array(); + protected $layoutIds = array(); + /** * Method to get list export data. * @@ -95,9 +99,11 @@ class ComponentbuilderModelJoomla_components extends JModelList if ($db->getNumRows()) { $items = $db->loadObjectList(); - // set values to display correctly. + // check if we have items if (ComponentbuilderHelper::checkArray($items)) { + // start loading the components + $this->smartExport['components'] = array(); foreach ($items as $nr => &$item) { $access = ($user->authorise('joomla_component.access', 'com_componentbuilder.joomla_component.' . (int) $item->id) && $user->authorise('joomla_component.access', 'com_componentbuilder')); @@ -105,12 +111,260 @@ class ComponentbuilderModelJoomla_components extends JModelList { unset($items[$nr]); continue; - } - + } + // add config fields + $this->setData($user, $db, 'field', $item->addconfig, 'field'); + // add admin views + $this->setData($user, $db, 'admin_view', $item->addadmin_views, 'adminview'); + // add custom admin views + $this->setData($user, $db, 'custom_admin_view', $item->addcustom_admin_views, 'customadminview'); + // add site views + $this->setData($user, $db, 'site_view', $item->addsite_views, 'siteview'); + // load to global object + $this->smartExport['components'][$item->id] = $item; + } + // add templates + if (ComponentbuilderHelper::checkArray($this->templateIds)) + { + $this->setData($user, $db, 'template', array('template' => $this->templateIds), 'template'); + } + // add layouts + if (ComponentbuilderHelper::checkArray($this->layoutIds)) + { + $this->setData($user, $db, 'layout', array('layout' => $this->layoutIds), 'layout'); + } + // has any data been set + if (ComponentbuilderHelper::checkArray($this->smartExport['components'])) + { + return true; } } - - return $items; + } + } + return false; + } + + /** + * Method to get data of a given table. + * + * @return mixed An array of data items on success, false on failure. + */ + protected function setData(&$user, &$db, $table, $values, $key) + { + // if json convert to array + if (ComponentbuilderHelper::checkJson($values)) + { + $values = json_decode($values, true); + } + // make sure we have an array + if (!ComponentbuilderHelper::checkArray($values) || !isset($values[$key]) || !ComponentbuilderHelper::checkArray($values[$key])) + { + return false; + } + $query = $db->getQuery(true); + + // Select some fields + $query->select($db->quoteName('a.*')); + + // From the componentbuilder_ANY table + $query->from($db->quoteName('#__componentbuilder_'. $table, 'a')); + $query->where('a.id IN (' . implode(',',$values[$key]) . ')'); + + // Implement View Level Access + if (!$user->authorise('core.options', 'com_componentbuilder')) + { + $groups = implode(',', $user->getAuthorisedViewLevels()); + $query->where('a.access IN (' . $groups . ')'); + } + + // Order the results by ordering + $query->order('a.ordering ASC'); + + // Load the items + $db->setQuery($query); + $db->execute(); + if ($db->getNumRows()) + { + $items = $db->loadObjectList(); + // check if we have items + if (ComponentbuilderHelper::checkArray($items)) + { + // set search array + if ('site_view' === $table || 'custom_admin_view' === $table) + { + $searchArray = array('php_view','php_jview','php_jview_display','php_document','js_document','css_document','css'); + } + // start loading the data + if (!isset($this->smartExport[$table])) + { + $this->smartExport[$table] = array(); + } + foreach ($items as $nr => &$item) + { + if (isset($this->smartExport[$table][$item->id])) + { + continue; + } + // actions to take if table is admin_view + if ('admin_view' === $table) + { + // add fields + $this->setData($user, $db, 'field', $item->addfields, 'field'); + } + // actions to take if table is field + if ('field' === $table) + { + // add field types + $this->setData($user, $db, 'fieldtype', array('fieldtype' => array($item->fieldtype)), 'fieldtype'); + } + // actions to take if table is site_view and custom_admin_view + if ('site_view' === $table || 'custom_admin_view' === $table) + { + // search for templates & layouts + $this->getTemplateLayout(base64_decode($item->default), $db); + // add search array templates and layouts + foreach ($searchArray as $scripter) + { + if (isset($view->{'add_'.$scripter}) && $view->{'add_'.$scripter} == 1) + { + $this->getTemplateLayout($view->$scripter, $db); + } + } + // add dynamic gets + $this->setData($user, $db, 'dynamic_get', array('dynamic_get' => array($item->main_get)), 'dynamic_get'); + $this->setData($user, $db, 'dynamic_get', array('dynamic_get' => $item->custom_get), 'dynamic_get'); + } + // load to global object + $this->smartExport[$table][$item->id] = $item; + } + } + } + } + + /** + * Set Template and Layout Data + * + * @param string $default The content to check + * + * @return void + * + */ + protected function getTemplateLayout($default, &$db) + { + // set the Template data + $temp1 = ComponentbuilderHelper::getAllBetween($default, "\$this->loadTemplate('","')"); + $temp2 = ComponentbuilderHelper::getAllBetween($default, '$this->loadTemplate("','")'); + $templates = array(); + $again = array(); + if (ComponentbuilderHelper::checkArray($temp1) && ComponentbuilderHelper::checkArray($temp2)) + { + $templates = array_merge($temp1,$temp2); + } + else + { + if (ComponentbuilderHelper::checkArray($temp1)) + { + $templates = $temp1; + } + elseif (ComponentbuilderHelper::checkArray($temp2)) + { + $templates = $temp2; + } + } + if (ComponentbuilderHelper::checkArray($templates)) + { + foreach ($templates as $template) + { + $data = $this->getDataWithAlias($template, 'template', $db); + if (ComponentbuilderHelper::checkArray($data)) + { + if (!isset($this->templateIds[$data['id']])) + { + $this->templateIds[$data['id']] = $data['id']; + // call self to get child data + $again[] = $data['html']; + $again[] = $data['php_view']; + } + } + } + } + // set the layout data + $lay1 = ComponentbuilderHelper::getAllBetween($default, "JLayoutHelper::render('","',"); + $lay2 = ComponentbuilderHelper::getAllBetween($default, 'JLayoutHelper::render("','",');; + if (ComponentbuilderHelper::checkArray($lay1) && ComponentbuilderHelper::checkArray($lay2)) + { + $layouts = array_merge($lay1,$lay2); + } + else + { + if (ComponentbuilderHelper::checkArray($lay1)) + { + $layouts = $lay1; + } + elseif (ComponentbuilderHelper::checkArray($lay2)) + { + $layouts = $lay2; + } + } + if (isset($layouts) && ComponentbuilderHelper::checkArray($layouts)) + { + foreach ($layouts as $layout) + { + $data = $this->getDataWithAlias($layout, 'layout', $db); + if (ComponentbuilderHelper::checkArray($data)) + { + if (!isset($this->layoutIds[$data['id']])) + { + $this->layoutIds[$data['id']] = $data['id']; + // call self to get child data + $again[] = $data['html']; + $again[] = $data['php_view']; + } + } + } + } + if (ComponentbuilderHelper::checkArray($again)) + { + foreach ($again as $get) + { + $this->getTemplateLayout($get, $db); + } + } + } + + /** + * Get Data With Alias + * + * @param string $n_ame The alias name + * @param string $table The table where to find the alias + * @param string $view The view code name + * + * @return array The data found with the alias + * + */ + protected function getDataWithAlias($n_ame, $table, &$db) + { + // Create a new query object. + $query = $db->getQuery(true); + $query->select($db->quoteName(array('a.id', 'a.alias', 'a.'.$table, 'a.php_view', 'a.add_php_view'))); + $query->from('#__componentbuilder_'.$table.' AS a'); + $db->setQuery($query); + $rows = $db->loadObjectList(); + foreach ($rows as $row) + { + $k_ey = ComponentbuilderHelper::safeString($row->alias); + $key = preg_replace("/[^A-Za-z]/", '', $k_ey); + $name = preg_replace("/[^A-Za-z]/", '', $n_ame); + if ($k_ey == $n_ame || $key == $name) + { + $php_view = ''; + if ($row->add_php_view == 1) + { + $php_view = base64_decode($row->php_view); + } + $contnent = base64_decode($row->{$table}); + // return to continue the search + return array('id' => $row->id, 'html' => $contnent, 'php_view' => $php_view); } } return false; diff --git a/admin/tables/joomla_component.php b/admin/tables/joomla_component.php index fb8f3223c..0597e05de 100644 --- a/admin/tables/joomla_component.php +++ b/admin/tables/joomla_component.php @@ -10,7 +10,7 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 101 of this MVC + @version @update number 112 of this MVC @build 18th March, 2017 @created 6th May, 2015 @package Component Builder diff --git a/admin/views/joomla_component/submitbutton.js b/admin/views/joomla_component/submitbutton.js index 94c99aa83..6d423a162 100644 --- a/admin/views/joomla_component/submitbutton.js +++ b/admin/views/joomla_component/submitbutton.js @@ -9,7 +9,7 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 101 of this MVC + @version @update number 112 of this MVC @build 18th March, 2017 @created 6th May, 2015 @package Component Builder diff --git a/admin/views/joomla_component/tmpl/edit.php b/admin/views/joomla_component/tmpl/edit.php index 240decd35..041724ed1 100644 --- a/admin/views/joomla_component/tmpl/edit.php +++ b/admin/views/joomla_component/tmpl/edit.php @@ -10,7 +10,7 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 101 of this MVC + @version @update number 112 of this MVC @build 18th March, 2017 @created 6th May, 2015 @package Component Builder diff --git a/admin/views/joomla_component/view.html.php b/admin/views/joomla_component/view.html.php index 068a09b01..e1307fa43 100644 --- a/admin/views/joomla_component/view.html.php +++ b/admin/views/joomla_component/view.html.php @@ -10,7 +10,7 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 101 of this MVC + @version @update number 112 of this MVC @build 18th March, 2017 @created 6th May, 2015 @package Component Builder diff --git a/admin/views/joomla_components/tmpl/default.php b/admin/views/joomla_components/tmpl/default.php index 1c816b9a2..c795d647b 100644 --- a/admin/views/joomla_components/tmpl/default.php +++ b/admin/views/joomla_components/tmpl/default.php @@ -10,7 +10,7 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 101 of this MVC + @version @update number 112 of this MVC @build 18th March, 2017 @created 6th May, 2015 @package Component Builder diff --git a/admin/views/joomla_components/tmpl/default_batch_body.php b/admin/views/joomla_components/tmpl/default_batch_body.php index 86ddc0a0c..112b91f54 100644 --- a/admin/views/joomla_components/tmpl/default_batch_body.php +++ b/admin/views/joomla_components/tmpl/default_batch_body.php @@ -10,7 +10,7 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 101 of this MVC + @version @update number 112 of this MVC @build 18th March, 2017 @created 6th May, 2015 @package Component Builder diff --git a/admin/views/joomla_components/tmpl/default_batch_footer.php b/admin/views/joomla_components/tmpl/default_batch_footer.php index 7e6141ca0..24b04be1f 100644 --- a/admin/views/joomla_components/tmpl/default_batch_footer.php +++ b/admin/views/joomla_components/tmpl/default_batch_footer.php @@ -10,7 +10,7 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 101 of this MVC + @version @update number 112 of this MVC @build 18th March, 2017 @created 6th May, 2015 @package Component Builder diff --git a/admin/views/joomla_components/tmpl/default_body.php b/admin/views/joomla_components/tmpl/default_body.php index cbde0b385..198ac25ac 100644 --- a/admin/views/joomla_components/tmpl/default_body.php +++ b/admin/views/joomla_components/tmpl/default_body.php @@ -10,7 +10,7 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 101 of this MVC + @version @update number 112 of this MVC @build 18th March, 2017 @created 6th May, 2015 @package Component Builder diff --git a/admin/views/joomla_components/tmpl/default_foot.php b/admin/views/joomla_components/tmpl/default_foot.php index 7455f46f4..d24f6857a 100644 --- a/admin/views/joomla_components/tmpl/default_foot.php +++ b/admin/views/joomla_components/tmpl/default_foot.php @@ -10,7 +10,7 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 101 of this MVC + @version @update number 112 of this MVC @build 18th March, 2017 @created 6th May, 2015 @package Component Builder diff --git a/admin/views/joomla_components/tmpl/default_head.php b/admin/views/joomla_components/tmpl/default_head.php index 1bf29b619..c59badd20 100644 --- a/admin/views/joomla_components/tmpl/default_head.php +++ b/admin/views/joomla_components/tmpl/default_head.php @@ -10,7 +10,7 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 101 of this MVC + @version @update number 112 of this MVC @build 18th March, 2017 @created 6th May, 2015 @package Component Builder diff --git a/admin/views/joomla_components/tmpl/default_toolbar.php b/admin/views/joomla_components/tmpl/default_toolbar.php index a7fd8a57c..9acd49e49 100644 --- a/admin/views/joomla_components/tmpl/default_toolbar.php +++ b/admin/views/joomla_components/tmpl/default_toolbar.php @@ -10,7 +10,7 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 101 of this MVC + @version @update number 112 of this MVC @build 18th March, 2017 @created 6th May, 2015 @package Component Builder diff --git a/admin/views/joomla_components/view.html.php b/admin/views/joomla_components/view.html.php index d9708af4a..79903d48b 100644 --- a/admin/views/joomla_components/view.html.php +++ b/admin/views/joomla_components/view.html.php @@ -10,7 +10,7 @@ |_| /-------------------------------------------------------------------------------------------------------------------------------/ - @version @update number 101 of this MVC + @version @update number 112 of this MVC @build 18th March, 2017 @created 6th May, 2015 @package Component Builder @@ -138,7 +138,7 @@ class ComponentbuilderViewJoomla_components extends JViewLegacy if ($this->user->authorise('joomla_component.export_component')) { // add Export Component button. - JToolBarHelper::custom('joomla_components.exportComponent', 'download', '', 'COM_COMPONENTBUILDER_EXPORT_COMPONENT', false); + JToolBarHelper::custom('joomla_components.smartExport', 'download', '', 'COM_COMPONENTBUILDER_EXPORT_COMPONENT', false); } if ($this->state->get('filter.published') == -2 && ($this->canState && $this->canDelete))