UPLOAD_NOTCOPIED);++$a) {
$ERRMSG .= $this->UPLOAD_NOTCOPIED[$a]."
";
}
}
$this->ERRMSG($ERRMSG);
}
$ct = (isset($_GET['dlmftpdir']) && (intval($_GET['dlmftpdir']) == 1) ? true : false);
$files = $this->dlm_sql_db('DLM_SELECT_ARRAY', "catid = ".$id." ORDER BY timestamp DESC");
$ddiv = ($_GET['thiscat'] && $num_dls > 0) ? true : false;
// generate file table content here - DIV 1 @ PAGE 2
$this->backend_dlm_build_filetable($files, (($ct) ? false : $ddiv), $this->globs['ftppath'], $this->globs['dlmpath'], $this->globs['dateformat'], $num_dls, intval($_GET['thiscat']), 1, 2);
// generate ftp/trash folder table content here - DIV 2 @ PAGE 2
$this->backend_dlm_build_ftptable($ct, $this->globs['ftppath'], intval($_GET['thiscat']), 2, 2);
// generate media library folder table content here - DIV 3 @ PAGE 2
$this->backend_dlm_build_s9ml_table($this->globs['dateformat'], $serendipity['serendipityPath'] . $serendipity['uploadPath'], 3, 2);
if( !is_array($cats) ) {
$cats = array();
$cats = $this->GetAllCats(true);
if (is_array($cats) && sizeof($cats) >= 1) {
unset($cat);
}
}
// new: generate categories table - DIV 4 (permanently open = true) @ PAGE 2
$this->backend_dlm_build_categories($cats, (($ct) ? false : true), $this->globs['ftppath'], intval($_GET['thiscat']), 4, 2);
// generate appendix trash & helptip
$this->backend_dlm_appendix($this->globs['ftppath'], intval($_GET['thiscat']), 5, 2);
}
}
} else {
$this->ERRMSG(PLUGIN_DOWNLOADMANAGER_CAT_NOT_FOUND);
}
} else {
/* BACKEND PAGE 1 ROOT SECTION
- add subcategories to root or selected category
- files in selected category,
- subcategories of root,
- the appendix (including the helptip and the clear trash button) */
if(!$_GET['thiscat'] || empty($_GET['thiscat'])) $_GET['thiscat'] = 1;
// generate categories add table - DIV 1 @PAGE 1 == startpage
$this->backend_dlm_add_categories($cats, 1, 1);
$files = $this->dlm_sql_db('DLM_SELECT_ARRAY', "catid = 1 ORDER BY timestamp DESC");
$fnum = (is_array($files) ? count($files) : 0);
// new: generate file table content here - DIV 2 @ PAGE 1 == startpage
$this->backend_dlm_build_filetable($files, $ddiv, $this->globs['ftppath'], $this->globs['dlmpath'], $this->globs['dateformat'], $fnum, intval($_GET['thiscat']), 2, 1);
if( !is_array($cats) ) {
$cats = array();
$cats = $this->GetAllCats(true);
if (is_array($cats) && sizeof($cats) >= 1) {
unset($files);
}
}
// generate categories table - DIV 3 (permanently open = true) @ PAGE 1 == startpage
$this->backend_dlm_build_categories($cats, true, $this->globs['ftppath'], intval($_GET['thiscat']), 3, 1);
// generate appendix trash & helptip
$this->backend_dlm_appendix($this->globs['ftppath'], intval($_GET['thiscat']), 4, 1);
}
/* get the backend dlm index template file */
echo $this->parseTemplate('backend.dlm.index.tpl');
} // logged-in end
}
function generate_content(&$title) {
$title = PLUGIN_DOWNLOADMANAGER_TITLE.' ('.$this->get_config('pageurl').')';
}
function install() {
$this->setupDB();
}
function event_hook($event, &$bag, &$eventData, $addData = null) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
$serendipity['plugin_dlm_version'] = &$bag->get('version');
if (isset($hooks[$event])) {
switch($event) {
case 'entry_display' :
if ($this->selected()) {
if (is_array($eventData)) {
$eventData['clean_page'] = true;
} else {
$eventData = array ('clean_page' => true);
}
}
return true;
break;
case 'backend_sidebar_entries':
$this->setupDB();
// forbid entry if not admin
if(serendipity_userLoggedIn() && $_SESSION['serendipityAuthedUser'] === true && $_SESSION['serendipityUserlevel'] == '255') {
?>
get_config('chg2archivespath')) ) {
$oldfilepath = ($this->get_config('absdownloadspath') ? $this->get_config('absdownloadspath') : $serendipity['serendipityPath'] . 'templates_c/.dlmanager/files');
$newfilepath = $serendipity['serendipityPath'] . 'archives/.dlm/files';
// upgrade the old encoded files to new dir
$updown = $this->backend_dlm_upgrade($oldfilepath, $newfilepath, 'absdownloadspath');
$oldinpath = ($this->get_config('absincomingpath') ? $this->get_config('absincomingpath') : $serendipity['serendipityPath'] . $serendipity['uploadPath'] . '.dlmanager/incoming');
$newinpath = $serendipity['serendipityPath'] . 'archives/.dlm/ftpin';
// upgrade the old incoming ftp/trash files to new dir
$upin = $this->backend_dlm_upgrade($oldinpath, $newinpath, 'absincomingpath');
if(true === ($updown || $upin)) {
$this->set_config('chg2archivespath', true);
$url = $_SERVER['PHP_SELF'] . '?serendipity[adminModule]=event_display&serendipity[adminAction]=downloadmanager&cpdone=1';
$this->backend_dlm_refresh($url);
}
}
break;
case 'backend_sidebar_entries_event_display_downloadmanager':
$serendipity['dlm']['stopadminprocess'] = false;
if (!is_object(isset($serendipity['smarty']))) {
serendipity_smarty_init(); // if not set to avoid member function assign() on a non-object error, start Smarty templating
}
// load the 0.24 upgrade hook
if (version_compare($serendipity['plugin_dlm_version'], '0.24', '<=')) {
serendipity_plugin_api::hook_event('backend_dlm_filecopy', $addData);
} else {
if(!serendipity_db_bool($this->get_config('chg2archivespath'))) $this->set_config('chg2archivespath', true);
}
if(intval($_GET['cpdone']) == 0) $this->set_config('chg2archivespath', true);
if( intval(isset($_GET['cpdone'])) || $serendipity['dlm']['stopadminprocess'] === false ) {
$this->ADMIN_showDownloads();
}
break;
case 'external_plugin':
$uri_parts = explode('?', str_replace('&', '&', $eventData));
// Try to get request parameters from eventData name
if (!empty($uri_parts[1])) {
$reqs = explode('&', $uri_parts[1]);
foreach($reqs AS $id => $req) {
$val = explode('=', $req);
if (empty($_REQUEST[$val[0]])) {
$_REQUEST[$val[0]] = $val[1];
}
}
}
$parts = explode('_', $uri_parts[0]);
if (!empty($parts[1])) {
$param = (int) $parts[1];
} else {
$param = null;
}
switch($parts[0]) {
case 'dlfile':
$fileid = intval($parts[1]);
serendipity_db_query("UPDATE {$serendipity['dbPrefix']}dma_downloadmanager_files SET dlcount = dlcount+1 WHERE id = " . $fileid);
$sql = "SELECT * FROM {$serendipity['dbPrefix']}dma_downloadmanager_files WHERE id = ".$fileid;
$file = serendipity_db_query($sql);
$mime = $this->getMime($file[0]['realfilename']);
$contenttype = $mime['TYPE'];
$filename = $file[0]['realfilename'];
$filename = str_replace(' ', '_', $filename);
$path = $this->globs['dlmpath'];
$sysname = $file[0]['systemfilename'];
$filesize = $file[0]['filesize'];
if (function_exists("getallheaders")) {
$headers = getallheaders();
}
if (substr($headers["Range"], 0, 6) == "bytes=") {
header("HTTP/1.1 206 Partial Content");
header("Content-Type: $contenttype");
header("Content-Disposition: attachment; filename=".$filename);
header("Accept-Ranges: bytes");
header("Connection: close");
$bytes = explode("=",$headers["Range"]);
$bytes = $bytes[1];
if (preg_match("@^-([0-9]+)@", $bytes, $bytes_len)) {
$bytes_len = $bytes_len[1];
$bytes_start = $filesize - $bytes_len;
$bytes_end = $filesize - 1;
header("Content-Length: ".$bytes_len);
} elseif (preg_match("@([0-9]+)-$@", $bytes, $bytes_start)) {
$bytes_start = $bytes_start[1];
$bytes_end = $filesize - 1;
$bytes_len = $filesize - $bytes_start;
header("Content-Length: $bytes_len");
} elseif (preg_match("@^([0-9]+)-([0-9]+)$@", $bytes, $bytes_pos))
{
$bytes_start = $bytes_pos[0];
$bytes_end = $bytes_pos[1];
if ($bytes_start < 0 || $bytes_start > ($filesize - 1)) {
$bytes_start = 0;
}
if ($bytes_end < $bytes_start || $bytes_end > ($filesize - 1)) {
$bytes_end = $filesize - 1;
}
$bytes_len = $bytes_end - $bytes_start + 1;
header("Content-Length: $bytes_len");
} else {
$bytes_start = 0;
$bytes_end = $filesize - 1;
$bytes_len = $bytes_end - $bytes_start + 1;
header("Content-Length: $bytes_len");
}
header("Content-Range: bytes $bytes_start-$bytes_end/".$filesize);
$fp = fopen($path."/".$sysname,"rb");
fseek($fp, $bytes_start);
$contents = fread ($fp, $bytes_len );
fclose($fp);
echo $contents;
} else {
$fp = fopen($path."/".$sysname,"rb");
$contents = fread ($fp, $filesize);
fclose($fp);
header("Content-Type: $contenttype");
header("Content-Disposition: attachment; filename=".$filename);
header("Accept-Ranges: bytes");
header("Content-Length: " . strlen($contents));
header("Connection: close");
echo $contents;
}
break;
}
return true;
break;
/* put here all your css stuff you need for the downloadmanagers plugin frontend output */
case 'css':
if (stristr($eventData, '#downloadmanager')) {
// class exists in CSS, so a user has customized it and we don't need default
return true;
}
$tfile = serendipity_getTemplateFile('style_dlmanager_frontend.css', 'serendipityPath');
if($tfile) echo @file_get_contents($tfile);
if (!$tfile || $tfile == 'style_dlmanager_frontend.css') {
$tfile = dirname(__FILE__) . '/style_dlmanager_frontend.css';
echo @file_get_contents($tfile);
}
return true;
break;
/* put here all you css stuff you need for the backend of dlm */
case 'css_backend':
if (stristr($eventData, '#backend_downloadmanager')) {
// class exists in CSS, so a user has customized it and we don't need default
return true;
}
$tfile = serendipity_getTemplateFile('style_dlmanager_backend.css', 'serendipityPath');
if($tfile) {
$tfilecontent = @file_get_contents($tfile);
}
if ( (!$tfile || $tfile == 'style_dlmanager_backend.css') && !$tfilecontent ) {
$tfile = dirname(__FILE__) . '/style_dlmanager_backend.css';
$tfilecontent = @file_get_contents($tfile);
}
// add replaced css content to the end of serendipity_admin.css
if(!empty($tfilecontent)) $this->backend_dlm_css($eventData, $tfilecontent);
return true;
break;
case 'entries_header' :
//this shows our page and not an empty one
$this->show();
return true;
break;
default:
return false;
break;
} // switch end
}
return true;
}
/***************************************************
* Backend administration functions
**************************************************/
/* add backend css to serendipity_admin.css */
function backend_dlm_css(&$eventData, &$becss) {
$eventData .= $becss;
}
/** helptip array
* HELPTIP_CF = (sub)category folder;
* HELPTIP_FF = file folder;
* HELPTIP_IF = incoming ftp/trash folder;
* HELPTIP_MF = s9y media library folder;
*/
function backend_dlm_helptip() {
return array(
'htp[1]' => PLUGIN_DOWNLOADMANAGER_HELPTIP_CF_CHANGE,
'hlp[2]' => PLUGIN_DOWNLOADMANAGER_HELPTIP_FF_CHANGE,
'hlp[3]' => PLUGIN_DOWNLOADMANAGER_HELPTIP_IF_VIEW,
'hlp[4]' => PLUGIN_DOWNLOADMANAGER_HELPTIP_IF_ERASE,
'hlp[5]' => PLUGIN_DOWNLOADMANAGER_HELPTIP_IF_TRASH,
'hlp[6]' => PLUGIN_DOWNLOADMANAGER_HELPTIP_FF_MULTI,
'hlp[7]' => PLUGIN_DOWNLOADMANAGER_HELPTIP_FF_SINGLE,
'hlp[8]' => PLUGIN_DOWNLOADMANAGER_HELPTIP_FF_KEEP,
'hlp[9]' => PLUGIN_DOWNLOADMANAGER_HELPTIP_IF_MOVE,
'hlp[10]' => PLUGIN_DOWNLOADMANAGER_HELPTIP_IF_LFTP,
'hlp[11]' => PLUGIN_DOWNLOADMANAGER_HELPTIP_DESC
/*
'htp[3]' => PLUGIN_DOWNLOADMANAGER_HELPTIP_IF_S9ML,
'hlp[]' => PLUGIN_DOWNLOADMANAGER_HELPTIP_,
*/
);
}
/**
* refresh a page to show correct values directly after move, erase, clean etc (mostly done on page 2)
* order by header(), Javascript, HTML (meta refresh)
*
* @param string request url
* @return false exit page
*/
function backend_dlm_refresh($url) {
if($url && !headers_sent()) {
if(header('Location: http://' . $_SERVER['HTTP_HOST'] . $url)) exit;
} else {
echo '';
echo '';
exit;
}
}
/**
* upgrade files with v.0,24 to /archives/.dlm/files and /archives/.dlm/ftpin folder
*
* @param string oldpath
* @param string newpath
* @param string config name set
*
* @return true or false
*/
function backend_dlm_upgrade($old, $new, $coname) {
global $serendipity;
if (!is_dir($new)) {
@mkdir($new, 0777, true);
}
// fetch the files (encoded or normal) of old path as an array
$files = $this->backend_dlm_fetch_pathfiles($old);
if(is_array($files['f_arr']) && !empty($files['f_arr']) ) {
foreach($files['f_arr'] as $k => $v) {
// This does not rename the files, as you might assume, instead, it moves them physically!
if(!@rename ($old.'/'.$v, $new.'/'.$v)) {
// void
} else {
$result[] = array($v => true);
}
}
if( is_array($result) && !empty($result) ){
unset($files);
unset($result);
$this->set_config($coname, $new);
return true;
} else {
if($coname == 'absincomingpath') echo '
';
$url = $_SERVER['PHP_SELF'] . '?serendipity[adminModule]=event_display&serendipity[adminAction]=downloadmanager&cpdone=0';
$this->ERRMSG($this->globs['attention'] . ' ' . sprintf(PLUGIN_DOWNLOADMANAGER_ERRORS_UPGRADE_NOTCOPIED, $old, $new, $url));
$serendipity['dlm']['stopadminprocess'] = true;
return false;
}
} else {
// nada in old path - set config and return true to continue
$this->set_config($coname, $new);
return true;
}
}
/***
* fetch dlm backend pathfiles table content
*
* @param string The path to the s9y media library
*
* @return array
*/
function backend_dlm_fetch_pathfiles($path) {
$fa['d_arr'] = array(); $d = 0;
$fa['f_arr'] = array(); $f = 0;
if( is_dir( $path ) ) {
if( $handle = opendir( $path ) ) {
while( false !== ( $file = readdir( $handle ) ) ) {
if( $file != "." && $file != ".." && $file[0] != "." ) {
if( is_dir( $path . "/" . $file ) )
$fa['d_arr'][++$d] = $file;
else
$fa['f_arr'][++$f] = $file;
}
}
}
}
if( is_dir( $path ) ) closedir( $handle );
return $fa;
}
/**
* recursive str_replaces in files array, happens to special keys only, used by smarty files array to set filesize, mime array and filedate
*
* @param array the array data
* @param string/boolean use with date() replacement funktion too
* @param string/boolean search in specific key only = string (optional)
* @param string/boolean new keyname, use with different replacement funktion only (optional)
*
* @return array
**/
function backend_str_replace_recursive(&$data, $p=false, $skey=false, $nkey=false) {
if(is_array($data)) {
foreach($data as $key => $value) {
if (is_array($value) ) {
$this->backend_str_replace_recursive($data[$key], $p, $skey, $nkey);
} else {
if($key == $skey) {
if(!$nkey) $data[$key] = ($p ? date($p, $value) : $this->calcFilesize($value));
elseif ($p === false) $data[$nkey] = $this->getMime($value);
else $data[$nkey] = ($p ? date($p, $value) : $this->calcFilesize($value));
}
}
}
}
return isset($data) ? $data : false;
}
/* see function backend_str_replace_recursive() - this one is for categories only */
function backend_str_replace_recursive_cat(&$data, $p=false, $skey=false, $nkey=false) {
if(is_array($data)) {
foreach($data as $key => $value) {
if (is_array($value) ) {
$this->backend_str_replace_recursive_cat($data[$key], $p, $skey, $nkey);
} else {
if($key === $skey) $data[$nkey] = (550 - (20 * $value));
}
}
}
return isset($data) ? $data : false;
}
/** generate backend appendix trash & helptip
*
* @param string The configs absincomepath
* @param int The category id number
* @param int The div number (standard=3)
* @param int The page number
*
* @return string
*/
function backend_dlm_appendix($absinth='', $cn=1, $dn=0, $pn=0) {
global $serendipity;
$attention = $this->globs['attention'];
// fetch all physically files in incoming ftp or trash table
$ifiles = $this->backend_dlm_fetch_pathfiles($absinth);
$ifn = count($ifiles['f_arr']);
unset($ifiles);
// assign the backend appendix vars to smarty template page section 'appendix'
$serendipity['smarty']->assign('dlmapx',
array(
'appendix' => true,
'cleanme' => ($ifn >= 1) ? true : false,
'helplist' => $this->backend_dlm_helptip()
)
);
// view all smarty template vars
#echo '';
#print_r( $serendipity['smarty']->get_template_vars() );
#echo '
';
return;
}
/***
* build the dlm backend add categories table
*
* @param array A referenced array of categories
* @param int The div number (standard=3)
* @param int The page number
*
* @return string
*/
function backend_dlm_add_categories($cats, $dn=0, $pn=0) {
global $serendipity;
// build the category list in backend => true and as