-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
341 lines (319 loc) · 11.1 KB
/
functions.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<?php
include 'inc/db.inc.php';
function get_top_uploaders()
{
$limit=3;
$query="SELECT * from users order by uploads desc limit $limit";
$query_run=mysql_query($query);
if(mysql_num_rows($query_run)>0)
{
while ($row=mysql_fetch_assoc($query_run))
{
# code...
$pic=0;
$author=$row['username'];
$avatar_image_folder='uploads/'.$author.'/avatar';
/*** file handling for getting the avatar image ***/
if($handle=opendir($avatar_image_folder))
{ //now we check for the avatar image in avatar_image_folder.only one image.
while(false!==($entry=readdir($handle)))//not false means ..true..we check for permisiion for opening the folder then read it with readdir.
{
if (($entry!='.') and ($entry!='..'))
{//there is no '.' or '..' in a file Name
# code...
$pic=1;//as if there is no '.' or '..' means there ia a pic.
$avatar_image_path = $avatar_image_folder.'/'.$entry;
//echo "<img src=$avatar_image_path alt=$entry width='300px'/>";
?>
<div class="col-md-4">
<div class="gallery-image">
<img src="<?php echo $avatar_image_path;?>"class="front">
<div class="back">
<div class="back-content">
<h3><?php echo $author; ?></h3>
<h6><i>No. of Uploads </i><?php echo $row['uploads']; ?></h6>
</div>
</div>
</div>
</div>
<?php
}
}
closedir($handle);//we need to close the handle if we have opened it.
}
if($pic==0){
?>
<div class="col-md-4">
<div class="gallery-image">
<img src="images/user-default.jpg"class="front">
<div class="back">
<div class="back-content">
<h3><?php echo $author; ?></h3>
<h6><i>No. of Uploads:</i><?php echo $row['uploads']; ?></h6>
</div>
</div>
</div>
</div>
<?php
}
}
}
}
function get_recent_pics()
{
$limit=3;
$query="SELECT * from pics order by pid desc limit $limit";
$query_run=mysql_query($query);
if(mysql_num_rows($query_run)>0)
{
while ($row=mysql_fetch_assoc($query_run)) {
# code...
$picname=$row['picname'];
$pid=$row['pid'];
$author=$row['username'];
$src='uploads/'.$author.'/'.$picname;
?>
<div class="col-md-4">
<div class="gallery-image">
<img src="<?php echo $src;?>"class="front">
<div class="back">
<div class="back-content">
<h3><?php echo $picname ?></h3>
<h6><i>By </i><?php echo $author ?></h6>
<a href="<?php echo $src?>"data-lightbox="gallery"><i class="fa fa-expand"></i></a>
</div>
</div>
</div>
</div>
<?php
}
}
}
function get_home_gallery_content($x)
{
$approved=1;
$query="SELECT * from pics where approved='$approved' limit $x";//that is length from 0 to 2 i.e length is 3;
$query_run=mysql_query($query);
if(mysql_num_rows($query_run)>0){
while($row=mysql_fetch_assoc($query_run))
{
$picname=$row['picname'];
$pid=$row['pid'];
$author=$row['username'];
$src='uploads/'.$author.'/'.$picname;
?>
<div class="col-md-4">
<div class="gallery-image">
<img src="<?php echo $src;?>" class="front">
<div class="back">
<div class="back-content">
<h3><?php echo $picname ?></h3>
<h6><i>By </i><?php echo $author ?></h6>
<a href="<?php echo $src?>"data-lightbox="gallery"><i class="fa fa-expand"></i></a>
</div>
</div>
</div>
</div>
<?php
}
}
?>
<script type="text/javascript">
lightbox.option({
'resizeDuration': 200,
'wrapAround': true
})
</script>
<?php
}
function get_gallery_content()
{
if(isset($_GET['page'])) //we need two things , page number and no. of images per page.
{
$page=(int)$_GET['page'];
}
else {
$page=$_GET['page']=1;
}
if(isset($_GET['per_page'])&&($_GET['per_page']<21))
{
$per_page=$_GET['per_page'];
}
else {
$per_page=3;
}
$approved=1;
$total_query="SELECT * from pics where approved='$approved'";
$total=mysql_num_rows(mysql_query($total_query));//to get the no. of images so we are retrieving the no. of rows we are getting
$pages=ceil($total/$per_page);//no. of pages ,to make it round of we have ceil function in php.
//echo $pages;
$start=($page*$per_page)-$per_page;//needed for query purpose , if at 1st page so start will be 0 , we want images to be shown from 1 to 3so index will be from 0 to 2.
//echo $start;
$query="SELECT * from pics where approved='$approved' limit $start,$per_page";//that is length from 0 to 2 i.e length is 3;
$query_run=mysql_query($query);
if(mysql_num_rows($query_run)>0){
while($row=mysql_fetch_assoc($query_run))
{
$picname=$row['picname'];
$pid=$row['pid'];
$author=$row['username'];
$src='uploads/'.$author.'/'.$picname;
?>
<div class="col-md-4">
<div class="gallery-image">
<img src="<?php echo $src;?>" class="front">
<div class="back">
<div class="back-content">
<h3><?php echo $picname ?></h3>
<h6><i>By </i><?php echo $author ?></h6>
<a href="<?php echo $src?>"data-lightbox="gallery"><i class="fa fa-expand"></i></a>
</div>
</div>
</div>
</div>
<?php
}
}
?>
<div class="clearfix">
</div>
<div id="pagination">
<?php
for($i=1;$i<=$pages;$i++)
{
?>
<a href="?page=<?php echo $i.'&perpage='.$per_page;?>">Page<?php echo $i; ?></a>
<?php
}
?>
</div>
<script type="text/javascript">
lightbox.option({
'resizeDuration': 200,
'wrapAround': true
})
</script>
<?php
}
function get_profile_info($username){
$fname="";
$lname="";
$email="";
$bio="";
$query="select * from users where username='$username'";
$query_run=mysql_query($query);
if(mysql_num_rows($query_run)>0){
echo "<div class='col-md-3'>
First Name :<br>
Last Name :<br>
Email :<br>
Bio :<br>
</div>";
while($row=mysql_fetch_assoc($query_run)){
echo "<div class='col-md-4'>";
echo $fname=$row['fname'].'<br>';
echo $lname=$row['lname'].'<br>';
echo $email=$row['email'].'<br>';
if($row['bio']==''){
echo 'you did not provide your bio yet<br>';
}
else{
echo $row['bio'];
}
echo "</div>";
}
}
}
function get_avatar_image($user){
$pic=0; //to check avatar folder contains only one image.
$upload_folder="uploads"; //its a folder
$user_folder=$upload_folder.'/'.$user; //user folder
$avatar_image_folder=$user_folder.'/avatar';
if(is_dir($upload_folder)) //is Directory ...means if a folder exists or not.
{
if(is_dir($user_folder)){ //now if we have upload folder so we check for user folder
}
else {
mkdir($user_folder);
}
}
else { //if no such folder exists then we create one.
mkdir($upload_folder);
if(is_dir($user_folder)){
}
else {
mkdir($user_folder);
}
}
if(is_dir($avatar_image_folder)) { //now for check for avatar_image_folder
# code...
}
else {
mkdir($avatar_image_folder);
}
if($handle=opendir($avatar_image_folder)){ //now we check for the avatar image in avatar_image_folder.only one image.
while(false!==($entry=readdir($handle)))//not false means ..true..we check for permisiion for opening the folder then read it with readdir.
{
if (($entry!='.') and ($entry!='..')) {//there is no '.' or '..' in a file Name
# code...
$pic=1;//as if there is no '.' or '..' means there ia a pic.
$avatar_image_path = $avatar_image_folder.'/'.$entry;
echo "<img src=$avatar_image_path alt=$entry id=avatar-image-id width='300px'/>";
}
}
closedir($handle);//we need to close the handle if we have opened it.
}
if($pic==0){
echo "<img src='images/user-default.jpg' id=avatar-image-id width='300px'/>"; //default profile pic.
}
}
//uploaded pics
function get_user_uploaded_pics($username){
$query="SELECT * from pics where username='$username' order by pid desc";
$query_run=mysql_query($query);
if(mysql_num_rows($query_run)>0){
while ($row=mysql_fetch_assoc($query_run)) {
# code...
$picid=$row['pid'];
$picname=$row['picname'];
$path='uploads/'.$username.'/'.$picname;
?>
<div class="col-md-4">
<img src="<?php echo $path;?>">
</div>
<?php
}
}
}
//admin function
function get_unapproved_pics(){
$approved=0;
$query="SELECT * from pics where approved='$approved'";
$queryrun=mysql_query($query);
if(mysql_num_rows($queryrun)>0){
while($row=mysql_fetch_assoc($queryrun))
{
$pid=$row['pid'];
$picname=$row['picname'];
$uname=$row['username'];
$src='uploads/'.$uname.'/'.$picname;
?>
<div id="row-<?php echo $pid?>">
<div class="col-md-4">
<img src="<?php echo $src; ?>"id="<?php echo $pid;?>"/>
</div>
<div class="col-md-4">
<?php echo $picname;?>
</div>
<div class="col-md-4">
<button id="yes-<?php echo $pid;?>"onclick="approveimage(<?php echo $pid;?>)">YES</button>
<button id="no-<?php echo $pid;?>"onclick="deleteimage(<?php echo $pid;?>)">No</button>
</div>
</div>
<div class="clearfix">
</div>
<?php
}
}
}
?>