function wp_ozh_yourls_url() { global $id; $short = esc_url(apply_filters('ozh_yourls_shorturl', wp_ozh_yourls_geturl($id))); if ($short) { $rel = esc_attr(apply_filters('ozh_yourls_shorturl_rel', 'nofollow alternate shorturl shortlink')); $title = esc_attr(apply_filters('ozh_yourls_shorturl_title', 'Short URL')); $anchor = esc_html(apply_filters('ozh_yourls_shorturl_anchor', $short)); echo "<a href=\"{$short}\" rel=\"{$rel}\" title=\"{$title}\">{$anchor}</a>"; } }
function wp_ozh_yourls_raw_url($echo = false) { global $id; $short = wp_ozh_yourls_geturl($id); if ($short) { if ($echo) { echo $short; } return $short; } }
function wp_ozh_yourls_raw_url($echo = false) { global $id; $short = apply_filters('ozh_yourls_shorturl', wp_ozh_yourls_geturl($id)); if ($short) { if ($echo) { echo $short; } return $short; } }
function wp_ozh_yourls_reset_url() { check_ajax_referer('yourls'); $post_id = (int) $_POST['yourls_post_id']; $old_shorturl = $_POST['yourls_shorturl']; delete_post_meta($post_id, 'yourls_shorturl'); $shorturl = wp_ozh_yourls_geturl($post_id); if ($shorturl) { $result = "New short URL generated: <a href='{$shorturl}'>{$shorturl}</a>"; update_post_meta($post_id, 'yourls_shorturl', $shorturl); } else { $result = "Bleh. Could not generate short URL. Maybe the URL shortening service is down? Please try again later!"; } $x = new WP_AJAX_Response(array('data' => $result, 'supplemental' => array('old_shorturl' => $old_shorturl, 'shorturl' => $shorturl))); $x->send(); die('1'); }
function wp_ozh_yourls_drawbox($post) { $type = $post->post_type; $status = $post->post_status; $id = $post->ID; $title = $post->post_title; if ($type != 'post' && $type != 'page') { return; } // Not sure this can actually happen since add_meta_box() should take care of this. Just in case. // Too early, young Padawan if ($status != 'publish') { echo '<p>When you publish this post, you will be able here to (re)promote it via Twitter.</p> <p>Depending on <a href="options-general.php?page=ozh_yourls">configuration</a>, this also happens automagically when you press "Publish" of course :)</p>'; return; } $shorturl = wp_ozh_yourls_geturl($id); // Bummer, could not generate a short URL if (!shorturl) { echo '<p>Bleh. The URL shortening service you configured could not be reached as of now. This might be a temporary problem, please try again later!</p>'; return; } global $wp_ozh_yourls; $action = 'Tweet this'; $promote = "Promote this {$type}"; $tweeted = get_post_meta($id, 'yourls_tweeted', true); $account = $wp_ozh_yourls['twitter_login']; wp_nonce_field('yourls', '_ajax_yourls', false); echo ' <input type="hidden" id="yourls_post_id" value="' . $id . '" /> <input type="hidden" id="yourls_shorturl" value="' . $shorturl . '" /> <input type="hidden" id="yourls_twitter_account" value="' . $account . '" />'; echo '<p><strong>Short URL</strong></p>'; echo '<div id="yourls-shorturl">'; echo "<p>This {$type}'s short URL: <strong><a href='{$shorturl}'>{$shorturl}</a></strong></p>\n\t<p>You can click Reset to generate another short URL if you picked another URL shortening service in the <a href='options-general.php?page=ozh_yourls'>plugin options</a></p>"; echo '<p style="text-align:right"><input class="button" id="yourls_reset" type="submit" value="Reset short URL" /></p>'; echo '</div>'; echo '<p><strong>' . $promote . ' on <a href="http://twitter.com/' . $account . '">@' . $account . '</a>: </strong></p> <div id="yourls-promote">'; if ($tweeted) { $action = 'Retweet this'; $promote = "Promote this {$type} again"; echo '<p><em>Note:</em> this post has already been tweeted. Not that there\'s something wrong to promote it again, of course :)</p>'; } echo '<p><textarea id="yourls_tweet" rows="1" style="width:100%">' . wp_ozh_yourls_maketweet($shorturl, $title) . '</textarea></p> <p style="text-align:right"><input class="button" id="yourls_promote" type="submit" value="' . $action . '" /></p> </div>'; ?> <script type="text/javascript"> /* <![CDATA[ */ (function($){ var yourls = { // Send a tweet send: function() { var post = {}; post['yourls_tweet'] = $('#yourls_tweet').val(); post['yourls_post_id'] = $('#yourls_post_id').val(); post['yourls_twitter_account'] = $('#yourls_twitter_account').val(); post['action'] = 'yourls-promote'; post['_ajax_nonce'] = $('#_ajax_yourls').val(); $('#yourls-promote').html('<p>Please wait...</p>'); $.ajax({ type : 'POST', url : '<?php echo admin_url('admin-ajax.php'); ?> ', data : post, success : function(x) { yourls.success(x, 'yourls-promote'); }, error : function(r) { yourls.error(r, 'yourls-promote'); } }); }, // Reset short URL reset: function() { var post = {}; post['yourls_post_id'] = $('#yourls_post_id').val(); post['yourls_shorturl'] = $('#yourls_shorturl').val(); post['action'] = 'yourls-reset'; post['_ajax_nonce'] = $('#_ajax_yourls').val(); $('#yourls-shorturl').html('<p>Please wait...</p>'); $.ajax({ type : 'POST', url : '<?php echo admin_url('admin-ajax.php'); ?> ', data : post, success : function(x) { yourls.success(x, 'yourls-shorturl'); yourls.update(x); }, error : function(r) { yourls.error(r, 'yourls-shorturl'); } }); }, // Update short URL in the tweet textarea update: function(x) { var r = wpAjax.parseAjaxResponse(x); r = r.responses[0]; var oldurl = r.supplemental.old_shorturl; var newurl = r.supplemental.shorturl; var bg = jQuery('#yourls_tweet').css('backgroundColor'); if (bg == 'transparent') {bg = '#fff';} $('#yourls_tweet') .val( $('#yourls_tweet').val().replace(oldurl, newurl) ) .animate({'backgroundColor':'#ff8'}, 500, function(){ jQuery('#yourls_tweet').animate({'backgroundColor':bg}, 500) }); }, // Ajax: success success : function(x, div) { if ( typeof(x) == 'string' ) { this.error({'responseText': x}, div); return; } var r = wpAjax.parseAjaxResponse(x); if ( r.errors ) this.error({'responseText': wpAjax.broken}, div); r = r.responses[0]; $('#'+div).html('<p>'+r.data+'</p>'); }, // Ajax: failure error : function(r, div) { var er = r.statusText; if ( r.responseText ) er = r.responseText.replace( /<.[^<>]*?>/g, '' ); if ( er ) $('#'+div).html('<p>Error during Ajax request: '+er+'</p>'); } }; $(document).ready(function(){ $('#yourls_promote').click(function(e) { yourls.send(); e.preventDefault(); }); $('#yourls_reset').click(function(e) { yourls.reset(); e.preventDefault(); }); $('#edit-slug-box').append('<span id="yourls-shorturl-button"><a onclick="prompt(\'Short URL:\', \'<?php echo $shorturl; ?> \'); return false;" class="button" href="#">Get Short URL</a></span>'); $('#yourls-shorturl-button a').css('border-color','#bbf'); }) })(jQuery); /* ]]> */ </script> <?php }
function wordbooker_short_url($post_id) { # This provides short_url responses by checking for various functions and using $wordbooker_settings = wordbooker_options(); if (isset($wordbooker_settings["wordbooker_disable_shorties"])) { $url = get_permalink($post_id); return $url; } $url = get_permalink($post_id); $url2 = $url; if (function_exists(fts_show_shorturl)) { $post = get_post($post_id); $url = fts_show_shorturl($post, $output = false); } if (function_exists(wp_ozh_yourls_geturl)) { $url = wp_ozh_yourls_geturl($post_id); } if ("!!!" . $url . "XXXX" == "!!!XXXX") { $url = $url2; } return $url; }