/**
  * Handles a status update that includes an image.
  * @param type $url
  * @param type $args
  * @return boolean
  */
 function handleMediaRequest($url, $args = array())
 {
     /* Load tmhOAuth for Media uploads only when needed: https://github.com/themattharris/tmhOAuth */
     if (!class_exists('tmhOAuth')) {
         require_once 'tmhOAuth/tmhOAuth.php';
         require_once 'tmhOAuth/tmhUtilities.php';
     }
     $auth = $args['auth'];
     if (!$auth) {
         $ack = get_option('app_consumer_key');
         $acs = get_option('app_consumer_secret');
         $ot = get_option('oauth_token');
         $ots = get_option('oauth_token_secret');
     } else {
         $ack = get_user_meta($auth, 'app_consumer_key', true);
         $acs = get_user_meta($auth, 'app_consumer_secret', true);
         $ot = get_user_meta($auth, 'oauth_token', true);
         $ots = get_user_meta($auth, 'oauth_token_secret', true);
     }
     // when performing as a scheduled action, need to include file.php
     if (!function_exists('get_home_path')) {
         require_once ABSPATH . 'wp-admin/includes/file.php';
     }
     $connect = array('consumer_key' => $ack, 'consumer_secret' => $acs, 'user_token' => $ot, 'user_secret' => $ots);
     $tmhOAuth = new tmhOAuth($connect);
     $attachment = wpt_post_attachment($args['id']);
     // if install is at root, can query src path. Otherwise, need to take full image.
     $at_root = wp_make_link_relative(home_url()) == home_url() || wp_make_link_relative(home_url()) == '/' ? true : false;
     if ($at_root) {
         $image_sizes = get_intermediate_image_sizes();
         if (in_array('large', $image_sizes)) {
             $size = 'large';
         } else {
             $size = array_pop($image_sizes);
         }
         $upload = wp_get_attachment_image_src($attachment, apply_filters('wpt_upload_image_size', $size));
         $path = get_home_path() . wp_make_link_relative($upload[0]);
         $image = str_replace('//', '/', $path);
     } else {
         $image = get_attached_file($attachment);
     }
     $image = apply_filters('wpt_image_path', $image, $args);
     $mime_type = get_post_mime_type($attachment);
     if (!$mime_type) {
         $mime_type = 'image/jpeg';
     }
     $code = $tmhOAuth->request('POST', $url, array('media[]' => "@{$image};type={$mime_type};filename={$image}", 'status' => $args['status']), true, true);
     if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
         $debug = array('media[]' => "@{$image};type={$mime_type};filename={$image}", 'status' => $args['status']);
         wpt_mail("Media Submitted - Post ID #{$args['id']}", print_r($debug, 1));
     }
     $response = $tmhOAuth->response['response'];
     if (is_wp_error($response)) {
         return false;
     }
     $this->http_code = $code;
     $this->last_api_call = $url;
     $this->format = 'json';
     $this->http_header = $response;
     return $response;
 }
