'LAN_UL_040'];
e107::getLanguage()->bcDefs($bcLans);
if (!isset($pref['upload_enabled']) ||( varset($pref['upload_class']) == 255))
{
e107::redirect();
exit;
}
if (!defined("USER_WIDTH") && defset('BOOTSTRAP')==false){ define("USER_WIDTH","width:97%"); }
require_once(e_HANDLER.'upload_handler.php');
class userUpload
{
function __construct()
{
/*
e107::css('inline', "
input[type=file] {
}
");
e107::js('inline', "
function frmVerify()
{
var message = '';
var spacer = '';
var testObjects = new Array(\"download_category\", \"user_email\", \"file_name\", \"file_realpath\", \"file_description\");
var errorMessages = new Array('".LAN_UL_032."', '".LAN_UL_033."', '".LAN_UL_034."', '".LAN_UL_036."', '".LAN_UL_035."');
var temp;
var i;
for (i = 0; i < 5; i++)
{
temp = document.getElementById(testObjects[i]);
if (temp && (temp.value == \"\"))
{
message = message + spacer + errorMessages[i];
spacer = '\\n';
}
}
if (message)
{
alert(message);
return false;
}
}
");
*/
}
public function init()
{
$ns = e107::getRender();
$uploadAccess = e107::pref('core','upload_class');
if(!check_class($uploadAccess))
{
$text = "
".LAN_UL_002."
";
$ns->tablerender(LAN_UL_020, $text);
return;
}
if (isset($_POST['upload']))
{
$this->processUpload();
return;
}
$this->renderForm();
}
function processUpload()
{
$ns = e107::getRender();
$sql = e107::getDb();
$mes = e107::getMessage();
$tp = e107::getParser();
$error = false;
$postemail ='';
$catID = null;
$catOwner = null;
$file = null;
$image = '';
$filesize = 0;
if ((!empty($_POST['file_email']) || USER == true) && !empty($_POST['file_name']) && !empty($_POST['file_description']) && !empty($_POST['category']))
{
// $uploaded = file_upload(e_FILE."public/", "unique");
$fl = e107::getFile();
$uploaded = $fl->getUploaded(e_UPLOAD, "unique", array('max_file_count' => 2, 'extra_file_types' => TRUE));
// First, see what errors the upload handler picked up
if ($uploaded === false)
{
$error = true;
$mes->addError(LAN_UL_021);
}
// Now see if we have a code file
if (count($uploaded) > 0)
{
if ($uploaded[0]['error'] == 0)
{
$file = $uploaded[0]['name'];
$filesize = $uploaded[0]['size'];
}
else
{
$error = true;
$mes->addError($uploaded[0]['message']);
}
}
// Now see if we have an image file
if (count($uploaded) > 1)
{
if ($uploaded[1]['error'] == 0)
{
$image = $uploaded[1]['name'];
}
else
{
$error = true;
$mes->addError($uploaded[1]['message']);
}
}
// The upload handler checks max file size
if(!empty($_POST['category']))
{
list($catOwner, $catID) = explode("__",$_POST['category'],2);
}
else
{
$error = true;
$mes->addError(LAN_UL_037);
}
// an error - delete the files to keep things tidy
if ($error)
{
@unlink($file);
@unlink($image);
}
else
{
if (USER)
{
$poster = USERID;
$row = e107::getUser()->toArray();
if ($row['user_hideemail'])
{
$postemail = '-witheld-';
}
else
{
$postemail = USEREMAIL;
}
}
else
{
$poster = "0";//.$tp -> toDB($_POST['file_poster']);
$postemail = $tp->toDB($_POST['file_email']);
}
if (($postemail != '-witheld-') && !check_email($postemail))
{
$error = true;
$mes->addError(LAN_UL_001);
}
else
{
if ($postemail == '-witheld-') $postemail = '';
$_POST['file_description'] = $tp->toDB($_POST['file_description']);
$file_time = time();
$insertQry = array(
'upload_id' => 0,
'upload_poster' => $poster,
'upload_email' => $postemail,
'upload_website' => $tp->toDB($_POST['file_website']),
'upload_datestamp' => $file_time,
'upload_name' => $tp->toDB($_POST['file_name']),
'upload_version' => $tp->toDB($_POST['file_version']),
'upload_file' => $file,
'upload_ss' => $image,
'upload_description' => $tp->toDB($_POST['file_description']),
'upload_demo' => $tp->toDB($_POST['file_demo']),
'upload_filesize' => $filesize,
'upload_active' => 0,
'upload_category' => intval($catID),
'upload_owner' => $catOwner
);
$sql->insert("upload", $insertQry);
$edata_fu = $insertQry;
$edata_fu["upload_user"] = $poster;
$edata_fu["upload_time"] = $file_time;
e107::getEvent()->trigger("fileupload", $edata_fu); // BC
e107::getEvent()->trigger("user_file_upload", $edata_fu);
$mes->addSuccess(LAN_404);
}
}
}
else
{ // Error - missing data
$mes->addError(LAN_REQUIRED_BLANK);
}
echo e107::getMessage()->render();
}
function renderForm()
{
/*
$template = "
";
*/
$ns = e107::getRender();
$tp = e107::getParser();
$text = "";
$ns->tablerender(defset('LAN_UL_040', 'Upload File'), $text);
}
//TODO Shortcodes for the form elements above.
function sc_author()
{
$poster = '';
return " ";
}
}
$up = new userUpload();
require_once(HEADERF);
$up->init();
require_once(FOOTERF);