Pocket::canRender PHP Method

canRender() public method

Whether or not this pocket should be processed based on its state.
public canRender ( array $Data ) : boolean
$Data array Data specific to the request.
return boolean
    public function canRender($Data)
    {
        if (!$this->ShowInDashboard && inSection('Dashboard')) {
            return false;
        }
        $IsMobile = isMobile();
        if ($this->MobileOnly && !$IsMobile || $this->MobileNever && $IsMobile) {
            return false;
        }
        if ($this->isAd() && checkPermission('Garden.NoAds.Allow')) {
            return false;
        }
        if ($this->EmbeddedNever && strcasecmp(Gdn::controller()->RequestMethod, 'embed') == 0) {
            return false;
        }
        // Check to see if the pocket is enabled.
        switch ($this->Disabled) {
            case Pocket::DISABLED:
                return false;
            case Pocket::TESTING:
                if (!checkPermission('Plugins.Pockets.Manage')) {
                    return false;
                }
                break;
        }
        // Check to see if the page matches.
        if ($this->Page && strcasecmp($this->Page, val('PageName', $Data)) != 0) {
            return false;
        }
        // Check to see if this is repeating.
        $Count = val('Count', $Data);
        if ($Count) {
            switch ($this->RepeatType) {
                case Pocket::REPEAT_AFTER:
                    if (strcasecmp($Count, Pocket::REPEAT_AFTER) != 0) {
                        return false;
                    }
                    break;
                case Pocket::REPEAT_BEFORE:
                    if (strcasecmp($Count, Pocket::REPEAT_BEFORE) != 0) {
                        return false;
                    }
                    break;
                case Pocket::REPEAT_ONCE:
                    if ($Count != 1) {
                        return false;
                    }
                    break;
                case Pocket::REPEAT_EVERY:
                    $Frequency = (array) $this->RepeatFrequency;
                    $Every = val(0, $Frequency, 1);
                    if ($Every < 1) {
                        $Every = 1;
                    }
                    $Begin = val(1, $Frequency, 1);
                    if ($Count % $Every > 0 || $Count < $Begin) {
                        return false;
                    }
                    break;
                case Pocket::REPEAT_INDEX:
                    if (!in_array($Count, (array) $this->RepeatFrequency)) {
                        return false;
                    }
                    break;
            }
        }
        // If we've passed all of the tests then the pocket can be processed.
        return true;
    }