-
Notifications
You must be signed in to change notification settings - Fork 0
/
zigsite.php
181 lines (121 loc) · 6.61 KB
/
zigsite.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
include("inc/zigdata.php");
if(isset($_GET['page'])){$page = $_GET['page'];} else {$page = 1;}
$startyear = $_GET["startyear"];
$endyear = $_GET["endyear"];
$search = $_GET["search"];
include("inc/header.php");
include("inc/topostyle.php");
// STEP 4 - function takes IDs and returns corresponding values from data.php
function get_grade($id,$item,$zigblog){
$title = $item["title"];
$date = $item["dateverbose"];
$photocred = $item["photocred"];
$content = $item["content"];
if ($item["imagesnumber"] == 0){"";} else if ($item["imagesnumber"] == 1){$imagecode = "<div class='w3-full'><img src='/img/zig/".$item["date"]."_1.jpg' alt='Chebucto' style='width:50%'></div>";} else if ($item["imagesnumber"] == 2){$imagecode = "<div class='w3-half'><img src='/img/zig/".$item["date"]."_1.jpg' alt='Chebucto' style='width:100%'></div><div class='w3-half'><img src='/img/zig/".$item["date"]."_2.jpg' alt='Chebucto' style='width:100%'></div>";} else if ($item["imagesnumber"] == 3){$imagecode = "<div class='w3-third'><img src='/img/zig/".$item["date"]."_1.jpg' alt='Chebucto' style='width:100%'></div><div class='w3-third'><img src='/img/zig/".$item["date"]."_2.jpg' alt='Chebucto' style='width:100%'></div><div class='w3-third'><img src='/img/zig/".$item["date"]."_3.jpg' alt='Chebucto' style='width:100%'></div>";} else if ($item["imagesnumber"] == 4){$imagecode = "<div class='w3-half'><img src='/img/zig/".$item["date"]."_1.jpg' alt='Chebucto' style='width:100%'></div><div class='w3-half'><img src='/img/zig/".$item["date"]."_2.jpg' alt='Chebucto' style='width:100%'></div><div class='w3-half'><img src='/img/zig/".$item["date"]."_3.jpg' alt='Chebucto' style='width:100%'></div><div class='w3-half'><img src='/img/zig/".$item["date"]."_4.jpg' alt='Chebucto' style='width:100%'></div>";}
$output = "<div class='w3-container w3-content w3-center w3-large blog-text w3-margin-bottom'><div class='w3-container w3-white w3-card'><h2 class='w3-wide'>".$title."</h2><p class='w3-opacity'><i>".$date."</i>".$imagecode."<div class='w3-opacity w3-center'>".$photocred."</div><p class='w3-left-align'>".$content."</p></div></div>"
;
return $output;
}
// STEP 2 - Search function - outputs an array of IDs based on parameters of a foreach loop, and specified input value $grade
function array_category($zigblog,$startyear,$endyear){
$output = array();
foreach ($zigblog as $id => $item){
if (isset($startyear) && $startyear >= $item["year"] && $endyear <= $item["year"]){//<- Start Test
$sort = $item['date'];
$output[$id] = $sort;
}
}
arsort($output);
return array_keys($output);
}
// STEP 1 - creates an variable containing an array of IDs generated by the array_category function. Specify the input to pass to the search function
$test = array_category($zigblog,$endyear,$startyear);
// Search function for blog
if ($search != null){$finalresult = mySearch($zigblog, "date", $search);} else {$finalresult = $test;}
function mySearch($array, $key, $search)
{
$results = array();
foreach ($array as $rootKey => $data) {
if (array_key_exists($key, $data)) {
if (strpos(strtolower($data["content"]), strtolower($search)) != false or strpos(strtolower($data["photocred"]), strtolower($search)) != false) {
$results[] = $rootKey;
}
}
}
return $results;
}
$resultstotal = count($finalresult);
// STEP 3 - takes an array of IDs from the search and returns valuses from get_grade function
// foreach (associateive array AS array key => array key's value) {code to execute}
//functions are named containers for code snippets to be executed with passed variables
//function function_name(variables to pass to function){code to execute using passed variables}
?>
<!-- Problem Sorter Controls -->
<div class="w3-container" id="where" style="padding-bottom:0px;">
<div class="w3-content" style="max-width:700px">
<h5 class="w3-center w3-padding-16"><span class="w3-tag w3-wide">ZIGS BLOG</span></h5>
<form action="zigsite.php" method="get">
<div class ="w3-center w3-bold">
<label for="lname" style="font-weight:bold">Search:</label>
<input type="text" id="search" name="search"><br>
</div>
<div class="slider">
<p><input type="range" min="1998" max="2008" value="0" class="slider" id="id1" name="startyear" method="get"></p>
</div>
<span>Start Year:</span> <span id="f" style="font-weight:bold;"></span>
<div class="slider">
<input type="range" min="1998" max="2008" value="2008" class="slider" id="id2" name="endyear" method="get">
<span>End Year:</span> <span id="g" style="font-weight:bold;"></span>
</div><br>
<p>
<div class="w3-center">
<button class="w3-button w3-black" type="submit">SORT</button>
</div>
</form>
</div>
</div>
<div class='w3-right-align w3-content w3-bold blog-text' style="font-weight:bold; padding-right:16px;">results: <?php echo $resultstotal;?></div>
<!-- Display area -->
<?php
function addOrUpdateUrlParam($name, $value) // function to create links adding new html parameters while keeping the old ones
{
$params = $_GET;
unset($params[$name]);
$params[$name] = $value;
return basename($_SERVER['PHP_SELF']).'?'.http_build_query($params);
}
// code to create pagination
$urlnext = addOrUpdateUrlParam("page", $page+1);
$urlprevious = addOrUpdateUrlParam("page", $page-1);
$itemsperpage = 20;
$pagestotal = ceil(count($finalresult)/$itemsperpage);
// STEP 4 code the calls the results of the sorted and formatted search array and inserts results into the page
$arrayslice = array_slice($finalresult,(0+($itemsperpage*($page -1))),$itemsperpage);
foreach ($arrayslice as $id){
echo get_grade($id,$zigblog[$id],$zigblog);
}
// Pagination links
?>
<div class="w3-center">
<?php if ($page > 1){echo "<a href='".$urlprevious."'>";} ?><button class="w3-button w3-large <?php if ($page > 1){echo "w3-black";} else {echo "w3-lightgrey";} ?>">‹</button><?php if ($page > 1){echo "</a>";} ?>
<?php if ($page < $pagestotal){echo "<a href='".$urlnext."'>";} ?><button class="w3-button w3-large <?php if ($page < $pagestotal){echo "w3-black";} else {echo "w3-lightgrey";} ?>">›</button><?php if ($page < $pagestotal){echo "</a>";} ?>
</div>
<?php include("inc/footer.php");?>
<script>
var slideCol = document.getElementById("id1");
var y = document.getElementById("f");
y.innerHTML = slideCol.value;
slideCol.oninput = function() {
y.innerHTML = this.value;
}
</script>
<script>
var slideCol2 = document.getElementById("id2");
var y2 = document.getElementById("g");
y2.innerHTML = slideCol2.value;
slideCol2.oninput = function() {
y2.innerHTML = this.value;
}
</script>
</html>