public function imageAction($type) { $image = new image(); $uid = (new userSessions())->getUserID(); $data = new \stdClass(); $data->profile = new \stdClass(); $data->home = new \stdClass(); $data->photos = new \stdClass(); $data->photoAlbums = new \stdClass(); $albumId = $this->request->getPost('albumId'); $tags = $this->request->getPost('tags'); //require to convert tags into array $tags = explode(',', $tags); switch ($type) { case 'profileWall': //profile wall $result = json_decode(json_encode(profiles::findFirst(array(array('uid' => $uid))))); if (!$result) { return false; } $fileData = $image->uploadProfileWall($result->profileWall); if ($fileData) { (new profiles())->setProfileWall($uid, $fileData); } $data->profile->wall = 'http://' . $fileData->webFileLocation . '?' . time(); $data->profile->uid = $uid; $this->response->setJsonContent($data); $this->response->send(); break; case 'profileAvatar': //profile avatar $result = json_decode(json_encode(profiles::findFirst(array(array('uid' => $uid))))); if (!$result) { return false; } $fileData = $image->uploadProfileAvatar($result->profileAvatar); if ($fileData) { (new profiles())->setProfileAvatar($uid, $fileData); } $data->profile->avatar = 'http://' . $fileData->webFileLocation . '?' . time(); $data->profile->uid = $uid; $this->response->setJsonContent($data); $this->response->send(); break; case 'homeWall': $result = json_decode(json_encode(profiles::findFirst(array(array('uid' => $uid))))); if (!$result) { return false; } $fileData = $image->uploadHomeWall($result->homeWall); if ($fileData) { (new profiles())->setHomeWall($uid, $fileData); } $data->home->wall = 'http://' . $fileData->webFileLocation . '?' . time(); $data->home->uid = $uid; $this->response->setJsonContent($data); $this->response->send(); break; case 'photo': $result = json_decode(json_encode(profiles::findFirst(array(array('uid' => $uid))))); if (!$result) { return false; } //add photo to photos $fileData = $image->uploadPhoto(); if ($fileData) { $photoItem = (new photos())->_create($uid, $albumId, $fileData, null, null, $tags); (new phototaggroups())->_save($uid, $tags); } //(new profiles())->setHomeWall($uid, $fileData); $data->photos->items = array($photoItem); $data->photos->uid = $uid; $this->response->setJsonContent($data); $this->response->send(); break; case 'photoAlbum': $result = json_decode(json_encode(profiles::findFirst(array(array('uid' => $uid))))); if (!$result) { return false; } //add photo to album photos $fileData = $image->uploadPhotoAlbum(); if ($fileData) { $photoAlbumData = (new photoalbums())->_create($uid, $fileData, null, null); } $data->photoAlbums->photo = 'http://' . $fileData->webFileLocation . '?' . time(); $data->photoAlbums->uid = $uid; $this->response->setJsonContent($data); $this->response->send(); break; default: echo 'type not found'; break; } $this->view->setRenderLevel(View::LEVEL_NO_RENDER); }
$profileAvatar = $app->c->set($profileData['profileAvatar']['webFileLocation'], null, 'http://', '?' . time()); } if (isset($profileData['username'])) { $username = $profileData['username']; } if (isset($profileData['fName'])) { $firstName = $profileData['fName']; } if (isset($profileData['lName'])) { $lastName = $profileData['lName']; } if (isset($profileData['key'])) { $key = $profileData['key']; } $friends = (new friends())->_get($uid); $profile = new profiles(); $friends = $profile->_mergeProfilesWithUserIds($friends); $follows = (new feedfollows())->_getFeedFollows($uid); $follows = $profile->_mergeProfilesWithUserIdsCache($follows); $user = array('user' => array('uid' => $uid, 'key' => $key, 'avatar' => $profileAvatar, 'wall' => $profileWall, 'username' => $username, 'name' => $firstName . ' ' . $lastName, 'friends' => $friends, 'follows' => $follows)); $app->response->setJsonContent($user); $app->response->send(); }); /* Feeds */ /* Home and Profile */ $app->get('/ajax/feeds/follows', function () use($app) { $_uid = (new userSessions())->requiredLogin(true); $feedFollows = (new feedfollows())->_getFeedFollows($_uid); $app->response->setContent(json_encode(array('feedFollows' => $feedFollows), JSON_PRETTY_PRINT)); $app->response->send(); });