Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
Prev Previous Post   Next Post Next
  #2  
Old 05-31-2013, 09:00 PM
arabuser arabuser is offline
 
Join Date: Aug 2004
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

download.php part2

PHP Code:
    if ($vbulletin->GPC['downloadid'])
    {
        
// Grab our permissions
        
$permissions VBDOWNLOADS::fetchPermissions($download$category);
    }
    else
    {
        
// Grab our permissions
        
$permissions VBDOWNLOADS::fetchPermissions(NULL$category);
    }

    if (!
$permissions['canupload'])
    {
        
// We can't upload
        
print_no_permission();
    }

    if (
$category['parentid'])
    {
        
// Store immediate category
        
$parentCategory VBDOWNLOADS::$cache['category'][$category['parentid']];

        do
        {
            
// Add to the navbits
            
$navbits[$vbulletin->options['dbtech_downloads_link'] . '.php?' $vbulletin->session->vars['sessionurl'] . 'categoryid=' $parentCategory['categoryid']] = $parentCategory['title'];

            if (isset(
VBDOWNLOADS::$cache['category'][$parentCategory['parentid']]))
            {
                
// Store -its-
                
$parentCategory VBDOWNLOADS::$cache['category'][$parentCategory['parentid']];
            }
        }
        while (isset(
VBDOWNLOADS::$cache['category'][$parentCategory['parentid']]));
    }

    if (
$vbulletin->GPC['downloadid'])
    {
        
// Add to the navbits
        
$navbits[$vbulletin->options['dbtech_downloads_link'] . '.php?' $vbulletin->session->vars['sessionurl'] . 'categoryid=' $category['categoryid']] = $category['title'];
        
$navbits[$vbulletin->options['dbtech_downloads_link'] . '.php?' $vbulletin->session->vars['sessionurl'] . 'do=download&downloadid=' $download['downloadid']] = $download['title'];
        
$navbits[''] = $pagetitle construct_phrase($vbphrase['dbtech_downloads_editing_download_x'], $download['title']);
    }
    else
    {
        
// Add to the navbits
        
$navbits[$vbulletin->options['dbtech_downloads_link'] . '.php?' $vbulletin->session->vars['sessionurl'] . 'categoryid=' $category['categoryid']] = $category['title'];
        
$navbits[''] = $pagetitle $vbphrase['dbtech_downloads_add_new_download'];
    }


    for (
$i 0$i 10$i++)
    {
        if (!isset(
$download['mirrors'][$i]))
        {
            
// Default value        
            
$download['mirrors'][$i] = array(
                
'link' => 'http://',
                
'hits' => 0,
            );
        }
        else
        {
            if (!
is_array($download['mirrors'][$i]))
            {
                
// Need to convert it to array
                
$download['mirrors'][$i] = array(
                    
'link' => $download['mirrors'][$i],
                    
'hits' => 0,
                );
            }

            if (!
$download['mirrors'][$i]['link'])
            {
                
// Set this to default
                
$download['mirrors'][$i]['link'] = 'http://';
            }
            else
            {
                
// Ensure this is safe
                
$download['mirrors'][$i]['link'] = htmlspecialchars_uni($download['mirrors'][$i]['link']);
            }
        }
    }

    if (
$download['password'])
    {
        
// Set placeholder password
        
$download['password'] = '!>=Password=<!';
    }

    
$extensioninfo '';
    
$extensions = array();
    foreach (
VBDOWNLOADS::$cache['extension'] as $extension)
    {
        if (!
in_array($extension['extensiongroupid'], $category['extensiongroups']))
        {
            
// Not in allowed extension group
            
continue;
        }

        
// Add to allowed extensions
        
$extensions[] = $extension['extension'];

        
$templater vB_Template::create('dbtech_downloads_modify_extensionbit');
            
$templater->register('extension',     $extension['extension']);
            
$templater->register('maxsize',     vb_number_format($extension['maxsize'], 2true));
        
$extensioninfo .= $templater->render();
    }

    
// Grab ordered list
    
$categoryList construct_ordered_categories();

    
// Construct the list of select options
    
