vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.6 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=194)
-   -   Show Thread Enhancements - Replace URL's With Page Title (https://vborg.vbsupport.ru/showthread.php?t=155909)

sweede 12-19-2007 06:23 PM

while(!feof) , while NOT end of file. the correct methon would be to use fread(resource, bytes) , which reads the stream until bytes and then closes the stream.

I actually tested this one.


HTML Code:


if (!function_exists(convert_url_to_bbcode_callback_auto_title)) {
    function convert_url_to_bbcode_callback_auto_title($messagetext, $prepend)
    {
            // the auto parser - adds [url] tags around neccessary things
            $messagetext = str_replace('\"', '"', $messagetext);
            $prepend = str_replace('\"', '"', $prepend);

            static $urlSearchArray, $urlReplaceArray, $emailSearchArray, $emailReplaceArray;
            if (empty($urlSearchArray))
            {
                    $taglist = '\[b|\[i|\[u|\[left|\[center|\[right|\[indent|\[quote|\[highlight|\[\*' .
                            '|\[/b|\[/i|\[/u|\[/left|\[/center|\[/right|\[/indent|\[/quote|\[/highlight';
                    $urlSearchArray = array(
                            "#(^|(?<=[^_a-z0-9-=\]\"'/@]|(?<=" . $taglist . ")\]))((https?|ftp|gopher|news|telnet)://|www\.)((\[(?!/)|[^\s[^$`\"'|{}<>])+)(?!\[/url|\[/img)(?=[,.!)]*(\)\s|\)$|[\s[]|$))#siU"
                    );

                    $urlReplaceArray = array(
                            "[url]\\2\\4[/url]"
                    );




                    $emailSearchArray = array(
                            "/([ \n\r\t])([_a-z0-9-]+(\.[_a-z0-9-]+)*@[^\s]+(\.[a-z0-9-]+)*(\.[a-z]{2,4}))/si",
                            "/^([_a-z0-9-]+(\.[_a-z0-9-]+)*@[^\s]+(\.[a-z0-9-]+)*(\.[a-z]{2,4}))/si"
                    );

                    $emailReplaceArray = array(
                            "\\1[email]\\2[/email]",
                            "[email]\\0[/email]"
                    );
            }

            $text = preg_replace_callback($urlSearchArray, "auto_title", $messagetext);

            if (strpos($text, "@"))
            {
                    $text = preg_replace($emailSearchArray, $emailReplaceArray, $text);
            }

            return $prepend . $text;
    }
   
    function auto_title_http_get($url){

        $url_stuff = parse_url($url);
        $port = isset($url_stuff['port']) ? $url_stuff['port'] : 80;

        $fp = fsockopen($url_stuff['host'], $port);

        $query  = "GET " . $url_stuff['path'] ."?". $url_stuff['query'] . " HTTP/1.0\n";
        $query .= "Host: " . $url_stuff['host'];
        $query .= "\n\n";

        fwrite($fp, $query);

      $buffer = fread($fp, 8192);

        preg_match('/Content-Length: ([0-9]+)/', $buffer, $parts);

        return substr($buffer, - $parts[1]);

    }
    function auto_title ($text)
    {

        if ($text[2] == 'www.' or $text[2] == 'WWW.') {
            $text[4] = $text[2] . $text[4];
            $text[2] = 'http://';
        }

        $paged = @fopen( $text[2] . $text[4], "r" ); #echo $page . "DONE";

        $page = auto_title_http_get($paged);

        preg_match("/<title>[\n\r\s]*(.*)[\n\r\s]*<\/title>/", $page, $title);

        if ($title[1] == '') {
            $title[1] = $text[2] . $text[4];
        }
            return "[url=\"" . $text[2] . $text[4] . "\"]" . preg_replace("/\&.+\;/", '', $title[1]) . "[/url]";
    }

}

$messagetext = preg_replace(
    '#(^|\[/(' . $skiptaglist . ')\])(.*(\[(' . $skiptaglist . ')|$))#siUe',
    "convert_url_to_bbcode_callback_auto_title('\\3', '\\1')",
    $messagetext
);


Jafo232 12-19-2007 06:42 PM

You are going to find that fsockopen can fall under the same security restrictions as fopen depending on the host.. Examples:

http://www.110mb.com/forum/external-...d-t3690.0.html

http://www.thescripts.com/forum/thread2690.html

http://www.webhostingtalk.com/archiv.../t-501791.html

http://forum.unlimitedmb.com/showthread.php?t=799

http://www.google.com/search?hl=en&c...ed&btnG=Search

So, yeah, I suppose your method COULD replace fopen, but the same reason why you would want to, could apply also to your solution.

HDT 12-19-2007 11:22 PM

After installed look like old thread that contains link do not retrieve the title,this need to rebuild thread and post cache?

Work on new parsed link only.

Please advise.

Jafo232 12-20-2007 01:11 AM

Works on new threads only.

HDT 12-20-2007 02:21 PM

Thanks Jafo for your confirmation.great work!

ymy 12-20-2007 06:51 PM

Quote:

Originally Posted by Phooey (Post 1396252)
Yet another vBSEO feature for free, thanks!

/installed

No, vBSEO feature work with external and internal URL
this hack only external URL :confused:

VADOS 12-20-2007 07:52 PM

*installed*
Thanx 4 the hack.

But could you tell me please how can I make links will be parsing without any external info, such as
Quote:

- Page 2 - My Board Name
I want to make links only with the name of the thread, but no more external info.

Jafo232 12-21-2007 01:08 AM

Quote:

Originally Posted by VADOS (Post 1405705)
*installed*
Thanx 4 the hack.

But could you tell me please how can I make links will be parsing without any external info, such as


I want to make links only with the name of the thread, but no more external info.

It only reads the pages title. So my advice would be to work on your page titles. :)

VADOS 12-21-2007 06:07 PM

So sorry... =(
*uninstalled*

KURTZ 12-25-2007 09:16 PM

runs perfectly on 3.7.0B3 :D


All times are GMT. The time now is 06:05 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01251 seconds
  • Memory Usage 1,755KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_html_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete