-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions.php
67 lines (61 loc) · 1.2 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
function determineHome($version)
{
if ($version == 3) {
return 'home';
} elseif ($version == 4) {
return 'introduction';
}
}
/**
* Get the root path for the documentation Markdown.
*
* @return string
*/
function doc_root()
{
return Bundle::path('docs').'documents/';
}
/**
* Get the parsed Markdown contents of a given page.
*
* @param string $page
* @return string
*/
function document($page)
{
return MdParser\Markdown(file_get_contents(doc_root().$page.'.md'));
}
/**
* Determine if a documentation page exists.
*
* @param string $page
* @return bool
*/
function document_exists($page)
{
return file_exists(doc_root().$page.'.md');
}
/**
* Get the title of the document
*
* @param string $document
* @return string
*/
function document_title($document)
{
$result = array();
$string = " ".$document;
$offset = 0;
while(true)
{
$ini = strpos($string,'<h1>',$offset);
if ($ini == 0)
break;
$ini += strlen('<h1>');
$len = strpos($string,'</h1>',$ini) - $ini;
$result[] = substr($string,$ini,$len);
$offset = $ini+$len;
}
return (isset($result[0])) ? $result[0] : null;
}