<?php
if(!defined('IN_MYBB')) die();
function xt_att_info(){
	return array(
		'name'			=> 'XThreads Download File',
		'description'	=> 'Use attachment.php file for downloading XThreads attachments.',
		'website'		=> 'http://mybbhacks.zingaburga.com',
		'author'		=> 'XThreads Mania',
		'authorsite'	=> 'http://mybbhacks.zingaburga.com',
		'version'		=> '1.0',
		'compatibility' => '*',
		'guid'        	=> ''
	);
}
function xt_att_activate(){}
function xt_att_deactivate(){}

$plugins->add_hook('attachment_start','xt_att_run');
function xt_att_run(){
	global $mybb;
	if($mybb->input['xtaid']){
		global $db;
		$query = $db->simple_select('xtattachments','*','aid='.intval($mybb->input['xtaid']));
		$xtattachment = $db->fetch_array($query);
		if(!$xtattachment) error('Invalid request');
		$tfcache = xthreads_gettfcache();
		if(!xthreads_user_in_groups($tfcache[$xtattachment['field']]['viewable_gids'])) error('You do not have permission to download this attachment from our site. Please wait our users put this file on the other site, and grab it from there.');
		$mybb->settings['redirects'] = 0;
		redirect($mybb->settings['bburl'].'/'.xthreads_get_xta_url($xtattachment));
	}
}
?>