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

Protected pages are still visible on navigation output #6

Open
webathlet opened this issue Jun 1, 2017 · 0 comments
Open

Protected pages are still visible on navigation output #6

webathlet opened this issue Jun 1, 2017 · 0 comments
Labels

Comments

@webathlet
Copy link

Hi everyone,

protected pages are still shown on normal outputed pages.

Following changes in Helper/Page/PageHelper.php will fix it as it is similar implemented in ModuleCustomNavigation of Contao core:

<?php
namespace Oneup\SiblingNavigation\Helper\Page;

class PageHelper extends \Backend {

    /**
     * Import the back end user object
     */
    public function __construct() {
        parent::__construct();
        $this->import('BackendUser', 'User');
    }

    public function generateSiblingNavigation($objPage, $type = 'regular', $hidden = '', $unpublished = '', $typeInternal = 'forward') {
        $prev, $prevPage = null;
        $next, $nextPage = null;

        $groups = array();

        // Get all groups of the current front end user
        if (FE_USER_LOGGED_IN) {
            $this->import('FrontendUser', 'FEUser');
            $groups = $this->FEUser->groups;
        }

        $published = "published = '1'";
        $hide = "hide = ''";

        if ('1' === $unpublished) {
            $published = "(published = '1' OR published = '')";
        }

        if ('1' === $hidden) {
            $hide = "(hide = '' OR hide = '1')";
        }

        $prevPage = \PageModel::findAll([
                    'column' => [
                        "pid = ?",
                        $published,
                        $hide,
                        "(type = ? OR type = ?)",
                        "sorting < ?",
                    ],
                    'value' => [
                        $objPage->pid,
                        $type,
                        $typeInternal,
                        $objPage->sorting,
                    ],
                    'order' => 'sorting DESC',
                        // no limit due to get all pages for checking protection state
                        //'limit' => 1,
        ]);
        while ($prevPage->next()) {
            $_groups = deserialize($nextPage->groups);
            if (!$prevPage->protected || BE_USER_LOGGED_IN || (is_array($_groups) && count(array_intersect($_groups, $groups)))) {
                $prev = $prevPage;
                break;
            }
        }

        $nextPage = \PageModel::findAll([
                    'column' => [
                        "pid = ?",
                        $published,
                        $hide,
                        "(type = ? OR type = ?)",
                        "sorting > ?",
                    ],
                    'value' => [
                        $objPage->pid,
                        $type,
                        $typeInternal,
                        $objPage->sorting,
                    ],
                    'order' => 'sorting ASC',
                        // no limit due to get all pages for checking protection state
                        //'limit' => 1,
        ]);
        while ($nextPage->next()) {
            $_groups = deserialize($nextPage->groups);
            if (!$nextPage->protected || BE_USER_LOGGED_IN || (is_array($_groups) && count(array_intersect($_groups, $groups)))) {
                $next = $nextPage;
                break;
            }
        }

        return array(
            'prev' => $prev ? $this->generateFrontendUrl($prev->row()) : null,
            'next' => $next ? $this->generateFrontendUrl($next->row()) : null,
            'prevTitle' => $prev ? $prev->title : '',
            'nextTitle' => $next ? $next->title : '',
            'objPrev' => $prev,
            'objNext' => $next,
        );
    }

}
?>

I haven't checked if same changes should be made to helper objects for news and events.

Thank you in advance
webathlet

@bytehead bytehead added the bug label Jun 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants