diff --git a/homepage/cwsvJudo/src/pages/test/phpLibs/cwsvJudo/news.php b/homepage/cwsvJudo/src/pages/test/phpLibs/cwsvJudo/news.php new file mode 100644 index 0000000..0af3193 --- /dev/null +++ b/homepage/cwsvJudo/src/pages/test/phpLibs/cwsvJudo/news.php @@ -0,0 +1,88 @@ +["flags"=> FILTER_NULL_ON_FAILURE]]; + + if (!is_null($min) && !is_null($max)){ + if( $min > $max ){ + swap($min, $max); + } + } + + if(!is_null($min)){ + $options["options"]["min_range"] = $min; + } + + if(!is_null($max)){ + $options["options"]["max_range"] = $max; + } + + return filter_var( + $value, + FILTER_VALIDATE_INT, + $options, + ); + +} + +function filter_integer(mixed $value) : ?int { + return filter_integer_range($value); +} + +function filter_id(mixed $value, int $min = 0) : ?int { + return filter_integer_range($value, $min, null); +} + +function filter_url(mixed $value){ + return filter_var( + $value, + FILTER_VALIDATE_URL, + ["options" => ["flags" => FILTER_NULL_ON_FAILURE]] + ); +} + +class PromoImage { + public function __construct(array $data) { + $this->src = filter_url($data["src"]); + $this->height = filter_integer_range( + value: $data["height"], + min: 0, + max: null + ); + $this->width = filter_integer_range($data["width"], 0, null); + } + + public function to_json(){ + return json_encode( + value: [ + "src" => $this->src, + "width" => $this->width, + "height" => $this->height + ] + ); + } + + private string $src; + private int $width; + private int $height; +} + +// a single news entry +class Entry{ + + // private + private int $id; + private \DateTime $date; + private string $title; + private string $content; + private string $author; + private PromoImage $promo; +} \ No newline at end of file