I'm using the BBCode module for my new blog and I love it (great module, thanks so much!) but there's one drawback currently:

The BBCode filter is not applied to the RSS feed. Which is kind of ugly if you consider the difference from the website to the newsfeed. (You can try out the feed from my blog to check on it.)

It would be awesome if the filter was also applied to the feed, as is, because RSS just ships HTML like standard web pages do.

CommentFileSizeAuthor
#31 blog_with_node_by_ref.diff.txt869 bytesAnonymous (not verified)
#30 node_by_ref.diff.txt3.29 KBAnonymous (not verified)
#12 hook_view_by_ref.patch1.55 KBdrewish
#10 blog_11.patch.txt631 bytesforngren
#7 blog_10.patch900 bytesRobRoy
#3 node_rss.patch634 bytesdrewish

Comments

jpetso’s picture

Hm... I just noticed that it does work on the earlier version of my blog on localhost. I haven't changed anything in regard with input filters though, so I have no idea why it works locally and fails with the online version. Maybe I'll just try upgrading to today's rc1... I guess the BBCode module isn't responsible for this, or at least it seems to be that way.

jpetso’s picture

Project: Bbcode » Drupal core
Version: 5.x-1.x-dev » 5.0-beta2
Component: Code » filter.module

Talking to drewish on IRC, it seems probable that there's some difference between PHP4 (which is installed on the server, v4.4.4) and PHP5 (which is installed on my local PC, v5.1.6). Quote:

<drewish> jpetso: that makes me wonder if it's a by reference difference between PHP4 and 5

I also tested the RSS feed with urlfilter, and as that doesn't work as well I'm reassigning this bug to Drupal core.

drewish’s picture

Title: RSS feeds are not BBCode-filtered » Filters not applied to RSS feeds
Version: 5.0-beta2 » 5.0-rc1
Component: filter.module » node.module
StatusFileSize
new634 bytes

The node being called needs to be returned not passed by reference.

drewish’s picture

Status: Active » Needs review

it's got a patch

drewish’s picture

i'd love some reviews...

joshk’s picture

Status: Needs review » Needs work

I think this may be a misdiagnosis of the problem. Some filters (e.g. the basic html filter, url-to-link maker) are applied, although BBcode changes are not in evidence. However, patch doesn't make bbcode work for me. I think the issue may be with how bbcode module does its translations.

Here's my test node:

I [b]need[/b] this to work.

And I need <em>this</em> to work, too.

What about my site? http://www.outlandishjosh.com

Viewing this node with the base "filtered html" setting + bbcode gives the expected result. Viewing source, here's what's being output to the browser:

<!-- begin content -->
<div id="node-1" class="node">



      <span class="submitted">Thu, 12/28/2006 - 00:06 — <a href="/~joshk/drupal5/?q=user/1" title="View user profile.">joshk</a></span>
  
  <div class="content">
    <p><p>I <span style="font-weight:bold">need</span> this to work.</p>

<p>And I need <em>this</em> to work, too.</p>
<p>What about my site? <a href="http://www.outlandishjosh.com" title="http://www.outlandishjosh.com"><a href="http://www.outlandishjosh.com">http://www.outlandishjosh.com</a></a></p>
</p>  </div>

  <div class="clear-block clear">
    <div class="meta">
        </div>

          <div class="links"><ul class="links inline"><li class="first comment_add"><a href="/~joshk/drupal5/?q=comment/reply/1#comment_form" title="Share your thoughts and opinions related to this posting." class="comment_add">Add new comment</a></li>
</ul></div>
      </div>

</div><div id="comments"></div><!-- end content --> 

Notice that the [b] has turned into a <span> declaration with inline CSS style. I think that may be the issue. Here's the source from the rss feed:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://vitus.chn.comcast.net/~joshk/drupal5" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>Drupal - </title>
 <link>http://vitus.chn.comcast.net/~joshk/drupal5</link>
 <description></description>
 <language>en</language>
