#0 | Abraham\TwitterOAuth\TwitterOAuth->oauth(oauth/request_token, Array([oauth_callback] => http://dada-data.net/en/tweet/signin))
/home/block-dada/dada-website/apps/frontend/Controllers/TweetController.php (25) <?php
namespace Akufen\Frontend\Controllers;
use Akufen\Frontend\Helpers\Pages;
class TweetController extends AbstractHacktions
{
/**
* Dada Tweet
*/
public function indexAction()
{
// Request an oauth token for authentication
$config = $this->di->getConfig();
$twitter = new \Abraham\TwitterOAuth\TwitterOAuth(
$config->application->twitter->consumerKey,
$config->application->twitter->consumerSecret
);
$twitter->setTimeouts(10, 15);
$twitterTokens = $twitter->oauth(
'oauth/request_token',
array('oauth_callback' => 'http://'.$_SERVER['HTTP_HOST'].'/'.$this->language.'/tweet/signin')
);
// Store the twitter callback
$this->session->set('twitterCallback', $this->request->get('_url').'?skip=true');
// Store the token for future validation
if(!$this->session->has('twitterToken')) {
$this->session->set('twitterToken', $twitterTokens['oauth_token']);
$this->session->set('twitterTokenSecret', $twitterTokens['oauth_token_secret']);
}
// Store temporary tokens for view rendering
$this->view->twitterTokens = $twitterTokens;
// Build seo meta tags
Pages::buildSeo($this->node, '/img/meta/fb/tweet.jpg');
// Handle the rest of the hacktion
$this->handleHacktion('tweet');
}
/**
* Twitter Signin Action
*/
public function twitterSigninAction()
{
// Retrieve the twitter params
$params = $this->request->get();
// Validate the access token with the verifier
try {
$config = $this->di->getConfig();
$twitter = new \Abraham\TwitterOAuth\TwitterOAuth(
$config->application->twitter->consumerKey,
$config->application->twitter->consumerSecret,
$this->session->get('twitterToken'),
$this->session->get('twitterSecret')
);
$twitter->setTimeouts(10, 15);
$response = $twitter->oauth(
'oauth/access_token',
array(
'oauth_verifier' => $params['oauth_verifier'],
'oauth_token' => $params['oauth_token']
)
);
} catch (\Exception $e) {
return $this->dispatcher->forward(array(
'controller' => 'error',
'action' => 'show404'
));
}
// Store twitter connect information
$this->session->set('twitterId', $response['user_id']);
$this->session->set('twitterUsername', $response['screen_name']);
$this->session->set('twitterToken', $response['oauth_token']);
$this->session->set('twitterSecret', $response['oauth_token_secret']);
// Redirect the user to twitter hacktions
return $this->response->redirect($this->session->get('twitterCallback'));
}
/**
* Twitter Intent Action
*/
public function tweetIntentAction()
{
// Request valid parameters
if(!$this->session->has('twitterToken') || !$this->request->isAjax() || !$this->request->hasPost('message'))
return $this->dispatcher->forward(array(
'controller' => 'error',
'action' => 'show404'
));
// Disable view rendering
$this->view->disable();
// Handle new twitter request
$config = $this->di->getConfig();
$twitter = new \Abraham\TwitterOAuth\TwitterOAuth(
$config->application->twitter->consumerKey,
$config->application->twitter->consumerSecret,
$this->session->get('twitterToken'),
$this->session->get('twitterSecret')
);
$twitter->setTimeouts(10, 15);
// Store message locally
$message = $this->request->getPost('message');
// Attempt to find #dadadata
if(!preg_match('/\#dadadata/mi', $message)) {
$message = trim($message).' #dadadata';
}
// Post the message for the user
$twitter->post('statuses/update', array(
'status' => $message
));
}
}
|
#4 | Phalcon\Mvc\Application->handle()
/home/block-dada/dada-website/public/index.php (84) <?php
try {
// Create dependency injector
$di = new \Phalcon\DI\FactoryDefault();
$di->set('config', function() {
return include __DIR__ . '/../config.php';
});
// Retrieve instance of configuration
$config = $di->getConfig();
// Set development flags
if(!$config->application->production) {
// Report all error
error_reporting(E_ALL);
// Create a new debug listener
$debug = new \Phalcon\Debug();
$debug->listen();
}
// Url service configuration
$di->set('url', function() use($config) {
$url = new \Phalcon\Mvc\Url();
$url->setBaseUri($config->application->baseUri);
return $url;
});
// Session service configuration
$di->set('session', function() {
$session = new \Phalcon\Session\Adapter\Files();
$session->start();
return $session;
}, true);
// Configure router
$di->set('router', function() use($config) {
$router = new \Phalcon\Mvc\Router();
$router->setDefaultModule($config->application->defaultModule);
$router->removeExtraSlashes(true);
// Iterate and mount router groups from the configuration
foreach($config->application->routers as $info) {
require_once $info->path;
$group = new $info->className;
$router->mount($group);
}
return $router;
}, true);
// Modules configuration
$routerAdapater = array();
$di->set('modules', function() use($config) {
$modules = array();
foreach($config->modules->toArray() as $module) {
// Find out if the module is a composer package
if(substr($module, 0, 1) == '/') {
$modulePath = '..' . $module;
} else $modulePath = '../vendor/' . $module . '/src';
// Find the module name
$segments = explode('/', $module);
$moduleName = end($segments);
// Build the module configuration array
$modules[$moduleName] = array(
'className' => 'Akufen\\' . ucfirst($moduleName). '\\Module',
'path' => $modulePath . '/Module.php'
);
}
return $modules;
});
// Application configuration
$application = new \Phalcon\Mvc\Application();
$application->setDI($di);
$application->registerModules($di->getModules());
// Handle the request
echo $application->handle()->getContent();
} catch (Phalcon\Exception $e) {
echo $e->getMessage();
} catch (PDOException $e) {
echo $e->getMessage();
}
|