//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, array('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, array('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'); $BUCKYS_GLOBALS['content'] = 'photo_edit'; $BUCKYS_GLOBALS['title'] = "Edit Photo - BuckysRoom"; require DIR_FS_TEMPLATE . $BUCKYS_GLOBALS['template'] . "/" . $BUCKYS_GLOBALS['layout'] . ".php";
if (trim($_POST['album_name']) == '') { buckys_redirect('/photo_album_edit.php?albumID=' . $_POST['albumID'], MSG_ALBUM_TITLE_EMPTY, MSG_TYPE_ERROR); } BuckysAlbum::updateAlbum($_POST['albumID'], trim($_POST['album_name']), $_POST['visibility'], $_POST['photos']); buckys_redirect("/photo_album_edit.php?albumID=" . $_POST['albumID'], MSG_ALBUM_UPDATED); } else { if ($_POST['action'] == 'remove-from-album' || $_POST['action'] == 'add-to-album') { $photoID = $_POST['photoID']; $photo = BuckysPost::getPostById($photoID); //Check Photo Owner if ($photo['poster'] != $userID) { echo MSG_INVALID_REQUEST; exit; } if ($_POST['action'] == 'remove-from-album') { BuckysAlbum::removePhotoFromAlbum($albumID, $photoID); } else { BuckysAlbum::addPhotoToAlbum($albumID, $photoID); } //Add echo 'success'; exit; } } } buckys_enqueue_stylesheet('account.css'); buckys_enqueue_stylesheet('posting.css'); buckys_enqueue_javascript('album.js'); $BUCKYS_GLOBALS['content'] = 'photo_album_edit'; $BUCKYS_GLOBALS['title'] = "Edit Photo Album - BuckysRoom"; require DIR_FS_TEMPLATE . $BUCKYS_GLOBALS['template'] . "/" . $BUCKYS_GLOBALS['layout'] . ".php";
/** * Remove Album * * @param mixed $albumID * @param mixed $userID * @return bool */ public static function deleteAlbum($albumID, $userID) { global $db; if (BuckysAlbum::checkAlbumOwner($albumID, $userID)) { //Remove Album $query = $db->prepare("DELETE FROM " . TABLE_ALBUMS . " WHERE albumID=%s AND OWNER=%s", $albumID, $userID); $db->query($query); //Remove Assigned Photos $query = $db->prepare("DELETE FROM " . TABLE_ALBUMS_PHOTOS . " WHERE albumID=%s", $albumID); $db->query($query); return true; } return false; }
/** * Save Post * * @param $userID * @param mixed $data * @return bool|int|null|string */ public static function savePhoto($userID, $data) { global $db, $TNB_GLOBALS; //Check the Photo File Name if (!isset($data['file']) || strpos($data['file'], "../") !== false || !file_exists(DIR_FS_PHOTO_TMP . $data['file'])) { buckys_add_message(MSG_FILE_UPLOAD_ERROR, MSG_TYPE_ERROR); return false; } $data['pageID'] = isset($data['pageID']) && is_numeric($data['pageID']) ? $data['pageID'] : BuckysPost::INDEPENDENT_POST_PAGE_ID; // Validate the file type $fileParts = pathinfo($data['file']); if (!in_array(strtolower($fileParts['extension']), $TNB_GLOBALS['imageTypes'])) { buckys_add_message(MSG_INVALID_PHOTO_TYPE, MSG_TYPE_ERROR); return false; } //Validate File Size list($width, $height, $type, $attr) = getimagesize(DIR_FS_PHOTO_TMP . $data['file']); if ($width * $height > MAX_IMAGE_WIDTH * MAX_IMAGE_HEIGHT) { buckys_add_message(MSG_PHOTO_MAX_SIZE_ERROR, MSG_TYPE_ERROR); return false; } //Checking File Size and move it from the tmp folder to the user photo folder and resize it. if ($data['post_visibility'] == 2) { //Calc Ratio using real image width $ratio = floatval($width / $data['width']); $sourceWidth = ($data['x2'] - $data['x1']) * $ratio; BuckysPost::moveFileFromTmpToUserFolder($userID, $data['file'], PROFILE_IMAGE_WIDTH, PROFILE_IMAGE_HEIGHT, $data['x1'] * $ratio, $data['y1'] * $ratio, $sourceWidth, $sourceWidth); if ($data['pageID'] == BuckysPost::INDEPENDENT_POST_PAGE_ID) { //Update User Profile Field BuckysUser::updateUserFields($userID, ['thumbnail' => $data['file']]); $is_profile = 1; } else { //Update Page Profile field $pageIns = new BuckysPage(); $pageIns->updateData($data['pageID'], ['logo' => $data['file']]); $is_profile = 1; } } else { if ($width > MAX_POST_IMAGE_WIDTH) { $height = $height * (MAX_POST_IMAGE_WIDTH / $width); $width = MAX_POST_IMAGE_WIDTH; } if ($height > MAX_POST_IMAGE_HEIGHT) { $width = $width * (MAX_POST_IMAGE_HEIGHT / $height); $height = MAX_POST_IMAGE_HEIGHT; } //Create normal image BuckysPost::moveFileFromTmpToUserFolder($userID, $data['file'], $width, $height, 0, 0); $is_profile = 0; } $now = date('Y-m-d H:i:s'); $newId = $db->insertFromArray(TABLE_POSTS, ['poster' => $userID, 'pageID' => $data['pageID'], 'profileID' => $data['profileID'], 'content' => $data['content'], 'type' => 'image', 'post_date' => $now, 'image' => $data['file'], 'visibility' => $data['post_visibility'] > 0 ? 1 : 0, 'is_profile' => $is_profile]); if (!$newId) { buckys_add_message($db->getLastError(), MSG_TYPE_ERROR); return false; } //Assign Photo to Album if (isset($data['album']) && $data['album'] != '') { if (!BuckysAlbum::checkAlbumOwner($data['album'], $userID)) { buckys_add_message(MSG_INVALID_ALBUM_ID, MSG_TYPE_ERROR); } else { BuckysAlbum::addPhotoToAlbum($data['album'], $newId); } } buckys_add_message(MSG_PHOTO_UPLOADED_SUCCESSFULLY); return $newId; }
} //If the parameter is null, goto homepage if (!$profileID) { buckys_redirect('/index.php'); } //Getting UserData from Id $userData = BuckysUser::getUserData($profileID); //Goto Homepage if the userID is not correct if (!buckys_not_null($userData) || !BuckysUser::checkUserID($profileID, true)) { buckys_redirect('/index.php'); } if (!$showPagePhotoFlag) { //if logged user can see all resources of the current user $canViewPrivate = $userID == $profileID || BuckysFriend::isFriend($userID, $profileID) || BuckysFriend::isSentFriendRequest($profileID, $userID); $photos = BuckysPost::getPhotosByUserID($profileID, $userID, $paramPageID, $canViewPrivate, $postID, $albumID, BuckysPost::$images_per_page); $albums = BuckysAlbum::getAlbumsByUserId($profileID); //Display $TNB_GLOBALS['title'] = trim($userData['firstName'] . ' ' . $userData['lastName']) . "'s Photos - " . TNB_SITE_NAME; $view['photo_type'] = 'profile'; buckys_enqueue_stylesheet('profile.css'); buckys_enqueue_stylesheet('posting.css'); buckys_enqueue_stylesheet('publisher.css'); buckys_enqueue_javascript('posts.js'); } else { //Show page photos if logged user can see all resources of the current user $photos = BuckysPost::getPhotosByUserID($profileID, null, $paramPageID, false, $postID, $albumID, BuckysPost::$images_per_page); //Display $TNB_GLOBALS['title'] = trim($pageData['title']) . "'s Photos - " . TNB_SITE_NAME; $view['photo_type'] = 'page'; $view['pageData'] = $pageData; buckys_enqueue_stylesheet('account.css');
} //Getting UserData from Id $userData = BuckysUser::getUserData($profileID); //Getting Albums $albums = BuckysAlbum::getAlbumsByUserId($userID); if (isset($_POST['action'])) { //Create New Album if ($_POST['action'] == 'create-album') { //If the album title is empty, throw error if (trim($_POST['new_album_name']) == '') { buckys_redirect('/photo_albums.php', MSG_ALBUM_TITLE_EMPTY, MSG_TYPE_ERROR); } $newId = BuckysAlbum::createAlbum($userID, trim($_POST['new_album_name']), $_POST['visibility']); buckys_redirect('/photo_albums.php'); } else { if ($_POST['action'] == 'delete-album') { if (BuckysAlbum::deleteAlbum($_POST['albumID'], $userID)) { echo 'success'; } else { echo 'error'; } exit; } } } buckys_enqueue_stylesheet('account.css'); buckys_enqueue_stylesheet('posting.css'); buckys_enqueue_javascript('album.js'); $BUCKYS_GLOBALS['content'] = 'photo_albums'; $BUCKYS_GLOBALS['title'] = "Photo Albums - BuckysRoom"; require DIR_FS_TEMPLATE . $BUCKYS_GLOBALS['template'] . "/" . $BUCKYS_GLOBALS['layout'] . ".php";
buckys_redirect('/photo_manage.php'); } else { if ($action == 'delete-photo') { if (!BuckysPost::deletePost($userID, $_REQUEST['photoID'])) { buckys_redirect('/photo_manage.php', MSG_INVALID_REQUEST, MSG_TYPE_ERROR); } else { buckys_redirect('/photo_manage.php', MSG_PHOTO_REMOVED, MSG_TYPE_SUCCESS); } } else { if ($action == 'remove-profile-photo') { BuckysUser::updateUserFields($userID, ['thumbnail' => '']); buckys_redirect('/photo_manage.php'); } } } } //Getting Album ID $albumID = isset($_REQUEST['albumID']) ? $_REQUEST['albumID'] : null; //Getting Current Page $page = isset($_GET['page']) ? $_GET['page'] : 1; $totalCount = BuckysPost::getNumberOfPhotosByUserID($userID, BuckysPost::INDEPENDENT_POST_PAGE_ID, $albumID); $pagination = new Pagination($totalCount, BuckysPost::$IMAGES_PER_PAGE_FOR_MANAGE_PHOTOS_PAGE, $page); $page = $pagination->getCurrentPage(); $photos = BuckysPost::getPhotosByUserID($userID, $userID, BuckysPost::INDEPENDENT_POST_PAGE_ID, true, null, $albumID, BuckysPost::$IMAGES_PER_PAGE_FOR_MANAGE_PHOTOS_PAGE); $albums = BuckysAlbum::getAlbumsByUserId($userID); buckys_enqueue_stylesheet('account.css'); buckys_enqueue_stylesheet('posting.css'); buckys_enqueue_stylesheet('info.css'); $TNB_GLOBALS['content'] = 'photo_manage'; $TNB_GLOBALS['title'] = "Manage Photos - " . TNB_SITE_NAME; require DIR_FS_TEMPLATE . $TNB_GLOBALS['template'] . "/" . $TNB_GLOBALS['layout'] . ".php";