<item>
 <title>Test</title>
 <link>http://vitus.chn.comcast.net/~joshk/drupal5/?q=node/1</link>
 <description>&lt;p&gt;&lt;p&gt;I &lt;span style=&quot;font-weight:bold&quot;&gt;need&lt;/span&gt; this to work.&lt;/p&gt;

&lt;p&gt;And I need &lt;em&gt;this&lt;/em&gt; to work, too.&lt;/p&gt;
&lt;p&gt;What about my site? &lt;a href=&quot;http://www.outlandishjosh.com&quot; title=&quot;http://www.outlandishjosh.com&quot;&gt;&lt;a href=&quot;http://www.outlandishjosh.com&quot;&gt;http://www.outlandishjosh.com&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;/p&gt;</description>
 <comments>http://vitus.chn.comcast.net/~joshk/drupal5/?q=node/1#comments</comments>
 <pubDate>Wed, 27 Dec 2006 16:06:29 -0800</pubDate>
 <dc:creator>joshk</dc:creator>
 <guid isPermaLink="FALSE">1 at http://vitus.chn.comcast.net/~joshk/drupal5</guid>
</item>
</channel>
</rss>

This is the same with or without the patch. It seems that the data is being put into the feed, and it's really a matter of the receiving end of the rss being able to parse the span with inline style data. Firefox certainly doesn't.

RobRoy’s picture

Title: Filters not applied to RSS feeds » Blog module not implementing hook_view() correctly
Version: 5.0-rc1 » 5.x-dev
Component: node.module » blog.module
Status: Needs work » Needs review
StatusFileSize
new900 bytes

Yeah, I just looked into it and hook_view says that you should modify the passed-by-reference node AND return that node. It's a bit odd, but this issue should be against blog_view() and maybe should look like this patch. Is this only with blog.module? Do page taxonomy feeds work okay? Please recatgorize if this patch doesn't help or you feel it's not the right approach.

With that said, I cannot reproduce this error on a fresh copy of 5.x-dev using PHP 4.4.4, so I'll try and do a test on PHP 5 later if this patch doesn't resolve the problem.

See http://api.drupal.org/api/HEAD/function/hook_view to see how the example does it.

dries’s picture

Is chunk required?

-  return node_prepare($node, $teaser);
+  $node = node_prepare($node, $teaser);
+  return $node;

It's prone to error, IMO, as people will tend to optimize that code to 'return node_prepare()'.

drewish’s picture

Dries, I agree it does seem really awkward. Since this is a change from 4.7 it really ought to be documented in the module update guide as such.

forngren’s picture

StatusFileSize
new631 bytes

Patch without the chunk. Aint it beautiful? One changed byte.

drewish’s picture

forngren, that won't work because node_prepare() doesn't take $node by reference.

drewish’s picture

StatusFileSize
new1.55 KB

this fixes the poll module which also doesn't take $node by reference. it also adds a comment to explain the purpose of the "extra" operation.

please pardon the DOS line endings.

RobRoy’s picture

@forngren/Dries - This chunk is definitely intentional and required because of the explanation drewish gave above. Look at the http://api.drupal.org/api/HEAD/function/hook_view example and docs. We need to set $node to change the referenced $node and then return it to be consistent with what the docs say, so IMO my patch still stands.

-  return node_prepare($node, $teaser);
+  $node = node_prepare($node, $teaser);
+  return $node;
drewish’s picture

i hope what robroy meant was his patch with my poll module addition stands ;) i'd really rather not have to try to re-explain it in another issue.

RobRoy’s picture

@drewish, Yeah, that poll inclusion is good. In theory it should be in another issue, but it's pretty small so it's probably alright here. Small nit: there needs to be a period at the end of the blog_view comment you added.

RobRoy’s picture

Oh and you can download Notepad++ to easily convert patches to Unix line endings.

drewish’s picture

robroy, i'd almost added a period but the bread crumb comment above didn't have one and i couldn't remember what the "official" style was.

