/**
 * Load action.
 *
 * @param string $action The name of the action
 *
 * @return void
 */
function ossn_action($action)
{
    global $Ossn;
    if (isset($Ossn->action) && array_key_exists($action, $Ossn->action)) {
        if (is_file($Ossn->action[$action])) {
            $params['action'] = $action;
            ossn_trigger_callback('action', 'load', $params);
            include_once $Ossn->action[$action];
            if (ossn_is_xhr()) {
                header('Content-Type: application/json');
                $vars = array();
                if (isset($_SESSION['ossn_messages']['success']) && !empty($_SESSION['ossn_messages']['success'])) {
                    $vars['success'] = $_SESSION['ossn_messages']['success'];
                }
                //danger = error bootstrap
                if (isset($_SESSION['ossn_messages']['danger']) && !empty($_SESSION['ossn_messages']['danger'])) {
                    $vars['error'] = $_SESSION['ossn_messages']['danger'];
                }
                if (isset($Ossn->redirect) && !empty($Ossn->redirect)) {
                    $vars['redirect'] = $Ossn->redirect;
                }
                if (isset($Ossn->ajaxData) && !empty($Ossn->ajaxData)) {
                    $vars['data'] = $Ossn->ajaxData;
                }
                unset($_SESSION['ossn_messages']);
                if (!empty($vars)) {
                    echo json_encode($vars);
                }
            }
        }
    } else {
        ossn_error_page();
    }
}
/**
 * Add css page handler
 *
 * @return false|null
 */
function ossn_css_pagehandler($css)
{
    if (ossn_site_settings('cache') == 1) {
        return false;
    }
    header("Content-type: text/css");
    $page = $css[0];
    if (empty($css[1])) {
        header('Content-Type: text/html; charset=utf-8');
        ossn_error_page();
    }
    if (empty($page)) {
        $page = 'view';
    }
    switch ($page) {
        case 'view':
            if (ossn_site_settings('cache') == 1) {
                return false;
            }
            if (ossn_is_hook('css', "register")) {
                echo ossn_call_hook('css', "register", $css);
            }
            break;
        default:
            header('Content-Type: text/html; charset=utf-8');
            ossn_error_page();
            break;
    }
}
/**
 * Trigger upgrade / Run upgrade
 *
 * @return void;
 * @access private
 */
function ossn_trigger_upgrades()
{
    if (!ossn_isAdminLoggedin()) {
        ossn_kill_upgrading();
        ossn_error_page();
    }
    $upgrades = ossn_get_process_upgrade_files();
    if (!is_array($upgrades) || empty($upgrades)) {
        ossn_trigger_message(ossn_print('upgrade:not:available'), 'error');
        ossn_kill_upgrading();
        redirect('administrator');
    }
    foreach ($upgrades as $upgrade) {
        $file = ossn_route()->upgrade . "upgrades/{$upgrade}";
        if (!(include_once $file)) {
            throw new exception(ossn_print('upgrade:file:load:error'));
        }
    }
    //need to reset cache files
    if (ossn_site_settings('cache') !== 0) {
        ossn_trigger_css_cache();
        ossn_trigger_js_cache();
    }
    return true;
}
Example #4
0
function ossn_search_page($pages)
{
    $page = $pages[0];
    if (empty($page)) {
        $page = 'search';
    }
    ossn_trigger_callback('page', 'load:search');
    switch ($page) {
        case 'search':
            $query = input('q');
            $type = input('type');
            $title = ossn_print("search:result", array($query));
            if (empty($type)) {
                $params['type'] = 'users';
            } else {
                $params['type'] = $type;
            }
            $type = $params['type'];
            if (ossn_is_hook('search', "type:{$type}")) {
                $contents['contents'] = ossn_call_hook('search', "type:{$type}", array('q' => input('q')));
            }
            $contents = array('content' => ossn_plugin_view('search/pages/search', $contents));
            $content = ossn_set_page_layout('search', $contents);
            echo ossn_view_page($title, $content);
            break;
        default:
            ossn_error_page();
            break;
    }
}
Example #5
0
function ossn_js_page_handler($pages)
{
    switch ($pages[0]) {
        case 'boot':
            if (!ossn_isLoggedIn()) {
                ossn_error_page();
            }
            if (isset($pages[1]) && $pages[1] == 'ossn.boot.chat.js') {
                header('Content-Type: application/javascript');
                echo ossn_plugin_view('js/OssnChat.Boot');
            }
            break;
        case 'selectfriend':
            $user = input('user');
            if (!empty($user)) {
                $user = ossn_user_by_guid($user);
                OssnChat::setUserChatSession($user);
                $friend['user'] = $user;
                echo ossn_plugin_view('chat/selectfriend', $friend);
            }
            break;
        default:
            ossn_error_page();
            break;
    }
}
/**
 * Invite page handler
 * 
 * @note Please don't call this function directly in your code.
 *
 * @return mixed
 * @access private
 */
