Merge pull request #39 from cosmocode/refactor
Major Refactoring, Clean-Up and Simplification
This commit is contained in:
2
.gitattributes
vendored
Normal file
2
.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/.* export-ignore
|
||||
/_test export-ignore
|
||||
11
.github/workflows/dokuwiki.yml
vendored
Normal file
11
.github/workflows/dokuwiki.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
name: DokuWiki Default Tasks
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: '58 2 25 * *'
|
||||
|
||||
|
||||
jobs:
|
||||
all:
|
||||
uses: dokuwiki/github-action/.github/workflows/all.yml@main
|
||||
13
.travis.yml
13
.travis.yml
@@ -1,13 +0,0 @@
|
||||
language: php
|
||||
php:
|
||||
- "7.0"
|
||||
- "5.6"
|
||||
# - "5.5"
|
||||
# - "5.4"
|
||||
# - "5.3"
|
||||
env:
|
||||
- DOKUWIKI=master
|
||||
- DOKUWIKI=stable
|
||||
before_install: wget https://raw.github.com/splitbrain/dokuwiki-travis/master/travis.sh
|
||||
install: sh travis.sh
|
||||
script: cd _test && phpunit --stderr --group plugin_filelist
|
||||
191
Crawler.php
Normal file
191
Crawler.php
Normal file
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\filelist;
|
||||
|
||||
class Crawler
|
||||
{
|
||||
/** @var string regexp to check extensions */
|
||||
protected $ext;
|
||||
|
||||
/** @var string */
|
||||
protected $sortby = 'name';
|
||||
|
||||
/** @var bool */
|
||||
protected $sortreverse = false;
|
||||
|
||||
/**
|
||||
* Initializes the crawler
|
||||
*
|
||||
* @param string $extensions The extensions to allow (comma separated list)
|
||||
*/
|
||||
public function __construct($extensions)
|
||||
{
|
||||
$this->ext = explode(',', $extensions);
|
||||
$this->ext = array_map('trim', $this->ext);
|
||||
$this->ext = array_map('preg_quote_cb', $this->ext);
|
||||
$this->ext = implode('|', $this->ext);
|
||||
}
|
||||
|
||||
public function setSortBy($sortby)
|
||||
{
|
||||
$this->sortby = $sortby;
|
||||
}
|
||||
|
||||
public function setSortReverse($sortreverse)
|
||||
{
|
||||
$this->sortreverse = $sortreverse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does a (recursive) crawl for finding files based on a given pattern.
|
||||
* Based on a safe glob reimplementation using fnmatch and opendir.
|
||||
*
|
||||
* @param string $path the path to search in
|
||||
* @param string $pattern the pattern to match to
|
||||
* @param bool $recursive whether to search recursively
|
||||
* @param string $titlefile the name of the title file
|
||||
* @return array a hierarchical filelist or false if nothing could be found
|
||||
*
|
||||
* @see http://www.php.net/manual/en/function.glob.php#71083
|
||||
*/
|
||||
public function crawl($root, $local, $pattern, $recursive, $titlefile)
|
||||
{
|
||||
$path = $root . $local;
|
||||
|
||||
if (($dir = opendir($path)) === false) return [];
|
||||
$result = [];
|
||||
while (($file = readdir($dir)) !== false) {
|
||||
if ($file[0] == '.' || $file == $titlefile) {
|
||||
// ignore hidden, system and title files
|
||||
continue;
|
||||
}
|
||||
$self = $local . '/' . $file;
|
||||
$filepath = $path . '/' . $file;
|
||||
if (!is_readable($filepath)) continue;
|
||||
|
||||
if ($this->fnmatch($pattern, $file) || (is_dir($filepath) && $recursive)) {
|
||||
if (!is_dir($filepath) && !$this->isExtensionAllowed($file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// get title file
|
||||
$filename = $file;
|
||||
if (is_dir($filepath)) {
|
||||
$title = $filepath . '/' . $titlefile;
|
||||
if (is_readable($title)) {
|
||||
$filename = io_readFile($title, false);
|
||||
}
|
||||
}
|
||||
|
||||
// prepare entry
|
||||
if (!is_dir($filepath) || $recursive) {
|
||||
$entry = [
|
||||
'name' => $filename,
|
||||
'local' => $self,
|
||||
'path' => $filepath,
|
||||
'mtime' => filemtime($filepath),
|
||||
'ctime' => filectime($filepath),
|
||||
'size' => filesize($filepath),
|
||||
'children' => ((is_dir($filepath) && $recursive) ?
|
||||
$this->crawl($root, $self, $pattern, $recursive, $titlefile) :
|
||||
false
|
||||
),
|
||||
'treesize' => 0,
|
||||
];
|
||||
|
||||
// calculate tree size
|
||||
if ($entry['children'] !== false) {
|
||||
foreach ($entry['children'] as $child) {
|
||||
$entry['treesize'] += $child['treesize'];
|
||||
}
|
||||
} else {
|
||||
$entry['treesize'] = 1;
|
||||
}
|
||||
|
||||
// add entry to result
|
||||
$result[] = $entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
return $this->sortItems($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the given items by the current sortby and sortreverse settings
|
||||
*
|
||||
* @param array $items
|
||||
* @return array
|
||||
*/
|
||||
protected function sortItems($items)
|
||||
{
|
||||
$callback = [$this, 'compare' . ucfirst($this->sortby)];
|
||||
if (!is_callable($callback)) return $items;
|
||||
|
||||
usort($items, $callback);
|
||||
if ($this->sortreverse) {
|
||||
$items = array_reverse($items);
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a file is allowed by the configured extensions
|
||||
*
|
||||
* @param string $file
|
||||
* @return bool
|
||||
*/
|
||||
protected function isExtensionAllowed($file)
|
||||
{
|
||||
if ($this->ext === '') return true; // no restriction
|
||||
return preg_match('/(' . $this->ext . ')$/i', $file);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replacement for fnmatch() for windows systems.
|
||||
*
|
||||
* @author jk at ricochetsolutions dot com
|
||||
* @link http://www.php.net/manual/en/function.fnmatch.php#71725
|
||||
*/
|
||||
protected function fnmatch($pattern, $string)
|
||||
{
|
||||
return preg_match(
|
||||
"#^" . strtr(
|
||||
preg_quote($pattern, '#'),
|
||||
[
|
||||
'\*' => '.*',
|
||||
'\?' => '.',
|
||||
'\[' => '[',
|
||||
'\]' => ']'
|
||||
]
|
||||
) . "$#i",
|
||||
$string
|
||||
);
|
||||
}
|
||||
|
||||
public function compareName($a, $b)
|
||||
{
|
||||
return strcmp($a['name'], $b['name']);
|
||||
}
|
||||
|
||||
public function compareIname($a, $b)
|
||||
{
|
||||
return strcmp(strtolower($a['name']), strtolower($b['name']));
|
||||
}
|
||||
|
||||
public function compareCtime($a, $b)
|
||||
{
|
||||
return $a['ctime'] <=> $b['ctime'];
|
||||
}
|
||||
|
||||
public function compareMtime($a, $b)
|
||||
{
|
||||
return $a['mtime'] <=> $b['mtime'];
|
||||
}
|
||||
|
||||
public function compareSize($a, $b)
|
||||
{
|
||||
return $a['size'] <=> $b['size'];
|
||||
}
|
||||
}
|
||||
339
LICENSE
Normal file
339
LICENSE
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
283
Output.php
Normal file
283
Output.php
Normal file
@@ -0,0 +1,283 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\filelist;
|
||||
|
||||
class Output
|
||||
{
|
||||
/** @var \Doku_Renderer */
|
||||
protected $renderer;
|
||||
|
||||
/** @var string */
|
||||
protected $basedir;
|
||||
|
||||
/** @var string */
|
||||
protected $webdir;
|
||||
|
||||
/** @var array */
|
||||
protected $files;
|
||||
|
||||
|
||||
public function __construct(\Doku_Renderer $renderer, $basedir, $webdir, $files)
|
||||
{
|
||||
$this->renderer = $renderer;
|
||||
$this->basedir = $basedir;
|
||||
$this->webdir = $webdir;
|
||||
$this->files = $files;
|
||||
}
|
||||
|
||||
public function renderAsList($params)
|
||||
{
|
||||
if ($this->renderer instanceof \Doku_Renderer_xhtml) {
|
||||
$this->renderer->doc .= '<div class="filelist-plugin">';
|
||||
}
|
||||
|
||||
$this->renderListItems($this->files, $params);
|
||||
|
||||
if ($this->renderer instanceof \Doku_Renderer_xhtml) {
|
||||
$this->renderer->doc .= '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the files as a table, including details if configured that way.
|
||||
*
|
||||
* @param array $params the parameters of the filelist call
|
||||
*/
|
||||
public function renderAsTable($params)
|
||||
{
|
||||
if ($this->renderer instanceof \Doku_Renderer_xhtml) {
|
||||
$this->renderer->doc .= '<div class="filelist-plugin">';
|
||||
}
|
||||
|
||||
$items = $this->flattenResultTree($this->files);
|
||||
$this->renderTableItems($items, $params);
|
||||
|
||||
if ($this->renderer instanceof \Doku_Renderer_xhtml) {
|
||||
$this->renderer->doc .= '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renders the files as a table, including details if configured that way.
|
||||
*
|
||||
* @param array $params the parameters of the filelist call
|
||||
*/
|
||||
protected function renderTableItems($items, $params)
|
||||
{
|
||||
|
||||
$renderer = $this->renderer;
|
||||
|
||||
|
||||
// count the columns
|
||||
$columns = 1;
|
||||
if ($params['showsize']) {
|
||||
$columns++;
|
||||
}
|
||||
if ($params['showdate']) {
|
||||
$columns++;
|
||||
}
|
||||
|
||||
$renderer->table_open($columns);
|
||||
|
||||
if ($params['tableheader']) {
|
||||
$renderer->tablethead_open();
|
||||
$renderer->tablerow_open();
|
||||
|
||||
$renderer->tableheader_open();
|
||||
$renderer->cdata($this->getLang('filename'));
|
||||
$renderer->tableheader_close();
|
||||
|
||||
if ($params['showsize']) {
|
||||
$renderer->tableheader_open();
|
||||
$renderer->cdata($this->getLang('filesize'));
|
||||
$renderer->tableheader_close();
|
||||
}
|
||||
|
||||
if ($params['showdate']) {
|
||||
$renderer->tableheader_open();
|
||||
$renderer->cdata($this->getLang('lastmodified'));
|
||||
$renderer->tableheader_close();
|
||||
}
|
||||
|
||||
$renderer->tablerow_close();
|
||||
$renderer->tablethead_close();
|
||||
}
|
||||
|
||||
$renderer->tabletbody_open();
|
||||
foreach ($items as $item) {
|
||||
$renderer->tablerow_open();
|
||||
$renderer->tablecell_open();
|
||||
$this->renderItemLink($item, $params['randlinks']);
|
||||
$renderer->tablecell_close();
|
||||
|
||||
if ($params['showsize']) {
|
||||
$renderer->tablecell_open(1, 'right');
|
||||
$renderer->cdata(filesize_h($item['size']));
|
||||
$renderer->tablecell_close();
|
||||
}
|
||||
|
||||
if ($params['showdate']) {
|
||||
$renderer->tablecell_open();
|
||||
$renderer->cdata(dformat($item['mtime']));
|
||||
$renderer->tablecell_close();
|
||||
}
|
||||
|
||||
$renderer->tablerow_close();
|
||||
}
|
||||
$renderer->tabletbody_close();
|
||||
$renderer->table_close();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Recursively renders a tree of files as list items.
|
||||
*
|
||||
* @param array $items the files to render
|
||||
* @param array $params the parameters of the filelist call
|
||||
* @param int $level the level to render
|
||||
* @return void
|
||||
*/
|
||||
protected function renderListItems($items, $params, $level = 1)
|
||||
{
|
||||
if ($params['style'] == 'olist') {
|
||||
$this->renderer->listo_open();
|
||||
} else {
|
||||
$this->renderer->listu_open();
|
||||
}
|
||||
|
||||
foreach ($items as $file) {
|
||||
if ($file['children'] === false && $file['treesize'] === 0) continue; // empty directory
|
||||
|
||||
$this->renderer->listitem_open($level);
|
||||
$this->renderer->listcontent_open();
|
||||
|
||||
if ($file['children'] !== false && $file['treesize'] > 0) {
|
||||
// render the directory and its subtree
|
||||
$this->renderer->cdata($file['name']);
|
||||
$this->renderListItems($file['children'], $params, $level + 1);
|
||||
} elseif ($file['children'] === false) {
|
||||
// render the file link
|
||||
$this->renderItemLink($file, $params['randlinks']);
|
||||
|
||||
// render filesize
|
||||
if ($params['showsize']) {
|
||||
$this->renderer->cdata($params['listsep'] . filesize_h($file['size']));
|
||||
}
|
||||
// render lastmodified
|
||||
if ($params['showdate']) {
|
||||
$this->renderer->cdata($params['listsep'] . dformat($file['mtime']));
|
||||
}
|
||||
}
|
||||
|
||||
$this->renderer->listcontent_close();
|
||||
$this->renderer->listitem_close();
|
||||
}
|
||||
|
||||
if ($params['style'] == 'olist') {
|
||||
$this->renderer->listo_close();
|
||||
} else {
|
||||
$this->renderer->listu_close();
|
||||
}
|
||||
}
|
||||
|
||||
protected function renderItemLink($item, $cachebuster = false)
|
||||
{
|
||||
if ($this->renderer instanceof \Doku_Renderer_xhtml) {
|
||||
$this->renderItemLinkXHTML($item, $cachebuster);
|
||||
} else {
|
||||
$this->renderItemLinkAny($item, $cachebuster);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a file link on the XHTML renderer
|
||||
*/
|
||||
protected function renderItemLinkXHTML($item, $cachebuster = false)
|
||||
{
|
||||
global $conf;
|
||||
/** @var \Doku_Renderer_xhtml $renderer */
|
||||
$renderer = $this->renderer;
|
||||
|
||||
//prepare for formating
|
||||
$link['target'] = $conf['target']['extern'];
|
||||
$link['style'] = '';
|
||||
$link['pre'] = '';
|
||||
$link['suf'] = '';
|
||||
$link['more'] = '';
|
||||
$link['url'] = $this->itemWebUrl($item, $cachebuster);
|
||||
$link['name'] = $item['name'];
|
||||
$link['title'] = $renderer->_xmlEntities($link['url']);
|
||||
if ($conf['relnofollow']) $link['more'] .= ' rel="nofollow"';
|
||||
[$ext,] = mimetype(basename($item['local']));
|
||||
$link['class'] = 'media mediafile mf_' . $ext;
|
||||
$renderer->doc .= $renderer->_formatLink($link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a file link on any Renderer
|
||||
* @param array $item
|
||||
* @param bool $cachebuster
|
||||
* @return void
|
||||
*/
|
||||
protected function renderItemLinkAny($item, $cachebuster = false)
|
||||
{
|
||||
$this->renderer->externalmedialink($this->itemWebUrl($item, $cachebuster), $item['name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Web URL for a given item
|
||||
*
|
||||
* @param array $item The item data as returned by the Crawler
|
||||
* @param bool $cachbuster add a cachebuster to the URL?
|
||||
* @return string
|
||||
*/
|
||||
protected function itemWebUrl($item, $cachbuster = false)
|
||||
{
|
||||
if (str_ends_with($this->webdir, '=')) {
|
||||
$url = $this->webdir . rawurlencode($item['local']);
|
||||
} else {
|
||||
$url = $this->webdir . $item['local'];
|
||||
}
|
||||
|
||||
if ($cachbuster) {
|
||||
if (strpos($url, '?') === false) {
|
||||
$url .= '?t=' . $item['mtime'];
|
||||
} else {
|
||||
$url .= '&t=' . $item['mtime'];
|
||||
}
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flattens the filelist by recursively walking through all subtrees and
|
||||
* merging them with a prefix attached to the filenames.
|
||||
*
|
||||
* @param array $items the tree to flatten
|
||||
* @param string $prefix the prefix to attach to all processed nodes
|
||||
* @return array a flattened representation of the tree
|
||||
*/
|
||||
protected function flattenResultTree($items, $prefix = '')
|
||||
{
|
||||
$result = [];
|
||||
foreach ($items as $file) {
|
||||
if ($file['children'] !== false) {
|
||||
$result = array_merge(
|
||||
$result,
|
||||
$this->flattenResultTree($file['children'], $prefix . $file['name'] . '/')
|
||||
);
|
||||
} else {
|
||||
$file['name'] = $prefix . $file['name'];
|
||||
$result[] = $file;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getLang($key)
|
||||
{
|
||||
$syntax = plugin_load('syntax', 'filelist');
|
||||
return $syntax->getLang($key);
|
||||
}
|
||||
}
|
||||
152
Path.php
Normal file
152
Path.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\filelist;
|
||||
|
||||
class Path
|
||||
{
|
||||
protected $paths = [];
|
||||
|
||||
/**
|
||||
* @param string $pathConfig The path configuration ftom the plugin settings
|
||||
*/
|
||||
public function __construct($pathConfig)
|
||||
{
|
||||
$this->paths = $this->parsePathConfig($pathConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Access the parsed paths
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPaths()
|
||||
{
|
||||
return $this->paths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the path configuration into an internal array
|
||||
*
|
||||
* roots (and aliases) are always saved with a trailing slash
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function parsePathConfig($pathConfig)
|
||||
{
|
||||
$paths = [];
|
||||
$lines = explode("\n", $pathConfig);
|
||||
$lastRoot = '';
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
if (empty($line)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (str_starts_with($line, 'A>')) {
|
||||
// this is an alias for the last read root
|
||||
$line = trim(substr($line, 2));
|
||||
if (!isset($paths[$lastRoot])) continue; // no last root, no alias
|
||||
$alias = static::cleanPath($line);
|
||||
$paths[$lastRoot]['alias'] = $alias;
|
||||
$paths[$alias] = &$paths[$lastRoot]; // alias references the original
|
||||
} elseif (str_starts_with($line, 'W>')) {
|
||||
// this is a web path for the last read root
|
||||
$line = trim(substr($line, 2));
|
||||
if (!isset($paths[$lastRoot])) continue; // no last path, no web path
|
||||
$paths[$lastRoot]['web'] = $line;
|
||||
} else {
|
||||
// this is a new path
|
||||
$line = static::cleanPath($line);
|
||||
$lastRoot = $line;
|
||||
$paths[$line] = [
|
||||
'root' => $line,
|
||||
'web' => DOKU_BASE . 'lib/plugins/filelist/file.php?root=' . rawurlencode($line) . '&file=',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $paths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given path is listable and return it's configuration
|
||||
*
|
||||
* @param string $path
|
||||
* @param bool $addTrailingSlash
|
||||
* @return array
|
||||
* @throws \Exception if the given path is not allowed
|
||||
*/
|
||||
public function getPathInfo($path, $addTrailingSlash = true)
|
||||
{
|
||||
$path = static::cleanPath($path, $addTrailingSlash);
|
||||
|
||||
$paths = $this->paths;
|
||||
$allowed = array_keys($paths);
|
||||
usort($allowed, static fn($a, $b) => strlen($a) - strlen($b));
|
||||
$allowed = array_map('preg_quote_cb', $allowed);
|
||||
$regex = '/^(' . implode('|', $allowed) . ')/';
|
||||
|
||||
if (!preg_match($regex, $path, $matches)) {
|
||||
throw new \Exception('Path not allowed: ' . $path);
|
||||
}
|
||||
$match = $matches[1];
|
||||
|
||||
$pathInfo = $paths[$match];
|
||||
$pathInfo['local'] = substr($path, strlen($match));
|
||||
$pathInfo['path'] = $pathInfo['root'] . $pathInfo['local'];
|
||||
|
||||
|
||||
return $pathInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean a path for better comparison
|
||||
*
|
||||
* Converts all backslashes to forward slashes
|
||||
* Keeps leading double backslashes for UNC paths
|
||||
* Ensure a single trailing slash unless disabled
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public static function cleanPath($path, $addTrailingSlash = true)
|
||||
{
|
||||
if (str_starts_with($path, '\\\\')) {
|
||||
$unc = '\\\\';
|
||||
} else {
|
||||
$unc = '';
|
||||
}
|
||||
$path = ltrim($path, '\\');
|
||||
$path = str_replace('\\', '/', $path);
|
||||
$path = self::realpath($path);
|
||||
if ($addTrailingSlash) {
|
||||
$path = rtrim($path, '/');
|
||||
$path .= '/';
|
||||
}
|
||||
|
||||
return $unc . $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Canonicalizes a given path. A bit like realpath, but without the resolving of symlinks.
|
||||
*
|
||||
* @author anonymous
|
||||
* @see <http://www.php.net/manual/en/function.realpath.php#73563>
|
||||
*/
|
||||
public static function realpath($path)
|
||||
{
|
||||
$path = explode('/', $path);
|
||||
$output = [];
|
||||
$counter = count($path);
|
||||
for ($i = 0; $i < $counter; $i++) {
|
||||
if ('.' == $path[$i]) continue;
|
||||
if ('' === $path[$i] && $i > 0) continue;
|
||||
if ('..' == $path[$i] && '..' != ($output[count($output) - 1] ?? '')) {
|
||||
array_pop($output);
|
||||
continue;
|
||||
}
|
||||
$output[] = $path[$i];
|
||||
}
|
||||
return implode('/', $output);
|
||||
}
|
||||
}
|
||||
30
README
30
README
@@ -1,9 +1,27 @@
|
||||
====== Filelist Plugin for DokuWiki ======
|
||||
filelist plugin for DokuWiki
|
||||
|
||||
All documentation for the Filelist Plugin is available online at:
|
||||
Lists files matching a given glob pattern.
|
||||
|
||||
* https://dokuwiki.org/plugin:filelist
|
||||
All documentation for this plugin can be found at
|
||||
https://www.dokuwiki.org/plugin:filelist
|
||||
|
||||
(c) 2007 - 2012 by Gina Häußge
|
||||
(c) 2012 - 2016 by Dokufreaks
|
||||
See COPYING for license info.
|
||||
If you install this plugin manually, make sure it is installed in
|
||||
lib/plugins/filelist/ - if the folder is called different it
|
||||
will not work!
|
||||
|
||||
Please refer to http://www.dokuwiki.org/extensions for additional info
|
||||
on how to install extensions in DokuWiki.
|
||||
|
||||
----
|
||||
Copyright (C) Gina Häußge, Dokufreaks <gina@foosel.net, freaks@dokuwiki.org>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; version 2 of the License
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
See the LICENSING file for details
|
||||
|
||||
86
_test/GeneralTest.php
Normal file
86
_test/GeneralTest.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\filelist\test;
|
||||
|
||||
use DokuWikiTest;
|
||||
|
||||
/**
|
||||
* General tests for the filelist plugin
|
||||
*
|
||||
* @group plugin_filelist
|
||||
* @group plugins
|
||||
*/
|
||||
class GeneralTest extends DokuWikiTest
|
||||
{
|
||||
|
||||
/**
|
||||
* Simple test to make sure the plugin.info.txt is in correct format
|
||||
*/
|
||||
public function testPluginInfo(): void
|
||||
{
|
||||
$file = __DIR__ . '/../plugin.info.txt';
|
||||
$this->assertFileExists($file);
|
||||
|
||||
$info = confToHash($file);
|
||||
|
||||
$this->assertArrayHasKey('base', $info);
|
||||
$this->assertArrayHasKey('author', $info);
|
||||
$this->assertArrayHasKey('email', $info);
|
||||
$this->assertArrayHasKey('date', $info);
|
||||
$this->assertArrayHasKey('name', $info);
|
||||
$this->assertArrayHasKey('desc', $info);
|
||||
$this->assertArrayHasKey('url', $info);
|
||||
|
||||
$this->assertEquals('filelist', $info['base']);
|
||||
$this->assertRegExp('/^https?:\/\//', $info['url']);
|
||||
$this->assertTrue(mail_isvalid($info['email']));
|
||||
$this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']);
|
||||
$this->assertTrue(false !== strtotime($info['date']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to ensure that every conf['...'] entry in conf/default.php has a corresponding meta['...'] entry in
|
||||
* conf/metadata.php.
|
||||
*/
|
||||
public function testPluginConf(): void
|
||||
{
|
||||
$conf_file = __DIR__ . '/../conf/default.php';
|
||||
$meta_file = __DIR__ . '/../conf/metadata.php';
|
||||
|
||||
if (!file_exists($conf_file) && !file_exists($meta_file)) {
|
||||
self::markTestSkipped('No config files exist -> skipping test');
|
||||
}
|
||||
|
||||
if (file_exists($conf_file)) {
|
||||
include($conf_file);
|
||||
}
|
||||
if (file_exists($meta_file)) {
|
||||
include($meta_file);
|
||||
}
|
||||
|
||||
$this->assertEquals(
|
||||
gettype($conf),
|
||||
gettype($meta),
|
||||
'Both ' . DOKU_PLUGIN . 'filelist/conf/default.php and ' . DOKU_PLUGIN . 'filelist/conf/metadata.php have to exist and contain the same keys.'
|
||||
);
|
||||
|
||||
if ($conf !== null && $meta !== null) {
|
||||
foreach ($conf as $key => $value) {
|
||||
$this->assertArrayHasKey(
|
||||
$key,
|
||||
$meta,
|
||||
'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'filelist/conf/metadata.php'
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($meta as $key => $value) {
|
||||
$this->assertArrayHasKey(
|
||||
$key,
|
||||
$conf,
|
||||
'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'filelist/conf/default.php'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
113
_test/PathTest.php
Normal file
113
_test/PathTest.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\filelist\test;
|
||||
|
||||
use dokuwiki\plugin\filelist\Path;
|
||||
use DokuWikiTest;
|
||||
|
||||
/**
|
||||
* Path related tests for the filelist plugin
|
||||
*
|
||||
* @group plugin_filelist
|
||||
* @group plugins
|
||||
*/
|
||||
class PathTest extends DokuWikiTest
|
||||
{
|
||||
|
||||
protected $path;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->path = new Path(
|
||||
<<<EOT
|
||||
C:\\xampp\\htdocs\\wiki\\
|
||||
\\\\server\\share\\path\\
|
||||
/linux/file/path/
|
||||
/linux/another/path/../..//another/blargh/../path
|
||||
A> alias
|
||||
W> webfoo
|
||||
EOT
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the configuration parsing for paths and aliases
|
||||
*/
|
||||
public function testGetPaths()
|
||||
{
|
||||
$expect = [
|
||||
'C:/xampp/htdocs/wiki/' => [
|
||||
'root' => 'C:/xampp/htdocs/wiki/',
|
||||
'web' => '/lib/plugins/filelist/file.php?root=C%3A%2Fxampp%2Fhtdocs%2Fwiki%2F&file=',
|
||||
],
|
||||
'\\\\server/share/path/' => [
|
||||
'root' => '\\\\server/share/path/',
|
||||
'web' => '/lib/plugins/filelist/file.php?root=%5C%5Cserver%2Fshare%2Fpath%2F&file=',
|
||||
],
|
||||
'/linux/file/path/' => [
|
||||
'root' => '/linux/file/path/',
|
||||
'web' => '/lib/plugins/filelist/file.php?root=%2Flinux%2Ffile%2Fpath%2F&file=',
|
||||
],
|
||||
'/linux/another/path/' => [
|
||||
'root' => '/linux/another/path/',
|
||||
'alias' => 'alias/',
|
||||
'web' => 'webfoo',
|
||||
],
|
||||
'alias/' => [
|
||||
'root' => '/linux/another/path/',
|
||||
'alias' => 'alias/',
|
||||
'web' => 'webfoo',
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($expect, $this->path->getPaths());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetPathInfoSuccess
|
||||
*/
|
||||
public function providePathInfoSuccess()
|
||||
{
|
||||
return [
|
||||
['/linux/another/path', '/linux/another/path/'],
|
||||
['/linux/another/path/foo', '/linux/another/path/foo/'],
|
||||
['alias', '/linux/another/path/'],
|
||||
['alias/foo', '/linux/another/path/foo/'],
|
||||
['C:\\xampp\\htdocs\\wiki', 'C:/xampp/htdocs/wiki/'],
|
||||
['C:\\xampp\\htdocs\\wiki\\foo', 'C:/xampp/htdocs/wiki/foo/'],
|
||||
['\\\\server\\share\\path\\', '\\\\server/share/path/'],
|
||||
['\\\\server\\share\\path\\foo', '\\\\server/share/path/foo/'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providePathInfoSuccess
|
||||
*/
|
||||
public function testGetPathInfoSuccess($path, $expect)
|
||||
{
|
||||
$pathInfo = $this->path->getPathInfo($path);
|
||||
$this->assertEquals($expect, $pathInfo['path']);
|
||||
}
|
||||
|
||||
public function providePathInfoFailure()
|
||||
{
|
||||
return [
|
||||
['/linux/file/path/../../../etc/'],
|
||||
['W:\\xampp\\htdocs\\wiki\\foo\\bar'],
|
||||
['/'],
|
||||
['./'],
|
||||
['../'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providePathInfoFailure
|
||||
*/
|
||||
public function testGetPathInfoFailure($path)
|
||||
{
|
||||
$this->expectExceptionMessageMatches('/Path not allowed/');
|
||||
$this->path->getPathInfo($path);
|
||||
}
|
||||
}
|
||||
195
_test/SyntaxTest.php
Normal file
195
_test/SyntaxTest.php
Normal file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
namespace dokuwiki\plugin\filelist\test;
|
||||
|
||||
use DokuWikiTest;
|
||||
use DOMWrap\Document;
|
||||
|
||||
|
||||
/**
|
||||
* Tests for the filelist plugin.
|
||||
*
|
||||
* These test assume that the directory filelist has the following content:
|
||||
* - exampledir (directory)
|
||||
* - example2.txt (text file)
|
||||
* - example.txt (text file)
|
||||
* - exampleimage.png (image file)
|
||||
*
|
||||
* @group plugin_filelist
|
||||
* @group plugins
|
||||
*/
|
||||
class plugin_filelist_test extends DokuWikiTest
|
||||
{
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$this->pluginsEnabled[] = 'filelist';
|
||||
parent::setUp();
|
||||
|
||||
// Setup config so that access to the TMP directory will be allowed
|
||||
$conf ['plugin']['filelist']['paths'] = TMP_DIR . '/filelistdata/' . "\n" . 'W> http://localhost/';
|
||||
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
// copy test files to test directory
|
||||
\TestUtils::rcopy(TMP_DIR, dirname(__FILE__) . '/filelistdata');
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a list of checks on the given document
|
||||
*
|
||||
* @param Document $doc
|
||||
* @param array $structure Array of selectors and expected count or content
|
||||
* @return void
|
||||
*/
|
||||
protected function structureCheck(Document $doc, $structure)
|
||||
{
|
||||
foreach ($structure as $selector => $expected) {
|
||||
if (is_numeric($expected)) {
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$doc->find($selector)->count(),
|
||||
'Selector ' . $selector . ' not found'
|
||||
);
|
||||
} else {
|
||||
$this->assertStringContainsString(
|
||||
$expected,
|
||||
$doc->find($selector)->text(),
|
||||
'Selector ' . $selector . ' not found'
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function checks that all files are listed in not recursive mode.
|
||||
*/
|
||||
public function test_not_recursive()
|
||||
{
|
||||
global $conf;
|
||||
|
||||
// Render filelist
|
||||
$instructions = p_get_instructions('{{filelist>' . TMP_DIR . '/filelistdata/*&style=list&direct=1}}');
|
||||
$xhtml = p_render('xhtml', $instructions, $info);
|
||||
|
||||
// We should find:
|
||||
// - example.txt
|
||||
// - exampleimage.png
|
||||
$result = strpos($xhtml, 'example.txt');
|
||||
$this->assertFalse($result === false, '"example.txt" not listed');
|
||||
$result = strpos($xhtml, 'exampleimage.png');
|
||||
$this->assertFalse($result === false, '"exampleimage.png" not listed');
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks that all files are listed in recursive mode.
|
||||
*/
|
||||
public function test_recursive()
|
||||
{
|
||||
// Render filelist
|
||||
$instructions = p_get_instructions('{{filelist>' . TMP_DIR . '/filelistdata/*&style=list&direct=1&recursive=1}}');
|
||||
$xhtml = p_render('xhtml', $instructions, $info);
|
||||
|
||||
// We should find:
|
||||
// - exampledir
|
||||
// - example2.txt
|
||||
// - example.txt
|
||||
// - exampleimage.png
|
||||
$result = strpos($xhtml, 'exampledir');
|
||||
$this->assertFalse($result === false, '"exampledir" not listed');
|
||||
$result = strpos($xhtml, 'example2.txt');
|
||||
$this->assertFalse($result === false, '"example2.txt" not listed');
|
||||
$result = strpos($xhtml, 'example.txt');
|
||||
$this->assertFalse($result === false, '"example.txt" not listed');
|
||||
$result = strpos($xhtml, 'exampleimage.png');
|
||||
$this->assertFalse($result === false, '"exampleimage.png" not listed');
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks that the unordered list mode
|
||||
* generates the expected XHTML structure.
|
||||
*/
|
||||
public function testUnorderedList()
|
||||
{
|
||||
// Render filelist
|
||||
$instructions = p_get_instructions('{{filelist>' . TMP_DIR . '/filelistdata/*&style=list&direct=1&recursive=1}}');
|
||||
$xhtml = p_render('xhtml', $instructions, $info);
|
||||
|
||||
$doc = new Document();
|
||||
$doc->html($xhtml);
|
||||
|
||||
$structure = [
|
||||
'div.filelist-plugin' => 1,
|
||||
'div.filelist-plugin > ul' => 1,
|
||||
'div.filelist-plugin > ul > li' => 3,
|
||||
'div.filelist-plugin > ul > li:nth-child(1)' => 1,
|
||||
'div.filelist-plugin > ul > li:nth-child(1) a' => 'example.txt',
|
||||
'div.filelist-plugin > ul > li:nth-child(2) ul' => 1,
|
||||
'div.filelist-plugin > ul > li:nth-child(2) ul > li' => 1,
|
||||
'div.filelist-plugin > ul > li:nth-child(2) ul > li a' => 'example2.txt',
|
||||
];
|
||||
|
||||
$this->structureCheck($doc, $structure);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks that the ordered list mode
|
||||
* generates the expected XHTML structure.
|
||||
*/
|
||||
public function testOrderedList()
|
||||
{
|
||||
// Render filelist
|
||||
$instructions = p_get_instructions('{{filelist>' . TMP_DIR . '/filelistdata/*&style=olist&direct=1&recursive=1}}');
|
||||
$xhtml = p_render('xhtml', $instructions, $info);
|
||||
|
||||
$doc = new Document();
|
||||
$doc->html($xhtml);
|
||||
|
||||
$structure = [
|
||||
'div.filelist-plugin' => 1,
|
||||
'div.filelist-plugin > ol' => 1,
|
||||
'div.filelist-plugin > ol > li' => 3,
|
||||
'div.filelist-plugin > ol > li:nth-child(1)' => 1,
|
||||
'div.filelist-plugin > ol > li:nth-child(1) a' => 'example.txt',
|
||||
'div.filelist-plugin > ol > li:nth-child(2) ol' => 1,
|
||||
'div.filelist-plugin > ol > li:nth-child(2) ol > li' => 1,
|
||||
'div.filelist-plugin > ol > li:nth-child(2) ol > li a' => 'example2.txt',
|
||||
];
|
||||
|
||||
$this->structureCheck($doc, $structure);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks that the table mode
|
||||
* generates the expected XHTML structure.
|
||||
*/
|
||||
public function test_table()
|
||||
{
|
||||
global $conf;
|
||||
|
||||
// Render filelist
|
||||
$instructions = p_get_instructions('{{filelist>' . TMP_DIR . '/filelistdata/*&style=table&direct=1&recursive=1}}');
|
||||
$xhtml = p_render('xhtml', $instructions, $info);
|
||||
|
||||
$doc = new Document();
|
||||
$doc->html($xhtml);
|
||||
|
||||
$structure = [
|
||||
'div.filelist-plugin' => 1,
|
||||
'div.filelist-plugin table' => 1,
|
||||
'div.filelist-plugin table > tbody > tr' => 3,
|
||||
'div.filelist-plugin table > tbody > tr:nth-child(1) a' => 'example.txt',
|
||||
'div.filelist-plugin table > tbody > tr:nth-child(2) a' => 'exampledir/example2.txt',
|
||||
'div.filelist-plugin table > tbody > tr:nth-child(3) a' => 'exampleimage.png',
|
||||
];
|
||||
|
||||
$this->structureCheck($doc, $structure);
|
||||
}
|
||||
}
|
||||
@@ -1,407 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Tests for the filelist plugin.
|
||||
*
|
||||
* These test assume that the directory filelist has the following content:
|
||||
* - exampledir (directory)
|
||||
* - example2.txt (text file)
|
||||
* - example.txt (text file)
|
||||
* - exampleimage.png (image file)
|
||||
*
|
||||
* @group plugin_filelist
|
||||
* @group plugins
|
||||
*/
|
||||
class plugin_filelist_test extends DokuWikiTest {
|
||||
public function setUp() {
|
||||
global $conf;
|
||||
|
||||
$this->pluginsEnabled[] = 'filelist';
|
||||
parent::setUp();
|
||||
|
||||
// Setup config so that access to the TMP directory will be allowed
|
||||
$conf ['plugin']['filelist']['allowed_absolute_paths'] = TMP_DIR.'/filelistdata/';
|
||||
$conf ['plugin']['filelist']['web_paths'] = 'http://localhost/';
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass(){
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
// copy test files to test directory
|
||||
TestUtils::rcopy(TMP_DIR, dirname(__FILE__) . '/filelistdata');
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks that all files are listed in not recursive mode.
|
||||
*/
|
||||
public function test_not_recursive () {
|
||||
global $conf;
|
||||
|
||||
// Render filelist
|
||||
$instructions = p_get_instructions('{{filelist>'.TMP_DIR.'/filelistdata/*&style=list&direct=1}}');
|
||||
$xhtml = p_render('xhtml', $instructions, $info);
|
||||
|
||||
// We should find:
|
||||
// - example.txt
|
||||
// - exampleimage.png
|
||||
$result = strpos ($xhtml, 'example.txt');
|
||||
$this->assertFalse($result===false, '"example.txt" not listed');
|
||||
$result = strpos ($xhtml, 'exampleimage.png');
|
||||
$this->assertFalse($result===false, '"exampleimage.png" not listed');
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks that all files are listed in recursive mode.
|
||||
*/
|
||||
public function test_recursive () {
|
||||
global $conf;
|
||||
|
||||
// Render filelist
|
||||
$instructions = p_get_instructions('{{filelist>'.TMP_DIR.'/filelistdata/*&style=list&direct=1&recursive=1}}');
|
||||
$xhtml = p_render('xhtml', $instructions, $info);
|
||||
|
||||
// We should find:
|
||||
// - exampledir
|
||||
// - example2.txt
|
||||
// - example.txt
|
||||
// - exampleimage.png
|
||||
$result = strpos ($xhtml, 'exampledir');
|
||||
$this->assertFalse($result===false, '"exampledir" not listed');
|
||||
$result = strpos ($xhtml, 'example2.txt');
|
||||
$this->assertFalse($result===false, '"example2.txt" not listed');
|
||||
$result = strpos ($xhtml, 'example.txt');
|
||||
$this->assertFalse($result===false, '"example.txt" not listed');
|
||||
$result = strpos ($xhtml, 'exampleimage.png');
|
||||
$this->assertFalse($result===false, '"exampleimage.png" not listed');
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks that the unordered list mode
|
||||
* generates the expected XHTML structure.
|
||||
*/
|
||||
public function test_list () {
|
||||
global $conf;
|
||||
|
||||
// Render filelist
|
||||
$instructions = p_get_instructions('{{filelist>'.TMP_DIR.'/filelistdata/*&style=list&direct=1&recursive=1}}');
|
||||
$xhtml = p_render('xhtml', $instructions, $info);
|
||||
|
||||
$doc = new DOMDocument();
|
||||
$doc->loadHTML($xhtml);
|
||||
|
||||
$first = $doc->documentElement;
|
||||
$this->assertEquals('html', $first->tagName);
|
||||
|
||||
$children = $first->childNodes;
|
||||
$this->assertTrue($children->length==1);
|
||||
$this->assertEquals('body', $children[0]->nodeName);
|
||||
|
||||
// We should have 'div' first
|
||||
$children = $children[0]->childNodes;
|
||||
$this->assertTrue($children->length==1);
|
||||
$this->assertEquals('div', $children[0]->nodeName);
|
||||
|
||||
// It should have the childs text, 'ol'
|
||||
$children = $children[0]->childNodes;
|
||||
$this->assertTrue($children->length==2);
|
||||
$this->assertEquals('#text', $children[0]->nodeName);
|
||||
$this->assertEquals('ul', $children[1]->nodeName);
|
||||
|
||||
// The 'ol' element should have 3 'li' childs
|
||||
$children = $children[1]->childNodes;
|
||||
$this->assertTrue($children->length==6);
|
||||
$this->assertEquals('li', $children[0]->nodeName);
|
||||
$this->assertEquals('#text', $children[1]->nodeName);
|
||||
$this->assertEquals('li', $children[2]->nodeName);
|
||||
$this->assertEquals('#text', $children[3]->nodeName);
|
||||
$this->assertEquals('li', $children[4]->nodeName);
|
||||
$this->assertEquals('#text', $children[5]->nodeName);
|
||||
|
||||
// First child of first 'li' should be the link to 'example.txt'
|
||||
$node = $children[0];
|
||||
$node_childs = $node->childNodes;
|
||||
$this->assertEquals('level1', $node->getAttribute('class'));
|
||||
$this->assertTrue($node_childs->length==1);
|
||||
$this->assertEquals('a', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('example.txt', $node_childs[0]->nodeValue);
|
||||
|
||||
// First child of second 'li' is directory 'exampledir' and another 'ol'
|
||||
$node = $children[2];
|
||||
$node_childs = $node->childNodes;
|
||||
$this->assertTrue($node_childs->length==2);
|
||||
$this->assertEquals('#text', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('exampledir', $node_childs[0]->nodeValue);
|
||||
$this->assertEquals('ul', $node_childs[1]->nodeName);
|
||||
|
||||
// That 'ol' should have one 'li' with 'class=level2'
|
||||
$node_childs = $node_childs[1]->childNodes;
|
||||
$this->assertTrue($node_childs->length==2);
|
||||
$this->assertEquals('li', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('level2', $node_childs[0]->getAttribute('class'));
|
||||
$this->assertEquals('#text', $node_childs[1]->nodeName);
|
||||
|
||||
// The link of that 'li' should reference 'example2.txt'
|
||||
$node_childs = $node_childs[0]->childNodes;
|
||||
$this->assertTrue($node_childs->length==1);
|
||||
$this->assertEquals('a', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('example2.txt', $node_childs[0]->nodeValue);
|
||||
|
||||
// First child of third 'li' should be the link to 'exampleimage.png'
|
||||
$node = $children[4];
|
||||
$node_childs = $node->childNodes;
|
||||
$this->assertEquals('level1', $node->getAttribute('class'));
|
||||
$this->assertTrue($node_childs->length==1);
|
||||
$this->assertEquals('a', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('exampleimage.png', $node_childs[0]->nodeValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks that the ordered list mode
|
||||
* generates the expected XHTML structure.
|
||||
*/
|
||||
public function test_olist () {
|
||||
global $conf;
|
||||
|
||||
// Render filelist
|
||||
$instructions = p_get_instructions('{{filelist>'.TMP_DIR.'/filelistdata/*&style=olist&direct=1&recursive=1}}');
|
||||
$xhtml = p_render('xhtml', $instructions, $info);
|
||||
|
||||
$doc = new DOMDocument();
|
||||
$doc->loadHTML($xhtml);
|
||||
|
||||
$first = $doc->documentElement;
|
||||
$this->assertEquals('html', $first->tagName);
|
||||
|
||||
$children = $first->childNodes;
|
||||
$this->assertTrue($children->length==1);
|
||||
$this->assertEquals('body', $children[0]->nodeName);
|
||||
|
||||
// We should have 'div' first
|
||||
$children = $children[0]->childNodes;
|
||||
$this->assertTrue($children->length==1);
|
||||
$this->assertEquals('div', $children[0]->nodeName);
|
||||
|
||||
// It should have the childs text, 'ol'
|
||||
$children = $children[0]->childNodes;
|
||||
$this->assertTrue($children->length==2);
|
||||
$this->assertEquals('#text', $children[0]->nodeName);
|
||||
$this->assertEquals('ol', $children[1]->nodeName);
|
||||
|
||||
// The 'ol' element should have 3 'li' childs
|
||||
$children = $children[1]->childNodes;
|
||||
$this->assertTrue($children->length==6);
|
||||
$this->assertEquals('li', $children[0]->nodeName);
|
||||
$this->assertEquals('#text', $children[1]->nodeName);
|
||||
$this->assertEquals('li', $children[2]->nodeName);
|
||||
$this->assertEquals('#text', $children[3]->nodeName);
|
||||
$this->assertEquals('li', $children[4]->nodeName);
|
||||
$this->assertEquals('#text', $children[5]->nodeName);
|
||||
|
||||
// First child of first 'li' should be the link to 'example.txt'
|
||||
$node = $children[0];
|
||||
$node_childs = $node->childNodes;
|
||||
$this->assertEquals('level1', $node->getAttribute('class'));
|
||||
$this->assertTrue($node_childs->length==1);
|
||||
$this->assertEquals('a', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('example.txt', $node_childs[0]->nodeValue);
|
||||
|
||||
// First child of second 'li' is directory 'exampledir' and another 'ol'
|
||||
$node = $children[2];
|
||||
$node_childs = $node->childNodes;
|
||||
$this->assertTrue($node_childs->length==2);
|
||||
$this->assertEquals('#text', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('exampledir', $node_childs[0]->nodeValue);
|
||||
$this->assertEquals('ol', $node_childs[1]->nodeName);
|
||||
|
||||
// That 'ol' should have one 'li' with 'class=level2'
|
||||
$node_childs = $node_childs[1]->childNodes;
|
||||
$this->assertTrue($node_childs->length==2);
|
||||
$this->assertEquals('li', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('level2', $node_childs[0]->getAttribute('class'));
|
||||
$this->assertEquals('#text', $node_childs[1]->nodeName);
|
||||
|
||||
// The link of that 'li' should reference 'example2.txt'
|
||||
$node_childs = $node_childs[0]->childNodes;
|
||||
$this->assertTrue($node_childs->length==1);
|
||||
$this->assertEquals('a', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('example2.txt', $node_childs[0]->nodeValue);
|
||||
|
||||
// First child of third 'li' should be the link to 'exampleimage.png'
|
||||
$node = $children[4];
|
||||
$node_childs = $node->childNodes;
|
||||
$this->assertEquals('level1', $node->getAttribute('class'));
|
||||
$this->assertTrue($node_childs->length==1);
|
||||
$this->assertEquals('a', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('exampleimage.png', $node_childs[0]->nodeValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks that the page mode
|
||||
* generates the expected XHTML structure.
|
||||
*/
|
||||
public function test_page () {
|
||||
global $conf;
|
||||
|
||||
// Render filelist
|
||||
$instructions = p_get_instructions('{{filelist>'.TMP_DIR.'/filelistdata/*&style=page&direct=1&recursive=1}}');
|
||||
$xhtml = p_render('xhtml', $instructions, $info);
|
||||
|
||||
$doc = new DOMDocument();
|
||||
$doc->loadHTML($xhtml);
|
||||
|
||||
$first = $doc->documentElement;
|
||||
$this->assertEquals('html', $first->tagName);
|
||||
|
||||
$children = $first->childNodes;
|
||||
$this->assertTrue($children->length==1);
|
||||
$this->assertEquals('body', $children[0]->nodeName);
|
||||
|
||||
// We should have a 'ul', 'h1', '#test' and 'div' node
|
||||
$children = $children[0]->childNodes;
|
||||
$this->assertTrue($children->length==4);
|
||||
$this->assertEquals('ul', $children[0]->nodeName);
|
||||
$this->assertEquals('h1', $children[1]->nodeName);
|
||||
$this->assertEquals('#text', $children[2]->nodeName);
|
||||
$this->assertEquals('div', $children[3]->nodeName);
|
||||
|
||||
// 'ul' should have the childs 'li', text, 'li', text
|
||||
//$children = $children[0]->childNodes;
|
||||
$node_childs = $children[0]->childNodes;
|
||||
$this->assertTrue($children->length==4);
|
||||
$this->assertEquals('li', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('#text', $node_childs[1]->nodeName);
|
||||
$this->assertEquals('li', $node_childs[2]->nodeName);
|
||||
$this->assertEquals('#text', $node_childs[3]->nodeName);
|
||||
|
||||
// Check first 'li' contents
|
||||
$node = $node_childs[0];
|
||||
$node_childs = $node->childNodes;
|
||||
$this->assertTrue($node_childs->length==1);
|
||||
$this->assertEquals('a', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('example.txt', $node_childs[0]->nodeValue);
|
||||
|
||||
// Check second 'li' contents
|
||||
$node = $children[0]->childNodes;
|
||||
$node_childs = $node[2]->childNodes;
|
||||
$this->assertTrue($node_childs->length==1);
|
||||
$this->assertEquals('a', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('exampleimage.png', $node_childs[0]->nodeValue);
|
||||
|
||||
// Check 'h1' contents
|
||||
$node = $children[1];
|
||||
$this->assertEquals('h1', $node->nodeName);
|
||||
$this->assertEquals('exampledir', $node->nodeValue);
|
||||
|
||||
// Check 'div' contents
|
||||
$node = $children[3];
|
||||
$this->assertEquals('div', $node->nodeName);
|
||||
$this->assertEquals('level1', $node->getAttribute('class'));
|
||||
|
||||
// Check 'div' childs
|
||||
$node_childs = $node->childNodes;
|
||||
$this->assertTrue($node_childs->length==2);
|
||||
$this->assertEquals('#text', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('ul', $node_childs[1]->nodeName);
|
||||
|
||||
// Check 'ul' childs, we should have 'li'
|
||||
$node_childs = $node_childs[1]->childNodes;
|
||||
$this->assertTrue($node_childs->length==2);
|
||||
$this->assertEquals('li', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('#text', $node_childs[1]->nodeName);
|
||||
|
||||
// The 'li' should have a 'a'
|
||||
$node_childs = $node_childs[0]->childNodes;
|
||||
$this->assertTrue($node_childs->length==1);
|
||||
$this->assertEquals('a', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('example2.txt', $node_childs[0]->nodeValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks that the table mode
|
||||
* generates the expected XHTML structure.
|
||||
*/
|
||||
public function test_table () {
|
||||
global $conf;
|
||||
|
||||
// Render filelist
|
||||
$instructions = p_get_instructions('{{filelist>'.TMP_DIR.'/filelistdata/*&style=table&direct=1&recursive=1}}');
|
||||
$xhtml = p_render('xhtml', $instructions, $info);
|
||||
|
||||
$doc = new DOMDocument();
|
||||
$doc->loadHTML($xhtml);
|
||||
|
||||
$first = $doc->documentElement;
|
||||
$this->assertEquals('html', $first->tagName);
|
||||
|
||||
$children = $first->childNodes;
|
||||
$this->assertTrue($children->length==1);
|
||||
$this->assertEquals('body', $children[0]->nodeName);
|
||||
|
||||
// We should have a 'div' node
|
||||
$children = $children[0]->childNodes;
|
||||
$this->assertTrue($children->length==1);
|
||||
$this->assertEquals('div', $children[0]->nodeName);
|
||||
$this->assertEquals('filelist-plugin', $children[0]->getAttribute('class'));
|
||||
|
||||
// Check 'div' childs
|
||||
$children = $children[0]->childNodes;
|
||||
$this->assertTrue($children->length==3);
|
||||
$this->assertEquals('#text', $children[0]->nodeName);
|
||||
$this->assertEquals('div', $children[1]->nodeName);
|
||||
$this->assertEquals('table sectionedit1', $children[1]->getAttribute('class'));
|
||||
$this->assertEquals('#text', $children[2]->nodeName);
|
||||
|
||||
// Check inner 'div' content
|
||||
$children = $children[1]->childNodes;
|
||||
$this->assertTrue($children->length==1);
|
||||
$this->assertEquals('table', $children[0]->nodeName);
|
||||
|
||||
// Check inner 'table' content
|
||||
$children = $children[0]->childNodes;
|
||||
$this->assertTrue($children->length==3);
|
||||
$this->assertEquals('tr', $children[0]->nodeName);
|
||||
$this->assertEquals('tr', $children[1]->nodeName);
|
||||
$this->assertEquals('tr', $children[2]->nodeName);
|
||||
|
||||
// Check table row 1
|
||||
$node_childs = $children[0]->childNodes;
|
||||
$this->assertTrue($node_childs->length==2);
|
||||
$this->assertEquals('td', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('#text', $node_childs[1]->nodeName);
|
||||
|
||||
// Check table row 1/cell 1 content
|
||||
$node_childs = $node_childs[0]->childNodes;
|
||||
$this->assertTrue($node_childs->length==1);
|
||||
$this->assertEquals('a', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('example.txt', $node_childs[0]->nodeValue);
|
||||
|
||||
// Check table row 2
|
||||
$node_childs = $children[1]->childNodes;
|
||||
$this->assertTrue($node_childs->length==2);
|
||||
$this->assertEquals('td', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('#text', $node_childs[1]->nodeName);
|
||||
|
||||
// Check table row 2/cell 1 content
|
||||
$node_childs = $node_childs[0]->childNodes;
|
||||
$this->assertTrue($node_childs->length==1);
|
||||
$this->assertEquals('a', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('exampledir/example2.txt', $node_childs[0]->nodeValue);
|
||||
|
||||
// Check table row 3
|
||||
$node_childs = $children[2]->childNodes;
|
||||
$this->assertTrue($node_childs->length==2);
|
||||
$this->assertEquals('td', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('#text', $node_childs[1]->nodeName);
|
||||
|
||||
// Check table row 3/cell 1 content
|
||||
$node_childs = $node_childs[0]->childNodes;
|
||||
$this->assertTrue($node_childs->length==1);
|
||||
$this->assertEquals('a', $node_childs[0]->nodeName);
|
||||
$this->assertEquals('exampleimage.png', $node_childs[0]->nodeValue);
|
||||
|
||||
/*print_r ($node_childs->children[1]);
|
||||
foreach ($node_childs as $node) {
|
||||
print ("\nTEST:".$node->nodeName." : ".$node->nodeValue."\n");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Options for the filelist plugin
|
||||
*/
|
||||
|
||||
$conf['paths'] = '';
|
||||
$conf['allow_in_comments'] = 0;
|
||||
$conf['allowed_absolute_paths'] = DOKU_INC;
|
||||
$conf['web_paths'] = DOKU_URL;
|
||||
$conf['defaults'] = '';
|
||||
$conf['extensions'] = '';
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Metadata for configuration manager plugin
|
||||
* Additions for the filelist plugin
|
||||
@@ -6,9 +7,7 @@
|
||||
* @author Gina Haeussge <osd@foosel.net>
|
||||
*/
|
||||
|
||||
$meta['paths'] = array('');
|
||||
$meta['allow_in_comments'] = array('onoff');
|
||||
$meta['allowed_absolute_paths'] = array('');
|
||||
$meta['web_paths'] = array('');
|
||||
$meta['defaults'] = array('string');
|
||||
$meta['extensions'] = array('string');
|
||||
|
||||
|
||||
5
deleted.files
Normal file
5
deleted.files
Normal file
@@ -0,0 +1,5 @@
|
||||
# This is a list of files that were present in previous releases
|
||||
# but were removed later. They should not exist in your installation.
|
||||
.travis.yml
|
||||
_test/filelist.test.php
|
||||
script.js
|
||||
41
file.php
Normal file
41
file.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
|
||||
|
||||
use dokuwiki\plugin\filelist\Path;
|
||||
|
||||
if (!defined('DOKU_INC')) define('DOKU_INC', __DIR__ . '/../../../');
|
||||
if (!defined('NOSESSION')) define('NOSESSION', true); // we do not use a session or authentication here (better caching)
|
||||
if (!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT', 1); // we gzip ourself here
|
||||
require_once(DOKU_INC . 'inc/init.php');
|
||||
|
||||
global $INPUT;
|
||||
|
||||
$syntax = plugin_load('syntax', 'filelist');
|
||||
if (!$syntax) die('plugin disabled?');
|
||||
|
||||
$pathUtil = new Path($syntax->getConf('paths'));
|
||||
$path = $INPUT->str('root') . $INPUT->str('file');
|
||||
|
||||
try {
|
||||
$pathInfo = $pathUtil->getPathInfo($path, false);
|
||||
if (!is_readable($pathInfo['path'])) {
|
||||
header('Content-Type: text/plain');
|
||||
http_status(404);
|
||||
echo 'Path not readable: ' . $pathInfo['path'];
|
||||
exit;
|
||||
}
|
||||
[$ext, $mime, $download] = mimetype($pathInfo['path'], false);
|
||||
$basename = basename($pathInfo['path']);
|
||||
header('Content-Type: ' . $mime);
|
||||
if ($download) {
|
||||
header('Content-Disposition: attachment; filename="' . $basename . '"');
|
||||
}
|
||||
http_sendfile($pathInfo['path']);
|
||||
readfile($pathInfo['path']);
|
||||
} catch (Exception $e) {
|
||||
header('Content-Type: text/plain');
|
||||
http_status(403);
|
||||
echo $e->getMessage();
|
||||
exit;
|
||||
}
|
||||
@@ -12,7 +12,3 @@ $lang['filesize'] = 'Dateigröße';
|
||||
$lang['lastmodified'] = 'Letzte Änderung';
|
||||
$lang['error_nomatch'] = 'Keine Treffer';
|
||||
$lang['error_outsidejail'] = 'Zugriff verweigert';
|
||||
$lang['preview'] = 'Vorschau';
|
||||
$lang['filetype'] = 'Dateityp';
|
||||
$lang['createdby'] = 'Erstellt von';
|
||||
$lang['creatorunknown'] = 'Unbekannt';
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
<?php
|
||||
|
||||
$lang['allow_in_comments'] = 'Filelistsyntax in Kommentaren erlauben.';
|
||||
$lang['allowed_absolute_paths'] = 'Komma-separierte Liste absoluter Pfade, die durchsucht werden dürfen.';
|
||||
$lang['web_paths'] = 'Komma-separierte Liste von URLs, über die die zuvor definierten und korrespondierenden absoluten Pfade erreicht werden können. MUSS die selbe Anzahl an Einträgen haben wie die Liste der absoluten Pfade';
|
||||
|
||||
@@ -12,7 +12,3 @@ $lang['filesize'] = 'Filesize';
|
||||
$lang['lastmodified'] = 'Last modified';
|
||||
$lang['error_nomatch'] = 'No match';
|
||||
$lang['error_outsidejail'] = 'Access denied';
|
||||
$lang['preview'] = 'Preview';
|
||||
$lang['filetype'] = 'Filetype';
|
||||
$lang['createdby'] = 'Created by';
|
||||
$lang['creatorunknown'] = 'Unknown';
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
<?php
|
||||
|
||||
$lang['allow_in_comments'] = 'Whether to allow the filelist syntax to be used in comments.';
|
||||
$lang['allowed_absolute_paths'] = 'Comma-separated list of absolute paths allowed for globbing.';
|
||||
$lang['web_paths'] = 'Comma-separated list of urls by which to reach the corresponding absolute path from the previous list. MUST have the exact same number of entries as allowed_absolute_paths.';
|
||||
$lang['defaults'] = 'Default options. Use the same syntax as in inline configuration';
|
||||
$lang['extensions'] = 'Comma-separated list of allowed file extensions to list';
|
||||
|
||||
@@ -5,7 +5,5 @@
|
||||
* @author Mark C. Prins <mprins@users.sf.net>
|
||||
*/
|
||||
$lang['allow_in_comments'] = 'Of de filelist syntax toegestaan is voor gebruik in commentaar.';
|
||||
$lang['allowed_absolute_paths'] = 'Komma-gescheiden lijst van absolute zoekpaden.';
|
||||
$lang['web_paths'] = 'Komma-gescheiden lijst van urls waarop overeenkomende paden uit voorgaande lijst gevonden kunnen worden. Het aantal elementen MOET exact gelijk zijn aan dat van allowed_absolute_paths.';
|
||||
$lang['defaults'] = 'Default options. Gebruik dezelfde syntax als de inline configuratie.';
|
||||
$lang['extensions'] = 'Komma-gescheiden lijst van toegestane bestandsextensies voor de lijst.';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
base filelist
|
||||
author Gina Häußge, Dokufreaks
|
||||
email gina@foosel.net, freaks@dokuwiki.org
|
||||
email freaks@dokuwiki.org
|
||||
date 2020-09-27
|
||||
name Filelist Plugin
|
||||
desc Lists files matching a given glob pattern.
|
||||
|
||||
50
script.js
50
script.js
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* For Filelist Plugin
|
||||
*
|
||||
* @author joachimmueller
|
||||
*/
|
||||
|
||||
/*
|
||||
* run on document load, setup everything we need
|
||||
*/
|
||||
jQuery(function () {
|
||||
"use strict";
|
||||
|
||||
// CONFIG
|
||||
|
||||
// these 2 variable determine popup's distance from the cursor
|
||||
// you might want to adjust to get the right result
|
||||
var xOffset = 10;
|
||||
var yOffset = 30;
|
||||
|
||||
// END CONFIG
|
||||
|
||||
jQuery("img.filelist_preview").hover(function (e) {
|
||||
this.t = this.title;
|
||||
this.title = "";
|
||||
|
||||
var c;
|
||||
if (this.t !== "") {
|
||||
c = "<br/>" + this.t;
|
||||
} else {
|
||||
c = "";
|
||||
}
|
||||
jQuery("body").append("<p id='plugin__filelist_preview'><img src='" + this.src + "' alt='Image preview' />" + c + "</p>");
|
||||
jQuery("#plugin__filelist_preview")
|
||||
.css("top", (e.pageY - xOffset) + "px")
|
||||
.css("left", (e.pageX + yOffset) + "px")
|
||||
.css("max-width", "300px")
|
||||
.css("max-height", "300px")
|
||||
.css("position", "absolute")
|
||||
.fadeIn("fast");
|
||||
}, function () {
|
||||
this.title = this.t;
|
||||
jQuery("#plugin__filelist_preview").remove();
|
||||
});
|
||||
jQuery("img.filelist_preview").mousemove(function (e) {
|
||||
jQuery("#plugin__filelist_preview")
|
||||
.css("top", (e.pageY - xOffset) + "px")
|
||||
.css("left", (e.pageX + yOffset) + "px")
|
||||
.css("position", "absolute");
|
||||
});
|
||||
});
|
||||
1112
syntax.php
1112
syntax.php
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user