/** * Add photo to album * * @params = $album Album guid * $photo Photo type * $access Private or Public ( its actually depend on album privacy) * * @return bool; */ public function AddPhoto($album, $photo = 'ossnphoto', $access = OSSN_PUBLIC) { //check access if (!in_array($access, ossn_access_types())) { $access = OSSN_PUBLIC; } //album initialize $this->album = new OssnAlbums(); $this->album = $this->album->GetAlbum($album); //check if album guid is not less than 0 and validate photo uploader if (!empty($album) && $album > 0 && $this->album->album->owner_guid == ossn_loggedin_user()->guid) { //initialize variables $this->owner_guid = $album; $this->type = 'object'; $this->subtype = 'ossn:aphoto'; $this->setFile($photo); $this->permission = $access; $this->setPath('album/photos/'); $this->setExtension(array('jpg', 'png', 'jpeg', 'gif')); //add file if ($this->addFile()) { $sizes = ossn_photos_sizes(); $resize = $this->getFiles(); if (isset($resize->{0}->value)) { $datadir = ossn_get_userdata("object/{$album}/{$resize->{0}->value}"); $file_name = str_replace('album/photos/', '', $resize->{0}->value); //crop photos and create new photos from source $sizes = ossn_photos_sizes(); foreach ($sizes as $size => $params) { $params = explode('x', $params); $width = $params[1]; $height = $params[0]; if ($size !== 'view') { $resized = ossn_resize_image($datadir, $width, $height, true); } else { $resized = ossn_resize_image($datadir, $width, $height, false); } //create newly created image $image = ossn_get_userdata("object/{$album}/album/photos/{$size}_{$file_name}"); file_put_contents($image, $resized); } //return true if photos is added to database return true; } } return false; } }
/** * addFile * Add file to database * * @param integer $object->owner_guid Guid of owner , the file belongs to * @param string $object->type Owner type, * @param string $object->subtype file type * * @return boolean */ public function addFile() { if (isset($this->file) && !empty($this->file) && !empty($this->owner_guid) && !empty($this->subtype) && !empty($this->type)) { $this->extensions = $this->allowedFileExtensions(); $this->extension = $this->getFileExtension($this->file['name']); //change user file extension to lower case #153 $this->extension = strtolower($this->extension); if ($this->typeAllowed()) { $this->newfilename = md5($this->file['name'] . rand() . time()) . '.' . $this->extension; $this->newfile = $this->path . $this->newfilename; $this->dir = ossn_get_userdata("{$this->type}/{$this->owner_guid}/{$this->path}"); if (!is_dir(ossn_get_userdata($this->dir))) { mkdir($this->dir, 0755, true); } $this->subtype = "file:{$this->subtype}"; $this->value = $this->newfile; if ($this->add()) { $filecontents = file_get_contents($this->file['tmp_name']); if (preg_match('/image/i', $this->file['type'])) { //allow devs to change default size , see #528 $image_res = array('width' => 2048, 'height' => 2048); $image_res = ossn_call_hook('file', 'image:resolution', $this, $image_res); //compress image before save $filecontents = ossn_resize_image($this->file['tmp_name'], $image_res['width'], $image_res['height']); } file_put_contents("{$this->dir}{$this->newfilename}", $filecontents); return true; } } } return false; }
/** * Comment page for viewing comment photos * * @access private; */ function ossn_comment_page($pages) { $page = $pages[0]; switch ($page) { case 'image': if (!empty($pages[1]) && !empty($pages[2])) { $file = ossn_get_userdata("annotation/{$pages[1]}/comment/photo/{$pages[2]}"); header('Content-Type: image/jpeg'); if (is_file($file)) { echo ossn_resize_image($file, 300, 300); } else { ossn_error_page(); } } else { ossn_error_page(); } break; case 'attachment': header('Content-Type: application/json'); if (isset($_FILES['file']['tmp_name']) && ossn_isLoggedin()) { $file = $_FILES['file']['tmp_name']; $unique = time() . '-' . substr(md5(time()), 0, 6) . '.jpg'; $newfile = ossn_get_userdata("tmp/photos/{$unique}"); $dir = ossn_get_userdata("tmp/photos/"); if (!is_dir($dir)) { mkdir($dir, 0755, true); } if (move_uploaded_file($file, $newfile)) { $file = base64_encode(ossn_string_encrypt($newfile)); echo json_encode(array('file' => base64_encode($file), 'type' => 1)); exit; } } echo json_encode(array('type' => 0)); break; case 'staticimage': $image = base64_decode(input('image')); if (!empty($image)) { $file = ossn_string_decrypt(base64_decode($image)); header('content-type: image/jpeg'); $file = rtrim(ossn_validate_filepath($file), '/'); if (is_file($file)) { echo file_get_contents($file); } else { ossn_error_page(); } } else { ossn_error_page(); } break; } }
* @package (Informatikon.com).ossn * @author OSSN Core Team <*****@*****.**> * @copyright 2014 iNFORMATIKON TECHNOLOGIES * @license General Public Licence http://opensource-socialnetwork.com/licence * @link http://www.opensource-socialnetwork.com/licence */ $file = new OssnFile(); $file->owner_guid = ossn_loggedin_user()->guid; $file->type = 'user'; $file->subtype = 'profile:photo'; $file->setFile('userphoto'); $file->setPath('profile/photo/'); if ($file->addFile()) { $resize = $file->getFiles(); if (isset($resize->{0}->value)) { $guid = ossn_loggedin_user()->guid; $datadir = ossn_get_userdata("user/{$guid}/{$resize->{0}->value}"); $file_name = str_replace('profile/photo/', '', $resize->{0}->value); $sizes = ossn_user_image_sizes(); foreach ($sizes as $size => $params) { $params = explode('x', $params); $width = $params[1]; $height = $params[0]; $resized = ossn_resize_image($datadir, $width, $height, true); file_put_contents(ossn_get_userdata("user/{$guid}/profile/photo/{$size}_{$file_name}"), $resized); } } echo 1; } else { echo 0; }
/** * Ossn Albums page handler * @pages: * getphoto, * view, * profile, * add * * @return false|null contents */ function ossn_album_page_handler($album) { $page = $album[0]; if (empty($page)) { return false; } switch ($page) { case 'getphoto': $guid = $album[1]; $picture = $album[2]; $size = input('size'); $name = str_replace(array('.jpg', '.jpeg', 'gif'), '', $picture); $etag = $size . $name . $guid; if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == "\"{$etag}\"") { header("HTTP/1.1 304 Not Modified"); exit; } // get image size if (empty($size)) { $datadir = ossn_get_userdata("object/{$guid}/album/photos/{$picture}"); } else { $datadir = ossn_get_userdata("object/{$guid}/album/photos/{$size}_{$picture}"); } //get image type $type = input('type'); if ($type == '1') { if (empty($size)) { $datadir = ossn_get_userdata("user/{$guid}/profile/photo/{$picture}"); } else { $datadir = ossn_get_userdata("user/{$guid}/profile/photo/{$size}_{$picture}"); } } if (is_file($datadir)) { $filesize = filesize($datadir); header("Content-type: image/jpeg"); header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', strtotime("+6 months")), true); header("Pragma: public"); header("Cache-Control: public"); header("Content-Length: {$filesize}"); header("ETag: \"{$etag}\""); readfile($datadir); return; } else { ossn_error_page(); } break; case 'getcover': $guid = $album[1]; $picture = $album[2]; $type = input('type'); $name = str_replace(array('.jpg', '.jpeg', 'gif'), '', $picture); $etag = $size . $name . $guid; if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == "\"{$etag}\"") { header("HTTP/1.1 304 Not Modified"); exit; } // get image size $datadir = ossn_get_userdata("user/{$guid}/profile/cover/{$picture}"); if (empty($type)) { $image = file_get_contents($datadir); } elseif ($type == 1) { $image = ossn_resize_image($datadir, 170, 170, true); } //get image file else show error page if (is_file($datadir)) { $filesize = filesize($datadir); header("Content-type: image/jpeg"); header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', strtotime("+6 months")), true); header("Pragma: public"); header("Cache-Control: public"); header("Content-Length: {$filesize}"); header("ETag: \"{$etag}\""); readfile($datadir); return; } else { ossn_error_page(); } break; case 'view': if (isset($album[1])) { $title = ossn_print('photos'); $user['album'] = $album[1]; $albumget = ossn_albums(); $owner = $albumget->GetAlbum($album[1])->album; if (empty($owner)) { ossn_error_page(); } //throw 404 page if there is no album access if ($owner->access == 3) { if (!ossn_validate_access_friends($owner->owner_guid)) { ossn_error_page(); } } //shows add photos if owner is loggedin user if (ossn_loggedin_user()->guid == $owner->owner_guid) { $addphotos = array('text' => ossn_print('add:photos'), 'href' => 'javascript::void(0);', 'id' => 'ossn-add-photos', 'data-url' => '?album=' . $album[1], 'class' => 'button-grey'); $delete_action = ossn_site_url("action/ossn/album/delete?guid={$album[1]}", true); $delete_album = array('text' => ossn_print('delete:album'), 'href' => $delete_action, 'class' => 'button-grey'); $control = ossn_plugin_view('output/url', $addphotos); $control .= ossn_plugin_view('output/url', $delete_album); } else { $control = false; } //set photos in module $contents = array('title' => ossn_print('photos'), 'content' => ossn_plugin_view('photos/pages/albums', $user), 'controls' => $control, 'module_width' => '850px'); //set page layout $module['content'] = ossn_set_page_layout('module', $contents); $content = ossn_set_page_layout('contents', $module); echo ossn_view_page($title, $content); } break; case 'profile': if (isset($album[1])) { $title = ossn_print('profile:photos'); $user['user'] = ossn_user_by_guid($album[1]); if (empty($user['user']->guid)) { ossn_error_page(); } //view profile photos in module layout $contents = array('title' => ossn_print('photos'), 'content' => ossn_plugin_view('photos/pages/profile/photos/all', $user), 'controls' => false, 'module_width' => '850px'); $module['content'] = ossn_set_page_layout('module', $contents); //set page layout $content = ossn_set_page_layout('contents', $module); echo ossn_view_page($title, $content); } break; case 'covers': if (isset($album[2]) && $album[1] == 'profile') { $title = ossn_print('profile:covers'); $user['user'] = ossn_user_by_guid($album[2]); if (empty($user['user']->guid)) { ossn_error_page(); } //view profile photos in module layout $contents = array('title' => ossn_print('covers'), 'content' => ossn_plugin_view('photos/pages/profile/covers/all', $user), 'controls' => false, 'module_width' => '850px'); $module['content'] = ossn_set_page_layout('module', $contents); //set page layout $content = ossn_set_page_layout('contents', $module); echo ossn_view_page($title, $content); } break; case 'add': //add photos (ajax) echo ossn_plugin_view('output/ossnbox', array('title' => ossn_print('add:album'), 'contents' => ossn_plugin_view('photos/pages/album/add'), 'success_id' => 'aga', 'callback' => '#ossn-album-submit')); break; default: ossn_error_page(); break; } }
/** * Get user default cover photo * * @return string|null data; */ function get_cover_photo($user, $params = array()) { if (!$user instanceof OssnUser) { return false; } $photo = $user->getProfileCover(); $etag = $photo->guid . $photo->time_created; if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == "\"{$etag}\"") { header("HTTP/1.1 304 Not Modified"); exit; } if (isset($photo->value)) { header("Content-type: image/jpeg"); header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', strtotime("+6 months")), true); header("Pragma: public"); header("Cache-Control: public"); header("ETag: \"{$etag}\""); if (!empty($params[1]) && $params[1] == 1) { $datadir = ossn_get_userdata("user/{$user->guid}/{$photo->value}"); echo ossn_resize_image($datadir, 170, 170, true); } else { $datadir = ossn_get_userdata("user/{$user->guid}/{$photo->value}"); $filesize = filesize($datadir); header("Content-Length: {$filesize}"); readfile($datadir); } return; } else { redirect('components/OssnProfile/images/transparent.png'); } }
/** * Edit * * @param (array) $params Contain title , description and guid of ad * * @return bool; */ public function EditAd($params) { self::initAttributes(); if (!empty($params['guid']) && !empty($params['title']) && !empty($params['description']) && !empty($params['siteurl'])) { $entity = get_ad_entity($params['guid']); $fields = array('title', 'description'); $data = array($params['title'], $params['description']); $this->data->site_url = $params['siteurl']; if ($this->updateObject($fields, $data, $entity->guid)) { if (isset($_FILES['ossn_ads']) && $_FILES['ossn_ads']['size'] !== 0) { $path = $entity->getParam('file:ossnads'); $replace_file = ossn_get_userdata("object/{$entity->guid}/{$path}"); if (!empty($path)) { $regen_image = ossn_resize_image($_FILES['ossn_ads']['tmp_name'], 2048, 2048); file_put_contents($replace_file, $regen_image); } } return true; } } return false; }
/** * Get user default cover photo * * @return string|null data; */ function get_cover_photo($guid, $params = array()) { $photo = new OssnFile(); $photo->owner_guid = $guid; $photo->type = 'user'; $photo->subtype = 'profile:cover'; $photos = $photo->getFiles(); if (isset($photos->{0}->value)) { if (!empty($params[1]) && $params[1] == 1) { $datadir = ossn_get_userdata("user/{$guid}/{$photos->{0}->value}"); echo ossn_resize_image($datadir, 170, 170, true); } else { $datadir = ossn_get_userdata("user/{$guid}/{$photos->{0}->value}"); return file_get_contents($datadir); } } else { redirect('components/OssnProfile/images/transparent.png'); } }
/** * addFile * Add file to database * * @param (object)->owner_guid guid of owner , the file belongs to * @param (object)->type owner type, * @param (object)->subtype file type * * @return (bool) */ public function addFile() { if (isset($this->file) && !empty($this->file) && !empty($this->owner_guid) && !empty($this->subtype) && !empty($this->type)) { if (preg_match('/image/i', $this->file['type'])) { $this->mime = $this->MimeTypeImages(); $this->newfilename = md5($this->file['name'] . rand() . time()) . '.' . $this->mime[$this->file['type']]; $this->newfile = $this->path . $this->newfilename; $this->dir = ossn_get_userdata("{$this->type}/{$this->owner_guid}/{$this->path}"); if (!is_dir(ossn_get_userdata($this->dir))) { mkdir($this->dir, 0755, true); } $this->subtype = "file:{$this->subtype}"; $this->value = $this->newfile; if ($this->add()) { $image = ossn_resize_image($this->file['tmp_name'], 2048, 2048); file_put_contents("{$this->dir}{$this->newfilename}", $image); return true; } } //normal types goes here //version 1.x //dev $arsalanshah } }
/** * Ossn Albums page handler * @pages: * getphoto, * view, * profile, * add * * @return false|null contents */ function ossn_album_page_handler($album) { $page = $album[0]; if (empty($page)) { return false; } switch ($page) { case 'getphoto': $guid = $album[1]; $picture = $album[2]; $size = input('size'); // get image size if (empty($size)) { $datadir = ossn_get_userdata("object/{$guid}/album/photos/{$picture}"); } else { $datadir = ossn_get_userdata("object/{$guid}/album/photos/{$size}_{$picture}"); } //get image type $type = input('type'); if ($type == '1') { if (empty($size)) { $datadir = ossn_get_userdata("user/{$guid}/profile/photo/{$picture}"); } else { $datadir = ossn_get_userdata("user/{$guid}/profile/photo/{$size}_{$picture}"); } } $image = file_get_contents($datadir); //get image file else show error page if (is_file($datadir)) { header('Content-Type: image/jpeg'); echo $image; } else { ossn_error_page(); } break; case 'getcover': $guid = $album[1]; $picture = $album[2]; $type = input('type'); // get image size $datadir = ossn_get_userdata("user/{$guid}/profile/cover/{$picture}"); if (empty($type)) { $image = file_get_contents($datadir); } elseif ($type == 1) { $image = ossn_resize_image($datadir, 170, 170, true); } //get image file else show error page if (is_file($datadir)) { header('Content-Type: image/jpeg'); echo $image; } else { ossn_error_page(); } break; case 'view': if (isset($album[1])) { $title = ossn_print('photos'); $user['album'] = $album[1]; $albumget = ossn_albums(); $owner = $albumget->GetAlbum($album[1])->album; if (empty($owner)) { ossn_error_page(); } //throw 404 page if there is no album access if ($owner->access == 3) { if (!ossn_validate_access_friends($owner->owner_guid)) { ossn_error_page(); } } //shows add photos if owner is loggedin user if (ossn_loggedin_user()->guid == $owner->owner_guid) { $addphotos = array('text' => ossn_print('add:photos'), 'href' => 'javascript::;', 'id' => 'ossn-add-photos', 'data-url' => '?album=' . $album[1], 'class' => 'button-grey'); $control = ossn_view('system/templates/output/url', $addphotos); } else { $control = false; } //set photos in module $contents = array('title' => ossn_print('photos'), 'content' => ossn_view('components/OssnPhotos/pages/albums', $user), 'controls' => $control, 'module_width' => '850px'); //set page layout $module['content'] = ossn_set_page_layout('module', $contents); $content = ossn_set_page_layout('contents', $module); echo ossn_view_page($title, $content); } break; case 'profile': if (isset($album[1])) { $title = ossn_print('profile:photos'); $user['user'] = ossn_user_by_guid($album[1]); if (empty($user['user']->guid)) { ossn_error_page(); } //view profile photos in module layout $contents = array('title' => ossn_print('photos'), 'content' => ossn_view('components/OssnPhotos/pages/profile/photos/all', $user), 'controls' => false, 'module_width' => '850px'); $module['content'] = ossn_set_page_layout('module', $contents); //set page layout $content = ossn_set_page_layout('contents', $module); echo ossn_view_page($title, $content); } break; case 'covers': if (isset($album[2]) && $album[1] == 'profile') { $title = ossn_print('profile:covers'); $user['user'] = ossn_user_by_guid($album[2]); if (empty($user['user']->guid)) { ossn_error_page(); } //view profile photos in module layout $contents = array('title' => ossn_print('covers'), 'content' => ossn_view('components/OssnPhotos/pages/profile/covers/all', $user), 'controls' => false, 'module_width' => '850px'); $module['content'] = ossn_set_page_layout('module', $contents); //set page layout $content = ossn_set_page_layout('contents', $module); echo ossn_view_page($title, $content); } break; case 'add': //add photos (ajax) echo ossn_view('system/templates/output/ossnbox', array('title' => ossn_print('add:album'), 'contents' => ossn_view('components/OssnPhotos/pages/album/add'), 'success_id' => 'aga', 'callback' => '#ossn-album-submit')); break; default: ossn_error_page(); break; } }
/** * addFile * Add file to database * * @param (object)->owner_guid guid of owner , the file belongs to * @param (object)->type owner type, * @param (object)->subtype file type * * @return (bool) */ public function addFile() { if (isset($this->file) && !empty($this->file) && !empty($this->owner_guid) && !empty($this->subtype) && !empty($this->type)) { $this->extensions = $this->allowedFileExtensions(); $this->extension = $this->getFileExtension($this->file['name']); //change user file extension to lower case #153 $this->extension = strtolower($this->extension); if (in_array($this->extension, $this->extensions)) { $this->newfilename = md5($this->file['name'] . rand() . time()) . '.' . $this->extension; $this->newfile = $this->path . $this->newfilename; $this->dir = ossn_get_userdata("{$this->type}/{$this->owner_guid}/{$this->path}"); if (!is_dir(ossn_get_userdata($this->dir))) { mkdir($this->dir, 0755, true); } $this->subtype = "file:{$this->subtype}"; $this->value = $this->newfile; if ($this->add()) { $filecontents = file_get_contents($this->file['tmp_name']); if (preg_match('/image/i', $this->file['type'])) { //compress image before save $filecontents = ossn_resize_image($this->file['tmp_name'], 2048, 2048); } file_put_contents("{$this->dir}{$this->newfilename}", $filecontents); return true; } } } return false; }