Is an applicable context?

@since 160715 Notice contexts.

@param array $notice Input notice.

@return bool True if an applicable context.
547073
protected function isApplicableContext(array $notice): bool
    {
        if ($this->Wp->is_network_admin) {
            $context = 'network';
        } elseif ($this->Wp->is_user_admin) {
            $context = 'user';
        } elseif ($this->Wp->is_admin) {
            $context = 'admin';
        } else { // Should not happen, but just in case.
            debug(0, $this->c::issue(vars(), 'Context unknown.'));
            return false; // Unknown w/ debugger.
        }
        $notice                  = $this->normalize($notice);
        $applicable_contexts     = preg_split('/[|\s]+/u', $notice['for_context'], -1, PREG_SPLIT_NO_EMPTY);
        $not_applicable_contexts = preg_split('/[|\s]+/u', $notice['not_for_context'], -1, PREG_SPLIT_NO_EMPTY);
        // e.g., `network|admin`, `network || admin`, or `network admin`.

        if ($applicable_contexts && !in_array($context, $applicable_contexts, true)) {
            return false; // Not applicable in this context.
        } elseif ($not_applicable_contexts && in_array($context, $not_applicable_contexts, true)) {
            return false; // Not applicable in this context.
        }
        return true; // Applicable context (default behavior).
    }
305685
public static function notice($message, $context = [], $channel = 'tastphp.logger')
    {
        $logger = static::getLoggerByLevelAndChannel(Monolog::NOTICE, $channel);
        $logger->addNotice($message, $context);
    }
70612
public function warning($message, array $context = array()) {
        $context['fromClass'] = get_called_class();
        foreach ($this->loggersInstances as $logger) {
            $logger->warning($message, $context);
        }
    }
687584
public function error($message, array $context = array())
    {
        if (self::isSetLogger()) {
            return self::$logger->error($message, $context);
        }

        return false;
    }
1302410
protected function addNotice($notice)
    {
        if (!$this->variant) {
            $notice       = trim($notice);
            $this->notice = strlen($notice) ? $this->exportNotice($notice) : null;
        }
    }
546064
public function notice($message, array $context = array())
    {
        // TODO: Implement notice() method.
        return $this->addRecord(\Psr\Log\LogLevel::NOTICE, $message, $context);
    }
783740
public function isGranted($permission, $context = null)
    {
        $roles = $this->roleService->getIdentityRoles();

        if (empty($roles)) {
            return false;
        }

        if (!$this->rbac->isGranted($roles, $permission)) {
            return false;
        }

        if ($this->hasAssertion($permission)) {
            return $this->assert($this->assertions[(string) $permission], $context);
        }

        return true;
    }
54424
def notice(self, msg, *args, **kw):
        """"""
        if self.isEnabledFor(NOTICE):
            self._log(NOTICE, msg, args, **kw)
187508
protected function listenNotificationsEvents(array $notification)
    {
        $events = Arr::get($notification, 'event');

        if($events === null && isset($notification['classname'])) {
            $events = app()->make($notification['classname'])->getEvents();
        }

        foreach ((array) $events as $event) {
            $this->runNotificationListener($event, $notification);
        }
    }
519118
public function isValidExtension()
    {
        return !count($this->allowedExtensions)
            || in_array($this->getFileExtension(), $this->allowedExtensions, true);
    }
566457
public function validateCount($value, array $context) {
		$maxWorkers = Config::maxworkers();
		if (!$value || !$maxWorkers) {
			return true;
		}

		$currentWorkers = $this->find()->where(['server' => $value])->count();
		if ($currentWorkers >= $maxWorkers) {
			return false;
		}

		return true;
	}
851143
protected function update(array $notices)
    {
        if ($this->get() === $notices) {
            return; // Nothing to do.
        }
        $this->s::sysOption('notices', $notices, false);
    }
902419
protected static function validate_contextlist_contexts(approved_contextlist $contextlist) {
        return array_reduce($contextlist->get_contexts(), function($carry, $context) {
            if ($context->contextlevel == CONTEXT_COURSE) {
                $carry[] = $context;
            }
            return $carry;
        }, []);
    }
