Пример #1
0
 /**
  * View user icon url
  *
  * @return string
  */
 public function iconURL()
 {
     $this->iconURLS = new stdClass();
     foreach (ossn_user_image_sizes() as $size => $dimensions) {
         $seo = md5($this->username . $size . $this->icon_time);
         $url = ossn_site_url("avatar/{$this->username}/{$size}/{$seo}.jpeg");
         $this->iconURLS->{$size} = $url;
     }
     return ossn_call_hook('user', 'icon:urls', $this, $this->iconURLS);
 }
Пример #2
0
 * @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;
}
/**
 * Get user profile photo
 *
 * @return mixed data;
 */
function get_profile_photo($guid, $size)
{
    $photo = new OssnFile();
    $photo->owner_guid = $guid;
    if (isset($size) && array_key_exists($size, ossn_user_image_sizes())) {
        $isize = "{$size}_";
    }
    $photo->type = 'user';
    $photo->subtype = 'profile:photo';
    $photos = $photo->getFiles();
    if (isset($photos->{0}->value) && !empty($photos->{0}->value)) {
        $datadir = ossn_get_userdata("user/{$guid}/{$photos->{0}->value}");
        if (!empty($size)) {
            $image = str_replace('profile/photo/', '', $photos->{0}->value);
            $datadir = ossn_get_userdata("user/{$guid}/profile/photo/{$isize}{$image}");
        }
        return file_get_contents($datadir);
    } else {
        $datadir = ossn_default_theme() . "images/nopictures/users/{$size}.jpg";
        return file_get_contents($datadir);
    }
    return false;
}
Пример #4
0
/**
 * Get user profile photo
 *
 * @return mixed data;
 */
function get_profile_photo($user, $size)
{
    if (!$user instanceof OssnUser) {
        return false;
    }
    if (isset($size) && array_key_exists($size, ossn_user_image_sizes())) {
        $isize = "{$size}_";
    }
    $photo = $user->getProfilePhoto();
    $etag = $photo->guid . $photo->time_created;
    if (isset($photo->time_created)) {
        header("Last-Modified: " . gmdate('D, d M Y H:i:s \\G\\M\\T', $photo->time_created));
    }
    header("Etag: {$etag}");
    if (isset($photo->guid) && 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) && !empty($photo->value)) {
        $datadir = ossn_get_userdata("user/{$user->guid}/{$photo->value}");
        if (!empty($size)) {
            $image = str_replace('profile/photo/', '', $photo->value);
            $datadir = ossn_get_userdata("user/{$user->guid}/profile/photo/{$isize}{$image}");
        }
    } else {
        $datadir = ossn_default_theme() . "images/nopictures/users/{$size}.jpg";
    }
    $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;
}
Пример #5
0
 /**
  * Delete profile photo
  *
  * @return bool;
  */
 public function deleteProfilePhoto()
 {
     if (isset($this->photoid)) {
         $this->file_id = $this->photoid;
         $this->entity = new OssnEntities();
         $file = $this->fetchFile();
         $source = ossn_get_userdata("user/{$file->owner_guid}/{$file->value}");
         //delete cropped photos
         unlink($source);
         foreach (ossn_user_image_sizes() as $size => $dimensions) {
             $filename = str_replace('profile/photo/', '', $file->value);
             $filename = ossn_get_userdata("user/{$file->owner_guid}/profile/photo/{$size}_{$filename}");
             if (is_file($filename)) {
                 unlink($filename);
             }
         }
         //delete photo from database
         if ($this->deleteEntity($file->guid)) {
             $params['photo'] = get_object_vars($file);
             ossn_trigger_callback('delete', 'profile:photo', $params);
             return true;
         }
     }
     return false;
 }