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        $nameToFilterOn = $useTitle ? $file['title'] : noNS($file['id']);
53        $pregOn = $useTitle ? $this->pregTitleOn : $this->pregOn;
54        $pregOff = $useTitle ? $this->pregTitleOff : $this->pregOff;
55
56        if (in_array($nameToFilterOn, $this->excludedFiles)) {
57            return false;
58        }
59        foreach($pregOn as $preg) {
60            if (!preg_match($preg, $nameToFilterOn)) {
61                return false;
62            }
63        }
64        foreach($pregOff as $preg) {
65            if (preg_match($preg, $nameToFilterOn)) {
66                return false;
67            }
68        }
69        return true;
70    }
71
72    abstract function prepareFile(&$file);
73    abstract function prepareFileTitle(&$file);
74}
75