186509
public function onAllAdminNotices()
    {
        if (!($notices = $this->get())) {
            return; // Nothing to do.
        }
        $time = time(); // The current time.

        foreach ($notices as $_key => &$_notice) {
            # Catch invalid/corrupted notices.

            if (!is_string($_key) || !is_array($_notice)) {
                unset($notices[$_key]);
                continue; // Ignore.
            }
            # Normalize the notice.

            $_notice = $this->normalize($_notice);

            # Initialize a few variables.

            $_markup           = '';
            $_current_user_can = false;
            $_is_applicable    = false;

            $_class = $this->App::CORE_CONTAINER_SLUG.'-menu-page-area';
            $_class .= ' -notice';
            $_class .= ' notice';

            $_style   = $_notice['style'];
            $_dismiss = ''; // Default; n/a.

            # Check for empty markup.

            if (!($_markup = $_notice['markup'])) {
                unset($notices[$_key]);
                continue; // Ignore.
            }
            # If transient, wipe after a single pass.

            if ($_notice['is_transient']) {
                unset($notices[$_key]);
            }
            # Has notice become too old; i.e., lingering?

            if ($_notice['_insertion_time'] < $this->outdated_notice_time
                && /* Not intentially delayed. */ $_notice['delay_until_time'] < $time) {
                unset($notices[$_key]); // Ancient history after this pass.
            }
            # Check conditions; i.e., is notice applicable?

            if (!$this->currentUserCan($_notice)) {
                continue; // Do not display.
            } elseif (!$this->isApplicableContext($_notice)) {
                continue; // Do not display.
            } elseif (!$this->isApplicablePage($_notice)) {
                continue; // Do not display.
            } elseif ($_notice['delay_until_time'] > $time) {
                continue; // Do not display.
            } elseif ($_notice['recurs_every'] && $_notice['_last_recur_dismiss_time']
                && $_notice['_last_recur_dismiss_time'] + $_notice['recurs_every'] > $time) {
                continue; // Do not display; not time to recur yet, based on last time.
            }
            # If `is_applicable` is a closure, check it's return value also.

            if ($this->c::isSerialized($_notice['is_applicable'])) {
                try { // Maybe catch exceptions here.
                    $_is_applicable = $this->c::unserializeClosure($_notice['is_applicable']);
                    $_is_applicable = $_is_applicable($this->App); // Should return (bool) or `null`.
                    $_is_applicable = $_is_applicable === null ? $_is_applicable : (bool) $_is_applicable;

                    // NOTE: A special return value of `null` indicates the notice
                    // is no longer applicable (at all) and should be dequeued entirely.

                    if ($_is_applicable === null) {
                        unset($notices[$_key]);
                        continue; // Ignore.
                    } elseif (!$_is_applicable) {
                        continue; // Do not display.
                    }
                } catch (\Throwable $Throwable) {
                    unset($notices[$_key]); // Avoid repeats.

                    if ($this->App->Config->©debug['©enable']) {
                        throw $Throwable;
                    }
                    continue; // Ignore.
                }
            }
            # If `markup` is a closure, call upon the closure now.

            if ($this->c::isSerialized($_notice['markup'])) {
                try { // Maybe catch exceptions here.
                    $_markup = $this->c::unserializeClosure($_notice['markup']);
                    $_markup = (string) $_markup($this->App); // Should return a string.

                    // NOTE: A special return value (empty) indicates the notice
                    // is no longer applicable (at all) and should be dequeued entirely.

                    if (!$_markup) {
                        unset($notices[$_key]);
                        continue; // Ignore.
                    }
                } catch (\Throwable $Throwable) {
                    unset($notices[$_key]); // Avoid repeats.

                    if ($this->App->Config->©debug['©enable']) {
                        throw $Throwable;
                    }
                    continue; // Ignore.
                }
            }
            # Setup notice classes for CSS in WP core.

            switch ($_notice['type']) {
                case 'info':
                    $_class .= ' notice-info';
                    break; // Blue coloration.

                case 'success':
                    $_class .= ' notice-success';
                    break; // Green coloration.

                case 'warning':
                    $_class .= ' notice-warning';
                    break; // Orange/yellow coloration.

                case 'error':
                    $_class .= ' notice-error';
                    break; // Red coloration.

                default: // Default (info).
                    $_class .= ' notice-info';
            }
            // Create dismiss icon if applicable.

            if ($_notice['is_persistent'] && $_notice['is_dismissable']) {
                // $_class .= ' is-dismissible';
                // We use a different approach for dismissals.

                $_style .= ' padding-right:38px; position:relative;';
                $_dismiss = '<a class="notice-dismiss" style="text-decoration:none;" href="'.esc_attr($this->dismissUrl($_key)).'">'.
                                '<span class="screen-reader-text">'.__('Dismiss this notice.', 'wp-sharks-core').'</span>'.
                            '</a>';
            }
            # Make sure markup is wrapped in a block-level tag so margins will exist.

            $_markup = $this->c::mbTrim($_markup); // Before checking.
            if (!preg_match('/^\<(?:p|div|form|h[1-6]|ul|ol)[\s>]/ui', $_markup)) {
                $_markup = '<p>'.$_markup.'</p>'; // Add `<p>` tag.
            }
            # Display notice `<div>` with the markup and a possible dismiss icon.

            echo '<div class="'.esc_attr($_class).'" style="'.esc_attr($_style).'">'.
                    $_markup.$_dismiss.// Possible dismiss icon.
                 '</div>';

            # Notice seen. Handle queue state logic now.

            if ($_notice['is_persistent']) {
                continue; // Persistent; do nothing.
                // See {@link dismiss()} for recurring + persistent notice handling.
                // A recurring + persistent notice is counted/updated when it's dismissed.
                // If it's not dismissable, then it simply remains until dequeued manually.
            } elseif ($_notice['recurs_every']) {
                ++$_notice['_recurrences']; // Update counter.

                if ($_notice['_recurrences'] < $_notice['recurs_times']) {
                    $_notice['_last_recur_dismiss_time'] = $time;
                } else {
                    unset($notices[$_key]); // Dequeue.
                }
            } else {
                unset($notices[$_key]); // Dequeue.
            }
        } // unset($_key, $_notice, $_markup, $_current_user_can, $_is_applicable, $_class, $_style, $_dismiss);

        $this->update($notices);
    }
1000186
public static function notice( $message, $context = array(), $extra = null )
    {
        return static::log( $message, LoggingLevels::NOTICE, $context, $extra );
    }
907596
public function beginNotice(string $message, array $context = []) {
        return $this->begin(LogLevel::NOTICE, $message, $context);
    }
285043
public function message_admins($notice) {

        $site = get_site();

        $subject = get_string('emailsubject', 'antivirus', format_string($site->fullname));
        $admins = get_admins();
        foreach ($admins as $admin) {
            $eventdata = new \core\message\message();
            $eventdata->courseid          = SITEID;
            $eventdata->component         = 'moodle';
            $eventdata->name              = 'errors';
            $eventdata->userfrom          = get_admin();
            $eventdata->userto            = $admin;
            $eventdata->subject           = $subject;
            $eventdata->fullmessage       = $notice;
            $eventdata->fullmessageformat = FORMAT_PLAIN;
            $eventdata->fullmessagehtml   = '';
            $eventdata->smallmessage      = '';
            message_send($eventdata);
        }
    }