* * * WARNING: This version is modified to Suit the Carlsberg needs!!!! * */ require_once(PATH_tslib."class.tslib_pibase.php"); require_once(PATH_t3lib."class.t3lib_basicfilefunc.php"); require_once(PATH_t3lib."class.t3lib_extfilefunc.php"); require_once(t3lib_extMgm::extPath("moc_filemanager")."/res/class.mount.php"); require_once(t3lib_extMgm::extPath("moc_filemanager")."/res/class.filemanager_div.php"); class tx_mocfilemanager_pi1 extends tslib_pibase { var $prefixId = "tx_mocfilemanager_pi1"; // Same as class name var $scriptRelPath = "pi1/class.tx_mocfilemanager_pi1.php"; // Path to this script relative to the extension dir. var $extKey = "moc_filemanager"; // The extension key. /** * MAIN Called by TYPO3 core engine */ function main($content,$conf) { $this->conf=$conf; $this->pi_setPiVarDefaults(); $this->pi_loadLL(); $this->pi_initPIflexForm(); $this->transferFlexToData(); $this->div = new filemanager_div(); $this->dbObj = $GLOBALS['TYPO3_DB']; $this->cInfo = t3lib_div::clientInfo(); //For now this is only for Internet explorer! $this->canUseLayers = ($this->cInfo['BROWSER'] == 'msie' ? 1 : 0); $this->recursive = $this->cObj->stdWrap($this->conf["recursive"],$this->conf["recursive."]);; $this->mode = strtoupper($this->cObj->stdWrap($this->conf["CODE"],$this->conf["CODE."])); $this->asExplorer = 1; //**************** DETERMINE WHERE TO GET FOUNTS FROM ******************* $this->selectFrom = strtoupper($this->cObj->stdWrap($this->conf["selectFrom"],$this->conf["selectFrom."])); $this->from = $this->cObj->stdWrap($this->conf["from"],$this->conf["from."]); list($filter["code"],$filter["mount"],$filter["dir"]) = split('[|]', $this->mode); $this->mode = $filter["code"]; $this->mountPID = $this->pi_getPidList($this->cObj->stdWrap($this->conf["mountStoragePID"],$this->conf["mountStoragePID."]),$this->recursive); $this->filesPID = $this->cObj->stdWrap($this->conf["filesStoragePID"],$this->conf["filesStoragePID."]); $this->maxDepth = $this->cObj->stdWrap($this->conf["maxDepth"],$this->conf["maxDepth."]); $this->showFilesPID = $this->cObj->stdWrap($this->conf["showFilesPID"],$this->conf["showFilesPID."]); if(!($this->showFilesPID)) { $this->showFilesPID = $GLOBALS["TSFE"]->id; } //This is a super hack, sorry for that, but It was the fastest way to solve the problem if($conf["superroot"]) { $this->documentRoot = $this->div->clean_dir($conf["superroot"].$this->cObj->stdWrap($conf["documentRoot"],$conf["documentRoot."])); } else { $this->documentRoot = $this->div->clean_dir($this->cObj->stdWrap($conf["documentRoot"],$conf["documentRoot."])); } $this->wraps=array(); $this->Activewraps=array(); $this->ActiveATagParams = array(); $this->ATagParams = array(); for($i = 0; $i <$this->maxDepth+1; $i++) { array_push($this->wraps,$this->conf["levels."]["level$i."]["wrap"]); array_push($this->Activewraps,$this->conf["levels."]["level$i."]["ACT."]["wrap"]); if($this->conf["levels."]["level$i."]["ATagParams"]) array_push($this->ATagParams,$this->conf["levels."]["level$i."]["ATagParams"]); else array_push($this->ATagParams,'class="filelink"'); if($this->conf["levels."]["level$i."]["ACT."]["ATagParams"]) array_push($this->ActiveATagParams,$this->conf["levels."]["level$i."]["ACT."]["ATagParams"]); else array_push($this->ActiveATagParams,'class="filelinkActive"'); } $this->mountwrap = $this->conf["mountwrap"]; $this->asExplorer = $this->conf["asExplorer"] ? 1:0; if($this->mode == "UPLOAD_ONLY") { if($this->from) { $temp = explode(",",$this->from); $this->mountID = $temp[0] ; // hard coded mount var stored in CODE parameter } } else { $this->mountID = t3lib_div::GPvar("mountpoint"); } $filename=t3lib_div::GPvar("filename"); //If this is set, hten a file is uploaded along the request. $uploadfile=t3lib_div::GPvar("uploadfile"); //If this is set, then the user asked to make a directory. $mkdir=t3lib_div::_GP("mkdir"); // Get the mountpoints. if($this->selectFrom == "CHOOSE") { //Mountpoints are chosen manually } if($this->selectFrom == "CHOOSE" || $this->selectFrom == "PAGES" || $this->selectFrom == "THISPAGE") { $this->mountlist = array(); if($this->selectFrom == "CHOOSE") $mountlist =$this->from; if($this->selectFrom == "PAGES") { $mountlist = $this->getAllMountIdsInPages($this->pi_getPidList($this->cObj->stdWrap($this->conf["mountStoragePID"],$this->conf["mountStoragePID."]),$this->recursive)); } if($this->selectFrom == "THISPAGE") $mountlist = $this->getAllMountIdsInPages($GLOBALS['TSFE']->id); foreach(explode(",",$mountlist) as $mp) { if($mp == $this->mountID) { $this->mount = new mount(intval($mp),$this->documentRoot); $this->mountlist[] = &$this->mount; } else { $this->mountlist[] = new mount(intval($mp),$this->documentRoot); } } //Make a check. If no mount is specified, make the first mount i mountlist the active one. Unless were in LISTDIRS mode, then there is no active mount. if(!$this->mount && $this->mode != "LISTDIRS") { $this->mount = &$this->mountlist[0]; } } else { //Default is to take it from piVars $this->mount = new mount($this->mountID,$this->documentRoot); $this->mountlist[] = &$this->mount; } $this->filehandler_mps=array(); $this->initSingleMountPoint($this->mount); $this->initFilehandler(); $reldir = ereg_replace("^/","",t3lib_div::GPvar("dir")); if($this->mount) { $dir=$this->div->clean_dir($this->mount->getDir()."/".$reldir); } else { $dir = ""; } // The rootline of files (The path broken up essentially) $this->filelistRootLine = explode("/",$reldir); $task=t3lib_div::GPvar("task"); //Init done. /* * * ####################### LISTDIRS ####################### * */ if($this->mode == "LISTDIRS") { foreach($this->mountlist as $mp) { if($this->hasAccess($mp,$dir,"read")) { $tempstr = ""; if($this->asExplorer) { $tempstr .= "
![]() |
'.$this->pi_getLL("noreadaccessfordownload").'
'; return $this->pi_wrapInBaseClass($content); } // print $this->div->test(); //print "Updating downloads for file $filename: ".$this->dbObj->UPDATEquery('tx_mocfilemanager_files','file="'.$this->dbObj->quoteStr($reldir."/".$filename,'tx_mocfilemanager_files').'" AND mount='.intval($this->mount->uid),array("downloads"=>'downloads + 1')); // print "Query: UPDATE tx_mocfilemanager_files SET downloads=downloads + 1 WHERE file='".addslashes($reldir."/".$filename)."' AND mount=".intval($this->mount->uid); $this->dbObj->sql_query("UPDATE tx_mocfilemanager_files SET downloads=downloads + 1 WHERE file='".addslashes($this->div->removeFirstSlash($reldir."/".$filename))."' AND mount=".intval($this->mount->uid)); // $file=$this->removeFirstSlash($file); //Clean all output buffers. while (@ob_end_clean()); //Set time limit to value given in conf if($this->conf["timeLimit"]>0) { set_time_limit($this->conf["timelimit"]); } if($this->conf["killChild"]) { apache_child_terminate(); } // including mimetypes.php here means it is only included when required, thereby saving parsing time for all other requests include("mimetypes.php"); // extract the file extesion and attempt to determine the Mime type from the file's extension $fileinfo = t3lib_div::split_fileref($filename); $mimetype = $mimetypes[$fileinfo["fileext"]]; if ($mimetype == "") { $mimetype = "application/octet-stream"; } $name = "$dir/$filename"; // return "Name: $dir/$filename"; $fp = fopen($name, 'rb'); // send the right headers header("Cache-control: must-revalidate, post-check=0, pre-check=0"); header("Content-Transfer-Encoding: binary"); header("Content-Type: $mimetype"); header("Content-Length: ".filesize($name)); header("Content-Disposition: attachment; filename=$filename"); header("Cache-control: private"); while (!feof($fp)) { $buffer = fgets($fp, 4096); echo $buffer; } fclose($fp); if($this->conf["timeLimit"]) set_time_limit(0); exit; } /* * * TASK = delete * * * */ if($task == "delete") { if(t3lib_div::GPvar("confirmed") == "yes") { if($this->filehandler->func_delete(array("data"=>"$dir/$filename"))) { $this->remove_file_entry("$reldir/$filename"); $relative_url = $this->pi_getPageLink($GLOBALS['TSFE']->id,'',array("mountpoint"=>$this->mountID, "dir"=>$reldir)); header("Location: http://" . $_SERVER['HTTP_HOST'] . $this->div->clean_dir(dirname($_SERVER['PHP_SELF'])) . "/" . $relative_url); } else { $content .= "".$this->pi_getLL("error")."
"; //$content .= "Du ønskede at slette filen $dir/$filename"; } } else { // This could be a javascript confirmation. $content .= "".$this->pi_getLL("areyousure")."
".$this->mount->getName().":$reldir/$filename
".$this->pi_getLL("noregret")."
"; $content .= "\n"; //return $content; return $this->pi_wrapInBaseClass($content); } } /* * * TASK = RENAME * */ if($task == "rename") { $newname = t3lib_div::GPvar("newname"); // $mountpoint = t3lib_div::GPvar("mountpoint"); $oldname = t3lib_div::GPvar("oldname"); if($newname) { if($this->hasAccess($this->mount,$dir,"upload")) { if($newname != $oldname) { $test = $this->filehandler->func_rename(array("target"=>"$dir/$oldname","data"=>$newname)); if(!$test) { return "Error renaming"; } $fileinfo = t3lib_div::split_fileref($test); $newname = $fileinfo["file"]; } $comment = t3lib_div::GPvar("comment"); $this->rename_file_entry("$reldir/$oldname","$reldir/$newname",$this->mount->uid,$comment); $relative_url = $this->pi_getPageLink($GLOBALS['TSFE']->id,'',array("mountpoint"=>$this->mountID, "dir"=>$reldir)); header("Location: http://" . $_SERVER['HTTP_HOST'] . $this->div->clean_dir(dirname($_SERVER['PHP_SELF'])) . "/" . $relative_url); exit(); } else { return $this->pi_wrapInBaseClass("".$this->pi_getLL("noaccessrename")."
"); } } else { // Render the rename form $content .= "".$this->pi_getLL("rename")." $oldname ".$this->pi_getLL("to")."
"; $content .= '"; //return $content; return $this->pi_wrapInBaseClass($content); } } /* * * TASK = MKDIR * */ // if($task == "mkdir") { if(!empty($mkdir)) { $comment = t3lib_div::GPvar("comment_dir"); if($this->hasAccess($this->mount,$dir,"mkdir")) { $newdir = t3lib_div::GPvar("newdirname"); if(strpos($newdir,"/")) return $this->pi_wrapInBaseClass("".$this->pi_getLL("noslashindirs")."
"); if(preg_match("/[åæøé]/i",$newdir)) { return $this->pi_wrapInBaseClass("".$this->pi_getLL("nospecialchars")."
"); } if(count(explode("/",$reldir)) > $this->maxDepth-1) return $this->pi_wrapInBaseClass("".$this->pi_getLL("todeep")." ".$this->maxDepth."
"); if(file_exists("$dir/$newdir")) { return $this->pi_wrapInBaseClass("Mappen $newdir eksisterer allerede
"); } if($this->filehandler->func_newfolder(array("data"=>$newdir,target=>"$dir/"))) { if($this->insert_file_entry("DIR",$reldir,$newdir,0,$comment)) { $relative_url = $this->pi_getPageLink($GLOBALS['TSFE']->id,'',array("mountpoint"=>$this->mountID, "dir"=>$reldir)); header("Location: http://" . $_SERVER['HTTP_HOST'] . $this->div->clean_dir(dirname($_SERVER['PHP_SELF'])) . "/" . $relative_url); exit(); // $content .= "".$this->pi_getLL("directory")."
//".$this->mountname."/$insertdir$newdir
".$this->pi_getLL("createdpress")." ".$this->mountname."/$reldir ".$this->pi_getLL("toupdate")."
Could not create dir $dir/$newdir, database error.
$query
"; } } else { $content .= ''.$this->pi_getLL("error").'
'; } } else { $content .= ''.$this->pi_getLL("noaccess").'
'; } } /* * * TASK = UPLOAD * */ if(!empty($uploadfile)) { if(!$this->hasAccess($this->mount,$reldir,"upload")) { return ''.$this->pi_getLL('no_upload_access').'
'; } if(1==0) { $content .= ''.$this->pi_getLL('fileextensionerror').': '.$this->conf["allowedExts"].':'.end($str).'
'; } else { $newname = basename($this->filehandler->func_upload(array("data"=>0,target=>"$dir/"))); $size= filesize("$dir/$newname"); $comment = t3lib_div::GPvar('comment_file'); if($newname) { $this->insert_file_entry("FILE",$reldir,$newname,$size,$comment); $relative_url = $this->pi_getPageLink($GLOBALS['TSFE']->id,'',array("mountpoint"=>$this->mountID, "dir"=>$reldir)); header("Location: http://" . $_SERVER['HTTP_HOST'] . $this->div->clean_dir(dirname($_SERVER['PHP_SELF'])) . "/" . $relative_url); } else { $content .= "".$this->pi_getLL("error")."
"; } } } /**************************************************** * Render all the mountpoints on the page ************************************************** */ foreach($this->mountlist as $mp) { if($mp->uid == $this->mount->uid) { $content .= $this->renderSingleMount($mp,$reldir); } else { $content .= $this->renderSingleMount($mp,""); } } $content .= $this->renderUploadAndCreate($this->mountlist,$reldir); } /* * * ####################### UPLOAD_ONLY ####################### * */ elseif($this->mode == "UPLOAD_ONLY") { // // upload the file // if(!empty($uploadfile)) { $newname = basename($this->filehandler->func_upload(array("data"=>0,target=>"$dir/"))); $comment = t3lib_div::GPvar('comment_file'); if($newname) { $this->insert_file_entry("FILE",$reldir,$newname,$comment); $content .= "".$this->pi_getLL("uploadsuccessful")."
"; } else { $content .= "".$this->pi_getLL("error")."
"; } } // // display the upload form // if($this->mount && $this->hasAccess($this->mount,$dir,"upload")) { $content .= "\n"; $typocont["additionalParams"]="&$dir=$reldir&mountpoint=".$this->mount; $content .= " '; $content .= " |
'.$this->pi_getLL('filename').': '.$entry.' '.$this->pi_getLL('size').': '.($row["size"] != 0 ? t3lib_div::formatSize($row['size']) : $this->pi_getLL('unknown')).' '.$this->pi_getLL('uploaded_date').': '.($row['uploaded'] ? strftime($this->conf['datetimeFormat'],$row['uploaded']) : $this->pi_getLL('unknown')).' '.$this->pi_getLL('uploaded_by').': '.($row['name'] ? $row['name'] : $this->pi_getLL('unknown')).' '.$this->pi_getLL('number_of_downloads').': '.$row['downloads'].' '.($this->conf['useDescriptions'] ? ' '.$row["comment"] : '').' |
Error in application
"); } $depth--; return $content; } function getPrefix($depth,$islast) { $content =""; for($i=0; $i<$depth; $i++) { $image = $islast[$i] ? 'blank.gif':'line.gif'; $content .= ''.$this->pi_getLL("noaccess").'
'); } if (is_dir("$dir")) { $files = t3lib_div::getFilesInDir("$dir","",0,"mtime"); $numfiles = count($files); if($this->canUseLayers) { $content .= ' '; } $content .= "';
// if we are in a subdirectory, then display the "folder_up" icon with a link to the parent directory
// calculate the Parent Directory
$parentdir = "";
if ($reldir && $this->conf["showParentDir"])
{
// find the last slash in the relative dir
$pos = strrpos($reldir, "/");
if ($pos === false)
{
// not found - the "newdir" is at the root of the mount
$parentdir = "";
}
else
{
$parentdir = substr($reldir, 0, $pos);
$parentdir = str_replace(" ", "%20", $parentdir);
}
}
if ($reldir && $this->conf["showParentDir"] && !$this->conf["parentDirStyle"])
{
// parentDirStyle is false - substitute the regular directory icon with the Up icon
$typoconf["additionalParams"]="&dir=$parentdir&mountpoint=".$mount->uid;
$content .= $this->cObj->typolink("![]() ![]() | ||
";
$numDirs=count($dirs);
$img = (($numfiles == 0) && ($numDirs==0)) ? "joinbottom-large.gif" : "joinlarge.gif";
$content .= '![]() | "; $content .= " | |
";
$img = (($numfiles == 0) && ($currentDir==$numDirs)) ? "joinbottom-large.gif" : "joinlarge.gif";
$content .= '![]() | ";
if($this->canUseLayers) {
$content .= '![]() ![]() ![]() ![]() | |
";
$content .="";
$count++;
$str = explode(".",$file); // Break it in pieces.
$extfile = $icons[end($str)];
if(empty($extfile))
$extfile="default.gif";
// **** The Jan-Erik Way
$typoconf["additionalParams"]="&filename=$file&dir=$reldir&task=download&mountpoint=".$mount->uid;
$image = ($count == $numfiles) ? 'joinbottom-large.gif':'joinlarge.gif';
$content .= ' | ";
if($this->canUseLayers) {
$content .= ' | ![]() ![]() ![]() ![]() "; // **** The TYPO# way. Take your pick... //$cf["path"]="uploads/pics/"; //$cf["icon"] = 1; //$cf["jumpurl"] = 1; //$cf["jumpurl."]["secure"]=1; //$cf["jumpurl."]["secure."]["mimetypes"]= "pdf=application/pdf,doc=application/msword,jpg=image/jpeg"; //$content .= $this->cObj->filelink("banner_dame.jpg",$cf)." "; $index++; } } $content .=" |
".$mount->getDir()."/$reldir ".$this->pi_getLL("doesnotexist")."
"; } return $content; } function initFilehandler() { $this->filehandler = new t3lib_extFileFunctions(); $f_ext = array("ftpspace"=>array("allow"=>$this->conf["allowedExts"])); $this->filehandler->init($this->filehandler_mps,$f_ext); $this->filehandler->init_actionPerms(31); } /** * Renders the upload and create (No TemplaVoila) */ function renderUploadAndCreate($mountlist,$reldir) { foreach($mountlist as $mount) { $dir=$this->div->clean_dir($mount->getDir()."/".$reldir); if($this->hasAccess($mount,$dir,"upload")) { $targetlist[] = ''; } } if(count($targetlist) > 0) { $content .= ""; } return $content; } /** * Init a single Mountpoint */ function initSingleMountPoint($mountpoint) { /* * Perform common initialization required by both VIEW & UPLOAD_ONLY */ if(!$mountpoint->uid) { //return $this->pi_wrapInBaseClass("Could not find mountpoint with UID: ".$mountpoint->uid."
"); return -1; } // ************ Init the filehandler (TYPO3 extFilefunctions) ********* //Clean up filepath $this->filehandler_mps[$mountpoint->uid]["path"] = $this->div->clean_dir($this->documentRoot."/".$mountpoint->data["path"])."/"; $this->filehandler_mps[$mountpoitn->uid]["name"] = $mountpoint->data["name"]; } /** * */ function transferFlexToData() { $this->cObj->data['field_mode'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'],'field_mode'); $this->cObj->data['field_selectfrom'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'],'field_selectfrom'); $this->cObj->data['field_from'] = $this->pi_getFFvalue($this->cObj->data['pi_flexform'],'field_from'); } } if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/moc_filemanager/pi1/class.tx_mocfilemanager_pi1.php"]) { include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/moc_filemanager/pi1/class.tx_mocfilemanager_pi1.php"]); } ?>