View Full Version : Adding Content Types
dfidler
03-22-2010, 10:07 PM
Hi All,
I am starting work on a plugin that I want to integrate into the vb4 attachment system, which involves adding a new contenttype. I've done some work around this already but have run into a few roadblocks along the way and figured that someone must have tried this already and I'm hoping that they've kept some crib notes.
I know that you need to add a new contenttype (and product), add a php file to /packages/attach/mynewtype.php.
But there seems to be a lot more than that.
Anyways, I'll get there in the end, but if someone does have some crib notes on how they got this done I'd really love to see them. I usually only have 3-5 hours per week to program so you could be saving me weeks of time. :)
Cheers,
Dave.
dfidler
04-01-2010, 09:02 AM
Never mind, I got it. This system is really flexible, but there are a lot of special cases that you have to dig through to get it to work.
I'm taking detailed notes so when I'm confident that i've got it all figured out, I'll post a tutorial on it.
Cheers,
Dave.
leitel
11-11-2010, 09:52 PM
I need to import a number of articles. I am trying to hack together a quick function. What follows is my initial attempt. Is there a more elegant approach?
<?php
define('VB_PRODUCT', 'vbcms');
define('VB_ENTRY', 1);
define('VB_ROUTER_SEGMENT', 'content');
define('GET_EDIT_TEMPLATES', 'picture');
define('CMS_SCRIPT', true);
define('THIS_SCRIPT', 'vbcms');
define('FRIENDLY_URL_LINK', 'vbcms');
// here I commented out:
// print_output(vB_Router::getResponse());
require_once('vb/_bootstrap.php');
// here I extended
// class whip_vBCms_Content_Article extends vBCms_Content_Article
require_once('_whip_vBCms_Content_Article.php');
$vBArticle = new whip_vBCms_Content_Article();
$contenttypeid = "18";
$sectionid = 1;
$parentnodeid = 1;
vB::$vbulletin->GPC_exists['parentnode'] = true;
vB::$vbulletin->GPC_exists['sectionid'] = true;
vB::$vbulletin->GPC['sectionid'] = $sectionid;
vB::$vbulletin->GPC_exists['new_contenttype'] = true;
vB::$vbulletin->GPC['parentnode'] = $parentnodeid;
try
{
$nodedm = new vBCms_DM_Article();
// create content handler
$content = vBCms_Content::create(vB_Types::instance()->getContentTypePackage($contenttypeid), vBCms_Types::instance()->getContentTypeClass($contenttypeid));
// insert default content for the contenttype and get the new contentid
$content->setParentNode(vB::$vbulletin->GPC['sectionid']);
$contentid = $content->createDefaultContent($nodedm);
}
catch (vB_Exception $e)
{
throw (new vB_Exception_DM('Could not create default content. Exception thrown with message: \'' . htmlspecialchars_uni($e->getMessage()) . '\''));
}
// Create new content node
$nodedm->set('contenttypeid', $contenttypeid);
$nodedm->set('contentid', $contentid);
$nodedm->set('parentnode', $sectionid);
$nodedm->set('title', (vB::$vbulletin->GPC_exists['section_title']?
vB::$vbulletin->GPC['section_title'] : vB::$vbulletin->GPC['section_title']) );
//allow child nodes to set the author. This is necessary when we
//promote a post
if (! $nodedm->getSet('userid'))
{
$nodedm->set('userid', vB::$vbulletin->userinfo['userid']);
}
$nodedm->setField('title', 'larry');
if (!($nodeid = $nodedm->save()))
{
throw (new vB_Exception_DM('Could not create new node for content: ' . print_r($nodedm->getErrors())));
}
$vBArticle->createDefaultContent($nodedm);
vB_Cache::instance()->event('section_nav_' . vB::$vbulletin->GPC['sectionid']);
vB_Cache::instance()->event('sections_updated');
vB_Cache::instance()->event('articles_updated');
vB_Cache::instance()->cleanNow();
echo '';
I know this is a bit of a slop job but just trying to gen something to get the ball rolling.
Thank you :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.