PDA

View Full Version : Hook to modify article content


kvnband
11-09-2012, 05:07 PM
Hi there. I need to modify the article content output for our articles based on preset criteria. I believe the hook I need is vbcms_article_populate_start, but 'pagetext' is protected so I can't modify it.

Where should I be looking in order to accomplish what I need?

kh99
11-09-2012, 05:48 PM
I don't have much experience with the CMS, but maybe try something like

$pagetext = $this->content->getPageText();
// do stuff to $pagetext here
$this->content->setProperty('pagetext', $pagetext);

kvnband
11-09-2012, 05:51 PM
Ah - I didn't know about setProperty. I'll investigate that in a bit.

Thanks!

--------------- Added 1352487282 at 1352487282 ---------------

Unfortunately, setProperty is also protected and I can't do anything with it.

Fatal error: Call to protected method vB_Item::setProperty() from context 'vBCms_Content_Article'

Sorry for what are surely stupid questions - This is my first time hooking into the CMS and it's very new to me.

kh99
11-09-2012, 05:56 PM
Yeah, I just decided I should try it myself and got the same error. Don't worry, they aren't stupid questions, but unfortunately I don't know the answers. I'll see if I can figure out something else - it might be possible to replace the content object with a new one.

kh99
11-09-2012, 06:05 PM
Edit: oh, no, you might not want to do the setInfo thing I posted - it seems to be changing the articles even after I disable the plugin. It might just be a cache, I'm not sure, but I don't want you to risk changing anything permanently.

Yep, the code I posted here then deleted seems to have permanently changed the content of some of my articles (but it's just a test system). That may or may not be a problem for you, maybe it's OK with you if they're chnaged in the db.

kh99
11-09-2012, 06:22 PM
OK, I really hope none of your articles got messed up by the last thing I posted, but I think this works: try using hook vbcms_article_populate_end and something like this:

// Make changes to $pagetext var, then
$view->pagetext = $pagetext;

kvnband
11-09-2012, 06:35 PM
I actually figured that one out right before you posted it. The problem is that it loses all bbcode formatting when I use it. I'mn trying to walk through the PHP code where it renders the bbcode, but so far haven't come up with what I need.

We're definitely on the right path though.

--------------- Added 1352490271 at 1352490271 ---------------

It looks like $this->rendered['pages'][$this->parameters['page']]; is the rendered view, but that doesn't do any good. I think we need to get the raw pagetext (Stored in $pagetext), do our processing to it, and then run it through the renderer and assign it to $view->pagetext. I just don't know how we can parse the bbcode, line breaks, smileys, etc....

Is there a built-in vb function that does all of that parsing that we can just call?

kh99
11-09-2012, 07:12 PM
Yeah, sorry again. I tried it with an article that only had one sentence so I didn't notice the bbcode problem. But you obviously need someone who knows about it instead of someone to help you guess at things. :) It might take a while though, I don't think everyone visits here every day.

kvnband
11-09-2012, 07:19 PM
Well you've definitely been a huge help, for sure. Hopefully someone else can chime in soon with the solution or I can figure it out with some more head banging :)

kh99
11-09-2012, 07:53 PM
OK, I did think of another possible approach: use hook template_render_ouput and do something like:

if ($this->template == 'vbcms_content_article_page')
{
// do something to $pagetext here.
}


At that point $pagetext will be html.

kvnband
11-09-2012, 08:03 PM
When was template_render_output introduced? Because I don't have that hook available here. All I've got is template_compile

kh99
11-09-2012, 08:13 PM
Oh, right - that was just added with 4.2.0. I guess if you wanted to you could add it manually, then if you ever update to 4.2.0 it will continue to work. (Of course if you ever restore the files of the version you have now, it would break).

kvnband
11-09-2012, 08:19 PM
Yeah, I'll give that a shot. This site is definitely not able to be upgraded right now, so manually adding the hook may be our best bet.

Thanks for your help. Hopefully this works for us.