From 095cc2857cb12760ed175a6d6cfbba2728b00ba0 Mon Sep 17 00:00:00 2001 From: Fabian Date: Tue, 19 May 2015 00:32:31 +0100 Subject: [PATCH 1/3] symphony v6.2 fixing, no complete --- content/content.index.php | 4 ++-- extension.driver.php | 32 +++++++++++++++----------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/content/content.index.php b/content/content.index.php index 71b033f..355a2b5 100644 --- a/content/content.index.php +++ b/content/content.index.php @@ -21,7 +21,7 @@ function __construct(){ */ public function build($context) { - if(Administration::instance()->Author->isDeveloper()) { + // if(Administration::instance()->Author->isDeveloper()) { if($_POST['with-selected'] == 'delete' && is_array($_POST['items'])) { foreach($_POST['items'] as $id_role => $value) @@ -30,7 +30,7 @@ public function build($context) } } parent::build($context); - } + //} } /** diff --git a/extension.driver.php b/extension.driver.php index b521cba..90c9abe 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -79,7 +79,7 @@ public function fetchNavigation() { public function extendNavigation($context) { $data = $this->getCurrentAuthorRoleData(); - if($data == false || Administration::instance()->Author->isDeveloper()) { + if($data == false || Administration::Author()->isDeveloper()) { return; } @@ -153,7 +153,7 @@ public function deleteAuthorRole($context) { * The context, providing the form and the author object */ public function addRolePicker($context) { - if(Administration::instance()->Author->isDeveloper()) { + // if(Administration::instance()->Author->isDeveloper()) { $group = new XMLElement('fieldset'); $group->setAttribute('class', 'settings'); $group->appendChild(new XMLElement('legend', __('Author Role'))); @@ -191,7 +191,7 @@ public function addRolePicker($context) { $i++; } - } + //} } /** @@ -230,9 +230,11 @@ public function checkCallback($context) { * @return mixed */ private function adjustIndex($context, $callback) { + $data = $this->getCurrentAuthorRoleData(); - if($data == false || Administration::instance()->Author->isDeveloper()) { + //print_r($data); + if($data == false || Administration::Author()->isDeveloper()) { return; } @@ -427,8 +429,8 @@ private function adjustIndex($context, $callback) { */ public function makePreAdjustements($context) { $data = $this->getCurrentAuthorRoleData(); - - if($data == false || Administration::instance()->Author->isDeveloper()) { + //print_r(Administration::Author()); + if($data == false || Administration::Author()->isDeveloper()) { return; } @@ -492,10 +494,7 @@ private static function replaceChild($parent, $child) { */ private function adjustEntryEditor($context, $callback) { $data = $this->getCurrentAuthorRoleData(); - - if($data == false || Administration::instance()->Author->isDeveloper()) { - return; - } + if($data == false) return; // Set the hidden fields: $hiddenFields = array(); @@ -580,9 +579,8 @@ private function adjustEntryEditor($context, $callback) { */ private function getCurrentAuthorRoleData() { if(Administration::instance()->isLoggedIn()) { - $id_author = Administration::instance()->Author->get('id'); + $id_author = Administration::Author()->get('id'); $id_role = $this->getAuthorRole($id_author); - if($id_role != false) { $data = $this->getData($id_role); return $data; @@ -601,7 +599,7 @@ private function getCurrentAuthorRoleData() { public function modifyAreas($context) { $data = $this->getCurrentAuthorRoleData(); - if($data == false || Administration::instance()->Author->isDeveloper()) { + if($data == false || Administration::Author()->isDeveloper()) { return; } @@ -622,7 +620,7 @@ public function modifyAreas($context) { * The context */ public function saveAuthorRole($context) { - if(Administration::instance()->Author->isDeveloper()) { + // if(Administration::instance()->Author->isDeveloper()) { //FIX $id_role = intval($_POST['fields']['role']); $id_author = $context['author']->get('id'); @@ -638,7 +636,7 @@ public function saveAuthorRole($context) { // Insert new role: Symphony::Database()->insert(array('id_role'=>$id_role, 'id_author'=>$id_author), 'tbl_author_roles_authors'); } - } + //} } /** @@ -882,8 +880,8 @@ public function install() { Symphony::Database()->query(" CREATE TABLE IF NOT EXISTS `tbl_author_roles_fields` ( `id` INT(11) unsigned NOT NULL auto_increment, - `id_role` INT(255) unsigned NOT NULL, - `id_field` INT(255) unsigned NOT NULL, + `id_role` INT(255) unsigned NOT NULL, + `id_field` INT(255) unsigned NOT NULL, `hidden` TINYINT(1) unsigned NOT NULL, PRIMARY KEY (`id`), KEY `id_role` (`id_role`), From 7cea000d6baae691edb83cd188b29868cb0511d9 Mon Sep 17 00:00:00 2001 From: Fabian Romero Date: Tue, 19 May 2015 15:03:39 +0100 Subject: [PATCH 2/3] Fixing and working --- extension.driver.php | 76 +++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/extension.driver.php b/extension.driver.php index 90c9abe..3412351 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -201,7 +201,6 @@ public function addRolePicker($context) { */ public function checkCallback($context) { $callback = Symphony::Engine()->getPageCallback(); - // Perform an action according to the callback: switch($callback['driver']) { case 'publish' : @@ -233,8 +232,7 @@ private function adjustIndex($context, $callback) { $data = $this->getCurrentAuthorRoleData(); - //print_r($data); - if($data == false || Administration::Author()->isDeveloper()) { + if($data == false || Administration::Author()->isDeveloper()) { return; } @@ -265,10 +263,11 @@ private function adjustIndex($context, $callback) { } } + if($rules['own_entries'] == 1 || $rules['edit'] == 0 || $rules['delete'] == 0 || $rules['use_filter'] == 1) { // For only show entries created by this author: // Get a list of entry id's created by this author: - $id_author = Administration::instance()->Author->get('id'); + $id_author = Administration::Author()->get('id'); if($rules['own_entries'] == 1) { // Only get the ID's of the current author to begin with: @@ -369,30 +368,33 @@ private function adjustIndex($context, $callback) { $child = self::findChildren($formChild,'select'); $child = $child[0]; - $newSelect = new XMLElement('select', null, $child->getAttributes()); + $children=($child)?$child->getAttributes():array(); + $newSelect = new XMLElement('select', null, $children); - foreach($child->getChildren() as $selectChild) { + foreach($children as $selectChild) { // See if delete is allowed: - if($selectChild->getAttribute('value') == 'delete' && $rules['delete'] == 1) { - $newSelect->appendChild($selectChild); - } - elseif($selectChild->getName() == 'optgroup' && $rules['edit'] == 1) { - // Check if the field that is edited is not a hidden field, because then editing is not allowed: - $optGroupChildren = $selectChild->getChildren(); - - if(!empty($optGroupChildren)) { - $value = $optGroupChildren[0]->getAttribute('value'); - - $a = explode('-', str_replace('toggle-', '', $value)); - - if(!in_array($a[0], $hiddenFields)) { - $newSelect->appendChild($selectChild); - } - } - } - elseif($selectChild->getName() == 'option' && $selectChild->getAttribute('value') != 'delete' && ($rules['edit'] == 1 || $rules['delete'] == 1)) { - $newSelect->appendChild($selectChild); - } + if(is_object($selectChild)){ + if( $selectChild->getAttribute('value') == 'delete' && $rules['delete'] == 1) { + $newSelect->appendChild($selectChild); + } + elseif($selectChild->getName() == 'optgroup' && $rules['edit'] == 1) { + // Check if the field that is edited is not a hidden field, because then editing is not allowed: + $optGroupChildren = $selectChild->getChildren(); + + if(!empty($optGroupChildren)) { + $value = $optGroupChildren[0]->getAttribute('value'); + + $a = explode('-', str_replace('toggle-', '', $value)); + + if(!in_array($a[0], $hiddenFields)) { + $newSelect->appendChild($selectChild); + } + } + } + elseif($selectChild->getName() == 'option' && $selectChild->getAttribute('value') != 'delete' && ($rules['edit'] == 1 || $rules['delete'] == 1)) { + $newSelect->appendChild($selectChild); + } + } } // if the new select has only one entry, @@ -429,7 +431,6 @@ private function adjustIndex($context, $callback) { */ public function makePreAdjustements($context) { $data = $this->getCurrentAuthorRoleData(); - //print_r(Administration::Author()); if($data == false || Administration::Author()->isDeveloper()) { return; } @@ -456,15 +457,18 @@ private static function findChildren($element, $names) { $names = explode(',', $names); } - $children = array(); - foreach($element->getChildren() as $child) { - $children = array_merge($children, self::findChildren($child,$names)); - - if(in_array($child->getName(), $names )) { - $children[] = $child; - } - } + $children = array(); + if(is_object($element)){ + foreach($element->getChildren() as $child) { + if(!is_string($child)){ + $children = array_merge($children, self::findChildren($child,$names)); + if(in_array($child->getName(), $names )) { + $children[] = $child; + } + } + } + } return $children; } @@ -476,7 +480,6 @@ private static function replaceChild($parent, $child) { foreach($parent->getChildren() as $position => $oldChild) { if($oldChild->getName() == $child->getName()) { $parent->replaceChildAt($position,$child); - return true; } @@ -703,7 +706,6 @@ public function getData($id_role) { // Get sections from the section manager: $availableSections = SectionManager::fetch(); -// print_r($availableSections); // The associated sections: $sections = Symphony::Database()->fetch(' From 7fa559433b5419e9643165a49cdc0f98cb18015b Mon Sep 17 00:00:00 2001 From: Fabian Romero Date: Tue, 19 May 2015 15:36:28 +0100 Subject: [PATCH 3/3] Extension information --- extension.meta.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extension.meta.xml b/extension.meta.xml index 0e2920b..9e9d820 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -15,11 +15,13 @@ - + Added functionality to hide menu elements created by other extensions. __Important:__ Since extensions can not (yet) influence the execution order of extensions in Symphony, you need to apply a tiny little 'hack' to Symphony to make sure the 'Author Roles'-extension is executed as last, after all other extensions have made their possible modifications to the navigation. Read the readme for more details. + +