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');
}
/**
* generate content API
*/
function generate_content(&$title)
{
$title = PLUGIN_DOWNLOADMANAGER_TITLE.' ('.$this->get_config('pageurl').')';
}
/**
* install API
*/
function install()
{
$this->setupDB();
}
/**
* event_ hook API
*/
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 'genpage':
if ($serendipity['rewrite'] != 'none') {
$nice_url = $serendipity['serendipityHTTPPath'] . $addData['uriargs'];
} else {
$nice_url = $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?/' . $addData['uriargs'];
}
$oldsubpage = $serendipity['GET']['subpage'];
if (empty($serendipity['GET']['subpage'])) {
$serendipity['GET']['subpage'] = $nice_url;
}
if ($this->selected()) {
$serendipity['head_title'] = $this->get_config('pagetitle');
$serendipity['head_subtitle'] = (function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['blogTitle']) : htmlspecialchars($serendipity['blogTitle'], ENT_COMPAT, LANG_CHARSET));
} else {
// Put subpage back so staticpage plugin will work
$serendipity['GET']['subpage'] = $oldsubpage;
}
break;
case 'entry_display' :
if ($this->selected()) {
// This is important to not display an entry list!
if (is_array($eventData)) {
$eventData['clean_page'] = true;
} else {
$eventData = array('clean_page' => true);
}
}
break;
case 'backend_sidebar_entries':
$this->setupDB();
// forbid entry if not admin
if (!serendipity_userLoggedIn() && $_SESSION['serendipityAuthedUser'] !== true && $_SESSION['serendipityUserlevel'] != '255') {
break;
}
if ($serendipity['version'][0] < 2) {
echo "\n".' '."\n";
}
break;
case 'backend_sidebar_admin_appearance':
$this->setupDB();
// forbid entry if not admin
if (!serendipity_userLoggedIn() && $_SESSION['serendipityAuthedUser'] !== true && $_SESSION['serendipityUserlevel'] != '255') {
break;
}
if ($serendipity['version'][0] > 1) {
echo "\n".' ' . PLUGIN_DOWNLOADMANAGER_TITLE . ''."\n";
}
break;
case 'backend_sidebar_entries_event_display_downloadmanager':
if (!is_object($serendipity['smarty'])) {
serendipity_smarty_init();
}
$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]);
$q = "UPDATE {$serendipity['dbPrefix']}dma_downloadmanager_files
SET dlcount = dlcount+1
WHERE id = $fileid";
serendipity_db_query($q);
$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;
}
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;
}
$dlm_css = '';
$tfile = serendipity_getTemplateFile('style_dlmanager_frontend.css', 'serendipityPath');
if ($tfile) {
$dlm_css = @file_get_contents($tfile);
}
if (!$tfile || $tfile == 'style_dlmanager_frontend.css') {
$tfile = dirname(__FILE__) . '/style_dlmanager_frontend.css';
$dlm_css = @file_get_contents($tfile);
}
$eventData .= $dlm_css; // append CSS
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);
}
if (!empty($tfilecontent) && $serendipity['version'][0] < 2) {
$tfilecontent .= '
#dlm_messages {
margin: 16px 0;
padding: 4px;
text-align: center;
}
';
}
// add replaced css content to the end of serendipity_admin.css
if (!empty($tfilecontent)) $this->backend_dlm_css($eventData, $tfilecontent);
break;
case 'entries_header' :
//this shows our page and not an empty one
$this->show();
break;
default:
return false;
}
return true;
} else {
return false;
}
}
/***************************************************
* 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(
'hlp[0]' => PLUGIN_DOWNLOADMANAGER_HELPTIP_CF_START,
'hlp[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
/*
'hlp[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;
}
}
/**
* fetch dlm backend pathfiles table content
*
* @param string The path to iterate
* @param boolean If path is Serendipity MediaLibrary (default false)
*
* @return array
*/
function backend_dlm_fetch_pathfiles($path, $ml=false)
{
$fa = array();
$fa['d_arr'] = array();
$fa['f_arr'] = array();
$d = 0;
$f = 0;
if (!is_dir($path)) return;
try {
$_dir = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
// NOTE: UnexpectedValueException thrown for PHP >= 5.3
} catch (Exception $e) {
echo "Error: " . $e->getMessage();#return;
}
if ($ml) {
$iterator = new RecursiveIteratorIterator($_dir, RecursiveIteratorIterator::SELF_FIRST);
} else {
$iterator = new RecursiveIteratorIterator($_dir, RecursiveIteratorIterator::CHILD_FIRST);
}
foreach ($iterator AS $file) {
$_bfname = $this->mb_basename($file);
$_mdepth = $ml ? $iterator->getDepth() : 0; // allows to avoid recursive file iteration in ML since we have the dir structure to navigate
if ($file->isFile() && $_mdepth == 0 && $_bfname != '.empty' && (false === (strpos($_bfname, '.serendipityThumb')))) {
$filename = $this->encodeToUTF($file->getPathname(), true); // OK
$fa['f_arr'][++$f] = str_replace("\\", "/", $filename);
} else {
// do we need to do this encoding stuff for dir path too?
if ($file->isDir()) {
$fa['d_arr'][++$d] = str_replace("\\", "/", $file->__toString());
}
}
}
#echo '';debug_print_backtrace();echo '
';
#echo '' . print_r($fa, true) . '
';
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 and assign 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;
// fetch all physically files in incoming ftp or trash table
$ifiles = $this->backend_dlm_fetch_pathfiles($absinth); // is 3rd and last run in workflow
$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(), true ) . '
';
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