1<?php
2/*
3 * Display Orphans Plugin
4 * Copyright (c) 2016 Jay Jeckel
5 * Licensed under the MIT license: https://opensource.org/licenses/MIT
6 * Permission is granted to use, copy, modify, and distribute the work.
7 * Full license information available in the project LICENSE file.
8*/
9
10namespace plugin\displayorphans;
11
12final class PageType
13{
14    private function __construct() { }
15
16    const ORPHAN = 'orphaned';
17
18    const WANTED = 'wanted';
19
20    const LINKED = 'linked';
21}
22
23final class Util
24{
25    private function __construct() { }
26
27    public static function /* array */ asList(/* string */ $text, /* string */ $delimiter = ' ', /* int */ $limit = PHP_INT_MAX)
28    { return empty(text) ? null : explode($delimiter, $text, $limit); }
29}
30
31final class Logic
32{
33    private function __construct() { }
34
35    public static function /* bool */ isPageIgnored(/* string */ $id, array $ignoredPages = null, array $ignoreNamespaces = null)
36    {
37        if (!empty($ignoredPages) && in_array($id, $ignoredPages)) { return true; }
38        if (!empty($ignoreNamespaces))
39        {
40            foreach ($ignoreNamespaces as $key => $namespace)
41            {
42                $namespace = rtrim($namespace, ':') . ':';
43                $sub = substr($id, 0, strlen($namespace));
44                if ($namespace == $sub) { return true; }
45            }
46        }
47        return false;
48    }
49
50    public static function /* bool */ isOrphanedPage(/* string */ $id, array $item,
51    array $ignoredPages = null, array $ignoreNamespaces = null)
52    { return $item['exists'] && $item['count'] == 0 && !Logic::isPageIgnored($id, $ignoredPages, $ignoreNamespaces); }
53
54    public static function /* bool */ isWantedPage(/* string */ $id, array $item,
55    array $ignoredPages = null, array $ignoreNamespaces = null)
56    { return !$item['exists'] && $item['count'] > 0 && !Logic::isPageIgnored($id, $ignoredPages, $ignoreNamespaces); }
57
58    public static function /* bool */ isLinkedPage(/* string */ $id, array $item,
59    array $ignoredPages = null, array $ignoreNamespaces = null)
60    { return $item['exists'] && $item['count'] > 0 && !Logic::isPageIgnored($id, $ignoredPages, $ignoreNamespaces); }
61}
62
63?>