Pictures with an img such as Only local images are allowed. generate:

HTML error while rendering tag "img": Relative URLs not allowed here

See: http://apps.facebook.com/indymedia_no/

Base-url should be added in fbml-rendering.

Comments

johanneswilm’s picture

Dave Cohen’s picture

Status: Active » Postponed (maintainer needs more info)

I see images on that page. Does that mean you fixed the problem?

At any rate, its a bad idea to use relative URLs on canvas pages. But how to solve the problem depends on how you are authoring the page. If your page is a node, and you've entered HTML with relative links, then theres nothing drupal can do for you. On the other hand, if you use something like the pathfilter module and write src="internal:path/to/image" then you'll get an absolute URL, but it might be a canvas page URL when you expected a URL directly to your site. It may be that Drupal for Facebook needs to implement a similar filter for it's own needs.

So if you want help with this, add a lot of detail to this issue, including how your page is authored, what the bad URL is, and what you think the right URL would be.

johanneswilm’s picture

Status: Postponed (maintainer needs more info) » Active

No, it is not fixed. Some pictures have absolute src-urls on other servers and they work fine.
I am actually not sure how the user edited the story but since it's not a user with root access not direct server access, it must have been through the general image-upload function. at any rate, if you want this module to properly display drupal pages in facebook it should provide for such cases. The following hack accomplishes the task, but you properly want it more properly integrated.:

function absolute_url($txt){
  $base_url = 'http://'.$_SERVER['HTTP_HOST'];
  $needle = 'src="';
  $new_txt = '';
  $new_base_url = $base_url;
  $base_url_parts = parse_url($base_url);
    while($pos = strpos($txt, $needle)){
      $pos += strlen($needle);
      if(substr($txt,$pos,7) != 'http://' && substr($txt,$pos,8) != 'https://' && substr($txt,$pos,6) != 'ftp://'){
        if(substr($txt,$pos,1) == '/') $new_base_url = $base_url_parts['scheme'].'://'.$base_url_parts['host'];
        $new_txt .= substr($txt,0,$pos).$new_base_url;
      } else {
        $new_txt .= substr($txt,0,$pos);
      }
      $txt = substr($txt,$pos);
    }
    $txt = $new_txt.$txt;
    $new_txt = '';
  return $txt;
}

and then in page.tpl.php change:

<?=$content?>

to

<?php echo(absolute_url($content)); ?>
Dave Cohen’s picture

Category: bug » feature

I worry about the code you've posted here for few reasons.

1) I think there is some inefficiency in all that string replacement for every page.
2) I'm not sure it will work for all combinations of base_url and base_path. In fact I don't think it will work when base_path is set.
3) It might interfer with one canvas page linking to another.

I'm leaning towards filters to solve the problem. As you may know, there is a pathfilter module which is useful for linking one drupal page to another. For example, "internal:node/99" will expand to the right thing, depending on base_url, base_path and clean_url settings. For DFF, I imagine a similar scheme but with more options. Possibly like this:

"fb_local:node/99" - expands to something like "http://example.com/base/path/?q=node/99". Useful for linking from a canvas page to a drupal site.

"fb_file:files/foo.gif" - expands to "http://example.com/base/path/files/foo.gif". Useful for linking to an image or any file from a canvas page.

"fb_canvas:myapp:node/99" - expands to something like "http://apps.facebook.com/myapp/node/99". Useful for linking from drupal site to a canvas page.

Does this seem like it would work for you?

I realize that not all modules will play nice with canvas pages. For instance, image_assist has its own filter scheme and I haven't tried that. This is one reason DFF is still for Drupal experts.

johanneswilm’s picture

Category: feature » bug

Yeah, I don't think you get around changing all the relative src-urls. Else DFF will simply not be compatible with lots of modules.

Your img_assist is a perfect example thereof. If you use all the standardoptions, it inserts a html-snippet like the following:

<span class="inline left"><img src="/files/images/Photo 18.thumbnail.jpg" alt="et testbilde: dette er bare en test!" title="et testbilde: dette er bare en test!"  class="image image-thumbnail" width="100" height="75" /><span class="caption" style="width: 98px;"><strong>et testbilde: </strong>dette er bare en test!</span></span>

If you instead choose the "filter tag" it inserts:

[img_assist|nid=1398|title=et testbilde|desc=dette er bare en test!|link=none|align=left|width=100|height=75]

which translates into:

  <div class="content"><p><span class="inline left"><img src="/files/images/Photo 18.thumbnail.jpg" alt="et testbilde: dette er bare en test!" title="et testbilde: dette er bare en test!"  class="image image-thumbnail" width="100" height="75" /><span class="caption" style="width: 98px;"><strong>et testbilde: </strong>dette er bare en test!</span></span></p>
<p>nncnnc</p>
<div class="image-clear"></div></div>

Loads of people will use the html-mode. And I think you'll have to calculate that most if not all will use the DFF as an alternative presentation mode for their data, not as the only mode. That is why you either need to change all modules to produce different html-output that is DFF compliant AND works with the regular http-display, or you need to filter through the code like I did.

on 1: doing string replacement in text can hardly be very work intensive, compared with tasks such as serving images

on 2: You probably are right. I just don't know what th proper way of referring to the original domain name.

on 3: I don't get it. when would that happen? "href" statements aren't changed, so it only happens when "src" is invoked, and only if no domain name is given. Cna you give me a code example where this would cause problems?

Dave Cohen’s picture

This whole thing feels hacky. Like Drupal is not built to support what we're trying to do. Not that I fault Drupal, because what we're trying to do is pretty wacky (same content on multiple URLs, where some links change depending on which URL is used).

If we add this sort of url rewriting to the theme, it seems to me it has to be configurable, because not everyone will need the overhead. And it needs to apply to the whole page (blocks, regions, etc...) not just the content.

Also, I don't think Drupal for Facebook needs to support all (or even any) third-party modules. That's why I consider this a feature request and not a bug report.

johanneswilm’s picture

ok, point taken. Makes sense to be able to turn it on or off. But not supporting img_assist without the user having to hack the main files really would make the module unusable for most cases, or not?

thollback’s picture

Category: bug » support

Hi All,

Is there a solution for the issue in this thread - the need for a filter to automatically transform relative paths to absolute paths for facebook?

Thanks,
Todd

j0nathan’s picture

Dave Cohen’s picture

Status: Active » Closed (duplicate)

FYI... I do not plan to fix this in the 5.x branch. If anyone has a fix, patches will be considered. I just think there are not enough 5.x users to justify working on it.

The other issue is against the 6.x branch. That's the one that should be of interest to most folks.