Permalink
Browse files

minor optimizations

  • Loading branch information...
zagraves committed Sep 23, 2009
1 parent ee820a7 commit 31c43b5e790a9f9bdea5aa23115d29adf6460c53
Showing with 186 additions and 191 deletions.
  1. +33 −42 yupdates.php
  2. +8 −18 yupdates_hooks.php
  3. +42 −54 yupdates_menu.php
  4. +4 −4 yupdates_options.php
  5. +56 −54 yupdates_sessionstore.php
  6. +43 −19 yupdates_utils.php
View
@@ -42,12 +42,15 @@
?>
<?php
define("YUPDATES_WIDGET_ENABLED", true);
-
- require_once("lib/OAuth/OAuth.php");
- require_once("lib/Yahoo/YahooOAuthApplication.class.php");
-
- require_once("yupdates_sessionstore.php");
- require_once("yupdates_utils.php");
+
+ 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");
@@ -63,30 +66,15 @@
add_action("delete_post", "yupdates_delete_post");
add_action("edit_post", "yupdates_edit_post");
add_action("publish_post", "yupdates_publish_post");
-
- $yupdates_session_store = NULL;
?>
<?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");
+ 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_store = yupdates_get_sessionStore();
-
- //
- $app_info = yupdatesdb_getApplicationInfo();
-
- // fetch application keys from user options
- $ck = get_option("yupdates_consumer_key");
- $cks = get_option("yupdates_consumer_secret");
- $appid = get_option("yupdates_application_id");
-
- //
- $application = new YahooOAuthApplication($ck, $cks, $appid);
- $application_has_session = yupdates_has_session($application, $session_store);
+
+ function yupdates_auth_init() {
+ $session = yupdates_get_session();
// handle directions from auth flow
if(array_key_exists("yupdates_clearauthorization", $_REQUEST))
@@ -98,27 +86,30 @@ function yupdates_auth_init() {
yupdates_close_popup();
}
- //
- if(!yupdatesdb_hasApplicationInfo() && stripos($_SERVER["REQUEST_URI"], "options-general.php?page=yupdates_plugin_options") === FALSE)
+ // show warnings
+ if(!yupdatesdb_hasApplicationInfo()
+ && stripos($_SERVER["REQUEST_URI"], PLUGIN_OPTIONS_URI) === FALSE)
{
- 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></div>
-HTML;
-
- }
add_action("admin_notices", "yupdates_appinfo_warning");
}
- else if(yupdatesdb_hasApplicationInfo() && stripos($_SERVER["REQUEST_URI"], "users.php?page=yupdates_menu") === FALSE)
+ else if( yupdatesdb_hasApplicationInfo()
+ && stripos($_SERVER["REQUEST_URI"], USER_MENU_URI) === FALSE
+ && !$session->hasSession )
+
{
- if(!$application_has_session) {
- function yupdates_authorization_warning() {
- echo <<<HTML
+ add_action("admin_notices", "yupdates_authorization_warning");
+ }
+ }
+
+ 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></div>
+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></div>
HTML;
- }
- add_action("admin_notices", "yupdates_authorization_warning");
- }
- }
}
?>
View
@@ -33,41 +33,31 @@
**/
function yupdates_delete_post($postid) {
-
+ // TODO
}
function yupdates_edit_post($postid) {
-
+ // TODO
}
function yupdates_publish_post($postid) {
- $session_store = yupdates_get_sessionStore();
-
- $app_info = yupdatesdb_getApplicationInfo();
-
- // fetch application keys from user options
- $ck = get_option("yupdates_consumer_key");
- $cks = get_option("yupdates_consumer_secret");
- $appid = get_option("yupdates_application_id");
- $title_template = get_option("yupdates_title_template");
-
- $application = new YahooOAuthApplication($ck, $cks, $appid);
- $application_has_session = yupdates_has_session($application, $session_store);
+ $session = yupdates_get_session();
- if($application_has_session) {
+ if($session->hasSession) {
$post = get_post($postid);
+ $title_template = get_option("yupdates_title_template");
$title_patterns = array('/#blog_title/', '/#blog_name/');
- $title_replacements = array($post->post_title,get_bloginfo("name"));
+ $title_replacements = array($post->post_title, get_bloginfo("name"));
$update = new stdclass();
$update->title = preg_replace($title_patterns, $title_replacements, $title_template);
$update->description = substr($post->post_content, 0, 256);
$update->link = get_bloginfo("url");
- $response = $application->insertUpdate(null, $update->description, $update->title, $update->link);
+ $response = $session->application->insertUpdate(null, $update->description, $update->title, $update->link);
- // todo: better error handling
+ // todo: do better error handling
if(is_null($response)) {
error_log("Failed to generate Yahoo! Update for blog post.");
}
View
@@ -32,71 +32,59 @@
* THE SOFTWARE.
**/
-require_once("yosdk_lib5/OAuth/OAuth.php");
-require_once("yosdk_lib5/Yahoo/YahooOAuthApplication.class.php");
-require_once("WordPressSessionStore.php");
+require_once("lib/OAuth/OAuth.php");
+require_once("lib/Yahoo/YahooOAuthApplication.class.php");
function yupdates_menu() {
- global $current_user;
- get_currentuserinfo();
-
- if(array_key_exists("yupdates_updateusers", $_REQUEST)) {
- if($_REQUEST["yupdates_include_updates"]) {
- yupdatesdb_addUpdatesUser($current_user->user_login);
- }
- else {
- yupdatesdb_removeUpdatesUser($current_user->user_login);
- }
- }
-
- // fetch application keys from user options
- $ck = get_option("yupdates_consumer_key");
- $cks = get_option("yupdates_consumer_secret");
- $appid = get_option("yupdates_application_id");
+ global $current_user;
+ get_currentuserinfo();
- $session_store = yupdates_get_sessionStore();
+ if(array_key_exists("yupdates_updateusers", $_REQUEST)) {
+ if($_REQUEST["yupdates_include_updates"]) {
+ yupdatesdb_addUpdatesUser($current_user->user_login);
+ }
+ else {
+ yupdatesdb_removeUpdatesUser($current_user->user_login);
+ }
+ }
- $application = new YahooOAuthApplication($ck, $cks, $appid);
- $application_has_session = yupdates_has_session($application, $session_store);
-
- $session = NULL;
- $user = NULL;
- $sharingUpdates = false;
+ $session = yupdates_get_session();
+ $sharingUpdates = false;
- if($application_has_session == false) {
- $request_token = $session_store->fetchRequestToken();
- $auth_url = ($request_token && $request_token->key) ? $application->getAuthorizationUrl($request_token) : "";
- } else {
- $sharingUpdates = yupdatesdb_isUpdatesUser($current_user->user_login);
- }
+ if($session->hasSession == false) {
+ $request_token = $session->store->fetchRequestToken();
+ $auth_url = ($request_token && $request_token->key) ? $session->application->getAuthorizationUrl($request_token) : "";
+ } else {
+ $sharingUpdates = yupdatesdb_isUpdatesUser($current_user->user_login);
+ }
?>
<div class="wrap">
<h2>Yahoo! Updates</h2>
-<?php if(!is_null($application) && $application_has_session) { ?>
-
-You have authorized the Yahoo! Updates plugin.
+<?php
+ if($session->application && $session->hasSession) {
+ echo <<<HTML
+You have already authorized the Yahoo! Updates plugin.
<form method="post">
-
-<?php if(YUPDATES_WIDGET_ENABLED) { ?>
-
- <p><label for="yupdates-include-updates">Include updates in widget? <input id="yupdates-include-updates" type="checkbox" name="yupdates_include_updates"<?php echo $sharingUpdates ? " checked='checked'" : "" ?>></label></p>
- <input type="submit" name="yupdates_updateusers" value="Update">
-
-<?php } ?>
-
- <input type="submit" name="yupdates_clearauthorization" value="Unauthorize">
-</form>
-
-<?php } else { ?>
+HTML;
+
+ if(YUPDATES_WIDGET_ENABLED) {
+ $checked = $sharingUpdates ? "checked='checked'" : "";
+ echo <<<HTML
+<p><label for="yupdates-include-updates">Include updates in widget? <input id="yupdates-include-updates" type="checkbox" name="yupdates_include_updates" $checked></label></p>
+<input type="submit" name="yupdates_updateusers" value="Update">
+HTML;
+ }
+ echo <<<HTML
+<input type="submit" name="yupdates_clearauthorization" value="Unauthorize"></form>
+HTML;
+ } else {
+ echo <<<HTML
You have not yet authorized the Yahoo! Updates plugin.
-<p>
- <input type="hidden" name="yupdates_authorize" value="true">
- <input type="submit" value="Authorize" onclick="_yupdates_authorize();">
-</p>
-
-<?php } ?>
-
+<p><input type="hidden" name="yupdates_authorize" value="true"><input type="submit" value="Authorize" onclick="_yupdates_authorize();"></p>
+HTML;
+ }
+?>
</div>
<script type="text/javascript">
View
@@ -33,11 +33,11 @@
**/
function yupdates_plugin_options() {
- $ck = get_option('yupdates_consumer_key');
- $cks = get_option('yupdates_consumer_secret');
- $appid = get_option('yupdates_application_id');
+ $ck = get_option('yupdates_consumer_key');
+ $cks = get_option('yupdates_consumer_secret');
+ $appid = get_option('yupdates_application_id');
$title_template = get_option('yupdates_title_template');
-
+
if($title_template == "") $title_template = "posted '#blog_title' on their WordPress blog '#blog_name'";
?>
<div class="wrap">
Oops, something went wrong.

0 comments on commit 31c43b5

Please sign in to comment.