vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Hook to modify article content (https://vborg.vbsupport.ru/showthread.php?t=290414)

kvnband 11-09-2012 05:07 PM

Hook to modify article content
 
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

Code:

$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 [DATE]1352487282[/DATE] at [TIME]1352487282[/TIME] ---------------

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:

Code:

// 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 [DATE]1352490271[/DATE] at [TIME]1352490271[/TIME] ---------------

It looks like
Code:

$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:

Code:

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.


All times are GMT. The time now is 11:01 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01114 seconds
  • Memory Usage 1,736KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (13)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete