Ejemplo n.º 1
0
 public function action_404()
 {
     // Lets see if theres a URL to redirect
     // $url = trim($_SERVER['REQUEST_URI'],'/');
     $url = str_replace(Uri::Base(), '', Uri::Create($_SERVER['REQUEST_URI']));
     $parts = preg_split('/\\//', $url);
     // var_dump($parts);
     if (count($parts) == 1) {
         $url = str_replace('%20', ' ', $url);
         static::$url_found = Model_Url::query()->where('short_url', $url)->get_one();
         if (empty(static::$url_found) === false) {
             return Controller_Url::action_view(static::$url_found);
         }
     } else {
         if (count($parts) == 2) {
             // $url = str_replace('%20',' ',$url[1]);
             $url = explode('/', $url);
             $url = $url[1];
             static::$url_found = Model_Url::query()->where('short_url', $url)->get_one();
             if (empty(static::$url_found) === false) {
                 return Controller_Url::action_view(static::$url_found);
             }
         }
     }
     $data = new stdClass();
     $this->template->content = View::forge('core/404');
 }
 public function before()
 {
     parent::before();
     if (Auth::Check() === false) {
         Response::Redirect(Uri::Base());
     }
 }
Ejemplo n.º 3
0
 public function action_recover($hash = null)
 {
     if (Input::Method() === "POST") {
         if ($user = \Model\Auth_User::find_by_email(Input::POST('email'))) {
             // generate a recovery hash
             $hash = \Auth::instance()->hash_password(\Str::random()) . $user->id;
             // and store it in the user profile
             \Auth::update_user(array('lostpassword_hash' => $hash, 'lostpassword_created' => time()), $user->username);
             // send an email out with a reset link
             \Package::load('email');
             $email = \Email::forge();
             $html = 'Your password recovery link <a href="' . Uri::Create('login/recover/' . $hash) . '">Recover My Password!</a>';
             // use a view file to generate the email message
             $email->html_body($html);
             // give it a subject
             $email->subject(\Settings::Get('site_name') . ' Password Recovery');
             // GET ADMIN EMAIL FROM SETTINGS?
             $admin_email = Settings::get('admin_email');
             if (empty($admin_email) === false) {
                 $from = $admin_email;
             } else {
                 $from = 'support@' . str_replace('http:', '', str_replace('/', '', Uri::Base(false)));
             }
             $email->from($from);
             $email->to($user->email, $user->fullname);
             // and off it goes (if all goes well)!
             try {
                 // send the email
                 $email->send();
                 Session::set('success', 'Email has been sent to ' . $user->email . '! Please check your spam folder!');
             } catch (\Exception $e) {
                 Session::Set('error', 'We failed to send the eamil , contact ' . $admin_email);
                 \Response::redirect_back();
             }
         } else {
             Session::Set('error', 'Sorry there is not a matching email!');
         }
     } elseif (empty($hash) === false) {
         $hash = str_replace(Uri::Create('login/recover/'), '', Uri::current());
         $user = substr($hash, 44);
         if ($user = \Model\Auth_User::find_by_id($user)) {
             // do we have this hash for this user, and hasn't it expired yet , must be within 24 hours
             if (isset($user->lostpassword_hash) and $user->lostpassword_hash == $hash and time() - $user->lostpassword_created < 86400) {
                 // invalidate the hash
                 \Auth::update_user(array('lostpassword_hash' => null, 'lostpassword_created' => null), $user->username);
                 // log the user in and go to the profile to change the password
                 if (\Auth::instance()->force_login($user->id)) {
                     Session::Set('current_password', Auth::reset_password($user->username));
                     Response::Redirect(Uri::Create('user/settings'));
                 }
             }
         }
         Session::Set('error', 'Invalid Hash!');
     }
     $this->template->content = View::forge('login/recover');
 }
Ejemplo n.º 4
0
 public function before()
 {
     parent::before();
     if (\Settings::Get('api') !== true) {
         echo 'API DISABLED';
         Session::Set('error', 'API Disabled');
         Response::redirect(Uri::Base());
         die;
     }
 }
 public function before()
 {
     // Lets render the template
     parent::before();
     // Check to see if the config exsists
     if (file_exists(APPPATH . 'config/production/db.php') === false) {
         Response::Redirect('install');
     }
     if (DBUtil::field_exists('urls', array('cached_preview')) === false && file_exists(APPPATH . 'classes/controller/upgrade.php')) {
         Response::Redirect(Uri::Create('upgrade'));
     }
     $real_base_url = Config::get('base_url');
     Config::set('base_url', str_replace('public/', '', $real_base_url));
     $base_url = Settings::get('different_short_url');
     if (empty($base_url) === false) {
         View::set_global(array('base_url' => $base_url), false, false);
     }
     if (trim(Uri::Base(), '/') == Settings::get('different_short_url')) {
         if (count(Uri::Segments()) == 2) {
             $route = Uri::to_assoc();
             if (isset($route) === true && $route['core'] == '404') {
                 // We are good!
             } else {
                 Response::Redirect(Settings::Get('base_url'));
             }
         } else {
             Response::Redirect(Settings::Get('base_url'));
         }
     }
     $data = null;
     if (Auth::Check()) {
         $user_id = Auth::get_user_id();
         static::$user_id = $user_id[1];
         $data['api_key'] = Auth::get('api_key');
         if (empty($data['api_key']) === true) {
             if (empty($data['api_key']) === true) {
                 $data['api_key'] = preg_replace('/\\+|\\/|\\=|\\?/', '', \Auth::instance()->hash_password(\Str::random()) . static::$user_id);
                 // invalidate the hash
                 \Auth::update_user(array('api_key' => $data['api_key']), Auth::get('username'));
             }
         }
     }
     // Lets set the default title , you can change it when calling the view
     $this->template->title = ucwords(str_replace('controller_', '', strtolower($this->request->route->controller)));
     try {
         Module::load('image');
         $this->template->image_js = true;
     } catch (Exception $e) {
     }
     // Lets get the header and footer and set a variable to use within the template
     $this->template->footer = View::forge('core/footer', $data);
     $this->template->header = View::forge('core/header');
 }
