22 function __construct(Path
$path, $entry = null) {
24 $this->entry
= $entry ?
: $path->getPathName();
27 function __destruct() {
28 if (is_resource($this->file
)) {
33 function formatUrl() {
34 return htmlspecialchars($this->entry
);
35 return implode("/", explode(DIRECTORY_SEPARATOR
, trim(substr(
36 $this->entry
, strlen($this->path
->getBaseDir())),
37 DIRECTORY_SEPARATOR
)));
40 protected function joinLink(array $parts) {
42 $upper = ctype_upper($parts[0][0]);;
43 for ($i = 0; $i < count($parts); ++
$i) {
44 if (!strlen($parts[$i]) ||
$parts[$i] === ".") {
48 if ($upper && !ctype_upper($parts[$i][0])) {
55 $upper = ctype_upper($parts[$i][0]);
60 function formatLink($basename = false) {
62 if (strlen($entry = trim($this->entry
, DIRECTORY_SEPARATOR
))) {
63 $parts = explode(DIRECTORY_SEPARATOR
, $entry);
64 $link = $basename ?
end($parts) : $this->joinLink($parts);
66 return htmlspecialchars($link);
69 protected function openFile() {
70 if (!is_resource($this->file
)) {
72 $file = $path($this->entry
);
73 if (!$file->isFile()) {
74 throw new \
Exception("Not a file: '$this->entry'");
76 if (!$this->file
= fopen($file->getFullPath(".md"), "r")) {
77 throw new \
Exception("Could not open {$this->entry}");
82 function readTitle() {
84 fseek($this->file
, 1, SEEK_SET
);
85 return htmlspecialchars(fgets($this->file
));
88 function readDescription() {
90 fseek($this->file
, 0, SEEK_SET
);
93 return htmlspecialchars(fgets($this->file
));