コード例 #1
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;
    }
}
コード例 #2
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');
            // 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;
    }
}