Beispiel #1
0
function display_errors($return = false)
{
    $new_flash = array();

    foreach($_SESSION['flash'] as $flash)
    {
        if($flash['ttd'] > 0)
        {
            $flash['ttd'] --;

            array_push($GLOBALS['errors'], $flash['message']);

            if($flash['ttd'] > 0)
                array_push($new_flash, $flash);
        }
    }

    $_SESSION['flash'] = $new_flash;

    $view = instance_view('errors');
    if($return == false)
        $view->parse();
    else
        return $view->parse_to_variable();
}
    function public_msg()
    {
        if(!isset($_SESSION['active_user']))
            redirect_to(make_url('users', 'login'));

        $_SESSION['direct_to'] = make_url('dmessages', 'public_msg');

        $dm  = instance_model('direct_message');

    // display public messages
        $messages = $dm->get_by_user_id($_SESSION['active_user']['id']);

        $view = instance_view("direct_message");
        $view = $view->parse_to_variable(array(
            'messages' => $messages,
            'uname'    => $_SESSION['active_user']['name'],
            'uid'      => $_SESSION['active_user']['id'],
            'form_message' => 'Delete',
            'form_target' => make_url('dmessages', 'destroy_public')));

    // Display sidebar
        $sb_view = instance_view("feed_sidebar");
        $sb_view = $sb_view->parse_to_variable(array(
            'uid'   => $_SESSION['active_user']['id'],
            'uname' => $_SESSION['active_user']['name']));

        $this->set_template_paramiters(
            array('main_content' => $view,
                  'sidebar'      => $sb_view));
    }
Beispiel #3
0
    function index()
    {
        $root = get_app_root();

        $view    = instance_view('admin/index');
        $content = $view -> parse_to_variable(array(
        ));

        $this->set_template_paramiters(array(
            'path'    => $root,
            'content' => $content
        ));
    }
Beispiel #4
0
    function display_navigation()
    {
        $m_navi = instance_model('navigation');
        $navi = $m_navi->get_all('Order');

        $m_page = instance_model('page');

        $output = array();
        foreach($navi as $row)
        {
            $out_title = '';
            $out_url   = '';

            if($row['Type'] == 'page')
            {
                $page = $m_page->get_by_id($row['Data']);

                if($page == array())
                {
                    $out_title = '[Not Found]';
                    $out_url   = '#';
                }
                else
                {
                    $out_title = $row['Title'];
                    $out_url   = make_url('page', $page[0]['Clean_title']);
                
                }
            }
            else if($row['Type'] == 'url')
            {
                $out_title = $row['Title'];
                $out_url   = $row['Data'];
            }

            $output []= array(
                'title' => $out_title,
                'url'   => $out_url);
        }

        $view = instance_view('navigation');
        $view->parse(array(
            'navi' => $output
        ));
    }
Beispiel #5
0
    function note()
    {
        $path = get_app_root();
        $params = $this->params;

        $note_db = instance_model('notes');

        if(!isset($params[2]))
        {
            $note_id = $note_db->allocate_note();
            redirect_to(make_url('kindlenote', 'note', $note_id));
        }

        $note_id = $params[2];
        $note = $note_db->get_note($note_id);

        $view = instance_view('note_edit');
        $view->parse(array(
            'path'    => $path,
            'note_id' => $note_id,
            'note'    => $note 
        ));
    }
    function avatar()
    {
        if(!isset($_SESSION['active_user']))
            redirect_to(make_url("users"));

        $usr = instance_model('users');
        $user = $usr->get_user_by_id($_SESSION['active_user']['id']);

        if($user == array())
            throw new no_such_user_exception();

        if(!isset($_POST['Submit']))
        {
        // Display main
            $view = instance_view('settings_avatar');
            $view = $view->parse_to_variable(array(
                'user' => $user));
        }
        else
        {
        // Validate file type
            $type = array_pop(preg_split('/\./', $_FILES['file']['name']));

            $valid_extensions = array('png', 'jpg', 'jpeg', 'JPG', 'JPEG');

            for($found_type = 0; $found_type < count($valid_extensions); $found_type ++)
                if($type == $valid_extensions[$found_type])
                {
                    $found_type = -1;
                    break;
                }

            if($found_type != -1)
            {
                new_flash('Invalid file type', 1);
                redirect_to(make_url('settings', 'avatar'));
            }

            $tmpname = 'media/' . sha1(time()) . '.' . $type;

            if (@move_uploaded_file($_FILES['file']['tmp_name'], $tmpname)) 
            {
            // Load the image
                if($type == 'png')
                    $img = @imagecreatefrompng($tmpname);
                else
                    $img = @imagecreatefromjpeg($tmpname);

                if($img == false)
                {
                    new_flash('Problem with image', 1);
                    redirect_to(make_url('settings', 'avatar'));
                }

            // Resize
                $oldsize = getimagesize($tmpname);

                $img_n = imagecreatetruecolor(100, 100);
                imagecopyresampled($img_n, $img, 0, 0, 0, 0,
                    100, 100, $oldsize[0], $oldsize[1]);

                $avatar = 'media/' . $_SESSION['active_user']['name'] . '.jpg';
                $result = imagejpeg($img_n, $avatar , 90); 

                unlink($tmpname);

                if($result == false)
                {
                    new_flash('Problem with image', 1);
                    redirect_to(make_url('settings', 'avatar'));
                }

                print make_ext_url($avatar);

                $usr->update_avatar($user[0]['ID'], 
                    make_ext_url($avatar));

            // Delete the old avatar as long as it is not the default
                $old_avatar = basename($user[0]['Avatar']);
                if(preg_match('/.+default_avatar\.jpg/', $old_avatar))
                    unlink('media/' . $old_avatar);

                redirect_to(make_url('settings', 'avatar'));
            }
            else
            {
                new_flash("File failed to upload");
                redirect_to(make_url('settings', 'avatar'));
            }
        }

    // Display sidebar
        $sb_view = instance_view("settings_sidebar");
        $sb_view = $sb_view->parse_to_variable(array(
            'uid'   => $_SESSION['active_user']['id'],
            'uname' => $_SESSION['active_user']['name']));

        $this->set_template_paramiters(
            array('main_content' => $view,
                  'sidebar'      => $sb_view));
    }
Beispiel #7
0
    function admin_files_delete()
    {
    // Require admin login
        if(!(isset($_SESSION['active_user']) && $_SESSION['active_user']['type'] == 'admin'))
            redirect_to('/');

        $this->load_outer_template('admin');

        $m_files = instance_model('files');

        if(isset($_POST['Submit']))
        {
            $action = $_POST['Submit'];
            $id     = $_POST['item'];

            if($action == "Delete") {
                $file = $m_files->get_by_id($id);

                if($file == array())
                    throw new exception("File does not exist");

            // delete file on disk
                $path = 'res/files/' . $file[0]['Title'];
                if(file_exists($path))
                    unlink($path);

                $path = 'res/files/thumbs/' . $file[0]['Title'];
                if(file_exists($path))
                    unlink($path);

            // remove from db
                $m_files->delete_by_id($id);
            }

            redirect_to(make_url('files', 'admin_files'));
        }

        if(!isset($this->params[2]) || (!is_numeric($this->params[2])))
            throw new exception("No member specified");

        $item = $this->params[2];

        $file = $m_files->get_by_id($item);

        if($file == array())
            throw new exception("File does not exist");

        $title = $file[0]['Title'];

        $view = instance_view('admin/delete_generic');
        $view = $view->parse_to_variable(array(
            'back_url' => make_url('files', 'admin_files'),
            'title'    => 'Delete file page',
            'msg'      => "Are you sure you wish to <strong>permenantly</strong> delete file $title?",
            'form_url' => make_url('files', 'admin_files_delete'),
            'item'     => $item
        ));

        $this->set_template_paramiters(array(
            'content' => $view
        ));
    }
    function following($rmt = false)
    {
        $flash = 'The specified user does not exist, here are the users on this node';

        if($rmt == false)
            $rmt = instance_model('remotes');

        if(!isset($this->params[2]))
        {
            new_flash($flash, 1);
            redirect_to(make_url('users'));
        }

        $usr = instance_model('users');
        $user = $usr->get_user_by_name($this->params[2]);

        if($user == array())
        {
            new_flash($flash, 1);
            redirect_to(make_url('users'));
        }

        $rel = instance_model('relations');
        $following = $rel->get_following($user[0]['ID']);

    // display main
        $view = instance_view('user_list');
        $view = $view->parse_to_variable(array(
            'users' => $following,
            'title' => 'Following',
            'form_message' => 'Unfollow',
            'form_target'  => make_url('relations', 'destroy'),
            'rmt'          => $rmt));

    // display sidebar
        $sb_view = instance_view('profile_sidebar');
        $sb_view = $sb_view->parse_to_variable(array(
            'uid'      => $user[0]['ID'],
            'uname'    => $user[0]['User_name'],
            'fname'    => $user[0]['Full_name'],
            'location' => $user[0]['Location'],
            'web'      => $user[0]['Web'],
            'bio'      => $user[0]['Bio']));

        $this->set_template_paramiters(
            array('main_content' => $view,
                  'sidebar'      => $sb_view));
    }
