1<?php
2/**
3 * Plugin nspages : Displays nicely a list of the pages of a namespace
4 *
5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
6 */
7if(!defined('DOKU_INC')) die();
8
9abstract class filePreparer {
10    /**
11     * Array  A list of files that shouldn't be displayed
12     */
13    private $excludedFiles;
14
15    /**
16     * Array  RegEx that a file should match to be displayed
17     */
18    private $pregOn;
19    private $pregTitleOn;
20
21    /**
22     * Array  RegEx that a file shouldn't match to be displayed
23     */
24    private $pregOff;
25    private $pregTitleOff;
26
27    protected $useTitle;
28    protected $useIdAndTitle;
29    protected $sortPageByDate;
30    protected $sortByCreationDate;
31
32    /**
33     * bool
34     */
35    protected $sortPageById;
36
37    function __construct($excludedFiles, $pregOn, $pregOff, $pregTitleOn, $pregTitleOff, $useTitle, $sortPageById,
38                         $useIdAndTitle, $sortPageByDate, $sortByCreationDate){
39        $this->excludedFiles = $excludedFiles;
40        $this->pregOn = $pregOn;
41        $this->pregOff = $pregOff;
42        $this->pregTitleOn = $pregTitleOn;
43        $this->pregTitleOff = $pregTitleOff;
44        $this->useTitle = $useTitle;
45        $this->sortPageById = $sortPageById;
46        $this->useIdAndTitle = $useIdAndTitle;
47        $this->sortPageByDate = $sortPageByDate;
48        $this->sortByCreationDate = $sortByCreationDate;
49    }
50
51    function isFileWanted($file, $useTitle) {
52        $wanted = true;
53        $nameToFilterOn = $useTitle ? $file['title'] : noNS($file['id']);
54        $pregOn = $useTitle ? $this->pregTitleOn : $this->pregOn;
55        $pregOff = $useTitle ? $this->pregTitleOff : $this->pregOff;
56
57        $wanted &= (!in_array($nameToFilterOn, $this->excludedFiles));
58        foreach($pregOn as $preg) {
59            $wanted &= preg_match($preg, $nameToFilterOn);
60        }
61        foreach($pregOff as $preg) {
62            $wanted &= !preg_match($preg, $nameToFilterOn);
63        }
64        return $wanted;
65    }
66
67    abstract function prepareFile(&$file);
68    abstract function prepareFileTitle(&$file);
69}
70