forked from buckyroberts/Social-Network
-
Notifications
You must be signed in to change notification settings - Fork 0
/
photo_edit.php
77 lines (58 loc) · 2.64 KB
/
photo_edit.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
<?php
require(dirname(__FILE__) . '/includes/bootstrap.php');
//Getting Current User ID
if(!($userID = buckys_is_logged_in())){
buckys_redirect('/index.php', MSG_NOT_LOGGED_IN_USER, MSG_TYPE_ERROR);
}
//Getting UserData from Id
$userData = BuckysUser::getUserData($userID);
//If Photo ID is empty, goto photo management page
if(!isset($_REQUEST['photoID']))
buckys_redirect('/photo_manage.php', MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
$photoId = $_REQUEST['photoID'];
$photo = BuckysPost::getPostById($photoId);
//Getting User Albums
$albums = BuckysAlbum::getAlbumsByUserId($userID);
//Getting Photo Albums
$photoAlbums = BuckysAlbum::getAlbumsByPostId($photoId);
if(!$photoAlbums)
$photoAlbums = [];
//If photo id is not correct or the owner is not the current user, goto photo management page
if(!$photo || $photo['poster'] != $userID)
buckys_redirect('/photo_manage.php', MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
if(isset($_POST['action'])){
//Create New Album
if($_POST['action'] == 'save-photo'){
if($photo['poster'] != $userID){
buckys_redirect('/photo_manage.php', MSG_INVALID_REQUEST, MSG_TYPE_ERROR);
}
//Update Photo Caption and Privacy
BuckysPost::updatePhoto($userID, $_POST);
//Change user profile image
if($_POST['photo_visibility'] == 2){
if(!$photo['is_profile']){
BuckysPost::createProfileImage($photo, $_POST);
}
//Update profile image with old one
BuckysUser::updateUserFields($userID, ['thumbnail' => $photo['image']]);
}else if($userData['thumbnail'] == $photo['image']){ //If it was a profile image and now it is not, remove it from the profile image
BuckysUser::updateUserFields($userID, ['thumbnail' => '']);
}
//Save Album
if(isset($_POST['album']) && $_POST['album'] != '' && isset($albums[$_POST['album']])){
BuckysAlbum::addPhotoToAlbum($_POST['album'], $photo['postID']);
}
buckys_redirect('/photo_edit.php?photoID=' . $photo['postID'], MSG_PHOTO_UPDATED, MSG_TYPE_SUCCESS);
exit;
}
}
$set_profile = isset($_GET['set_profile']) ? $_GET['set_profile'] : null;
buckys_enqueue_stylesheet('account.css');
buckys_enqueue_stylesheet('posting.css');
buckys_enqueue_stylesheet('jquery.Jcrop.css');
buckys_enqueue_javascript('jquery.Jcrop.js');
buckys_enqueue_javascript('jquery.color.js');
buckys_enqueue_javascript('edit_photo.js');
$TNB_GLOBALS['content'] = 'photo_edit';
$TNB_GLOBALS['title'] = "Edit Photo - " . TNB_SITE_NAME;
require(DIR_FS_TEMPLATE . $TNB_GLOBALS['template'] . "/" . $TNB_GLOBALS['layout'] . ".php");