function ossn_invite_pagehandler()
{
    if (!ossn_isLoggedin()) {
        ossn_error_page();
    }
    $title = ossn_print('com:ossn:invite:friends');
    $contents['content'] = ossn_view('components/OssnInvite/pages/invite');
    $content = ossn_set_page_layout('newsfeed', $contents);
    echo ossn_view_page($title, $content);
}
Example #7
0
function severpages($pages)
{
    if (!ossn_isLoggedin()) {
        ossn_error_page();
    }
    $title = ossn_print('com:ossn:severload');
    //give a exact path to file <components/serverpages/pages/serverload>
    $contents['content'] = ossn_view('components/serverpages/pages/severload');
    $content = ossn_set_page_layout('contents', $contents);
    echo ossn_view_page($title, $content);
}
/**
 * Load action.
 *
 * @param string $action The name of the action
 *
 * @return void
 */
function ossn_action($action)
{
    global $Ossn;
    if (isset($Ossn->action) && array_key_exists($action, $Ossn->action)) {
        if (is_file($Ossn->action[$action])) {
            $params['action'] = $action;
            ossn_trigger_callback('action', 'load', $params);
            include_once $Ossn->action[$action];
        }
    } else {
        ossn_error_page();
    }
}
function ossn_action($action)
{
    global $Ossn;
    if (isset($Ossn->action) && array_key_exists($action, $Ossn->action)) {
        if (is_file($Ossn->action[$action])) {
            ossn_trigger_callback('action', "load:{$action}");
            include_once $Ossn->action[$action];
        }
    } else {
        ossn_error_page();
        exit;
    }
}
function ossn_site_pages($pages)
{
    $page = $pages[0];
    if (empty($page)) {
        redirect(REF);
    }
    $OssnSitePages = new OssnSitePages();
    switch ($page) {
        case 'about':
            $OssnSitePages->pagename = 'about';
            $OssnSitePages = $OssnSitePages->getPage();
            if (isset($OssnSitePages->description)) {
                $params['contents'] = html_entity_decode(html_entity_decode($OssnSitePages->description));
            }
            $params['title'] = ossn_print('site:about');
            $title = $params['title'];
            $contents = array('content' => ossn_view('components/OssnSitePages/pages/page', $params));
            $content = ossn_set_page_layout('contents', $contents);
            echo ossn_view_page($title, $content);
            break;
        case 'terms':
            $OssnSitePages->pagename = 'terms';
            $OssnSitePages = $OssnSitePages->getPage();
            if (isset($OssnSitePages->description)) {
                $params['contents'] = html_entity_decode(html_entity_decode($OssnSitePages->description));
            }
            $params['title'] = ossn_print('site:terms');
            $title = $params['title'];
            $contents = array('content' => ossn_view('components/OssnSitePages/pages/page', $params));
            $content = ossn_set_page_layout('contents', $contents);
            echo ossn_view_page($title, $content);
            break;
        case 'privacy':
            $OssnSitePages->pagename = 'privacy';
            $OssnSitePages = $OssnSitePages->getPage();
            if (isset($OssnSitePages->description)) {
                $params['contents'] = html_entity_decode(html_entity_decode($OssnSitePages->description));
            }
            $params['title'] = ossn_print('site:privacy');
            $title = $params['title'];
            $contents = array('content' => ossn_view('components/OssnSitePages/pages/page', $params));
            $content = ossn_set_page_layout('contents', $contents);
            echo ossn_view_page($title, $content);
            break;
        default:
            ossn_error_page();
            break;
    }
}
function ossn_load_page($handler, $page)
{
    global $Ossn;
    ossn_add_context($handler);
    $page = explode('/', $page);
    if (isset($Ossn->page) && isset($Ossn->page[$handler]) && !empty($handler) && is_callable($Ossn->page[$handler])) {
        ob_start();
        call_user_func($Ossn->page[$handler], $page, $handler);
        $contents = ob_get_clean();
        $params['page'] = $page;
        $params['handler'] = $handler;
        return ossn_call_hook('page', 'load', $params, $contents);
    } else {
        return ossn_error_page();
    }
}
Example #12
0
/**
 * Ad image page handler
 *
 * Pages: photo
 *
 * @return image;
 * @access public
 */
