Created
December 13, 2010 01:51
-
-
Save nojimage/738558 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
class ExTwitterFormHelper extends TwitterFormHelper { | |
/** | |
* create OAuth Link | |
* | |
* @param $options | |
* loading: loading message | |
* login: login link text | |
* datasource: datasource name (default: twitter) | |
* authenticate: use authenticate link (default: false) | |
*/ | |
public function oauthLink($options = array()) { | |
$default = array( | |
'loading' => __d('twitter_kit', 'Loading...', true), | |
'login' => __d('twitter_kit', 'Login Twitter', true), | |
'datasource' => 'twitter', | |
'authenticate' => false, | |
'loginElementId' => 'twitter-login-wrap', | |
); | |
$options = am($default, $options); | |
$action = $options['authenticate'] ? 'authenticate_url' : 'authorize_url'; | |
$request_url = $this->Html->url(array('plugin' => 'twitter_kit', 'controller' => 'oauth', 'action' => $action . '/' . urlencode($options['datasource'])), true); | |
$this->Js->buffer(" | |
$.getJSON('{$request_url}', {}, function(data){ | |
var link = $('<a>').attr('href', data.url).html('{$options['login']}'); | |
$('#{$options['loginElementId']} .loading').remove(); | |
$('#{$options['loginElementId']}').append(link); | |
}); | |
"); | |
$out = sprintf('<span id="%s"><span class="loading">%s</span></span>', $options['loginElementId'], $options['loading']); | |
return $this->output($out); | |
} | |
} |
This file contains hidden or 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 | |
$this->ExTwitterForm->oauthLink(array('login' => $this->Html->image('login-button.png'))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment