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

Reply
 
Thread Tools Display Modes
  #21  
Old 09-25-2007, 05:39 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
<?php
// include backend
require_once('global.php');

// input
$name $_GET['name'];
$lat $_GET['lat'];
$lon $_GET['lon'];
$uid intval($_GET['uid']);
$gid $_GET['gid'];
$desc $_GET['desc'];
$phone $_GET['phone'];
$addr $_GET['addr'];
$addr2 $_GET['addr2'];
$city $_GET['city'];
$state $_GET['state'];
$zip $_GET['zip'];
$cat $_GET['cat'];

// fetch userinfo
if (!$userinfo fetch_userinfo($uid))
{
    die(
"Invalid User!");
}

// initialize datamanager
$threaddm =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');

// set data
$threaddm->set('forumid'57);
$threaddm->set('userid'$userinfo['userid']);
$threaddm->set('username'$userinfo['username']);
$threaddm->set('postuserid'$userinfo['userid']);
$threaddm->set('postusername'$userinfo['username']);
$threaddm->set('title''Some Title');
$threaddm->set('pagetext'$desc);
$threaddm->set('open'1);
$threaddm->set('allowsmilie'1);
$threaddm->set('visible'1);

// error checks
$threaddm->pre_save();
if (!empty(
$threaddm->errors))
{
    die(
"An Error Occurred!");
}

// save
$threadid $threaddm->save();
unset(
$threaddm);

// rebuild caches
require_once('includes/functions_databuild.php');
build_thread_counters($threadid);
build_forum_counters(57);   
?>
@toucan42: Threads were merged, please don't create multiple threads.
Reply With Quote
  #22  
Old 09-25-2007, 07:10 PM
toucan42 toucan42 is offline
 
Join Date: Sep 2006
Posts: 112
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Interestingly I am back at the error:

Quote:
That username is already in use or does not meet the administrator's standards. If you are admintw42 and you have forgotten your password, click here.
However we are further down the code in class_dm_threadpost.php.

the two lines of code:

PHP Code:
$threaddm->set('postuserid'$userinfo['userid']);
$threaddm->set('postusername'$userinfo['username']); 
are erroring out with the message :

Quote:
Fatal error: Field postusername is not defined in $validfields in class vb_datamanager_thread_firstpost in /includes/class_dm.php on line 485
Looking at the documentation at http://members.vbulletin.com/api/ on vb_datamanager_thread_firstpost it says about userid and username:

Quote:

'username'=>array(TYPE_STR,REQ_NO,VF_METHOD),// maps to thread.postusername
'userid'=>array(TYPE_UINT,REQ_NO,VF_METHOD),// maps to thread.postuserid
So should $userinfo for these two assignments be set to something from a different variable representing threadinfo? I'm so sorry I am striggling with this and appreciate the folks who have been pitching in to help me understand.

--------------- Added at 13:07 ---------------

ok here is my script currently and still facing the error:

Quote:
That username is already in use or does not meet the administrator's standards. If you are admintw42 and you have forgotten your password, click here.
PHP Code:
<?php
// include backend
require_once('global.php');

// input
$name $_GET['name'];
$lat $_GET['lat'];
$lon $_GET['lon'];
$uid intval($_GET['uid']);
$gid $_GET['gid'];
$desc $_GET['desc'];
$phone $_GET['phone'];
$addr $_GET['addr'];
$addr2 $_GET['addr2'];
$city $_GET['city'];
$state $_GET['state'];
$zip $_GET['zip'];
$cat $_GET['cat'];

// fetch userinfo
if (!$userinfo fetch_userinfo($uid))
{
    die(
"Invalid User!");
}

// initialize datamanager
$threaddm =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');
$threadinfo = array();

// set data
$forumtouse 57;

$foruminfo fetch_foruminfo ($forumtouse);

$threaddm->set('forumid'$forumtouse);

$threaddm->set('userid'$userinfo['userid']);
$threaddm->set('username'$userinfo['username']);

//$threaddm->set('postusername', $userinfo['username']);
//$threaddm->set('postuserid', $userinfo['userid']);

$threaddm->set('title''Some Title');
$threaddm->set('pagetext'$desc);
$threaddm->set('open'1);
$threaddm->set('allowsmilie'1);
$threaddm->set('visible'1);

