Skip to content
Browse files

CCK API support

  • Loading branch information...
1 parent 4036257 commit 3ea505c9f5c97bb9fa55b1cbd57672eb1feca08c @zagraves zagraves committed Jan 22, 2010
Showing with 431 additions and 317 deletions.
  1. +77 −81 yupdates.php
  2. +56 −0 yupdates_application.php
  3. +1 −0 yupdates_db.php
  4. +138 −115 yupdates_options.php
  5. +3 −2 yupdates_sessionstore.php
  6. +156 −119 yupdates_utils.php
View
158 yupdates.php
@@ -9,7 +9,7 @@
* @package yos-updates-wordpress
* @subpackage yahoo
*
- * @author Ryan Kennedy <rckenned@yahoo-inc.com>, Lawrence Morrisroe <lem@yahoo-inc.com>, Zach Graves <zachg@yahoo-inc.com>
+ * @author Ryan Kennedy <rckenned@yahoo-inc.com>, Lawrence Morrisroe <lem@yahoo-inc.com>, Zach Graves <zachg@yahoo-incnc.com>
* @copyright Copyrights for code authored by Yahoo! Inc. is licensed under the following terms:
* @license BSD Open Source License
*
@@ -41,100 +41,96 @@
*/
?>
<?php
- define("YUPDATES_WIDGET_ENABLED", true);
+define("YUPDATES_WIDGET_ENABLED", true);
+
+define("PLUGIN_OPTIONS_URI","options-general.php?page=yupdates_plugin_options");
+define("USER_MENU_URI","users.php?page=yupdates_menu");
+
+require_once("lib/OAuth/OAuth.php");
+require_once("lib/Yahoo/YahooOAuthApplication.class.php");
+
+// require_once("yupdates_application.php");
+require_once("yupdates_sessionstore.php");
+require_once("yupdates_utils.php");
+require_once("yupdates_menu.php");
+require_once("yupdates_options.php");
+require_once("yupdates_hooks.php");
+require_once("yupdates_db.php");
+
+if(YUPDATES_WIDGET_ENABLED) {
+ require_once("yupdates_widgets.php");
+}
+
+add_action("admin_menu", "yupdates_plugin_menu");
+add_action("init", "yupdates_auth_init");
+add_action("publish_post", "yupdates_publish_post");
+// add_action("delete_post", "yupdates_delete_post");
+// add_action("edit_post", "yupdates_edit_post");
+
+function yupdates_plugin_menu() {
+ add_submenu_page("users.php", "Yahoo! Updates Page", "Yahoo! Updates Authorization", 0, "yupdates_menu", "yupdates_menu");
+ add_options_page("Yahoo! Updates Plugin Options", "Yahoo! Updates Plugin", 8, "yupdates_plugin_options", "yupdates_plugin_options");
+}
+
+function yupdates_auth_init() {
+ $session = yupdates_get_session();
- define("PLUGIN_OPTIONS_URI","options-general.php?page=yupdates_plugin_options");
- define("USER_MENU_URI","users.php?page=yupdates_menu");
-
- require_once("lib/OAuth/OAuth.php");
- require_once("lib/Yahoo/YahooOAuthApplication.class.php");
-
- require_once("yupdates_sessionstore.php");
- require_once("yupdates_utils.php");
- require_once("yupdates_menu.php");
- require_once("yupdates_options.php");
- require_once("yupdates_hooks.php");
- require_once("yupdates_db.php");
-
- if(YUPDATES_WIDGET_ENABLED) {
- require_once("yupdates_widgets.php");
- }
-
- add_action("admin_menu", "yupdates_plugin_menu");
- add_action("init", "yupdates_auth_init");
-
- add_action("publish_post", "yupdates_publish_post");
- // add_action("delete_post", "yupdates_delete_post");
- // add_action("edit_post", "yupdates_edit_post");
-?>
-<?php
- function yupdates_plugin_menu() {
- add_submenu_page("users.php", "Yahoo! Updates Page", "Yahoo! Updates Authorization", 0, "yupdates_menu", "yupdates_menu");
- add_options_page("Yahoo! Updates Plugin Options", "Yahoo! Updates Plugin", 8, "yupdates_plugin_options", "yupdates_plugin_options");
+ // handle directions from auth flow
+ if(array_key_exists("yupdates_clearauthorization", $_REQUEST)) {
+ yupdates_clear_session();
+ } else if(array_key_exists("auth_popup", $_REQUEST)) {
+ yupdates_close_popup();
}
- function yupdates_auth_init() {
- $session = yupdates_get_session();
-
- // handle directions from auth flow
- if(array_key_exists("yupdates_clearauthorization", $_REQUEST))
- {
- yupdates_clear_session();
- }
- else if(array_key_exists("auth_popup", $_REQUEST))
- {
- yupdates_close_popup();
- }
-
- // show warnings
- if($session->hasSession == false)
- {
- if($session->store->hasRequestToken()) {
- $request_token = $session->store->fetchRequestToken();
- if(is_null($request_token->key) && !is_null($request_token->oauth_problem)) {
- add_action("admin_notices", "yupdates_requestTokenProblem_warning");
- } else if(stripos($_SERVER["REQUEST_URI"], USER_MENU_URI) === FALSE) {
- add_action("admin_notices", "yupdates_authorization_warning");
- }
- } else if(yupdatesdb_hasApplicationInfo() && stripos($_SERVER["REQUEST_URI"], USER_MENU_URI) === FALSE ) {
+ // show warnings
+ if($session->hasSession == false) {
+ if($session->store->hasRequestToken()) {
+ $request_token = $session->store->fetchRequestToken();
+ if($request_token && is_null($request_token->key) && !is_null($request_token->oauth_problem)) {
+ add_action("admin_notices", "yupdates_requestTokenProblem_warning");
+ } else if(stripos($_SERVER["REQUEST_URI"], USER_MENU_URI) === FALSE) {
add_action("admin_notices", "yupdates_authorization_warning");
- } else if($session->store->hasAccessToken()) {
- // do nothing, we're all set.
}
- }
-
- if(!yupdatesdb_hasApplicationInfo()
- && stripos($_SERVER["REQUEST_URI"], PLUGIN_OPTIONS_URI) === FALSE)
- {
- add_action("admin_notices", "yupdates_appinfo_warning");
- }
+ }/* else if(yupdatesdb_hasApplicationInfo() && stripos($_SERVER["REQUEST_URI"], USER_MENU_URI) === FALSE ) {
+ echo "no request token";
+ add_action("admin_notices", "yupdates_authorization_warning");
+ } else if($session->store->hasAccessToken()) {
+ // do nothing, we're all set now.
+ } else {
+ echo "no tokens!";
+ }*/
}
- function yupdates_requestTokenProblem_warning() {
- $session_store = yupdates_get_currentUserSessionStore();
- $token = $session_store->fetchRequestToken();
- $oauth_problem = !is_null($token->oauth_problem) ? $token->oauth_problem : "Unknown Error";
-
- echo <<<HTML
+ if(!yupdatesdb_hasApplicationInfo() && stripos($_SERVER["REQUEST_URI"], PLUGIN_OPTIONS_URI) === FALSE) {
+ add_action("admin_notices", "yupdates_appinfo_warning");
+ }
+}
+
+function yupdates_requestTokenProblem_warning() {
+ $session_store = yupdates_get_currentUserSessionStore();
+ $token = $session_store->fetchRequestToken();
+ $oauth_problem = !is_null($token->oauth_problem) ? $token->oauth_problem : "Unknown Error";
+
+ echo <<<HTML
<div id="yupdates-authorization-warning" class="updated fade">
- <p><strong>OAuth Error: Request token $oauth_problem. <a href="options-general.php?page=yupdates_plugin_options#settings">Re-configure the plugin.</a></strong></p>
+<p><strong>Yahoo! Updates - OAuth Error: Request token $oauth_problem. <a href="options-general.php?page=yupdates_plugin_options#settings">Re-configure the plugin.</a></strong></p>
</div>
HTML;
- }
-
- function yupdates_appinfo_warning() {
- echo <<<HTML
+}
+
+function yupdates_appinfo_warning() {
+ echo <<<HTML
<div id="yupdates-appinfo-warning" class="updated fade">
- <p><strong>You haven't configured the Yahoo! Updates Plugin yet. <a href="options-general.php?page=yupdates_plugin_options">Configure the plugin.</a></strong></p>
+<p><strong>You haven't configured the Yahoo! Updates Plugin yet. <a href="options-general.php?page=yupdates_plugin_options">Configure the plugin.</a></strong></p>
</div>
HTML;
- }
-
- function yupdates_authorization_warning() {
- echo <<<HTML
+}
+
+function yupdates_authorization_warning() {
+ echo <<<HTML
<div id="yupdates-authorization-warning" class="updated fade">
- <p><strong>You haven't authorized the Yahoo! Updates Plugin yet. <a href="users.php?page=yupdates_menu">Authorize the plugin now.</a></strong></p>
+<p><strong>You haven't authorized the Yahoo! Updates Plugin yet. <a href="users.php?page=yupdates_menu">Authorize the plugin now.</a></strong></p>
</div>
HTML;
- }
+}
?>
View
56 yupdates_application.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * Yahoo! Updates Wordpress Plugin
+ *
+ * Find documentation and support on Yahoo! Developer Network: http://developer.yahoo.com
+ *
+ * Hosted on GitHub: http://github.com/yahoo/yos-updates-wordpress/tree/master
+ *
+ * @package yos-updates-wordpress
+ * @subpackage yahoo
+ *
+ * @author Ryan Kennedy,
+ * @author Lawrence Morrisroe <lem@yahoo-inc.com>
+ * @author Zach Graves <zachg@yahoo-inc.com>
+ * @author Micah Laaker <micahl@yahoo-inc.com>
+ * @copyright Copyrights for code authored by Yahoo! Inc. is licensed under the following terms:
+ * @license BSD Open Source License
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ **/
+
+function yupdates_plugin_application() {
+ $application_id = $_GET['appid'];
+ $consumer_key = $_GET['key'];
+ $consumer_secret = $_GET['secret'];
+
+ echo <<<HTML
+<script type="text/javascript">
+var opener = parent.opener;
+
+if(opener.hasOwnProperty('yupdates_setCredentials') && typeof opener.yupdates_setCredentials == 'function') {
+ opener.yupdates_setCredentials("{$consumer_key}","{$consumer_secret}","{$application_id}");
+}
+</script>
+
+HTML;
+}
+
+yupdates_plugin_application();
+?>
View
1 yupdates_db.php
@@ -40,6 +40,7 @@
define("YUPDATES_TITLE_TEMPLATE_OPTION", "yupdates_title_template");
$updateUsers = get_option(YUPDATES_USER_OPTION);
+
if(is_bool($updateUsers) && !$updateUsers) {
$updateUsers = array();
}
View
253 yupdates_options.php
@@ -45,16 +45,33 @@
if ( ! defined( 'WP_PLUGIN_DIR' ) )
define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
+define('YUPDATES_DEFAULT_TITLE_TEMPLATE', "posted '#blog_title' on their WordPress blog '#blog_name'");
function yupdates_plugin_options() {
- $ck = get_option('yupdates_consumer_key');
- $cks = get_option('yupdates_consumer_secret');
- $appid = get_option('yupdates_application_id');
- $bitly_key = get_option("yupdates_bitly_apiKey");
- $bitly_login = get_option("yupdates_bitly_login");
- $title_template = get_option('yupdates_title_template');
+ $session = yupdates_get_session();
+
+ // oauth keys
+ $consumer_key = $session->application->consumer_key;
+ $consumer_secret = $session->application->consumer_secret;
+ $appid = $session->application->application_id;
+
+ $has_application = ($consumer_key && $consumer_secret && $appid);
- if($title_template == "") $title_template = "posted '#blog_title' on their WordPress blog '#blog_name'";
+ // extAuth options
+ $extAuth_host = $_SERVER["HTTP_HOST"];
+ $extAuth_application_url = get_bloginfo('wpurl');
+ $extAuth_third_party = $extAuth_host;
+ $extAuth_scopes = 'yurw';
+ $extAuth_title = sprintf("WordPress plugin for %s", $extAuth_application_url);
+ $extAuth_description = sprintf("This application powers the updates plugin for your WordPress blog on %s", $extAuth_host);
+ $extAuth_return_to_url = sprintf("%s/plugins/yupdates_wordpress/yupdates_application.php", WP_CONTENT_URL);
+ $extAuth_favicon_url = sprintf("http://%s/favicon.ico", $extAuth_host);
+
+ // blog options
+ $title_template_opt = get_option('yupdates_title_template');
+ $title_template = ($title_template_opt) ? $title_template_opt : YUPDATES_DEFAULT_TITLE_TEMPLATE;
+ $bitly_key = get_option("yupdates_bitly_apiKey");
+ $bitly_login = get_option("yupdates_bitly_login");
?>
<style type="text/css">
.authTitle {
@@ -64,6 +81,7 @@ function yupdates_plugin_options() {
font-weight: bold;
}
</style>
+
<script type="text/javascript">
<!--
function switchDisplay(obj) {
@@ -72,123 +90,128 @@ function switchDisplay(obj) {
}
//-->
</script>
+
<div class="wrap">
-
- <a name="settings"></a>
-
- <form method="post" action="options.php">
-<?php
- if(function_exists("wp_nonce_field")) {
- wp_nonce_field('update-options');
- }
+ <a name="application_settings"></a>
+ <h3 class="authTitle">Create a Yahoo! Application</h3>
+<?php
+ if($has_application == FALSE):
?>
-
- <h3 class="authTitle">Yahoo! API Access Settings</h3>
-Enter your API Key, Shared Secret, and App ID from the Yahoo! Developer Network. (These are needed so your WordPress blog can read
-and write data on your behalf without revealing your Yahoo! ID and password).
- <table class="form-table">
- <tr valign="top">
- <th scope="row">Yahoo! API Key</th>
- <td><input type="text" size="64" name="yupdates_consumer_key" value="<?php echo $ck; ?>" /></td>
- </tr>
- <tr valign="top">
- <th scope="row">Yahoo! Shared Secret</th>
- <td><input type="text" size="64" name="yupdates_consumer_secret" value="<?php echo $cks; ?>" /></td>
- </tr>
- <tr valign="top">
- <th scope="row">Yahoo! Application ID</th>
- <td><input type="text" size="20" name="yupdates_application_id" value="<?php echo $appid; ?>" /></td>
- </tr>
- </table>
-
- <p><em>Don't know what these are, or how to get them?</em> <a onclick="switchDisplay('ydnhelp');" title="Switch the Menu">
- Show/hide instructions for how to get a Yahoo! API key.</a> (It's quick and free.)</p>
-
- <div id="ydnhelp" style="display:none; border: 1px solid #cccccc; margin: 10px; padding: 20px;">
+ <p>In order to get started, you'll need to create a new Yahoo! Application and later authorize it to access your Yahoo! account.
+ (This is needed so your WordPress blog can read and write updates on your behalf without you revealing your Yahoo! ID and password).</p>
+ <p>We've filled in the required fields below, click 'Create Application' below to submit.</p>
+ <div id="yupdates_app_setup">
+<? else: ?>
+ <p>Hey, it looks like you've already set up an application. Awesome! <a onclick="switchDisplay('yupdates_app_setup');" title="Switch the Menu">Here's the form</a> in case you need it again.</p>
+ <div id="yupdates_app_setup" style="display:none;">
+<? endif; ?>
+ <form method="post" action="http://soldsomeheat-vm0.corp.yahoo.com/projects/extAuth" id="yahoo_extAuthForm" name="yahoo_extAuthForm" target="yahoo_extAuthWindow">
+ <table class="form-table">
+ <tr valign="top">
+ <th scope="row">Yahoo! Application Name</th>
+ <td><input type="text" size="64" name="name" value="<?php echo $extAuth_title; ?>" /></td>
+ </tr>
+ <tr valign="top">
+ <th scope="row">Yahoo! Application Description</th>
+ <td><input type="text" size="64" name="description" value="<?php echo $extAuth_description; ?>" /></td>
+ </tr>
+ <tr valign="top">
+ <th scope="row">Favicon URL</th>
+ <td><input type="text" size="35" name="favicon" value="<?php echo $extAuth_favicon_url; ?>" /></td>
+ </tr>
+ </table>
+
+ <input type="hidden" name="third_party" value="<?php echo $extAuth_third_party; ?>"/>
+ <input type="hidden" name="return_to" value="<?php echo $extAuth_return_to_url; ?>"/>
+ <input type="hidden" name="scopes" value="<?php echo $extAuth_scopes; ?>"/>
+ <input type="hidden" name="application_url" value="<?php echo $extAuth_application_url ?>">
+ <input type="hidden" name="domain" value="<?php echo $extAuth_host ?>">
+
+ <p id="createApp" class="submit"><input type="submit" name="Submit" value="<?php _e('Create Application') ?>"/></p>
+ </form>
+ </div>
+ <hr noshade="noshade" />
- <h4 class="authTitle">How to get a Yahoo! API Key</h4>
- <ol>
- <li><p>Go to the <a href="https://developer.apps.yahoo.com/dashboard/createKey.html" target="_new">
- Yahoo! Developer Network</a> to register for an API key, and complete
- the form with the following information:</p>
- <ol>
- <li type="a"><strong>Application Name:</strong> Enter "<?php bloginfo('name'); ?>"</li>
- <li type="a"><strong>Kind of Application:</strong> Choose "Web-based"</li>
- <li type="a"><strong>Description:</strong> Describe your site here.</li>
- <li type="a"><strong>Application URL:</strong> Enter "<?php bloginfo('url'); ?>"</li>
- <li type="a"><strong>Favicon URL:</strong> Provide the URL to a GIF, JPG or PNG image (note: ICO is <em>not</em> supported)
- to serve as the favicon for your blog, if you have one. This will be used if you
- generate a Yahoo! Update with each blog post.
- <br />
- (e.g. <img src="<?php echo WP_CONTENT_URL; ?>/plugins/yupdates-wordpress/images/favicon.png" width="16" height="16" align="bottom" /> John posted "My First iPhone Experiences" from his blog: Mac User Fans. )
- </li>
- <li type="a"><strong>Application Domain:</strong> Enter "<?php echo sprintf("http://%s", $_SERVER['HTTP_HOST']) ?>"</li>
- </ol>
- </li>
+ <a name="settings"></a>
+ <h3 class="authTitle">Yahoo! Updates Settings</h3>
- <li><p class="authStep"><strong>Choose access to private user data.</strong></p>
- <p><img src="<?php echo WP_CONTENT_URL; ?>/plugins/yupdates-wordpress/images/auth_step2_scopes.png"></p>
- </li>
- <li><p class="authStep"><strong>Choose Read/Write access to Yahoo! Updates.</strong></td>
- <p><img src="<?php echo WP_CONTENT_URL; ?>/plugins/yupdates-wordpress/images/auth_step3_read-write.png"></p>
- </li>
- <li><p class="authStep"><strong>Agree to the Yahoo! Terms of Use, and click the "Get API Key" button.</strong></p>
- <p><img src="<?php echo WP_CONTENT_URL; ?>/plugins/yupdates-wordpress/images/auth_step4_apikey.png"></p>
- </li>
- <li><p class="authStep"><strong>If you haven't done so previously, verify
- ownership of your domain with Yahoo! by creating a file with the specified
- name and uploading that to the root directory of your domain.</strong></p>
- </li>
- <li><p class="authStep"><strong>Once you've successfully created your API
- key, copy your API key information from the success screen (sample below) to the Yahoo! API Access Settings below:</strong></p>
- <p><img src="<?php echo WP_CONTENT_URL; ?>/plugins/yupdates-wordpress/images/auth_step6_success.png" width="562" height="233"></p>
- </li>
- </ol>
-</div>
-
- <hr noshade="noshade" />
- <h3 class="authTitle">Yahoo! Updates Settings</h3>
- <table class="form-table">
- <tr valign="top">
- <th scope="row">Customize your Yahoo! Updates event display:</th>
- <td>
- <p>&lt;Your Yahoo! name&gt;<input type="text" size="50" name="yupdates_title_template" value="<?php echo $title_template; ?>" />
- <br />
- <small>Use the following tags in the display field above:</small>
- <br />
- <ul>
- <li><small>"#blog_title" = the title of your blog post</small></li>
- <li><small>"#blog_name" = the name of your blog (i.e. "<?php bloginfo('name'); ?>")</small></li>
- </ul></p>
- </td>
- </tr>
- </table>
+ <form method="post" action="options.php">
+ <table class="form-table">
+ <tr valign="top">
+ <th scope="row">Customize your Yahoo! Updates event display:</th>
+ <td>
+ &lt;Your Yahoo! name&gt;<input type="text" size="50" name="yupdates_title_template" value="<?php echo $title_template; ?>" />
+ <br />
+ <small>Use the following tags in the display field above:</small>
+ <br />
+ <ul>
+ <li><small>"#blog_title" = the title of your blog post</small></li>
+ <li><small>"#blog_name" = the name of your blog (i.e. "<?php bloginfo('name'); ?>")</small></li>
+ </ul>
+ </td>
+ </tr>
+ </table>
<hr noshade="noshade" />
+
<h3 class="authTitle">bit.ly Settings (optional)</h3>
- Configure your <a href="http://bit.ly/account/">bit.ly account</a>. This allows us to shorten the link
- back to your blog posts in the update, and allows you to track clicks in <a href="http://bit.ly/app/history/">your history</a>:
- <?php if($bitly_key && $bitly_login) { ?>
- <br/>To stop using bit.ly, just remove your credentials below and save.
- <?php } ?>
- <table class="form-table">
- <tr valign="top">
- <th scope="row">bit.ly API Key</th>
- <td><input type="text" size="64" name="yupdates_bitly_apiKey" value="<?php echo $bitly_key; ?>" /></td>
- </tr>
- <tr valign="top">
- <th scope="row">bit.ly Username</th>
- <td><input type="text" size="20" name="yupdates_bitly_login" value="<?php echo $bitly_login; ?>" /></td>
- </tr>
+ <p>Configure your <a href="http://bit.ly/account/">bit.ly account</a>. This allows us to shorten the link
+ back to your blog posts in the update, and allows you to track clicks in <a href="http://bit.ly/app/history/">your history</a>:</p>
+ <?php if($bitly_key && $bitly_login): ?>
+ <br/>To stop using bit.ly, just remove your credentials below and save.
+ <?php endif; ?>
+ <table class="form-table">
+ <tr valign="top">
+ <th scope="row">bit.ly API Key</th>
+ <td><input type="text" size="64" name="yupdates_bitly_apiKey" value="<?php echo $bitly_key; ?>" /></td>
+ </tr>
+ <tr valign="top">
+ <th scope="row">bit.ly Username</th>
+ <td><input type="text" size="20" name="yupdates_bitly_login" value="<?php echo $bitly_login; ?>" /></td>
+ </tr>
</table>
-
- <input type="hidden" name="action" value="update" />
- <input type="hidden" name="page_options" value="yupdates_consumer_key,yupdates_consumer_secret,yupdates_application_id,yupdates_title_template,yupdates_bitly_apiKey,yupdates_bitly_login" />
- <p class="submit">
- <input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" />
- </p>
- </form>
+
+ <input type="hidden" id="yupdates_consumer_key" name="yupdates_consumer_key" value="<?php echo $consumer_key; ?>"/>
+ <input type="hidden" id="yupdates_consumer_secret" name="yupdates_consumer_secret" value="<?php echo $consumer_secret; ?>"/>
+ <input type="hidden" id="yupdates_application_id" name="yupdates_application_id" value="<?php echo $appid; ?>"/>
+
+ <input type="hidden" name="action" value="update" />
+ <input type="hidden" name="page_options" value="yupdates_consumer_key,yupdates_consumer_secret,yupdates_application_id,yupdates_title_template,yupdates_bitly_apiKey,yupdates_bitly_login" />
+ <?php if(function_exists("wp_nonce_field")) wp_nonce_field('update-options'); ?>
+
+ <p class="submit"><input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" class="button-primary"/></p>
+ </form>
</div>
+<script type="text/javascript">
+<!--
+function yupdates_setCredentials(consumer_key, consumer_secret, application_id) {
+ _gel('yupdates_consumer_key').value = consumer_key;
+ _gel('yupdates_consumer_secret').value = consumer_secret;
+ _gel('yupdates_application_id').value = application_id;
+
+ var updated = document.createElement('div');
+ updated.className = "updated fade";
+
+ if(consumer_key && consumer_secret && application_id) {
+ updated.innerHTML = "<p><strong>Thanks! Click '<?php _e('Save Changes'); ?>' below to continue.</strong></p>";
+ } else {
+ updated.innerHTML = "<p><strong>Houston, we have a problem. Missing required keys from extAuth response.";
+ updated.innerHTML+= "consumer_key = '"+consumer_key+"', consumer_secret = '"+consumer_secret+"', application_id = '"+application_id+"'</strong></p>";
+ }
+
+ _gel('createApp').appendChild(updated);
+}
+
+function _gel(id) {
+ return document.getElementById(id);
+}
+
+function switchDisplay(obj) {
+ var el = document.getElementById(obj);
+ el.style.display = (el.style.display != "none") ? 'none' : '';
+}
+//-->
+</script>
<?
}
?>
View
5 yupdates_sessionstore.php
@@ -32,7 +32,7 @@
* THE SOFTWARE.
**/
- class WordPressSessionStore {
+class WordPressSessionStore {
var $optionName = NULL;
var $option = NULL;
var $consumerKey = "";
@@ -59,8 +59,9 @@ function validateConsumerKey()
{
if($this->consumerKey != $this->option["ck"]) {
$this->resetOption();
- return FALSE;
+ return false;
}
+
return true;
}
View
275 yupdates_utils.php
@@ -30,154 +30,191 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
- **/
-
- $yupdates_session_store = NULL;
-
- function yupdates_has_session($session) {
- if($session->store->hasAccessToken())
- {
- $access_token = $session->store->fetchAccessToken();
-
- if(!$access_token->key || !$access_token->secret) {
- return FALSE;
- }
-
- $access_token = $session->application->getAccessToken($access_token);
- $session->store->storeAccessToken($access_token);
+ **/
+$yupdates_session_store = NULL;
+
+function yupdates_has_session($session) {
+ if($session->store->hasAccessToken())
+ {
+ $access_token = $session->store->fetchAccessToken();
+
+ if(!$access_token->key || !$access_token->secret) {
+ return false;
+ }
+
+ // refresh the token.
+ $access_token = yupdates_get_accessToken($session, $access_token);
+
+ $token = $session->application->token;
+
+ return ($token && $token->key);
+ }
+ else if($session->store->hasRequestToken())
+ {
+ $request_token = yupdates_get_requestToken($session);
+ // $request_token = $session->store->fetchRequestToken();
+
+ if(!$request_token->key || !$request_token->secret) {
+ $session->store->clearRequestToken();
+ $token = yupdates_get_requestToken($session);
- return ($session->application->token && $session->application->token->key);
- }
- else if($session->store->hasRequestToken())
- {
- yupdates_get_requestToken($session);
- $request_token = $session->store->fetchRequestToken();
+ return false;
+ }
+
+ if(array_key_exists("oauth_token", $_REQUEST) && array_key_exists("oauth_verifier", $_REQUEST)) {
+ $oauth_verifier = $_REQUEST["oauth_verifier"];
+ $access_token = $session->application->getAccessToken($request_token, $oauth_verifier);
- if(!$request_token->key || !$request_token->secret) {
+ if($access_token->key && $access_token->secret) {
$session->store->clearRequestToken();
- yupdates_get_requestToken($session);
- return FALSE;
- }
-
- if(array_key_exists("oauth_token", $_REQUEST) && array_key_exists("oauth_verifier", $_REQUEST)) {
- $oauth_verifier = $_REQUEST["oauth_verifier"];
- $access_token = $session->application->getAccessToken($request_token, $oauth_verifier);
+ $session->store->storeAccessToken($access_token);
- if($access_token->key && $access_token->secret) {
- $session->store->clearRequestToken();
- $session->store->storeAccessToken($access_token);
- return TRUE;
- }
+ return TRUE;
}
-
- return FALSE;
- }
- else
- {
- yupdates_get_requestToken($session);
-
- return FALSE;
}
+
+ return false;
}
+ else if($session->application->consumer_key && $session->application->consumer_secret)
+ {
+ $token = yupdates_get_requestToken($session);
+
+ return false;
+ }
- function yupdates_get_requestToken($session) {
- $callback_params = array("auth_popup"=>"true");
- $callback = yupdates_get_oauthCallback($callback_params);
- $request_token = $session->application->getRequestToken($callback);
- $session->store->storeRequestToken($request_token);
- }
+ return false;
+}
+
+function yupdates_get_requestToken($session) {
+ $callback_params = array("auth_popup"=>"true");
+ $callback = yupdates_get_oauthCallback($callback_params);
- function yupdates_clear_session() {
- global $current_user;
- get_currentuserinfo();
-
- $user = $current_user->user_login;
- $session_store = yupdates_get_sessionStore($user);
-
- $session_store->clearRequestToken();
- $session_store->clearAccessToken();
-
- // todo: infinite looping
- header(sprintf("Location: %s", $_SERVER["REQUEST_URI"]));
- exit();
- }
+ $request_token = $session->application->getRequestToken($callback);
+ $session->store->storeRequestToken($request_token);
- function yupdates_get_oauthCallback($parameters=array()) {
- return sprintf("http://%s%s&%s",$_SERVER["HTTP_HOST"], $_SERVER["REQUEST_URI"], http_build_query($parameters));
- }
+ return $request_token;
+}
+
+function yupdates_get_accessToken($session, $access_token=NULL) {
+ $access_token = $session->application->getAccessToken($access_token);
+ $session->store->storeAccessToken($access_token);
- function yupdates_get_currentUserSessionStore() {
- if(!$yupdates_session_store) {
- global $current_user;
- get_currentuserinfo();
-
- $user = $current_user->user_login;
- $yupdates_session_store = yupdates_get_sessionStore($user);
- }
- return $yupdates_session_store;
- }
+ return $access_token;
+}
+
+function yupdates_clear_session() {
+ global $current_user;
+ get_currentuserinfo();
- function yupdates_get_sessionStore($user) {
- return new WordPressSessionStore($user, get_option("yupdates_consumer_key"));
- }
+ $user = $current_user->user_login;
+ $session_store = yupdates_get_sessionStore($user);
- function yupdates_get_application() {
- // fetch application keys from user options
- $ck = get_option("yupdates_consumer_key");
- $cks = get_option("yupdates_consumer_secret");
- $appid = get_option("yupdates_application_id");
-
- return new YahooOAuthApplication($ck, $cks, $appid);
- }
+ $session_store->clearRequestToken();
+ $session_store->clearAccessToken();
- function yupdates_get_session($user=NULL) {
- // create session object with application, token store
- $session = new stdclass();
- $session->application = yupdates_get_application();
- $session->store = (is_null($user)) ? yupdates_get_currentUserSessionStore() : yupdates_get_sessionStore($user);
-
- $session->hasSession = yupdates_has_session($session);
-
- return $session;
+ /* delete keys
+ go to /wp-admin/options.php to update the array with any yupdates_* keys.
+ $options = array(
+ 'yupdates_application_id','yupdates_bitly_apiKey','yupdates_bitly_login','yupdates_consumer_key',
+ 'yupdates_consumer_secret','yupdates_title_template','yupdates_tokens_','yupdates_tokens_admin',
+ 'yupdates_tokens_admin_dj0yJmk9WGhERFFkSHMzWEZxJmQ9WVdrOVJXVlhXVE','yupdates_tokens__dj0yJmk9WGhERFFkSHMzWEZxJmQ9WVdrOVJXVlhXVEZWTm5',
+ 'yupdates_updates_widget_users','yupdates_update_title','yupdates_update_title_template','yupdates_widget_count'
+ );
+ foreach($options as $name) {
+ delete_option($name);
}
+ */
- function yupdates_get_bitly_options() {
- $options = new stdclass();
- $options->apiKey = get_option("yupdates_bitly_apiKey");
- $options->login = get_option("yupdates_bitly_login");
+ // todo: infinite looping
+ header(sprintf("Location: %s", $_SERVER["HTTP_HOST"]));
+ exit();
+}
+
+function yupdates_get_oauthCallback($parameters=array()) {
+ return sprintf("http://%s%s&%s",$_SERVER["HTTP_HOST"], $_SERVER["REQUEST_URI"], http_build_query($parameters));
+}
+
+function yupdates_get_currentUserSessionStore() {
+ if(!$yupdates_session_store) {
+ global $current_user;
+ get_currentuserinfo();
- return $options;
+ $user = $current_user->user_login;
+ $yupdates_session_store = yupdates_get_sessionStore($user);
}
+ return $yupdates_session_store;
+}
+
+function yupdates_get_sessionStore($user) {
+ $consumer_key = get_option("yupdates_consumer_key");
+ return new WordPressSessionStore($user, $consumer_key);
+}
+
+function yupdates_get_application() {
+ // fetch application keys from user options
+ $consumer_key = get_option("yupdates_consumer_key");
+ $consumer_secret = get_option("yupdates_consumer_secret");
+ $appid = get_option("yupdates_application_id");
+
+ return new YahooOAuthApplication($consumer_key, $consumer_secret, $appid);
+}
+
+function yupdates_get_session($user=NULL) {
+ // create session object with application, token store
+ $session = new stdclass();
+ $session->application = yupdates_get_application();
+ $session->store = (is_null($user)) ? yupdates_get_currentUserSessionStore() : yupdates_get_sessionStore($user);
+ $session->user = $user;
- function yupdates_bitly_shorten($permalink, $apiKey, $login) {
- $params = array();
- $params["apiKey"] = $apiKey;
- $params["login"] = $login;
- $params["longUrl"] = $permalink;
- $params["version"] = "2.0.1";
- $params["history"] = "1";
+ // pass the session off to check for tokens in the store.
+ // updates tokens as needed and returns true/false if a session exists
+ // (if access token exists)
+ $session->hasSession = yupdates_has_session($session);
+
+ return $session;
+}
- $base_url = "http://api.bit.ly/shorten";
+function yupdates_get_bitly_options() {
+ $options = new stdclass();
+ $options->apiKey = get_option("yupdates_bitly_apiKey");
+ $options->login = get_option("yupdates_bitly_login");
+
+ return $options;
+}
- $http = YahooCurl::fetch($base_url, $params);
- $rsp = $http["response_body"];
- $data = json_decode($rsp);
+function yupdates_bitly_shorten($permalink, $apiKey, $login) {
+ $base_url = "http://api.bit.ly/shorten";
+ $params = array(
+ 'apiKey' => $apiKey,
+ 'login' => $login,
+ 'longUrl' => $permalink,
+ 'version' => '2.0.1',
+ 'history' => '1'
+ );
+
+ $http = YahooCurl::fetch($base_url, $params);
+
+ $rsp = $http["response_body"];
+ $data = json_decode($rsp);
- if($data && $data->statusCode == "OK" && $data->results) {
- $results = get_object_vars($data->results);
- $site = $results[$permalink];
+ if($data && $data->statusCode == "OK" && isset($data->results)) {
+ $results = get_object_vars($data->results);
+ $site = $results[$permalink];
+
+ if($site && isset($site->shortUrl)) {
$shortUrl = $site->shortUrl;
return $shortUrl;
- } else {
- return $permalink;
}
}
+
+ return $permalink;
+}
- function yupdates_close_popup() {
+function yupdates_close_popup() {
?>
<script type="text/javascript">
- window.close();
+window.close();
</script>
<?php
- }
+}
?>

0 comments on commit 3ea505c

Please sign in to comment.
Something went wrong with that request. Please try again.