Forums


QdbS - Quote database System :: Forums :: QdbS Support
<< Previous thread | Next thread >>   

vBulletin front-end bridging v1.5 IMPORTANT UPDATE!

Author Post
tyteen4a03
Wed Jun 23 2010, 15:10:16
Registered Member #27
Joined: Sat Nov 07 2009, 15:40:14
Posts: 13
While waiting for QdbS v2 I decided to release this vBulletin bridge.

This bridge is tested on vBulletin 3.8.5 only. I am not sure about 3.6-3.8.4, but one thing is sure that it won't work for vB4.

Features:
  • Who submitted

  • Requires login to add quote and rate

  • Log username rate with IP

  • (WORKING)Admin panel integration (see below if you want to help)

  • (WORKING)Use vB BBcode parser when adding quote


Install steps:
1. Run this SQL query:

ALTER TABLE `(tableprefix)_votes` ADD `username` VARCHAR( 255 ) NULL AFTER `id`;
ALTER TABLE `(tableprefix)_quotes` ADD `submitter` VARCHAR( 255 ) NOT NULL AFTER `quote`;
ALTER TABLE `(tableprefix)_queue` ADD `submitter` VARCHAR( 255 ) NOT NULL AFTER `quote`;


2. Put this in anywhere of your function.php. If you have not installed BBcode parsing, make a new file called function.php and put the following content:

    function input_filter($ncode)
    {
        $ncode = preg_replace('/[^ _A-Za-z0-9-]/', '', $ncode);
        return $ncode;
    }

If you have intsalled BBcode parsing before skip this step.
2a: Open classes.php, find:

include("settings.php");

Add below:

include("functions.php");


3. Create new file called login.php and put in the following content:

<?php
/**************************************************************************

    This file is part of the Quotes Database System (QdbS)
    Copyright (C) 2003-2010 QdbS.org
    Written by Kyle Florence (kyle.florence@gmail.com)
    Maintained by Matthew Beeching (jobe@qdbs.org)
    Table Prefix patch by Thomas Ward (jouva@moufette.com)
    vBulletin bridging by Timothy Choi AKA tyteen4a03 (tyteen4a03@hk-diy.net)
    Login script by Evan Holloway AKA The Evina (evan@evinext.com)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
***************************************************************************/
include('classes.php');

if (isset(
$_POST['username']) && isset($_POST['user_password']) && $_POST['validlogin']) {
    
$_SESSION['logged-in'] = true;
}
if (
$_POST['validlogin'] != true) {
        print(
$tpl->fetch($tpl->tdir.'layout_header.tpl'));
        print(
$tpl->fetch($tpl->tdir.'invalid_action.tpl'));
        print(
$tpl->fetch($tpl->tdir.'layout_footer.tpl'));
        die;
    }
if (
$_SESSION['logged-in']) {
    if (
$_POST['validlogin'] == true) {
        
$_SESSION['validlogin'] == true;
        
$_SESSION['username'] = htmlspecialchars($_POST['username']);

        if (
$_POST['remember_me']) {
            
$expire time()+60*60*24*30;
            
setcookie('qdbs_user'$_SESSION['username'], $expire);
            
setcookie('qdbs_pass'$_SESSION['user_password'], $expire);
        } elseif (!
$_POST['remember_me'] && isset($_COOKIE['qdbs_user'])) {
            
// Destroy the cookies
            
$expire time()-60*60*24*30;
            
setcookie('qdbs_user'''$expire);
            
setcookie('qdbs_pass'''$expire);
        }
    }
    if (
$_qdbs[vb_db] != $qdbs[db]) {
        
mysql_select_db($_qdbs[vb_db]);
    }
    
$q mysql_query("SELECT salt,password,usergroupid,membergroupids FROM ".$_qdbs[vb_tpfx]."user WHERE username='".$_SESSION['username']."'");
    
$uinfo mysql_fetch_assoc($q);
    
$password_code md5(md5($_POST['user_password']) . $uinfo['salt']);
    if (
$password_code != $uinfo['password']) {
        
session_start();
        
session_unset();
        
session_destroy();
        print(
$tpl->fetch($tpl->tdir.'layout_header.tpl'));
        print(
$tpl->fetch($tpl->tdir.'wrong_password.tpl'));
        print(
$tpl->fetch($tpl->tdir.'layout_footer.tpl'));
        die;
    }
    
$ugroup['main'] = $uinfo['usergroupid'];
    
$ugroup['ext'] = $uinfo['membergroupids'] ? explode(',',$uinfo['membergroupids']) : '';
    
#Admin->Supermod->Mod check
    
if ($ugroup['main'] == or in_array(6$ugroup['ext'])) {
        
$_SESSION['alevel'] == 3;
    } elseif (
$ugroup['main'] == or in_array(5$ugroup['ext'])) {
        
$_SESSION['alevel'] == 2;
    } elseif (
$ugroup['main'] == or in_array(7$ugroup['ext'])) {
        
$_SESSION['alevel'] == 1;
    } else {
        
$_SESSION['alevel'] == 0;
    }

    print(
$tpl->fetch($tpl->tdir.'layout_header.tpl'));
    print(
$tpl->fetch($tpl->tdir.'login_success.tpl'));
    print(
$tpl->fetch($tpl->tdir.'layout_footer.tpl'));;
    die;
} else {
    
// See if this page was from index
    
if ($_POST['validlogin']) {
        print(
$tpl->fetch($tpl->tdir.'layout_header.tpl'));
        print(
$tpl->fetch($tpl->tdir.'quote_fieldmissing.tpl'));
        print(
$tpl->fetch($tpl->tdir.'layout_footer.tpl'));;
        die;
    }
    
// Else tell the user to log in
    
else {
        print(
$tpl->fetch($tpl->tdir.'layout_header.tpl'));
        print(
$tpl->fetch($tpl->tdir.'please_login.tpl'));
        print(
$tpl->fetch($tpl->tdir.'layout_footer.tpl'));
        die;
    }
}
?>

4. Edit index.php
Find:

        case 'rate':

Add below:

            if (!$_SESSION['logged-in') {
                print($tpl->fetch($tpl->tdir.'layout_header.tpl'));
                print($tpl->fetch($tpl->tdir.'please_login.tpl'));
                print($tpl->fetch($tpl->tdir.'layout_footer.tpl'));
                break;
            }

Find:

$sql = "INSERT INTO ".$_qdbs[tpfx]."votes (id,rate,ip) VALUES ('".mysql_real_escape_string($_GET['q'])."', 'up', '".mysql_real_escape_string($ip)."')";

Replace with:

$sql = "INSERT INTO ".$_qdbs[tpfx]."votes (id,username,rate,ip) VALUES ('".mysql_real_escape_string($_GET['q'])."', '{$_SESSION['username']}', 'up', '".mysql_real_escape_string($ip)."')";

Find:

$sql = "INSERT INTO ".$_qdbs[tpfx]."votes (id,rate,ip) VALUES ('".mysql_real_escape_string($_GET['q'])."', 'down', '".mysql_real_escape_string($ip)."')";

Replace with:

$sql = "INSERT INTO ".$_qdbs[tpfx]."votes (id,username,rate,ip) VALUES ('".mysql_real_escape_string($_GET['q'])."', '{$_SESSION['username']}', 'down', '".mysql_real_escape_string($ip)."')";

Find:

$tpl->set('q_submitter', $row['submitter']);

Add below for ALL MATCHES

$tpl->set('q_submitter', $row['submitter']);

Find:

$quote = nl2br($quote);

Add below:

$submitter = $_SESSION['username'];
if (!$_SESSION['logged-in']) {
                print($tpl->fetch($tpl->tdir.'layout_header.tpl'));
                print($tpl->fetch($tpl->tdir.'please_login.tpl'));
                print($tpl->fetch($tpl->tdir.'layout_footer.tpl'));
                break;
            }
            elseif (!$quote)
            {
                print($tpl->fetch($tpl->tdir.'quote_fieldmissing.tpl'));        
            }

Find:

             if (ini_get("magic_quotes_runtime") or ini_get("magic_quotes_gpc")) {
                  $sql = "INSERT INTO ".$_qdbs[tpfx]."queue (id,quote) VALUES ('NULL', '".mysql_real_escape_string(stripslashes($quote))."')";
             } else {
                  $sql = "INSERT INTO ".$_qdbs[tpfx]."queue (id,quote) VALUES ('NULL', '".mysql_real_escape_string($quote)."')";
             }

Replace with:

            if (ini_get("magic_quotes_runtime") or ini_get("magic_quotes_gpc")) {
                $sql = "INSERT INTO ".$_qdbs[tpfx]."queue (id,quote,submitter) VALUES ('NULL', '".mysql_real_escape_string(stripslashes($quote))."', '".mysql_real_escape_string(stripslashes($submitter))."' )";
            } else {
                $sql = "INSERT INTO ".$_qdbs[tpfx]."queue (id,quote,submitter) VALUES ('NULL', '".mysql_real_escape_string($quote)."', '".mysql_real_escape_string($submitter)."' )";
            }

Find:

        switch ($_GET['p']) {

Add below:

            case 'login':
                print($tpl->fetch($tpl->tdir.'login_form.tpl'));
                break;


Continued in the next post...

[ Edited Sun Aug 01 2010, 10:54:41 ]
Back to top
tyteen4a03
Wed Jun 23 2010, 16:26:04
Registered Member #27
Joined: Sat Nov 07 2009, 15:40:14
Posts: 13
And now the time for our lovely template modifications.

All of those are designed for the default skin.

http://proj.hk-diy.net/qdbs/vb_templates.zip


Also:
In settings.php place this at anywhere in the script:

$_qdbs[vb_db] = 'database here';
$_qdbs[vb_tpfx] = 'vb table prefix here';



[ Edited Sun Aug 01 2010, 10:55:53 ]
Back to top
tyteen4a03
Sat Jul 10 2010, 18:20:03
Registered Member #27
Joined: Sat Nov 07 2009, 15:40:14
Posts: 13
This is the admin panel I am working on. Somehow the session isn't passed on.

I would also like someone to integrate the admin panel to the vBulletin system instead of relying on the admin panel. IMO The moderation panel is better than the simple add-remove panel we have.

(BTW You might have noticed that there is 3 session var sent: isadmin, issupermod and ismod. This is built for later categories use.)


<?php
/**************************************************************************

    This file is part of the Quotes Database System (QdbS)
    Copyright (C) 2003-2010 QdbS.org
    Written by Kyle Florence (kyle.florence@gmail.com)
    Maintained by Matthew Beeching (jobe@qdbs.org)
    Table Prefix patch by Thomas Ward (jouva@moufette.com)
    vBulletin bridging by Timothy Choi AKA tyteen4a03 (tyteen4a03@hk-diy.net)
    Login script by Evan Holloway AKA The Evina (evan@evinext.com) 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    $Id: index.php 23 2010-01-11 13:39:05Z jobe1986 $

***************************************************************************/
error_reporting(E_ALL & ~E_NOTICE & ~8192);
require(
"../settings.php");
require(
"../functions.php");
require(
"../classes.php");

if (!
defined("INSTALLED")) {
    
header("Location: ./install/");
    exit;
}

$sql "SELECT COUNT(id) FROM ".$_qdbs[tpfx]."quotes";
$start $pgr->findStart($pgr->limit);
$count mysql_result($db->_sql($sql),0);
$pages $pgr->findPages($count$pgr->limit);
!isset(
$_GET['page']) ? $page '1' $page $_GET['page'];
$tpl->set('page_list'$pgr->pageList($page$pages));

if (
$_GET['do'] || $_POST['do']) {
    if (
$_SESSION['alevel'] == 1) {
        switch (
$_GET['do']) {
            case 
'add':
                
$sql "SELECT * FROM ".$_qdbs[tpfx]."queue WHERE id='".mysql_real_escape_string($_GET['q'])."'";
                
$r $db->_sql($sql);
                
$row $db->fetch_row($r);
                if (
ini_get("magic_quotes_runtime") or ini_get("magic_quotes_gpc")) {
                     
$sql "INSERT INTO ".$_qdbs[tpfx]."quotes (id,quote,rating,submitter) VALUES ('NULL', '".mysql_real_escape_string(stripslashes($row['quote']))."', '0', '".mysql_real_escape_string(stripslashes($row['submitter']))."')";
                } else {
                     
$sql "INSERT INTO ".$_qdbs[tpfx]."quotes (id,quote,rating,submitter) VALUES ('NULL', '".mysql_real_escape_string($row['quote'])."', '0', '".mysql_real_escape_string($row['submitter'])."')";
                }
                
$r $db->_sql($sql);
                
$sql "DELETE FROM ".$_qdbs[tpfx]."queue WHERE id='".mysql_real_escape_string($_GET['q'])."'";
                
$r $db->_sql($sql);
                
                
header ("Location: ".$ref);
                break;
            case 
'del':
                
$sql "DELETE FROM ".$_qdbs[tpfx]."queue WHERE id='".mysql_real_escape_string($_GET['q'])."'";
                
$r $db->_sql($sql);
                
                
header ("Location: ".$ref);
                break;
        }
        switch (
$_POST['do']) {
            case 
'update':
                if (
$_SESSION['alevel'] == 3) {
                    
$sql "UPDATE ".$_qdbs[tpfx]."settings SET template='".mysql_real_escape_string($_POST['template_dir'])."', qlimit='".mysql_real_escape_string($_POST['q_limit'])."', title='".mysql_real_escape_string($_POST['p_title'])."', heading='".mysql_real_escape_string($_POST['p_heading'])."', style='".mysql_real_escape_string($_POST['css_style'])."'";
                    
$r $db->_sql($sql);
                    
$tpl->set('logged'$tpl->fetch('.'.$tpl->tdir.'admin_links.tpl'));
                    print(
$tpl->fetch('.'.$tpl->tdir.'admin_header.tpl'));
                    print(
$tpl->fetch('.'.$tpl->tdir.'admin_success.tpl'));
                    print(
$tpl->fetch('.'.$tpl->tdir.'admin_footer.tpl'));
                }
                break;
        }
    }
} else {
    
// Header
    
if ($_SESSION['alevel'] == 1) {
        
$tpl->set('logged'$tpl->fetch('.'.$tpl->tdir.'admin_links.tpl'));
    } else {
        
$tpl->set('logged''&nbsp;');
    }
    print(
$tpl->fetch('.'.$tpl->tdir.'admin_header.tpl'));
    if (
$SESSION['alevel'] == 1) {
        if (
$_GET['p'] == 'settings') {
            if (
$_SESSION['isadmin'] == 1) {
                
$sql "SELECT * FROM ".$_qdbs[tpfx]."settings";
                
$r $db->_sql($sql);
                
$row $db->fetch_row($r);
                
$tpl->set('s_title'$row['title']);
                
$tpl->set('s_heading'$row['heading']);
                
$tpl->set('s_style'$row['style']);
                
$tpl->set('s_tdir'$row['template']);
                
$tpl->set('s_limit'$row['qlimit']);
                print(
$tpl->fetch('.'.$tpl->tdir.'admin_settings_header.tpl'));
                print(
$tpl->fetch('.'.$tpl->tdir.'admin_settings_footer.tpl'));
           } else {
                print(
$tpl->fetch('.'.$tpl->tdir.'admin_settings_1.tpl'));
            }
        } else {
            
$sql "SELECT * FROM ".$_qdbs[tpfx]."queue ORDER BY id DESC LIMIT ".intval($start).", ".intval($pgr->limit);
            
$r $db->_sql($sql);
            if(
mysql_num_rows($r) > 0) {
                while (
$row $db->fetch_row($r)) {
                    
$tpl->set('q_id'$row['id']);
                    
$tpl->set('quote'$row['quote']);
                    
$tpl->set('q_submitter'$row['submitter']);
                    print(
$tpl->fetch('.'.$tpl->tdir.'admin_block.tpl'));
                }

            } else {
                print(
$tpl->fetch('.'.$tpl->tdir.'admin_noquotes.tpl'));
            }
        }
    } else {
        print(
$tpl->fetch('.'.$tpl->tdir.'login_form.tpl'));
    }
    
    
// Footer
    
$tpl->set('q_count'$db->q_count);
    
$tpl->set('r_count'$db->r_count);
    print(
$tpl->fetch('.'.$tpl->tdir.'admin_footer.tpl'));
}
?>


[ Edited Sun Aug 01 2010, 10:58:58 ]
Back to top
tyteen4a03
Sun Aug 01 2010, 05:55:03
Registered Member #27
Joined: Sat Nov 07 2009, 15:40:14
Posts: 13
A very important update, fixed lots of bugs. Please update your file!
Back to top
Jobe
Sun Aug 01 2010, 09:41:12


Joined: Mon Oct 08 2007, 15:54:30
Posts: 32
Random suggestion, rather then using 3 vars for the access level, why not use a single var and say 0 for none, 1 for mod, 2 for supermod and 3 for admin?
Back to top
tyteen4a03
Sun Aug 01 2010, 10:53:33
Registered Member #27
Joined: Sat Nov 07 2009, 15:40:14
Posts: 13
Updated, thanks.
Back to top
Moderators: Jobe, Eck

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System