-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
825 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('/')); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,7 @@ | |
*/ | ||
'packages' => array( | ||
'orm', | ||
'twitter', | ||
), | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
Autoloader::add_namespace('\\Twitter', __DIR__.'/classes'); |
Oops, something went wrong.