construct_category_select_options($categories$categoryList);

    
$categoryOptions '';
    foreach (
$categories as $categoryid => $title)
    {
        if (
in_array($categoryid$_excludeCategories))
        {
            
// Can't view category
            
continue;
        }

        if (!
$category VBDOWNLOADS::$cache['category'][$categoryid])
        {
            
// Invalid category
            
continue;
        }

        if (!
is_array($category['permissions']['upload']))
        {
            
$category['permissions']['upload'] = array();
        }

        
$allowUgs = array();
        foreach (
$category['permissions']['upload'] as $usergroupid => $canupload)
        {
            if (
$canupload)
            {
                
// This UG can upload this
                
$allowUgs[] = $usergroupid;
            }
        }

        if (
            !
count($allowUgs) OR 
            !
is_member_of($vbulletin->userinfo$allowUgs)/* OR (
                $category['ownerid'] AND 
                $category['ownerid'] != $vbulletin->userinfo['userid'] AND
                !VBDOWNLOADS::$permissions['ismanager']
            )*/
        
)
        {
            
// We can't access this category
            
continue;
        }        

        
$templater vB_Template::create('option');
            
$templater->register('optionselected',     $download['categoryid'] == $categoryid 'selected="selected"' '');
            
$templater->register('optionvalue',     $categoryid);
            
$templater->register('optiontitle',     htmlspecialchars_uni($title));
        
$categoryOptions .= $templater->render();
    }

    require_once(
DIR '/includes/functions_editor.php');
    
$editorid construct_edit_toolbar($download['description'], false'nonforum'falsefalsefalse);
    
    
// Mail sending form
    
$page_templater vB_Template::create('dbtech_downloads_modify');
        
$page_templater->register('download',         $download);
        
$page_templater->register('editorid',         $editorid);
        
$page_templater->register('messagearea',     $messagearea);
        
$page_templater->register('categories',     $categoryOptions);
        
$page_templater->register('extensioninfo',     $extensioninfo);
        
$page_templater->register('extensions',     implode('|'$extensions));
        
$page_templater->register('jQueryPath',        VBDOWNLOADS::jQueryPath());        
        
$page_templater->register('jQueryUiPath',    VBDOWNLOADS::jQueryUiPath());        
    
$HTML $page_templater->render();
}