Beispiel #9
0
    function admin_navi_delete()
    {
    // Require admin login
        if(!(isset($_SESSION['active_user']) && $_SESSION['active_user']['type'] == 'admin'))
            redirect_to('/');

        $this->load_outer_template('admin');

        $m_navi = instance_model('navigation');

        if(isset($_POST['Submit']))
        {
            $action = $_POST['Submit'];
            $id     = $_POST['item'];

            if($action == "Delete") {
                $link = $m_navi->get_by_id($id);

                if($link == array())
                    throw new exception("Navi link does not exist");

            // remove from db
                $m_navi->delete_by_id($id);
            }

            redirect_to(make_url('navi', 'admin_navi'));
        }

        if(!isset($this->params[2]) || (!is_numeric($this->params[2])))
            throw new exception("No link specified");

        $item = $this->params[2];

        $link = $m_navi->get_by_id($item);

        if($link == array())
            throw new exception("Navi link does not exist");

        $title = $link[0]['Title'];

        $view = instance_view('admin/delete_generic');
        $view = $view->parse_to_variable(array(
            'back_url' => make_url('navi', 'admin_navi'),
            'title'    => 'Delete navigation link',
            'msg'      => "Are you sure you wish to <strong>permenantly</strong> delete link $title?",
            'form_url' => make_url('navi', 'admin_navi_delete'),
            'item'     => $item
        ));

        $this->set_template_paramiters(array(
            'content' => $view
        ));
    }
Beispiel #10
0
 function load_outer_template($template_name)
 {
     $this->outer_template = instance_view($template_name, 'theme/');
 }
    function profile()
    {
        $flash = 'The specified user does not exist, here are the users on this node';
        if(!isset($this->params[2]))
        {
            new_flash($flash, 1);
            redirect_to(make_url('users'));
        }

        $user_name = $this->params[2];

        $usr = instance_model('users');
        $user = $usr->get_user_by_name($user_name);

        if($user == array())
        {
            new_flash($flash, 1);
            redirect_to(make_url('users'));
        }

        $msg = instance_model('messages');
        $messages = $msg->get_by_user_id($user[0]['ID']);

        $view = instance_view('profile');
        $view = $view->parse_to_variable(array(
            'messages' => $messages,
            'user'     => $user,
            'form_message' => 'Delete',
            'form_target'  => make_url('messages', 'destroy')));

        $sb_view = instance_view('profile_sidebar');
        $sb_view = $sb_view->parse_to_variable(array(
            'uid'      => $user[0]['ID'],
            'uname'    => $user[0]['User_name'],
            'fname'    => $user[0]['Full_name'],
            'location' => $user[0]['Location'],
            'web'      => $user[0]['Web'],
            'bio'      => $user[0]['Bio']));

    // Display
        $this->set_template_paramiters(
            array('main_content' => $view,
                  'sidebar'      => $sb_view));
    }
