WEB PHP help please

Discussion in 'OT Technology' started by Browning, Jul 21, 2009.

  1. Browning

    Browning Active Member

    Joined:
    Feb 14, 2005
    Messages:
    89,465
    Likes Received:
    10
    I'm trying to add another url shortening site to the tweet this wordpress plugin and am lost. :o

    I think this is the part that needs edited. Tried pasting the whole thing but it was too large:o
    Code:
    /**
     * Retrieves the shortened URL for a post, taking into account the user's
     * settings. No arguments. Works on the current post.
     * Must be used within the loop.
     */
    function get_tweet_this_short_url() {
        global $id;
        $purl = get_permalink();
        $cached_url = get_post_meta($id, 'tweet_this_url', true);
        if($cached_url && $cached_url != 'getnew')
            return $cached_url;
        else {
            $u = tt_option('tt_url_service');
            if(ini_get('allow_url_fopen') == 1 ||
                ini_get('allow_url_fopen') == 'on' ||
                ini_get('allow_url_fopen') == 'On' ||
                function_exists('curl_init'))
                    $u = $u;
                else $u = 'local';
            switch($u) {
            case 'adjix': {
                if(tt_option('tt_adjix_api_key') == '')
                    $adid = '';
                else $adid = '&partnerID=' .
                    tt_option('tt_adjix_api_key');
                if(tt_option('tt_ad_vu') != 'true')
                    $s = '';
                else $s = '&ultraShort=y';
                $url = tt_read_file('http://api.adjix.com/shrinkLink' .
                    '?url=' . $purl . $adid . $s);
                }
                break;
            case 'bit.ly':
                $url = tt_read_file('http://bit.ly/api?url=' . $purl);
                break;
            case 'h3o.de':
                $url = tt_read_file('http://h3o.de/api/index.php?' .
                'url=' . $purl);
                break;
            case 'hex.io':
                $url = str_replace('www.', '', tt_read_file('http://' .
                'www.hex.io/api-create.php?url=' . $purl));
                break;
            case 'idek.net':
                $url = tt_read_file('http://idek.net/c.php?idek-api=' .
                'true&idek-ref=Tweet+This&idek-url=' . $purl);
                break;
            case 'is.gd':
                $url = tt_read_file('http://is.gd/api.php?longurl=' .
                $purl);
                break;
            case 'lin.cr':
                $url = tt_read_file('http://lin.cr/?mode=api&full=1' .
                '&l=' . $purl);
                break;
            case 'metamark':
                $url = tt_read_file('http://metamark.net/api/rest/' .
                'simple?long_url=' . $purl);
                break;
            case 'ri.ms':
                $url = tt_read_file('http://ri.ms/api-create.php?' .
                'url=' . $purl);
                break;
            case 'snurl':
                $url = tt_read_file('http://snurl.com/site/snip?r=' .
                'simple&link=' . $purl);
                break;
            case 'tinyurl':
                $url = tt_read_file('http://tinyurl.com/' .
                'api-create.php?url=' . $purl);
                break;
            case 'urlb.at':
                $url = tt_read_file('http://urlb.at/api/rest/?url=' .
                urlencode($purl));
                break;
            case 'tweetburner': {
                if(function_exists('curl_init')) {
                $ch = curl_init('http://tweetburner.com/links');
                curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
                curl_setopt($ch,CURLOPT_POST,1);
                curl_setopt($ch,CURLOPT_POSTFIELDS,'link[url]=$purl');
                curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
                $url = curl_exec($ch);
                curl_close($ch);
                }
                else $u = 'local';
                }
                break;
            case 'local': {
                global $id;
                $url = get_bloginfo('url') . '/?p=' . $id;
                }
                break;
            default:
                $url = tt_read_file('http://th8.us/api.php?url=' .
                $purl . '&client=Tweet+This+v1.4.1&format=simple');
            }
            if(tt_option('tt_url_www') == 'true' && $u != 'tweetburner') {
                $url = str_replace('http://www.', 'www.', $url);
                $url = str_replace('http://', 'www.', $url);
                }
            if($u != 'local' && (strlen($url) > 30 || $url == 'Error' ||
                $url == 'www.' || $url == 'http://'))
                $url = get_bloginfo('url') . '/?p=' . $id;
            if(tt_option('tt_30') == 'true' && strlen($purl) < 30) {
                $url = $purl; if(tt_option('tt_url_www') == 'true') {
                    $url = str_replace('http://www.', 'www.',
                        $url);
                    $url = str_replace('http://', 'www.', $url);
                    }
                }
            if($cached_url == 'getnew')
                update_post_meta($id, 'tweet_this_url', $url,
                'getnew');
            else add_post_meta($id, 'tweet_this_url', $url, true);
            }
        return $url;
    }
    
    
    /**
     * Echoes the above function for convenience.
     */
    How would I go about adding another?:hsd:
     
  2. hank85

    hank85 sudo shred /dev/sda -f -v -z --iterations=6

    Joined:
    Jul 23, 2008
    Messages:
    4,360
    Likes Received:
    0
    Code:
    case 'PROVIDER':
    $url = str_replace('www.', '', tt_read_file('SUBMITURL' . $purl));
    break;
    
    You're also going to need to edit the portion where you select which provider you want to use.
     
  3. Browning

    Browning Active Member

    Joined:
    Feb 14, 2005
    Messages:
    89,465
    Likes Received:
    10
  4. brds

    brds OT Supporter

    Joined:
    Jun 26, 2006
    Messages:
    17,650
    Likes Received:
    15
    Location:
    Atlanta
    all your trying to do is mimic tinyftw? why not just store the url the user enters in the database, then when the site (ie www.tinyftw.com/go/####) just pull the address from the DB based on the #### and forward them to that address?


    I might be totally misunderstanding what you're saying though :dunno:
     
  5. intrktevo

    intrktevo New Member

    Joined:
    Oct 18, 2004
    Messages:
    5,781
    Likes Received:
    0
    Location:
    UCF
    looks like he is just trying to add another provider to a wordpress plugin, not create his own..

    in that case just add another section to that switch statement as hank mentioned. you will then need to find where all the providers are listed so the user may select it
     
  6. Browning

    Browning Active Member

    Joined:
    Feb 14, 2005
    Messages:
    89,465
    Likes Received:
    10
    can't get this to work:o
     

Share This Page