$threaddm->set_info ('forum'$foruminfo);

$threaddm->set_info('thread'$threadinfo);  

// error checks
$threaddm->pre_save();
if (!empty(
$threaddm->errors))
{
    echo (
$threaddm->errors);
}

// save
$threadid $threaddm->save();
unset(
$threaddm);

// rebuild caches
require_once('includes/functions_databuild.php');
build_thread_counters($threadid);
build_forum_counters($forumtouse);   
?>
This has been blocking me for a week. I am hoping someone can help me figure out why it isn't creating the new thread.
Reply With Quote
  #23  
Old 09-26-2007, 06:12 PM
CarlitoBrigante's Avatar
CarlitoBrigante CarlitoBrigante is offline
 
Join Date: Nov 2002
Location: Iceland
Posts: 182
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is how you should do it; of course, leaving this as it is means inviting malicious users to abuse it, but I think you mentioned this was part of a bigger AJAX script. Another suggestion, which I have not implemented here because I do not know exactly what each variable will contain, is to always use vBulletin GPC variable instead than accessing $_GET directly. In fact, while it's true that DataManagers do data validation for you, you may never know when you are going to use the data in some other bits of the code; better safe than sorry, always.

PHP Code:
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT''ajaxpost');
define('LOCATION_BYPASS'1);
define('NOPMPOPUP'1);

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();
// get special data templates from the datastore
$specialtemplates = array();
// pre-cache templates used by all actions
$globaltemplates = array();
// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');

// ######################### CONFIGURATION ###########################
// Forum where you want to post
$ajaxposter_forumid 5;
// Title of the thread
$ajaxposter_title "Some Title...";

// input
$name $_GET['name'];
$lat $_GET['lat'];
$lon $_GET['lon'];
$uid intval($_GET['uid']);
$gid $_GET['gid'];
$desc $_GET['desc'];
$phone $_GET['phone'];
$addr $_GET['addr'];
$addr2 $_GET['addr2'];
$city $_GET['city'];
$state $_GET['state'];
$zip $_GET['zip'];
$cat $_GET['cat'];

// fetch userinfo
if (!$userinfo fetch_userinfo($uid))
{
    die(
"Invalid User!");
}
// initialize datamanager
$threaddm =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');
// set data
$foruminfo fetch_foruminfo($ajaxposter_forumid);
$threaddm->set_info('forum',$foruminfo);
$threaddm->set_info('user',$userinfo);
$threaddm->set('userid',$userinfo['userid']);
$threaddm->set('forumid',$ajaxposter_forumid);
$threaddm->set('title',$ajaxposter_title);
$threaddm->set('pagetext'$desc);
$threaddm->set('open'1);
$threaddm->set('allowsmilie'1);
$threaddm->set('visible'1);
// error checks
$threaddm->pre_save();
if (!empty(
$threaddm->errors))
{
    echo (
$threaddm->errors);
}
// save
$threadid $threaddm->save();
unset(
$threaddm);
// rebuild caches
require_once('includes/functions_databuild.php');
build_thread_counters($threadid);
build_forum_counters($ajaxposter_forumid); 
?>
Reply With Quote
  #24  
Old 10-01-2007, 06:18 PM
ralle89 ralle89 is offline
 
Join Date: Oct 2005
Location: Denmark
Posts: 63
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello again guys.
I am sorry to revive this thread but I now also learned how to delete a thread.
So now the big question is. How do I undelete it?

PS. I delete threads softly.
Reply With Quote
  #25  
Old 10-02-2007, 05:01 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
// initialize datamanager
$threaddm =& datamanager_init('Thread'$vbulletinERRTYPE_STANDARD'threadpost');

// fetch thread info
$threadinfo fetch_threadinfo($threadid);

// set data
$threaddm->set_existing($threadinfo);
$threaddm->set('visible'1);

// save
$threaddm->save();
unset(
$threaddm); 
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:15 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.04680 seconds
  • Memory Usage 2,286KB
  • Queries Executed 13 (?)
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
  • (5)bbcode_php
  • (4)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
  • (2)pagenav_pagelink
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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_postinfo_query
  • fetch_postinfo
  • 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