32ef3ceb6c9a0fdc432bc65938cbc3343a64e068
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: '{$this->entry}'");
79 if (!$this->file
= fopen($file->getFullPath(".md"), "r")) {
80 throw new \
Exception("Could not open {$this->entry}");
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")),