BB Code Media Site - Match Url - is there a way to make "P<id>" capture also the slash "/" ?

cclaerhout

Well-known member
P<id> normal behaviour is to capture the string between slashes. But I would need to capture also what is behind slash.

Example: https://picasaweb.google.com/myaccount/myalbum

I need to capture myaccount AND myalbum to manipulate them in the callback. But It's not possible.

Of course, I could use the BB Code system to do this, but I would certainly face the problem of "autolinking" problem.

It's quite frustrating to spend hours doing things which requires normally a few minutes.
 
Actually that is what I use
PHP:
#https?://picasaweb\.google\.com/(?P<id>.+/.+)$#s
But it returns me "h"...
 
I've tested it again... If I paste my link, it doesn't work. But if I add a letter or a number to my link, it's working... I don't get it...

Link example:
Code:
https://picasaweb.google.com/cedric.claerhout/TepcoPhotos?authkey=Gv1sRgCP_t6quEt8nFmgE
Returns me a "h"

But If I delete letter, or add something, it's working...
 
I wanted to go further than the previous problem so I've tried this:
Code:
[media=picasa_slideshow]cedric.claerhout/TepcoPhotos?authkey=Gv1sRgCP_t6quEt8nFmgE[/media]

For the purpose of the test, my Embed HTML was the following one:
Code:
<div>{$id}</div>

And it doesn't work. The result is blank. Why ? Because the question mark (?) :(
If I delete it, it's working then.
 
1st capture problem: fixed
With this regex, it's working:
Code:
#https?://picasaweb\.google\.com/(?P<id>.+/.+(?:\?authkey=.+)?)$#siU
It appears the question mark was again the problem. So I put that section like an option. Adn this time, strangely, it works.

2nd problem: no fixed
Unfortunately it doesn't fix the problem described in my previous post. And this problem also causes direct URL inputs (without using the Media BB Code button) aren't modified.
 
Correct. The ID can't contain a question mark. I believe this code is responsible:

library/XenForo/BbCode/Formatter/Base.php

Rich (BB code):
	public function renderTagMedia(array $tag, array $rendererStates)
	{
		$mediaKey = trim($this->stringifyTree($tag['children']));
		if (preg_match('#[&?"\'<>\r\n]#', $mediaKey) || strpos($mediaKey, '..') !== false)
		{
			return '';
		}

		$mediaSiteId = strtolower($tag['option']);
		if ($mediaSiteId == 'youtube')
		{
			// youtube iframe embed bug workaround
			$mediaKey = str_replace('/', '', $mediaKey);
		}
		if (isset($this->_mediaSites[$mediaSiteId]))
		{
			$embedHtml = $this->_getMediaSiteHtmlFromCallback($mediaKey, $this->_mediaSites[$mediaSiteId]);

			if (!$embedHtml)
			{
				$embedHtml = $this->_mediaSites[$mediaSiteId]['embed_html'];
				$embedHtml = str_replace('{$id}', urlencode($mediaKey), $embedHtml);
			}

			return $embedHtml;
		}
		else
		{
			return '';
		}
	}

These characters aren't allowed:

&
?
"
'
<
>
\r (carriage return)
\n (new line)

This sanitization is to prevent any kind of injection into the HTML.
 
You can use callbacks to handle more complex matching. This is the most complicated media site I have done:

http://xenforo.com/community/threads/add-more-video-sites-bb-code-media.7608/page-8#post-275820

It's a good example of how far you can go with callbacks. I had to scrape the web page, extract two separate values for the ID, delimit them with a pipe, and then extract them in a separate callback to build the embed code. I had to extract the exact pieces I needed. I couldn't just pass the entire query string because it contained some of those disallowed characters.
 
You can use callbacks to handle more complex matching. This is the most complicated media site I have done:

http://xenforo.com/community/threads/add-more-video-sites-bb-code-media.7608/page-8#post-275820

It's a good example of how far you can go with callbacks. I had to scrape the web page, extract two separate values for the ID, delimit them with a pipe, and then extract them in a separate callback to build the embed code. I had to extract the exact pieces I needed. I couldn't just pass the entire query string because it contained some of those disallowed characters.

First of all, thank you to have identified the source of the problem.

Then I can't use what you did. In your example you choose to use the {$id} (so not to use regex). But if I do that, the capture part of the url will stop at the slash tag and won't go further. The Callback isn't the problem, actually it's already written... but to work he needs XenForo to send him datas.

I'm going to try again to see if I can manage to make this callback works with the BB Code system. Otherwise, I will listen Model libraries and will play with the post model to be able to capture what I want.
 
I manage to make it work with the BB code solution. I still need to create the administration configuration options and then I will release it.
 
Top Bottom