";
}
$nextprevQry = $this->qry;
$nextprevQry['from'] = '[FROM]';
unset($nextprevQry['id'],$nextprevQry['name'],$nextprevQry['action']);
$newUrl = e107::url('download','category',$catRows, array('query'=>$nextprevQry));
$nextprev = array(
'tmpl_prefix' =>'default',
'total' => $total_downloads,
'amount' => intval($this->qry['view']),
'current' => $this->qry['from'],
'url' => urldecode($newUrl)
);
global $nextprev_parms;
$nextprev_parms = http_build_query($nextprev,false); // 'tmpl_prefix='.deftrue('NEWS_NEXTPREV_TMPL', 'default').'&total='. $total_downloads.'&amount='.$amount.'¤t='.$newsfrom.$nitems.'&url='.$url;
$text .= $tp->parseTemplate($DOWNLOAD_LIST_NEXTPREV, TRUE, $sc);
return $text;
}
/**
* Render a 'Broken Download' Report form.
*/
private function renderReport()
{
$sql = e107::getDb();
$tp = e107::getParser();
$ns = e107::getRender();
$frm = e107::getForm();
$pref = e107::getPref();
$mes = e107::getMessage();
$dlrow = $this->rows;
// Check if user is allowed to make reports, and if user is allowed to view the actual download item
if(!check_class($dlrow['download_class']) || !check_class($pref['download_reportbroken']))
{
$mes->addError(LAN_dl_79);
return $ns->tablerender(LAN_PLUGIN_DOWNLOAD_NAME, $mes->render(), 'download-report', true);
}
$download_name = $tp->toDB($dlrow['download_name']);
$download_sef = $dlrow['download_sef'];
$download_id = (int) $dlrow['download_id'];
$breadcrumb = array();
$breadcrumb[] = array('text' => LAN_PLUGIN_DOWNLOAD_NAME, 'url' => e107::url('download','index', $dlrow));
$breadcrumb[] = array('text' => $dlrow['download_category_name'], 'url' => e107::url('download','category', $dlrow));
$breadcrumb[] = array('text' => $dlrow['download_name'], 'url' => e107::url('download','item', $dlrow));
$breadcrumb[] = array('text' => LAN_dl_45, 'url' => null);
e107::breadcrumb($breadcrumb);
if (isset($_POST['report_download']))
{
$report_add = $tp->toDB($_POST['report_add']);
$user = USER ? USERNAME : LAN_GUEST;
$ip = e107::getIPHandler()->getIP(false);
// Replaced by e_notify
/*
if ($pref['download_email'])
{ // this needs to be moved into the NOTIFY, with an event.
require_once(e_HANDLER."mail.php");
$subject = LAN_dl_60." ".SITENAME;
$report = LAN_dl_58." ".SITENAME.":\n".(substr(SITEURL, -1) == "/" ? SITEURL : SITEURL."/")."download.php?view.".$download_id."\n
".LAN_dl_59." ".$user."\n".$report_add;
sendemail(SITEADMINEMAIL, $subject, $report);
}*/
$brokendownload_data = array(
'download_id' => $download_id,
'download_sef' => $download_sef,
'download_name' => $download_name,
'report_add' => $report_add,
'user' => $user,
'ip' => $ip,
);
e107::getEvent()->trigger('user_download_brokendownload_reported', $brokendownload_data);
$sql->insert('generic', "0, 'Broken Download', ".time().",'".USERID."', '{$download_name}', {$download_id}, '{$report_add}'");
$text = $frm->breadcrumb($breadcrumb);
$text .= "
".LAN_dl_48."
".LAN_dl_49."";
return $ns->tablerender(LAN_PLUGIN_DOWNLOAD_NAME, $text, 'download-report', true);
}
else
{
$text = $frm->breadcrumb($breadcrumb);
$formUrl = e107::url('download', 'report', $dlrow);
$fileUrl = e107::url('download', 'view', $dlrow);
$text .= "";
return $ns->tablerender(LAN_PLUGIN_DOWNLOAD_NAME, $text, 'download-report', true);
}
}
/**
* Render Download Mirrors for the selected file.
*/
private function renderMirror()
{
$sql = e107::getDb();
$tp = e107::getParser();
$ns = e107::getRender();
$pref = e107::getPref();
if(deftrue('BOOTSTRAP')) // v2.x
{
$template = e107::getTemplate('download','download','mirror');
$DOWNLOAD_MIRROR_START = $template['start'];
$DOWNLOAD_MIRROR = $template['item'];
$DOWNLOAD_MIRROR_END = $template['end'];
}
else // Legacy v1.x
{
$template_name = 'download_template.php';
if (is_readable(THEME."templates/".$template_name))
{
require_once(THEME."templates/".$template_name);
}
elseif (is_readable(THEME.$template_name))
{
require_once(THEME.$template_name);
}
else
{
require_once(e_PLUGIN."download/templates/".$template_name);
}
}
/** @var download_shortcodes $sc */
$sc = e107::getScBatch('download',true);
$sc->wrapper('download/mirror');
$sc->breadcrumb();
$sc->qry = $this->qry;
// $load_template = 'download_template';
// if (!isset($DOWNLOAD_MIRROR_START)) eval($template_load_core);
$sql->select("download_mirror");
$mirrorList = $sql->db_getList("ALL", 0, 200, "mirror_id");
$query = "
SELECT d.*, dc.* FROM #download AS d
LEFT JOIN #download_category AS dc ON d.download_category = dc.download_category_id
WHERE d.download_id = ".$this->qry['id']."
LIMIT 1";
// global $dlmirrorfile, $dlmirror;
if($sql->gen($query))
{
$dlrow = $sql->fetch();
// $dlrow['mirrorlist'] = $mirrorList;
$sc->setVars($dlrow);
$array = explode(chr(1), $dlrow['download_mirror']);
if (2 == varset($pref['mirror_order']))
{
// Order by name, sort array manually
usort($array, "sort_download_mirror_order");
}
//elseif (1 == varset($pref['mirror_order']))
//{
// // Order by ID - do nothing order is as stored in DB
//}
elseif (0 == varset($pref['mirror_order'], 0))
{
// Shuffle the mirror list into a random order
$c = count($array);
for ($i=1; $i<$c; $i++)
{
$d = mt_rand(0, $i);
$tmp = $array[$i];
$array[$i] = $array[$d];
$array[$d] = $tmp;
}
}
$dl_text = $tp->parseTemplate($this->templateHeader, TRUE, $sc);
$dl_text .= $tp->parseTemplate($DOWNLOAD_MIRROR_START, TRUE, $sc);
$download_mirror = 1;
foreach($array as $mirrorstring)
{
if($mirrorstring)
{
$dlmirrorfile = explode(",", $mirrorstring);
// $dlmirror = $mirrorList[$dlmirrorfile[0]];
$sc->mirror['dlmirrorfile'] = $dlmirrorfile;
$sc->mirror['dlmirror'] = $mirrorList[$dlmirrorfile[0]];
$dl_text .= $tp->parseTemplate($DOWNLOAD_MIRROR, TRUE, $sc);
}
}
$dl_text .= $tp->parseTemplate($DOWNLOAD_MIRROR_END, TRUE, $sc);
$dl_text .= $tp->parseTemplate($this->templateFooter, TRUE, $sc);
return $ns->tablerender(LAN_PLUGIN_DOWNLOAD_NAME, $dl_text, 'download-mirror', true);
}
}
/**
* Render Download Errors.
*/
private function renderError()
{
$ns = e107::getRender();
$pref = e107::getPref();
$tp = e107::getParser();
$sc = e107::getScBatch('download',true);
$header = $tp->parseTemplate($this->templateHeader,true, $sc);
$footer = $tp->parseTemplate($this->templateFooter,true, $sc);
switch ($this->qry['error'])
{
case 1 : // No permissions
if (strlen($pref['download_denied']) > 0)
{
$errmsg = $tp->toHTML($pref['download_denied'],true, 'DESCRIPTION');
}
else
{
$errmsg = LAN_dl_63;
}
break;
case 2 : // Quota exceeded
$errmsg = LAN_dl_62;
break;
default: // Generic error - shouldn't happen
$errmsg = LAN_ERROR." ".$this->qry['error'];
}
return $ns->tablerender(LAN_PLUGIN_DOWNLOAD_NAME, $header. "
".$errmsg."
". $footer, 'download-error', true);
}
function getCategorySelectList($currentID=0, $incSubSub=true, $groupOnMain=true, $blankText=" ", $name="download_category")
{
global $sql,$parm;
$boxinfo = "\n";
$qry = "
SELECT dc.download_category_name, dc.download_category_order, dc.download_category_id, dc.download_category_parent,
dc1.download_category_parent AS d_parent1
FROM #download_category AS dc
LEFT JOIN #download_category as dc1 ON dc1.download_category_id=dc.download_category_parent AND dc1.download_category_class IN (".USERCLASS_LIST.")
LEFT JOIN #download_category as dc2 ON dc2.download_category_id=dc1.download_category_parent ";
if (ADMIN === FALSE) $qry .= " WHERE dc.download_category_class IN (".USERCLASS_LIST.") ";
$qry .= " ORDER by dc2.download_category_order, dc1.download_category_order, dc.download_category_order"; // This puts main categories first, then sub-cats, then sub-sub cats
if (!$sql->gen($qry))
{
return "Error reading categories ";
exit;
}
$boxinfo .= "\n";
return $boxinfo;
}
}
function sort_download_mirror_order($a, $b)
{
$a = explode(",", $a);
$b = explode(",", $b);
if ($a[1] == $b[1]) {
return 0;
}
return ($a[1] < $b[1]) ? -1 : 1;
}