vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   How to create a article via API / auto-create of articles (https://vborg.vbsupport.ru/showthread.php?t=244747)

Adan0s 06-16-2010 07:09 PM

How to create a article via API / auto-create of articles
 
Hey there,

is there any reference or tutorial on how to create articles with the API? Or even better, is there something like a mod or a function to automatically create articles out of threads which are posted in a specific forum?

greeting

fzone 06-18-2010 10:06 AM

hi, i would also like to know if there is anyway this can be done,
I want to have an rss feed post straight to an article (primary content)
I would really appreciate it if someone could help!

Adan0s 06-20-2010 06:57 PM

*bump* any news on this? do you think the vb-team will reply with a solution if I ask them via a support ticket?

Adan0s 06-28-2010 05:26 PM

I contacted the official support and got this answer, in case someone also wants to know how to do it:

Quote:

Hello,

Thank you for contacting vBulletin Support. I am sorry but we do not support creating articles via API at this time. Such an API is scheduled for inclusion in a future version though we don't have a specific version number or date available at this time. The API is currently being written to specification and we'll make an announcement when we have more information.

leitel 11-12-2010 11:26 AM

Has anyone come up with an interim hack/mod/solution? Although the API will be very useful, I need something to import a batch of articles NOW. I'll accept any scraps / code snippets. Thank you :)

Adan0s 11-12-2010 06:26 PM

Well I got a direct response from a vB developer with some information for creating articles via own code. Also i got a code example by an user of vbulletin-germany.org.

Code Example (provided by Andreas http://www.vbulletin-germany.org/sho...96&postcount=4, modified by me):

Code:

<?php
define('VB_AREA', 'API');
require('./includes/init.php');
require_once(DIR . '/includes/class_bootstrap_framework.php');
vB_Bootstrap_Framework::init();

function create_article($sectionid, $title, $pagetext, $userid, $categoryid = '', $datestamp = '', $description = '', $htmltitle = '')
{
    global $db;
   
    if (empty($htmltitle)) $htmltitle = $title;
    if (empty($categoryid)) $categoryid = 41;

    $nodedm = new vBCMS_DM_Article();
    $nodedm->info['skip_verify_pagetext'] = true;
    $nodedm->set('contenttypeid', vB_Types::instance()->getContentTypeID('vBCms_Article'));
    $nodedm->set('parentnode', $sectionid);
    $nodedm->set('publicpreview', 1);
    $nodedm->set('comments_enabled', 1);
    $nodedm->set('pagetext', $pagetext);
    $nodedm->set('title', $title);
    $nodedm->set('html_title', $htmltitle);
    $nodedm->set('description', $description);
    $nodedm->set('userid', $userid);
    $nodedm->set('url', vB_Friendly_Url::clean_entities($title));
    $nodeid = $nodedm->save();
    if (empty($nodeid))
    {
        return false;
    }
    else
    {
        $db->query_write("INSERT INTO ". TABLE_PREFIX . "cms_nodecategory (nodeid, categoryid) values (" . $nodeid . ", $categoryid) ");
        $db->query_write("UPDATE " . TABLE_PREFIX . "cms_node SET new = 0 WHERE nodeid = $nodeid");
        if(empty($datestamp) OR $datestamp < 946681200) // if datestamp is empty or before 01.01.2000
        {
            $datestamp = TIMENOW  - vBCms_ContentManager::getTimeOffset(vB::$vbulletin->userinfo, false); // use current datestamp
        }
        $db->query_write("UPDATE " . TABLE_PREFIX . "cms_node set setpublish = 1, publishdate = $datestamp WHERE nodeid = $nodeid");
    }
           
    return $nodeid;
}

echo create_article(113, 'Headline', 'article text', 1);
?>

And the additional information by Ed Brown:

Quote:

We don't have an API. You'll have to work directly with the database insert. You'll need to put data in the following tables:

1) cms_article- the most important fields are userid (the author), pagetext, setpublish (whether the page is published) and publishdate (unix timestamp when is was/will be published. If there are images, they are referenced as [ATTACH=CONFIG]<attachmentid>[/ATTACH]. The content needs to be rendered in BBCode if it is anything but plain text.
2) cms_node. This is a modified preorder traversal table. You can ignore the nodeleft and noderight values and when you are done run a "verify and repair node table" in the admincp, which will save a lot of trouble. The most important fields are nodeid, parentnode (the nodeid of the section into which the article will go), contenttypeid, contentid (from the article table), and url
3) cms_nodeinfo. There is one record here for every record in cms_node, with the same nodeid. The most important field here is the title.
4) (if you have attachments) filedata . There must be a record here for every image you need. One image file can be referenced by multiple articles.
5) (if you have attachments) attachment. This relates the image data to the articles, and is where the permission comes from.
I built my whole e107 importer around those two bits. If you need more help just ask.

leitel 11-12-2010 06:40 PM