function ossn_ads_handler($pages)
{
    $page = $pages[0];
    if (empty($page)) {
        return false;
    }
    switch ($page) {
        case 'photo':
            header('Content-Type: image/jpeg');
            if (!empty($pages[1]) && !empty($pages[1]) && $pages[2] == md5($pages[1]) . '.jpg') {
                echo ossn_ad_image($pages[1]);
            }
            break;
        default:
            echo ossn_error_page();
            break;
    }
}
Example #13
0
/**
 * Output a page.
 *
 * If page is not registered then user will see a 404 page;
 *
 * @param  (string) $handler Page handler name;
 * @param  (string) $page  handler/page;
 * @last edit: $arsalanshah
 * @Reason: Initial;
 *
 * @return mix|null data
 * @access private
 */
function ossn_load_page($handler, $page)
{
    global $Ossn;
    $context = $handler;
    if (isset($page) && !empty($page)) {
        $context = "{$handler}/{$page}";
    }
    //set context
    ossn_add_context($context);
    $page = explode('/', $page);
    if (isset($Ossn->page) && isset($Ossn->page[$handler]) && !empty($handler) && is_callable($Ossn->page[$handler])) {
        //get page contents
        ob_start();
        call_user_func($Ossn->page[$handler], $page, $handler);
        $contents = ob_get_clean();
        //supply params to hook
        $params['page'] = $page;
        $params['handler'] = $handler;
        return ossn_call_hook('page', 'load', $params, $contents);
    } else {
        return ossn_error_page();
    }
}
/**
 * Register a uservalidation page
 * @pages:
 *       uservalidate,
 *
 * @return bool
 */
function ossn_uservalidate_pagehandler($pages)
{
    $page = $pages[0];
    if (empty($page)) {
        echo ossn_error_page();
    }
    switch ($page) {
        case 'activate':
            if (!empty($pages[1]) && !empty($pages[2])) {
                $user = new OssnUser();
                $user->guid = $pages[1];
                if ($user->ValidateRegistration($pages[2])) {
                    ossn_trigger_message(ossn_print('user:account:validated'), 'success');
                    redirect();
                } else {
                    ossn_trigger_message(ossn_print('user:account:validate:fail'), 'success');
                    redirect();
                }
            }
            break;
    }
}
/**
 * Register site index page
 * @pages:
 *       index or home,
 *
 * @return boolean|null
 */
function ossn_index_pagehandler($index)
{
    if (ossn_isLoggedin()) {
        redirect('home');
    }
    $page = $index[0];
    if (empty($page)) {
        $page = 'home';
    }
    switch ($page) {
        case 'home':
            echo ossn_plugin_view('pages/index');
            break;
        default:
            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;
    }
}
/**
 * Register a page handler for administrator login;
 * @pages:
 *       administrator/login,
 * @return mixeddata
 */
function ossn_administrator_login_pagehandler($pages)
{
    $page = $pages[0];
    if (empty($page)) {
        $page = 'login';
    }
    switch ($page) {
        case 'login':
            $title = ossn_print('admin:login');
            $contents['contents'] = ossn_view("pages/administrator/contents/login");
            $contents['title'] = $title;
            $content = ossn_set_page_layout('administrator/login', $contents);
            echo ossn_view_page($title, $content, 'administrator');
            break;
        default:
            ossn_error_page();
            break;
    }
}
/**
 * Notifications page
 *
 * @param (array) $pages Array containg pages
 *
 * @return mixed data;
 * @access public
 */
function ossn_notifications_page($pages)
{
    $page = $pages[0];
    if (empty($page)) {
        return false;
    }
    switch ($page) {
        case 'all':
            $title = 'Notifications';
            $contents = array('content' => ossn_view('components/OssnNotifications/pages/all'));
            $content = ossn_set_page_layout('media', $contents);
            echo ossn_view_page($title, $content);
            break;
        default:
            ossn_error_page();
            break;
    }
}
/**
 * Check user blocks.
 *
 * @return void;
 * @access private;
 */
function ossn_user_block($name, $type, $return, $params)
{
    /*
     * Deny from visiting profile
     */
    if ($params['handler'] == 'u') {
        $user = ossn_user_by_username($params['page'][0]);
        if (OssnBlock::UserBlockCheck($user)) {
            ossn_error_page();
        }
    }
    /*
     * Deny from sending messages
     */
    if ($params['handler'] == 'messages' && isset($params['page'][1])) {
        $user = ossn_user_by_username($params['page'][1]);
        if ($user && OssnBlock::UserBlockCheck($user)) {
            ossn_error_page();
        }
    }
    /*
     * Deny from viewing user wall posts
     */
    if ($params['handler'] == 'post' && $params['page'][0] == 'view' && com_is_active('OssnWall')) {
        $post = new OssnWall();
        $post = $post->GetPost($params['page'][1]);
        $user = ossn_user_by_guid($post->owner_guid);
        if (OssnBlock::UserBlockCheck($user)) {
            ossn_error_page();
        }
    }
    /*
     * Deny from viewing profile photos album and albums
     */
    if ($params['handler'] == 'album') {
        //check if album is profile photos
        if ($params['page'][0] == 'profile') {
            $user = ossn_user_by_guid($params['page'][1]);
            //if album is not profile photos album then it means it simple album
        } elseif ($params['page'][0] == 'view') {
            $album = new OssnAlbums();
            $album = $album->GetAlbum($params['page'][1]);
            $user = ossn_user_by_guid($album->album->owner_guid);
        }
        if (isset($user) && OssnBlock::UserBlockCheck($user)) {
            ossn_error_page();
        }
    }
}
Example #20
0
/**
 * Viatges "handler" 
 * @pages:
 *       view,
 *       add
 *       
 *
 * @return diferent contents
 */