Beispiel #12
0
    function admin_gallery_delete()
    {
    // Require admin login
        if(!(isset($_SESSION['active_user']) && $_SESSION['active_user']['type'] == 'admin'))
            redirect_to('/');

        $this->load_outer_template('admin');

        if(!isset($this->params[2]) || (!is_numeric($this->params[2])))
            throw new exception("No set specified");

        $set_id = $this->params[2];

        $m_gallery = instance_model('gallery');

        if(isset($_POST['Submit']))
        {
            $action = $_POST['Submit'];
            $id     = $_POST['item'];

            if($action == "Delete") {
                $image = $m_gallery->get_by_id($id);

                if($image == array())
                    throw new exception("Image does not exist");

                $m_set     = instance_model('gallery_set');
                $m_members = instance_model('members');

                $set = $m_set->get_by_id($set_id);

                if($set == array())
                    throw new exception("Image set does not exist");

                $member = $m_members->get_by_id($set[0]['Owner']);

                if($member == array())
                    throw new exception("Member does not exist");

            // delete file on disk
                $path = 'res/gallery/' . $member[0]['Clean_title'] . '/' . $image[0]['File'];
                if(file_exists($path))
                    unlink($path);

                $path = 'res/gallery/' . $member[0]['Clean_title'] . '/thumbs/' . $image[0]['File'];
                if(file_exists($path))
                    unlink($path);

            // remove from db
                $m_gallery->delete_by_id($id);
            }

            redirect_to(make_url('members', 'admin_gallery', $set_id));
        }


        if(!isset($this->params[3]) || (!is_numeric($this->params[3])))
            throw new exception("No image specified");

        $item   = $this->params[3];

        $image = $m_gallery->get_by_id($item);

        if($image == array())
            throw new exception("Image does not exist");

        $title = $image[0]['File'];

        $view = instance_view('admin/delete_generic');
        $view = $view->parse_to_variable(array(
            'back_url' => make_url('members', 'admin_gallery', $set_id),
            'title'    => 'Delete gallery image',
            'msg'      => "Are you sure you wish to <strong>permenantly</strong> delete image $title?",
            'form_url' => make_url('members', 'admin_gallery_delete', $set_id, $item),
            'item'     => $item
        ));

        $this->set_template_paramiters(array(
            'content' => $view
        ));
    }
    function index($rmt = null)
    {
    // if not logged in, display list of users registered on this node
        if(!isset($_SESSION['active_user']))
            redirect_to(make_url("users"));

        $_SESSION['direct_to'] = make_url('messages');

    // if logged in, display timeline
        $msg = instance_model("messages");
        $csh = instance_model("message_cache");
        $rel = instance_model("relations");

        if($rmt == null)
            $rmt = instance_model("remotes");

        $local_user_id = $_SESSION['active_user']['id'];

    // get array of folowed users
        $folowed_users = $rel->get_following($local_user_id);

    // Check if the remote cache needs updating, update it if it does
        foreach($folowed_users as $remote_user)
            $csh->check_update($remote_user['Remote_URL']);

   // Combine messages from current user with cached messages from the users
    // it is following
        $message_list = array();

        $local_messages = $msg->get_by_user_id($local_user_id);

        $remote_url  = make_follow_url($_SESSION['active_user']['name']);
        $profile_url = make_profile_url($_SESSION['active_user']['name']);
        $remote_name = $_SESSION['active_user']['name'];

        $usr = instance_model('users');
        $user = $usr->get_user_by_id($_SESSION['active_user']['id']);

        foreach($local_messages as $message)
        {
            array_push($message_list, array(
                'Remote_URL'     => $remote_url,
                'Remote_profile' => $profile_url,
                'Remote_avatar'  => $user[0]['Avatar'],
                'Remote_name'    => $_SESSION['active_user']['name'],
                'Remote_time'    => $message['Time'],
                'Remote_message' => $message['Message']));
        }

        foreach($folowed_users as $user)
        {
            $cache = $csh->get_remote($user['Remote_URL']);

            foreach($cache as $item)
                array_push($message_list, $item);
        }

    // sort message list by time
        $sort_array = array();

        foreach($message_list as $item)
            array_push($sort_array, $item['Remote_time']);

        arsort($sort_array);

        $sorted_messages = array();

        foreach($sort_array as $key => $value)
            array_push($sorted_messages, $message_list[$key]);

    // display messages from the cache
        $view = instance_view("messages");
        $view = $view->parse_to_variable(array(
            "messages" => $sorted_messages));

    // Display sidebar
        $sb_view = instance_view("feed_sidebar");
        $sb_view = $sb_view->parse_to_variable(array(
            'uid'   => $_SESSION['active_user']['id'],
            'uname' => $_SESSION['active_user']['name']));

        $this->set_template_paramiters(
            array('main_content' => $view,
                  'sidebar'      => $sb_view));
    }
