-
Notifications
You must be signed in to change notification settings - Fork 3
/
functions.inc
132 lines (107 loc) · 3.98 KB
/
functions.inc
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
require_once 'Michelf/MarkdownExtra.inc.php';
use Michelf\MarkdownExtra;
function
getnews ($verbosity) { /* 1 = Display full body text
0 = Display first 1000 characters of body text
-1 = Display first 200 characters of body text.
*/
$news = array ();
$dir_handle = @opendir ('news/');
while ($file = readdir ($dir_handle)) {
if(stristr ($file, '.txt')) {
$filenum = str_replace ('.txt', '', $file);
$id = intval ($filenum);
$contentarr = file ("news/{$file}");
$title = trim ($contentarr[0]);
$date = trim ($contentarr[2]);
unset ($contentarr[0]);
unset ($contentarr[1]);
unset ($contentarr[2]);
unset ($contentarr[3]);
$body = trim (implode ('', $contentarr));
if ($verbosity == 0 and strlen ($body) > 1000) {
$body = substr ($body, 0, 1000) . "...";
} else if ($verbosity == -1 and strlen ($body) > 200) {
$body = substr ($body, 0, 200) . "...";
}
$body = MarkdownExtra::defaultTransform($body);
$news[$id] = array ('id' => $id,
'title' => $title,
'date' => $date,
'body' => $body);
}
}
closedir ($dir_handle);
return $news;
}
function
news ($page, $navlinks, $archivelink) {
$newsarray = getnews (1);
krsort ($newsarray);
$news = "";
/* Pagination */
$newsperpage = 2;
$gonext = FALSE;
$goback = FALSE;
$nextpage = $page + 1;
$lastpage = $page - 1;
/* News display */
$count = 0;
foreach ($newsarray as $item) {
if ($count < ($page + 1) * $newsperpage and $count >= $page * $newsperpage) {
$news .= "<div class=\"newsitem\">
<h3><a href=\"/news.php?id={$item['id']}\" title=\"{$item['title']}\">{$item['title']}</a></h3>
<span class=\"date\">{$item['date']}</span>
<p>{$item['body']}</p>
</div>";
}
$count ++;
}
$gonext = ($page < ceil(count($newsarray) / $newsperpage));
$goback = ($page != 0);
$newslinks = "";
if (($gonext or $goback) and ($navlinks or $archivelink)) {
$newslinks = '<ul id="newslinks">';
if ($goback and $navlinks) {
$newslinks .= "<li><a href=\"http://www.uzbl.org/index.php?page={$lastpage}\">« Previous</a></li>";
}
if ($gonext and $navlinks) {
$newslinks .= "<li><a href=\"http://www.uzbl.org/index.php?page={$nextpage}\">Next »</a></li>";
}
if ($archivelink) {
$newslinks .= "<li><a href=\"http://www.uzbl.org/archives.php\">Archives</a></li>";
}
$newslinks .= '</ul>';
}
return $news . $newslinks;
}
function
navigation () {
$pages = array (
'/' => 'Home',
'faq.php' => 'FAQ',
'readme.php' => 'Readme',
'get.php' => 'Get',
'community.php' => 'Community',
'contribute.php' => 'Contribute',
'https://github.com/uzbl/uzbl/issues' => 'Bugs'
);
$indexaliases = array ('', 'index.php', 'news.php', 'commits.php'); // These things should highlight "Home" in the navbar.
$uri = str_replace ('/', '', $_SERVER['REQUEST_URI']);
$uri = (in_array ($uri, $indexaliases)) ? '/' : $uri;
$output = '';
foreach ($pages as $page => $name) {
$id = ($page == $uri) ? ' id="selected"' : '';
$link = (substr ($page, 0, 1) == '/') ? "/{$page}" : $page;
$output = "<li{$id}><a href=\"{$page}\">{$name}</a></li>\n{$output}";
}
return $output;
}
function
markdown_file ($file) {
$filecontents = file_get_contents ($file);
$markdown = MarkdownExtra::defaultTransform ($filecontents);
return $markdown;
}
?>