本文整理汇总了PHP中File::config方法的典型用法代码示例。如果您正苦于以下问题:PHP File::config方法的具体用法?PHP File::config怎么用?PHP File::config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File
的用法示例。
在下文中一共展示了File::config方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCMSFields
public function getCMSFields()
{
$fields = new FieldList(new TabSet('Root'));
// Details
$thumbnailField = new UploadField('CoverImage', _t('ImageGalleryAlbum.COVERIMAGE', 'Cover Image'));
$thumbnailField->getValidator()->setAllowedExtensions(File::config()->app_categories['image']);
$fields->addFieldsToTab('Root.Main', array(new TextField('AlbumName', _t('ImageGalleryAlbum.ALBUMTITLE', 'Album Title'), null, 255), new TextareaField('Description', _t('ImageGalleryAlbum.DESCRIPTION', 'Description')), $thumbnailField));
// Image listing
$galleryConfig = GridFieldConfig_RecordEditor::create();
// Enable bulk image loading if necessary module is installed
// @see composer.json/suggests
if (class_exists('GridFieldBulkManager')) {
$galleryConfig->addComponent(new GridFieldBulkManager());
}
if (class_exists('GridFieldBulkImageUpload')) {
$galleryConfig->addComponents($imageConfig = new GridFieldBulkImageUpload('ImageID'));
$imageConfig->setConfig('fieldsClassBlacklist', array('ImageField', 'UploadField', 'FileField'));
if ($uploadFolder = $this->Folder()) {
// Set upload folder - Clean up 'assets' from target path
$path = preg_replace('/(^' . ASSETS_DIR . '\\/?)|(\\/$)/i', '', $uploadFolder->RelativePath);
$imageConfig->setConfig('folderName', $path);
}
}
// Enable image sorting if necessary module is installed
// @see composer.json/suggests
if (class_exists('GridFieldSortableRows')) {
$galleryConfig->addComponent(new GridFieldSortableRows('SortOrder'));
}
$galleryField = new GridField('GalleryItems', 'Gallery Items', $this->GalleryItems(), $galleryConfig);
$fields->addFieldToTab('Root.Images', $galleryField);
return $fields;
}
示例2: getCMSFields
public function getCMSFields()
{
$fields = new FieldList();
$fields->push(new TabSet('Root', new Tab('Main', _t('SiteTree.TABMAIN', 'Main'), new TextField('Title', _t('UniadsObject.db_Title', 'Title')))));
if ($this->ID) {
$previewLink = Director::absoluteBaseURL() . 'admin/' . UniadsAdmin::config()->url_segment . '/UniadsObject/preview/' . $this->ID;
$fields->addFieldToTab('Root.Main', new ReadonlyField('Impressions', _t('UniadsObject.db_Impressions', 'Impressions')), 'Title');
$fields->addFieldToTab('Root.Main', new ReadonlyField('Clicks', _t('UniadsObject.db_Clicks', 'Clicks')), 'Title');
$fields->addFieldsToTab('Root.Main', array(DropdownField::create('CampaignID', _t('UniadsObject.has_one_Campaign', 'Campaign'), DataList::create('UniadsCampaign')->map())->setEmptyString(_t('UniadsObject.Campaign_none', 'none')), DropdownField::create('ZoneID', _t('UniadsObject.has_one_Zone', 'Zone'), DataList::create('UniadsZone')->map())->setEmptyString(_t('UniadsObject.Zone_select', 'select one')), new NumericField('Weight', _t('UniadsObject.db_Weight', 'Weight (controls how often it will be shown relative to others)')), new TextField('TargetURL', _t('UniadsObject.db_TargetURL', 'Target URL')), new Treedropdownfield('InternalPageID', _t('UniadsObject.has_one_InternalPage', 'Internal Page Link'), 'Page'), new CheckboxField('NewWindow', _t('UniadsObject.db_NewWindow', 'Open in a new Window')), $file = new UploadField('File', _t('UniadsObject.has_one_File', 'Advertisement File')), $AdContent = new TextareaField('AdContent', _t('UniadsObject.db_AdContent', 'Advertisement Content')), $Starts = new DateField('Starts', _t('UniadsObject.db_Starts', 'Starts')), $Expires = new DateField('Expires', _t('UniadsObject.db_Expires', 'Expires')), new NumericField('ImpressionLimit', _t('UniadsObject.db_ImpressionLimit', 'Impression Limit')), new CheckboxField('Active', _t('UniadsObject.db_Active', 'Active')), new LiteralField('Preview', '<a href="' . $previewLink . '" target="_blank">' . _t('UniadsObject.Preview', 'Preview this advertisement') . "</a>")));
$app_categories = File::config()->app_categories;
$file->setFolderName($this->config()->files_dir);
$file->getValidator()->setAllowedMaxFileSize(array('*' => $this->config()->max_file_size));
$file->getValidator()->setAllowedExtensions(array_merge($app_categories['image'], $app_categories['flash']));
$AdContent->setRows(10);
$AdContent->setColumns(20);
$Starts->setConfig('showcalendar', true);
$Starts->setConfig('dateformat', i18n::get_date_format());
$Starts->setConfig('datavalueformat', 'yyyy-MM-dd');
$Expires->setConfig('showcalendar', true);
$Expires->setConfig('dateformat', i18n::get_date_format());
$Expires->setConfig('datavalueformat', 'yyyy-MM-dd');
$Expires->setConfig('min', date('Y-m-d', strtotime($this->Starts ? $this->Starts : '+1 days')));
}
$this->extend('updateCMSFields', $fields);
return $fields;
}
示例3: getExtensionsAllowed
/**
* @return array|scalar
*/
public function getExtensionsAllowed()
{
$allCategories = File::config()->app_categories;
$ret = array_merge($allCategories['zip'], $allCategories['doc']);
$ret[] = 'zip';
return $ret;
}
示例4: getCMSFields
public function getCMSFields()
{
$fields = new FieldList(new TabSet('Root'));
// Details
$fields->addFieldToTab('Root.Main', new TextareaField('Caption', _t('ImageGalleryItem.CAPTION', 'Caption')));
// Create image
$imageField = new UploadField('Image');
$imageField->getValidator()->setAllowedExtensions(File::config()->app_categories['image']);
$fields->addFieldToTab('Root.Main', $imageField);
return $fields;
}
示例5: getCMSFields
public function getCMSFields()
{
$fields = new FieldList(new TabSet('Root'));
// Details
$fields->addFieldToTab('Root.Main', new TextareaField('Caption', _t('MagnificGalleryItem.CAPTION', 'Caption')));
// Create image
$imageField = new UploadField('Image');
$imageField->getValidator()->setAllowedExtensions(File::config()->app_categories['image']);
$imageField->setFolderName($this->Album()->getUploadFolder());
$fields->addFieldToTab('Root.Main', $imageField);
// Details
$fields->addFieldToTab('Root.Main', new TextField('VideoLink', _t('MagnificGalleryItem.VIDEOLINK', 'Video link')));
return $fields;
}
示例6: open
public static function open($file)
{
global $config;
// static variable singleton
if (!self::$config_file) {
self::$config_file = $file;
}
// Check if config file exist and is readable, then include it
if (is_readable(self::$config_file)) {
require_once self::$config_file;
//echo 'configuration file <b>' . self::$config_file . '</b> succesfully loaded <br />';
self::$config = $config;
return true;
} else {
throw new Exception("Config file not found or bad file permissions");
}
}
示例7: configureUploadField
/**
* @param UploadField|\DisplayLogicWrapper $field
* @param string $configVarName - allow you to switch config to check e.g. 'allowed_video_files'
* @throws Exception
*/
protected function configureUploadField($field, $configVarName = 'allowed_files')
{
$fieldName = $field->getName();
if ($field instanceof \DisplayLogicWrapper) {
// drill down into wrapper to get actual UploadField
$field = $field->fieldByName($fieldName);
}
list($minlength, $maxlength, $pattern) = $this->fieldConstraints($fieldName, [0, 0, '']);
$field->setAllowedMaxFileNumber($maxlength ?: null);
// don't allow existing media to be re-attached it's a has_one so would be messy
$allowExistingFiles = $this->config()->get('can_attach_existing');
$field->setCanAttachExisting($allowExistingFiles);
$field->setFolderName($this->uploadFolderName());
// could be string for category or an array of extensions
// try extension first, then model
$extensions = $allowedFiles = $this->config()->get($configVarName) ?: $this()->config()->get($configVarName);
$categories = [];
if (!is_array($allowedFiles)) {
// could be comma separated list of categories
$categories = explode(',', $allowedFiles);
// get extensions from category so we always get a list of extensions for the CMS right title
$allCategoryExtensions = \File::config()->get('app_categories') ?: [];
foreach ($categories as $category) {
if (isset($allCategoryExtensions[$category])) {
$extensions = $allCategoryExtensions[$category];
} else {
$extensions = [$category];
}
}
}
if (is_array($allowedFiles)) {
// was an array originally, so pass merged extensions
$field->setAllowedExtensions($extensions);
} elseif ($categories) {
// array of categories to apply to setAllowedFileCategories as parameters
call_user_func_array([$field, 'setAllowedFileCategories'], $categories);
} elseif ($allowedFiles) {
// not an array so a category e.g. 'video'
$field->setAllowedFileCategories($allowedFiles);
} else {
throw new Exception("No {$configVarName} configuration set");
}
$field->setRightTitle($this->fieldDecoration($fieldName, 'Label', $field->Title(), ['extensions' => implode(', ', $extensions)]));
}
示例8: getCMSFields
public function getCMSFields()
{
// If the album is not created yet, ask first for an album title to create the folder
if (!$this->ID) {
$fields = new FieldList();
$fields->push(new TextField('AlbumName', _t('MagnificGalleryAlbum.ALBUMTITLE', 'Album Title'), null, 255));
$fields->push(new LiteralField('AlbumSaveInfos', _t('MagnificGalleryAlbum.ALBUMSAVEINFOS', 'You can add images and a description once the album is saved'), null, 255));
return $fields;
}
$fields = new FieldList(new TabSet('Root'));
// Image listing
$galleryConfig = GridFieldConfig_RecordEditor::create();
// Enable bulk image loading if necessary module is installed
// @see composer.json/suggests
if (class_exists('GridFieldBulkManager')) {
$galleryConfig->addComponent(new GridFieldBulkManager());
}
if (class_exists('GridFieldBulkUpload')) {
$galleryConfig->addComponents($imageConfig = new GridFieldBulkUpload('Image'));
$imageConfig->setUfSetup('setFolderName', $this->getUploadFolder());
}
// Enable image sorting if necessary module is installed
// @see composer.json/suggests
if (class_exists('GridFieldSortableRows')) {
$galleryConfig->addComponent(new GridFieldSortableRows('SortOrder'));
} else {
if (class_exists('GridFieldOrderableRows')) {
$galleryConfig->addComponent(new GridFieldOrderableRows('SortOrder'));
}
}
$galleryField = new GridField('GalleryItems', 'Gallery Items', $this->GalleryItems(), $galleryConfig);
$fields->addFieldToTab('Root.Main', $galleryField);
// Details
$thumbnailField = new UploadField('CoverImage', _t('MagnificGalleryAlbum.COVERIMAGE', 'Cover Image'));
$thumbnailField->getValidator()->setAllowedExtensions(File::config()->app_categories['image']);
$thumbnailField->setFolderName($this->getUploadFolder());
$fields->addFieldsToTab('Root.Album', array(new TextField('AlbumName', _t('MagnificGalleryAlbum.ALBUMTITLE', 'Album Title'), null, 255), new TextareaField('Description', _t('MagnificGalleryAlbum.DESCRIPTION', 'Description')), $thumbnailField));
return $fields;
}
示例9: testPublicAdapter
public function testPublicAdapter()
{
$_SERVER['SERVER_SOFTWARE'] = 'Apache/2.2.22 (Win64) PHP/5.3.13';
$adapter = new PublicAssetAdapter($this->rootDir);
$this->assertFileExists($this->rootDir . '/.htaccess');
$this->assertFileNotExists($this->rootDir . '/web.config');
$htaccess = $adapter->read('.htaccess');
$content = $htaccess['contents'];
// Allowed extensions set
$this->assertContains('RewriteCond %{REQUEST_URI} !.(?i:', $content);
foreach (File::config()->allowed_extensions as $extension) {
$this->assertRegExp('/\\b' . preg_quote($extension) . '\\b/', $content);
}
// Rewrite rules
$this->assertContains('RewriteRule .* ../framework/main.php?url=%1 [QSA]', $content);
$this->assertContains('RewriteRule error[^\\/]*.html$ - [L]', $content);
// Test flush restores invalid content
\file_put_contents($this->rootDir . '/.htaccess', '# broken content');
$adapter->flush();
$htaccess2 = $adapter->read('.htaccess');
$this->assertEquals($content, $htaccess2['contents']);
// Test URL
$this->assertEquals('/assets/AssetAdapterTest/file.jpg', $adapter->getPublicUrl('file.jpg'));
}
示例10: activate
/**
* Set this store as the new asset backend
*
* @param string $basedir Basedir to store assets, which will be placed beneath 'assets' folder
*/
public static function activate($basedir)
{
// Assign this as the new store
$adapter = new AssetAdapter(ASSETS_PATH . '/' . $basedir);
$filesystem = new Filesystem($adapter);
$filesystem->addPlugin(new FlysystemUrlPlugin());
$backend = new AssetStoreTest_SpyStore();
$backend->setFilesystem($filesystem);
Injector::inst()->registerService($backend, 'AssetStore');
// Disable legacy and set defaults
Config::inst()->remove(get_class(new FlysystemAssetStore()), 'legacy_filenames');
Config::inst()->update('Director', 'alternate_base_url', '/');
DBFile::config()->force_resample = false;
File::config()->force_resample = false;
self::reset();
self::$basedir = $basedir;
// Ensure basedir exists
SS_Filesystem::makeFolder(self::base_path());
}
示例11: JSONConfig
/**
* Creates a JSON string of all the variables that can be set in the Config
*
* @return string
*/
public function JSONConfig()
{
$r = $this->request;
// Remove null values and normalise leading dot
$allExts = $r->getVar('allowedExtensions') ? explode(',', $r->getVar('allowedExtensions')) : File::config()->allowed_extensions;
$exts = array_map(function ($item) {
return $item[0] == '.' ? $item : '.' . $item;
}, array_filter($allExts, 'strlen'));
$types = explode(',', $r->getVar('allowedTypes'));
return Convert::array2json(array('baseRoute' => Controller::join_links(Director::baseURL(), $this->Link()), 'maxFilesize' => FileAttachmentField::get_filesize_from_ini(), 'allowedExtensions' => implode(',', $exts), 'thumbnailsDir' => DROPZONE_DIR . '/images/file-icons', 'langNewFolder' => _t('AssetAdmin.NEWFOLDER', 'NewFolder'), 'iconSize' => self::ICON_SIZE, 'thumbnailWidth' => self::IMAGE_WIDTH, 'thumbnailHeight' => self::IMAGE_HEIGHT, 'defaultSort' => $this->config()->default_sort, 'defaultView' => $this->config()->default_view, 'maxCacheSize' => $this->config()->max_cache_size, 'folderExtension' => self::FOLDER_EXTENSION, 'allowSelection' => (bool) $r->getVar('allowSelection'), 'maxSelection' => (int) $r->getVar('maxSelection'), 'canUpload' => (bool) $r->getVar('canUpload'), 'canDelete' => (bool) $r->getVar('canDelete'), 'canEdit' => (bool) $r->getVar('canEdit'), 'canCreateFolder' => (bool) $r->getVar('canCreateFolder'), 'allowedTypes' => !empty($types) ? $types : null));
}
示例12: syncChildren
/**
* Synchronize the file database with the actual content of the assets
* folder.
*/
public function syncChildren()
{
$parentID = (int) $this->ID;
// parentID = 0 on the singleton, used as the 'root node';
$added = 0;
$deleted = 0;
$skipped = 0;
// First, merge any children that are duplicates
$duplicateChildrenNames = DB::prepared_query('SELECT "Name" FROM "File" WHERE "ParentID" = ? GROUP BY "Name" HAVING count(*) > 1', array($parentID))->column();
if ($duplicateChildrenNames) {
foreach ($duplicateChildrenNames as $childName) {
// Note, we do this in the database rather than object-model; otherwise we get all sorts of problems
// about deleting files
$children = DB::prepared_query('SELECT "ID" FROM "File" WHERE "Name" = ? AND "ParentID" = ?', array($childName, $parentID))->column();
if ($children) {
$keptChild = array_shift($children);
foreach ($children as $removedChild) {
DB::prepared_query('UPDATE "File" SET "ParentID" = ? WHERE "ParentID" = ?', array($keptChild, $removedChild));
DB::prepared_query('DELETE FROM "File" WHERE "ID" = ?', array($removedChild));
}
} else {
user_error("Inconsistent database issue: SELECT ID FROM \"File\" WHERE Name = '{$childName}'" . " AND ParentID = {$parentID} should have returned data", E_USER_WARNING);
}
}
}
// Get index of database content
// We don't use DataObject so that things like subsites doesn't muck with this.
$dbChildren = DB::prepared_query('SELECT * FROM "File" WHERE "ParentID" = ?', array($parentID));
$hasDbChild = array();
if ($dbChildren) {
foreach ($dbChildren as $dbChild) {
$className = $dbChild['ClassName'];
if (!$className) {
$className = "File";
}
$hasDbChild[$dbChild['Name']] = new $className($dbChild);
}
}
$unwantedDbChildren = $hasDbChild;
// if we're syncing a folder with no ID, we assume we're syncing the root assets folder
// however the Filename field is populated with "NewFolder", so we need to set this to empty
// to satisfy the baseDir variable below, which is the root folder to scan for new files in
if (!$parentID) {
$this->Filename = '';
}
// Iterate through the actual children, correcting the database as necessary
$baseDir = $this->FullPath;
// @todo this shouldn't call die() but log instead
if ($parentID && !$this->Filename) {
die($this->ID . " - " . $this->FullPath);
}
if (file_exists($baseDir)) {
$actualChildren = scandir($baseDir);
$ignoreRules = Filesystem::config()->sync_blacklisted_patterns;
$allowedExtensions = File::config()->allowed_extensions;
$checkExtensions = $this->config()->apply_restrictions_to_admin || !Permission::check('ADMIN');
foreach ($actualChildren as $actualChild) {
$skip = false;
// Check ignore patterns
if ($ignoreRules) {
foreach ($ignoreRules as $rule) {
if (preg_match($rule, $actualChild)) {
$skip = true;
break;
}
}
}
// Check allowed extensions, unless admin users are allowed to bypass these exclusions
if ($checkExtensions && !is_dir($baseDir . $actualChild) && ($extension = self::get_file_extension($actualChild)) && !in_array(strtolower($extension), $allowedExtensions)) {
$skip = true;
}
if ($skip) {
$skipped++;
continue;
}
// A record with a bad class type doesn't deserve to exist. It must be purged!
if (isset($hasDbChild[$actualChild])) {
$child = $hasDbChild[$actualChild];
if (!$child instanceof Folder && is_dir($baseDir . $actualChild) || $child instanceof Folder && !is_dir($baseDir . $actualChild)) {
DB::prepared_query('DELETE FROM "File" WHERE "ID" = ?', array($child->ID));
unset($hasDbChild[$actualChild]);
}
}
if (isset($hasDbChild[$actualChild])) {
$child = $hasDbChild[$actualChild];
unset($unwantedDbChildren[$actualChild]);
} else {
$added++;
$childID = $this->constructChild($actualChild);
$child = DataObject::get_by_id("File", $childID);
}
if ($child && is_dir($baseDir . $actualChild)) {
$childResult = $child->syncChildren();
$added += $childResult['added'];
$deleted += $childResult['deleted'];
$skipped += $childResult['skipped'];
//.........这里部分代码省略.........
示例13: isValidFile
/**
* Check if the following path is valid
*
* @param type $path
*/
protected function isValidFile($path)
{
$extension = strtolower(pathinfo($path, PATHINFO_EXTENSION));
$allowed = array_map('strtolower', File::config()->allowed_extensions);
return in_array($extension, $allowed);
}
示例14: validate
/**
* Hook to validate this record against a validation result
*
* @param ValidationResult $result
* @param string $filename Optional filename to validate. If omitted, the current value is validated.
* @return bool Valid flag
*/
public function validate(ValidationResult $result, $filename = null)
{
if (empty($filename)) {
$filename = $this->getFilename();
}
if (empty($filename) || $this->isValidFilename($filename)) {
return true;
}
// Check allowed extensions
$extensions = $this->getAllowedExtensions();
if (empty($extensions)) {
$extensions = File::config()->allowed_extensions;
}
sort($extensions);
$message = _t('File.INVALIDEXTENSION', 'Extension is not allowed (valid: {extensions})', 'Argument 1: Comma-separated list of valid extensions', array('extensions' => wordwrap(implode(', ', $extensions))));
$result->error($message);
return false;
}
示例15: setAllowedFileCategories
/**
* Limit allowed file extensions by specifying categories of file types.
* These may be 'image', 'audio', 'mov', 'zip', 'flash', or 'doc'
* See {@link File::$allowed_extensions} for details of allowed extensions
* for each of these categories
*
* @param string $category Category name
* @param string,... $categories Additional category names
* @return UploadField Self reference
*/
public function setAllowedFileCategories($category)
{
$extensions = array();
$knownCategories = File::config()->app_categories;
// Parse arguments
$categories = func_get_args();
if (func_num_args() === 1 && is_array(reset($categories))) {
$categories = reset($categories);
}
// Merge all categories into list of extensions
foreach (array_filter($categories) as $category) {
if (isset($knownCategories[$category])) {
$extensions = array_merge($extensions, $knownCategories[$category]);
} else {
user_error("Unknown file category: {$category}", E_USER_ERROR);
}
}
return $this->setAllowedExtensions($extensions);
}