-
Notifications
You must be signed in to change notification settings - Fork 0
/
authors_info.php
649 lines (614 loc) · 27.1 KB
/
authors_info.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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
<?php
require_once'Core/init.php';
$user = new User;
if(!$user->isLoggedIn())
Redirect::to('index.php');
?>
<!DOCTYPE html>
<html>
<head>
<link rel="preload" as="script" href="Includes/js/materialize.min.js">
<link rel="preload" as="script" href="https://use.fontawesome.com/819d78ad52.js">
<link rel="preload" as="script" href="Includes/js/jquery.min.js">
<link rel="preload" as="style" href="//fonts.googleapis.com/icon?family=Material+Icons">
<title>
Update Profile
</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="keywords" content="blog, technology, code, program, alorithms"/>
<meta name="description" content="We emphaisze on solving problems">
<link href="//fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/css/materialize.min.css">
<style>
body
{
background-color: #fafafa;
}
.brand-logo
{
display: inline-block;
height: 100%;
}
.brand-logo > img {
vertical-align: middle
}
.col.s12 > .btn
{
width: 100%;
}
nav ul .dropdown-button
{
width: 200px !important;
}
input[type="search"]
{
height: 64px !important; /* or height of nav */
}
.authors_profile_pic
{
max-height: 300px !important;
}
.pagination li.active
{
background-color: #42A5F5;
}
.card .card-content
{
padding-bottom: 0px;
padding-top: 10px;
}
div .margin-eliminate
{
margin-bottom: 10px;
}
p .margin-eliminate
{
margin: 0px;
}
ul .align-inline
{
overflow: hidden;
}
.align-inline > li
{
display: inline-block;
margin-right: 10px;
}
.edit-blog
{
position: absolute;
top: 20px;
right: 50px;
}
.delete-blog
{
position: absolute;
top: 20px;
right: 20px;
}
.token_container
{
display: none;
}
</style>
</head>
<body>
<?php
include'header.php';
?>
<script type="text/javascript">
document.getElementById('nav-bar').classList.remove('transparent');
</script>
<div class="container">
<div class="section">
<form action="" method="post" enctype="multipart/form-data">
<div class="row">
<div class="col l4 s12 m6 offset-m3">
<img class="responsive-img materialboxed authors_profile_pic" src="<?php echo Config::get('url/upload_dir').'/'.$user->data()->image_url ?>" width="100%">
<div class="row">
<div class="col s12">
<div class="file-field input-field">
<div class="btn blue">
<span>Upload</span>
<input type="file" name="profile_pic" id="profile_pic">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text" placeholder="Upload image" >
</div>
</div>
</div>
</div>
</div>
<div class="col l6 offset-l2 s12">
<div class="row">
<div class="input-field col s12">
<input type="text" name="name" id="name" value="<?php echo $user->data()->name; ?>">
<label for="name">Name</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input disabled type="text" name="username" id="username" value="<?php echo $user->data()->username ?>">
<label for="username">Username</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input type="text" name="github_username" id="github_username" value="<?php echo $user->data()->github_username; ?>">
<label for="github_username">Github Username</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input type="text" name="facebook_username" id="facebook_username" value="<?php echo $user->data()->facebook_username ?>">
<label for="facebook_username">Facebook Username</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input type="text" name="twitter_username" id="twitter_username" value="<?php echo $user->data()->twitter_username ?>">
<label for="twitter_username">Twitter Username</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input type="text" name="google_profileId" id="google_profileId" value="<?php echo $user->data()->google_profileId ?>">
<label for="google_profileId">Google ProfileId</label>
</div>
</div>
<div class="row token_container">
<div class="input-field col s12">
<input type="hidden" name="_token" id="_token" value="<?php echo Token::generate(); ?>">
</div>
</div>
<div class="row hide-on-large-only">
<div class="input-field col s12">
<label for="description">Tell us about youself</label>
<textarea class="materialize-textarea" id="description" name="description"><?php echo $user->data()->user_description ?></textarea>
</div>
</div>
</div>
</div>
<div class="row hide-on-med-and-down">
<div class="col s12">
<label for="description">Tell us about youself</label>
<textarea class="materialize-textarea" id="description" name="description"><?php echo $user->data()->user_description ?></textarea>
</div>
</div>
<div class="row">
<div class="col s12 l3 m4">
<button type="button" class="btn waves-effect waves-light blue" name="update" id="update">Update</button>
</div>
</div>
</form>
</div>
</div>
<div class="container">
<div class="row">
<div class="section">
<ul class='align-inline'>
<li>
<h5>Blogs Written</h5>
</li>
<li>
<a class="btn-floating pulse btn-small waves-effect waves-light blue toggle-user-blogs"><i class="material-icons">add</i></a>
</li>
</ul>
</div>
<div class="user-blogs">
<?php
$blogs_based_on_user = DB::getInstance()->SortByField('blogs', array('created_on', 'DESC'), array('users_id', '=', $user->data()->id));
$blog_count = $blogs_based_on_user->count(); // getting the total count of blogs written by current user
$blogs_based_on_user = $blogs_based_on_user->results(); // getting the id of blogs who have queried tag in them
if($blog_count == 0)
{
echo
"<h6 class='center-align'>You have't written any blogs yet. <a href='write_blog.php'>Write your very first blog</a></h6>";
}
else
{
echo "<div class='content'>";
foreach($blogs_based_on_user as $blog_based_on_user)
{
$blog = DB::getInstance()->get('blogs', array('id', '=', $blog_based_on_user->id))->first(); // fetch blogs from table 'blogs' with blog_id of $blog_based_on_tag as parameter
$blog_tags = DB::getInstance()->get('blog_tags', array('blog_id', '=', $blog->id)); // getting all blog_tags associated with the fetched blog
$blog_tags = $blog_tags->results();
$date=strtotime($blog->created_on); // changing the format of timestamp fetched from the database, converting it to milliseconds
echo
"<div class='col s12 m12'>
<div class='card horizontal white'>
<div class='card-content'>
<span class='card-title'>".date('M d Y', $date)."</span>
<div class='row margin-eliminate'>
<div class='col s12'>
<h5><a class='views' data-attribute='{$blog->views}' href='/view_blog.php?blog_id={$blog->id}'".">".ucfirst($blog->title)."</a></h5>
<h6>".ucfirst($blog->description)."</h6>
</div>
</div>
<div class='row margin-eliminate'>
<div class='valign-wrapper'>
<div class='col l6 s4'>
<div class='valign-wrapper'>
<i class='material-icons hide-on-small-only' style='color:grey'>book</i>
<p class='grey-text'>".$blog->blog_minutes_read." min read</p>
</div>
</div>
<div class='col l6 s8'>
<a class='chip' href='/user_profile.php?user={$user->data()->username}'>
<img src='".Config::get('url/upload_dir')."/{$user->data()->image_url}' alt='Contact Person'>{$user->data()->username}
</a>
</div>
</div>
</div>
<div class='row'>
<div class='measure-count' data-attribute='{$blog->id}'>
<div class='col s2 l1 m1'>
<i class='fa fa-eye fa-2x' aria-hidden='true' style='color:grey'></i>
</div>
<div class='col s1 l1 m1'>
{$blog->views}
</div>
<div class='col s2 l1 m1 offset-m1 offset-s1 offset-l1'>
<i class='fa fa-thumbs-up fa-2x' aria-hidden='true' style='color:grey'></i>
</div>
<div class='col s1 l1 m1'>
{$blog->likes}
</div>
<div class='col s2 l1 m1 offset-m1 offset-s1 offset-l1'>
<i class='fa fa-thumbs-down fa-2x' aria-hidden='true' style='color:grey'></i>
</div>
<div class='col s1 l1 m1'>
{$blog->dislikes}
</div>
</div>
</div>
<div class='row'>
<div class='col s12'>";
foreach($blog_tags as $blog_tag)
{
$tag = $blog_tag->tags;
echo "<a class='chip' href='/view_blogs_tag.php?tag={$tag}'>{$tag}</a>";
}
echo
"</div>
</div>
</div>
<ul>
<li>
<a href='update_blog.php?blog_id={$blog->id}' class='blue-text edit-blog right' data-attribute='{$blog->id}'><i class='material-icons'>mode_edit</i></a>
</li>
<li>
<a href='#' class='blue-text delete-blog right' data-attribute='{$blog->id}'><i class='material-icons'>delete</i></a>
</li>
</ul>
</div>
</div>";
}
echo "</div>";
}
/* uncomment the following code if want to add pagination to the page */
// $blogs = DB::getInstance()->SortByField('blogs', array('created_on', 'DESC'), array('users_id', '=', $user->data()->id));
// $num_blogs = $blogs->count();
// $num_pages = ceil($num_blogs/5);
// $blogs = $blogs->results();
// $blogs = array_splice($blogs, 0, 5);
// if($num_blogs) // show blogs if there are any, otherwise show message 'No blogs'
// {
// echo "<div class='content' id='content'>";
// foreach($blogs as $blog)
// {
// $blog_tags = DB::getInstance()->get('blog_tags', array('blog_id', '=', $blog->id));
// $blog_tags = $blog_tags->results();
// $date=strtotime($blog->created_on); // changing the format of timestamp fetched from the database, converting it to milliseconds
// echo
// "<div class='row blog'>
// <div class='col s12 hide-on-large-only'>
// <div class='col s6'>
// <blockquote>".
// date('M d', $date).' '.
// date('Y', $date).
// "</blockquote>
// </div>
// <div class='col s6'>
// <a href='#' class='blue-text delete-blog' data-attribute='{$blog->id}'><i class='material-icons right'>delete</i></a> <a href='update_blog.php?blog_id={$blog->id}' class='blue-text edit-blog' data-attribute='{$blog->id}'><i class='material-icons right'>mode_edit</i></a>
// </div>
// </div>
// <div class='col s2 l2 hide-on-med-and-down'>
// <blockquote>".
// date('M', $date)."<br>".
// date('Y d', $date).
// "</blockquote>
// </div>
// <div class='col s12 l10'>
// <div class='row hide-on-med-and-down'>
// <div class='col s12 l10'>
// <h5><a class='views' data-attribute='{$blog->views}' href='".Config::get('url/endpoint')."/view_blog.php?blog_id={$blog->id}'".">".ucfirst($blog->title)."</a></h5>
// </div>
// <div class='hide-on-small-only'>
// <a href='#' class='blue-text delete-blog' data-attribute='{$blog->id}'><i class='material-icons right'>delete</i></a> <a href='update_blog.php?blog_id={$blog->id}' class='blue-text edit-blog' data-attribute='{$blog->id}'><i class='material-icons right'>mode_edit</i></a>
// </div>
// </div>
// <h6>".ucfirst($blog->description)."</h6><br>
// <div class='row'>
// <div class='measure-count' data-attribute='{$blog->id}'>
// <div class='col s2 l1'>
// <i class='fa fa-eye fa-2x' aria-hidden='true' style='color:grey'></i>
// </div>
// <div class='col s1 l1'>
// {$blog->views}
// </div>
// <div class='col s2 l1 offset-s1 offset-l1'>
// <i class='fa fa-thumbs-up fa-2x' aria-hidden='true' style='color:grey'></i>
// </div>
// <div class='col s1 l1'>
// {$blog->likes}
// </div>
// <div class='col s2 l1 offset-s1 offset-l1'>
// <i class='fa fa-thumbs-down fa-2x' aria-hidden='true' style='color:grey'></i>
// </div>
// <div class='col s1 l1'>
// {$blog->dislikes}
// </div>
// </div>
// </div>";
// foreach($blog_tags as $blog_tag)
// {
// echo "<div class='chip'>".$blog_tag->tags."</div>";
// }
// echo
// "<div class='section'>
// <div class='divider'></div>
// </div>
// </div>
// </div>";
// }
// echo
// "</div>
// <div class='section center-align'>
// <ul class='pagination'>";
// for($x = 1; $x <= $num_pages; $x++)
// {
// if($x == 1)
// {
// echo "<li class='waves-effect pagination active'><a href='#' class='blog-pagination'>".$x."</a></li>";
// }
// else
// {
// echo "<li class='waves-effect pagination'><a href='#' class='blog-pagination'>".$x."</a></li>";
// }
// }
// echo
// "</ul>
// </div>";
// }
// else
// {
// echo "<div class='section center-align'>No blogs yet. <a href='write_blog.php'>Write the very first blog.</a></div>";
// }
?>
</div>
</div>
</div>
<footer class="page-footer blue lighten-1">
<div class="container">
<div class="row">
<div class="col l6 s12">
<h5 class="white-text">TechSense</h5>
<p class="grey-text text-lighten-4">Publish your passions your way. Whether you'd like to share your knowledge, experiences or the latest tech news, create a unique and beautiful blog for free.</p>
</div>
<div class="col l4 offset-l2 s12">
<h5 class="white-text">View Our Other Projects</h5>
<ul>
<li><a class="grey-text text-lighten-3" href="https://www.silive.in" target="blank">silive.in</a></li>
<li><a class="grey-text text-lighten-3" href="#!" target="blank">Blood Donation Campaign 2017</a></li>
<li><a class="grey-text text-lighten-3" href="#!" target="blank">Table Tennis Tournament</a></li>
</ul>
</div>
</div>
</div>
<div class="footer-copyright">
<div class="container center-align">
© 2017 Software Incubator
</div>
</div>
</footer>
<script src="Includes/js/jquery.min.js"></script>
<script src="https://use.fontawesome.com/819d78ad52.js"></script>
<script type="text/javascript" src="Includes/js/materialize.min.js"></script>
<script type="text/javascript">
$("#update").off('click');
// $('.nav-bar').removeClass('transparent');
if(typeof(Storage) !== "undefined")
{
console.log('not undefined');
if(sessionStorage.getItem("flashMessage") !== null)
{
Materialize.toast(sessionStorage.getItem("flashMessage"), 5000 ,'green');
sessionStorage.removeItem('flashMessage');
}
}
$(document).ready(function(){
$(".button-collapse").sideNav();
$("#profile_pic").change(readURL);
$('#update').on('click', function() {
if(!validateData())
{
return false;
}
var data = new FormData();
var file_data = $('input[type="file"]')[0].files;
if(file_data.length)
{
data.append("profile_pic", file_data[0]);
}
var input_data = $('form').serializeArray();
$.each(input_data, function(key, input){
data.append(input.name, input.value);
});
$.ajax({
url: 'authors_info_backend.php',
data: data,
type: 'POST',
contentType: false,
dataType: "json",
processData: false, // not processing the data
success: function(response)
{
// var response = JSON.parse(response);
console.log(response._token);
if(response.error_status === true)
{
console.log(response._token);
if(response.error_code != 1)
{
$('#_token').val(response._token);
}
Materialize.toast(response.error, 5000, "red");
$('#description').focus();
}
else
{
$('#_token').val(response._token);
Materialize.toast("Your Information has been updated successfully", 5000, "green");
}
}
});
});
$('.toggle-user-blogs').click(function() {
$('.user-blogs').slideToggle('slow');
});
function readURL()
{
$('.authors_profile_pic').attr('src', '').hide(); // remove the current src of image
if (this.files && this.files[0]) { // checking if any present in the files array
var reader = new FileReader(); // instantiating fileReader
$(reader).load(function(e) { // when loading finishes, set the src to the new image's url
$('.authors_profile_pic').attr('src', e.target.result)
});
reader.readAsDataURL(this.files[0]); // generating thumbnail
}
}
$('.authors_profile_pic').load(function(e) {
$(this).css('height', '300px').show(); // setti
});
function validateData()
{
var name = $('#name').val();
var description = $('#description').val();
if(name === '')
{
Materialize.toast('Name is required', 5000, 'red');
return false;
}
if(description === '')
{
Materialize.toast('Description is required', 5000, 'red');
return false;
}
return true;
}
// function pagination(object)
// {
// $('.pagination').find('.active').removeClass('active');
// $(object).parent().addClass('active');
// var page_id = $(object).html();
// console.log("page_id = " + page_id);
// // var _token = $('#_token').val();
// $.ajax({
// type: 'POST',
// url: 'pagination_backend.php',
// data: {page_id: page_id, author: true},
// dataType: "json",
// cache: false,
// async: false,
// success: function(response)
// {
// // var response = JSON.parse(response);
// console.log(response);
// if(response.error_status)
// {
// Materialize.toast(response.error, 5000, 'red');
// }
// else
// {
// // console.log("count records is " + response.count);
// // $('#_token').val(response._token);
// $('.content').html(response.content);
// }
// }
// });
// }
// function alterPagination()
// {
// var object = $('li.active').find('.blog-pagination'); //getting the child of active class of pagination
// pagination(object); // fetching the blogs again whenever a blog gets deleted in order to maintain pagination
// var counter = 0;
// $('.content').find('.blog').each(function(){
// ++counter;
// });
// if(counter < 5) // 5 is the value of maximum that can be shown in one page
// {
// if($('li.active').next().length)
// $('li.active').next().remove();
// }
// if(counter == 0)
// {
// var current_page = parseInt($('li.active').find('.blog-pagination').html()); // getting which page is active right now
// if(current_page > 1) // if current_page > 1 then proceed
// {
// var obj = $('.pagination').find('li.active'); // getting active class
// pagination($(obj).prev().find('.blog-pagination')); // fetching the blogs again, because here switching from one page to another page is needed to be done
// $(obj).remove(); // removing the current page since there's no blog in it
// }
// else if(current_page == 1)
// {
// $('.pagination').remove();
// }
// }
// }
// $('.blog-pagination').click(function(e){
// e.preventDefault();
// pagination(this);
// });
$('.content').on('click', '.delete-blog', function(e){
e.preventDefault();
var user_response = confirm("Are you sure you want to delete this blog?");
if(user_response == true)
{
var blog_id = $(this).attr('data-attribute');
// var _token = $('#_token').val();
var object = $(this);
$.ajax({
type: 'POST',
url: 'delete_blog.php',
data: {blog_id: blog_id},
dataType: "json",
cache: false,
success: function(response)
{
// var response = JSON.parse(response);
// console.log(response);
// $('#_token').val(response._token);
if(response.error_status == true)
{
Materialize.toast(response.error, 5000, "red");
}
else
{
Materialize.toast("The blog has been deleted successfully", 5000, "green");
$(object).parent().parent().parent().remove(); // to remove the blog
// alterPagination();
}
}
});
}
else
{
return false;
}
});
});
</script>
</body>
</html>