forked from ademcan/canSnippet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
104 lines (90 loc) · 3.62 KB
/
index.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
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
<?php
/*
@author: Ademcan ([email protected])
@name: index.php
@description: initial page
*/
include "config.php";
session_start();
if (!file_exists("snippets.sqlite")) {
echo "<script>location.href='install.php';</script>";
} else {
include 'includes/menu.php';
$mytable ="snippets";
$base=new SQLite3($config["dbname"]);
$count_query = "SELECT count(*) as count FROM $mytable";
$results_count = $base->query($count_query);
$row_count = $results_count->fetchArray();
$snippets_count = $row_count['count'];
$limit = 10;
$page = 1;
if (isset($_GET['page'])){
$page = intval($_GET['page']);
}
$start_count = $limit * ($page-1);
// if logged in, the user can see the private snippets
if(isset($_SESSION['valid']) && $_SESSION['valid']){
$query_name = "SELECT * FROM $mytable ORDER BY ID DESC LIMIT $start_count,$limit";
}
// if not logged in, select only public snippets
else {
$query_name = "SELECT * FROM $mytable WHERE private != 'on' ORDER BY ID DESC LIMIT $start_count,$limit";
}
$results_name = $base->query($query_name);
$settingsQuery = "SELECT * FROM settings";
$settingsInfo = $base->query($settingsQuery);
$settings = $settingsInfo->fetchArray();
$title = $settings["title"];
echo '<h1>{ '.$title.' }</h1>';
if($snippets_count == 0){
echo "You don't have any snippet yet, you can add new snippets from the Admin interface.";
}
// Loop and write all the recent snippets
while($row = $results_name->fetchArray())
{
$name = $row['name'];
$code = $row['code'];
$language = $row['language'];
$private = $row['private'];
$date = $row['date'];
$id = $row['ID'];
$description = $row['description'];
if ($private=="on"){
echo '<h2><a href="details.php?id='.$id.'">',$name ,'</a><img src="images/lockFlat.png" style="width:20px; height: 20px;padding-left:10px;" /></h2>';
}
else{
echo '<h2><a href="details.php?id='.$id.'">',$name ,'</a></h2>';
}
if ($language=="html"){
$languageClass = "language-markup";
}
else if ($language=="text"){
$languageClass = "language-markup";
}
else{
$languageClass = "language-".$language;
}
echo '<font size="1"><i>'.$language.'</i> - '.$date.'</font><br>';
echo '<img src="images/info.png" style="vertical-align: middle;"/>';
echo ' '.nl2br($description);
echo '<section class="'.$languageClass.'"> <pre><code>'.$code.'</code></pre> </section>' ;
echo '<hr><br>';
}
echo "<br><br>";
// Pagination
// First page
if($snippets_count > $limit & $page == 1){
echo '<center><a href= "index.php?page=2"> Older snippets >>> </a></center>';
}
// Last page
if($page > 1 & $snippets_count <= ($limit*$page) & $snippets_count > ($limit*($page-1)) ){
echo '<center><a href= "index.php?page='.($page-1).'"> <<< Newer snippets </a></center>';
}
// Middle page
if($page > 1 & $snippets_count > ($limit*$page)){
echo '<center><a href= "index.php?page='.($page-1).'"> <<< Newer snippets</a> -- <a href="index.php?page='.($page+1).'">Older snippets >>></a></center>';
}
echo '<center><font size="1">Powered by <a href="http://www.ademcan.net/index.php?d=2014/01/16/08/47/25-save-and-share-your-snippets-with-cansnippet">canSnippet</a> v1.0 beta - by ademcan<font></center>';
echo '<br></div> </body></html>';
}
?>