vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Modification Requests/Questions (Unpaid) (https://vborg.vbsupport.ru/forumdisplay.php?f=112)
-   -   Add "TAG NAME" to my hack. (https://vborg.vbsupport.ru/showthread.php?t=126793)

MRGTB 09-16-2006 08:23 PM

Add "TAG NAME" to my hack.
 
I released a hack here that is all but complete now as final version except for one feature I want to add to it: https://vborg.vbsupport.ru/showthrea...highlight=ed2k

The feature I want to add is included in another hack here which is very much like mine. But suffered from problems which mine doesn't. But there is a feature in that hack that I want to incorporate into my hack. I have tried loads of ways to contact the author all week, but have been unable to get in touch with him.

The feature in that hack that I want to incorporate into mine, is the "ADD CUSTOM TAG" feature. Which basicley lets you add a custom TAG which will be included in the links posted. The best way I can describe this is to post the code and then highlight bits of the code I'm interested in RED so you can see what I'm talking about.

You will of course have to download my hack from the link above, so you can open my hack and look at how this can be done, by comparing both hacks together. Here is the code below that I'm interested in taking over to my hack. And here is links to both hacks to download both version to compare.

https://vborg.vbsupport.ru/showthrea...highlight=ed2k
https://vborg.vbsupport.ru/showthrea...highlight=ed2k


Code:

<?xml version="1.0" encoding="ISO-8859-1"?>

<plugins>
        <plugin active="1" product="vbulletin">
                <title>Extended auto-linker (adds ed2k and sip link recognition)</title>
                <hookname>url_to_bbcode</hookname>
                <phpcode><![CDATA[// Hook url_to_bbcode

if (!function_exists('convert_url_to_bbcode_callback_extended'))
{
        /**
        * Extended callback function for convert_url_to_bbcode
        *
        * @param        string        Message text
        * @param        string        Text to prepend
        *
        * @return        string
        */
        function convert_url_to_bbcode_callback_extended($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';
                        // Note the slightly changed regex which introduces ed2k and sip protocols and allows "|" as a character in URIs
                        $urlSearchArray = array(
                                "#(^|(?<=[^_a-z0-9-=\]\"'/@]|(?<=" . $taglist . ")\]))((https?|ftp|gopher|news|telnet)://|www\.|sip:|ed2k://)((\[(?!/)|[^\s[^$!`\"'{}<>])+)(?!\[/url|\[/img)(?=[,.]*(\)\s|\)$|[\s[]|$))#siUe",
                        );
       
                        $urlReplaceArray = array(
                                "convert_url_to_bbcode_callback_extended_callback('\\2','\\4')",
                        );
       
                        $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\\2",
                                "\\0"
                        );
                }
       
                $text = preg_replace($urlSearchArray, $urlReplaceArray, $messagetext);
                if (strpos($text, "@"))
                {
                        $text = preg_replace($emailSearchArray, $emailReplaceArray, $text);
                }
       
                return $prepend . $text;
        }
}

if (!function_exists('convert_url_to_bbcode_callback_extended_callback'))
{
        /**
        * Callback function returning "normal" links as usual and ed2k links specially formatted
        *
        * @param        string        Prefix containing the protocol part of the url
        * @param        string        Remainder of the link
        *
        * @return        string
        */
        function convert_url_to_bbcode_callback_extended_callback($protocolprefix, $link)
        {
                // Optionally specify a tag which get automatically added to the ed2k link
                // $filenametag = '[MyCrewTag]';


                if (strtolower($protocolprefix) == 'ed2k://')
                {
                        $ed2klinkparts = @split('\|', $link);
                        if (is_array($ed2klinkparts) && count($ed2klinkparts) > 5 && strtolower($ed2klinkparts[1]) == 'file')
                        {
                                if ($filenametag != '')
                                {
                                        // Add tag to filename
                                        $path_parts = pathinfo($ed2klinkparts[2]);
                                        $tempfilename = $ed2klinkparts[2];
                                        $ed2klinkparts[2] = basename($path_parts['basename'], $path_parts['extension']) . urlencode($filenametag) . '.' . $path_parts['extension'];
                                        $link = join('|', $ed2klinkparts);
                                        $ed2klinkparts[2] = $tempfilename;
                                }

                                return '' . urldecode($ed2klinkparts[2]) . ' (' . format_bytesize($ed2klinkparts[3]) . ')';
                        }
                        elseif (is_array($ed2klinkparts) && count($ed2klinkparts) > 3 && strtolower($ed2klinkparts[1]) == 'server')
                        {
                                return 'ed2k Server ' . $ed2klinkparts[2] . ':' . $ed2klinkparts[3] . '';
                        }
                        else
                        {
                                return $protocolprefix . $link;
                        }
                }
                else
                {
                        return '' . $protocolprefix . $link . '';
                }
        }
}

if (!function_exists('format_bytesize'))
{
        /**
        * Function to convert a byte size in a human readable form
        *
        * @param        int        Bytes
        * @param        int        decimal places
        *
        * @return        string
        */
        function format_bytesize($bytes, $dec_places = 2)
        {
                if ($bytes > (1024*1024*1024)) {
                        $result  = sprintf('%.' . $dec_places . 'f', $bytes / (1024*1024*1024));
                        $result .= 'GBytes';
                } elseif ($bytes > (1024*1024)) {
                        $result  = sprintf('%.' . $dec_places . 'f', $bytes / (1024*1024));
                        $result .= 'MBytes';
                } elseif ($bytes > 1024) {
                        $result  = sprintf('%.' . $dec_places . 'f', $bytes / 1024);
                        $result .= 'kBytes';
                } 
                return $result;
        }
}

// Return replacement using extended callback function
$messagetext = preg_replace(
        '#(^|\[/(' . $skiptaglist . ')\])(.*(\[(' . $skiptaglist . ')|$))#siUe',
        "convert_url_to_bbcode_callback_extended('\\3', '\\1')",
        $messagetext
);

return $messagetext;]]></phpcode>
        </plugin>
</plugins>

Just want to add that I have been working on this for days, but have been unable my self to carry the ADD TAG across to mine, not because it can't be done. I just can't figure it out!


All times are GMT. The time now is 04:16 AM.

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.01082 seconds
  • Memory Usage 1,750KB
  • 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_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (1)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete