예제 #1
0
 public function addFile($file)
 {
     Loader::library("file/importer");
     Loader::library("mootools/plugin_parser", FRONTEND_DEVELOPER_PACKAGE_HANDLE);
     $fi = new FileImporter();
     $fv = $fi->import($file, basename($file), $this->getExistFile(basename($file)));
     if (!$fv instanceof FileVersion) {
         $message = FileImporter::getErrorMessage($result);
         return $message;
     }
     $parser = new MootoolsPluginParser();
     $meta = $parser->parse($file);
     $requireValues = array();
     if (is_array($meta["requires"])) {
         $requires = $meta["requires"];
         foreach ($requires as $module) {
             $option = SelectAttributeTypeOption::getByValue($module);
             if (empty($option)) {
                 $ak = FileAttributeKey::getByHandle(MOOTOOLS_PLUGIN_DEPENDENCES);
                 $type = SelectAttributeTypeOption::add($ak, $module, true);
                 $value = $type->getSelectAttributeOptionValue();
             } else {
                 $value = $option->getSelectAttributeOptionValue();
             }
             $requireValues[$value] = $value;
         }
     }
     $namespaces = explode('.', $meta['name']);
     $packageName = array_shift($namespaces);
     $moduleName = str_replace('.js', '', basename($file));
     $componentName = $packageName . '/' . $moduleName;
     $authors = is_array($meta["authors"]) ? join(",", $meta["authors"]) : $meta["authors"];
     $license = is_array($meta["license"]) ? join(",", $meta["license"]) : $meta["license"];
     $fv->setAttribute(MOOTOOLS_PLUGIN, true);
     $fv->setAttribute(MOOTOOLS_COMPONENT_NAME, $componentName);
     $fv->setAttribute(MOOTOOLS_PLUGIN_LICENSE, $license);
     $fv->setAttribute(MOOTOOLS_PLUGIN_AUTHORS, $authors);
     $fv->setAttribute(MOOTOOLS_PLUGIN_DEPENDENCES, $requireValues);
     $fv->setAttribute(MOOTOOLS_PLUGIN_DISPLAY_ORDER, 0);
     $fv->updateDescription($meta["description"]);
     $fv->updateTags("mootools\nplugin");
     $this->_fileset->addFileToSet($fv);
     return $fv;
 }
     // if we can't get the filename from the file itself OR from the mime-type I'm not sure there's much else we can do
     //}
     if (strlen($fname)) {
         // write the downloaded file to a temporary location on disk
         $handle = fopen($fpath . '/' . $fname, "w");
         fwrite($handle, $response->getBody());
         fclose($handle);
         // import the file into concrete
         if ($fp->canAddFileType($cf->getExtension($fname))) {
             $fi = new FileImporter();
             $resp = $fi->import($fpath . '/' . $fname, $fname, $fr);
         } else {
             $resp = FileImporter::E_FILE_INVALID_EXTENSION;
         }
         if (!$resp instanceof FileVersion) {
             $errors[] .= $fname . ': ' . FileImporter::getErrorMessage($resp) . "\n";
         } else {
             $import_responses[] = $resp;
             if (!is_object($fr)) {
                 // we check $fr because we don't want to set it if we are replacing an existing file
                 $respf = $resp->getFile();
                 $respf->setOriginalPage($_POST['ocID']);
             }
         }
         // clean up the file
         unlink($fpath . '/' . $fname);
     } else {
         // could not figure out a file name
         $errors[] = t('Could not determine the name of the file at ') . $this_url;
     }
 } else {
예제 #3
0
파일: single.php 프로젝트: ceko/concrete5-1
        if (!$resp instanceof \Concrete\Core\File\Version) {
            $errorCode = $resp;
        } else {
            if (!is_object($fr)) {
                // we check $fr because we don't want to set it if we are replacing an existing file
                $respf = $resp->getFile();
                $respf->setOriginalPage($_POST['ocID']);
            } else {
                $respf = $fr;
            }
        }
    } else {
        $errorCode = $_FILES['Filedata']['error'];
    }
} else {
    if (isset($_FILES['Filedata'])) {
        // first, we check for validate upload token. If the posting of a file fails because of
        // post_max_size then this may not even be set, leading to misleading errors
        $error->add($valt->getErrorMessage());
    } else {
        $errorCode = FileImporter::E_PHP_FILE_ERROR_DEFAULT;
    }
}
if ($errorCode > -1) {
    $error->add(FileImporter::getErrorMessage($errorCode));
}
$r->setError($error);
if (is_object($respf)) {
    $r->setFile($respf);
}
$r->outputJSON();
예제 #4
0
			$respf->setOriginalPage($_POST['ocID']);
		}
	} else {
		$errorCode = $_FILES['Filedata']['error'];
	}
} else if (isset($_FILES['Filedata'])) {
	// first, we check for validate upload token. If the posting of a file fails because of
	// post_max_size then this may not even be set, leading to misleading errors

	$error = $valt->getErrorMessage();
} else {
	$errorCode = FileImporter::E_PHP_FILE_ERROR_DEFAULT;
}

