/** * Upload component * * @requires component package file, * * @return bool; */ public function upload() { $archive = new ZipArchive(); $data_dir = ossn_get_userdata('tmp/components'); if (!is_dir($data_dir)) { mkdir($data_dir, 0755, true); } $zip = $_FILES['com_file']; $newfile = "{$data_dir}/{$zip['name']}"; if (move_uploaded_file($zip['tmp_name'], $newfile)) { if ($archive->open($newfile) === TRUE) { $archive->extractTo($data_dir); //make community components works on installer #394 $validate = $archive->statIndex(0); $validate = str_replace('/', '', $validate['name']); $archive->close(); if (is_dir("{$data_dir}/{$validate}") && is_file("{$data_dir}/{$validate}/ossn_com.php") && is_file("{$data_dir}/{$validate}/ossn_com.xml")) { $archive->open($newfile); $archive->extractTo(ossn_route()->com); $archive->close(); $this->newCom($validate); OssnFile::DeleteDir($data_dir); return true; } } } return false; }
/** * Upload component * * @requires component package file, * * @return bool; */ public function upload() { $archive = new ZipArchive(); $data_dir = ossn_get_userdata('tmp/components'); if (!is_dir($data_dir)) { mkdir($data_dir, 0755, true); } $zip = $_FILES['com_file']; $newfile = "{$data_dir}/{$zip['name']}"; if (move_uploaded_file($zip['tmp_name'], $newfile)) { if ($archive->open($newfile) === TRUE) { $archive->extractTo($data_dir); $archive->close(); $validate = pathinfo($zip['name'], PATHINFO_FILENAME); if (is_file("{$data_dir}/{$validate}/ossn_com.php") && is_file("{$data_dir}/{$validate}/ossn_com.xml")) { $archive->open($newfile); $archive->extractTo(ossn_route()->com); $archive->close(); $this->newCom($validate); OssnFile::DeleteDir($data_dir); return true; } } } return false; }
/** * Upload component * * Requires component package file, * * @return boolean */ public function upload() { $archive = new ZipArchive(); $data_dir = ossn_get_userdata('tmp/themes'); if (!is_dir($data_dir)) { mkdir($data_dir, 0755, true); } $file = new OssnFile(); $file->setFile('theme_file'); $file->setExtension(array('zip')); $zip = $file->file; $newfile = "{$data_dir}/{$zip['name']}"; if (move_uploaded_file($zip['tmp_name'], $newfile)) { if ($archive->open($newfile) === TRUE) { $archive->extractTo($data_dir); $archive->close(); $validate = pathinfo($zip['name'], PATHINFO_FILENAME); if (is_file("{$data_dir}/{$validate}/ossn_theme.php") && is_file("{$data_dir}/{$validate}/ossn_theme.xml")) { $archive->open($newfile); $archive->extractTo(ossn_route()->themes); $archive->close(); OssnFile::DeleteDir($data_dir); return true; } } } return false; }
/** * Get ad image * * @return image; * @access public */ function ossn_ad_image($guid) { $photo = new OssnFile(); $photo->owner_guid = $guid; $photo->type = 'object'; $photo->subtype = 'ossnads'; $photos = $photo->getFiles(); if (isset($photos->{0}->value) && !empty($photos->{0}->value)) { $datadir = ossn_get_userdata("object/{$guid}/{$photos->{0}->value}"); return file_get_contents($datadir); } }
/** * Upload component * * Requires component package file, * * @return boolean */ public function upload() { $archive = new ZipArchive(); $data_dir = ossn_get_userdata('tmp/components'); if (!is_dir($data_dir)) { mkdir($data_dir, 0755, true); } $zip = $_FILES['com_file']; $newfile = "{$data_dir}/{$zip['name']}"; if (move_uploaded_file($zip['tmp_name'], $newfile)) { if ($archive->open($newfile) === TRUE) { $translit = OssnTranslit::urlize($zip['name']); //make community components works on installer #394 //Component installer problems with certain zip - archives #420 $archive->extractTo($data_dir . '/' . $translit); $dirctory = scandir($data_dir . '/' . $translit, 1); $dirctory = $dirctory[0]; $files = $data_dir . '/' . $translit . '/' . $dirctory . '/'; $archive->close(); if (is_dir($files) && is_file("{$files}ossn_com.php") && is_file("{$files}ossn_com.xml")) { $ossn_com_xml = simplexml_load_file("{$files}ossn_com.xml"); //need to check id , since ossn v3.x if (isset($ossn_com_xml->id) && !empty($ossn_com_xml->id)) { //move to components directory if (OssnFile::moveFiles($files, ossn_route()->com . $ossn_com_xml->id . '/')) { //add new component to system $this->newCom($ossn_com_xml->id); //why it shows success even if the component is not updated #510 OssnFile::DeleteDir($data_dir); return true; } } } } } return false; }
/** * 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 } }
/** * Delete Annotation * * @params $annotation = annotation_id * * @return bool; */ public function deleteAnnotation($annotation) { self::initAttributes(); if ($this->deleteByOwnerGuid($annotation, 'annotation')) { $this->statement("DELETE FROM yorumlar WHERE(id='{$annotation}')"); if ($this->execute()) { $data = ossn_get_userdata("annotation/{$annotation}/"); if (is_dir($data)) { OssnFile::DeleteDir($data); rmdir($data); } $params['annotation'] = $annotation; ossn_trigger_callback('annotation', 'delete', $params); 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; } }
/** * Groups page handler * * Pages: * groups/ * groups/add ( ajax ) * @return mixdata; * @access private */ function ossn_groups_page($pages) { $page = $pages[0]; if (empty($page)) { return false; } switch ($page) { case 'add': $params = array('action' => ossn_site_url() . 'action/group/add', 'component' => 'OssnGroups', 'class' => 'ossn-form'); $form = ossn_view_form('add', $params, false); echo ossn_plugin_view('output/ossnbox', array('title' => ossn_print('add:group'), 'contents' => $form, 'callback' => '#ossn-group-submit')); break; case 'cover': if (isset($pages[1]) && !empty($pages[1])) { $File = new OssnFile(); $File->file_id = $pages[1]; $File = $File->fetchFile(); $etag = $File->guid . $File->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($File->guid)) { $Cover = ossn_get_userdata("object/{$File->owner_guid}/{$File->value}"); $filesize = filesize($Cover); 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($Cover); return; } else { ossn_error_page(); } } break; default: echo ossn_error_page(); break; } }
/** * Delete user from syste, * * @return boolean */ public function deleteUser() { self::initAttributes(); if (!empty($this->guid) && !empty($this->username)) { $params['from'] = 'ossn_users'; $params['wheres'] = array("guid='{$this->guid}'"); if ($this->delete($params)) { //delete user files $datadir = ossn_get_userdata("user/{$this->guid}/"); if (is_dir($datadir)) { OssnFile::DeleteDir($datadir); //From of v2.0 DeleteDir delete directory also #138 //rmdir($datadir); } //delete user entites also $this->deleteByOwnerGuid($this->guid, 'user'); //delete annotations $this->OssnAnnotation->owner_guid = $this->guid; $this->OssnAnnotation->deleteAnnotationByOwner($this->guid); //trigger callback so other components can be notified when user deleted. //should delete relationships ossn_delete_user_relations($this); $vars['entity'] = $this; ossn_trigger_callback('user', 'delete', $vars); return true; } } return false; }
/** * Delete object; * * @param integer $object Object guid * * @return boolean */ public function deleteObject($object) { self::initAttributes(); if (isset($this->guid)) { $object = $this->guid; } //delete entites of (this) object if ($this->deleteByOwnerGuid($object, 'object')) { $data = ossn_get_userdata("object/{$object}/"); if (is_dir($data)) { OssnFile::DeleteDir($data); } } $delete['from'] = 'ossn_object'; $delete['wheres'] = array("guid='{$object}'"); if ($this->delete($delete)) { return true; } return false; }
/** * Delete profile photo * * @params = $this->photoid Id of photo * * @return bool; */ public function deleteAlbumPhoto() { if (isset($this->photoid)) { $this->file_id = $this->photoid; $this->entity = new OssnEntities(); $file = $this->fetchFile(); $source = ossn_get_userdata("object/{$file->owner_guid}/{$file->value}"); //delete croped photos unlink($source); foreach (ossn_photos_sizes() as $size => $dimensions) { $filename = str_replace('album/photos/', '', $file->value); $filename = ossn_get_userdata("object/{$file->owner_guid}/album/photos/{$size}_{$filename}"); unlink($filename); } //delete photo from database if ($this->deleteEntity($file->guid)) { $params['photo'] = get_object_vars($file); ossn_trigger_callback('delete', 'album:photo', $params); return true; } } return false; }
/** * Delete object; * * @params = $object => object guid * * @return bool; */ public function deleteObject($object) { //delete entites of (this) object if ($this->deleteByOwnerGuid($object, 'object')) { $data = ossn_get_userdata("object/{$object}/"); if (is_dir($data)) { OssnFile::DeleteDir($data); rmdir($data); } } $this->statement("DELETE FROM paylasimlar WHERE(guid='{$object}')"); if ($this->execute()) { 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; }
/** * OssnWall post page handlers * * @param array $pages List of pages * * @return false|mixed data * @access private */ function ossn_post_page($pages) { $page = $pages[0]; if (empty($page)) { return false; } switch ($page) { case 'view': $title = ossn_print('post:view'); $wall = new OssnWall(); $post = $pages[1]; $post = $wall->GetPost($post); if (empty($post->guid) || empty($pages[1])) { ossn_error_page(); } $params['post'] = $post; $contents = array('content' => ossn_plugin_view('wall/pages/view', $params)); $content = ossn_set_page_layout('newsfeed', $contents); echo ossn_view_page($title, $content); break; case 'photo': if (isset($pages[1]) && isset($pages[2])) { $name = str_replace(array('.jpg', '.jpeg', 'gif'), '', $pages[2]); $etag = $pages[1] . $name; if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == "\"{$etag}\"") { header("HTTP/1.1 304 Not Modified"); exit; } $image = ossn_get_userdata("object/{$pages[1]}/ossnwall/images/{$pages[2]}"); //get image file else show error page if (is_file($image)) { //Image cache on wall post #529 $filesize = filesize($image); 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($image); return; } else { ossn_error_page(); } } break; case 'privacy': if (ossn_is_xhr()) { $params = array('title' => ossn_print('privacy'), 'contents' => ossn_plugin_view('wall/privacy'), 'callback' => '#ossn-wall-privacy'); echo ossn_plugin_view('output/ossnbox', $params); } break; case 'refresh_home': echo ossn_plugin_view('wall/siteactivity'); 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'); } }
/** * Groups page handler * * Pages: * groups/ * groups/add ( ajax ) * @return mixdata; * @access private */ function ossn_groups_page($pages) { $page = $pages[0]; if (empty($page)) { return false; } switch ($page) { case 'add': $params = array('action' => ossn_site_url() . 'action/group/add', 'component' => 'OssnGroups', 'class' => 'ossn-form'); $form = ossn_view_form('add', $params, false); echo ossn_view('system/templates/ossnbox', array('title' => ossn_print('add:group'), 'contents' => $form, 'callback' => '#ossn-group-submit')); break; case 'cover': if (isset($pages[1]) && !empty($pages[1])) { $File = new OssnFile(); $File->file_id = $pages[1]; $File = $File->fetchFile(); if (isset($File->guid)) { $Cover = ossn_get_userdata("object/{$File->owner_guid}/{$File->value}"); header('Content-Type: image/jpeg'); echo file_get_contents($Cover); } else { ossn_error_page(); } } break; default: echo ossn_error_page(); break; } }
/** * 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; } }
/** * OssnWall post page handlers * * @param array $pages List of pages * * @return false|mixed data * @access private */ function ossn_post_page($pages) { $page = $pages[0]; if (empty($page)) { return false; } switch ($page) { case 'view': $title = ossn_print('post:view'); $wall = new OssnWall(); $post = $pages[1]; $post = $wall->GetPost($post); if (empty($post->guid) || empty($pages[1])) { ossn_error_page(); } $params['post'] = $post; $contents = array('content' => ossn_plugin_view('wall/pages/view', $params)); $content = ossn_set_page_layout('newsfeed', $contents); echo ossn_view_page($title, $content); break; case 'photo': if (isset($pages[1]) && isset($pages[2])) { $image = ossn_get_userdata("object/{$pages[1]}/ossnwall/images/{$pages[2]}"); header('Content-Type: image/jpeg'); echo file_get_contents($image); } break; case 'privacy': if (ossn_is_xhr()) { $params = array('title' => ossn_print('privacy'), 'contents' => ossn_plugin_view('wall/privacy'), 'callback' => '#ossn-wall-privacy'); echo ossn_plugin_view('output/ossnbox', $params); } break; case 'refresh_home': echo ossn_plugin_view('wall/siteactivity'); break; default: ossn_error_page(); break; } }
function get_cover_photo($guid) { $photo = new OssnFile(); $photo->owner_guid = $guid; $photo->type = 'user'; $photo->subtype = 'profile:cover'; $photos = $photo->getFiles(); if (isset($photos->{0}->value)) { $datadir = ossn_get_userdata("user/{$guid}/{$photos->{0}->value}"); return file_get_contents($datadir); } else { redirect('components/OssnProfile/images/transparent.png'); } }
/** * 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; } }
* @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; }
/** * Generate a paths for plugins for cache * * @return string|false */ function ossn_plugins_cache_paths() { $file = ossn_get_userdata("system/plugins_paths"); if (is_file($file) && ossn_site_settings('cache') == 1) { $file = file_get_contents($file); return json_decode($file, true); } return false; }
/** * 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; }