1<?php
2
3class helper_plugin_gdpr_utils extends DokuWiki_Plugin
4{
5
6
7    /**
8     * Recursively collect all (page|media) changlogs within the current directory
9     *
10     * @param Directory $dir
11     *
12     * @return string[] filenames of changelogs in the current directory and subdirectories
13     */
14    public function collectChangelogs(Directory $dir)
15    {
16        $changlogs = [];
17        while (false !== ($entry = $dir->read())) {
18            if ($entry === '.' || $entry === '..') {
19                continue;
20            }
21            $fn = $dir->path . '/' . $entry;
22            if (is_dir($fn)) {
23                $changlogs = array_merge($changlogs, $this->collectChangelogs(dir($fn)));
24                continue;
25            }
26            list($extension, $basename) = explode('.', strrev($entry), 2);
27            $extension = strrev($extension);
28            $basename = strrev($basename);
29            if ($extension !== 'changes') {
30                continue;
31            }
32            if ($basename[0] === '_') {
33                continue;
34            }
35            $changlogs[] = $dir->path . '/' . $entry;
36        }
37        return $changlogs;
38    }
39}
40