function trip_page_handler($trip)
{
    $page = $trip[0];
    if (empty($page)) {
        ossn_error_page();
        //Mostra 404
    }
    // var_dump($trip);
    switch ($page) {
        //Vista viatge (Accés públic no existeix restricció de visualització)
        case 'view':
            $view = new OptionTrips();
            $viewAlbum = new OssnAlbums();
            $album = $viewAlbum->GetAlbum(19);
            //Agafa id del viatge
            $infoTrip = $view->GetTrip($trip[1]);
            //Agafa id del viatge
            $infoDays = $view->GetTripDays($trip[1]);
            // var_dump($image);
            //$photo['entity'] = $image;
            $trip['info'] = $infoTrip;
            $trip['day'] = $infoDays;
            $trip['album'] = $album;
            //redirect user to home page if trip is empty
            if (empty($infoTrip)) {
                redirect();
            }
            //Missing "back" button to trips
            $owner = ossn_user_by_guid($infoTrip->guid);
            $back = array('text' => ossn_print('back'), 'href' => ossn_site_url("u/{$owner->username}/trips"), 'class' => 'button-grey');
            $control = ossn_plugin_view('output/url', $back);
            $contents = array('title' => ossn_print('trip:details'), 'content' => ossn_plugin_view('trips/pages/trip/view', $trip), 'controls' => $control, 'module_width' => '850px');
            //inclou page layout
            $module['content'] = ossn_set_page_layout('module', $contents);
            //Inclou modul amb els botons d'accions
            $content = ossn_set_page_layout('contents', $module);
            echo ossn_view_page($title, $content);
            break;
            //Afegir viatge
        //Afegir viatge
        case 'add':
            //Missing "back" button to trips
            $owner = ossn_loggedin_user()->username;
            // var_dump($owner);
            $back = array('text' => ossn_print('back'), 'href' => ossn_site_url("u/{$owner}/trips"), 'class' => 'button-grey');
            $control = ossn_plugin_view('output/url', $back);
            $contents = array('title' => ossn_print('add:trip'), 'content' => ossn_plugin_view('trips/pages/trip/add'), 'controls' => $control, 'module_width' => '850px');
            //inclou page layout
            $module['content'] = ossn_set_page_layout('module', $contents);
            //Inclou modul amb els botons d'accions
            $content = ossn_set_page_layout('contents', $module);
            echo ossn_view_page($title, $content);
            // echo ossn_plugin_view('output/url', array(
            // 		'title' => ossn_print('add:trip'),
            // 		'contents' => ossn_plugin_view('trips/pages/trip/add'),
            // 		'callback' => '#ossn-trip-submit'
            // ));
            break;
        case 'addPhoto':
            //add photos (ajax)
            if (!ossn_is_xhr()) {
                ossn_error_page();
            }
            echo ossn_plugin_view('output/ossnbox', array('title' => ossn_print('add:photos'), 'contents' => ossn_plugin_view('trips/pages/trip/addPhoto'), 'callback' => '#photos-submit'));
            break;
        default:
            ossn_error_page();
            //Mostra 404
            break;
    }
}
Example #21
0
/**
 * 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;
    }
}
Example #22
0
/**
 * Avatar page handler
 *
 * @return image;
 */
function avatar_page_handler($avatar)
{
    if (isset($avatar[0])) {
        if (!isset($avatar[1]) && empty($avatar[1])) {
            $avatar[1] = '';
        }
        $user = ossn_user_by_username($avatar[0]);
        if (!empty($user->guid)) {
            get_profile_photo($user, $avatar[1]);
        } else {
            ossn_error_page();
        }
    }
}
/**
 * Avatar page handler
 *
 * @return image;
 */