Beispiel #14
0
    function edit()
    {
        if(!(isset($_SESSION['active_user']) && $_SESSION['active_user']['type'] == 'admin'))
            redirect_to('/');

        $this->load_outer_template('admin');

        $usr = instance_model('users');

        if(!isset($_POST['Submit']))
        {
            $user = $usr->get_user_by_id($_SESSION['active_user']['id']);

            if($user == array())
                throw new exception("User does not exist");

            $form_vals = make_reg_vals_array('', $user[0]['Ppal_email'], '', '');

        // display user edit form
            $view = instance_view('users/edit');
            $view = $view->parse_to_variable(array(
                'form_vals' => $form_vals));

            $this->set_template_paramiters(array(
                'content' => $view
            ));
        }
        else
        {
        // reed the form
            $form_vals = array(
                'errs'       => array(),
                'ppal_email' => $_POST['ppal_email'],
                'oldpass'    => $_POST['oldpass'],
                'pass'       => $_POST['pass'],
                'pass_v'     => $_POST['pass_v']);

        // Instance users model
            $test_exists = array();

        // Validate email
            try
            {
                validate_email($form_vals['ppal_email']);
                $test_exists = $usr->get_user_by_email($form_vals['ppal_email']);

                if($test_exists != array() && $test_exists[0]['ID'] != $_SESSION['active_user']['id'])
                {
                    new_flash('Email address is already in use', 1);
                    $form_vals['ppal_email'] = '';
                }
            }
            catch(exception $e)
            {
                    new_flash('Email address is invalid', 1);
            }

        // Validate passwords
            if($form_vals['oldpass'] != '')
            {
                try {
                    $selected_user = $usr->verify_user($_SESSION['active_user']['name'], $form_vals['oldpass']);

                    if($selected_user == false)
                        throw new exception();

                    if(mb_strlen($form_vals['pass'], 'utf8') < 6)
                        new_flash('Password too short, min 6 charicters', 1);

                    else if(sha1($form_vals['pass']) != sha1($form_vals['pass_v']))
                        new_flash('Passwords do not match', 1);
                }
                catch(redirecting_to $e)
                {
                    throw $e;
                }
                catch(exception $e)
                {
                    new_flash('Username or password is incorrect', 1);
                }
            }

            if(count(get_errors()) == 0)
            {
            // Everything was valid, save, login and redirect
                $usr->update_user_email($_SESSION['active_user']['id'], $form_vals['ppal_email']);

                if($form_vals['oldpass'])
                {
                    $usr->update_password($_SESSION['active_user']['id'], $form_vals['pass']);
                }

                new_flash("Settings updated", 1);
            }

        // else re-display the register form and show errors
            //else
            //{
                $view = instance_view("users/edit");
                $view = $view->parse_to_variable(array(
                    'form_vals' => $form_vals));

                $this->set_template_paramiters(array(
                    'content' => $view
                ));
            //}
        }
    }
Beispiel #15
0
function handle_error($e)
{
    if(APP_MODE == 'test')
        throw $e;
    else
    {
    // Log the error with transaction id if avalable
        $type  = get_class($e);
        $trace = print_r($e->getTrace(), true);
        $msg = $e->getMessage();

        $pay_id = 'n/a';
        if(isset($_SESSION['payment_id']))
            $pay_id = $_SESSION['payment_id'];

        if($type == 'e_404')
        {
            $error = instance_view('404', 'theme/');
            $error = $error->parse_to_variable(array()); 
        }
        else
        {
            try {
                $model = instance_model('error_log');
                $code = $model->create($type, $msg, $trace, $pay_id);
            } catch(exception $e) {
                die();
            }

            $error = instance_view('server_error', 'theme/');
            $error = $error->parse_to_variable(array(
                'code' => $code
            )); 
        }

        $outer_template = instance_view('template', 'theme/');
        $outer_template->parse(array(
            'content' => $error
        ));
    }
}