From a39289ac9cf13d0c364cf1904dabdb9b7da87f18 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Mon, 5 Mar 2018 02:13:42 +0200 Subject: [PATCH] Added feature that will allow custom icons on the dashboard of component to use custom links - resolved gh-240. Tweaked the compiler messages. --- README.md | 4 +- admin/README.txt | 4 +- admin/compiler/joomla_3/DASHJModelList.php | 102 ++++++++++-------- admin/compiler/joomla_3/JControllerLegacy.php | 8 +- admin/controller.php | 8 +- admin/helpers/compiler.php | 2 + admin/helpers/compiler/a_Get.php | 8 ++ admin/helpers/compiler/e_Interpretation.php | 93 +++++++++------- admin/models/componentbuilder.php | 102 ++++++++++-------- componentbuilder.xml | 2 +- 10 files changed, 197 insertions(+), 136 deletions(-) diff --git a/README.md b/README.md index 87766018e..d9b77b479 100644 --- a/README.md +++ b/README.md @@ -126,11 +126,11 @@ Component Builder is mapped as a component in itself on my local development env + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](http://joomlacomponentbuilder.com) + *First Build*: 30th April, 2015 -+ *Last Build*: 3rd March, 2018 ++ *Last Build*: 5th March, 2018 + *Version*: 2.6.17 + *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*: **183567** ++ *Line count*: **183587** + *Field count*: **1645** + *File count*: **1169** + *Folder count*: **189** diff --git a/admin/README.txt b/admin/README.txt index 87766018e..d9b77b479 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -126,11 +126,11 @@ Component Builder is mapped as a component in itself on my local development env + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](http://joomlacomponentbuilder.com) + *First Build*: 30th April, 2015 -+ *Last Build*: 3rd March, 2018 ++ *Last Build*: 5th March, 2018 + *Version*: 2.6.17 + *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*: **183567** ++ *Line count*: **183587** + *Field count*: **1645** + *File count*: **1169** + *Folder count*: **189** diff --git a/admin/compiler/joomla_3/DASHJModelList.php b/admin/compiler/joomla_3/DASHJModelList.php index e5d5053d2..65f0b06c4 100644 --- a/admin/compiler/joomla_3/DASHJModelList.php +++ b/admin/compiler/joomla_3/DASHJModelList.php @@ -48,6 +48,7 @@ class ###Component###Model###Component### extends JModelList $viewGroups = array( 'main' => array(###DASHBOARDICONS###) );###DASHBOARDICONACCESS### + // loop over the $views foreach($viewGroups as $group => $views) { $i = 0; @@ -56,47 +57,62 @@ class ###Component###Model###Component### extends JModelList foreach($views as $view) { $add = false; - if (strpos($view,'.') !== false) + // external views (links) + if (strpos($view,'||') !== false) { - $dwd = explode('.', $view); - if (count($dwd) == 3) + $dwd = explode('||', $view); + if (count($dwd) == 3) + { + list($type, $name, $url) = $dwd; + $viewName = $name; + $alt = $name; + $url = $url; + $image = $name.'.'.$type; + $name = 'COM_###COMPONENT###_DASHBOARD_'.###Component###Helper::safeString($name,'U'); + } + } + // internal views + elseif (strpos($view,'.') !== false) + { + $dwd = explode('.', $view); + if (count($dwd) == 3) + { + list($type, $name, $action) = $dwd; + } + elseif (count($dwd) == 2) + { + list($type, $name) = $dwd; + $action = false; + } + if ($action) + { + $viewName = $name; + switch($action) { - list($type, $name, $action) = $dwd; - } - elseif (count($dwd) == 2) - { - list($type, $name) = $dwd; - $action = false; - } - if ($action) - { - $viewName = $name; - switch($action) - { - case 'add': - $url ='index.php?option=com_###component###&view='.$name.'&layout=edit'; - $image = $name.'_'.$action.'.'.$type; - $alt = $name.' '.$action; - $name = 'COM_###COMPONENT###_DASHBOARD_'.###Component###Helper::safeString($name,'U').'_ADD'; - $add = true; - break; - default: - $url = 'index.php?option=com_categories&view=categories&extension=com_###component###.'.$name; - $image = $name.'_'.$action.'.'.$type; - $alt = $name.' '.$action; - $name = 'COM_###COMPONENT###_DASHBOARD_'.###Component###Helper::safeString($name,'U').'_'.###Component###Helper::safeString($action,'U'); - break; - } - } - else - { - $viewName = $name; - $alt = $name; - $url = 'index.php?option=com_###component###&view='.$name; - $image = $name.'.'.$type; - $name = 'COM_###COMPONENT###_DASHBOARD_'.###Component###Helper::safeString($name,'U'); - $hover = false; + case 'add': + $url = 'index.php?option=com_###component###&view='.$name.'&layout=edit'; + $image = $name.'_'.$action.'.'.$type; + $alt = $name.' '.$action; + $name = 'COM_###COMPONENT###_DASHBOARD_'.###Component###Helper::safeString($name,'U').'_ADD'; + $add = true; + break; + default: + $url = 'index.php?option=com_categories&view=categories&extension=com_###component###.'.$name; + $image = $name.'_'.$action.'.'.$type; + $alt = $name.' '.$action; + $name = 'COM_###COMPONENT###_DASHBOARD_'.###Component###Helper::safeString($name,'U').'_'.###Component###Helper::safeString($action,'U'); + break; } + } + else + { + $viewName = $name; + $alt = $name; + $url = 'index.php?option=com_###component###&view='.$name; + $image = $name.'.'.$type; + $name = 'COM_###COMPONENT###_DASHBOARD_'.###Component###Helper::safeString($name,'U'); + $hover = false; + } } else { @@ -149,7 +165,7 @@ class ###Component###Model###Component### extends JModelList // check access if($user->authorise($accessAdd, 'com_###component###') && $user->authorise($accessTo, 'com_###component###') && $dashboard_add) { - $icons[$group][$i] = new StdClass; + $icons[$group][$i] = new StdClass; $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; @@ -161,7 +177,7 @@ class ###Component###Model###Component### extends JModelList // check access if($user->authorise($accessTo, 'com_###component###') && $dashboard_list) { - $icons[$group][$i] = new StdClass; + $icons[$group][$i] = new StdClass; $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; @@ -173,7 +189,7 @@ class ###Component###Model###Component### extends JModelList // check access if($user->authorise($accessAdd, 'com_###component###') && $dashboard_add) { - $icons[$group][$i] = new StdClass; + $icons[$group][$i] = new StdClass; $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; @@ -182,7 +198,7 @@ class ###Component###Model###Component### extends JModelList } else { - $icons[$group][$i] = new StdClass; + $icons[$group][$i] = new StdClass; $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; @@ -191,7 +207,7 @@ class ###Component###Model###Component### extends JModelList } else { - $icons[$group][$i] = new StdClass; + $icons[$group][$i] = new StdClass; $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; diff --git a/admin/compiler/joomla_3/JControllerLegacy.php b/admin/compiler/joomla_3/JControllerLegacy.php index a94d8357b..96a5e8685 100644 --- a/admin/compiler/joomla_3/JControllerLegacy.php +++ b/admin/compiler/joomla_3/JControllerLegacy.php @@ -88,18 +88,22 @@ class ###Component###Controller extends JControllerLegacy protected function getViewRelation($view) { + // check the we have a value if (###Component###Helper::checkString($view)) { + // the view relationships $views = array(###VIEWARRAY### ); // check if this is a list view - if (in_array($view,$views)) + if (in_array($view, $views)) { + // this is a list view return array('edit' => false, 'view' => array_search($view,$views), 'views' => $view); } // check if it is an edit view - elseif (array_key_exists($view,$views)) + elseif (array_key_exists($view, $views)) { + // this is a edit view return array('edit' => true, 'view' => $view, 'views' => $views[$view]); } } diff --git a/admin/controller.php b/admin/controller.php index 2a95e81fe..94c1b24f3 100644 --- a/admin/controller.php +++ b/admin/controller.php @@ -85,8 +85,10 @@ class ComponentbuilderController extends JControllerLegacy protected function getViewRelation($view) { + // check the we have a value if (ComponentbuilderHelper::checkString($view)) { + // the view relationships $views = array( 'joomla_component' => 'joomla_components', 'admin_view' => 'admin_views', @@ -120,13 +122,15 @@ class ComponentbuilderController extends JControllerLegacy 'library_files_folders_urls' => 'libraries_files_folders_urls' ); // check if this is a list view - if (in_array($view,$views)) + if (in_array($view, $views)) { + // this is a list view return array('edit' => false, 'view' => array_search($view,$views), 'views' => $view); } // check if it is an edit view - elseif (array_key_exists($view,$views)) + elseif (array_key_exists($view, $views)) { + // this is a edit view return array('edit' => true, 'view' => $view, 'views' => $views[$view]); } } diff --git a/admin/helpers/compiler.php b/admin/helpers/compiler.php index 6254b8058..05f49fc4e 100644 --- a/admin/helpers/compiler.php +++ b/admin/helpers/compiler.php @@ -183,7 +183,9 @@ class Compiler extends Infusion // the correct string $externalCodeString = ($externalCount == 1) ? JText::_('code/string') : JText::_('code/strings'); // the notice + $this->app->enqueueMessage(JText::_('

External Code Notice

'), 'Notice'); $this->app->enqueueMessage(JText::sprintf('There has been %s - %s added to this component as EXTERNALCODE. To avoid shipping your component with malicious %s always make sure that the correct code/string values were used.', $externalCount, $externalCodeString, $externalCodeString), 'Notice'); + $this->app->enqueueMessage('
', 'Notice'); } // end the timer here $this->time_end = microtime(true); diff --git a/admin/helpers/compiler/a_Get.php b/admin/helpers/compiler/a_Get.php index 35de9b301..18e8363a1 100644 --- a/admin/helpers/compiler/a_Get.php +++ b/admin/helpers/compiler/a_Get.php @@ -3713,7 +3713,9 @@ class Get // set key $key = '[EXTERNA'.'LCODE='.$target.']'; // set the notice + $this->app->enqueueMessage(JText::_('

External Code Warning

'), 'Warning'); $this->app->enqueueMessage(JText::sprintf('The %s is not a valid url/path!', $key), 'Warning'); + $this->app->enqueueMessage('
', 'Warning'); // remove the placeholder $bucket[$key] = ''; } @@ -3765,7 +3767,9 @@ class Get // update local hash $this->db->updateObject('#__componentbuilder_external_code', $object, 'target'); // give notice of the change + $this->app->enqueueMessage(JText::_('

External Code Warning

'), 'Warning'); $this->app->enqueueMessage(JText::sprintf('The code/string from %s has been changed since the last compilation, please investigate to insure the changes are safe!', $key), 'Warning'); + $this->app->enqueueMessage('
', 'Warning'); } } else @@ -3777,13 +3781,17 @@ class Get // insert local hash $this->db->insertObject('#__componentbuilder_external_code', $object); // give notice the first time this is added + $this->app->enqueueMessage(JText::_('

External Code Notice

'), 'Notice'); $this->app->enqueueMessage(JText::sprintf('The code/string from %s has been added for the first time, please investigate to insure the correct code/string was used!', $key), 'Notice'); + $this->app->enqueueMessage('
', 'Notice'); } } else { // set notice that we could not get a valid string from the target + $this->app->enqueueMessage(JText::_('

External Code Warning

'), 'Warning'); $this->app->enqueueMessage(JText::sprintf('The %s returned an invalid string!', $key), 'Warning'); + $this->app->enqueueMessage('
', 'Warning'); } } // add to local bucket diff --git a/admin/helpers/compiler/e_Interpretation.php b/admin/helpers/compiler/e_Interpretation.php index 77fe0eb84..3898f0b1f 100644 --- a/admin/helpers/compiler/e_Interpretation.php +++ b/admin/helpers/compiler/e_Interpretation.php @@ -12356,69 +12356,80 @@ class Interpretation extends Fields $nameUpper = ComponentbuilderHelper::safeString($menu['name_code'], 'U'); if (isset($menu['dashboard_list']) && $menu['dashboard_list'] == 1 && $view['adminview'] == $menu['before']) { - if (isset($menu['link']) && ComponentbuilderHelper::checkString($menu['link'])) + $type = ComponentbuilderHelper::imageInfo('images/' . $menu['icon']); + if ($type) { - // TODO must look at adding custom links to icons aswell - return ''; + // icon builder loader + $this->iconBuilder[$type .".". $nameList] = 'images/' . $menu['icon']; } else { - $type = ComponentbuilderHelper::imageInfo('images/' . $menu['icon']); - if ($type) - { - $type = $type . "."; - // icon builder loader - $this->iconBuilder[$type . $nameList] = 'images/' . $menu['icon']; - } - else - { - $type = 'png.'; - } - // build lang - $langName = $menu['name'] . '

'; - $langKey = $this->langPrefix . '_DASHBOARD_' . $nameUpper; - // add to lang - $this->langContent[$this->lang][$langKey] = $langName; + $type = 'png'; + } + // build lang + $langName = $menu['name'] . '

'; + $langKey = $this->langPrefix . '_DASHBOARD_' . $nameUpper; + // add to lang + $this->langContent[$this->lang][$langKey] = $langName; + + // if this is a link build the icon values with pipe + if (isset($menu['link']) && ComponentbuilderHelper::checkString($menu['link'])) + { // set icon if ($counter == 0) { $counter++; - $icon .= "'" . $type . $nameList . "'"; + $icon .= "'".$type."||".$nameList."||".$menu['link']."'"; } else { $counter++; - $icon .= ", '" . $type . $nameList . "'"; + $icon .= ", '".$type."||".$nameList."||".$menu['link']."'"; + } + } + else + { + // set icon + if ($counter == 0) + { + $counter++; + $icon .= "'" . $type .".". $nameList . "'"; + } + else + { + $counter++; + $icon .= ", '" . $type .".". $nameList . "'"; } } } elseif (isset($menu['dashboard_list']) && $menu['dashboard_list'] == 1 && empty($menu['before'])) { - if (isset($menu['link']) && ComponentbuilderHelper::checkString($menu['link'])) + $type = ComponentbuilderHelper::imageInfo('images/' . $menu['icon']); + if ($type) { - // TODO must look at adding custom links to icons aswell - return ''; + // icon builder loader + $this->iconBuilder[$type .".". $nameList] = 'images/' . $menu['icon']; } else { - $type = ComponentbuilderHelper::imageInfo('images/' . $menu['icon']); - if ($type) - { - $type = $type . "."; - // icon builder loader - $this->iconBuilder[$type . $nameList] = 'images/' . $menu['icon']; - } - else - { - $type = 'png.'; - } - // build lang - $langName = $menu['name'] . '

'; - $langKey = $this->langPrefix . '_DASHBOARD_' . $nameUpper; - // add to lang - $this->langContent[$this->lang][$langKey] = $langName; + $type = 'png'; + } + // build lang + $langName = $menu['name'] . '

'; + $langKey = $this->langPrefix . '_DASHBOARD_' . $nameUpper; + // add to lang + $this->langContent[$this->lang][$langKey] = $langName; + + // if this is a link build the icon values with pipe + if (isset($menu['link']) && ComponentbuilderHelper::checkString($menu['link'])) + { // set icon - $this->lastCustomDashboardIcon[$nr] = ", '" . $type . $nameList . "'"; + $this->lastCustomDashboardIcon[$nr] = ", '".$type."||".$nameList."||".$menu['link']."'"; + } + else + { + // set icon + $this->lastCustomDashboardIcon[$nr] = ", '" . $type .".". $nameList . "'"; } } } diff --git a/admin/models/componentbuilder.php b/admin/models/componentbuilder.php index f87531edd..910bb317a 100644 --- a/admin/models/componentbuilder.php +++ b/admin/models/componentbuilder.php @@ -176,6 +176,7 @@ class ComponentbuilderModelComponentbuilder extends JModelList 'library_files_folders_urls.create' => 'library_files_folders_urls.create', 'libraries_files_folders_urls.access' => 'library_files_folders_urls.access', 'library_files_folders_urls.access' => 'library_files_folders_urls.access'); + // loop over the $views foreach($viewGroups as $group => $views) { $i = 0; @@ -184,47 +185,62 @@ class ComponentbuilderModelComponentbuilder extends JModelList foreach($views as $view) { $add = false; - if (strpos($view,'.') !== false) + // external views (links) + if (strpos($view,'||') !== false) { - $dwd = explode('.', $view); - if (count($dwd) == 3) + $dwd = explode('||', $view); + if (count($dwd) == 3) + { + list($type, $name, $url) = $dwd; + $viewName = $name; + $alt = $name; + $url = $url; + $image = $name.'.'.$type; + $name = 'COM_COMPONENTBUILDER_DASHBOARD_'.ComponentbuilderHelper::safeString($name,'U'); + } + } + // internal views + elseif (strpos($view,'.') !== false) + { + $dwd = explode('.', $view); + if (count($dwd) == 3) + { + list($type, $name, $action) = $dwd; + } + elseif (count($dwd) == 2) + { + list($type, $name) = $dwd; + $action = false; + } + if ($action) + { + $viewName = $name; + switch($action) { - list($type, $name, $action) = $dwd; - } - elseif (count($dwd) == 2) - { - list($type, $name) = $dwd; - $action = false; - } - if ($action) - { - $viewName = $name; - switch($action) - { - case 'add': - $url ='index.php?option=com_componentbuilder&view='.$name.'&layout=edit'; - $image = $name.'_'.$action.'.'.$type; - $alt = $name.' '.$action; - $name = 'COM_COMPONENTBUILDER_DASHBOARD_'.ComponentbuilderHelper::safeString($name,'U').'_ADD'; - $add = true; - break; - default: - $url = 'index.php?option=com_categories&view=categories&extension=com_componentbuilder.'.$name; - $image = $name.'_'.$action.'.'.$type; - $alt = $name.' '.$action; - $name = 'COM_COMPONENTBUILDER_DASHBOARD_'.ComponentbuilderHelper::safeString($name,'U').'_'.ComponentbuilderHelper::safeString($action,'U'); - break; - } - } - else - { - $viewName = $name; - $alt = $name; - $url = 'index.php?option=com_componentbuilder&view='.$name; - $image = $name.'.'.$type; - $name = 'COM_COMPONENTBUILDER_DASHBOARD_'.ComponentbuilderHelper::safeString($name,'U'); - $hover = false; + case 'add': + $url = 'index.php?option=com_componentbuilder&view='.$name.'&layout=edit'; + $image = $name.'_'.$action.'.'.$type; + $alt = $name.' '.$action; + $name = 'COM_COMPONENTBUILDER_DASHBOARD_'.ComponentbuilderHelper::safeString($name,'U').'_ADD'; + $add = true; + break; + default: + $url = 'index.php?option=com_categories&view=categories&extension=com_componentbuilder.'.$name; + $image = $name.'_'.$action.'.'.$type; + $alt = $name.' '.$action; + $name = 'COM_COMPONENTBUILDER_DASHBOARD_'.ComponentbuilderHelper::safeString($name,'U').'_'.ComponentbuilderHelper::safeString($action,'U'); + break; } + } + else + { + $viewName = $name; + $alt = $name; + $url = 'index.php?option=com_componentbuilder&view='.$name; + $image = $name.'.'.$type; + $name = 'COM_COMPONENTBUILDER_DASHBOARD_'.ComponentbuilderHelper::safeString($name,'U'); + $hover = false; + } } else { @@ -277,7 +293,7 @@ class ComponentbuilderModelComponentbuilder extends JModelList // check access if($user->authorise($accessAdd, 'com_componentbuilder') && $user->authorise($accessTo, 'com_componentbuilder') && $dashboard_add) { - $icons[$group][$i] = new StdClass; + $icons[$group][$i] = new StdClass; $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; @@ -289,7 +305,7 @@ class ComponentbuilderModelComponentbuilder extends JModelList // check access if($user->authorise($accessTo, 'com_componentbuilder') && $dashboard_list) { - $icons[$group][$i] = new StdClass; + $icons[$group][$i] = new StdClass; $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; @@ -301,7 +317,7 @@ class ComponentbuilderModelComponentbuilder extends JModelList // check access if($user->authorise($accessAdd, 'com_componentbuilder') && $dashboard_add) { - $icons[$group][$i] = new StdClass; + $icons[$group][$i] = new StdClass; $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; @@ -310,7 +326,7 @@ class ComponentbuilderModelComponentbuilder extends JModelList } else { - $icons[$group][$i] = new StdClass; + $icons[$group][$i] = new StdClass; $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; @@ -319,7 +335,7 @@ class ComponentbuilderModelComponentbuilder extends JModelList } else { - $icons[$group][$i] = new StdClass; + $icons[$group][$i] = new StdClass; $icons[$group][$i]->url = $url; $icons[$group][$i]->name = $name; $icons[$group][$i]->image = $image; diff --git a/componentbuilder.xml b/componentbuilder.xml index b7c7b92aa..437faf01c 100644 --- a/componentbuilder.xml +++ b/componentbuilder.xml @@ -1,7 +1,7 @@ COM_COMPONENTBUILDER - 3rd March, 2018 + 5th March, 2018 Llewellyn van der Merwe llewellyn@joomlacomponentbuilder.com http://joomlacomponentbuilder.com