本文整理汇总了PHP中Upload::config方法的典型用法代码示例。如果您正苦于以下问题:PHP Upload::config方法的具体用法?PHP Upload::config怎么用?PHP Upload::config使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Upload
的用法示例。
在下文中一共展示了Upload::config方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public function init()
{
//setting the uploads directory to make sure images uploaded through the content
//editor are saved the right place
$curr = LeftAndMain::curr();
if ($curr) {
//Debug::dump(get_class($curr));
//Debug::dump(ClassInfo::ancestry($curr));
$currClass = null;
foreach (ClassInfo::ancestry($curr) as $class) {
foreach (self::$supported_classes as $supported_class) {
if ($class == $supported_class) {
$currClass = $class;
}
}
}
//Debug::dump($currClass);
//switch (get_class($curr)) {
switch ($currClass) {
//Page administration
case 'CMSPagesController':
case 'CMSPageEditController':
$page = $curr->currentPage();
if ($page && $page->hasExtension('AssetsFolderExtension')) {
Upload::config()->uploads_folder = $page->getAssetsFolderDirName();
}
//Debug::dump($page->Title);
break;
case 'ModelAdmin':
//For ModelAdmin we're falling back to cookies that we believe to have
//been set when setting the cms fields, see AssetFolderExtension::updateCMSFields()
//...as it seems to be almost impossible to figure out the current object elsewise
//see below for tries
//pull requests to fix this welcome!!!
//Debug::dump($this->owner->getURLParams());
//Debug::dump($this->owner->request->param('ModelClass'));
//Debug::dump($this->owner->request->remaining());
//Debug::dump($this->owner->request->getVars());
//Debug::dump($this->owner->request->params());
//Debug::dump($curr->currentPageID());
Upload::config()->uploads_folder = Cookie::get('cms-uploaddirrules-uploads-folder');
break;
//Settings
//Settings
case 'CMSSettingsController':
if (Object::has_extension('SiteConfig', 'AssetsFolderExtension')) {
$sc = SiteConfig::current_site_config();
Upload::config()->uploads_folder = $sc->getAssetsFolderDirName();
}
default:
}
}
}
示例2: testConfigOverwriteWarningCannotRelaceFiles
/**
* Test that UploadField:overwriteWarning cannot overwrite Upload:replaceFile
*/
public function testConfigOverwriteWarningCannotRelaceFiles()
{
Upload::config()->replaceFile = false;
UploadField::config()->defaultConfig = array_merge(UploadField::config()->defaultConfig, array('overwriteWarning' => true));
$tmpFileName = 'testUploadBasic.txt';
$response = $this->mockFileUpload('NoRelationField', $tmpFileName);
$this->assertFalse($response->isError());
$responseData = Convert::json2array($response->getBody());
$uploadedFile = DataObject::get_by_id('File', (int) $responseData[0]['id']);
$this->assertTrue(is_object($uploadedFile), 'The file object is created');
$this->assertFileExists(AssetStoreTest_SpyStore::getLocalPath($uploadedFile));
$tmpFileName = 'testUploadBasic.txt';
$response = $this->mockFileUpload('NoRelationField', $tmpFileName);
$this->assertFalse($response->isError());
$responseData = Convert::json2array($response->getBody());
$uploadedFile2 = DataObject::get_by_id('File', (int) $responseData[0]['id']);
$this->assertTrue(is_object($uploadedFile2), 'The file object is created');
$this->assertFileExists(AssetStoreTest_SpyStore::getLocalPath($uploadedFile2));
$this->assertTrue($uploadedFile->Filename !== $uploadedFile2->Filename, 'Filename is not the same');
$this->assertTrue($uploadedFile->ID !== $uploadedFile2->ID, 'File database record is not the same');
}
示例3: updateAssetsFolderCMSField
/**
* @param FieldList $fields
* @return FieldList
*/
public static function updateAssetsFolderCMSField($obj, FieldList $fields)
{
//prepopulating object with asset folder - if allowed
if ($obj->AssetsFolderID == 0) {
$url = $obj->assetsFolderUrlToBeWritten();
if ($url) {
//this creates the directory, and attaches it to the page,
//as well as saving the object one more time - with the attached folder
$obj->findOrMakeAssetsFolder($url, false);
}
}
$dirName = $obj->getAssetsFolderDirName();
$dirExists = false;
if ($dirName) {
$dirExists = true;
//Setting and showing the uploads folder
//This doesn't work for iframe uploads, there we need
//the AssetsFolderAdmin extension to LeftAndMain
Upload::config()->uploads_folder = $dirName;
//Cookie fallback for moments where it's impossible to figure
//out the uploads folder through the leftandmain controller.
//e.g. ModelAdmin - {@see AssetsFolderAdmin}
if (Cookie::get('cms-uploaddirrules-uploads-folder') != $dirName) {
Cookie::set('cms-uploaddirrules-uploads-folder', $dirName);
}
}
//The Upload Directory field
//TODO make it configurable if field should be shown
//TODO make field placement configurable
$field = AssetsFolderCmsFieldsHelper::assetsFolderField($obj, $dirExists);
$fields->removeByName('AssetsFolder');
//Adding fields - to tab or just pushing
$isPage = false;
$ancestry = $obj->getClassAncestry();
foreach ($ancestry as $c) {
if ($c == 'SiteTree') {
$isPage = true;
}
}
if ($dirExists) {
$field = ToggleCompositeField::create('UploadDirRulesNotes', 'Upload Rules (' . $dirName . ')', [$field]);
//configurable tab
$tab = $obj->config()->uploaddirrules_fieldtab;
if (isset($tab)) {
$fields->addFieldToTab($tab, $field);
} else {
if ($isPage) {
//$fields->addFieldToTab('Root.Main', $htmlField, 'Content');
$fields->addFieldToTab('Root.Main', $field);
} else {
//TODO this should be configurable
switch ($obj->ClassName) {
case 'Subsite':
$fields->addFieldToTab('Root.Configuration', $field);
break;
case 'SiteConfig':
case 'GenericContentBlock':
$fields->addFieldToTab('Root.Main', $field);
break;
default:
if ($fields->fieldByName('Root.Main')) {
$fields->addFieldToTab('Root.Main', $field);
} else {
$fields->push($field);
}
}
}
}
} else {
$noteTab = new Tab('Note', 'Note', $field);
$fields->insertBefore($noteTab, 'Main');
}
return $fields;
}
示例4: __construct
/**
* Constructor
*
* @access public
*/
public function __construct()
{
self::$config = config_load('upload');
$this->error = new Error();
}
示例5: getAssetsFolderField
/**
* Upload Dir Rules message and fields to display in the CMS
*
* @param bool $dirExists
* @return LiteralField|null
*/
protected function getAssetsFolderField()
{
$field = null;
$msg = null;
$dirName = $this->owner->getAssetsFolderDirName();
$dirExists = false;
if ($dirName) {
$dirExists = true;
}
if ($dirExists) {
//Message
$defaultMsg = '<em>Files uploaded via the content area will be uploaded to</em>' . '<br /> <strong>' . Upload::config()->uploads_folder . '</strong>';
if ($this->owner instanceof UploadDirRulesInterface) {
$msg = $this->owner->getMessageUploadDirectory();
}
if (!$msg) {
$msg = $defaultMsg;
}
//TODO these could also be global settings
$manageAble = true;
$editable = true;
//As this is happening from the subsites administration, when editing a subsite
//you'd probably be on another site, and hence can't access the site's files anyway
if ($this->owner->ClassName == 'Subsite') {
$manageAble = false;
$editable = false;
}
if ($editable) {
//Asset folder is editable
$field1 = new TreeDropdownField("AssetsFolderID", "Change Directory:", "Folder");
$field1->setRightTitle('Directory changes take place after saving.');
//Dropdown field style adjustments
//TODO move this to an external stylesheet as these styles don't kick in on AJAX loads
Requirements::customCSS("\n\t\t\t\t\t#TreeDropdownField_Form_EditForm_AssetsFolderID {\n\t\t\t\t\t\tmin-width: 260px;\n\t\t\t\t\t}\n\t\t\t\t\t.UploadDirectoryFields .fieldgroup label {\n\t\t\t\t\t\tpadding: 0 0 4px;\n\t\t\t\t\t}\n\t\t\t\t");
$dir = $this->owner->AssetsFolder();
$filescount = File::get()->filter(array("ParentID" => $dir->ID))->count();
$manageButton = null;
if ($manageAble) {
$manageButton = "<a href='/admin/assets/show/" . $dir->ID . "' class='ss-ui-button ss-ui-button-small ui-button'>\n\t\t\t\t\t\tManage Files (" . $filescount . ")</a>";
}
$field2 = new LiteralField("UploadDirRulesNote", "<div style='margin-bottom:10px;margin-right:16px;'>{$msg}</div>" . $manageButton);
$field = new FieldGroup(array($field2, $field1));
$field->setTitle('Upload Directory');
$field->addExtraClass('UploadDirectoryFields');
$field->setName('UploadDirectoryFields');
} else {
//Asset folder is not editable
$field = new LiteralField('UploadDirRulesNote', '
<div class="field text" id="UploadDirRulesNote">
<label class="left">Upload Directory</label>
<div class="middleColumn">
<p style="margin-bottom: 0; padding-top: 0px;">
' . $msg . '
<br />
<em>If you need to edit or change this folder, please contact your administrator.</em>
</p>
</div>
</div>
');
}
} else {
//Message
$defaultMsg = 'Please <strong>choose a name and save</strong> for adding content.';
if ($this->owner instanceof UploadDirRulesInterface) {
$msg = $this->owner->getMessageSaveFirst();
}
if (!$msg) {
$msg = $defaultMsg;
}
$field = new LiteralField('UploadDirRulesNote', '
<p class="message notice" >' . $msg . '</p>
');
}
return $field;
}