custom url mycode
1master1 Offline
Member
***
Posts: 232
Joined: Oct 2010
Post: #1
custom url mycode
can anyone create a mybb which parse only url for the url links we place inside the [code] tags?
if we use default code tag, it will not parse the url links and displays plain whole url links in a single line. and if we just put http://www.blablabla.bla links without coding they will automatically parsed with url tag and if the url is longer, they will be replaced with terminated short link as http://www.blablac......

i need a custom mycode, where is parses the long/short http links with url tag only and it must not terminate the longer links instead it must display a bottom scroll bar which is done by default code tags.
12-07-2010 12:12 PM
Find all posts by this user Quote this message in a reply
Imran Offline
Member
***
Posts: 204
Joined: Apr 2010
Post: #2
RE: custom url mycode
Yes, [code] tags doesn't show links inside them, but we have another option. Try to use quote tags instead. Like;

Quote:http://zingaburga.com

It shows the links too.

[Image: logo.png]

[Image: twitter.png]
(This post was last modified: 12-08-2010 03:19 AM by Imran.)
12-08-2010 03:19 AM
Visit this user's website Find all posts by this user Quote this message in a reply
1master1 Offline
Member
***
Posts: 232
Joined: Oct 2010
Post: #3
RE: custom url mycode
yeah, i have tried using quote tag, but it is truncating long url links and showing ... in the short link
12-08-2010 03:47 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #4
RE: custom url mycode
To remove URL shortening (affects everything), find and remove the following from inc/class_parser.php

PHP Code:
1
2
3
4
5
6
7
		if($name == $url && (!isset($this->options['shorten_urls']) || $this->options['shorten_urls'] != 0))
		{
			if(my_strlen($url) > 55)
			{
				$name = my_substr($url, 0, 40)."...".my_substr($url, -10);
			}
		}


For links in code tags, try this (untested), find in inc/class_parser.php:

