diff --git a/README.md b/README.md index e7e1a4c4a..cc5cc1669 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ The Component Builder for [Joomla](https://extensions.joomla.org/extension/compo Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will safe you lots of time and money. A real must have! -You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.9.0) with **ALL** its features and **ALL** concepts totally open-source and free! +You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.9.1) with **ALL** its features and **ALL** concepts totally open-source and free! > Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45) @@ -125,11 +125,11 @@ Watch the [proposed development workflow](https://vdm.bz/proposed-development-wo + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 14th September, 2018 -+ *Version*: 2.9.0 ++ *Last Build*: 19th September, 2018 ++ *Version*: 2.9.1 + *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **193091** ++ *Line count*: **193291** + *Field count*: **1081** + *File count*: **1273** + *Folder count*: **201** diff --git a/admin/README.txt b/admin/README.txt index e7e1a4c4a..cc5cc1669 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -9,7 +9,7 @@ The Component Builder for [Joomla](https://extensions.joomla.org/extension/compo Whether you're a seasoned [Joomla](https://extensions.joomla.org/extension/component-builder/) developer, or have just started, Component Builder will safe you lots of time and money. A real must have! -You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.9.0) with **ALL** its features and **ALL** concepts totally open-source and free! +You can install it quite easily and with no limitations. On [github](https://github.com/vdm-io/Joomla-Component-Builder/releases) is the latest release (2.9.1) with **ALL** its features and **ALL** concepts totally open-source and free! > Watch Quick Build of a Hello World component in [JCB on Youtube](https://www.youtube.com/watch?v=IQfsLYIeblk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=45) @@ -125,11 +125,11 @@ Watch the [proposed development workflow](https://vdm.bz/proposed-development-wo + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 14th September, 2018 -+ *Version*: 2.9.0 ++ *Last Build*: 19th September, 2018 ++ *Version*: 2.9.1 + *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **193091** ++ *Line count*: **193291** + *Field count*: **1081** + *File count*: **1273** + *Folder count*: **201** diff --git a/admin/compiler/joomla_3/Helper.php b/admin/compiler/joomla_3/Helper.php index cc78071d2..2913f37da 100644 --- a/admin/compiler/joomla_3/Helper.php +++ b/admin/compiler/joomla_3/Helper.php @@ -303,14 +303,16 @@ abstract class ###Component###Helper /** * Get the action permissions * - * @param string $view The related view name - * @param int $record The item to act upon - * @param string $views The related list view name + * @param string $view The related view name + * @param int $record The item to act upon + * @param string $views The related list view name + * @param mixed $target Only get this permission (like edit, create, delete) + * @param string $component The target component * * @return object The JObject of permission/authorised actions * **/ - public static function getActions($view, &$record = null, $views = null) + public static function getActions($view, &$record = null, $views = null, $target = null, $component = '###component###') { // get the user object $user = JFactory::getUser(); @@ -324,7 +326,7 @@ abstract class ###Component###Helper } // get all actions from component $actions = JAccess::getActionsFromFile( - JPATH_ADMINISTRATOR . '/components/com_###component###/access.xml', + JPATH_ADMINISTRATOR . '/components/com_' . $component . '/access.xml', "/access/section[@name='component']/" ); // if non found then return empty JObject @@ -335,13 +337,33 @@ abstract class ###Component###Helper // get created by if not found if (self::checkObject($record) && !isset($record->created_by) && isset($record->id)) { - $record->created_by = self::getVar($view, 'id', $record->id, 'created_by'); + $record->created_by = self::getVar($view, $record->id, 'id', 'created_by', '=', $component); } // set actions only set in component settings $componentActions = array('core.admin', 'core.manage', 'core.options', 'core.export'); + // check if we have a target + $checkTarget = false; + if ($target) + { + // convert to an array + if (self::checkString($target)) + { + $target = array($target); + } + // check if we are good to go + if (self::checkArray($target)) + { + $checkTarget = true; + } + } // loop the actions and set the permissions foreach ($actions as $action) { + // check target action filter + if ($checkTarget && self::filterActions($view, $action->name, $target)) + { + continue; + } // set to use component default $fallback = true; // reset permission per/action @@ -356,7 +378,7 @@ abstract class ###Component###Helper // we are in item $area = 'item'; // The record has been set. Check the record permissions. - $permission = $user->authorise($action->name, 'com_###component###.' . $view . '.' . (int) $record->id); + $permission = $user->authorise($action->name, 'com_' . $component . '.' . $view . '.' . (int) $record->id); // if no permission found, check edit own if (!$permission) { @@ -366,8 +388,8 @@ abstract class ###Component###Helper // the correct target $coreCheck = (array) explode('.', $action->name); // check that we have both local and global access - if ($user->authorise($coreCheck[0] . '.edit.own', 'com_###component###.' . $view . '.' . (int) $record->id) && - $user->authorise($coreCheck[0] . '.edit.own', 'com_###component###')) + if ($user->authorise($coreCheck[0] . '.edit.own', 'com_' . $component . '.' . $view . '.' . (int) $record->id) && + $user->authorise($coreCheck[0] . '.edit.own', 'com_' . $component)) { // allow edit $result->set($action->name, true); @@ -401,15 +423,15 @@ abstract class ###Component###Helper $categoryCheck = $action->name; } // The record has a category. Check the category permissions. - $catpermission = $user->authorise($categoryCheck, 'com_###component###.' . $views . '.category.' . (int) $record->catid); + $catpermission = $user->authorise($categoryCheck, 'com_' . $component . '.' . $views . '.category.' . (int) $record->catid); if (!$catpermission && !is_null($catpermission)) { // With edit, if the created_by matches current user then dig deeper. if (($action->name === 'core.edit' || $action->name === $view . '.edit') && $record->created_by > 0 && ($record->created_by == $user->id)) { // check that we have both local and global access - if ($user->authorise('core.edit.own', 'com_###component###.' . $views . '.category.' . (int) $record->catid) && - $user->authorise($core . '.edit.own', 'com_###component###')) + if ($user->authorise('core.edit.own', 'com_' . $component . '.' . $views . '.category.' . (int) $record->catid) && + $user->authorise($core . '.edit.own', 'com_' . $component)) { // allow edit $result->set($action->name, true); @@ -441,13 +463,36 @@ abstract class ###Component###Helper // Since items are created by users and global permissions is set by system admin. else { - $result->set($action->name, $user->authorise($action->name, 'com_###component###')); + $result->set($action->name, $user->authorise($action->name, 'com_' . $component)); } } } return $result; } + /** + * Filter the action permissions + * + * @param string $action The action to check + * @param array $targets The array of target actions + * + * @return boolean true if action should be filtered out + * + **/ + protected static function filterActions(&$view, &$action, &$targets) + { + foreach ($targets as $target) + { + if (strpos($action, $view . '.' . $target) !== false || + strpos($action, 'core.' . $target) !== false) + { + return false; + break; + } + } + return true; + } + /** * Get any component's model **/ diff --git a/admin/compiler/joomla_3/Helper_site.php b/admin/compiler/joomla_3/Helper_site.php index 35765eb54..db1f8c8f1 100644 --- a/admin/compiler/joomla_3/Helper_site.php +++ b/admin/compiler/joomla_3/Helper_site.php @@ -618,14 +618,16 @@ abstract class ###Component###Helper /** * Get the action permissions * - * @param string $view The related view name - * @param int $record The item to act upon - * @param string $views The related list view name + * @param string $view The related view name + * @param int $record The item to act upon + * @param string $views The related list view name + * @param mixed $target Only get this permission (like edit, create, delete) + * @param string $component The target component * * @return object The JObject of permission/authorised actions * **/ - public static function getActions($view, &$record = null, $views = null) + public static function getActions($view, &$record = null, $views = null, $target = null, $component = '###component###') { // get the user object $user = JFactory::getUser(); @@ -639,7 +641,7 @@ abstract class ###Component###Helper } // get all actions from component $actions = JAccess::getActionsFromFile( - JPATH_ADMINISTRATOR . '/components/com_###component###/access.xml', + JPATH_ADMINISTRATOR . '/components/com_' . $component . '/access.xml', "/access/section[@name='component']/" ); // if non found then return empty JObject @@ -650,13 +652,33 @@ abstract class ###Component###Helper // get created by if not found if (self::checkObject($record) && !isset($record->created_by) && isset($record->id)) { - $record->created_by = self::getVar($view, 'id', $record->id, 'created_by'); + $record->created_by = self::getVar($view, $record->id, 'id', 'created_by', '=', $component); } // set actions only set in component settings $componentActions = array('core.admin', 'core.manage', 'core.options', 'core.export'); + // check if we have a target + $checkTarget = false; + if ($target) + { + // convert to an array + if (self::checkString($target)) + { + $target = array($target); + } + // check if we are good to go + if (self::checkArray($target)) + { + $checkTarget = true; + } + } // loop the actions and set the permissions foreach ($actions as $action) { + // check target action filter + if ($checkTarget && self::filterActions($view, $action->name, $target)) + { + continue; + } // set to use component default $fallback = true; // reset permission per/action @@ -671,7 +693,7 @@ abstract class ###Component###Helper // we are in item $area = 'item'; // The record has been set. Check the record permissions. - $permission = $user->authorise($action->name, 'com_###component###.' . $view . '.' . (int) $record->id); + $permission = $user->authorise($action->name, 'com_' . $component . '.' . $view . '.' . (int) $record->id); // if no permission found, check edit own if (!$permission) { @@ -681,8 +703,8 @@ abstract class ###Component###Helper // the correct target $coreCheck = (array) explode('.', $action->name); // check that we have both local and global access - if ($user->authorise($coreCheck[0] . '.edit.own', 'com_###component###.' . $view . '.' . (int) $record->id) && - $user->authorise($coreCheck[0] . '.edit.own', 'com_###component###')) + if ($user->authorise($coreCheck[0] . '.edit.own', 'com_' . $component . '.' . $view . '.' . (int) $record->id) && + $user->authorise($coreCheck[0] . '.edit.own', 'com_' . $component)) { // allow edit $result->set($action->name, true); @@ -716,15 +738,15 @@ abstract class ###Component###Helper $categoryCheck = $action->name; } // The record has a category. Check the category permissions. - $catpermission = $user->authorise($categoryCheck, 'com_###component###.' . $views . '.category.' . (int) $record->catid); + $catpermission = $user->authorise($categoryCheck, 'com_' . $component . '.' . $views . '.category.' . (int) $record->catid); if (!$catpermission && !is_null($catpermission)) { // With edit, if the created_by matches current user then dig deeper. if (($action->name === 'core.edit' || $action->name === $view . '.edit') && $record->created_by > 0 && ($record->created_by == $user->id)) { // check that we have both local and global access - if ($user->authorise('core.edit.own', 'com_###component###.' . $views . '.category.' . (int) $record->catid) && - $user->authorise($core . '.edit.own', 'com_###component###')) + if ($user->authorise('core.edit.own', 'com_' . $component . '.' . $views . '.category.' . (int) $record->catid) && + $user->authorise($core . '.edit.own', 'com_' . $component)) { // allow edit $result->set($action->name, true); @@ -756,13 +778,36 @@ abstract class ###Component###Helper // Since items are created by users and global permissions is set by system admin. else { - $result->set($action->name, $user->authorise($action->name, 'com_###component###')); + $result->set($action->name, $user->authorise($action->name, 'com_' . $component)); } } } return $result; } + /** + * Filter the action permissions + * + * @param string $action The action to check + * @param array $targets The array of target actions + * + * @return boolean true if action should be filtered out + * + **/ + protected static function filterActions(&$view, &$action, &$targets) + { + foreach ($targets as $target) + { + if (strpos($action, $view . '.' . $target) !== false || + strpos($action, 'core.' . $target) !== false) + { + return false; + break; + } + } + return true; + } + /** * Check if have an json string * diff --git a/admin/compiler/joomla_3/JViewLegacy_edit.php b/admin/compiler/joomla_3/JViewLegacy_edit.php index d73bc3f1a..f89163c04 100644 --- a/admin/compiler/joomla_3/JViewLegacy_edit.php +++ b/admin/compiler/joomla_3/JViewLegacy_edit.php @@ -28,13 +28,15 @@ class ###Component###View###View### extends JViewLegacy */ public function display($tpl = null) { + // set params + $this->params = JComponentHelper::getParams('com_###component###'); // Assign the variables $this->form = $this->get('Form'); $this->item = $this->get('Item'); $this->script = $this->get('Script'); $this->state = $this->get('State'); // get action permissions - $this->canDo = ###Component###Helper::getActions('###view###',$this->item); + $this->canDo = ###Component###Helper::getActions('###view###', $this->item); // get input $jinput = JFactory::getApplication()->input; $this->ref = $jinput->get('ref', 0, 'word'); diff --git a/admin/compiler/joomla_3/JViewLegacy_edit_site.php b/admin/compiler/joomla_3/JViewLegacy_edit_site.php index b86f135e9..40fb90d8c 100644 --- a/admin/compiler/joomla_3/JViewLegacy_edit_site.php +++ b/admin/compiler/joomla_3/JViewLegacy_edit_site.php @@ -28,13 +28,15 @@ class ###Component###View###View### extends JViewLegacy */ public function display($tpl = null) { + // set params + $this->params = JComponentHelper::getParams('com_###component###'); // Assign the variables $this->form = $this->get('Form'); $this->item = $this->get('Item'); $this->script = $this->get('Script'); $this->state = $this->get('State'); // get action permissions - $this->canDo = ###Component###Helper::getActions('###view###',$this->item); + $this->canDo = ###Component###Helper::getActions('###view###', $this->item); // get input $jinput = JFactory::getApplication()->input; $this->ref = $jinput->get('ref', 0, 'word'); @@ -119,7 +121,7 @@ class ###Component###View###View### extends JViewLegacy $this->document = JFactory::getDocument(); } $this->document->setTitle(JText::_($isNew ? 'COM_###COMPONENT###_###VIEW###_NEW' : 'COM_###COMPONENT###_###VIEW###_EDIT')); - // we need this to fix the form display + // we need this to fix the form display (TODO) $this->document->addStyleSheet(JURI::root()."administrator/templates/isis/css/template.css", (###Component###Helper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/css'); $this->document->addScript(JURI::root()."administrator/templates/isis/js/template.js", (###Component###Helper::jVersion()->isCompatible('3.8.0')) ? array('version' => 'auto') : 'text/javascript'); // the default style of this view diff --git a/admin/compiler/joomla_3/edit.php b/admin/compiler/joomla_3/edit.php index 4a75fecb3..8e87bf81a 100644 --- a/admin/compiler/joomla_3/edit.php +++ b/admin/compiler/joomla_3/edit.php @@ -22,7 +22,7 @@ JHtml::_('behavior.tooltip'); JHtml::_('behavior.formvalidation'); JHtml::_('formbehavior.chosen', 'select'); JHtml::_('behavior.keepalive'); -$componentParams = JComponentHelper::getParams('com_###component###'); +$componentParams = $this->params; // will be removed just use $this->params instead ?> ###EDITBODYFADEIN###