-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
76 lines (68 loc) · 2.63 KB
/
Copy pathapi.php
File metadata and controls
76 lines (68 loc) · 2.63 KB
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
<?php
require 'vendor/autoload.php';
error_reporting(E_ERROR | E_PARSE);
function getMeta ($articleName)
{
return json_decode(file_get_contents("articles/$articleName/meta.json", true), true);
}
function listArticles ($searchQuery="")
{
$articles = "";
foreach (array_diff(scandir("articles"), array(".","..")) as $article)
{
if ((strpos(strtolower(getMeta($article)["title"]), strtolower($searchQuery)) !== false) || (!$searchQuery))
{
$articles .= "<tr>" .
"<td><a href='?kb=$article'>" . getMeta($article)["title"] . "</a></td>" .
"<td>" . getMeta($article)["author"] . "</td>" .
"<td>" . getMeta($article)["date"] . "</td>" .
"<td>" . implode(", ", getMeta($article)["categories"]) . "</td>" .
"</tr>";
}
}
return $articles;
}
function parseArticle($articleName)
{
$parser = new Parsedown();
$parser->setSafeMode(true);
/* get contents of the file */
$article = file_get_contents("articles/$articleName/content.md", true);
/* remove html tags, and parse */
$article = $parser->text($article);
/* get metadata */
$articleInfo = getMeta($articleName);
/* return that stuff */
return array($articleInfo, $article, $articleName);
}
function makeHtmlFromParsedArticle($articleArray)
{
$articleInfo = $articleArray[0];
$contents = $articleArray[1];
return "
<div class='article'>
<h2>$articleInfo[title]</h2>
<h4>Opublikowano $articleInfo[date] przez $articleInfo[author]</h4>
<hr>
<p>
$contents
</p>
<hr>
<a href='https://twitter.com/share?text=Dziękuję%20@cloudsdalefm%20za%20pomoc!%20:D&url=https://help.cloudsdalefm.net/index.php?kb=$articleArray[2]' target='_blank' class='toright'>Zatweetuj i wyraź swoje zadowolenie</a>
</div>
";
}
/* --------------------------------------------------- */
if (isset($_POST["searchQuery"]))
{
echo "<table>
<tr class='ftr'>
<td>Tytuł</td>
<td>Autor</td>
<td>Data</td>
<td>Kategorie</td>
</tr>
" . listArticles($_POST["searchQuery"])
. "</table>";
}
?>