Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 2.6.2 working #31

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions content/content.index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -30,7 +30,7 @@ public function build($context)
}
}
parent::build($context);
}
//}
}

/**
Expand Down
102 changes: 51 additions & 51 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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')));
Expand Down Expand Up @@ -191,7 +191,7 @@ public function addRolePicker($context) {

$i++;
}
}
//}
}

/**
Expand All @@ -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' :
Expand Down Expand Up @@ -230,9 +229,10 @@ public function checkCallback($context) {
* @return mixed
*/
private function adjustIndex($context, $callback) {

$data = $this->getCurrentAuthorRoleData();

if($data == false || Administration::instance()->Author->isDeveloper()) {
if($data == false || Administration::Author()->isDeveloper()) {
return;
}

Expand Down Expand Up @@ -263,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:
Expand Down Expand Up @@ -367,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,
Expand Down Expand Up @@ -427,8 +431,7 @@ private function adjustIndex($context, $callback) {
*/
public function makePreAdjustements($context) {
$data = $this->getCurrentAuthorRoleData();

if($data == false || Administration::instance()->Author->isDeveloper()) {
if($data == false || Administration::Author()->isDeveloper()) {
return;
}

Expand All @@ -454,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;
}
Expand All @@ -474,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;
}

Expand All @@ -492,10 +497,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();
Expand Down Expand Up @@ -580,9 +582,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;
Expand All @@ -601,7 +602,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;
}

Expand All @@ -622,7 +623,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');

Expand All @@ -638,7 +639,7 @@ public function saveAuthorRole($context) {
// Insert new role:
Symphony::Database()->insert(array('id_role'=>$id_role, 'id_author'=>$id_author), 'tbl_author_roles_authors');
}
}
//}
}

/**
Expand Down Expand Up @@ -705,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('
Expand Down Expand Up @@ -882,8 +882,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`),
Expand Down
4 changes: 3 additions & 1 deletion extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
<releases>
<release version="1.0" date="2011-03-17" min="2.2" max="2.2.5" />
<release version="1.1" date="2012-05-08" min="2.3" />
<release version="1.2" date="2012-10-04" min="2.3">
<release version="1.2" date="2012-10-04" min="2.3" >
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.
</release>
<release version="1.3" date="2015-04-19" min="2.6" />

</releases>
</extension>