function avatar_page_handler($avatar)
{
    if (isset($avatar[0])) {
        if (!isset($avatar[1]) && empty($avatar[1])) {
            $avatar[1] = '';
        }
        $user = ossn_user_by_username($avatar[0]);
        if (!empty($user->guid)) {
            header('Content-Type: image/jpeg');
            echo get_profile_photo($user->guid, $avatar[1]);
        } else {
            ossn_error_page();
        }
    }
}
Example #24
0
/**
 * 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;
    }
}
/**
 * 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;
    }
}
function ossn_messages_page($pages)
{
    if (!ossn_isLoggedin()) {
        ossn_error_page();
    }
    $OssnMessages = new OssnMessages();
    $page = $pages[0];
    if (empty($page)) {
        $page = 'messages';
    }
    switch ($page) {
        case 'message':
            $username = $pages[1];
            if (!empty($username)) {
                $user = ossn_user_by_username($username);
                if (empty($user->guid)) {
                    ossn_error_page();
                }
                $title = ossn_print('ossn:message:between', array($user->fullname));
                $OssnMessages->markViewed($user->guid, ossn_loggedin_user()->guid);
                $params['data'] = $OssnMessages->get(ossn_loggedin_user()->guid, $user->guid);
                $params['user'] = $user;
                $params['recent'] = $OssnMessages->recentChat(ossn_loggedin_user()->guid);
                $contents = array('content' => ossn_plugin_view('messages/pages/view', $params));
                $content = ossn_set_page_layout('media', $contents);
                echo ossn_view_page($title, $content);
            } else {
                ossn_error_page();
            }
            break;
        case 'all':
            $params['recent'] = $OssnMessages->recentChat(ossn_loggedin_user()->guid);
            $active = $params['recent'][0];
            if (isset($active->message_to) && $active->message_to == ossn_loggedin_user()->guid) {
                $getuser = $active->message_from;
            }
            if (isset($active->message_from) && $active->message_from == ossn_loggedin_user()->guid) {
                $getuser = $active->message_to;
            }
            if (isset($getuser)) {
                $user = ossn_user_by_guid($getuser);
                $OssnMessages->markViewed($getuser, ossn_loggedin_user()->guid);
                $params['data'] = $OssnMessages->get(ossn_loggedin_user()->guid, $getuser);
                $params['user'] = $user;
            }
            $contents = array('content' => ossn_plugin_view('messages/pages/messages', $params));
            if (!isset($getuser)) {
                $contents = array('content' => ossn_plugin_view('messages/pages/messages-none'));
            }
            $title = ossn_print('messages');
            $content = ossn_set_page_layout('media', $contents);
            echo ossn_view_page($title, $content);
            break;
        case 'getnew':
            $username = $pages[1];
            $guid = ossn_user_by_username($username)->guid;
            $messages = $OssnMessages->getNew($guid, ossn_loggedin_user()->guid);
            if ($messages) {
                foreach ($messages as $message) {
                    $user = ossn_user_by_guid($message->message_from);
                    $message = $message->message;
                    $params['user'] = $user;
                    $params['message'] = $message;
                    echo ossn_plugin_view('messages/templates/message-send', $params);
                }
                $OssnMessages->markViewed($guid, ossn_loggedin_user()->guid);
                echo '<script>Ossn.playSound();</script>';
            }
            break;
        case 'getrecent':
            $params['recent'] = $OssnMessages->recentChat(ossn_loggedin_user()->guid);
            echo ossn_plugin_view('messages/templates/message-with', $params);
            break;
        default:
            ossn_error_page();
            break;
    }
}
Example #27
0
/**
 * Group page handler
 * This page also contain subpages like group/<guid>/members
 *
 * Pages:
 *      group/<guid>
 *      group/<guid>/<subpage>
 * Subpage need to be register seperatly.
 *
 * @return mixdata;
 * @access private
 */
function ossn_group_page($pages)
{
    if (empty($pages[0])) {
        ossn_error_page();
    }
    if (!empty($pages[0]) && !empty($pages[0])) {
        if (isset($pages[1])) {
            $params['subpage'] = $pages[1];
        } else {
            $params['subpage'] = '';
        }
        if (!ossn_is_group_subapge($params['subpage']) && !empty($params['subpage'])) {
            return false;
        }
        $group = ossn_get_group_by_guid($pages[0]);
        if (empty($group->guid)) {
            ossn_error_page();
        }
        ossn_set_page_owner_guid($group->guid);
        ossn_trigger_callback('page', 'load:group');
        $params['group'] = $group;
        $title = $group->title;
        $view = ossn_plugin_view('groups/pages/profile', $params);
        $contents['content'] = ossn_group_layout($view);
        $content = ossn_set_page_layout('contents', $contents);
        echo ossn_view_page($title, $content);
    }
}
/**
 * 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;
    }
}
Example #29
0
/**
 * Register a page handler for administrator login;
 * @pages:
 *       administrator/login,
 * @return mixeddata
 */
function ossn_administrator_login_pagehandler($pages)
{
    $page = $pages[0];
    if (empty($page)) {
        $page = 'login';
    }
    $logout = input('logout');
    if ($logout == 'true') {
        ossn_trigger_message(ossn_print('logged:out'));
        redirect('administrator');
    }
    switch ($page) {
        case 'login':
            $title = ossn_print('admin:login');
            $contents['contents'] = ossn_plugin_view("pages/administrator/contents/login");
            $contents['title'] = $title;
            $content = ossn_set_page_layout('administrator/login', $contents);
            echo ossn_view_page($title, $content, 'administrator');
            break;
        default:
            ossn_error_page();
            break;
    }
}