if ($errorCode > -1 && $error == '') {
	$error = FileImporter::getErrorMessage($errorCode);
}
?>
<html>
<head>
<script language="javascript">
	<?php  if(strlen($error)) { ?>
		window.parent.ccmAlert.notice("<?php echo t('Upload Error')?>", "<?php echo str_replace("\n", '', nl2br($error))?>");
		window.parent.ccm_alResetSingle();
	<?php  } else { ?>
		highlight = new Array();
		highlight.push(<?php echo $resp->getFileID()?>);
		
		<?php  if (is_object($fr)) { ?>
			window.parent.jQuery.fn.dialog.closeTop();
		<?php  } ?>
 function importFile($fileUrl)
 {
     $u = new User();
     $cf = Loader::helper('file');
     $fp = FilePermissions::getGlobal();
     if (!$fp->canAddFiles()) {
         die(t("Unable to add files."));
     }
     //$valt = Loader::helper('validation/token');
     Loader::library("file/importer");
     Loader::library('3rdparty/Zend/Http/Client');
     Loader::library('3rdparty/Zend/Uri/Http');
     $file = Loader::helper('file');
     Loader::helper('mime');
     $error = array();
     // load all the incoming fields into an array
     $this_url = $fileUrl;
     // validate URL
     if (Zend_Uri_Http::check($this_url)) {
         // URL appears to be good... add it
         $incoming_urls[] = $this_url;
     } else {
         $errors[] = '"' . $this_url . '"' . t(' is not a valid URL.');
     }
     //}
     //if (!$valt->validate('import_remote')) {
     //	$errors[] = $valt->getErrorMessage();
     //}
     if (count($incoming_urls) < 1) {
         $errors[] = t('You must specify at least one valid URL.');
     }
     $import_responses = array();
     // if we haven't gotten any errors yet then try to process the form
     if (count($errors) < 1) {
         // itterate over each incoming URL adding if relevant
         foreach ($incoming_urls as $this_url) {
             // try to D/L the provided file
             // This all sets up the CURL actions to check the page
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, $this_url);
             curl_setopt($ch, CURLOPT_HEADER, true);
             curl_setopt($ch, CURLOPT_NOBODY, true);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
             curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
             //follow up to 10 redirections - avoids loops
             $data = curl_exec($ch);
             $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
             // Get the HTTP Code
             // Get final redirected URL, will be the same if URL is not redirected
             $new_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
             curl_close($ch);
             // Array of HTTP status codes. Trim down if you would like to.
             $codes = array(0 => 'Domain Not Found', 100 => 'Continue', 101 => 'Switching Protocols', 200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported');
             if (isset($codes[$http_code])) {
                 if ($codes[$http_code] == "OK") {
                     $client = new Zend_Http_Client($this_url);
                     $response = $client->request();
                     if ($response->isSuccessful()) {
                         $uri = Zend_Uri_Http::fromString($this_url);
                         $fname = '';
                         $fpath = $file->getTemporaryDirectory();
                         // figure out a filename based on filename, mimetype, ???
                         if (preg_match('/^.+?[\\/]([-\\w%]+\\.[-\\w%]+)$/', $uri->getPath(), $matches)) {
                             // got a filename (with extension)... use it
                             $fname = $matches[1];
                         } else {
                             if (!is_null($response->getHeader('Content-Type'))) {
                                 // use mimetype from http response
                                 $fextension = MimeHelper::mimeToExtension($response->getHeader('Content-Type'));
                                 if ($fextension === false) {
                                     $errors[] = t('Unknown mime-type: ') . $response->getHeader('Content-Type');
                                 } else {
                                     // make sure we're coming up with a unique filename
                                     do {
                                         // make up a filename based on the current date/time, a random int, and the extension from the mime-type
                                         $fname = date('d-m-Y_H:i_') . mt_rand(100, 999) . '.' . $fextension;
                                     } while (file_exists($fpath . '/' . $fname));
                                 }
                             }
                         }
                         //else {
                         // if we can't get the filename from the file itself OR from the mime-type I'm not sure there's much else we can do
                         //}
                         if (strlen($fname)) {
                             // write the downloaded file to a temporary location on disk
                             $handle = fopen($fpath . '/' . $fname, "w");
                             fwrite($handle, $response->getBody());
                             fclose($handle);
                             // import the file into concrete
                             if ($fp->canAddFileType($cf->getExtension($fname))) {
                                 $fi = new FileImporter();
                                 $resp = $fi->import($fpath . '/' . $fname, $fname, $fr);
                             } else {
                                 $resp = FileImporter::E_FILE_INVALID_EXTENSION;
                             }
                             if (!$resp instanceof FileVersion) {
                                 $errors[] .= $fname . ': ' . FileImporter::getErrorMessage($resp) . "\n";
                             } else {
                                 $import_responses[] = $resp;
                             }
                             // clean up the file
                             unlink($fpath . '/' . $fname);
                         } else {
                             // could not figure out a file name
                             $errors[] = t('Could not determine the name of the file at ') . $this_url;
                         }
                     } else {
                         // warn that we couldn't download the file
                         $errors[] = t('There was an error downloading ') . $this_url;
                     }
                 }
             } else {
                 $errors[] = t("Error connecting to file's server, file skipped");
             }
         }
     }
     //print_r($errors);
     if ($resp instanceof FileVersion) {
         return $resp;
     }
 }
예제 #6
0
}
$searchInstance = $_POST['searchInstance'];
$r = new FileEditResponse();
$files = array();
if ($valt->validate('import_incoming')) {
    if (!empty($_POST)) {
        $fi = new FileImporter();
        foreach ($_POST as $k => $name) {
            if (preg_match("#^send_file#", $k)) {
                if (!$fp->canAddFileType($cf->getExtension($name))) {
                    $resp = FileImporter::E_FILE_INVALID_EXTENSION;
                } else {
                    $resp = $fi->importIncomingFile($name);
                }
                if (!$resp instanceof \Concrete\Core\File\Version) {
                    $error->add($name . ': ' . FileImporter::getErrorMessage($resp));
                } else {
                    $files[] = $resp;
                    if ($_POST['removeFilesAfterPost'] == 1) {
                        $fsl = \Concrete\Core\File\StorageLocation\StorageLocation::getDefault()->getFileSystemObject();
                        $fsl->delete(REL_DIR_FILES_INCOMING . '/' . $name);
                    }
                    if (!is_object($fr)) {
                        // we check $fr because we don't want to set it if we are replacing an existing file
                        $respf = $resp->getFile();
                        $respf->setOriginalPage($_POST['ocID']);
                    } else {
                        $respf = $fr;
                    }
                }
            }
예제 #7
0
    }
    if (!$validExtension) {
        $error[] = t('Invalid File Extension');
    }
}
if (count($error) > 0) {
    // send in the errors
    $errorStr = implode(', ', $error);
    $file->error = $errorStr . '.';
    echo Loader::helper('json')->encode($file);
    exit;
}
// -- end intitial validation -- //
// begin file import
$fi = new FileImporter();
$fv = $fi->import($_FILES["file"]["tmp_name"], $_FILES["file"]["name"]);
if (!$fv instanceof \Concrete\Core\Entity\File\Version) {
    $file->error = $fi->getErrorMessage($fv);
    $file->timestamp = $_POST['timestamp'];
} else {
    $file_set = Config::get('conversations.attachments_pending_file_set');
    $fs = FileSet::getByName($file_set);
    if (!is_object($fs)) {
        $fs = FileSet::createAndGetSet($file_set, FileSet::TYPE_PUBLIC, USER_SUPER_ID);
    }
    $fs->addFileToSet($fv);
    $file->id = $fv->getFileID();
    $file->tag = $_POST['tag'];
    $file->timestamp = $_POST['timestamp'];
}
echo Loader::helper('json')->encode($file);
예제 #8
0
         } else {
             if (!$fp->canAddFileType($f->getExtension())) {
                 $error = t('You do not have permission to perform this action.');
             } else {
                 //Save the new copy with a suffix that differentiates it from the original (e.g. myphoto.jpg -> myphoto_400x200.jpg)
                 $suffix = "_{$_POST['crop_w']}x{$_POST['crop_h']}";
                 $extension_with_dot = '.' . $f->getExtension();
                 $new_file_name = basename($f->getPath(), $extension_with_dot) . $suffix . $extension_with_dot;
                 $overwrite_file_object = $is_overwrite ? $f : false;
                 $new_fv = $fi->import($f->getPath(), $new_file_name, $overwrite_file_object);
             }
         }
     }
 }
 if (empty($error) && !$new_fv instanceof FileVersion) {
     $error = FileImporter::getErrorMessage($new_fv);
 } else {
     //TODO: If no crop is selected and original image size is unchanged, set_ocid() fails when $fileVersion->getFile() is called [Fatal error: Call to a member function getFile() on a non-object]
     set_ocid($new_fv, $is_overwrite);
     $ich->edit($new_fv->getPath(), $_POST['crop_x'], $_POST['crop_y'], $_POST['crop_w'], $_POST['crop_h'], $_POST['target_w'], $_POST['target_h']);
     $new_fv->refreshAttributes();
     if ($is_overwrite) {
         $f->refreshCache();
     }
 }
 //Send json response
 $obj = new stdClass();
 $obj->message = $error;
 $obj->error = empty($error) ? 0 : 1;
 $obj->fID = empty($error) ? $new_fv->getFileID() : '';
 print $js->encode($obj);