coders, check this out

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wolfy
    Confirmed User
    • Dec 2003
    • 3574

    #1

    coders, check this out

    This is a plugin for wordpress that makes urls clickable. Example - it will turn the text http://www.link.com into
    Code:
    <a href="http://www.link.com" title="http://www.link.com" target="_blank">http://www.link.com</a>.
    The only problem is that text stripped from an email automatically has this added to the url - <http://www.link.com>. I need those brackets stripped from the text so it displays correctly.

    I'm sure it can be done with no more than 4 lines of code, can anyone tell me how to fix it? I'll throw in a few bucks if you want it.

    (that hahahaha is 2 of these =)

    Code:
    function c2c_truncate_link ($url, $mode='0', $trunc_before='', $trunc_after='...') {
        if (1 hahahaha $mode) {
                    $url = preg_replace("/(([a-z]+?):\\/\\/[A-Za-z0-9\-\.]+).*/i", "$1", $url);
                    $url = $trunc_before . preg_replace("/([A-Za-z0-9\-\.]+\.(com|org|net|gov|edu|us|info|biz|ws|name|tv)).*/i", "$1", $url) . $trunc_after;
            } elseif (($mode > 10) && (strlen($url) > $mode)) {
                    $url = $trunc_before . substr($url, 0, $mode) . $trunc_after;
            }
            return $url;
    } //end c2c_truncate_link()
    
    // mode: 0=full url; 1=host-only ;11+=number of characters to truncate after
    function c2c_hyperlink_urls ($text, $mode='0', $trunc_before='', $trunc_after='...', $open_in_new_window=true) {
        $text = ' ' . $text . ' ';
        $new_win_txt = ($open_in_new_window) ? ' target="_blank"' : '';
            
        // Hyperlink Class B domains *.(com|org|net|gov|edu|us|info|biz|ws|name|tv)(/*)
        $text = preg_replace("#([\s{}\(\)\[\]])([A-Za-z0-9\-\.]+)\.(com|org|net|gov|edu|us|info|biz|ws|name|tv)((?:/[^\s{}\(\)\[\]]*[^\.,\s{}\(\)\[\]]?)?)#ie",
            "'$1<a href=\"http://$2.$3$4\" title=\"http://$2.$3$4\"$new_win_txt>' . c2c_truncate_link(\"$2.$3$4\", \"$mode\", \"$trunc_before\", \"$trunc_after\") . '</a>'",
            $text);
    
        // Hyperlink anything with an explicit protocol
        $text = preg_replace("#([\s{}\(\)\[\]])(([a-z]+?)://([A-Za-z_0-9\-]+\.([^\s{}\(\)\[\]]+[^\s,\.\;{}\(\)\[\]])))#ie",
            "'$1<a href=\"$2\" title=\"$2\"$new_win_txt>' . c2c_truncate_link(\"$4\", \"$mode\", \"$trunc_before\", \"$trunc_after\") . '</a>'",
                    $text);
    
        // Hyperlink e-mail addresses
        $text = preg_replace("#([\s{}\(\)\[\]])([A-Za-z0-9\-_\.]+?)@([^\s,{}\(\)\[\]]+\.[^\s.,{}\(\)\[\]]+)#ie",
            "'$1<a href=\"mailto:$2@$3\" title=\"mailto:$2@$3\">' . c2c_truncate_link(\"$2@$3\", \"$mode\", \"$trunc_before\", \"$trunc_after\") . '</a>'",
            $text);
    
        return substr($text,1,strlen($text)-2);
    } //end c2c_hyperlink_urls()
  • Wolfy
    Confirmed User
    • Dec 2003
    • 3574

    #2
    $text = preg_replace("#<((Link: http://|www)http://|www\.)(.*)>#","\\1\\2",$text);

    didn't work. That leaves the closing bracket intact...

    Comment

    • pornguy
      Too lazy to set a custom title
      • Mar 2003
      • 62910

      #3
      Cool. Looks like it could be something to play with.
      PornGuy skype me pornguy_epic

      AmateurDough The Hottes Shemales online!
      TChicks.com | Angeles Cid | Mariana Cordoba | MAILERS WELCOME!

      Comment

      • boner 2.0
        Too lazy to set a custom title
        • Jul 2004
        • 10970

        #4
        cig whore
        Her name is Monica

        Comment

        • Wolfy
          Confirmed User
          • Dec 2003
          • 3574

          #5
          Originally posted by boner 2.0
          Her name is Monica

          Comment

          • psyko514
            See sig. Join Epic Cash.
            • Oct 2002
            • 22366

            #6
            Originally posted by pornguy
            Cool. Looks like it could be something to play with.
            did you even read his post?

            Bad Girl Bucks
            - 50% Revshare through CCBill.
            Promote BrandyDDD, Pixie's Pillows, Action Allie and more!

            Phoenix Forum Pics | Webmaster Access Montreal pics
            email: psyko514(a)gmail.com | icq: 214-702-014

            Comment

            • psyko514
              See sig. Join Epic Cash.
              • Oct 2002
              • 22366

              #7
              Originally posted by Wolfy
              $text = preg_replace("#<((Link: http://|www)http://|www\.)(.*)>#","\\1\\2",$text);

              didn't work. That leaves the closing bracket intact...

              can't you run the line twice? once to remove the opening bracket and once to remove the closing bracket?

              my PHP knowledge is limited...

              Bad Girl Bucks
              - 50% Revshare through CCBill.
              Promote BrandyDDD, Pixie's Pillows, Action Allie and more!

              Phoenix Forum Pics | Webmaster Access Montreal pics
              email: psyko514(a)gmail.com | icq: 214-702-014

              Comment

              • Wolfy
                Confirmed User
                • Dec 2003
                • 3574

                #8
                Originally posted by psyko514
                can't you run the line twice? once to remove the opening bracket and once to remove the closing bracket?

                my PHP knowledge is limited...
                there's a tiny bit more to it - with that line added, it formats www.link.com to a clickable "http://.link.com/" <- there's an extra "." in the url it outputs. Also, it screws up a url written with "http://"


                My php is pretty limited too, I mostly end up with s

                Comment

                • teksonline
                  So Fucking Banned
                  • Jan 2005
                  • 2904

                  #9
                  in your character class your backslashing your . before the @ i dont think you want to do that. but i havent looked at this much, i have headache, hit me up on aim and tell me exact problme i can give you the answer

                  Comment

                  • Wolfy
                    Confirmed User
                    • Dec 2003
                    • 3574

                    #10
                    it's simple, :P

                    $text=str_replace("<", "", $text);
                    $text=str_replace(">", "", $text);

                    I win!

                    Comment

                    • teksonline
                      So Fucking Banned
                      • Jan 2005
                      • 2904

                      #11
                      also I see alot of this A-Za-z0-9 which can be substituded with /w+

                      Comment

                      • Wolfy
                        Confirmed User
                        • Dec 2003
                        • 3574

                        #12
                        : to Cyborg for the help lol

                        Comment

                        • Wolfy
                          Confirmed User
                          • Dec 2003
                          • 3574

                          #13
                          Dammit I killed Sarah Connor!! WHO WAS THAT MASKED MAN?!!!

                          Sorry for the confusion, I'm just passing it on. This thread is dead, somebody post *******.

                          Comment

                          Working...