Last active
August 29, 2015 14:26
-
-
Save shgysk8zer0/ece99476f809dfe232a3 to your computer and use it in GitHub Desktop.
TwitterAPI
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
DirectoryIndex index.html index.phtml index.php | |
#Configure PHP's autoloader and set include_path, min PHP version | |
<IfModule env_module> | |
SetEnv CONFIG_DIR ../../config | |
SetEnv AUTOLOAD_DIR ../../classes | |
</IfModule> | |
#Loads the autoloader script before executing main PHP file | |
php_value auto_prepend_file ../../std-php-functions/autoloader.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
<?php | |
namespace shgysk8zer0; | |
init(); | |
$timer = new Core\Timer; | |
$URL = new Core\URL; | |
$document = new DOM\HTML; | |
$session = new Core\Session; | |
if (isset($session->oAuth)) { | |
$oAuth = unserialize($session->oAuth); | |
} else { | |
$creds = new Core\Resources\Parser('twitter.json'); | |
$oAuth = new TwitterAPI\oAuth($creds->key, $creds->secret); | |
$session->oAuth = serialize($oAuth); | |
} | |
$Twitter = new TwitterAPI\Requests\UserTimeline($oAuth); | |
unset($URL->path, $creds, $oAuth); | |
if (array_key_exists('form', $_REQUEST) and $_REQUEST['form'] === 'twitter') { | |
$resp = new Core\JSON_Response; | |
check_nonce(); | |
$Twitter->screen_name = $_REQUEST['twitter']['user']; | |
$Twitter->count = $_REQUEST['twitter']['count']; | |
$tweets = new Core\ArrayObject($Twitter()); | |
$details = $document->body->append('details'); | |
$details->open(null); | |
$details('summary', 'Recent Tweets'); | |
$tweets->reduce(function(\DOMElement $list, \stdClass $tweet) | |
{ | |
$list('li', $tweet->text); | |
return $list; | |
}, | |
$details('ul') | |
); | |
$resp->html('main', "$details"); | |
exit($resp); | |
} | |
$Twitter->screen_name = 'shgysk8zer0'; | |
$Twitter->count = 10; | |
$tweets = new Core\ArrayObject($Twitter()); | |
$document->documentElement->class('no-js')->lang('en')->dir('ltr'); | |
$document->head->append('title', 'Twitter User_Timeline API'); | |
$document->head->append('base')->href($URL); | |
$document->head->append('meta')->name('viewport')->content('width=device-width'); | |
$document->head->append('meta')->name('description')->content('A demo of shgysk8zer0/TwitterAPI'); | |
$document->head->append('meta')->name('keywords')->content('Twitter, API, PHP, OOP'); | |
$document->head->append('meta')->name('referrer')->content('origin'); | |
$document->head->append('meta')->name('author')->content($_SERVER['SERVER_ADMIN']); | |
$document->head->append('link')->rel('stylesheet')->href('stylesheets/default-theme/output.css'); | |
$document->head->append('script')->type('application/javascript')->async()->src('scripts/combined.js'); | |
$document->body->class('flex row wrap'); | |
$header = $document->body->append('header'); | |
$main = $document->body->append('main'); | |
$footer = $document->body->append('footer', '©' . date('Y')); | |
$header('h1', 'shgysk8zer0/twitterapi'); | |
$form = $header('form'); | |
$form->action($_SERVER['PHP_SELF'])->method('post')->name('twitter'); | |
$fieldset = $form('fieldset'); | |
$fieldset->form = $form->name; | |
$label = $fieldset('label'); | |
$uname = $fieldset('input')->type('search')->name('twitter[user]')->id('twitter_user') | |
->pattern('\w+')->placeholder('handle')->required(); | |
$label->for($uname->id)->data_icon('t'); | |
$fieldset('input')->type('number')->name('twitter[count]')->id('twitter_count') | |
->min(5)->max(50)->size(2)->value(10)->required(); | |
$fieldset('button')->type('submit')->data_icon('.'); | |
unset($form, $fieldset, $label, $uname); | |
$details = $main('details'); | |
$details->open(true); | |
$details('summary', 'Recent Tweets'); | |
$tweets->reduce(function(\DOMElement $list, \stdClass $tweet) | |
{ | |
$list('li', $tweet->text); | |
return $list; | |
}, | |
$details('ul') | |
); | |
unset($details, $tweets); | |
$src_view = $document->body->append('dialog')->id('view_src'); | |
$src_view('button')->data_close("#{$src_view->id}"); | |
$src_view('button')->data_fullscreen("#{$src_view->id}"); | |
$src_view('br'); | |
$src_view->importHTML(highlight_file(__FILE__, true)); | |
$footer('a')->href('https://twitter.com/shgysk8zer0')->target('_blank')->name('Twitter') | |
->append('svg')->class('logo') | |
->append('use')->{'xlink:href'}('images/icons/combined.svg#twitter'); | |
$footer('a')->href('https://github.com/shgysk8zer0/twitterapi')->target('_blank') | |
->append('svg')->class('logo') | |
->append('use')->{'xlink:href'}('images/icons/combined.svg#mark-github'); | |
$footer('button')->data_show_modal("#{$src_view->id}")->append('svg') | |
->class('icon')->append('use')->{'xlink:href'}('images/icons/combined.svg#code'); | |
exit($document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment