2017-06-18 14:23:37 +00:00
|
|
|
<?php
|
2017-11-17 01:23:18 +00:00
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
2017-06-18 14:23:37 +00:00
|
|
|
declare(strict_types=1);
|
2019-02-26 03:41:12 +00:00
|
|
|
namespace JKingWeb\Arsse\Context;
|
2017-08-29 14:50:31 +00:00
|
|
|
|
2017-09-26 20:45:41 +00:00
|
|
|
use JKingWeb\Arsse\Misc\ValueInfo;
|
2019-02-26 16:11:42 +00:00
|
|
|
use JKingWeb\Arsse\Misc\Date;
|
2017-06-18 14:23:37 +00:00
|
|
|
|
2019-02-26 03:41:12 +00:00
|
|
|
class ExclusionContext {
|
2017-06-18 14:23:37 +00:00
|
|
|
public $folder;
|
2019-04-02 13:32:31 +00:00
|
|
|
public $folders;
|
2017-11-16 20:56:14 +00:00
|
|
|
public $folderShallow;
|
2019-04-02 13:32:31 +00:00
|
|
|
public $foldersShallow;
|
2019-03-07 16:07:22 +00:00
|
|
|
public $tag;
|
2019-04-02 13:32:31 +00:00
|
|
|
public $tags;
|
2019-03-07 16:07:22 +00:00
|
|
|
public $tagName;
|
2019-04-02 13:32:31 +00:00
|
|
|
public $tagNames;
|
2017-06-18 14:23:37 +00:00
|
|
|
public $subscription;
|
2019-04-02 13:32:31 +00:00
|
|
|
public $subscriptions;
|
2017-06-18 14:23:37 +00:00
|
|
|
public $edition;
|
2017-07-07 02:53:17 +00:00
|
|
|
public $editions;
|
2019-04-02 13:32:31 +00:00
|
|
|
public $article;
|
2017-07-07 02:53:17 +00:00
|
|
|
public $articles;
|
2017-10-13 04:04:26 +00:00
|
|
|
public $label;
|
2019-04-02 13:32:31 +00:00
|
|
|
public $labels;
|
2017-10-13 04:04:26 +00:00
|
|
|
public $labelName;
|
2019-04-02 13:32:31 +00:00
|
|
|
public $labelNames;
|
2019-02-26 03:41:12 +00:00
|
|
|
public $annotationTerms;
|
|
|
|
public $searchTerms;
|
|
|
|
public $titleTerms;
|
|
|
|
public $authorTerms;
|
2019-02-26 16:11:42 +00:00
|
|
|
public $oldestArticle;
|
|
|
|
public $latestArticle;
|
|
|
|
public $oldestEdition;
|
|
|
|
public $latestEdition;
|
|
|
|
public $modifiedSince;
|
|
|
|
public $notModifiedSince;
|
|
|
|
public $markedSince;
|
|
|
|
public $notMarkedSince;
|
2017-06-18 14:23:37 +00:00
|
|
|
|
|
|
|
protected $props = [];
|
2019-02-26 04:37:14 +00:00
|
|
|
protected $parent;
|
|
|
|
|
|
|
|
public function __construct(self $c = null) {
|
|
|
|
$this->parent = $c;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __clone() {
|
2019-04-02 23:58:35 +00:00
|
|
|
// if the context was cloned because its parent was cloned, change the parent to the clone
|
2019-02-26 04:37:14 +00:00
|
|
|
if ($this->parent) {
|
2019-02-26 04:59:48 +00:00
|
|
|
$t = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS | \DEBUG_BACKTRACE_PROVIDE_OBJECT, 2)[1];
|
|
|
|
if (($t['object'] ?? null) instanceof self && $t['function'] === "__clone") {
|
|
|
|
$this->parent = $t['object'];
|
2019-02-26 04:37:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 16:12:40 +00:00
|
|
|
/** @codeCoverageIgnore */
|
2019-02-26 04:37:14 +00:00
|
|
|
public function __destruct() {
|
|
|
|
unset($this->parent);
|
|
|
|
}
|
2017-06-18 14:23:37 +00:00
|
|
|
|
|
|
|
protected function act(string $prop, int $set, $value) {
|
2017-08-29 14:50:31 +00:00
|
|
|
if ($set) {
|
2018-12-05 01:41:21 +00:00
|
|
|
if (is_null($value)) {
|
|
|
|
unset($this->props[$prop]);
|
|
|
|
$this->$prop = (new \ReflectionClass($this))->getDefaultProperties()[$prop];
|
|
|
|
} else {
|
|
|
|
$this->props[$prop] = true;
|
|
|
|
$this->$prop = $value;
|
|
|
|
}
|
2019-02-26 04:37:14 +00:00
|
|
|
return $this->parent ?? $this;
|
2017-06-18 14:23:37 +00:00
|
|
|
} else {
|
|
|
|
return isset($this->props[$prop]);
|
|
|
|
}
|
|
|
|
}
|
2017-07-07 02:53:17 +00:00
|
|
|
|
2019-04-02 13:32:31 +00:00
|
|
|
protected function cleanIdArray(array $spec, bool $allowZero = false): array {
|
2017-07-07 02:53:17 +00:00
|
|
|
$spec = array_values($spec);
|
2017-08-29 14:50:31 +00:00
|
|
|
for ($a = 0; $a < sizeof($spec); $a++) {
|
2019-04-02 13:32:31 +00:00
|
|
|
if (ValueInfo::id($spec[$a], $allowZero)) {
|
2017-09-26 20:45:41 +00:00
|
|
|
$spec[$a] = (int) $spec[$a];
|
2017-07-07 02:53:17 +00:00
|
|
|
} else {
|
2019-04-02 13:32:31 +00:00
|
|
|
$spec[$a] = null;
|
2017-07-07 02:53:17 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-05 15:03:15 +00:00
|
|
|
return array_values(array_unique(array_filter($spec, function($v) {
|
2019-04-02 13:32:31 +00:00
|
|
|
return !is_null($v);
|
|
|
|
})));
|
2017-07-07 02:53:17 +00:00
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2019-02-22 16:13:42 +00:00
|
|
|
protected function cleanStringArray(array $spec): array {
|
|
|
|
$spec = array_values($spec);
|
2019-02-22 17:34:06 +00:00
|
|
|
$stop = sizeof($spec);
|
|
|
|
for ($a = 0; $a < $stop; $a++) {
|
|
|
|
if (strlen($str = ValueInfo::normalize($spec[$a], ValueInfo::T_STRING | ValueInfo::M_DROP) ?? "")) {
|
2019-02-22 16:13:42 +00:00
|
|
|
$spec[$a] = $str;
|
|
|
|
} else {
|
|
|
|
unset($spec[$a]);
|
|
|
|
}
|
|
|
|
}
|
2019-02-26 17:54:27 +00:00
|
|
|
return array_values(array_unique($spec));
|
2019-02-22 16:13:42 +00:00
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function folder(int $spec = null) {
|
2017-06-18 14:23:37 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2019-04-02 13:32:31 +00:00
|
|
|
public function folders(array $spec = null) {
|
|
|
|
if (isset($spec)) {
|
|
|
|
$spec = $this->cleanIdArray($spec, true);
|
|
|
|
}
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
2017-11-16 20:56:14 +00:00
|
|
|
public function folderShallow(int $spec = null) {
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
2019-03-07 16:07:22 +00:00
|
|
|
}
|
|
|
|
|
2019-04-02 13:32:31 +00:00
|
|
|
public function foldersShallow(array $spec = null) {
|
|
|
|
if (isset($spec)) {
|
|
|
|
$spec = $this->cleanIdArray($spec, true);
|
|
|
|
}
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
2019-03-07 16:07:22 +00:00
|
|
|
public function tag(int $spec = null) {
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
2019-04-02 13:32:31 +00:00
|
|
|
public function tags(array $spec = null) {
|
|
|
|
if (isset($spec)) {
|
|
|
|
$spec = $this->cleanIdArray($spec);
|
|
|
|
}
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
2019-03-07 16:07:22 +00:00
|
|
|
public function tagName(string $spec = null) {
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
2017-11-16 20:56:14 +00:00
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2019-04-02 13:32:31 +00:00
|
|
|
public function tagNames(array $spec = null) {
|
|
|
|
if (isset($spec)) {
|
|
|
|
$spec = $this->cleanStringArray($spec);
|
|
|
|
}
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function subscription(int $spec = null) {
|
2017-06-18 14:23:37 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2019-04-02 13:32:31 +00:00
|
|
|
public function subscriptions(array $spec = null) {
|
|
|
|
if (isset($spec)) {
|
|
|
|
$spec = $this->cleanIdArray($spec);
|
|
|
|
}
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function edition(int $spec = null) {
|
2017-06-18 14:23:37 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2018-10-26 18:58:04 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function article(int $spec = null) {
|
2017-06-18 14:23:37 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2017-07-07 02:53:17 +00:00
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function editions(array $spec = null) {
|
2018-12-05 01:41:21 +00:00
|
|
|
if (isset($spec)) {
|
2019-02-22 16:13:42 +00:00
|
|
|
$spec = $this->cleanIdArray($spec);
|
2017-07-21 02:40:09 +00:00
|
|
|
}
|
2017-07-07 02:53:17 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
2017-08-29 14:50:31 +00:00
|
|
|
public function articles(array $spec = null) {
|
2018-12-05 01:41:21 +00:00
|
|
|
if (isset($spec)) {
|
2019-02-22 16:13:42 +00:00
|
|
|
$spec = $this->cleanIdArray($spec);
|
2017-07-21 02:40:09 +00:00
|
|
|
}
|
2017-07-07 02:53:17 +00:00
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2017-10-13 04:04:26 +00:00
|
|
|
|
|
|
|
public function label(int $spec = null) {
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
2019-04-02 13:32:31 +00:00
|
|
|
public function labels(array $spec = null) {
|
|
|
|
if (isset($spec)) {
|
|
|
|
$spec = $this->cleanIdArray($spec);
|
|
|
|
}
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
2017-10-13 04:04:26 +00:00
|
|
|
public function labelName(string $spec = null) {
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
2019-04-02 13:32:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function labelNames(array $spec = null) {
|
|
|
|
if (isset($spec)) {
|
|
|
|
$spec = $this->cleanStringArray($spec);
|
|
|
|
}
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
2017-10-13 04:04:26 +00:00
|
|
|
}
|
2017-11-16 20:56:14 +00:00
|
|
|
|
2019-02-24 01:14:52 +00:00
|
|
|
public function annotationTerms(array $spec = null) {
|
|
|
|
if (isset($spec)) {
|
|
|
|
$spec = $this->cleanStringArray($spec);
|
|
|
|
}
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
2019-02-22 16:13:42 +00:00
|
|
|
public function searchTerms(array $spec = null) {
|
|
|
|
if (isset($spec)) {
|
|
|
|
$spec = $this->cleanStringArray($spec);
|
|
|
|
}
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2019-02-25 15:46:43 +00:00
|
|
|
|
|
|
|
public function titleTerms(array $spec = null) {
|
|
|
|
if (isset($spec)) {
|
|
|
|
$spec = $this->cleanStringArray($spec);
|
|
|
|
}
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function authorTerms(array $spec = null) {
|
|
|
|
if (isset($spec)) {
|
|
|
|
$spec = $this->cleanStringArray($spec);
|
|
|
|
}
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2019-02-26 16:11:42 +00:00
|
|
|
|
|
|
|
public function latestArticle(int $spec = null) {
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function oldestArticle(int $spec = null) {
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function latestEdition(int $spec = null) {
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function oldestEdition(int $spec = null) {
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function modifiedSince($spec = null) {
|
|
|
|
$spec = Date::normalize($spec);
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function notModifiedSince($spec = null) {
|
|
|
|
$spec = Date::normalize($spec);
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function markedSince($spec = null) {
|
|
|
|
$spec = Date::normalize($spec);
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function notMarkedSince($spec = null) {
|
|
|
|
$spec = Date::normalize($spec);
|
|
|
|
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
|
|
|
}
|
2017-08-29 14:50:31 +00:00
|
|
|
}
|