<?php
class download extends plug {
// Bezeichnung des Plugs
var $label = "Download";
// Parameter die in Datenbank gespeichert werden
// save_as kann Werte 'none', 'number' und 'string' annehmen
var $form = array (
"main" => array (
"property" => array("file","title","description","count")
)
);
var $property = array(
"id" => array("type" => "INT NOT NULL AUTO_INCREMENT PRIMARY KEY", "save_as" => "none", "label" => ""),
"title" => array("type" => "VARCHAR(64)", "save_as" => "string", "label" => "Titel"),
"file" => array("type" => "VARCHAR(64)", "save_as" => "string", "label" => "Dateiname"),
"description" => array("type" => "TEXT", "save_as" => "string", "label" => "Beschreibung", "use_editor" => TRUE, "rows" => 10, "editable" => TRUE),
"count" => array("type" => "INT", "save_as" => "int","label" => "bisherige Downloads")
);
function show_form_element($property_name, &$value, $form_id = 0) {
global $paths,$core;
if ($property_name == "file") {
$str = "<p>Datei</p>";
$dir_handle = opendir($paths["project"]."/".$core->get_pref("site_download_dir"));
$str .= "<select name='file'>";
while ($file_name = readdir($dir_handle)) {
if ($file_name != ".." && $file_name != "."){
if ($file_name == $value) $sel = "selected=selected"; else $sel = "";
$str.= "<option $sel>".$file_name."</option>";
}
}
$str.= "</select> <p>Nur Administratoren können Downloads hinzufügen oder löschen</p> ";
return $str;
}
else return plug::show_form_element($property_name, $value, $form_id);
}
function output($content_id, $content_list) {
global $database,$core,$project;
$d_dir = $core->get_pref("site_download_dir");
extract($this->get_content_editable($content_id));
$content = $description;
$link = "_FILE <a href=\"index.php?page_id=$_GET[page_id]&file=$content_id\">$file</a>";
$size = "_SIZE ".round(filesize(getcwd()."/".$d_dir."/".$file)/1024,2)." kb";
$unixTime = filemtime(getcwd()."/".$d_dir."/".$file);
if ($unixTime) {
$time = date("d M Y, H:i:s", $unixTime);
} else {
$time = "_FNOTFOUND";
}
if ($core->get_pref("site_download_size")) $link.= " | $size | _DATE $time";
if ($core->get_pref("site_download_desc")) $desc = "<h2>_DESC</h2><p class=\"downloadcontent\">$content</p>";
if ($core->get_pref("site_download_count")) $cnt = "<p class=\"downloadcount\">Downloads: $count</p>";
if (empty($_GET['file'])){
$str = "<div class=\"download\"><h1>Download: $title</h1><p>$link</p>$desc $cnt</div>";
return $core->get_i18n($str);
}
else{
if ($content_id == $_GET[file]){
if ($core->get_pref("site_referer_check") == "TRUE"){
if ($project["SSL"] == TRUE) $http = "https///";
else $http = "https://";
if ($_SERVER["HTTP_REFERER"] == $http.$project["guest_domain"]."/index.php" || $_SERVER["HTTP_REFERER"] == "http://".$project["guest_domain"]."/".$project["project_dir"]."/index.php") $ref_ok = TRUE;
// check for correct referer
}
else $ref_ok = TRUE;
if (!empty($ref_ok)){
$path = getcwd()."/".$d_dir;
$tbl_download = $database["prefix"]."_download";
$count ++;
$core->query("UPDATE $tbl_download SET count=$count WHERE id = $id");
$dot_pos = strrpos($file, ".");
$ext = strtolower(substr($file, $dot_pos + 1));
$sql = "select type from ".$database["prefix"]."_mime where ext='$ext'";
$res = $core->query($sql);
if (mysql_num_rows($res) == 1) {
$row = mysql_fetch_array($res);
$type = $row["type"];
}
else $type = "text";
header("Content-Type: ".$type);
header("Location: $d_dir/$file");
}
else{
header("Location:index.php");
}
}
}
}
function form_test(&$POST_VARS, &$error_text) {
if (trim($POST_VARS[title]))
return TRUE;
else {
$error_text = "Füllen Sie bitte das Feld 'Titel' aus!";
return FALSE;
}
}
function output_javascript() {
return;
}
}
?>