function linkFileProcess($uid, $step, $url)
 {
     DOCMAN_token::check() or die('Invalid Token');
     global $_DMUSER, $_DOCMAN;
     if ($url == '') {
         return array('_error' => 1, '_errmsg' => _DML_FILENAME_REQUIRED);
     }
     $path = $_DOCMAN->getCfg('dmpath');
     //get file validation settings
     if ($_DMUSER->isSpecial) {
         $validate = _DM_VALIDATE_ADMIN;
     } else {
         if ($_DOCMAN->getCfg('user_all', false)) {
             $validate = _DM_VALIDATE_USER_ALL;
         } else {
             $validate = _DM_VALIDATE_USER;
         }
     }
     //upload the file
     $upload = new DOCMAN_FileUpload();
     $file = $upload->uploadLINK($url, $validate);
     if (!$file) {
         $msg = _DML_ERROR_LINKING . " - " . $upload->_err;
         return array('_error' => 1, '_errmsg' => $msg);
     }
     $msg = _DML_LINKED;
     return array('_error' => 0, '_errmsg' => $msg);
 }
Exemplo n.º 2
0
function uploadWizard($step = 1, $method = 'http', $old_filename)
{
    global $_DOCMAN;
    $mainframe = JFactory::getApplication();
    $database = JFactory::getDBO();
    switch ($step) {
        case 1:
            $lists['methods'] = dmHTML::uploadSelectList($method);
            HTML_DMFiles::uploadWizard($lists);
            break;
        case 2:
            switch ($method) {
                case 'http':
                    HTML_DMFiles::uploadWizard_http($old_filename);
                    break;
                case 'ftp':
                    HTML_DMFiles::uploadWizard_ftp();
                    break;
                case 'link':
                    $mainframe->redirect("index.php?option=com_docman&section=documents&task=new&makelink=1", _DML_CREATEALINK);
                    // HTML_DMFiles::uploadWizard_link();
                    break;
                case 'transfer':
                    HTML_DMFiles::uploadWizard_transfer();
                    break;
                default:
                    $mainframe->redirect("index.php?option=com_docman&section=files", _DML_SELECTMETHODFIRST);
            }
            break;
        case 3:
            DOCMAN_token::check() or die('Invalid Token');
            switch ($method) {
                case 'http':
                    $path = $_DOCMAN->getCfg('dmpath');
                    $upload = new DOCMAN_FileUpload();
                    $file_upload = JRequest::getVar('upload', '', 'files', 'array');
                    $result =& $upload->uploadHTTP($file_upload, $path, _DM_VALIDATE_ADMIN);
                    if (!$result) {
                        $mainframe->redirect("index.php?option=com_docman&section=files", _DML_ERROR_UPLOADING . " - " . $upload->_err);
                    } else {
                        $batch = JRequest::getCmd('batch', null);
                        if ($batch && $old_filename != null) {
                            require_once JPATH_ADMINISTRATOR . DS . 'includes' . DS . 'pcl' . DS . 'pclzip.lib.php';
                            if (!extension_loaded('zlib')) {
                                $mainframe->redirect("index.php?option=com_docman&section=files", _DML_ZLIB_ERROR);
                            }
                            $target_directory = $_DOCMAN->getCfg('dmpath');
                            $zip = new PclZip($target_directory . DS . $result->name);
                            $file_to_unzip = preg_replace('/(.+)\\..*$/', '$1', $target_directory . DS . $result->name);
                            if (!$zip->extract($target_directory)) {
                                $mainframe->redirect("index.php?option=com_docman&section=files", _DML_UNZIP_ERROR);
                            }
                            @unlink($target_directory . DS . $result->name);
                        }
                        if ($old_filename && $old_filename != $file_upload['name']) {
                            $file = $_DOCMAN->getCfg('dmpath') . DS . $old_filename;
                            @unlink($file);
                            $database->setQuery("UPDATE #__docman SET dmfilename='" . $database->getEscaped($result->name) . "' WHERE dmfilename='" . $database->getEscaped($old_filename) . "'");
                            if (!$database->query()) {
                                echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1);</script>\n";
                                exit;
                            }
                        }
                        //HTML_DMFiles::uploadWizard_sucess($result, $batch, $old_filename);
                        $mainframe->redirect("index.php?option=com_docman&section=files&task=upload&step=4" . "&result=" . urlencode($result->name) . "&batch=" . (0 + $batch) . "&old_filename=" . $old_filename, _DML_SUCCESS . ' &quot;' . $result->name . '&quot; - ' . _DML_FILEUPLOADED);
                    }
                    break;
                case 'ftp':
                    break;
                case 'link':
                    break;
                case 'transfer':
                    $url = stripslashes(JRequest::getString('url', null, 'post'));
                    $name = stripslashes(JRequest::getString('localfile', null, 'post'));
                    $path = $_DOCMAN->getCfg('dmpath') . DS;
                    $upload = new DOCMAN_FileUpload();
                    $result = $upload->uploadURL($url, $path, _DM_VALIDATE_ADMIN, $name);
                    if ($result) {
                        // HTML_DMFiles::uploadWizard_sucess($result, 0, 1);
                        $mainframe->redirect("index.php?option=com_docman&section=files&task=upload&step=4" . "&result=" . urlencode($result->name) . "&batch=0&old_filename=1", _DML_SUCCESS . ' &quot;' . $result->name . '&quot; - ' . _DML_FILEUPLOADED);
                    } else {
                        $mainframe->redirect("index.php?option=com_docman&section=files", $upload->_err);
                    }
                    break;
            }
            break;
        case '4':
            /* New step that gives us a header completion message rather than
            		   "in body" completion. For uniformity
            		 */
            $file = new StdClass();
            $file->name = urlencode(stripslashes(JRequest::getString('result', 'INTERNAL ERROR')));
            $batch = JRequest::getInt('batch', 0);
            $old_filename = JRequest::getString('old_filename', null);
            HTML_DMFiles::uploadWizard_sucess($file, $batch, $old_filename, 0);
            break;
    }
    //End switch($step)
}
 function transferFileProcess($uid, $step, $url, &$file)
 {
     DOCMAN_token::check() or die('Invalid Token');
     global $_DMUSER, $_DOCMAN;
     if ($file == '') {
         return array('_error' => 1, '_errmsg' => _DML_FILENAME_REQUIRED);
     }
     /* ------------------------------ *
      *   MAMBOT - Setup All Mambots   *
      * ------------------------------ */
     $logbot = new DOCMAN_mambot('onLog');
     $prebot = new DOCMAN_mambot('onBeforeUpload');
     $postbot = new DOCMAN_mambot('onAfterUpload');
     $logbot->setParm('filename', $file);
     $logbot->setParm('user', $_DMUSER);
     $logbot->copyParm('process', 'upload');
     $prebot->setParmArray($logbot->getParm());
     // Copy the parms over
     $postbot->setParmArray($logbot->getParm());
     /* ------------------------------ *
      *   Pre-upload                    *
      * ------------------------------ */
     $prebot->trigger();
     if ($prebot->getError()) {
         $logbot->setParm('msg', $prebot->getErrorMsg());
         $logbot->copyParm('status', 'LOG_ERROR');
         $logbot->trigger();
         return array('_error' => 1, '_errmsg' => $prebot->getErrorMsg());
     }
     /* ------------------------------ *
      *   Upload                        *
      * ------------------------------ */
     $path = $_DOCMAN->getCfg('dmpath') . DS;
     //get file validation settings
     if ($_DMUSER->isSpecial) {
         $validate = _DM_VALIDATE_ADMIN;
     } else {
         if ($_DOCMAN->getCfg('user_all', false)) {
             $validate = _DM_VALIDATE_USER_ALL;
         } else {
             $validate = _DM_VALIDATE_USER;
         }
     }
     //upload the file
     $upload = new DOCMAN_FileUpload();
     $file = $upload->uploadURL($url, $path, $validate, $file);
     /* -------------------------------- *
      *    Post-upload                   *
      * -------------------------------- */
     if (!$file) {
         $msg = _DML_ERROR_UPLOADING . " - " . $upload->_err;
         $logbot->setParm('msg', $msg);
         $logbot->setParm('file', $url);
         $logbot->copyParm('status', 'LOG_ERROR');
         $logbot->trigger();
         return array('_error' => 1, '_errmsg' => $msg);
     }
     $msg = "&quot;" . $file->name . "&quot; " . _DML_UPLOADED;
     $logbot->copyParm(array('msg' => $msg, 'status' => 'LOG_OK'));
     $logbot->trigger();
     $postbot->setParm('file', $file);
     $postbot->trigger();
     if ($postbot->getError()) {
         $logbot->setParm('msg', $postbot->getErrorMsg());
         $logbot->copyParm('status', 'LOG_ERROR');
         $logbot->trigger();
         return array('_error' => 1, '_errmsg' => $postbot->getErrorMsg());
     }
     return array('_error' => 0, '_errmsg' => $msg);
 }
Exemplo n.º 4
0
 function uploadPackageURL($url)
 {
     $upload = new DOCMAN_FileUpload();
     $file = $upload->uploadURL($url, $this->uploaddir());
     if (!$file) {
         $this->setError(1, $upload->_err);
         return false;
     }
     $this->installArchive($file->name);
     return $file;
 }