1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'XenForo Development Discussions' started by cclaerhout, Feb 15, 2012.

  1. cclaerhout

    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.
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  3. cclaerhout

    cclaerhout Well-Known Member

    Actually that is what I use
    But it returns me "h"...
  4. cclaerhout

    cclaerhout Well-Known Member

    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:
    Returns me a "h"

    But If I delete letter, or add something, it's working...
  5. cclaerhout

    cclaerhout Well-Known Member

    I wanted to go further than the previous problem so I've tried this:
    For the purpose of the test, my Embed HTML was the following one:
    And it doesn't work. The result is blank. Why ? Because the question mark (?) :(
    If I delete it, it's working then.
  6. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Did you enable Use 'Match URLs' as PCRE regular expressions under Advanced Options?
  7. cclaerhout

    cclaerhout Well-Known Member

    1st capture problem: fixed
    With this regex, it's working:
    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.
  8. cclaerhout

    cclaerhout Well-Known Member

    Yes of course.
  9. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Correct. The ID can't contain a question mark. I believe this code is responsible:


    	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;
    			return '';
    These characters aren't allowed:

    \r (carriage return)
    \n (new line)

    This sanitization is to prevent any kind of injection into the HTML.
    cclaerhout likes this.
  10. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    You can use callbacks to handle more complex matching. This is the most complicated media site I have done:


    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.
  11. cclaerhout

    cclaerhout Well-Known Member

    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.
  12. cclaerhout

    cclaerhout Well-Known Member

    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.

Share This Page