usually i use dos2unix to convert line endings but i hadn't had a chance to dig up a copy on this computer.

Anonymous’s picture

Is the returned value used? The issue here is that the node_view change allows for $node within the function to modify the array memory area as given by the caller so that when the callee modifies the value and then returns the caller already has the changes. So, there is no reason to return $node from the callee.

RobRoy’s picture

@drewish - The official style is to have a period at the end, so any added comments should conform to this style IMO, even if surrounding comments do not.

@earnie - Please see http://api.drupal.org/api/HEAD/function/hook_view as I stated above. "The passed-by-reference $node parameter should be modified as necessary and returned so it can be properly presented by theme('node', $node)."

drewish’s picture

earnie, it is used. take a look at node_build_content(). my original proposal in comment #3 was to just have node_feed() work the same way.

Anonymous’s picture

Ok, you'll need to forgive my ignorance here but I still don't see a need to return $node from blog_view or hook_view. The return actually removes the advantage of passing the node array by reference. So I would code the chunk as

<?php
-  return node_prepare($node, $teaser);
+  $node = node_prepare($node, $teaser);
?>

because of this chunk

<?php
-function blog_view($node, $teaser = FALSE, $page = FALSE) {
+function blog_view(&$node, $teaser = FALSE, $page = FALSE) {
?>

With the change to pass the node array by reference then code that does something like ``$node = mymodule_view($node);'' is wrong since it removes all hope of needing the call by reference in the first place.

BTW, I think the call by reference change for the node array needs extended to node_prepare as well but that is a different issue.

RobRoy’s picture

@earnie - Yes, I understand what you're saying, but this change is to get existing view hooks to work as described on the api docs. Your issues for hook_view and hook_prepare would be two separate API changing issues for D6 as the current implementation seems to require both pass by reference and returning that node for certain direct calls to hook_view as stated in the docs.

Anonymous’s picture

@drewish: As I read your patch given in node_rss.patch per #3 in review of hook_view, it shouldn't be needed.

@RobRoy: Which is the reason I asked if it was used when I chimed in. However, hook_view needs patched to remove the return and node_prepare needs patched to make use of call by reference for the node array for the next API change release.

Now where is that TODO list? :)

Anonymous’s picture

@drewish: dos2unix can be found in http://downloads.sf.net/mingw/mingw-utils-0.3.tar.gz. The file is only a 1.5MB download.

heine’s picture

Priority: Normal » Critical

We need to get this straight as ambiguity can lead to nasty XSS problems on PHP 4.

Either we fix the hook_view docs and apply drewish's patch in #3, making a return $node mandatory for hook_view (my preference) or we rewrite node_build_content and node_prepare to work with the a reference to $node.

chx’s picture

Status: Needs review » Reviewed & tested by the community

First of all, there is no easy solution here, we are late in cycle and need to change something. My 2c is on http://drupal.org/files/issues/node_rss.patch and fixing hook_view documentation. Less references are always better.

dries’s picture

I agree with chx (#26). Let's go with that patch, and make sure the documentation gets fixed. We're in a code freeze, but it is not too late to fix critical bugs elegantly.

RobRoy’s picture

I agree with that. I did a quick search to make sure that no other invoke calls to hook_view expect the referenced node to be changed, and they don't. I'll update the docs now.

RobRoy’s picture

HEAD docs for hook_view and node_example_view have been updated.

Anonymous’s picture

StatusFileSize
new3.29 KB

I actually tried a modification yesterday of node_build_content and node_prepare as in the attached file. I'll post a second file with the blog.module changes needed since I can only attach one file per post. The changes are against HEAD.

Anonymous’s picture

StatusFileSize
new869 bytes

And the blog.module changes

drumm’s picture

Status: Reviewed & tested by the community » Fixed

I committed the patch agreed upon by Dries and chx since the documentation seems to be moving.

RobRoy’s picture

@earnie - Those are separate issues and are probably best suited for 6.x-dev.

Anonymous’s picture

Status: Fixed » Closed (fixed)