Beispiel #2
0
function post_jd_twitter($id)
{
    if (empty($_POST) || defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || wp_is_post_revision($id) || isset($_POST['_inline_edit']) || defined('DOING_AJAX') && DOING_AJAX || !wpt_in_post_type($id)) {
        return;
    }
    if (isset($_POST['_yourls_keyword'])) {
        $yourls = $_POST['_yourls_keyword'];
        $update = update_post_meta($id, '_yourls_keyword', $yourls);
    }
    if (isset($_POST['_jd_twitter'])) {
        $jd_twitter = $_POST['_jd_twitter'];
        $update = update_post_meta($id, '_jd_twitter', $jd_twitter);
    }
    if (isset($_POST['_jd_wp_twitter']) && $_POST['_jd_wp_twitter'] != '') {
        $jd_wp_twitter = $_POST['_jd_wp_twitter'];
        $update = update_post_meta($id, '_jd_wp_twitter', $jd_wp_twitter);
    }
    if (isset($_POST['_jd_tweet_this'])) {
        $jd_tweet_this = $_POST['_jd_tweet_this'] == 'no' ? 'no' : 'yes';
        $update = update_post_meta($id, '_jd_tweet_this', $jd_tweet_this);
    } else {
        if (isset($_POST['_wpnonce'])) {
            $jd_tweet_default = get_option('jd_tweet_default') == 1 ? 'no' : 'yes';
            $update = update_post_meta($id, '_jd_tweet_this', $jd_tweet_default);
        }
    }
    if (isset($_POST['wpt_clear_history']) && $_POST['wpt_clear_history'] == 'clear') {
        delete_post_meta($id, '_wpt_failed');
        delete_post_meta($id, '_jd_wp_twitter');
    }
    // WPT PRO //
    $update = apply_filters('wpt_insert_post', $_POST, $id);
    // WPT PRO //
    // only send debug data if post meta is updated.
    if (WPT_DEBUG && function_exists('wpt_pro_exists') && ($update == true || is_int($update))) {
        wpt_mail("Post Meta Inserted: #{$id}", print_r($_POST, 1));
        // DEBUG
    }
}
function wpt_apply_term_filters($filter, $args)
{
    $post_type = isset($args['type']) ? $args['type'] : false;
    $post_ID = isset($args['id']) ? $args['id'] : false;
    // $filter == true == allowed
    $term_ids = array();
    $filters = get_option('wpt_terms');
    if (is_array($filters)) {
        $filtered_taxonomies = array_keys($filters);
        $taxonomies = get_object_taxonomies($post_type, 'names');
        $terms = wp_get_object_terms($post_ID, $taxonomies);
        foreach ($terms as $term) {
            $term_ids[$term->taxonomy][] = $term->term_id;
            // term IDs are unique, so I don't care which taxonomy this is.
        }
        $positive = get_option('wpt_term_filters');
        // items in array are checked positively
        foreach ($filters as $key => $value) {
            // if there are terms in both sets
            // this keeps going unless any test comes up as false.
            if (!empty($filters[$key])) {
                if (isset($term_ids[$key])) {
                    $result = array_intersect($term_ids[$key], $filters[$key]);
                    if (isset($positive[$key]) && count($result) >= 1) {
                        $filter = true;
                    } else {
                        if (isset($positive[$key]) && count($result) == 0) {
                            $filter = false;
                        } else {
                            if (count($result) >= 1 && !isset($positive[$key])) {
                                return false;
                            }
                        }
                    }
                }
            }
        }
    }
    wpt_mail("3d: Taxonomy limits completed - {$filter} - #{$post_ID}", print_r($args, 1));
    return apply_filters('wpt_modify_term_filters', $filter, $args);
}
 function jd_shorten_link($url, $thisposttitle, $post_ID, $testmode = false)
 {
     if (WPT_DEBUG && function_exists('wpt_pro_exists')) {
         wpt_mail("Initial Link Data: #{$post_ID}", "{$url}, {$thisposttitle}, {$post_ID}, {$testmode}");
         // DEBUG
     }
     // filter link before sending to shortener or adding analytics
     $url = apply_filters('wpt_shorten_link', $url, $post_ID);
     if ($testmode == false) {
         if (get_option('use-twitter-analytics') == 1 || get_option('use_dynamic_analytics') == 1) {
             if (get_option('use_dynamic_analytics') == '1') {
                 $campaign_type = get_option('jd_dynamic_analytics');
                 if ($campaign_type == "post_category" && $testmode != 'link') {
                     $category = get_the_category($post_ID);
                     $campaign = sanitize_title($category[0]->cat_name);
                 } else {
                     if ($campaign_type == "post_ID") {
                         $campaign = $post_ID;
                     } else {
                         if ($campaign_type == "post_title" && $testmode != 'link') {
                             $post = get_post($post_ID);
                             $campaign = sanitize_title($post->post_title);
                         } else {
                             if ($testmode != 'link') {
                                 $post = get_post($post_ID);
                                 $post_author = $post->post_author;
                                 $campaign = get_the_author_meta('user_login', $post_author);
                             } else {
                                 $post_author = '';
                                 $campaign = '';
                             }
                         }
                     }
                 }
             } else {
                 $campaign = get_option('twitter-analytics-campaign');
             }
             if (strpos($url, "%3F") === FALSE && strpos($url, "?") === FALSE) {
                 $ct = "?";
             } else {
                 $ct = "&";
             }
             $medium = apply_filters('wpt_utm_medium', 'twitter');
             $source = apply_filters('wpt_utm_source', 'twitter');
             $ga = "utm_campaign={$campaign}&utm_medium={$medium}&utm_source={$source}";
             $url .= $ct .= $ga;
         }
         $url = urldecode(trim($url));
         // prevent double-encoding
         $encoded = urlencode($url);
     } else {
         $url = urldecode(trim($url));
         // prevent double-encoding
         $encoded = urlencode($url);
     }
     // custom word setting
     $keyword_format = get_option('jd_keyword_format') == '1' ? $post_ID : false;
     $keyword_format = get_option('jd_keyword_format') == '2' ? get_post_meta($post_ID, '_yourls_keyword', true) : $keyword_format;
     $error = '';
     // Generate and grab the short url
     switch (get_option('jd_shortener')) {
         case 0:
         case 1:
         case 3:
             $shrink = $url;
             break;
         case 4:
             if (function_exists('wp_get_shortlink')) {
                 // wp_get_shortlink doesn't natively support custom post types; but don't return an error in that case.
                 $shrink = $post_ID != false ? wp_get_shortlink($post_ID, 'post') : $url;
             }
             if (!$shrink) {
                 $shrink = $url;
             }
             break;
         case 2:
             // updated to v3 3/31/2010
             $bitlyapi = trim(get_option('bitlyapi'));
             $bitlylogin = trim(strtolower(get_option('bitlylogin')));
             $decoded = jd_remote_json("https://api-ssl.bitly.com/v3/shorten?longUrl=" . $encoded . "&login="******"&apiKey=" . $bitlyapi . "&format=json");
             if ($decoded) {
                 if ($decoded['status_code'] != 200) {
                     $shrink = $decoded;
                     $error = $decoded['status_txt'];
                 } else {
                     $shrink = $decoded['data']['url'];
                 }
             } else {
                 $shrink = false;
             }
             if (!is_valid_url($shrink)) {
                 $shrink = false;
             }
             break;
         case 5:
             // local YOURLS installation
             global $yourls_reserved_URL;
             define('YOURLS_INSTALLING', true);
             // Pretend we're installing YOURLS to bypass test for install or upgrade
             define('YOURLS_FLOOD_DELAY_SECONDS', 0);
             // Disable flood check
             $opath = get_option('yourlspath');
             $ypath = str_replace('user', 'includes', $opath);
             if (file_exists(dirname($ypath) . '/load-yourls.php')) {
                 // YOURLS 1.4+
                 require_once dirname($ypath) . '/load-yourls.php';
                 global $ydb;
                 if (function_exists('yourls_add_new_link')) {
                     $yourls_result = yourls_add_new_link($url, $keyword_format, $thisposttitle);
                 } else {
                     $yourls_result = $url;
                 }
             } else {
                 // YOURLS 1.3
                 if (file_exists(get_option('yourslpath'))) {
                     require_once get_option('yourlspath');
                     $yourls_db = new wpdb(YOURLS_DB_USER, YOURLS_DB_PASS, YOURLS_DB_NAME, YOURLS_DB_HOST);
                     $yourls_result = yourls_add_new_link($url, $keyword_format, $yourls_db);
                 }
             }
             if ($yourls_result) {
                 $shrink = $yourls_result['shorturl'];
             } else {
                 $shrink = false;
             }
             break;
         case 6:
             // remote YOURLS installation
             $yourlslogin = trim(get_option('yourlslogin'));
             $yourlsapi = stripcslashes(get_option('yourlsapi'));
             $api_url = sprintf(get_option('yourlsurl') . '?username=%s&password=%s&url=%s&format=json&action=shorturl&keyword=%s', $yourlslogin, $yourlsapi, $encoded, $keyword_format);
             $json = jd_remote_json($api_url, false);
             if ($json) {
                 $shrink = $json->shorturl;
             } else {
                 $shrink = false;
             }
             break;
         case 7:
             $suprapi = trim(get_option('suprapi'));
             $suprlogin = trim(get_option('suprlogin'));
             if ($suprapi != '') {
                 $decoded = jd_remote_json("http://su.pr/api/shorten?longUrl=" . $encoded . "&login="******"&apiKey=" . $suprapi);
             } else {
                 $decoded = jd_remote_json("http://su.pr/api/shorten?longUrl=" . $encoded);
             }
             if ($decoded['statusCode'] == 'OK') {
                 $page = str_replace("&", "&", urldecode($url));
                 $shrink = $decoded['results'][$page]['shortUrl'];
                 $error = $decoded['errorMessage'];
             } else {
                 $shrink = false;
                 $error = $decoded['errorMessage'];
             }
             if (!is_valid_url($shrink)) {
                 $shrink = false;
             }
             break;
         case 8:
             // Goo.gl
             $target = "https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyBSnqQOg3vX1gwR7y2l-40yEG9SZiaYPUQ";
             $body = "{'longUrl':'{$url}'}";
             //$body = json_encode($data);
             $json = jd_fetch_url($target, 'POST', $body, 'Content-Type: application/json');
             $decoded = json_decode($json);
             //$url = $decoded['id'];
             $shrink = $decoded->id;
             if (!is_valid_url($shrink)) {
                 $shrink = false;
             }
             break;
         case 9:
             // Twitter Friendly Links
             $shrink = $url;
             if (function_exists('twitter_link')) {
                 // use twitter_link if available
                 $shrink = twitter_link($post_ID);
             }
             break;
         case 10:
             // jotURL
             //jotURL, added: 2013-04-10
             $joturlapi = trim(get_option('joturlapi'));
             $joturllogin = trim(get_option('joturllogin'));
             $joturl_longurl_params = trim(get_option('joturl_longurl_params'));
             if ($joturl_longurl_params != '') {
                 if (strpos($url, "%3F") === FALSE && strpos($url, "?") === FALSE) {
                     $ct = "?";
                 } else {
                     $ct = "&";
                 }
                 $url .= $ct . $joturl_longurl_params;
                 $encoded = urlencode(urldecode(trim($url)));
                 // prevent double-encoding
             }
             //\jotURL
             $decoded = jd_fetch_url("https://api.joturl.com/a/v1/shorten?url=" . $encoded . "&login="******"&key=" . $joturlapi . "&format=plain");
             if ($decoded !== false) {
                 $shrink = $decoded;
                 //jotURL, added: 2013-04-10
                 $joturl_shorturl_params = trim(get_option('joturl_shorturl_params'));
                 if ($joturl_shorturl_params != '') {
                     if (strpos($shrink, "%3F") === FALSE && strpos($shrink, "?") === FALSE) {
                         $ct = "?";
                     } else {
                         $ct = "&";
                     }
                     $shrink .= $ct . $joturl_shorturl_params;
                 }
                 //\jotURL
             } else {
                 $error = $decoded;
                 $shrink = false;
             }
             if (!is_valid_url($shrink)) {
                 $shrink = false;
             }
             break;
             update_option('wpt_shortener_status', "{$shrink} : {$error}");
     }
     if (!$testmode) {
         if ($shrink === false || filter_var($shrink, FILTER_VALIDATE_URL) === false) {
             update_option('wp_url_failure', '1');
             $shrink = urldecode($url);
         } else {
             update_option('wp_url_failure', '0');
         }
     }
     wpt_store_url($post_ID, $shrink);
     return $shrink;
 }
