本文整理汇总了PHP中Folder::findOrMake方法的典型用法代码示例。如果您正苦于以下问题:PHP Folder::findOrMake方法的具体用法?PHP Folder::findOrMake怎么用?PHP Folder::findOrMake使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Folder
的用法示例。
在下文中一共展示了Folder::findOrMake方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: complete
/**
* Completes the job by zipping up the generated export and creating an
* export record for it.
*/
protected function complete()
{
$siteTitle = SiteConfig::current_site_config()->Title;
$filename = preg_replace('/[^a-zA-Z0-9-.+]/', '-', sprintf('%s-%s.zip', $siteTitle, date('c')));
$dir = Folder::findOrMake(SiteExportExtension::EXPORTS_DIR);
$dirname = ASSETS_PATH . '/' . SiteExportExtension::EXPORTS_DIR;
$pathname = "{$dirname}/{$filename}";
SiteExportUtils::zip_directory($this->tempDir, "{$dirname}/{$filename}");
Filesystem::removeFolder($this->tempDir);
$file = new File();
$file->ParentID = $dir->ID;
$file->Title = $siteTitle . ' ' . date('c');
$file->Filename = $dir->Filename . $filename;
$file->write();
$export = new SiteExport();
$export->ParentClass = $this->rootClass;
$export->ParentID = $this->rootId;
$export->Theme = $this->theme;
$export->BaseUrlType = ucfirst($this->baseUrlType);
$export->BaseUrl = $this->baseUrl;
$export->ArchiveID = $file->ID;
$export->write();
if ($this->email) {
$email = new Email();
$email->setTo($this->email);
$email->setTemplate('SiteExportCompleteEmail');
$email->setSubject(sprintf('Site Export For "%s" Complete', $siteTitle));
$email->populateTemplate(array('SiteTitle' => $siteTitle, 'Link' => $file->getAbsoluteURL()));
$email->send();
}
}
示例2: testCreateWithFilenameWithSubfolder
function testCreateWithFilenameWithSubfolder()
{
// Note: We can't use fixtures/setUp() for this, as we want to create the db record manually.
// Creating the folder is necessary to avoid having "Filename" overwritten by setName()/setRelativePath(),
// because the parent folders don't exist in the database
$folder = Folder::findOrMake('/FileTest/');
$testfilePath = 'assets/FileTest/CreateWithFilenameHasCorrectPath.txt';
// Important: No leading slash
$fh = fopen(BASE_PATH . '/' . $testfilePath, "w");
fwrite($fh, str_repeat('x', 1000000));
fclose($fh);
$file = new File();
$file->Filename = $testfilePath;
// TODO This should be auto-detected
$file->ParentID = $folder->ID;
$file->write();
$this->assertEquals('CreateWithFilenameHasCorrectPath.txt', $file->Name, '"Name" property is automatically set from "Filename"');
$this->assertEquals($testfilePath, $file->Filename, '"Filename" property remains unchanged');
// TODO This should be auto-detected, see File->updateFilesystem()
// $this->assertType('Folder', $file->Parent(), 'Parent folder is created in database');
// $this->assertFileExists($file->Parent()->getFullPath(), 'Parent folder is created on filesystem');
// $this->assertEquals('FileTest', $file->Parent()->Name);
// $this->assertType('Folder', $file->Parent()->Parent(), 'Grandparent folder is created in database');
// $this->assertFileExists($file->Parent()->Parent()->getFullPath(), 'Grandparent folder is created on filesystem');
// $this->assertEquals('assets', $file->Parent()->Parent()->Name);
}
示例3: requireDefaultAlbum
private function requireDefaultAlbum()
{
$class = $this->albumClass;
$album = new $class();
$album->AlbumName = "Default Album";
$album->ImageGalleryPageID = $this->ID;
$album->ParentID = $this->RootFolderID;
$folder = Folder::findOrMake('image-gallery/' . $this->RootFolder()->Name . '/' . $album->AlbumName);
$folder->write();
$album->FolderID = $folder->ID;
$album->write();
}
示例4: doExport
public function doExport($data, $form)
{
$data = $form->getData();
$links = array();
$siteTitle = SiteConfig::current_site_config()->Title;
// If the queued jobs module is installed, then queue up an export
// job rather than performing the export.
if (class_exists('QueuedJobService')) {
$job = new SiteExportJob($form->getRecord());
$job->theme = $data['ExportSiteTheme'];
$job->baseUrl = $data['ExportSiteBaseUrl'];
$job->baseUrlType = $data['ExportSiteBaseUrlType'];
$job->email = $data['ExportSiteCompleteEmail'];
singleton('QueuedJobService')->queueJob($job);
return new SS_HTTPResponse($form->dataFieldByName('SiteExports')->FieldHolder(), 200, 'The site export job has been queued.');
}
// First generate a temp directory to store the export content in.
$temp = TEMP_FOLDER;
$temp .= sprintf('/siteexport_%s', date('Y-m-d-His'));
mkdir($temp);
$exporter = new SiteExporter();
$exporter->root = $form->getRecord();
$exporter->theme = $data['ExportSiteTheme'];
$exporter->baseUrl = $data['ExportSiteBaseUrl'];
$exporter->makeRelative = $data['ExportSiteBaseUrlType'] == 'rewrite';
$exporter->exportTo($temp);
// Then place the exported content into an archive, stored in the assets
// root, and create a site export for it.
$filename = preg_replace('/[^a-zA-Z0-9-.+]/', '-', sprintf('%s-%s.zip', $siteTitle, date('c')));
$dir = Folder::findOrMake(self::EXPORTS_DIR);
$dirname = ASSETS_PATH . '/' . self::EXPORTS_DIR;
$pathname = "{$dirname}/{$filename}";
SiteExportUtils::zip_directory($temp, "{$dirname}/{$filename}");
Filesystem::removeFolder($temp);
$file = new File();
$file->ParentID = $dir->ID;
$file->Title = $siteTitle . ' ' . date('c');
$file->Filename = $dir->Filename . $filename;
$file->write();
$export = new SiteExport();
$export->ParentClass = $form->getRecord()->class;
$export->ParentID = $form->getRecord()->ID;
$export->Theme = SSViewer::current_theme();
$export->BaseUrlType = ucfirst($data['ExportSiteBaseUrlType']);
$export->BaseUrl = $data['ExportSiteBaseUrl'];
$export->ArchiveID = $file->ID;
$export->write();
return new SS_HTTPResponse($form->dataFieldByName('SiteExports')->FieldHolder(), 200, 'The site export has been generated.');
}
示例5: onBeforeWrite
function onBeforeWrite()
{
parent::onBeforeWrite();
if (isset($_POST['AlbumName'])) {
$clean_name = SiteTree::generateURLSegment($_POST['AlbumName']);
if ($this->FolderID) {
$this->Folder()->setName($clean_name);
$this->Folder()->Title = $clean_name;
$this->Folder()->write();
} else {
$folder = Folder::findOrMake('image-gallery/' . $this->ImageGalleryPage()->RootFolder()->Name . '/' . $clean_name);
$this->FolderID = $folder->ID;
}
}
}
示例6: upload
/**
* Processes the uploaded files in the request. Most of the legwork is handled in {@link KickAssetUtil}
*
* @return SS_HTTPResponse
*/
public function upload(SS_HTTPRequest $r)
{
// We don't want anyone uploading to the root assets folder..
if (!$this->defaultFolder) {
$this->defaultFolder = Folder::findOrMake("Uploads");
}
$response = KickAssetUtil::handle_upload($r, $this->defaultFolder);
if (empty($response)) {
return new SS_HTTPResponse("File did not upload", 500);
}
if (is_array($response)) {
return new SS_HTTPResponse(implode(',', $response), 200);
}
return new SS_HTTPResponse("Error: " . $response, 500);
}
示例7: Field
public function Field($properties = array())
{
Requirements::javascript(THIRDPARTY_DIR . '/jquery-livequery/jquery.livequery.js');
Requirements::javascript('pixlr/thirdparty/supa/Supa.js');
Requirements::javascript('pixlr/javascript/supa-field.js');
Requirements::css('pixlr/css/pixlr.css');
$id = $this->id();
$div = '<div id="' . $id . 'Container" class="' . $this->extraClass() . ' supaField">';
$div .= '<div class="supaButtons">';
$div .= $this->createTag('input', array('id' => $id . 'Paste', 'value' => _t('Pixlr.PASTE', 'Paste'), 'type' => 'button', 'class' => 'supaPasteButton'));
$div .= $this->createTag('input', array('id' => $id . 'Upload', 'value' => _t('Pixlr.UPLOAD', 'Upload'), 'type' => 'button', 'class' => 'supaUploadButton', 'style' => 'display: none'));
$div .= $this->createTag('input', array('type' => 'checkbox', 'value' => '1', 'name' => 'AndEdit', 'id' => $id . 'AndEdit'));
$div .= '<label for="' . $id . 'AndEdit' . '">and Edit</label>';
$div .= $this->createTag('input', array('class' => 'supaFileID', 'type' => 'hidden', 'value' => ''));
$div .= '</div><div class="supaOptions" style="display: none">';
if ($this->options['show_selector']) {
$treeField = new TreeDropdownField('SupaLocation', _t('Pixlr.UPLOAD_LOCATION', 'Save to'), 'File');
$div .= $treeField->Field();
} else {
// create a default target for uploading to
$target = Folder::findOrMake($this->options['target']);
$div .= $this->createTag('input', array('type' => 'hidden', 'name' => 'SupaLocation', 'value' => $target->ID));
}
$div .= $this->createTag('input', array('id' => $id . 'Filename', 'value' => $this->options['name'], 'name' => 'SupaImageName'));
$params = array('parent' => '{input[name=FolderID]}', 'force' => true, 'imgstate' => 'existing', 'title' => '{#' . $id . 'Filename}.png');
$pixlr = new PixlrEditorField('EditSelectedImage' . $id, _t('Pixlr.EDIT_SELECTED', 'Edit Selected'), '{#' . $id . 'Container .supaFileID}', $params);
$div .= $pixlr->Field();
$div .= '</div><div class="supaFileUrl"></div><div class="supaAppletWrapper" id="' . $id . 'AppletWrapper">';
$url = Director::absoluteBaseURL() . 'pixlr/thirdparty/supa/Supa.jar';
$div .= '<applet id="' . $id . 'Applet" class="supaApplet"
archive="' . $url . '"
code="de.christophlinder.supa.SupaApplet"
width="' . $this->options['width'] . '"
height="' . $this->options['height'] . '">
<!--param name="clickforpaste" value="true"-->
<param name="imagecodec" value="png">
<param name="encoding" value="base64">
<param name="previewscaler" value="fit to canvas">
<!--param name="trace" value="true"-->
Applets disabled :(
</applet> ';
$div .= '</div></div>';
return $div;
}
示例8: setUp
function setUp()
{
parent::setUp();
// clear File to start.
$files = DataObject::get("File");
if ($files) {
foreach ($files as $f) {
$f->deleteDatabaseOnly();
}
}
$folder = Folder::findOrMake('/dynamic_templates/');
$test1 = $this->setUpTemplate($folder, 'tmp__TemplateNoManifest');
$test2 = $this->setUpTemplate($folder, 'tmp__TemplateWithManifest');
$this->recurse_copy(Director::baseFolder() . "/dynamictemplate/tests/TemplateNoManifest", Director::baseFolder() . "/assets/dynamic_templates/tmp__TemplateNoManifest");
$this->recurse_copy(Director::baseFolder() . "/dynamictemplate/tests/TemplateWithManifest", Director::baseFolder() . "/assets/dynamic_templates/tmp__TemplateWithManifest");
$test1->syncChildren();
$test2->syncChildren();
// $this->dump_files("end of setUp");
}
示例9: CurrentUploadFolder
/**
* Determine the "current" upload folder, e.g. If the {@see $uploadFolder} is not defined,
* then get the folder of the last file uploaded
*
* @return Folder
*/
public function CurrentUploadFolder()
{
if ($this->allowFolderSelection && $this->getUploadFolder() == "Uploads") {
if ($result = $this->Files()) {
if ($result instanceof File) {
return $result->Parent();
} elseif ($result instanceof DataObjectSet) {
return $result->First()->Parent();
}
}
}
return Folder::findOrMake($this->getUploadFolder());
}
示例10: load
/**
* Save an file passed from a form post into this object.
*
* @param $tmpFile array Indexed array that PHP generated for every file it uploads.
* @param $folderPath string Folder path relative to /assets
* @return Boolean|string Either success or error-message.
*/
function load($tmpFile, $folderPath = false) {
$this->clearErrors();
if(!$folderPath) $folderPath = self::$uploads_folder;
if(!$this->file) $this->file = new File();
if(!is_array($tmpFile)) {
user_error("File::loadUploaded() Not passed an array. Most likely, the form hasn't got the right enctype", E_USER_ERROR);
}
if(!$tmpFile['size']) {
$this->errors[] = _t('File.NOFILESIZE', 'Filesize is zero bytes.');
return false;
}
$valid = $this->validate($tmpFile);
if(!$valid) return false;
// @TODO This puts a HUGE limitation on files especially when lots
// have been uploaded.
$base = Director::baseFolder();
$parentFolder = Folder::findOrMake($folderPath);
// Create a folder for uploading.
if(!file_exists(ASSETS_PATH)){
mkdir(ASSETS_PATH, Filesystem::$folder_create_mask);
}
if(!file_exists(ASSETS_PATH . "/" . $folderPath)){
mkdir(ASSETS_PATH . "/" . $folderPath, Filesystem::$folder_create_mask);
}
// Generate default filename
$fileName = str_replace(' ', '-',$tmpFile['name']);
$fileName = ereg_replace('[^A-Za-z0-9+.-]+','',$fileName);
$fileName = ereg_replace('-+', '-',$fileName);
$fileName = basename($fileName);
$relativeFilePath = ASSETS_DIR . "/" . $folderPath . "/$fileName";
// if filename already exists, version the filename (e.g. test.gif to test1.gif)
while(file_exists("$base/$relativeFilePath")) {
$i = isset($i) ? ($i+1) : 2;
$oldFilePath = $relativeFilePath;
// make sure archives retain valid extensions
if(substr($relativeFilePath, strlen($relativeFilePath) - strlen('.tar.gz')) == '.tar.gz' ||
substr($relativeFilePath, strlen($relativeFilePath) - strlen('.tar.bz2')) == '.tar.bz2') {
$relativeFilePath = ereg_replace('[0-9]*(\.tar\.[^.]+$)',$i . '\\1', $relativeFilePath);
} else {
$relativeFilePath = ereg_replace('[0-9]*(\.[^.]+$)',$i . '\\1', $relativeFilePath);
}
if($oldFilePath == $relativeFilePath && $i > 2) user_error("Couldn't fix $relativeFilePath with $i tries", E_USER_ERROR);
}
if(file_exists($tmpFile['tmp_name']) && copy($tmpFile['tmp_name'], "$base/$relativeFilePath")) {
$this->file->ParentID = $parentFolder->ID;
// This is to prevent it from trying to rename the file
$this->file->Name = basename($relativeFilePath);
$this->file->write();
return true;
} else {
$this->errors[] = _t('File.NOFILESIZE', 'Filesize is zero bytes.');
return false;
}
}
示例11: create_empty_template
public static function create_empty_template($name)
{
$template = new DynamicTemplate();
$base = $name;
$holder = Folder::findOrMake(self::$dynamic_template_folder);
$template->ParentID = $holder->ID;
$suffix = 1;
while (DataObject::get('DynamicTemplate', "\"Name\" LIKE '%" . $name . "%'")) {
$name = "{$base}{$suffix}";
$suffix++;
}
$template->Name = $name;
$template->Title = $name;
$template->write();
if (!file_exists($template->getFullPath())) {
mkdir($template->getFullPath(), Filesystem::$folder_create_mask);
}
return $template;
}
示例12: transferlegacycontent
/**
* Transfer all the content from the Image table into the File table.
* @deprecated This function is only used to migrate content from old databases.
*/
function transferlegacycontent()
{
if (!Permission::check('ADMIN')) {
Security::permissionFailure($this);
}
$images = DB::query("SELECT * FROM _obsolete_Image");
echo "<h3>Transferring images</h3>";
foreach ($images as $image) {
if (($className = $image['ClassName']) && $image['Filename']) {
echo "<li>Importing {$image['Filename']}";
$folderName = str_replace('assets/', '', dirname($image['Filename']));
$name = basename($image['Filename']);
$folderObj = Folder::findOrMake($folderName);
$fileObj = new $className();
$fileObj->Name = $name;
$fileObj->ParentID = $folderObj->ID;
$fileObj->write();
$fileObj->destroy();
echo " as {$fileObj->ID}";
list($baseClass, $fieldName) = explode('_', $className, 2);
//if($baseClass == 'News') $baseClass = 'NewsHolder';
//if($baseClass == 'FAQ') $baseClass = 'FaqHolder';
$parentObj = DataObject::get_by_id($baseClass, $image['ParentID']);
if ($parentObj && $fieldName) {
$fieldName .= "ID";
echo "<li>{$parentObj->class}.{$parentObj->ID}.{$fieldName} = {$fileObj->ID}";
$parentObj->{$fieldName} = $fileObj->ID;
$parentObj->write();
$parentObj->destroy();
}
// echo " and linking to $baseClass.$image[ParentID]->$fieldName";
}
}
}
示例13: moverootfilesto
function moverootfilesto()
{
if ($folder = $this->urlParams[ID]) {
$newParent = Folder::findOrMake($folder);
$files = DataObject::get("File", "ClassName != 'Folder' AND ParentID = 0");
foreach ($files as $file) {
echo "<li>", $file->RelativePath;
$file->ParentID = $newParent->ID;
echo " -> ", $file->RelativePath;
}
}
}
示例14: getReportFolder
/**
* Gets the report folder needed for storing the report files
*
* @param String $format
*/
protected function getReportFolder()
{
$id = $this->ReportID;
if (!$id) {
$id = 'preview';
}
$folderName = 'advanced-reports/' . $this->ReportID . '/' . $this->ID;
return Folder::findOrMake($folderName);
}
示例15: createThumbnail
private function createThumbnail()
{
$img_title = "flv_thumb_" . $this->ID;
if ($existing = DataObject::get("Image", "Title = '{$img_title}'")) {
foreach ($existing as $file) {
$file->delete();
}
}
$folder = Folder::findOrMake(self::$thumbnail_folder);
$img_filename = self::clean_file(self::remove_file_extension($this->Title)) . ".jpg";
$abs_thumb = Director::baseFolder() . "/" . $folder->Filename . $img_filename;
$args = sprintf("-y -i %s -an -s %s -ss %d -an -r 1 -vframes 1 -y -vcodec mjpeg -f mjpeg %s", $this->absoluteFLVPath(), self::$default_thumbnail_width . "x" . self::$default_thumbnail_height, self::$thumbnail_seconds, $abs_thumb);
self::ffmpeg($args);
$img = new Image();
$img->setField('ParentID', $folder->ID);
$img->Filename = $folder->Filename . $img_filename;
$img->Title = $img_title;
$img->write();
}