-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
167 lines (137 loc) · 5.27 KB
/
index.php
File metadata and controls
167 lines (137 loc) · 5.27 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
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
<?php
/*
+ ----------------------------------------------------------------------------+
| PHPDirector.
| $License: GPL General Public License
| $Website: phpdirector.co.uk
| $Author: Ben Swanson
| $Contributors - Dennis Berko and Monte Ohrt (Monte Ohrt)
+----------------------------------------------------------------------------+
*/
require('header.php');
// required connect
SmartyPaginate::connect();
// set items per page
$limit = config('vids_per_page');
SmartyPaginate::setLimit($limit);
//SORTING???
switch ($_GET["sort"]){
case "name":
$sort = "name";
break;
case "date":
$sort = "date";
break;
case "views":
$sort = "views";
break;
default:
$sort = "date";
$order1 = "DESC";
}
//Check if theres a Get called order then is its down order by DESC if its up dont order by DESC if no get varriable order by non DESC
if(isset($_GET["order"])){
$order = $_GET["order"];
if($order == "up"){
$order1 = "";
}
if($order == "down"){
$order1 = "DESC";
}
}
//SORTING END ???
if ($_GET["pt"] == "all") {
$_query = sprintf("SELECT SQL_CALC_FOUND_ROWS * FROM pp_files WHERE `approved` = '1' AND `reject` = '0' ORDER BY $sort $order1 LIMIT %d,%d",
SmartyPaginate::getCurrentIndex(), SmartyPaginate::getLimit());
}elseif ($_GET["pt"] == "feature") {
$_query = sprintf("SELECT SQL_CALC_FOUND_ROWS * FROM pp_files WHERE `approved` = '1' AND `feature` = '1' AND `reject` = '0' ORDER BY $sort $order1 LIMIT %d,%d",
SmartyPaginate::getCurrentIndex(), SmartyPaginate::getLimit());
}elseif (isset($_GET["cat"])) {
$cat = $_GET["cat"];
$_query = sprintf("SELECT SQL_CALC_FOUND_ROWS * FROM pp_files WHERE `category` = '$cat' AND `approved` = '1' ORDER BY $sort $order1 LIMIT %d,%d",
SmartyPaginate::getCurrentIndex(), SmartyPaginate::getLimit());
$smarty->assign('pagetype', $cat);
}elseif (isset($_GET[search])){
$search = $_GET[search];
$_query = sprintf("SELECT SQL_CALC_FOUND_ROWS * FROM pp_files WHERE `name` like '%%$search%%' AND `approved` = '1' ORDER BY $sort $order1 LIMIT %d,%d",
SmartyPaginate::getCurrentIndex(), SmartyPaginate::getLimit());
$smarty->assign('pagetype', 'Search Results');
}elseif(isset($_GET[tag])){
//Dam those people who want to see which videos have a tag!
//This is getting the tags from pp_tags
$tagquery = mysql_query('SELECT video_id FROM `pp_tags` WHERE `name` LIKE CONVERT(_utf8 \''.$_GET[tag].'\' USING latin1) COLLATE latin1_swedish_ci');
//This is so at the end of $in it doesn't have a extra comma
$tagrows = mysql_num_rows($tagquery);
$in = null;
$i = 0;
while ($tags = mysql_fetch_assoc($tagquery)){
$i++;
if($i == $tagrows){//This is so at the end of $in it doesn't have a extra comma
$in = $in." '".$tags[video_id]."'";
}else{
$in = $in." '".$tags[video_id]."',";
}
}
$_query = sprintf("SELECT SQL_CALC_FOUND_ROWS * FROM pp_files WHERE `approved` = '1' AND `id` IN (".$in.") AND `reject` = '0' ORDER BY $sort $order1 LIMIT %d,%d",SmartyPaginate::getCurrentIndex(), SmartyPaginate::getLimit()); //$in is all the rows that have the correct tag
$smarty->assign('pagetype', 'Tags');
}else{
$_query = sprintf("SELECT SQL_CALC_FOUND_ROWS * FROM pp_files WHERE `approved` = '1' AND `feature` = '1' AND `reject` = '0' ORDER BY $sort $order1 LIMIT %d,%d",
SmartyPaginate::getCurrentIndex(), SmartyPaginate::getLimit());
$smarty->assign('pagetype', 'Featured Videos');
};
$_result = mysql_query($_query); // assign your db results to the template
$_data = array();
$i=0;
while ($_row = mysql_fetch_array($_result, MYSQL_ASSOC)) {
$month = date("M", strtotime($_row[date]));
$day = date("d", strtotime($_row[date]));
//image
if ($_row['picture'] !== null){
$tehpic = $_row[picture];
$amp = array("&");
$new_replace = array("&");
$newphrase = str_replace("$amp", "$new_replace", "$tehpic");
$picture = $newphrase;
}
//image
$tmp = array(
'id' => $_row['id'],
'month' => $month,
'day' => $day,
'name' => $_row['name'],
'creator' => $_row['creator'],
'picture' => $picture,
'description' => $_row['description'],
'br' => $br
);
$_data[$i++] = $tmp;
// collect each record into $_data
}
// now we get the total number of records from the table
// now we get the total number of records from the table
$_query = "SELECT FOUND_ROWS() as total";
$_result = mysql_query($_query);
$_row = mysql_fetch_array($_result, MYSQL_ASSOC);
SmartyPaginate::setTotal($_row['total']);
mysql_free_result($_result);
///DB
$smarty->assign('videos', $_data);
if ($_row['total'] == 0){ //if no videos display error.
$error = "There Where No Results";
$smarty->assign_by_ref('error', $error);
$smarty->display('error.tpl');
exit;
}
// assign {$paginate} var
SmartyPaginate::assign($smarty);
if (isset($_GET["pt"])){
SmartyPaginate::setUrl('index.php?pt='.$_GET["pt"]);
}elseif(isset($_GET["cat"])){
SmartyPaginate::setUrl('index.php?cat='.$_GET["cat"]);
}else{
}
// display results
$smarty->display('index.tpl');
SmartyPaginate::disconnect();
mysql_close($mysql_link);
?>