Beispiel #5
0
 /**
  * Handles a status update that includes an image.
  *
  * @param type $url
  * @param type $args
  *
  * @return boolean
  */
 function handleMediaRequest($url, $args = array())
 {
     /* Load tmhOAuth for Media uploads only when needed: https://github.com/themattharris/tmhOAuth */
     /* It's not possible to upload media using WP_HTTP, so this needs to use cURL. */
     if (!class_exists('tmhOAuth')) {
         require_once plugin_dir_path(__FILE__) . 'tmhOAuth/tmhOAuth.php';
         require_once plugin_dir_path(__FILE__) . 'tmhOAuth/tmhUtilities.php';
     }
     $auth = $args['auth'];
     if (!$auth) {
         $ack = get_option('app_consumer_key');
         $acs = get_option('app_consumer_secret');
         $ot = get_option('oauth_token');
         $ots = get_option('oauth_token_secret');
     } else {
         $ack = get_user_meta($auth, 'app_consumer_key', true);
         $acs = get_user_meta($auth, 'app_consumer_secret', true);
         $ot = get_user_meta($auth, 'oauth_token', true);
         $ots = get_user_meta($auth, 'oauth_token_secret', true);
     }
     // when performing as a scheduled action, need to include file.php
     if (!function_exists('get_home_path')) {
         require_once ABSPATH . 'wp-admin/includes/file.php';
     }
     $connect = array('consumer_key' => $ack, 'consumer_secret' => $acs, 'user_token' => $ot, 'user_secret' => $ots);
     $tmhOAuth = new tmhOAuth($connect);
     $attachment = $args['media'];
     $image_sizes = get_intermediate_image_sizes();
     if (in_array('large', $image_sizes)) {
         $size = 'large';
     } else {
         $size = array_pop($image_sizes);
     }
     $upload = wp_get_attachment_image_src($attachment, apply_filters('wpt_upload_image_size', $size));
     $image_url = $upload[0];
     $remote = wp_remote_get($image_url);
     $binary = wp_remote_retrieve_body($remote);
     $mime_type = get_post_mime_type($attachment);
     if (!$mime_type) {
         $mime_type = 'image/jpeg';
     }
     /* End New */
     $code = $tmhOAuth->request('POST', $url, array('media' => "{$binary}"), true, true);
     $response = $tmhOAuth->response['response'];
     $full = $tmhOAuth->response;
     wpt_mail("Media Posted - Media ID #{$args['media']}", print_r($full, 1) . "\n" . "\n" . print_r($upload, 1) . "\n" . $image_url);
     if (is_wp_error($response)) {
         return '';
     }
     $this->http_code = $code;
     $this->last_api_call = $url;
     $this->format = 'json';
     $this->http_header = $response;
     $response = json_decode($response);
     $media_id = $response->media_id_string;
     return $media_id;
 }