Thank you. It works!!

I noticed however that the new node/article is not found when searching content contained in a newly added article.

Is there a method for forcing an update of the index?

Your post made my day!!!!

--------------- Added [DATE]1289599712[/DATE] at [TIME]1289599712[/TIME] ---------------

I tried this to index the new article:

PHP Code:

vB_Search_Indexcontroller_QueueProcessor::indexNow('vBCms''vBCms_Article','index'array_slice(func_get_args(), 3)); 

Still no joy.

The last parameter is looking for an Associative Array of values. I suppose I can manually populate an array.

--------------- Added [DATE]1289600978[/DATE] at [TIME]1289600978[/TIME] ---------------

Here is the revised code to set publish ON and to index the article immediately. If you adding a batch, it would be better to find the way to index them as a batch.


PHP Code:

<?php
define
('VB_AREA''API');
define('VB_ENTRY'1);

require(
'./includes/init.php');
require_once(
DIR '/includes/class_bootstrap_framework.php');
require_once (
DIR "/vb/search/core.php");
require_once (
DIR '/vb/search/indexcontroller/queueprocessor.php');

vB_Bootstrap_Framework::init();

function 
create_article($sectionid$title$pagetext$userid$description ''$htmltitle '')
{
    global 
$db;

    if (!
$htmltitle)
    {
        
$htmltitle $title;
    }

    
$nodedm = new vBCMS_DM_Article();
    
$nodedm->info['skip_verify_pagetext'] = true;
    
$nodedm->set('contenttypeid'vB_Types::instance()->getContentTypeID('vBCms_Article'));
    
$nodedm->set('parentnode'$sectionid);
    
$nodedm->set('publicpreview'1);
    
$nodedm->set('comments_enabled'1);
    
$nodedm->set('pagetext'$pagetext);
    
$nodedm->set('title'$title);
    
$nodedm->set('html_title'$htmltitle);
    
$nodedm->set('description'$description);
    
$nodedm->set('userid'$userid);
    
$nodedm->set('publishdate'TIMENOW);
    
$nodedm->set('url'vB_Friendly_Url::clean_entities($title));
    if (!
$nodeid $nodedm->save())
    {
        return 
false;
    }
    else
    {
        
$db->query_write("UPDATE " TABLE_PREFIX "cms_node SET new = 0, setpublish = 1 WHERE nodeid = $nodeid");
    }
    
$data['nodeid'] = $nodeid;
    
$data['pagetext'] = $pagetext;
    
vB_Search_Indexcontroller_QueueProcessor::indexNow('vbcms''article','index'$data);
    return 
$nodeid;
}
create_article(1'Now is the time for all good martians...''Dies ist ein Test'1'foo');

:

Please feel free to share any other code snippets such as adding tags, etc. to an article.

Thanks again for the useful suggestions.

Adan0s 11-13-2010 07:31 AM

Quote:

2) cms_node. This is a modified preorder traversal table. You can ignore the nodeleft and noderight values and when you are done run a "verify and repair node table" in the admincp, which will save a lot of trouble. The most important fields are nodeid, parentnode (the nodeid of the section into which the article will go), contenttypeid, contentid (from the article table), and url
this should normaly update the index.

to add tags, just add the following line into the method:

Code:

$nodedm->set('keywords', $keywords);
and append an additional variable to the top

Code:

function create_article($sectionid, $title, $pagetext, $userid, $description = '', $htmltitle = '', $keywords = '')

leitel 11-13-2010 10:59 AM

I did a test to see if item is added to the index after it is added. I removed my code:
PHP Code:

    //$data['nodeid'] = $nodeid;
    //$data['pagetext'] = $pagetext;
    //vB_Search_Indexcontroller_QueueProcessor::indexNow('vbcms', 'article','index', $data); 

I added an article and it was not found using search.

I added the param for keywords and that works great.

However, I don't see a method for associating tags vs keywords. I am referring to the tags that form the basis for tag cloud.

--------------- Added [DATE]1289654370[/DATE] at [TIME]1289654370[/TIME] ---------------

I was mistaken. My code to immediately update index with new article is wrong. It isn't working. I also tried Verify and Repair Node Table.

Adan0s 11-13-2010 11:50 AM

Sorry, thought the keywords were interpreted as tags.

To add tags to the article look in the following class:

Quote:

includes/class_taggablecontent.php
The following function is propably the thing you are searching for. Unfortunately I also don't know how exactly to use it. You propably need to create an entity of vB_Taggable_Content_Item, add the appropriate information (public static function create($registry, $contenttypeid, $contentid, $contentinfo = null)) and then use the following method:

Quote:

public function add_tags_to_content($taglist, $limits)


All times are GMT. The time now is 06:48 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.01180 seconds
  • Memory Usage 1,793KB
  • 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
  • (3)bbcode_code_printable
  • (3)bbcode_php_printable
  • (5)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete