本文整理汇总了PHP中Gdn_Upload::generateTargetName方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_Upload::generateTargetName方法的具体用法?PHP Gdn_Upload::generateTargetName怎么用?PHP Gdn_Upload::generateTargetName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn_Upload
的用法示例。
在下文中一共展示了Gdn_Upload::generateTargetName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: banner
/**
* Banner management screen.
*
* @since 2.0.0
* @access public
*/
public function banner()
{
$this->permission('Garden.Community.Manage');
$this->addSideMenu('dashboard/settings/banner');
$this->title(t('Banner'));
$Validation = new Gdn_Validation();
$ConfigurationModel = new Gdn_ConfigurationModel($Validation);
$ConfigurationModel->setField(array('Garden.HomepageTitle' => c('Garden.Title'), 'Garden.Title', 'Garden.Description'));
// Set the model on the form.
$this->Form->setModel($ConfigurationModel);
// Get the current logo.
$Logo = c('Garden.Logo');
if ($Logo) {
$Logo = ltrim($Logo, '/');
// Fix the logo path.
if (stringBeginsWith($Logo, 'uploads/')) {
$Logo = substr($Logo, strlen('uploads/'));
}
$this->setData('Logo', $Logo);
}
// Get the current mobile logo.
$MobileLogo = c('Garden.MobileLogo');
if ($MobileLogo) {
$MobileLogo = ltrim($MobileLogo, '/');
// Fix the logo path.
if (stringBeginsWith($MobileLogo, 'uploads/')) {
$MobileLogo = substr($MobileLogo, strlen('uploads/'));
}
$this->setData('MobileLogo', $MobileLogo);
}
// Get the current favicon.
$Favicon = c('Garden.FavIcon');
$this->setData('Favicon', $Favicon);
$ShareImage = c('Garden.ShareImage');
$this->setData('ShareImage', $ShareImage);
// If seeing the form for the first time...
if (!$this->Form->authenticatedPostBack()) {
// Apply the config settings to the form.
$this->Form->setData($ConfigurationModel->Data);
} else {
$SaveData = array();
if ($this->Form->save() !== false) {
$Upload = new Gdn_Upload();
try {
// Validate the upload
$TmpImage = $Upload->validateUpload('Logo', false);
if ($TmpImage) {
// Generate the target image name
$TargetImage = $Upload->generateTargetName(PATH_UPLOADS);
$ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
// Delete any previously uploaded images.
if ($Logo) {
$Upload->delete($Logo);
}
// Save the uploaded image
$Parts = $Upload->SaveAs($TmpImage, $ImageBaseName);
$ImageBaseName = $Parts['SaveName'];
$SaveData['Garden.Logo'] = $ImageBaseName;
$this->setData('Logo', $ImageBaseName);
}
$TmpMobileImage = $Upload->validateUpload('MobileLogo', false);
if ($TmpMobileImage) {
// Generate the target image name
$TargetImage = $Upload->generateTargetName(PATH_UPLOADS);
$ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
// Delete any previously uploaded images.
if ($MobileLogo) {
$Upload->delete($MobileLogo);
}
// Save the uploaded image
$Parts = $Upload->saveAs($TmpMobileImage, $ImageBaseName);
$ImageBaseName = $Parts['SaveName'];
$SaveData['Garden.MobileLogo'] = $ImageBaseName;
$this->setData('MobileLogo', $ImageBaseName);
}
$ImgUpload = new Gdn_UploadImage();
$TmpFavicon = $ImgUpload->validateUpload('Favicon', false);
if ($TmpFavicon) {
$ICOName = 'favicon_' . substr(md5(microtime()), 16) . '.ico';
if ($Favicon) {
$Upload->delete($Favicon);
}
// Resize the to a png.
$Parts = $ImgUpload->SaveImageAs($TmpFavicon, $ICOName, 16, 16, array('OutputType' => 'ico', 'Crop' => true));
$SaveData['Garden.FavIcon'] = $Parts['SaveName'];
$this->setData('Favicon', $Parts['SaveName']);
}
$TmpShareImage = $Upload->ValidateUpload('ShareImage', false);
if ($TmpShareImage) {
$TargetImage = $Upload->GenerateTargetName(PATH_UPLOADS, false);
$ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
if ($ShareImage) {
$Upload->delete($ShareImage);
}
//.........这里部分代码省略.........
示例2: editCategory
/**
* Editing a category.
*
* @since 2.0.0
* @access public
*
* @param int $CategoryID Unique ID of the category to be updated.
*/
public function editCategory($CategoryID = '')
{
// Check permission
$this->permission('Garden.Community.Manage');
// Set up models
$RoleModel = new RoleModel();
$PermissionModel = Gdn::permissionModel();
$this->Form->setModel($this->CategoryModel);
if (!$CategoryID && $this->Form->authenticatedPostBack()) {
if ($ID = $this->Form->getFormValue('CategoryID')) {
$CategoryID = $ID;
}
}
// Get category data
$this->Category = $this->CategoryModel->getID($CategoryID);
if (!$this->Category) {
throw notFoundException('Category');
}
$this->Category->CustomPermissions = $this->Category->CategoryID == $this->Category->PermissionCategoryID;
// Set up head
$this->addJsFile('jquery.alphanumeric.js');
$this->addJsFile('categories.js');
$this->addJsFile('jquery.gardencheckboxgrid.js');
$this->title(t('Edit Category'));
$this->addSideMenu('vanilla/settings/managecategories');
// Make sure the form knows which item we are editing.
$this->Form->addHidden('CategoryID', $CategoryID);
$this->setData('CategoryID', $CategoryID);
// Load all roles with editable permissions
$this->RoleArray = $RoleModel->getArray();
$this->fireEvent('AddEditCategory');
if ($this->Form->authenticatedPostBack()) {
$this->setupDiscussionTypes($this->Category);
$Upload = new Gdn_Upload();
$TmpImage = $Upload->validateUpload('PhotoUpload', false);
if ($TmpImage) {
// Generate the target image name
$TargetImage = $Upload->generateTargetName(PATH_UPLOADS);
$ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
// Save the uploaded image
$Parts = $Upload->saveAs($TmpImage, $ImageBaseName);
$this->Form->setFormValue('Photo', $Parts['SaveName']);
}
$this->Form->setFormValue('CustomPoints', (bool) $this->Form->getFormValue('CustomPoints'));
if ($this->Form->save()) {
$Category = CategoryModel::categories($CategoryID);
$this->setData('Category', $Category);
if ($this->deliveryType() == DELIVERY_TYPE_ALL) {
redirect('vanilla/settings/managecategories');
}
}
} else {
$this->Form->setData($this->Category);
$this->setupDiscussionTypes($this->Category);
$this->Form->setValue('CustomPoints', $this->Category->PointsCategoryID == $this->Category->CategoryID);
}
// Get all of the currently selected role/permission combinations for this junction.
$Permissions = $PermissionModel->getJunctionPermissions(array('JunctionID' => $CategoryID), 'Category', '', array('AddDefaults' => !$this->Category->CustomPermissions));
$Permissions = $PermissionModel->unpivotPermissions($Permissions, true);
if ($this->deliveryType() == DELIVERY_TYPE_ALL) {
$this->setData('PermissionData', $Permissions, true);
}
// Render default view
$this->render();
}
示例3: handleAddonUpload
/**
* Handle form upload of an addon zip archive.
*
* @return array
*/
protected function handleAddonUpload()
{
$Upload = new Gdn_Upload();
$Upload->allowFileExtension(null);
$Upload->allowFileExtension('zip');
$AnalyzedAddon = [];
try {
// Validate the upload.
$TmpFile = $Upload->validateUpload('File');
$Extension = pathinfo($Upload->getUploadedFileName(), PATHINFO_EXTENSION);
// Generate the target name.
$TargetFile = $Upload->generateTargetName('addons', $Extension);
$TargetPath = PATH_UPLOADS . '/' . $TargetFile;
if (!file_exists(dirname($TargetPath))) {
mkdir(dirname($TargetPath), 0777, true);
}
// Save the file to a temporary location for parsing.
if (!move_uploaded_file($TmpFile, $TargetPath)) {
throw new Exception("We couldn't save the file you uploaded. Please try again later.", 400);
}
$AnalyzedAddon = UpdateModel::analyzeAddon($TargetPath, true);
// If the long description is blank, load up the readme if it exists
$formDescription = $this->Form->getFormValue('Description2', '');
if ($formDescription == '') {
$Readme = $this->parseReadme($TargetPath);
if ($Readme) {
$AnalyzedAddon['Description2'] = $Readme;
}
} else {
$AnalyzedAddon['Description2'] = $formDescription;
}
// Get an icon if one exists.
$Icon = $this->extractIcon($TargetPath, val('Icon', $AnalyzedAddon, ''));
if ($Icon) {
// Overwrite info array value with the path to the saved file.
$AnalyzedAddon['Icon'] = $Icon;
}
// Set the filename for the CDN.
$Upload->EventArguments['OriginalFilename'] = AddonModel::slug($AnalyzedAddon, true) . '.zip';
// Save the uploaded file. After this, we no longer have a local copy to analyze.
$Parsed = $Upload->saveAs($TargetPath, $TargetFile);
$AnalyzedAddon['File'] = $Parsed['SaveName'];
unset($AnalyzedAddon['Path']);
trace($AnalyzedAddon, 'Analyzed Addon');
$this->Form->formValues($AnalyzedAddon);
} catch (Exception $ex) {
$this->Form->addError($ex);
// Delete the erroneous file.
try {
if (isset($AnalyzedAddon) && isset($AnalyzedAddon['File'])) {
$Upload->delete($AnalyzedAddon['File']);
}
} catch (Exception $Ex2) {
}
}
if (isset($TargetPath) && file_exists($TargetPath)) {
unlink($TargetPath);
}
return $AnalyzedAddon;
}
示例4: editCategory
/**
* Editing a category.
*
* @since 2.0.0
* @param int|string $CategoryID Unique ID of the category to be updated.
* @throws Exception when category cannot be found.
*/
public function editCategory($CategoryID = '')
{
// Check permission
$this->permission(['Garden.Community.Manage', 'Garden.Settings.Manage'], false);
// Set up models
$RoleModel = new RoleModel();
$PermissionModel = Gdn::permissionModel();
$this->Form->setModel($this->CategoryModel);
if (!$CategoryID && $this->Form->authenticatedPostBack()) {
if ($ID = $this->Form->getFormValue('CategoryID')) {
$CategoryID = $ID;
}
}
// Get category data
$this->Category = CategoryModel::categories($CategoryID);
if (!$this->Category) {
throw notFoundException('Category');
}
// Category data is expected to be in the form of an object.
$this->Category = (object) $this->Category;
$this->Category->CustomPermissions = $this->Category->CategoryID == $this->Category->PermissionCategoryID;
$displayAsOptions = categoryModel::getDisplayAsOptions();
// Restrict "Display As" types based on parent.
$parentCategory = $this->CategoryModel->getID($this->Category->ParentCategoryID);
$parentDisplay = val('DisplayAs', $parentCategory);
if ($parentDisplay === 'Flat') {
unset($displayAsOptions['Heading']);
}
// Set up head
$this->addJsFile('jquery.alphanumeric.js');
$this->addJsFile('manage-categories.js');
$this->addJsFile('jquery.gardencheckboxgrid.js');
$this->title(t('Edit Category'));
$this->setHighlightRoute('vanilla/settings/categories');
// Make sure the form knows which item we are editing.
$this->Form->addHidden('CategoryID', $CategoryID);
$this->setData('CategoryID', $CategoryID);
// Load all roles with editable permissions
$this->RoleArray = $RoleModel->getArray();
$this->fireAs('SettingsController');
$this->fireEvent('AddEditCategory');
if ($this->Form->authenticatedPostBack()) {
$this->setupDiscussionTypes($this->Category);
$Upload = new Gdn_Upload();
$TmpImage = $Upload->validateUpload('PhotoUpload', false);
if ($TmpImage) {
// Generate the target image name
$TargetImage = $Upload->generateTargetName(PATH_UPLOADS);
$ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
// Save the uploaded image
$Parts = $Upload->saveAs($TmpImage, $ImageBaseName);
$this->Form->setFormValue('Photo', $Parts['SaveName']);
}
$this->Form->setFormValue('CustomPoints', (bool) $this->Form->getFormValue('CustomPoints'));
// Enforces tinyint values on boolean fields to comply with strict mode
$this->Form->setFormValue('HideAllDiscussions', forceBool($this->Form->getFormValue('HideAllDiscussions'), '0', '1', '0'));
$this->Form->setFormValue('Archived', forceBool($this->Form->getFormValue('Archived'), '0', '1', '0'));
$this->Form->setFormValue('AllowFileUploads', forceBool($this->Form->getFormValue('AllowFileUploads'), '0', '1', '0'));
if ($parentDisplay === 'Flat' && $this->Form->getFormValue('DisplayAs') === 'Heading') {
$this->Form->addError('Cannot display as a heading when your parent category is displayed flat.', 'DisplayAs');
}
if ($this->Form->save()) {
$Category = CategoryModel::categories($CategoryID);
$this->setData('Category', $Category);
if ($this->deliveryType() == DELIVERY_TYPE_ALL) {
$destination = $this->categoryPageByParent($parentCategory);
redirect($destination);
} elseif ($this->deliveryType() === DELIVERY_TYPE_DATA && method_exists($this, 'getCategory')) {
$this->Data = [];
$this->getCategory($CategoryID);
return;
}
}
} else {
$this->Form->setData($this->Category);
$this->setupDiscussionTypes($this->Category);
$this->Form->setValue('CustomPoints', $this->Category->PointsCategoryID == $this->Category->CategoryID);
}
// Get all of the currently selected role/permission combinations for this junction.
$Permissions = $PermissionModel->getJunctionPermissions(array('JunctionID' => $CategoryID), 'Category', '', array('AddDefaults' => !$this->Category->CustomPermissions));
$Permissions = $PermissionModel->unpivotPermissions($Permissions, true);
if ($this->deliveryType() == DELIVERY_TYPE_ALL) {
$this->setData('PermissionData', $Permissions, true);
}
// Render default view
$this->setData('Operation', 'Edit');
$this->setData('DisplayAsOptions', $displayAsOptions);
$this->render();
}