Skip to content

Commit

Permalink
Merge branch 'release/v1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrrgn committed Apr 19, 2011
2 parents eadb846 + e743c19 commit 9cf1d0d
Show file tree
Hide file tree
Showing 15 changed files with 825 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fuel/app/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* Set the timezone to what you need it to be.
*/
date_default_timezone_set('UTC');
date_default_timezone_set('America/New_York');

/**
* Set the encoding you would like to use.
Expand Down
30 changes: 30 additions & 0 deletions fuel/app/classes/controller/scraps.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,23 @@
* @link http://scrapyrd.com
*/

use Twitter\Tweet;

class Controller_Scraps extends Controller_Template {

public $template = 'scraps/template';

public function before()
{
parent::before();
$this->template->logged_in = Tweet::instance()->logged_in();

if ($this->template->logged_in)
{
$this->template->user = Model_User::find_by_id(Session::get('user_id'));
}
}

public function router($method, $params)
{
$method === '' and $method = 'index';
Expand Down Expand Up @@ -49,6 +62,16 @@ public function action_reply($short_id)
}
}

public function action_list()
{
if ( ! $this->template->logged_in)
{
Response::redirect('twitter/login');
}
$scraps = Model_Scrap::find_all_by_user_id(Session::get('user_id'));
$this->template->title = 'My Scraps';
$this->template->content = new View('scraps/list', array('scraps' => $scraps));
}

public function action_new()
{
Expand All @@ -71,13 +94,20 @@ public function action_new()
$last_scrap->save();
}

$user_id = null;
if ($this->template->logged_in)
{
$user_id = Session::get('user_id');
}

$scrap = new Model_Scrap;
$scrap->contents = $contents;
$scrap->short_id = $short_id;
$scrap->type = Input::post('type');
$scrap->private = $private;
$scrap->created_at = time();
$scrap->updated_at = time();
$scrap->user_id = $user_id;
$scrap->views = 0;
$scrap->save();

Expand Down
50 changes: 50 additions & 0 deletions fuel/app/classes/controller/twitter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

use Twitter\Tweet;

class Controller_Twitter extends Controller {

public function action_login()
{
if ( ! Tweet::instance()->logged_in() )
{
Tweet::instance()->set_callback(Uri::create('twitter/callback'));
Tweet::instance()->login();
}
else
{
Response::redirect(Uri::create('/'));
}
}

public function action_logout()
{
Session::destroy();
Response::redirect(Uri::create('/'));
}


public function action_callback()
{
$tokens = Tweet::instance()->get_tokens();
$twitter_user = Tweet::instance()->call('get', 'account/verify_credentials');

$user = Model_User::find_by_screen_name($twitter_user->screen_name);
if ( ! $user)
{
$user = new Model_User();
}
$user->screen_name = $twitter_user->screen_name;
$user->name = $twitter_user->name;
$user->description = $twitter_user->description;
$user->avatar = $twitter_user->profile_image_url;
$user->oauth_token = $tokens['oauth_token'];
$user->oauth_token_secret = $tokens['oauth_token_secret'];
$user->save();

Session::set('user_id', $user->id);

Response::redirect(Uri::create('/'));
}

}
5 changes: 5 additions & 0 deletions fuel/app/classes/model/user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

class Model_User extends Orm\Model { }

/* End of file user.php */
1 change: 1 addition & 0 deletions fuel/app/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
*/
'packages' => array(
'orm',
'twitter',
),

/**
Expand Down
1 change: 1 addition & 0 deletions fuel/app/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
return array(
'_root_' => 'scraps/index', // The default route
'_404_' => 'scraps/404', // The main 404 route
'twitter(:any)?' => 'twitter$1',
'(:any)' => 'scraps/$1',
);
25 changes: 25 additions & 0 deletions fuel/app/migrations/004_create_users.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Fuel\Migrations;

class Create_users {

public function up()
{
\DBUtil::create_table('users', array(
'id' => array('constraint' => 11, 'type' => 'int', 'auto_increment' => true),
'screen_name' => array('constraint' => 255, 'type' => 'varchar'),
'name' => array('constraint' => 255, 'type' => 'varchar'),
'description' => array('type' => 'text'),
'avatar' => array('type' => 'text'),
'oauth_token' => array('constraint' => 255, 'type' => 'varchar'),
'oauth_token_secret' => array('constraint' => 255, 'type' => 'varchar'),

), array('id'));
}

public function down()
{
\DBUtil::drop_table('users');
}
}
16 changes: 16 additions & 0 deletions fuel/app/migrations/005_add_user_id_to_scraps.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Fuel\Migrations;

class Add_user_id_to_scraps {

public function up()
{
\DB::query('ALTER TABLE `scraps` ADD `user_id` INT(11) NULL')->execute();
}

public function down()
{
\DB::query('ALTER TABLE `scraps` DROP COLUMN `user_id`')->execute();
}
}
6 changes: 6 additions & 0 deletions fuel/app/views/scraps/list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php foreach ($scraps as $scrap): ?>
<div class="scrap">
<?php echo Html::anchor($scrap->short_id, Uri::create($scrap->short_id)); ?> - Created on <?php echo date('F j, Y \a\t g:i a', $scrap->created_at); ?>
<div class="preview"><pre><code><?php echo Str::truncate($scrap->contents, 200, '...', true); ?></code></pre></div>
</div>
<?php endforeach; ?>
11 changes: 11 additions & 0 deletions fuel/app/views/scraps/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,20 @@
<h1>ScrapYrd</h1>
<ul id="nav">
<li><?php echo Html::anchor('', 'New Scrap'); ?></li>
<?php if ($logged_in): ?>
<li><?php echo Html::anchor('list', 'My Scraps'); ?></li>
<?php endif; ?>
</ul>
<div id="info">
<span id="user_info">
<?php if ( ! $logged_in): ?>
<?php echo Html::anchor('twitter/login', Asset::img('sign-in-with-twitter.png')); ?>&nbsp;|
Share your Code Scraps!
<?php else: ?>
Logged in as <strong><?php echo $user->name; ?></strong> <?php echo Asset::img($user->avatar, array('height' => '25', 'width' => '25', 'class' => 'avatar')); ?> |
<?php echo Html::anchor('twitter/logout', 'Logout'); ?>
<?php endif; ?>
</span>
</div>
<div style="clear:both;"></div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions fuel/packages/twitter/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

Autoloader::add_namespace('\\Twitter', __DIR__.'/classes');
Loading

0 comments on commit 9cf1d0d

Please sign in to comment.