-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch-tags.php
executable file
·67 lines (50 loc) · 1.66 KB
/
search-tags.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
header("Content-Type: json", true);
$postData = $_POST["tags"];
$searchTags = json_decode($postData);
$html = "";
class MyDB extends SQLite3
{
function __construct()
{
$this->open('db/images.db');
}
}
$db = new MyDB();
if(!$db){
echo $db->lastErrorMsg();
}
$searchString = "SELECT DISTINCT path FROM images";
if (count($searchTags))
$searchString.=' WHERE ';
foreach ($searchTags as $tag) {
$tag = strtolower($tag);
$searchString.="tag = '$tag' OR ";
}
$searchString = chop($searchString, ' OR ');
error_log($searchString);
$pathsResult = $db->query($searchString);
$paths = array();
while($path=$pathsResult->fetchArray()) {
array_push($paths, $path);
}
$html.= "<div class='row'>";
for($i=0; $i<count($paths); $i++) {
$p = $paths[$i][0];
$divClass = 'small-4 columns';
if ($i==count($paths)-1)
$divClass.=' end';
$html.= "<div class='$divClass'><div class='panel'><a href='#' onClick='viewPhoto(\"$p\")'><img src=\"$p\" width='600px' style='margin-bottom:10px'></a>";
$tags = $db->query("SELECT tag FROM images WHERE path = '$p'");
while($tag=$tags->fetchArray()) {
if (in_array($tag[0], $searchTags))
$html.= "<div class='button tiny round success' style='margin: 2px 2px 2px 0px'>$tag[0]</div>";
else
$html.= "<div class='button tiny round secondary' style='margin: 2px 2px 2px 0px'>$tag[0]</div>";
}
$html.= "</div></div>";
}
$html.= "</div>";
$arr = array('html' => $html);
echo json_encode($arr);
?>