forked from ademcan/canSnippet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.php
128 lines (116 loc) · 4.97 KB
/
action.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/*
@author: Ademcan ([email protected])
@name: action.php
@description: action class for browse snippets page
*/
include "config.php";
session_start();
$mytable ="snippets";
$base=new SQLite3($config["dbname"]);
if(isset($_POST["action"]) && strval($_POST['action'])=="getcode"){
$id = intval($_POST["id"]);
// get entry
$query_language = "SELECT * FROM $mytable where id = '$id' ";
$results_language = $base->query($query_language);
while($row = $results_language->fetchArray())
{
$code = iconv("ISO-8859-15", "UTF-8",$row['code']);
$language = $row['language'];
$date = $row['date'];
$name = iconv("ISO-8859-15", "UTF-8",$row['name']);
$private = $row['private'];
$description = iconv("ISO-8859-15", "UTF-8",$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>' ;
}
}
if(isset($_POST["action"]) && $_POST['action']=="getname" ){
$language = SQLite3::escapeString($_POST["language"]);
// get entry
if(isset($_SESSION['valid']) && $_SESSION['valid']){
$query_language = "SELECT * FROM $mytable where language = '$language' ";
}
else {
$query_language = "SELECT * FROM $mytable where language = '$language' AND private != 'on' ";
}
$results_language = $base->query($query_language);
echo '
Choose a snippet<br><br>
<center>
<select name="selectCode" id="selectCode" class="box" ">
</center>
<option selected >Choose a snippet </option>';
while($row = $results_language->fetchArray())
{
$name = iconv("ISO-8859-15", "UTF-8",$row['name']);
$id = $row['ID'];
echo '<option value="'.$id.'">'.$name.'</option>';
}
echo '</select>';
}
// Search snippet
if( isset($_POST["search"]) ){
include 'includes/menu.php';
$mytable ="snippets";
$base=new SQLite3($config["dbname"]);
$search = SQLite3::escapeString($_POST['search']);
if(isset($_SESSION['valid']) && $_SESSION['valid']){
$query_name = "SELECT * FROM $mytable WHERE name LIKE '%$search%' OR description LIKE '%$search%' OR language LIKE '%$search%'";
}
else {
$query_name = "SELECT * FROM $mytable WHERE (name LIKE '%$search%' OR description LIKE '%$search%' OR language LIKE '%$search%') AND private != 'on' ";
}
$results_name = $base->query($query_name);
echo '<h1> Search results for "'.$_POST['search'].'"</h1>';
// Loop and write all the recent snippets
while($row = $results_name->fetchArray())
{
$private = $row['private'];
$name = $row['name'];
$code = $row['code'];
$language = $row['language'];
$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 style="width:95%; height:5px;background-color:#2ecc71;border-radius:20px;border-color:#2ecc71;border-style:none;">';
}
echo '</div></body></html>';
}
?>