Skip to content
Browse files

final update

  • Loading branch information...
1 parent 8adbc94 commit e86aeedcb0ca3b2278a992fd1360a7b6b89fe420 @zagraves zagraves committed Feb 22, 2010
Showing with 59 additions and 61 deletions.
  1. +19 −47 yupdates_hooks.php
  2. +12 −4 yupdates_options.php
  3. +28 −10 yupdates_utils.php
View
66 yupdates_hooks.php
@@ -46,54 +46,26 @@ function yupdates_edit_post($postid)
function yupdates_publish_post($postid)
{
- $session = yupdates_get_session();
+ $post = get_post($postid);
+ $permalink = get_permalink($postid);
- if($session->hasSession) {
- $post = get_post($postid);
- $permalink = get_permalink($postid);
-
- $bitly_options = yupdates_get_bitly_options();
- if($bitly_options->apiKey && $bitly_options->login) {
- $bitly_permalink = yupdates_bitly_shorten($permalink, $bitly_options->apiKey, $bitly_options->login);
- $permalink = $bitly_permalink;
- }
-
- $title_template = get_option("yupdates_title_template");
- $title_patterns = array('/%blog_title%/', '/%blog_name%/');
- $title_replacements = array($post->post_title, get_bloginfo("name"));
-
- // $rsp = $session->application->insertUpdate(null, $update->description, $update->title, $update->link);
-
- $update = new stdclass();
- $update->title = preg_replace($title_patterns, $title_replacements, $title_template);
- $update->description = substr($post->post_excerpt, 0, 256);
- $update->link = $permalink;
-
- // do this temporarily until we have the PHP5 SDK using YQL exclusively.
- $update->pubDate = time();
- $update->guid = $session->application->token->yahoo_guid();
- $update->source = 'APP.'.$session->application->application_id;
-
- $suid = sha1(json_encode($update));
-
- $query = "INSERT INTO social.updates (guid, title, description, link, pubDate, source, suid) VALUES (\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\");";
- $query = sprintf($query,
- $update->guid,
- $update->title,
- $update->description,
- $update->link,
- $update->pubDate,
- $update->source,
- $suid
- );
-
- $rsp = $session->application->yql($query, array(), 'PUT');
-
- if(isset($rsp->error)) {
- error_log("Failed to generate Yahoo! Update for blog post ({$postid}) ".json_encode($update));
- }
-
- return $suid;
+ $bitly_options = yupdates_get_bitly_options();
+ if($bitly_options->apiKey && $bitly_options->login) {
+ $bitly_permalink = yupdates_bitly_shorten($permalink, $bitly_options->apiKey, $bitly_options->login);
+ $permalink = $bitly_permalink;
}
+
+ $title_template = get_option("yupdates_title_template");
+ $title_patterns = array('/%blog_title%/', '/%blog_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_excerpt, 0, 256);
+ $update->link = $permalink;
+
+ $suid = yupdates_insertUpdate($update);
+
+ return $suid;
}
?>
View
16 yupdates_options.php
@@ -42,7 +42,7 @@
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%'");
-define('YUPDATES_EXTAUTH_HOST', "http://soldsomeheat-vm0.corp.yahoo.com/projects/extAuth");
+define('YUPDATES_EXTAUTH_HOST', "http://developer.yahoo.com/projects/createconsumerkey");
define('YUPDATES_EXTAUTH_DEFAULT_SCOPES', "yurw");
function yupdates_plugin_options() {
@@ -86,7 +86,7 @@ function yupdates_plugin_options() {
<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 your blog with Yahoo! Updates, awesome! <a onclick="switchDisplay('yupdates_app_setup');" title="Switch the Menu">Here's the form</a> if you'd like to update the application.</p>
+ <p>Hey, it looks like you've already set up your blog with Yahoo! Updates, awesome! <a onclick="_switchDisplay('yupdates_app_setup');" title="Switch the Menu">Here's the form</a> if you'd like to update the application.</p>
<div id="yupdates_app_setup" style="display:none;">
<? endif; ?>
@@ -164,7 +164,7 @@ function yupdates_plugin_options() {
<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>
+ <p class="submit"><input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" class="button-primary" click="javascript:yupdates_submitAuthForm()"/></p>
</form>
</div>
<script type="text/javascript">
@@ -187,11 +187,19 @@ function yupdates_setCredentials(consumer_key, consumer_secret, application_id)
_gel('createApp').appendChild(updated);
}
+function yupdates_submitAuthForm() {
+ var form = _gel('yahoo_extAuthForm');
+ var formTarget = form.getAttribute('target');
+
+ window.open('', formTarget, 'status=0,toolbar=0,location=0,menubar=0,width=545,height=650');
+ document.yahoo_extAuthForm.submit();
+}
+
function _gel(id) {
return document.getElementById(id);
}
-function switchDisplay(obj) {
+function _switchDisplay(obj) {
var el = document.getElementById(obj);
el.style.display = (el.style.display != "none") ? 'none' : '';
}
View
38 yupdates_utils.php
@@ -196,25 +196,43 @@ function yupdates_bitly_shorten($permalink, $apiKey, $login)
$yql = new YahooYQLQuery();
$rsp = $yql->execute($query);
- $bitly = $rsp->query->results->bitly;
-
- if($bitly && $bitly->statusCode == 'OK' && isset($bitly->results)) {
- $results = $bitly->results->nodeKeyVal;
+ if(isset($rsp->query) && isset($rsp->query->results)) {
+ $results = $rsp->query->results;
+
+ $bitly = (isset($results->bitly)) ? $results->bitly : false;
- if($results && isset($results->shortUrl)) {
- return $results->shortUrl;
+ if($bitly && isset($bitly->results) && $bitly->statusCode == 'OK') {
+ $results = $bitly->results->nodeKeyVal;
+
+ if($results && isset($results->shortUrl)) {
+ return $results->shortUrl;
+ }
}
}
-
+
return $permalink;
}
+function yupdates_insertUpdate($update)
+{
+ $session = yupdates_get_session();
+
+ if($update && $session->hasSession) {
+ $suid = null;
+ $results = $session->application->insertUpdate(null, $update->description, $update->title, $update->link, $suid);
+
+ return ($results) ? $suid : false;
+ }
+
+ return false;
+}
+
function yupdates_close_popup()
{
?>
-<script type="text/javascript">
-window.close();
-</script>
+ <script type="text/javascript">
+ window.close();
+ </script>
<?php
}
?>

0 comments on commit e86aeed

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