// #############################################################################
if ($_POST['action2'] == 'update')
{
    
// Grab stuff
    
$vbulletin->input->clean_array_gpc('p', array(
        
'downloadid'     => TYPE_UINT,
        
'download'         => TYPE_ARRAY,
        
'wysiwyg'         => TYPE_BOOL,
        
'subject'         => TYPE_STR,
        
'message'         => TYPE_STR,
        
'users'         => TYPE_STR,
        
'filelist'         => TYPE_ARRAY,
    ));

    if (
$vbulletin->GPC['subject'] == '' OR $vbulletin->GPC['message'] == '')
    {
        
// Something was missin'
        
eval(standard_error(fetch_error('please_complete_required_fields')));
    }

    if (
in_array($vbulletin->GPC['download']['categoryid'], $_excludeCategories))
    {
        
// Can't view category
        
print_no_permission();
    }

    if (
$vbulletin->GPC['wysiwyg'])
    {
        
// We were using WYSIWYG editor
        
if (!file_exists(DIR '/includes/functions_wysiwyg.php'))
        {
            
// New editor
            
require_once(DIR '/includes/class_wysiwygparser.php');
            
$html_parser = new vB_WysiwygHtmlParser($vbulletin);
            
$message $html_parser->parse_wysiwyg_html_to_bbcode($vbulletin->GPC['message'], true);
        }
        else
        {
            
// Old editor
            
require_once(DIR '/includes/functions_wysiwyg.php');
            
$message convert_wysiwyg_html_to_bbcode($vbulletin->GPC['message'], true);
        }
    }
    else
    {
        
// Not WYSIWYG, interpret as-is
        
$message $vbulletin->GPC['message'];
    }
    
    if (!
function_exists('convert_url_to_bbcode'))
    {
        
// Ensure we can convert URL to BBCode
        
require_once(DIR '/includes/functions_newpost.php');
    }
    
    
// Convert URL to BBCode
    
$vbulletin->GPC['download']['description'] = convert_url_to_bbcode($message);

    if (!
$category VBDOWNLOADS::$cache['category'][$vbulletin->GPC['download']['categoryid']])
    {
        
// Invalid category
        
standard_error(fetch_error('dbtech_downloads_invalid_x'$vbphrase['dbtech_downloads_category'], $vbulletin->GPC['download']['categoryid']));
    }

    
$vbulletin->GPC['download']['private'] = array();
    if (
$category['canprivate'])
    {
        
// We can have private downloads
        
$users preg_split('#\s*,\s*#s'$vbulletin->GPC['users'], -1PREG_SPLIT_NO_EMPTY);
        
        
$lookup = array();
        foreach (
$users as $username)
        {
            if (!
$username)
            {
                
// Just in case
                
continue;
            }
            
            
// Lookup userid
            
$lookup[] = htmlspecialchars_uni($username);
        }
        
        if (
count($lookup))
        {
            
$vbulletin->GPC['download']['private'] = VBDOWNLOADS::$db->fetchAllSingleKeyed('SELECT username, userid FROM $user WHERE username :queryList''username''userid', array(':queryList' => VBDOWNLOADS::$db->queryList($lookup)));
        }
    }

    if (
$vbulletin->GPC['download']['password'])
    {
        
// We have a password of some description
        
if (!$category['canpassword'])
        {
            
// We couldn't have passworded downloads
            
$vbulletin->GPC['download']['password'] = '';
        }
        else if (
$vbulletin->GPC['download']['password'] != '!>=Password=<!')
        {
            
// hash the new password
            
$vbulletin->GPC['download']['password'] = md5($vbulletin->GPC['download']['password']);
        }
        else
        {
            
// Our password was the PH pass, don't update it
            
unset($vbulletin->GPC['download']['password']);
        }
    }

    if (
$vbulletin->GPC['downloadid'])
    {
        
// Grab the download
        
$download VBDOWNLOADS::$db->fetchRow('SELECT * FROM $dbtech_downloads_download WHERE downloadid = ?', array($vbulletin->GPC['downloadid']));

        if (
$download['moderation'] AND !VBDOWNLOADS::$permissions['ismanager'])
        {
            
// File is under moderation
            
standard_error(fetch_error('dbtech_downloads_file_being_reviewed'));
        }

        if (
            !
VBDOWNLOADS::$permissions['ismanager'] AND 
            
$download['userid'] != $vbulletin->userinfo['userid'] AND
            
$vbulletin->userinfo['userid']
        )
        {
            
// Private download
            
standard_error(fetch_error('dbtech_downloads_private_file_error'));
        }
    }
    else
    {
        
// I'm being lazy
        
$vbulletin->GPC['download']['userid'] = $vbulletin->userinfo['userid'];
    }

    for (
$i 0$i 10$i++)
    {
        if (!isset(
$vbulletin->GPC['download']['mirrors'][$i]))
        {
            
// Default value        
            
$vbulletin->GPC['download']['mirrors'][$i] = array(
                
'link' => 'http://',
                
'hits' => 0,
            );
        }
        else
        {
            if (!
is_array($vbulletin->GPC['download']['mirrors'][$i]))
            {
                
// Need to convert it to array
                
$vbulletin->GPC['download']['mirrors'][$i] = array(
                    
'link' => $vbulletin->GPC['download']['mirrors'][$i],
                    
'hits' => 0,
                );
            }

            if (!
$vbulletin->GPC['download']['mirrors'][$i]['link'])
            {
                
// Set this to default
                
$vbulletin->GPC['download']['mirrors'][$i]['link'] = 'http://';
            }
        }
    }

    
// I'm being lazy
    
$vbulletin->GPC['download']['title'] = $vbulletin->GPC['subject'];

    
// Update numfiles from form
    
$vbulletin->GPC['download']['numfiles'] = count($vbulletin->GPC['filelist']);

    
// init data manager
    
$dm =& VBDOWNLOADS::initDataManager('Download'$vbulletinERRTYPE_STANDARD);
    
    
// set existing info if this is an update
    
if ($vbulletin->GPC['downloadid'])
    {
        
// Set existing
        
$dm->set_existing($download);
    }
    
    
// download fields
    
foreach ($vbulletin->GPC['download'] AS $key => $val)
    {
        if (!
$vbulletin->GPC['downloadid'] OR $existing[$key] != $val)
        {
            
// Only set changed values
            
$dm->set($key$val);
        }
    }
    
    
// Save! Hopefully.
    
$downloadid $vbulletin->GPC['download']['downloadid'] = $dm->save();

    if (
$vbulletin->GPC['downloadid'])
    {
        
// Ensure this is set
        
$downloadid $vbulletin->GPC['download']['downloadid'] = $vbulletin->GPC['downloadid'];
    }
    
/*DBTECH_PRO_START*/
    
else
    {
        if (
class_exists('VBSHOUT'))
        {
            foreach ((array)
VBSHOUT::$cache['instance'] as $instanceid => $instance)
            {
                
// Init the Shout DM
                
$shout VBSHOUT::initDataManager('Shout'$vbulletinERRTYPE_SILENT);
                    
$shout->set_info('automated'true);                
                    
$shout->set('message'construct_phrase($vbphrase['dbtech_downloads_vbshout_message'], 
                        
$vbulletin->options['bburl'], 
                        
$vbulletin->options['dbtech_downloads_link'], 
                        
$downloadid
                        
$vbulletin->db->escape_string($vbulletin->GPC['subject']))
                    );
                    
$shout->set('userid'$vbulletin->userinfo['userid']);
                    
$shout->set('type'VBSHOUT::$shouttypes['notif']);
                    
$shout->set('instanceid'$instanceid);
                
$shout->save();
                unset(
$shout);
            }
        }

        if (
$category['forumid'])
        {
            
// Post a new thread
            
$thread =& datamanager_init('Thread_FirstPost'$vbulletinERRTYPE_ARRAY'threadpost');
                
$thread->set('title',         VBDOWNLOADS::convertVars($vbulletin->options['dbtech_downloads_thread_title'],         $vbulletin->GPC['download']));
                
$thread->set('pagetext',     VBDOWNLOADS::convertVars($vbulletin->options['dbtech_downloads_thread_message'],     $vbulletin->GPC['download']));
                
$thread->set('forumid',     $category['forumid']);
                
$thread->set('userid',         $vbulletin->userinfo['userid']);
                
$thread->set('allowsmilie'true);
                
$thread->set('visible',     true);
            
$thread->save();
            
            require_once(
DIR '/includes/functions_databuild.php');
            
build_forum_counters($category['forumid']);
        }
    }
    
/*DBTECH_PRO_END*/

    
if (count($vbulletin->GPC['filelist']))
    {
        
$fileIds = array();
        foreach (
$vbulletin->GPC['filelist'] as $fileid => $fileinfo)
        {
            
$fileIds[] = $fileid;
        }

        
$fileList VBDOWNLOADS::$db->fetchAllKeyed('
            SELECT *
            FROM $dbtech_downloads_file
            WHERE fileid :queryList
        '
'fileid', array(
            
':queryList' => VBDOWNLOADS::$db->queryList($fileIds),
        ));

        foreach (
$vbulletin->GPC['filelist'] as $fileid => $fileinfo)
        {
            if (!
is_array($fileList[$fileid]))
            {
                if (!
$vbulletin->GPC['downloadid'])
                {
                    
VBDOWNLOADS::$db->delete('dbtech_downloads_file', array($fileid), 'WHERE fileid = ?');
                    
VBDOWNLOADS::$db->query('UPDATE $dbtech_downloads_download SET numfiles = numfiles - 1 WHERE downloadid = ?', array($downloadid));
                }

                
// Skip this
                
continue;
            }

            
// Update the file
            
$dm =& VBDOWNLOADS::initDataManager('File'$vbulletinERRTYPE_SILENT);
                
$dm->set_existing($fileList[$fileid]);
                
$dm->set('downloadid'$downloadid);
                
$dm->set('screenshot'$fileinfo['screenshot']);
                
$dm->set('thumbnail'$fileinfo['thumbnail']);
            
$dm->save();
        }
    }
    
    
$vbulletin->url $vbulletin->options['dbtech_downloads_link'] . '.php?' $vbulletin->session->vars['sessionurl'] . 'do=download&amp;downloadid=' $downloadid;
    eval(
print_standard_redirect('redirect_dbtech_downloads_file_added'));
}
?> 
Reply With Quote
 

Thread Tools
Display Modes

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 02:58 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.04745 seconds
  • Memory Usage 3,457KB
  • Queries Executed 12 (?)
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)bbcode_code
  • (4)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (11)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)showthread_list
  • (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_threadedmode.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_threaded
  • showthread_threaded_construct_link
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete