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 05-31-2006, 05:06 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by sambah
Aha. I was wondering what all the $db, $this->db, $vbulletin->db etc malarky was
The main purpose of the database object is support for other databases without recoding all of the files. It also gives you fancy errors when you mess something up. Doing the same for each query using the native calls (mysql_query() for example), would require you to have to check it every time for failure.

Well... I'm out for the night, but I'll leave you guys with some good reads about vBulletin and how to write your own scripts using it...

Tutorial Index:
https://vborg.vbsupport.ru/showthread.php?t=99570

Pay special attention to these threads:
https://vborg.vbsupport.ru/showthread.php?t=98047
https://vborg.vbsupport.ru/showthread.php?t=98009
Reply With Quote
  #22  
Old 05-31-2006, 12:13 PM
jwocky jwocky is offline
 
Join Date: Mar 2005
Posts: 138
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok I took a break from the coding this morning to add some more style to the script and this is what I discovered..

For the fellow newbies, if you want your script to output a page that looks just like a VB page this is what you want to start and end your script with:

Start:
PHP Code:
<?php

// ####################### SET PHP ENVIRONMENT ###########################  
error_reporting(E_ALL & ~E_NOTICE);  

// ############# REQUIRE BACK-END #######################  

require_once('./global.php');  

// ############# Get Some templates #######################  

eval('$headinclude = "' fetch_template('headinclude') . '";');  
eval(
'$header = "' fetch_template('header') . '";');  
eval(
'$navbar = "' fetch_template('navbar') . '";');  

// ############# Output templates #######################  

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';  
echo 
'<html dir="' $stylevar[textdirection] . '" lang="' $stylevar[languagecode] . '">';  
echo 
$headinclude;  
echo 
'<body>';  
echo 
$header;  
echo 
$navbar;
End:
PHP Code:
echo $footer;  

echo 
'</body>';  
echo 
'</html>'


?> 

And now onto Step 5.

I'm right now trying to add some functionality to the script, I want it to be able to go and edit the .txt file I have and be able to add data, remove data, or edit data from it.

Again for me its the basis, so I'm just trying to get a function call to work only if I hit a button. I can make the button appear and will probably do this by making a form that posts to itself.

My question is, is there a way to load a .php file and have it go straight to running a certain function?

Is that what the "?" in the filename is for?.. Ie. I see some scripts running like this: "https://vborg.vbsupport.ru/newreply.php?do=newreply&noquote=1&p=993576" Is the newreply.php?do=newreply telling the newreply.php to only run the newreply function ?

I tried to do something similar on my own script but that obviously didn't work yet

UPDATE

I've found the answer to that..

What I did was look at vb's own file and just copied what they did from their login script, this is how I got it working

I added this into my main body of the script:

PHP Code:
echo 'Run Update on users <FORM ACTION="main.php" METHOD="POST"><input type="hidden" name="do" value="start"><INPUT align=center TYPE="submit" VALUE="Vendor Access"> 
then I put in this if statement later on


PHP Code:
if ($_POST['do'] == 'start')
{
 
start(); 

So basicly what thats saying is If someone enters this page with a value of "do=start" then I want it to run the start();

And of course my button in an above section would labeled name="do" value="start"

So all is well so far, steaming right along! Now to get my user.txt data to post itself in a nice form which would let you edit it. I think this will be hard as hell, but here I go...!

UPDATE #2

Ok so now i'm writing the section of this program that will find the given user's threads (threads started by him) in a predefinied forum and then close the thread.

This is what I have so far:

PHP Code:
    $prevarts $vbulletin->db->query_read("SELECT threadid, title, forumid FROM " TABLE_PREFIX "thread WHERE postuserid = $userid AND forumid IN ($mrkt) ORDER BY dateline DESC");
    while (
$titles $vbulletin->db->fetch_array($prevarts))
    {
    
$tit $titles['title'];
    
$tid $titles['threadid'];
    
$fid $titles['forumid'];
            echo 
"<BR>Closing thread: <b>" $tit;
    } 
now the echo does spit out the threads started by that user, however it is doing it in more then the predefined forumid. What its including are threads that were started in that definied forumid but later moved to another forum. Is there a way to refine the SELECT call to pick out only the threads that are still currently in that forumid ?

Also does anyone have a clue how to move from here to tell the DB to close that given thread ?

Thanks!!

UPDATE #3

Took me a while, but I got the script to close the threads one by one by using this bit of code.. woohoo!


PHP Code:
/* CLOSE THREAD */

    
$prevarts $vbulletin->db->query_read("SELECT threadid, title, forumid FROM " TABLE_PREFIX "thread WHERE postuserid = $userid AND forumid IN ($mrkt) ORDER BY dateline DESC");
    while (
$titles $vbulletin->db->fetch_array($prevarts))
    {
    
$tit $titles['title'];
    
$tid $titles['threadid'];
    
$fid $titles['forumid'];
            echo 
"Closing thread: <b>" $tit "</b>";
        echo 
"<BR>";

    
$vbulletin->db->query_write("UPDATE " TABLE_PREFIX "thread SET open = 0 WHERE threadid = '$tid'");

    }

/* END CLOSE THREAD */ 

$mrkt is a predefined forumid# since i want this to only effect one of my forums, not the entire place.
Reply With Quote
  #23  
Old 06-05-2006, 02:15 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Did you figure everything out? The "?" and everything after it in the URL, is known as the query string. It can be accessed via the $_GET array. file.php?do=closethread&t=15 will translate into the following $_GET array:
PHP Code:
$_GET = array(
    
'do' => 'closethread',
    
't' => 15
); 
Because there values can be easily tainted, if you are using them in queries (or even at all) you should make sure they are "clean". The threads I posted above should show you how to use vBulletin's cleaning functions to make them safe. Once this is done, they all go into $vbulletin->GPC.

$_POST is similar, it is populated from form elements where the form action is set to post. These are just as insecure as $_GET values, so be sure to clean them.

Also, it might be easier to use a template instead of using echo and basically recreating the standard shell template (GENERIC_SHELL).
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 05:55 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.10367 seconds
  • Memory Usage 2,216KB
  • 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
  • (7)bbcode_php
  • (1)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
  • (3)post_thanks_box
  • (3)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (3)post_thanks_postbit_info
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)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