|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the PHPoole/Cecil package. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) Arnaud Ligny <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Cecil\Command; |
|
12
|
|
|
|
|
13
|
|
|
use Cecil\Command\ListContent\FileExtensionFilter; |
|
14
|
|
|
use Cecil\Command\ListContent\FilenameRecursiveTreeIterator; |
|
15
|
|
|
use RecursiveDirectoryIterator; |
|
16
|
|
|
use RecursiveTreeIterator; |
|
17
|
|
|
|
|
18
|
|
|
class ListContent extends AbstractCommand |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $contentDir; |
|
24
|
|
|
|
|
25
|
|
|
public function processCommand() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->contentDir = $this->getPHPoole()->getConfig()->get('content.dir'); |
|
28
|
|
|
|
|
29
|
|
|
try { |
|
30
|
|
|
$this->wlAnnonce(sprintf('%s/', $this->contentDir)); |
|
31
|
|
|
$pages = $this->getPagesTree(); |
|
32
|
|
|
if ($this->getConsole()->isUtf8()) { |
|
33
|
|
|
$unicodeTreePrefix = function (RecursiveTreeIterator $tree) { |
|
34
|
|
|
$prefixParts = [ |
|
35
|
|
|
RecursiveTreeIterator::PREFIX_LEFT => ' ', |
|
36
|
|
|
RecursiveTreeIterator::PREFIX_MID_HAS_NEXT => '│ ', |
|
37
|
|
|
RecursiveTreeIterator::PREFIX_END_HAS_NEXT => '├ ', |
|
38
|
|
|
RecursiveTreeIterator::PREFIX_END_LAST => '└ ', |
|
39
|
|
|
]; |
|
40
|
|
|
foreach ($prefixParts as $part => $string) { |
|
41
|
|
|
$tree->setPrefixPart($part, $string); |
|
42
|
|
|
} |
|
43
|
|
|
}; |
|
44
|
|
|
$unicodeTreePrefix($pages); |
|
45
|
|
|
} |
|
46
|
|
|
foreach ($pages as $page) { |
|
47
|
|
|
$this->getConsole()->writeLine($page); |
|
48
|
|
|
} |
|
49
|
|
|
$this->getConsole()->writeLine(''); |
|
50
|
|
|
} catch (\Exception $e) { |
|
51
|
|
|
throw new \Exception(sprintf($e->getMessage())); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Return a console displayable tree of pages. |
|
57
|
|
|
* |
|
58
|
|
|
* @throws \Exception |
|
59
|
|
|
* |
|
60
|
|
|
* @return FilenameRecursiveTreeIterator |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getPagesTree() |
|
63
|
|
|
{ |
|
64
|
|
|
$pagesPath = $this->path.'/'.$this->contentDir; |
|
65
|
|
|
if (!is_dir($pagesPath)) { |
|
66
|
|
|
throw new \Exception(sprintf('Invalid directory: %s.', $pagesPath)); |
|
67
|
|
|
} |
|
68
|
|
|
$dirIterator = new RecursiveDirectoryIterator($pagesPath, RecursiveDirectoryIterator::SKIP_DOTS); |
|
69
|
|
|
$dirIterator = new FileExtensionFilter($dirIterator, $this->getPHPoole()->getConfig()->get('content.ext')); |
|
70
|
|
|
$pages = new FilenameRecursiveTreeIterator( |
|
71
|
|
|
$dirIterator, |
|
72
|
|
|
FilenameRecursiveTreeIterator::SELF_FIRST |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
return $pages; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|