PDA

View Full Version : VBCMS Plugin Woes


Carpesimia
07-19-2011, 07:22 PM
Hi Team,

I'm trying to write a plugin that will affect each of the articles on the VBCMS home. I want to evaluate something for each article, and if i find what I am looking for, I want to show some text or an image on that specific preview.

So, I've run into some issues:

1) I cannot even get anything from a plugin to show in the "vbcms_content_article_preview" template. None of the vbcms_xxxx hooks worked, so i even tried global_start (which im using for similar logic in navbar template), which still doesnt work. Here's my test code:

Hook: global_start

Code:

$testme = "abc123cba";

vB_Template::preRegister('vbcms_content_article_pr eview',array('testme' => $testme));

inside my vbcms_content_article_preview template, i have:

:{vb:raw testme}:

All I see is "::", the variable doesnt show.

----------------------------------------------------------

2) I want to process my logic for EACH article on the page. So I need a hook that gets fired multiple times, and allows me to send output to the template in question for each iteration.


I have paid support over at vbulletin.com, but they sent me over here anyways, as youse guys are the bomb.
----------------------------------------------------------

An example of this plugin, might be to show a small graphic for new articles, vs articles over a week old, vs articles over a month old.

Please give a hand, as Im ripping out what little hair i have left!!

Dead Eddie
07-19-2011, 08:59 PM
If you're just doing it on the preview, try this:

Hook name: vbcms_article_populate_end

if(self::VIEW_PREVIEW == $viewtype){
$view->custom='I am the very model of a modern major general';
}

Then, within the "vbcms_content_article_preview" template, your variable is {vb:raw custom}.

Carpesimia
07-19-2011, 09:09 PM
If you're just doing it on the preview, try this:

Hook name: vbcms_article_populate_end

if(self::VIEW_PREVIEW == $viewtype){
$view->custom='I am the very model of a modern major general';
}

Then, within the "vbcms_content_article_preview" template, your variable is {vb:raw custom}.


Excellent! That works.

Now, the next question. How do i find the node-id for the current article iteration? I believe that it is piece i am still missing.

Dead Eddie
07-19-2011, 09:34 PM
$this->getNodeId();

Although, you already have a wealth of information available to you about the article at this hook already. What do you need the node id for?

Lynne
07-19-2011, 10:17 PM
(global_start is deprecated - do a search in your files and you will see this. So, it is not evaled at all in the CMS pages.)

Carpesimia
07-20-2011, 12:01 AM
$this->getNodeId();

Although, you already have a wealth of information available to you about the article at this hook already. What do you need the node id for?

Im using special tags to discern a special meaning for different articles. If you have the tag, I need to show a special graphic on the preview page. So I need the nodeid so I can check for the presence of the tag. If the tag exists, I'll fill in my var and the image will appear on the page.

This was the best way to do it and still remain non-intrusive.

--------------- Added 1311123733 at 1311123733 ---------------

(global_start is deprecated - do a search in your files and you will see this. So, it is not evaled at all in the CMS pages.)

AH! Makes sense. Wish the support rep I had on the phone earlier told me that. He just agreed it should work, and sent me here.

Dead Eddie
07-20-2011, 12:23 AM
You're talking about default, vBulletin tags? You'll actually need the contenttypeid/contentid, not the nodeid.


$this->content->getContentTypeId();
$this->content->getContentId();


If you haven't found it yet...use the taggablecontent class. Won't save you a query...but it'll save you from rewriting one. :)

Carpesimia
07-20-2011, 12:37 AM
You're talking about default, vBulletin tags? You'll actually need the contenttypeid/contentid, not the nodeid.


$this->content->getContentTypeId();
$this->content->getContentId();


If you haven't found it yet...use the taggablecontent class. Won't save you a query...but it'll save you from rewriting one. :)

Actually hadnt tested yet, but I had assumed it was nodeid. Just hadnt gotten that far yet. Thanks! Where do i find info on the taggablecontent class? I have already written my query, but am all about doing things the proper way when possible.

Dead Eddie
07-20-2011, 01:00 AM
Not sure if one way is more "proper" than the other, but here's what you're looking at...


require_once DIR . '/includes/class_taggablecontent.php';
$taggable = vB_Taggable_Content_Item::create(vB::$vbulletin, $this->content->getContentTypeId(), $this->content->getContentId(), $this->content);
$tag_list = $taggable->fetch_existing_tag_list();


You can look at /includes/class_taggablecontent.php for more information on using the class.

nirvana43
10-30-2011, 11:26 AM
For future referance :
If you want to get nodeId of all articles on that page then create a plugin at hook : vbcms_article_populate_start

And then below will get you nodeId of each article :
$this->content->getNodeId()

Note that it is content->getNodeId() and not node->getNodeId().

Cheers!
Aditya Hajare

P.S. I'm assuming you know all about pre-registering vars to templates etc. etc. Thats why i'm not writing this in details. But if you want sample code then lemme know. Cheers!