本文整理汇总了PHP中Folder::find_or_make方法的典型用法代码示例。如果您正苦于以下问题:PHP Folder::find_or_make方法的具体用法?PHP Folder::find_or_make怎么用?PHP Folder::find_or_make使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Folder
的用法示例。
在下文中一共展示了Folder::find_or_make方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
function index()
{
$posts = $this->request->postVars();
$filename = $posts['filename'];
$surveyID = intval($posts['surveyID']);
if (!$filename || !Member::currentUser() || !$surveyID || !($Survey = Survey::get()->filter('ID', $surveyID)->first())) {
return false;
}
$folder = Folder::find_or_make('jsonFormFiles');
$fullFileName = Director::baseFolder() . '/' . $folder->getRelativePath() . $filename . '.json';
$jsonString = '{"name":"' . $Survey->Name . '","startDate": "' . $Survey->StartDate . '", "endDate": "' . $Survey->EndDate . '","sections": [';
foreach ($Survey->Sections() as $Section) {
$jsonString .= '{"Title": "' . $Section->Title . '","Descripton": "' . $Section->Description . '","sectionQuestions": [';
foreach ($Section->SurveyQuestions() as $SQ) {
$jsonString .= '{"number": "' . $SQ->Number . '","title": "' . $SQ->Title . '","description":"' . $SQ->Description . '","helpText": "' . $SQ->HelpText . '","questions": [';
foreach ($SQ->Questions() as $Question) {
$jsonString .= $Question->renderJson();
}
$jsonString = rtrim($jsonString, ",");
$jsonString .= ']},';
}
$jsonString = rtrim($jsonString, ",");
$jsonString .= ']},';
}
$jsonString = rtrim($jsonString, ",");
$jsonString .= ']}';
file_put_contents($fullFileName, $jsonString);
$Survey->LastJsonGenerated = SS_Datetime::now()->getValue();
$Survey->write();
}
示例2: importMedia
protected function importMedia($item, $page)
{
$source = $item->getSource();
$params = $this->importer->getParams();
$folder = $params['AssetsPath'];
$content = $item->Content;
if ($folder) {
$folderId = Folder::find_or_make($folder)->ID;
}
$url = trim(preg_replace('~^[a-z]+://~', null, $source->BaseUrl), '/');
$pattern = sprintf('~[a-z]+://%s/wp-content/uploads/[^"]+~', $url);
if (!preg_match_all($pattern, $page->Content, $matches)) {
return;
}
foreach ($matches[0] as $match) {
if (!($contents = @file_get_contents($match))) {
continue;
}
$name = basename($match);
$path = Controller::join_links(ASSETS_PATH, $folder, $name);
$link = Controller::join_links(ASSETS_DIR, $folder, $name);
file_put_contents($path, $contents);
$page->Content = str_replace($match, $link, $page->Content);
}
Filesystem::sync($folderId);
$page->write();
}
开发者ID:helpfulrobot,项目名称:silverstripe-australia-wordpressconnector,代码行数:27,代码来源:WordpressPageTransformer.php
示例3: testCreateWithFilenameWithSubfolder
public 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::find_or_make('/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->assertInstanceOf('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->assertInstanceOf('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);
}
示例4: squareImage
public function squareImage()
{
Folder::find_or_make(Director::baseFolder() . '/assets/ytimages');
if (!file_exists(Director::baseFolder() . '/assets/ytimages/' . $this->Code . '.png')) {
//Your Image
$imgSrc = "http://img.youtube.com/vi/{$this->Code}/hqdefault.jpg";
//getting the image dimensions
list($width, $height) = getimagesize($imgSrc);
//saving the image into memory (for manipulation with GD Library)
$myImage = imagecreatefromjpeg($imgSrc);
// calculating the part of the image to use for thumbnail
if ($width > $height) {
$y = 0;
$x = ($width - $height) / 2;
$smallestSide = $height;
} else {
$x = 0;
$y = ($height - $width) / 2;
$smallestSide = $width;
}
// copying the part into thumbnail
$thumbSize = 120;
$thumb = imagecreatetruecolor($thumbSize, $thumbSize);
imagecopyresampled($thumb, $myImage, 0, 0, $x, $y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);
imagepng($thumb, Director::baseFolder() . '/assets/ytimages/' . $this->Code . '.png');
}
return '/assets/ytimages/' . $this->Code . '.png';
}
示例5: readFolder
public function readFolder($folder = "")
{
$folderPath = ASSETS_PATH . '/' . $folder;
if (!file_exists($folderPath)) {
$this->httpError(404);
}
return Folder::find_or_make(str_replace(ASSETS_DIR, "", $folderPath));
}
示例6: checkFolder
function checkFolder()
{
// Ensure the album folder exists
if (!(($folder = $this->Folder()) && $folder->exists()) && $this->URLSegment && (($page = $this->ImageGalleryPage()) && $page->exists()) && (($rootFolder = $page->RootFolder()) && $rootFolder->exists())) {
$folder = Folder::find_or_make("image-gallery/{$rootFolder->Name}/{$this->URLSegment}");
$this->FolderID = $folder->ID;
}
}
示例7: checkFolder
function checkFolder()
{
// Ensure root folder exists, but avoid saving folders like "new-image-gallery-page"
if ($this->exists() && !(($folder = $this->RootFolder()) && $folder->exists()) && $this->URLSegment) {
$folder = Folder::find_or_make("image-gallery/{$this->URLSegment}");
$this->RootFolderID = $folder->ID;
}
}
示例8: setFolderName
/**
* Specify the pdf location
*
* @param string $folder The name of the desired folder. Creates a new one if folder doesn't exist.
*/
public function setFolderName($folder = null)
{
if ($folder) {
$folder = Folder::find_or_make($folder);
$this->folderID = $folder->ID;
$folder = str_replace('/assets/', '', $folder->Url);
$this->folder = rtrim($this->folder . $folder, '/') . '/';
}
}
示例9: updateCMSFields
public function updateCMSFields(\FieldList $oFields)
{
Folder::find_or_make('responsive-gallery');
$aGalleryImagesFields = array();
if ($this->owner->ID > 0) {
$oFields->addFieldsToTab('Root.' . _t('ResponsiveGalleryExtension.GALLERYIMAGES_TAB', 'Gallery Images'), $this->getFieldsForImagesTab());
$oFields->addFieldsToTab('Root.' . _t('ResponsiveGalleryExtension.GALLERYSETTINGS_TAB', 'Gallery Settings'), $this->getFieldsForSettingsTab());
}
}
示例10: __construct
/**
* sets up base file and folder ready for file generating
* @param $filename
*/
public function __construct($filename)
{
$folder = Folder::find_or_make('/ics-files/' . $filename);
$this->fileName = strtolower($filename);
$this->fileObject = new File();
$this->fileObject->SetName($this->fileName . ".ics");
$this->fileObject->setParentID($folder->ID);
$this->fileObject->write();
$this->filePath = $this->fileObject->getFullPath();
}
示例11: setUp
public function setUp()
{
parent::setUp();
$this->folder = Folder::find_or_make(ASSETS_DIR . '/versionedfiles-test');
$file = $this->folder->getFullPath() . 'test-file.txt';
file_put_contents($file, 'first-version');
$this->file = new File();
$this->file->ParentID = $this->folder->ID;
$this->file->Filename = $this->folder->getFilename() . 'test-file.txt';
$this->file->write();
SecurityToken::disable();
}
示例12: file2FolderFilename
protected function file2FolderFilename($filename, $withoutBase = false)
{
if (self::$save_pdfs_here) {
$folder = Director::baseFolder() . "/" . self::$save_pdfs_here . "/";
$folderObject = Folder::find_or_make($folder);
if ($withoutBase) {
$folderFilename = $folderObject->getRelativePath() . $filename;
} else {
$folderFilename = $folderObject->getFullPath() . $filename;
}
return $folderFilename;
}
}
示例13: 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.
*/
public function load($tmpFile, $folderPath = false)
{
if (!$folderPath) {
$folderPath = Config::inst()->get('Upload', 'uploads_folder');
}
// @TODO This puts a HUGE limitation on files especially when lots
// have been uploaded.
$base = Director::baseFolder();
$parentFolder = Folder::find_or_make($folderPath);
// Generate default filename
$fileArray = explode('/', $tmpFile);
$fileName = $fileArray[count($fileArray) - 1];
$nameFilter = FileNameFilter::create();
$file = $nameFilter->filter($fileName);
$fileName = basename($file);
$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 = preg_replace('/[0-9]*(\\.tar\\.[^.]+$)/', $i . '\\1', $relativeFilePath);
} else {
if (strpos($relativeFilePath, '.') !== false) {
$relativeFilePath = preg_replace('/[0-9]*(\\.[^.]+$)/', $i . '\\1', $relativeFilePath);
} else {
if (strpos($relativeFilePath, '_') !== false) {
$relativeFilePath = preg_replace('/_([^_]+$)/', '_' . $i, $relativeFilePath);
} else {
$relativeFilePath .= '_' . $i;
}
}
}
if ($oldFilePath == $relativeFilePath && $i > 2) {
user_error("Couldn't fix {$relativeFilePath} with {$i} tries", E_USER_ERROR);
}
}
if (file_exists($tmpFile) && copy($tmpFile, $base . "/" . $relativeFilePath)) {
$this->owner->ParentID = $parentFolder->ID;
// This is to prevent it from trying to rename the file
$this->owner->Name = basename($relativeFilePath);
$this->owner->write();
return true;
} else {
return false;
}
}
示例14: findOrMakeAssetsFolder
/**
* Find or make assets folder
* called from onBeforeWrite.
*
* @param string $url
* @param bool $doWrite
*
* @return Folder|null
*/
public function findOrMakeAssetsFolder($url, $doWrite = true)
{
$owner = $this->owner;
$dir = Folder::find_or_make($url);
$owner->AssetsFolderID = $dir->ID;
if ($doWrite) {
$owner->write();
}
//Special case for when creating a new subsite
//the directory will need to be associated with the subsite
if ($owner->ClassName == 'Subsite') {
$dir->SubsiteID = $owner->ID;
$dir->write();
}
return $dir;
}
示例15: run
/**
* Implement this method in the task subclass to
* execute via the TaskRunner
*/
public function run($request)
{
$currentSite = Multisites::inst()->getCurrentSite();
$folderName = $currentSite->Host ? $currentSite->Host : "site-{$currentSite->ID}";
$folder = Folder::find_or_make($folderName);
$files = File::get()->filter('ParentID', array(0))->exclude('ID', $folder->ID);
if (!$files->count()) {
return;
}
foreach ($files as $file) {
if (file_exists($file->getFullPath())) {
$file->ParentID = $folder->ID;
$file->write();
echo $file->Filename . ' moved <br />';
}
}
}
开发者ID:helpfulrobot,项目名称:sheadawson-silverstripe-multisites,代码行数:21,代码来源:MultisitesInitAssetsTask.php