PHP Code:
$code = str_replace('\\', '\', $code);

add after:

PHP Code:
$code = preg_replace('#([>\s()]|^)((http|ftp|news)\://([^/"\s<\[.]+\.)+\w+(\:[0-9]+)?(/[^"\s<\[]*)?)#i', '$1<a href="$2">$2</a>', $code);


My Blog
12-08-2010 03:52 PM
Find all posts by this user Quote this message in a reply
1master1 Offline
Member
***
Posts: 232
Joined: Oct 2010
Post: #5
RE: custom url mycode
Thank you zinga, both worked.
Well, some people said to use custom mycode instead of changing the core

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
 tags as it changes all.

So after making your edits to the core file, i thought of copying the whole function for the mycode_parse_code and added a copy of it below it and tried to create the custom code just by changing all the $code instances in that function with the new mycode name, but it had thrown some error when i used that code tags ex: [newtag] [/newtag]
Code USed:
[code]/**
	* Parses quotes with post id and/or dateline.
	*
	* @param string The message to be parsed
	* @param string The username to be parsed
	* @param boolean Are we formatting as text?
	* @return string The parsed message.
	*/
	function mycode_parse_post_quotes($message, $username, $text_only=false)
	{
		global $lang, $templates, $theme, $mybb;

		$linkback = $date = "";

		$message = trim($message);
		$message = preg_replace("#(^<br(\s?)(\/?)>|<br(\s?)(\/?)>$)#i", "", $message);

		if(!$message) return '';

		$message = str_replace('\"', '"', $message);
		$username = str_replace('\"', '"', $username)."'";
		$delete_quote = true;

		preg_match("#pid=(?:&quot;|\"|')?([0-9]+)[\"']?(?:&quot;|\"|')?#i", $username, $match);
		if(intval($match[1]))
		{
			$pid = intval($match[1]);
			$url = $mybb->settings['bburl']."/".get_post_link($pid)."#pid$pid";
			if(defined("IN_ARCHIVE"))
			{
				$linkback = " <a href=\"{$url}\">[ -> ]</a>";
			}
			else
			{
				eval("\$linkback = \" ".$templates->get("postbit_gotopost", 1, 0)."\";");
			}
			
			$username = preg_replace("#(?:&quot;|\"|')? pid=(?:&quot;|\"|')?[0-9]+[\"']?(?:&quot;|\"|')?#i", '', $username);
			$delete_quote = false;
		}

		unset($match);
		preg_match("#dateline=(?:&quot;|\"|')?([0-9]+)(?:&quot;|\"|')?#i", $username, $match);
		if(intval($match[1]))
		{
			if($match[1] < TIME_NOW)
			{
				$postdate = my_date($mybb->settings['dateformat'], intval($match[1]));
				$posttime = my_date($mybb->settings['timeformat'], intval($match[1]));
				$date = " ({$postdate} {$posttime})";
			}
			$username = preg_replace("#(?:&quot;|\"|')? dateline=(?:&quot;|\"|')?[0-9]+(?:&quot;|\"|')?#i", '', $username);
			$delete_quote = false;
		}

		if($delete_quote)
		{
			$username = my_substr($username, 0, my_strlen($username)-1);
		}

		if($text_only)
		{
			return "\n".htmlspecialchars_uni($username)." $lang->wrote{$date}\n--\n{$message}\n--\n";
		}
		else
		{
			$span = "";
			if(!$delete_quote)
			{
				$span = "<span>{$date}</span>";
			}
			
			return "<blockquote><cite>{$span}".htmlspecialchars_uni($username)." $lang->wrote{$linkback}</cite>{$message}</blockquote>\n";
		}
	}

	/**
	* Parses code MyCode.
	*
	* @param string The message to be parsed
	* @param boolean Are we formatting as text?
	* @return string The parsed message.
	*/
	/**function mycode_parse_code($code, $text_only=false)
	{
		global $lang;

		if($text_only == true)
		{
			return "\n{$lang->code}\n--\n{$code}\n--\n";
		}

		// Clean the string before parsing.
		$code = preg_replace('#^(\t*)(\n|\r|\0|\x0B| )*#', '\\1', $code);
		$code = rtrim($code);
		$original = preg_replace('#^\t*#', '', $code);

		if(empty($original))
		{
			return;
		}

		$code = str_replace('$', '$', $code);
		$code = preg_replace('#\$([0-9])#', '\\\$\\1', $code);
		$code = str_replace('\\', '\', $code);
		$code = preg_replace('#([>\s()]|^)((http|ftp|news)\://([^/"\s<\[.]+\.)+\w+(\:[0-9]+)?(/[^"\s<\[]*)?)#i', '$1<a href="$2">$2</a>', $code);
		$code = str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', $code);
		$code = str_replace("  ", '&nbsp;&nbsp;', $code);

		return "<div class=\"codeblock\">\n<div class=\"title\">".$lang->code."\n</div><div class=\"body\" dir=\"ltr\"><code>".$code."</code></div></div>\n";
	}
	**/
	function mycode_parse_cdkpu($cdkpu, $text_only=false)
	{
		global $lang;

		if($text_only == true)
		{
			return "\n{$lang->code}\n--\n{$cdkpu}\n--\n";
		}

		// Clean the string before parsing.
		$cdkpu = preg_replace('#^(\t*)(\n|\r|\0|\x0B| )*#', '\\1', $cdkpu);
		$cdkpu = rtrim($cdkpu);
		$original = preg_replace('#^\t*#', '', $cdkpu);

		if(empty($original))
		{
			return;
		}

		$cdkpu = str_replace('$', '$', $cdkpu);
		$cdkpu = preg_replace('#\$([0-9])#', '\\\$\\1', $cdkpu);
		$cdkpu = str_replace('\\', '\', $cdkpu);
		$cdkpu = preg_replace('#([>\s()]|^)((http|ftp|news)\://([^/"\s<\[.]+\.)+\w+(\:[0-9]+)?(/[^"\s<\[]*)?)#i', '$1<a href="$2">$2</a>', $cdkpu);
		$cdkpu = str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', $cdkpu);
		$cdkpu = str_replace("  ", '&nbsp;&nbsp;', $cdkpu);

		return "<div class=\"codeblock\">\n<div class=\"title\">".$lang->code."\n</div><div class=\"body\" dir=\"ltr\"><cdkpu>".$cdkpu."</cdkpu></div></div>\n";
	}

	/**
	* Parses PHP code MyCode.
	*
	* @param string The message to be parsed
	* @param boolean Whether or not it should return it as pre-wrapped in a div or not.
	* @param boolean Are we formatting as text?
	* @return string The parsed message.
	*/
	function mycode_parse_php($str, $bare_return = false, $text_only = false)
	{
		global $lang;

		if($text_only == true)
		{
			return "\n{$lang->php_code}\n--\n$str\n--\n";
		}

		// Clean the string before parsing except tab spaces.
		$str = preg_replace('#^(\t*)(\n|\r|\0|\x0B| )*#', '\\1', $str);
		$str = rtrim($str);

		$original = preg_replace('#^\t*#', '', $str);

		if(empty($original))
		{
			return;
		}

		$str = str_replace('&amp;', '&', $str);
		$str = str_replace('&lt;', '<', $str);
		$str = str_replace('&gt;', '>', $str);

		// See if open and close tags are provided.
		$added_open_tag = false;
		if(!preg_match("#^\s*<\?#si", $str))
		{
			$added_open_tag = true;
			$str = "<?php \n".$str;
		}

		$added_end_tag = false;
		if(!preg_match("#\?>\s*$#si", $str))
		{
			$added_end_tag = true;
			$str = $str." \n?>";
		}

		$code = @highlight_string($str, true);

		// Do the actual replacing.
		$code = preg_replace('#<code>\s*<span style="color: \#000000">\s*#i', "<code>", $code);
		$code = preg_replace("#</span>\s*</code>#", "</code>", $code);
		$code = preg_replace("#</span>(\r\n?|\n?)</code>#", "</span></code>", $code);
		$code = str_replace("\\", '\', $code);
		$code = str_replace('$', '$', $code);
		$code = preg_replace("#&amp;\#([0-9]+);#si", "&#$1;", $code);

		if($added_open_tag)
		{
			$code = preg_replace("#<code><span style=\"color: \#([A-Z0-9]{6})\">&lt;\?php( |&nbsp;)(<br />?)#", "<code><span style=\"color: #$1\">", $code);
		}

		if($added_end_tag)
		{
			$code = str_replace("?&gt;</span></code>", "</span></code>", $code);
			// Wait a minute. It fails highlighting? Stupid highlighter.
			$code = str_replace("?&gt;</code>", "</code>", $code);
		}

		$code = preg_replace("#<span style=\"color: \#([A-Z0-9]{6})\"></span>#", "", $code);
		$code = str_replace("<code>", "<div dir=\"ltr\"><code>", $code);
		$code = str_replace("</code>", "</code></div>", $code);
		$code = preg_replace("# *$#", "", $code);

		if($bare_return)
		{
			return $code;
		}

		// Send back the code all nice and pretty
		return "<div class=\"codeblock phpcodeblock\"><div class=\"title\">$lang->php_code\n</div><div class=\"body\">".$code."</div></div>\n";
	}

Error:

Code:
Fatal error: Call to undefined method postParser::mycode_parse_code() in D:\Program Files\wamp\www\com\inc\class_parser.php on line 179


I see some other instances of $code in function mycode_parse_php

Do i need to change or duplicate them with new mycode tag?

Mainly i'm thinking of adding new custom tag code below the [code] function in inc/class_parser itself, if possible to create a new custom tag code which can be added from acp->mycode, i appreciate to have like that. but my priority is for changing in core class_parser file

12-09-2010 10:27 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #6
RE: custom url mycode
You said that it worked, so what do you want more?

My Blog
(This post was last modified: 12-09-2010 12:27 PM by ZiNgA BuRgA.)
12-09-2010 12:26 PM
Find all posts by this user Quote this message in a reply
1master1 Offline
Member
***
Posts: 232
Joined: Oct 2010
Post: #7
RE: custom url mycode
can we make it as addon my code? without changing the core [code] tag function in inc/class_praser, can we add additional custom mycode function below that existing [code] tag function?

function mycode_parse_code { --- }
additional custom function here   function mycode_parse_customcode { --- } with the same code functions but with that extra live links and non truncating feature without changing the main function mycode_parse_code { --- }
12-10-2010 05:31 AM
Find all posts by this user Quote this message in a reply
1master1 Offline
Member
***
Posts: 232
Joined: Oct 2010
Post: #8
RE: custom url mycode
here, i wanna make it clear.
Thanks for the edits yumi, they are working. But my intention is, we have the related functions and code for the [code] tag in inc/class_parser and i think its not a good idea to make the edits you specified to existing [code] functions.
So, i'm thinking of duplicating the [code] related functions and code in class_parser and defining it will required function name as like function mycode_parse_customname { and same [code] tag code along with the edits you specified }
Like this we can use [code] with its default functionality and the new custom code with your extra edits added.

inc/class_parser:
function mycode_parse_code { code functions }
function mycode_parse_customname { code functions + extra edits you specified }
12-15-2010 10:55 PM
Find all posts by this user Quote this message in a reply
1master1 Offline
Member
***
Posts: 232
Joined: Oct 2010
Post: #9
RE: custom url mycode
any update?
12-18-2010 12:59 PM
Find all posts by this user Quote this message in a reply
1master1 Offline
Member
***
Posts: 232
Joined: Oct 2010
Post: #10
RE: custom url mycode
(12-08-2010 03:52 PM)ZiNgA BuRgA Wrote:  For links in code tags, try this (untested), find in inc/class_parser.php:

PHP Code:
$code = str_replace('\\', '&#92;', $code);

add after:

PHP Code:
$code = preg_replace('#([>\s()]|^)((http|ftp|news)\://([^/"\s<\[.]+\.)+\w+(\:[0-9]+)?(/[^"\s<\[]*)?)#i', '$1<a href="$2">$2</a>', $code);


Sometimes, it is converting the raw links to live url links. But sometimes it is not showing the live links.

Is there any possibility to add the
if(usergroup==2)
{
$code = preg_replace('#([>\s()]|^)((http|ftp|news)\://([^/"\s<\[.]+\.)+\w+(\:[0-9]+)?(/[^"\s<\[]*)?)#i', '$1<a href="$2">$2</a>', $code);
}
01-05-2011 12:27 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: