diff --git a/LICENCE.TXT b/LICENCE.TXT old mode 100644 new mode 100755 diff --git a/assets/author_roles.css b/assets/author_roles.css old mode 100644 new mode 100755 diff --git a/assets/author_roles.js b/assets/author_roles.js old mode 100644 new mode 100755 diff --git a/content/content.index.php b/content/content.index.php old mode 100644 new mode 100755 index 71b033f..01bb835 --- a/content/content.index.php +++ b/content/content.index.php @@ -19,9 +19,9 @@ function __construct(){ * Build the page * @param array $context */ - public function build($context) + public function build(array $context = Array()) { - 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) @@ -118,4 +118,4 @@ public function __viewIndex() $this->Form->appendChild($tableActions); } } -?> \ No newline at end of file +?> diff --git a/content/content.roles.php b/content/content.roles.php old mode 100644 new mode 100755 index 08eae0b..4b464fd --- a/content/content.roles.php +++ b/content/content.roles.php @@ -17,7 +17,7 @@ function __construct(){ $this->_driver = Symphony::ExtensionManager()->create('author_roles'); } - public function build($context) + public function build(array $context = Array()) { $this->_action = isset($context[0]) ? $context[0] : false; if($this->_action == 'edit' && isset($context[1]) && is_numeric($context[1])) @@ -278,4 +278,4 @@ private function getValue($item_name) } } } -?> \ No newline at end of file +?> diff --git a/extension.driver.php b/extension.driver.php old mode 100644 new mode 100755 index b521cba..3e6f31f --- a/extension.driver.php +++ b/extension.driver.php @@ -1,9 +1,9 @@ 'Author Roles', 'version' => '1.2', @@ -16,8 +16,7 @@ public function about() } // Set the delegates: - public function getSubscribedDelegates() - { + public function getSubscribedDelegates() { return array( array( 'page' => '/backend/', @@ -79,35 +78,35 @@ public function fetchNavigation() { public function extendNavigation($context) { $data = $this->getCurrentAuthorRoleData(); - if($data == false || Administration::instance()->Author->isDeveloper()) { + if ($data == false || Administration::instance()->Author()->isDeveloper()) { return; } $custom_elements = explode("\n", $data['custom_elements']); - foreach($custom_elements as &$elem) { + foreach ($custom_elements as &$elem) { $elem = trim($elem); } // Disable non-visible sections: $visible = array(); - foreach($data['sections'] as $id => $rules) { - if($rules['visible'] == 1) { + foreach ($data['sections'] as $id => $rules) { + if ($rules['visible'] == 1) { array_push($visible, $id); } } - foreach($context['navigation'] as &$group) { - foreach($group['children'] as &$section) { - if(isset($section['section'])) { - if(!in_array($section['section']['id'], $visible)) { + foreach ($context['navigation'] as &$group) { + foreach ($group['children'] as &$section) { + if (isset($section['section'])) { + if (!in_array($section['section']['id'], $visible)) { $section['visible'] = 'no'; } } - if(isset($section['link'])) { - if(in_array($section['link'], $custom_elements)) { + if (isset($section['link'])) { + if (in_array($section['link'], $custom_elements)) { $section['visible'] = 'no'; } } @@ -122,28 +121,28 @@ public function extendNavigation($context) { */ public function deleteAuthorRole($context) { // When a new author is created $context is false: - if($context == false) { + if ($context == false) { return; } // When a bulk action delete is performed the ID's are stored in this manner: - if(isset($context['author_ids'])) { + if (isset($context['author_ids'])) { $context = $context['author_ids']; } // When 'Delete' is clicked in the author-edit screen: - if(isset($context['author_id'])) { + if (isset($context['author_id'])) { $context = array($context['author_id']); } // When a single ID is provided: - if(!is_array($context)) { + if (!is_array($context)) { $context = array($context); } // Delete the links: - foreach($context as $id_author) { - Symphony::Database()->query('DELETE FROM `tbl_author_roles_authors` WHERE `id_author` = '.$id_author.';'); + foreach ($context as $id_author) { + Symphony::Database()->query('DELETE FROM `tbl_author_roles_authors` WHERE `id_author` = ' . $id_author . ';'); } } @@ -153,7 +152,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() || Administration::instance()->Author()->isManager()) { $group = new XMLElement('fieldset'); $group->setAttribute('class', 'settings'); $group->appendChild(new XMLElement('legend', __('Author Role'))); @@ -169,9 +168,9 @@ public function addRolePicker($context) { $roles = $this->getRoles(); // See which role this user has: - $id_role = $context['author']->get('id') != false ? Symphony::Database()->fetchVar('id_role', 0, 'SELECT `id_role` FROM `tbl_author_roles_authors` WHERE `id_author` = '.$context['author']->get('id').';') : 0; + $id_role = $context['author']->get('id') != false ? Symphony::Database()->fetchVar('id_role', 0, 'SELECT `id_role` FROM `tbl_author_roles_authors` WHERE `id_author` = ' . $context['author']->get('id') . ';') : 0; - foreach($roles as $role) { + foreach ($roles as $role) { $options[] = array($role['id'], $role['id'] == $id_role, $role['name']); } @@ -183,8 +182,8 @@ public function addRolePicker($context) { $i = 0; - foreach($context['form']->getChildren() as $formChild) { - if($formChild->getName() != 'fieldset') { + foreach ($context['form']->getChildren() as $formChild) { + if ($formChild->getName() != 'fieldset') { // Inject here: $context['form']->insertChildAt($i, $group); } @@ -203,10 +202,10 @@ public function checkCallback($context) { $callback = Symphony::Engine()->getPageCallback(); // Perform an action according to the callback: - switch($callback['driver']) { + switch ($callback['driver']) { case 'publish' : // The Publish Screen: - switch($callback['context']['page']) { + switch ($callback['context']['page']) { case 'index' : // The index: $this->adjustIndex($context, $callback); @@ -232,15 +231,15 @@ public function checkCallback($context) { private function adjustIndex($context, $callback) { $data = $this->getCurrentAuthorRoleData(); - if($data == false || Administration::instance()->Author->isDeveloper()) { + if ($data == false || Administration::instance()->Author()->isDeveloper()) { return; } // Set the hidden fields: $hiddenFields = array(); - foreach($data['fields'] as $id_field => $rules) { - if($rules['hidden'] == 1) { + foreach ($data['fields'] as $id_field => $rules) { + if ($rules['hidden'] == 1) { // This field is hidden. array_push($hiddenFields, $id_field); } @@ -248,73 +247,76 @@ private function adjustIndex($context, $callback) { $section = $callback['context']['section_handle']; - foreach($data['sections'] as $id_section => $rules) { - if($rules['handle'] == $section) { + foreach ($data['sections'] as $id_section => $rules) { + if ($rules['handle'] == $section) { // Check if there are rules: - if($rules['create'] == 0) { + if ($rules['create'] == 0) { // It is not allowed to create new items: $children = current($context['oPage']->Context->getChildrenByName('ul'))->getChildrenByName('li'); - foreach($children as $key => $child) { - if(strpos($child->getValue(),__('Create New')) !== false) { - $value = $child->getValue(); - $child->setValue(''.strip_tags(str_replace(__('Create New'), '', $value)).''); + foreach ($children as $key => $child) { +// echo "
";
+//						var_dump($child->getChildren()[0]->getValue());
+//						echo "
"; +// die(); + foreach ($child->getChildren() as $k => $c) { + if (strpos($c->getValue(), __('Create New')) !== false) { + $value = $child->getChildren()[0]->getValue(); + $child->setValue('' . strip_tags(str_replace(__('Create New'), '', $value)) . ''); + } } } } - if($rules['own_entries'] == 1 || $rules['edit'] == 0 || $rules['delete'] == 0 || $rules['use_filter'] == 1) { + 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::instance()->Author()->get('id'); - if($rules['own_entries'] == 1) { + if ($rules['own_entries'] == 1) { // Only get the ID's of the current author to begin with: - $results = Symphony::Database()->fetch('SELECT `id` FROM `tbl_entries` WHERE `author_id` = '.$id_author.';'); - } - else { + $results = Symphony::Database()->fetch('SELECT `id` FROM `tbl_entries` WHERE `author_id` = ' . $id_author . ';'); + } else { // Get all the ID's: $results = Symphony::Database()->fetch('SELECT `id` FROM `tbl_entries`;'); } $ids = array(); - foreach($results as $result) - { + foreach ($results as $result) { $ids[] = $result['id']; } // Add or remove ID's from the filter: - if($rules['use_filter'] == 1) { + if ($rules['use_filter'] == 1) { $rule = explode(':', $rules['filter_rule']); - if(count($rule) == 2) { + if (count($rule) == 2) { // Valid filter, now get the ID's: $filteredIDs = array(); $action = $rule[0]; $idsArr = explode(',', $rule[1]); - foreach($idsArr as $idExpr) { + foreach ($idsArr as $idExpr) { $a = explode('-', trim($idExpr)); - if(count($a)==1) { + if (count($a) == 1) { // Regular ID $filteredIDs[] = $a[0]; - } - elseif(count($a)==2) { + } elseif (count($a) == 2) { // Range $from = $a[0]; - $to = $a[1]; + $to = $a[1]; - if($to >= $from) { - for($i = $from; $i <= $to; $i++){ + if ($to >= $from) { + for ($i = $from; $i <= $to; $i++) { $filteredIDs[] = $i; } } } } - switch($action) { + switch ($action) { case 'show' : // Only show the given ids. Well that's easy: $ids = $filteredIDs; @@ -330,86 +332,90 @@ private function adjustIndex($context, $callback) { // Now, check each table row: $newContents = new XMLElement('div', null, $context['oPage']->Contents->getAttributes()); - foreach($context['oPage']->Contents->getChildren() as $contentsChild) { - if($contentsChild->getName() == 'form') { + foreach ($context['oPage']->Contents->getChildren() as $contentsChild) { + if ($contentsChild->getName() == 'form') { $newForm = new XMLElement('form', null, $contentsChild->getAttributes()); - foreach($contentsChild->getChildren() as $formChild) { + foreach ($contentsChild->getChildren() as $formChild) { // only show entries created by this author, or which are allowed by the filter: - if($formChild->getName() == 'table' && ($rules['own_entries'] == 1 || $rules['use_filter'] == 1)) { + + + + if ($formChild->getName() == 'table' && ($rules['own_entries'] == 1 || $rules['use_filter'] == 1)) { $newTable = new XMLElement('table', null, $formChild->getAttributes()); - foreach($formChild->getChildren() as $tableChild) { - if($tableChild->getName() == 'tbody') { + foreach ($formChild->getChildren() as $tableChild) { + if ($tableChild->getName() == 'tbody') { $newTableBody = new XMLElement('tbody', null, $tableChild->getAttributes()); - foreach($tableChild->getChildren() as $tableRow) { + foreach ($tableChild->getChildren() as $tableRow) { // Check the ID: $id = explode('-', $tableRow->getAttribute('id')); - if(in_array($id[1], $ids)) { + if (in_array($id[1], $ids)) { $newTableBody->appendChild($tableRow); } } $newTable->appendChild($newTableBody); - } - else { + } else { $newTable->appendChild($tableChild); } } $newForm->appendChild($newTable); - } - elseif($formChild->getName() == 'div' && $formChild->getAttribute('class') == 'actions') { + } elseif ($formChild->getName() == 'div' && $formChild->getAttribute('class') == 'actions') { // Only proceed if you can either edit or delete. Otherwise it would have much sense to have an apply-button here... - if($rules['delete'] == 1 || $rules['edit'] == 1) { - $child = self::findChildren($formChild,'select'); + if ($rules['delete'] == 1 || $rules['edit'] == 1) { + + $child = self::findChildren($formChild, 'select'); + +// echo "
";
+//							var_dump($formChild);
+//							echo "
"; +// die(); + $child = $child[0]; $newSelect = new XMLElement('select', null, $child->getAttributes()); - foreach($child->getChildren() as $selectChild) { + foreach ($child->getChildren() as $selectChild) { // See if delete is allowed: - if($selectChild->getAttribute('value') == 'delete' && $rules['delete'] == 1) { + if ($selectChild->getAttribute('value') == 'delete' && $rules['delete'] == 1) { $newSelect->appendChild($selectChild); - } - elseif($selectChild->getName() == 'optgroup' && $rules['edit'] == 1) { + } 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)) { + if (!empty($optGroupChildren)) { $value = $optGroupChildren[0]->getAttribute('value'); $a = explode('-', str_replace('toggle-', '', $value)); - if(!in_array($a[0], $hiddenFields)) { + if (!in_array($a[0], $hiddenFields)) { $newSelect->appendChild($selectChild); } } - } - elseif($selectChild->getName() == 'option' && $selectChild->getAttribute('value') != 'delete' && ($rules['edit'] == 1 || $rules['delete'] == 1)) { + } 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, // it is the dummy entry and we can discard it - if($newSelect->getNumberOfChildren() > 1 ) { + if ($newSelect->getNumberOfChildren() > 1) { self::replaceChild($formChild, $newSelect); $newForm->appendChild($formChild); } } - } - else { + } else { $newForm->appendChild($formChild); } } $newContents->appendChild($newForm); $context['oPage']->Form = $newForm; - } - else { + } else { $newContents->appendChild($contentsChild); } } @@ -428,7 +434,7 @@ private function adjustIndex($context, $callback) { public function makePreAdjustements($context) { $data = $this->getCurrentAuthorRoleData(); - if($data == false || Administration::instance()->Author->isDeveloper()) { + if ($data == false || Administration::instance()->Author()->isDeveloper()) { return; } @@ -436,11 +442,11 @@ public function makePreAdjustements($context) { $callback = Symphony::Engine()->getPageCallback(); // If the user is only allowed to see his or her own entries, then the configuration should be overwritten to a maximum. - if($callback['driver'] == 'publish' && $callback['context']['page'] == 'index') { + if ($callback['driver'] == 'publish' && $callback['context']['page'] == 'index') { $section = $callback['context']['section_handle']; - foreach($data['sections'] as $id_section => $rules) { - if($rules['handle'] == $section && $rules['own_entries'] == 1) { + foreach ($data['sections'] as $id_section => $rules) { + if ($rules['handle'] == $section && $rules['own_entries'] == 1) { Symphony::Configuration()->set('pagination_maximum_rows', PHP_INT_MAX, 'symphony'); } } @@ -450,17 +456,19 @@ public function makePreAdjustements($context) { // return all ancestors of the given element with the given names // names can be a comma seperated list or an array of strings private static function findChildren($element, $names) { - if(!is_array($names)) { + if (!is_array($names)) { $names = explode(',', $names); } $children = array(); - foreach($element->getChildren() as $child) { - $children = array_merge($children, self::findChildren($child,$names)); + foreach ($element->getChildren() as $child) { + if (is_object($child)) { + $children = array_merge($children, self::findChildren($child, $names)); - if(in_array($child->getName(), $names )) { - $children[] = $child; + if (in_array($child->getName(), $names)) { + $children[] = $child; + } } } @@ -471,19 +479,24 @@ private static function findChildren($element, $names) { // name matches the name of the second argument with // the second argument private static function replaceChild($parent, $child) { - foreach($parent->getChildren() as $position => $oldChild) { - if($oldChild->getName() == $child->getName()) { - $parent->replaceChildAt($position,$child); + if (is_object($parent)) { + foreach ($parent->getChildren() as $position => $oldChild) { + if (is_object($oldChild)) { + if ($oldChild->getName() == $child->getName()) { + $parent->replaceChildAt($position, $child); - return true; - } + return true; + } + } - if(self::replaceChild($oldChild, $child)) { - return true; + if (self::replaceChild($oldChild, $child)) { + return true; + } } } return false; } + /** Adjust the entry editor on the publish page * @param $context * Provided with a page object @@ -493,65 +506,62 @@ private static function replaceChild($parent, $child) { private function adjustEntryEditor($context, $callback) { $data = $this->getCurrentAuthorRoleData(); - if($data == false || Administration::instance()->Author->isDeveloper()) { + if ($data == false || Administration::instance()->Author()->isDeveloper()) { return; } // Set the hidden fields: $hiddenFields = array(); - foreach($data['fields'] as $id_field => $rules) { - if($rules['hidden'] == 1) { + foreach ($data['fields'] as $id_field => $rules) { + if ($rules['hidden'] == 1) { // This field is hidden. array_push($hiddenFields, $id_field); } } // Fields should be hidden with JavaScript, so the data still gets posted when saving an entry: - $script = new XMLElement('script', 'var roles_hidden_fields = ['.implode(',', $hiddenFields).'];', array('type'=>'text/javascript')); + $script = new XMLElement('script', 'var roles_hidden_fields = [' . implode(',', $hiddenFields) . '];', array('type' => 'text/javascript')); $context['oPage']->addElementToHead($script); - $context['oPage']->addScriptToHead(URL.'/extensions/author_roles/assets/author_roles.js'); + $context['oPage']->addScriptToHead(URL . '/extensions/author_roles/assets/author_roles.js'); $section = $callback['context']['section_handle']; - foreach($data['sections'] as $id_section => $rules) { - if($rules['handle'] == $section) { - if($rules['edit'] == 0 || $rules['delete'] == 0 || $rules['create'] == 0) { + foreach ($data['sections'] as $id_section => $rules) { + if ($rules['handle'] == $section) { + if ($rules['edit'] == 0 || $rules['delete'] == 0 || $rules['create'] == 0) { // Hide the delete button when the author is not allowed to delete: // Hide the submit-button when the author is not allowed to create or edit: $newContents = new XMLElement('div', null, $context['oPage']->Contents->getAttributes()); - foreach($context['oPage']->Contents->getChildren() as $contentsChild) { - if($contentsChild->getName() == 'form') { + foreach ($context['oPage']->Contents->getChildren() as $contentsChild) { + if ($contentsChild->getName() == 'form') { $newForm = new XMLElement('form', null, $contentsChild->getAttributes()); - foreach($contentsChild->getChildren() as $formChild) { - if($formChild->getName() == 'div' && $formChild->getAttribute('class') == 'actions') { + foreach ($contentsChild->getChildren() as $formChild) { + if ($formChild->getName() == 'div' && $formChild->getAttribute('class') == 'actions') { $actionDiv = new XMLElement('div', null, $formChild->getAttributes()); - foreach($formChild->getChildren() as $actionChild) { - if($actionChild->getAttribute('name') == 'action[save]') { + foreach ($formChild->getChildren() as $actionChild) { + if ($actionChild->getAttribute('name') == 'action[save]') { // Check whether this is a create or an edit: - if( - ($callback['context']['page'] == 'edit' && $rules['edit'] == 1) || - ($callback['context']['page'] == 'new' && $rules['create'] == 1)) - { + if ( + ($callback['context']['page'] == 'edit' && $rules['edit'] == 1) || + ($callback['context']['page'] == 'new' && $rules['create'] == 1)) { $actionDiv->appendChild($actionChild); } - } - elseif($actionChild->getAttribute('name') == 'action[delete]' && $rules['delete'] == 1) { + } elseif ($actionChild->getAttribute('name') == 'action[delete]' && $rules['delete'] == 1) { $actionDiv->appendChild($actionChild); } } - if($rules['edit'] == 1|| $rules['create'] == 1) { + if ($rules['edit'] == 1 || $rules['create'] == 1) { $newForm->appendChild($actionDiv); } - } - else { - if($rules['edit'] == 0) { - foreach(self::findChildren($formChild,'input,select,textarea') as $child) { - $child->setAttribute('disabled','disabled'); + } else { + if ($rules['edit'] == 0) { + foreach (self::findChildren($formChild, 'input,select,textarea') as $child) { + $child->setAttribute('disabled', 'disabled'); } } @@ -561,8 +571,7 @@ private function adjustEntryEditor($context, $callback) { $newContents->appendChild($newForm); $context['oPage']->Form = $newForm; - } - else { + } else { $newContents->appendChild($contentsChild); } } @@ -579,17 +588,18 @@ private function adjustEntryEditor($context, $callback) { * An associated array with all the information you need, or false if no role is assigned */ private function getCurrentAuthorRoleData() { - if(Administration::instance()->isLoggedIn()) { - $id_author = Administration::instance()->Author->get('id'); - $id_role = $this->getAuthorRole($id_author); + if (Administration::instance()->Author()) { + $id_author = Administration::instance()->Author()->get('id'); + $id_role = $this->getAuthorRole($id_author); - if($id_role != false) { + if ($id_role != false) { $data = $this->getData($id_role); return $data; - } - else { + } else { return false; } + } else { + return false; } } @@ -601,14 +611,14 @@ private function getCurrentAuthorRoleData() { public function modifyAreas($context) { $data = $this->getCurrentAuthorRoleData(); - if($data == false || Administration::instance()->Author->isDeveloper()) { + if ($data == false || Administration::instance()->Author()->isDeveloper()) { return; } $newOptions = array(); - foreach($data['sections'] as $id_section => $rules) { - if($rules['visible'] == 1) { + foreach ($data['sections'] as $id_section => $rules) { + if ($rules['visible'] == 1) { $newOptions[] = array($id_section, $id_section == $context['default_area'], $rules['name']); } } @@ -622,21 +632,21 @@ public function modifyAreas($context) { * The context */ public function saveAuthorRole($context) { - if(Administration::instance()->Author->isDeveloper()) { + if (Administration::instance()->Author()->isDeveloper() || Administration::instance()->Author()->isManager()) { $id_role = intval($_POST['fields']['role']); $id_author = $context['author']->get('id'); - if($id_author == null) { + if ($id_author == null) { // This author has just been created, get the ID of this newly created author: - $id_author = Symphony::Database()->fetchVar('id', 0, 'SELECT `id` FROM `tbl_authors` WHERE `username` = \''.$context['author']->get('username').'\';'); + $id_author = Symphony::Database()->fetchVar('id', 0, 'SELECT `id` FROM `tbl_authors` WHERE `username` = \'' . $context['author']->get('username') . '\';'); } // Delete previously set roles: $this->deleteAuthorRole($id_author); - if($id_role != 0) { + if ($id_role != 0) { // Insert new role: - Symphony::Database()->insert(array('id_role'=>$id_role, 'id_author'=>$id_author), 'tbl_author_roles_authors'); + Symphony::Database()->insert(array('id_role' => $id_role, 'id_author' => $id_author), 'tbl_author_roles_authors'); } } } @@ -669,7 +679,7 @@ public function getAuthors($id_role) { `tbl_authors` A, `tbl_author_roles_authors` B WHERE - B.`id_role` = '.$id_role.' AND + B.`id_role` = ' . $id_role . ' AND B.`id_author` = A.`id`;'); return $authors; @@ -683,7 +693,7 @@ public function getAuthors($id_role) { * The role ID */ public function getAuthorRole($id_author) { - $id_role = Symphony::Database()->fetchVar('id_role', 0, 'SELECT `id_role` FROM `tbl_author_roles_authors` WHERE `id_author` = '.$id_author.';'); + $id_role = Symphony::Database()->fetchVar('id_role', 0, 'SELECT `id_role` FROM `tbl_author_roles_authors` WHERE `id_author` = ' . $id_author . ';'); return $id_role; } @@ -696,17 +706,16 @@ public function getAuthorRole($id_author) { * An associated array with all the information you need of this role, or false of no role is supplied */ public function getData($id_role) { - if($id_role != false) { + if ($id_role != false) { $data = array(); // The name of the role: - $roleResult = Symphony::Database()->fetch('SELECT * FROM `tbl_author_roles` WHERE `id` = '.$id_role.';'); + $roleResult = Symphony::Database()->fetch('SELECT * FROM `tbl_author_roles` WHERE `id` = ' . $id_role . ';'); $data['name'] = $roleResult[0]['name']; $data['custom_elements'] = $roleResult[0]['custom_elements']; // Get sections from the section manager: $availableSections = SectionManager::fetch(); // print_r($availableSections); - // The associated sections: $sections = Symphony::Database()->fetch(' SELECT @@ -721,18 +730,18 @@ public function getData($id_role) { FROM `tbl_author_roles_sections` A WHERE - A.`id_role` = '.$id_role.' + A.`id_role` = ' . $id_role . ' ;'); $data['sections'] = array(); - foreach($sections as $section) { + foreach ($sections as $section) { $id_section = $section['id_section']; unset($section['id_section']); - foreach($availableSections as $s) { + foreach ($availableSections as $s) { /* @var $s Section */ - if($s->get('id') == $id_section) { + if ($s->get('id') == $id_section) { $section['name'] = $s->get('name'); $section['handle'] = $s->get('handle'); } @@ -742,10 +751,10 @@ public function getData($id_role) { } // The fields: - $fields = Symphony::Database()->fetch('SELECT * FROM `tbl_author_roles_fields` WHERE `id_role` = '.$id_role.';'); + $fields = Symphony::Database()->fetch('SELECT * FROM `tbl_author_roles_fields` WHERE `id_role` = ' . $id_role . ';'); $data['fields'] = array(); - foreach($fields as $field) { + foreach ($fields as $field) { $id_field = $field['id_field']; unset($field['id']); unset($field['id_field']); @@ -755,8 +764,7 @@ public function getData($id_role) { // The entries: return $data; - } - else { + } else { return false; } } @@ -767,10 +775,10 @@ public function getData($id_role) { * The ID of the role */ public function deleteRole($id) { - Symphony::Database()->query('DELETE FROM `tbl_author_roles` WHERE `id` = '.$id.';'); - Symphony::Database()->query('DELETE FROM `tbl_author_roles_authors` WHERE `id_role` = '.$id.';'); - Symphony::Database()->query('DELETE FROM `tbl_author_roles_sections` WHERE `id_role` = '.$id.';'); - Symphony::Database()->query('DELETE FROM `tbl_author_roles_fields` WHERE `id_role` = '.$id.';'); + Symphony::Database()->query('DELETE FROM `tbl_author_roles` WHERE `id` = ' . $id . ';'); + Symphony::Database()->query('DELETE FROM `tbl_author_roles_authors` WHERE `id_role` = ' . $id . ';'); + Symphony::Database()->query('DELETE FROM `tbl_author_roles_sections` WHERE `id_role` = ' . $id . ';'); + Symphony::Database()->query('DELETE FROM `tbl_author_roles_fields` WHERE `id_role` = ' . $id . ';'); } /** @@ -785,50 +793,47 @@ public function saveData($values) { $name = isset($values['name']) ? Symphony::Database()->cleanValue($values['name']) : ''; $custom_elements = isset($values['custom_elements']) ? $values['custom_elements'] : ''; - if(!empty($name) && isset($values['id_role'])) { + if (!empty($name) && isset($values['id_role'])) { // Create the role: - if($values['id_role'] == 0) { - Symphony::Database()->insert(array('name'=>$name, 'custom_elements'=>$custom_elements), 'tbl_author_roles'); + if ($values['id_role'] == 0) { + Symphony::Database()->insert(array('name' => $name, 'custom_elements' => $custom_elements), 'tbl_author_roles'); $id_role = Symphony::Database()->getInsertId(); - } - else { + } else { $id_role = $values['id_role']; - Symphony::Database()->update(array('name'=>$name, 'custom_elements'=>$custom_elements), 'tbl_author_roles', '`id` = '.$id_role); + Symphony::Database()->update(array('name' => $name, 'custom_elements' => $custom_elements), 'tbl_author_roles', '`id` = ' . $id_role); } // First delete all links in the database before new ones are created: - Symphony::Database()->query('DELETE FROM `tbl_author_roles_sections` WHERE `id_role` = '.$id_role.';'); - Symphony::Database()->query('DELETE FROM `tbl_author_roles_fields` WHERE `id_role` = '.$id_role.';'); - - foreach($values['section'] as $id_section => $info) { - $insert = array('id_role'=>$id_role, 'id_section'=>$id_section); - $insert['visible'] = isset($info['visible']) ? 1 : 0; - $insert['create'] = isset($info['create']) ? 1 : 0; - $insert['edit'] = isset($info['edit']) ? 1 : 0; - $insert['delete'] = isset($info['delete']) ? 1 : 0; + Symphony::Database()->query('DELETE FROM `tbl_author_roles_sections` WHERE `id_role` = ' . $id_role . ';'); + Symphony::Database()->query('DELETE FROM `tbl_author_roles_fields` WHERE `id_role` = ' . $id_role . ';'); + + foreach ($values['section'] as $id_section => $info) { + $insert = array('id_role' => $id_role, 'id_section' => $id_section); + $insert['visible'] = isset($info['visible']) ? 1 : 0; + $insert['create'] = isset($info['create']) ? 1 : 0; + $insert['edit'] = isset($info['edit']) ? 1 : 0; + $insert['delete'] = isset($info['delete']) ? 1 : 0; $insert['own_entries'] = isset($info['own_entries']) ? 1 : 0; - $insert['use_filter'] = isset($info['use_filter']) ? 1 : 0; + $insert['use_filter'] = isset($info['use_filter']) ? 1 : 0; // Filter rule: - if(isset($info['filter_rule']) && isset($info['filter_rule_type'])) { - $insert['filter_rule'] = $info['filter_rule_type'].':'.$info['filter_rule']; + if (isset($info['filter_rule']) && isset($info['filter_rule_type'])) { + $insert['filter_rule'] = $info['filter_rule_type'] . ':' . $info['filter_rule']; } Symphony::Database()->insert($insert, 'tbl_author_roles_sections'); // Fields: - if(isset($info['fields'])) { - foreach($info['fields'] as $id_field => $value) { - Symphony::Database()->insert(array('id_role'=>$id_role, 'id_field'=>$id_field, 'hidden'=>1), 'tbl_author_roles_fields'); + if (isset($info['fields'])) { + foreach ($info['fields'] as $id_field => $value) { + Symphony::Database()->insert(array('id_role' => $id_role, 'id_field' => $id_field, 'hidden' => 1), 'tbl_author_roles_fields'); } } // Entries: - } return $id_role; - } - else { + } else { return false; } } @@ -909,11 +914,11 @@ public function uninstall() { * The version that is currently installed in this Symphony installation * @return boolean */ - public function update($previousVersion) { - if(version_compare($previousVersion, '1.2', '<')) { + public function update($previousVersion = false) { + if (version_compare($previousVersion, '1.2', '<')) { // Update from pre-1.1 to 1.2: return Symphony::Database()->query('ALTER TABLE `tbl_author_roles` ADD `custom_elements` TEXT NULL;'); } } -} +} diff --git a/extension.meta.xml b/extension.meta.xml old mode 100644 new mode 100755 diff --git a/lang/lang.ru.php b/lang/lang.ru.php old mode 100644 new mode 100755 diff --git a/readme.md b/readme.md old mode 100644 new mode 100755