Go Back   vb.org Archive > Community Discussions > Modification Requests/Questions (Unpaid)
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 09-16-2006, 08:23 PM
MRGTB MRGTB is offline
 
Join Date: Dec 2004
Posts: 548
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:41 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.03276 seconds
  • Memory Usage 2,170KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete