0becc69988b52ae844c52b108959b5194fd1b5f2
22 function __construct(Path
$path, $entry = null) {
24 $this->entry
= trim($entry ?
: $path->getPathName(), DIRECTORY_SEPARATOR
);
27 function __destruct() {
28 if (is_resource($this->file
)) {
33 function formatUrl() {
34 return htmlspecialchars($this->entry
);
37 private function joinLink(array $parts) {
39 $upper = ctype_upper($parts[0][0]);;
40 for ($i = 0; $i < count($parts); ++
$i) {
41 if (!strlen($parts[$i]) ||
$parts[$i] === ".") {
45 if ($upper && !ctype_upper($parts[$i][0])) {
52 $upper = ctype_upper($parts[$i][0]);
57 function formatLink($basename = false) {
59 if (strlen($this->entry
)) {
60 $parts = explode(DIRECTORY_SEPARATOR
, $this->entry
);
61 $link = $basename ?
end($parts) : $this->joinLink($parts);
63 return htmlspecialchars($link);
68 $file = $path($this->entry
);
72 private function openFile() {
73 if (!is_resource($this->file
)) {
74 $file = $this->getPath();
76 if (!$file->isFile()) {
77 throw new \
Exception("Not a file: '{$file}'");
79 if (!$this->file
= fopen($file->getFullPath(".md"), "r")) {
80 throw new \
Exception("Could not open {$file}");
85 function readTitle() {
87 fseek($this->file
, 1, SEEK_SET
);
88 return htmlspecialchars(fgets($this->file
));
91 function readDescription() {
93 fseek($this->file
, 0, SEEK_SET
);
96 return htmlspecialchars(fgets($this->file
));
99 function formatEditUrl() {
101 $base = current(explode(DIRECTORY_SEPARATOR
, $path->getPathName()));
102 $file = $path($base);
103 if ($file->isFile(".mdref")) {
104 return sprintf(file_get_contents($file->getFullPath(".mdref")),
109 function recurse(Finder
$refs, $pattern, callable
$cb) {
110 $path = $refs->find($refs->getBaseUrl()->mod($this->entry
));
111 foreach (new RefListing($path, $refs->glob($path, $pattern)) as $entry) {
112 /* @var $entry RefEntry */
113 $cb($entry, $pattern, function($entry, $pattern) use ($refs, $cb) {
114 $entry->recurse($refs, $pattern, $cb);