Ejemplo n.º 6
0
        echo isset($base_url) === true ? $base_url . '/' . $url->short_url : Uri::Create($url->short_url);
        ?>
"><?php 
        echo $url->short_url;
        ?>
</a></td>
                                                                            <td><?php 
        echo number_format($url->hits);
        ?>
</td>
                                                                            <td><?php 
        echo Settings::time_ago($url->updated_at);
        ?>
</td>
                                                                            <td><a href="<?php 
        echo \Uri::Base() . 'stats/' . $url->short_url;
        ?>
">View Stats</a></td>
                                                                    </tr>
								<?php 
    }
}
?>
					</tbody>
					
				</table>
		</div>


</div>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
           text_input.focus ();
           text_input.select ();
        }
        
        var max_file_size = <?php 
echo min($max_upload, $max_post);
?>
;
        
        $(document).ready(function()
        {
            $('.colorbox').colorbox({photo:true, maxWidth:'95%', maxHeight:'95%'}).resize();
            
            $("#content-short-url .btn").zclip({
                path:'<?php 
echo Uri::Base();
?>
assets/swf/ZeroClipboard.swf',
                copy:function(){return $('#appendedInputButton').val();},
                afterCopy:function(){
                    $('#show_copy').slideDown();
                }
            });
            
            $(".confirm").on("click", function(e) {
                    e.preventDefault();
                    var targetUrl = $(this).attr("href");
                    
                    $("#dialog").html($(this).attr('data-text'));
                    $("#dialog").dialog({
                            buttons : {
            $.get('<?php 
    echo Uri::Create('url/make_image?url_id=' . $url_object->id . '');
    ?>
', function(data_url)
            {
                $('#preview_text').hide();
                $('#preview').attr('src',data_url);
            });
        });
        
        
    </script>
<?php 
}
if (isset($base_url) === false) {
    $base_url = Uri::Base();
} else {
    $base_url = $base_url . '/';
}
?>

<div class="row">
<div class="col-lg-8 col-lg-offset-2">
	<h2>Your new URL has been created!</h2> 

<div class="row">
    <div class="col-lg-8 col-lg-offset-2" id="content-short-url">
            <hr>
            <div style="display: none;" id="show_copy" class="alert alert-info">Copied</div>
            <div class="input-group margin-bottom-10">
                    <input id="appendedInputButton" class="form-control input-lg" type="text" value="<?php 
Ejemplo n.º 9
0
 public function action_stats($short_url)
 {
     $data['url'] = Model_Url::query()->where('short_url', $short_url)->get_one();
     if (empty($data['url']) === false) {
         $data['unqiue_hits'] = DB::select('ip')->distinct()->from('url_stats')->where('url_id', $data['url']->id)->execute();
         $data['unqiue_hits'] = count($data['unqiue_hits']);
         $data['unqiue_hits_today'] = DB::select('ip')->distinct()->from('url_stats')->where('url_id', $data['url']->id)->where('created_at', '>=', strtotime('today 12:01'))->where('created_at', '<=', strtotime('today 12:01 + 1 day'))->execute();
         $data['unqiue_hits_today'] = count($data['unqiue_hits_today']);
         $data['hits_today'] = DB::select('id')->from('url_stats')->where('url_id', $data['url']->id)->where('created_at', '>=', strtotime('today 12:01'))->where('created_at', '<=', strtotime('today 12:01 + 1 day'))->execute();
         $data['hits_today'] = count($data['hits_today']);
         $new_results = '';
         // Get countries Stats
         $countries = DB::select('country')->from('url_stats')->distinct(true)->where('url_id', $data['url']->id)->execute()->as_array();
         if (empty($countries) === false) {
             foreach ($countries as $country) {
                 $hit_count = Model_Url_Stat::query()->related('url')->where('country', $country)->where('url_id', $data['url']->id)->count();
                 $new_results .= "['" . $country['country'] . "', " . $hit_count . "], ";
             }
             $data['stats'] = $new_results;
         } else {
             $data['stats'] = null;
         }
         $this->template->content = View::forge('url/stats', $data);
     } else {
         Session::Set('error', 'No URL was found');
         Response::Redirect(Uri::Base());
     }
 }
Ejemplo n.º 10
0
 public static function Create_User($opauth, $user_id = null)
 {
     if (empty($user_id) === true) {
         $user_id = static::$user_id;
     }
     if ($user_id != 0 && empty($user_id) === false) {
         // call Opauth to link the provider login with the local user
         $insert_id = $opauth->link_provider(array('parent_id' => $user_id, 'user_id' => 0, 'provider' => $opauth->get('auth.provider'), 'uid' => $opauth->get('auth.uid'), 'access_token' => $opauth->get('credentials.token', null), 'secret' => $opauth->get('credentials.secret', null), 'refresh_token' => $opauth->get('credentials.refresh_token', null), 'expires' => $opauth->get('credentials.expires', null), 'created_at' => time()));
     } else {
         Response::Redirect(Uri::Base());
     }
 }