Please help me to finish my inlineRegexp plugin to append href to posts


(Admir Hodzic) #1

I am trying to append links inside my posts with external sources.
I want to parse my posts and find attached files inside posts.
For those files I want to append external links in hope that I am going to get oneboxing.
My pure JS looks like this

http://jsfiddle.net/adopilot/g44Nq/

Unfortunately I can’t find way to combine this with Discourse.Dialect.inlineRegexp
I read twice

My reqex is bit complicated I have to do two way parsing to get needed results.

I am wondering how I can have several functions and operations inside Discourse.Dialect.inlineRegexp
to emit only one .
Is there any other function which can append HTML to post ?


(Mittineague) #2

This old code from phpBB includes/bbcode.php uses several regex patterns

	// matches a [url]xxxx://www.phpbb.com[/url] code..
	$patterns[] = "#\[url\]([\w]+?://([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is";
	$replacements[] = $bbcode_tpl['url1'];

	// [url]www.phpbb.com[/url] code.. (no xxxx:// prefix).
	$patterns[] = "#\[url\]((www|ftp)\.([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is";
	$replacements[] = $bbcode_tpl['url2'];

	// [url=xxxx://www.phpbb.com]phpBB[/url] code..
	$patterns[] = "#\[url=([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is";
	$replacements[] = $bbcode_tpl['url3'];

	// [url=www.phpbb.com]phpBB[/url] code.. (no xxxx:// prefix).
	$patterns[] = "#\[url=((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is";
	$replacements[] = $bbcode_tpl['url4'];

(Admir Hodzic) #3

I still do not know How I cluod append (add) my new html inside topic.
Also I have no clue how I cloud subtract numbers using regexp.


(Robin Ward) #4

I’m sorry I don’t fully understand what you’re trying to do here.

Can you give me an example of the input you want and the HTML output you are looking for?


(Admir Hodzic) #5

Thanx on trying to help.

This is raw post from genrated by e mail from my voip server

Postovani Servis Agent 1:

	Stigla je nova govorna poruka u trajanju od 0:10 min:sec (ukupno 24 poruke)
 u vBox 771 od pozivaoca "PSTN-033771625" <033771625>, na dan 17.07.2014 u 17:19:03.


				--ROBOT - SERVISNA SLUZBA - KONTAKT CENTAR
 !!!771!!!.


$$$24$$$.
<a class='attachment' href='/uploads/default/1795/100123d19325fec1.WAV'>msg0024.WAV</a> (16.1 KB)

Since discourse do not allow oneboxing of self hosted WAV files.
I am trying to rewrite this post to include HREF (link) to WAV file on other server whic can be played and one boxed

I want to acording to this href inside post add my href wit link with extened one boxed file

I want to add my link

Postovani Servis Agent 1:

	Stigla je nova govorna poruka u trajanju od 0:10 min:sec (ukupno 24 poruke)
 u vBox 771 od pozivaoca "PSTN-033771625" <033771625>, na dan 17.07.2014 u 17:19:03.


				--ROBOT - SERVISNA SLUZBA - KONTAKT CENTAR
 !!!771!!!.


$$$24$$$.
<a class='attachment' href='/uploads/default/1795/100123d19325fec1.WAV'>msg0024.WAV</a> (16.1 KB)

http://172.16.0.54/vbox-msg/771/INBOX/msg0023.wav

(Robin Ward) #6

I see, so your importer adds the file attachment and you want the player to be embedded in the post.

@zogstrip where is that HTML inserted for attachments? Could the format of the HTML be overridden by a plugin so that people could put players in there?


(Régis Hanol) #7

One solution would be to remove the .wav extension from the list of authorized extensions and thus Discourse won’t consider uploading wave files.


(Admir Hodzic) #8

I do not have problem with uploads.
What I want is to add HERF (link) inside topic according to text of topic.
I am looking for way to add my link inside topic.
It can be done by Discourse.Dialect.inlineRegexp .
My problem is that I have multiple regexp expressions for one task, also to get needed results I need to do mathematical operations on regexp matches. Is there any Discourse.Dialect which can inserts HTML inside topics using javascript functions as you show us how we can have independent JavaScript functions when we operate with texts in Pirate Speak (sample , turtorial)