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'], 2, true));
$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', false, false, false);
// 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'], -1, PREG_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', $vbulletin, ERRTYPE_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', $vbulletin, ERRTYPE_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', $vbulletin, ERRTYPE_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', $vbulletin, ERRTYPE_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&downloadid=' . $downloadid;
eval(print_standard_redirect('redirect_dbtech_downloads_file_added'));
}
?>