Can Someone Help Me To Edit A mod?

Status
Not open for further replies.

blow

Active Member
97
2010
0
85
Hi wjunction is there any chance someone can edit a vbulletin 3 mod for me?

I made a request on vb.org asking for a Add To Favorites Mod:
Code:
http://www.vbulletin.org/forum/showthread.php?t=307823

Blind-Eddie posted a good one & we've been working on it for the last 2 days editing it to make it how we want it.
We've added a bigger button on the showthread template, instead of a small link in the thread tools options...

Anyway we cant seem to make it add to favorites automatically. Right now you click 'Add To Favorites' then it loads a page & you have to click submit. Then it gets added to the favorites in the ucp...

Could someone edit it so when you click 'Add To Favorites' it submits the thread to favorites automatically,
all with 1 click?

akanevsky the original coder for the mod has put this in the thread: vBFavorites on vb.org
I no longer support my hacks. Please feel free to update them and release new versions elsewhere as long as I get the credit for the original modification.

To make it a bit easier this is the vbfavorites.php file, the only file you have to upload. The other file included in the zip is the product.xml file, but i think that just adds the templates ect.

So could someone edit this code so when you click the 'Add To Favorites' link it submits the thread to favorites automatically, all with 1 click?

Code:
<?php
/*======================================================================*\
|| #################################################################### ||
|| # vB Favorites for vBulletin 3.5.x - 3.8.x by Psionic Vision
|| #################################################################### ||
|| # Copyright ©2009 Anton Kanevsky (ankan925@gmail.com) aka Psionic Vision. All Rights Reserved.
|| # This file may redistributed under GPL license for non-commercial purposes only.
|| #################################################################### ||
\*======================================================================*/

######################################################################################
error_reporting(E_ALL & ~E_NOTICE);

######################################################################################
define('THIS_SCRIPT', 'vbfavorites');

######################################################################################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array(
    'vbfavorites_editor',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

######################################################################################
require_once('./global.php');

#################################################################################################################################
#################################################################################################################################
#################################################################################################################################

if (!isset($_REQUEST['do']) OR !$vbulletin->userinfo['userid'])
{
    print_no_permission();
}

#################################################################################################################################
#################################################################################################################################
#################################################################################################################################

if ($_REQUEST['do'] == 'add')
{
    // retrieve gpc data
    $vbulletin->input->clean_array_gpc('r', array(
        'entry_id' => TYPE_UINT, 
        'entry_type' => TYPE_STR,
    ));

    // define source properties
    switch ($vbulletin->GPC['entry_type'])
    {
        case 'thread':
        {
            if (!$vbulletin->options['vbfavorites_favthreads_enabled'])
            {
                print_no_permission();
            }
            $table = 'thread';
            $idfield = 'threadid';
            $titlefield = 'title';
            $vbulletin->url = "showthread.php?" . $vbulletin->session->vars['sessionurl'] . "t=" . $vbulletin->GPC['entry_id'];
        }
        break;
        case 'post':
        {
            if (!$vbulletin->options['vbfavorites_favposts_enabled'])
            {
                print_no_permission();
            }
            $table = 'post';
            $idfield = 'postid';
            $titlefield = 'title';
            $vbulletin->url = "showthread.php?" . $vbulletin->session->vars['sessionurl'] . "p=" . $vbulletin->GPC['entry_id'] . "#post" . $vbulletin->GPC['entry_id'];
        }
        break;
        case 'user':
        {
            if (!$vbulletin->options['vbfavorites_favusers_enabled'])
            {
                print_no_permission();
            }
            $table = 'user';
            $idfield = 'userid';
            $titlefield = 'username';
            $vbulletin->url = "member.php?" . $vbulletin->session->vars['sessionurl'] . "u=" . $vbulletin->GPC['entry_id'];
        }
        break;
        default:
        {
            eval(standard_error(fetch_error('vbfavorites_e_invalid_source')));
        }
    }
    
    // see if the item already exists in user's favorites...
    $verify_entry = $db->query_first("
        SELECT * 
        FROM `" . TABLE_PREFIX . "favorites`
        WHERE 
            `userid` = '" . $vbulletin->userinfo['userid'] . "'
            AND `entry_id` = '" . $vbulletin->GPC['entry_id'] . "' 
            AND `entry_type` = '" . $db->escape_string($vbulletin->GPC['entry_type']) . "' 
        LIMIT 1
    ");
    
    if ($verify_entry)
    {
        eval(standard_error(fetch_error('vbfavorites_e_entry_exists')));
    }
    
    // since item does not exist in user's favorites, see if it is a valid item...
    $verify_source = $db->query_first("
        SELECT `{$idfield}`, `{$titlefield}`
        FROM `" . TABLE_PREFIX . "{$table}`
        WHERE `{$idfield}` = '" . $vbulletin->GPC['entry_id'] . "'
    ");

    if (!$verify_source)
    {
        eval(standard_error(fetch_error('vbfavorites_e_invalid_source')));
    }

    if (isset($_POST['submit']))
    {
        // retrieve additional gpc data
        $vbulletin->input->clean_gpc('r', 'entry_title', TYPE_NOHTML);

        // ensure absence of errors
        if (!$vbulletin->GPC['entry_title'])
        {
            eval(standard_error(fetch_error('vbfavorites_e_no_title')));
        }

        // insert data into favorites
        $db->query_write("
            INSERT INTO `" . TABLE_PREFIX . "favorites`
            ( 
                `entry_id`, 
                `entry_title`, 
                `entry_type`, 
                `userid`, 
                `dateline` 
            ) 
            VALUES 
            ( 
                " . $vbulletin->GPC['entry_id'] . ",
                '" . $db->escape_string($vbulletin->GPC['entry_title']) . "',
                '" . $db->escape_string($vbulletin->GPC['entry_type']) . "',
                " . $vbulletin->userinfo['userid'] . ",
                " . TIMENOW . "
            )
        ");

        // spit redirect
        eval(print_standard_redirect('vbfavorites_r_entry_saved'));
    }
    else
    {
        // get form data
        $vbulletin->GPC['entry_title'] = $verify_source["$titlefield"];
        
        // set configuration
        $show['editform'] = false;
        
        // spit out the form
        $navbits = construct_navbits(array($vbphrase['vbfavorites'])); 
        eval('$navbar = "' . fetch_template('navbar') . '";');
        eval('print_output("' . fetch_template('vbfavorites_editor') . '");');
    }
}

#################################################################################################################################
#################################################################################################################################
#################################################################################################################################

if ($_REQUEST['do'] == 'edit')
{
    // retrieve gpc data
    $vbulletin->input->clean_array_gpc('r', array(
        'entry_id' => TYPE_UINT, 
        'entry_type' => TYPE_STR
    ));
    
    // get current entry
    $verify_entry = $db->query_first("
        SELECT * FROM `" . TABLE_PREFIX . "favorites`
        WHERE 
            `userid` = '" . $vbulletin->userinfo['userid'] . "' 
            AND `entry_id` = '" . $vbulletin->GPC['entry_id'] . "'
            AND `entry_type` = '" . $db->escape_string($vbulletin->GPC['entry_type']) . "'                                        
        LIMIT 1
    ");

    // verify item existence...
    if (!$verify_entry)
    {
        eval(standard_error(fetch_error('vbfavorites_e_invalid_entry')));
    }

    // if there are no errors, we may continue...
    if (isset($_POST['submit']))
    {
        $vbulletin->input->clean_gpc('p', 'entry_title', TYPE_NOHTML);
            
        // ensure absence of errors
        if (empty($vbulletin->GPC['entry_title']))
        {
            eval(standard_error(fetch_error('vbfavorites_e_no_title')));
        }

        // insert data into favorites
        $db->query_write("
            UPDATE `" . TABLE_PREFIX . "favorites`
            SET 
                `entry_title` = '" . $db->escape_string($vbulletin->GPC['entry_title']) . "'
            WHERE 
                `userid` = '" . $vbulletin->userinfo['userid'] . "' 
                AND `entry_id` = '" . $vbulletin->GPC['entry_id'] . "' 
                AND `entry_type` = '" . $db->escape_string($vbulletin->GPC['entry_type']) . "'
            LIMIT 1
        ");

        $vbulletin->url = "usercp.php?" . $vbulletin->session->vars['sessionurl'];
        eval(print_standard_redirect('vbfavorites_r_entry_saved'));
    }
    else
    {
        // get form data
        $vbulletin->GPC['entry_title'] = $verify_entry['entry_title'];
        
        // set configuration
        $show['editform'] = true;

        // spit out the form
        $navbits = construct_navbits(array($vbphrase['vbfavorites']));
        eval('$navbar = "' . fetch_template('navbar') . '";');
        eval('print_output("' . fetch_template('vbfavorites_editor') . '");');
    }
}

#################################################################################################################################
#################################################################################################################################
#################################################################################################################################

if ($_REQUEST['do'] == 'delete')
{
    if (isset($_REQUEST['entry_id']))
    {    
        if (!is_array($_REQUEST['entry_id']))
        {
            $single = true;
            $vbulletin->input->clean_gpc('r', 'entry_id', TYPE_UINT);
            $ids = $vbulletin->GPC['entry_id'];
        }
        else
        {
            $single = false;
            $vbulletin->input->clean_gpc('r', 'entry_id', TYPE_ARRAY_UINT);
            $ids = implode(',', $vbulletin->GPC['entry_id']);
        }
        
        $vbulletin->input->clean_gpc('r', 'entry_type', TYPE_STR);
        $vbulletin->input->clean_gpc('r', 'from_user_cp', TYPE_BOOL);
        
        switch ($vbulletin->GPC['entry_type'])
        {
            case 'thread':
            {
                $vbulletin->url = "showthread.php?" . $vbulletin->session->vars['sessionurl'] . "t=" . $ids;
            }
            break;
            case 'post':
            {
                $vbulletin->url = "showthread.php?" . $vbulletin->session->vars['sessionurl'] . "p=" . $ids . "#post" . $ids;
            }
            break;
            case 'user':
            {
                $vbulletin->url = "member.php?" . $vbulletin->session->vars['sessionurl'] . "u=" . $ids;
            }
            break;
            default:
            {
                eval(standard_error(fetch_error('vbfavorites_e_invalid_source')));
            }
        }
            
        $vbulletin->db->query_write("
            DELETE FROM `" . TABLE_PREFIX . "favorites`
            WHERE `userid` = " . $vbulletin->userinfo['userid'] . "
            AND `entry_id` IN ($ids)
            AND `entry_type` = '" . $db->escape_string($vbulletin->GPC['entry_type']) . "' 
        ");
    }
    else
    {
        // fall back to usercp
        $single = false;
    }
        
    if ($single)
    {
        eval(print_standard_redirect('vbfavorites_r_entry_deleted'));
    }
    else
    {
        $vbulletin->url = "usercp.php" . $vbulletin->session->vars['sessionurl_q'];
        eval(print_standard_redirect('vbfavorites_r_entries_deleted'));
    }
}

/*======================================================================*\
|| #################################################################### ||
|| # vB Favorites for vBulletin 3.5.x - 3.8.x by Psionic Vision
|| #################################################################### ||
\*======================================================================*/
?>

If needed i could provide a vb3 test forum for someone to try to do it.
 
Status
Not open for further replies.
Back
Top