Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-16-2010, 07:09 PM
Adan0s Adan0s is offline
 
Join Date: May 2008
Location: Germany
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #2  
Old 06-18-2010, 10:06 AM
fzone fzone is offline
 
Join Date: Jan 2010
Posts: 2
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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!
Reply With Quote
  #3  
Old 06-20-2010, 06:57 PM
Adan0s Adan0s is offline
 
Join Date: May 2008
Location: Germany
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

*bump* any news on this? do you think the vb-team will reply with a solution if I ask them via a support ticket?
Reply With Quote
  #4  
Old 06-28-2010, 05:26 PM
Adan0s Adan0s is offline
 
Join Date: May 2008
Location: Germany
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 11-12-2010, 11:26 AM
leitel leitel is offline
 
Join Date: Mar 2003
Location: Costa Rica
Posts: 118
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #6  
Old 11-12-2010, 06:26 PM
Adan0s Adan0s is offline
 
Join Date: May 2008
Location: Germany
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 11-12-2010, 06:40 PM
leitel leitel is offline
 
Join Date: Mar 2003
Location: Costa Rica
Posts: 118
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #8  
Old 11-13-2010, 07:31 AM
Adan0s Adan0s is offline
 
Join Date: May 2008
Location: Germany
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 = '')
Reply With Quote
  #9  
Old 11-13-2010, 10:59 AM
leitel leitel is offline
 
Join Date: Mar 2003
Location: Costa Rica
Posts: 118
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #10  
Old 11-13-2010, 11:50 AM
Adan0s Adan0s is offline
 
Join Date: May 2008
Location: Germany
Posts: 45
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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)
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:49 AM.


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.04120 seconds
  • Memory Usage 2,289KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (3)bbcode_php
  • (5)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete