repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
concrete5/concrete5 | concrete/src/File/Importer.php | Importer.import | public function import($pointer, $filename = false, $fr = false, $prefix = null)
{
$fh = $this->app->make('helper/validation/file');
$fi = $this->app->make('helper/file');
$cf = $this->app->make('helper/concrete/file');
$filename = (string) $filename;
if ($filename === '') {
// determine filename from $pointer
$filename = basename($pointer);
}
$sanitizedFilename = $fi->sanitize($filename);
// test if file is valid, else return FileImporter::E_FILE_INVALID
if (!$fh->file($pointer)) {
return self::E_FILE_INVALID;
}
if (!$fh->extension($filename)) {
return self::E_FILE_INVALID_EXTENSION;
}
if ($fr instanceof FileEntity) {
$fsl = $fr->getFileStorageLocationObject();
} else {
$fsl = $this->app->make(StorageLocationFactory::class)->fetchDefault();
}
if (!($fsl instanceof StorageLocation)) {
return self::E_FILE_INVALID_STORAGE_LOCATION;
}
// store the file in the file storage location.
$filesystem = $fsl->getFileSystemObject();
if ($prefix) {
$prefixIsAutoGenerated = false;
} else {
// note, if you pass in a prefix manually, make sure it conforms to standards
// (e.g. it is 12 digits, numeric only)
$prefix = $this->generatePrefix();
$prefixIsAutoGenerated = true;
}
$src = @fopen($pointer, 'rb');
if ($src === false) {
return self::E_FILE_INVALID;
}
try {
$filesystem->writeStream(
$cf->prefix($prefix, $sanitizedFilename),
$src,
[
'visibility' => AdapterInterface::VISIBILITY_PUBLIC,
'mimetype' => $this->app->make('helper/mime')->mimeFromExtension($fi->getExtension($sanitizedFilename)),
]
);
} catch (Exception $e) {
if (!$prefixIsAutoGenerated) {
return self::E_FILE_UNABLE_TO_STORE_PREFIX_PROVIDED;
} else {
return self::E_FILE_UNABLE_TO_STORE;
}
} finally {
@fclose($src);
}
if (!($fr instanceof FileEntity)) {
// we have to create a new file object for this file version
$fv = File::add($sanitizedFilename, $prefix, ['fvTitle' => $filename], $fsl, $fr);
} else {
// We get a new version to modify
$fv = $fr->getVersionToModify(true);
$fv->updateFile($sanitizedFilename, $prefix);
}
$fv->refreshAttributes(false);
foreach ($this->importProcessors as $processor) {
if ($processor->shouldProcess($fv)) {
$processor->process($fv);
}
}
if ($this->rescanThumbnailsOnImport) {
$fv->refreshThumbnails(true);
}
$fv->releaseImagineImage();
return $fv;
} | php | public function import($pointer, $filename = false, $fr = false, $prefix = null)
{
$fh = $this->app->make('helper/validation/file');
$fi = $this->app->make('helper/file');
$cf = $this->app->make('helper/concrete/file');
$filename = (string) $filename;
if ($filename === '') {
// determine filename from $pointer
$filename = basename($pointer);
}
$sanitizedFilename = $fi->sanitize($filename);
// test if file is valid, else return FileImporter::E_FILE_INVALID
if (!$fh->file($pointer)) {
return self::E_FILE_INVALID;
}
if (!$fh->extension($filename)) {
return self::E_FILE_INVALID_EXTENSION;
}
if ($fr instanceof FileEntity) {
$fsl = $fr->getFileStorageLocationObject();
} else {
$fsl = $this->app->make(StorageLocationFactory::class)->fetchDefault();
}
if (!($fsl instanceof StorageLocation)) {
return self::E_FILE_INVALID_STORAGE_LOCATION;
}
// store the file in the file storage location.
$filesystem = $fsl->getFileSystemObject();
if ($prefix) {
$prefixIsAutoGenerated = false;
} else {
// note, if you pass in a prefix manually, make sure it conforms to standards
// (e.g. it is 12 digits, numeric only)
$prefix = $this->generatePrefix();
$prefixIsAutoGenerated = true;
}
$src = @fopen($pointer, 'rb');
if ($src === false) {
return self::E_FILE_INVALID;
}
try {
$filesystem->writeStream(
$cf->prefix($prefix, $sanitizedFilename),
$src,
[
'visibility' => AdapterInterface::VISIBILITY_PUBLIC,
'mimetype' => $this->app->make('helper/mime')->mimeFromExtension($fi->getExtension($sanitizedFilename)),
]
);
} catch (Exception $e) {
if (!$prefixIsAutoGenerated) {
return self::E_FILE_UNABLE_TO_STORE_PREFIX_PROVIDED;
} else {
return self::E_FILE_UNABLE_TO_STORE;
}
} finally {
@fclose($src);
}
if (!($fr instanceof FileEntity)) {
// we have to create a new file object for this file version
$fv = File::add($sanitizedFilename, $prefix, ['fvTitle' => $filename], $fsl, $fr);
} else {
// We get a new version to modify
$fv = $fr->getVersionToModify(true);
$fv->updateFile($sanitizedFilename, $prefix);
}
$fv->refreshAttributes(false);
foreach ($this->importProcessors as $processor) {
if ($processor->shouldProcess($fv)) {
$processor->process($fv);
}
}
if ($this->rescanThumbnailsOnImport) {
$fv->refreshThumbnails(true);
}
$fv->releaseImagineImage();
return $fv;
} | [
"public",
"function",
"import",
"(",
"$",
"pointer",
",",
"$",
"filename",
"=",
"false",
",",
"$",
"fr",
"=",
"false",
",",
"$",
"prefix",
"=",
"null",
")",
"{",
"$",
"fh",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'helper/validation/file'",
")",
";",
"$",
"fi",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'helper/file'",
")",
";",
"$",
"cf",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'helper/concrete/file'",
")",
";",
"$",
"filename",
"=",
"(",
"string",
")",
"$",
"filename",
";",
"if",
"(",
"$",
"filename",
"===",
"''",
")",
"{",
"// determine filename from $pointer",
"$",
"filename",
"=",
"basename",
"(",
"$",
"pointer",
")",
";",
"}",
"$",
"sanitizedFilename",
"=",
"$",
"fi",
"->",
"sanitize",
"(",
"$",
"filename",
")",
";",
"// test if file is valid, else return FileImporter::E_FILE_INVALID",
"if",
"(",
"!",
"$",
"fh",
"->",
"file",
"(",
"$",
"pointer",
")",
")",
"{",
"return",
"self",
"::",
"E_FILE_INVALID",
";",
"}",
"if",
"(",
"!",
"$",
"fh",
"->",
"extension",
"(",
"$",
"filename",
")",
")",
"{",
"return",
"self",
"::",
"E_FILE_INVALID_EXTENSION",
";",
"}",
"if",
"(",
"$",
"fr",
"instanceof",
"FileEntity",
")",
"{",
"$",
"fsl",
"=",
"$",
"fr",
"->",
"getFileStorageLocationObject",
"(",
")",
";",
"}",
"else",
"{",
"$",
"fsl",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"StorageLocationFactory",
"::",
"class",
")",
"->",
"fetchDefault",
"(",
")",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"fsl",
"instanceof",
"StorageLocation",
")",
")",
"{",
"return",
"self",
"::",
"E_FILE_INVALID_STORAGE_LOCATION",
";",
"}",
"// store the file in the file storage location.",
"$",
"filesystem",
"=",
"$",
"fsl",
"->",
"getFileSystemObject",
"(",
")",
";",
"if",
"(",
"$",
"prefix",
")",
"{",
"$",
"prefixIsAutoGenerated",
"=",
"false",
";",
"}",
"else",
"{",
"// note, if you pass in a prefix manually, make sure it conforms to standards",
"// (e.g. it is 12 digits, numeric only)",
"$",
"prefix",
"=",
"$",
"this",
"->",
"generatePrefix",
"(",
")",
";",
"$",
"prefixIsAutoGenerated",
"=",
"true",
";",
"}",
"$",
"src",
"=",
"@",
"fopen",
"(",
"$",
"pointer",
",",
"'rb'",
")",
";",
"if",
"(",
"$",
"src",
"===",
"false",
")",
"{",
"return",
"self",
"::",
"E_FILE_INVALID",
";",
"}",
"try",
"{",
"$",
"filesystem",
"->",
"writeStream",
"(",
"$",
"cf",
"->",
"prefix",
"(",
"$",
"prefix",
",",
"$",
"sanitizedFilename",
")",
",",
"$",
"src",
",",
"[",
"'visibility'",
"=>",
"AdapterInterface",
"::",
"VISIBILITY_PUBLIC",
",",
"'mimetype'",
"=>",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'helper/mime'",
")",
"->",
"mimeFromExtension",
"(",
"$",
"fi",
"->",
"getExtension",
"(",
"$",
"sanitizedFilename",
")",
")",
",",
"]",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"!",
"$",
"prefixIsAutoGenerated",
")",
"{",
"return",
"self",
"::",
"E_FILE_UNABLE_TO_STORE_PREFIX_PROVIDED",
";",
"}",
"else",
"{",
"return",
"self",
"::",
"E_FILE_UNABLE_TO_STORE",
";",
"}",
"}",
"finally",
"{",
"@",
"fclose",
"(",
"$",
"src",
")",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"fr",
"instanceof",
"FileEntity",
")",
")",
"{",
"// we have to create a new file object for this file version",
"$",
"fv",
"=",
"File",
"::",
"add",
"(",
"$",
"sanitizedFilename",
",",
"$",
"prefix",
",",
"[",
"'fvTitle'",
"=>",
"$",
"filename",
"]",
",",
"$",
"fsl",
",",
"$",
"fr",
")",
";",
"}",
"else",
"{",
"// We get a new version to modify",
"$",
"fv",
"=",
"$",
"fr",
"->",
"getVersionToModify",
"(",
"true",
")",
";",
"$",
"fv",
"->",
"updateFile",
"(",
"$",
"sanitizedFilename",
",",
"$",
"prefix",
")",
";",
"}",
"$",
"fv",
"->",
"refreshAttributes",
"(",
"false",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"importProcessors",
"as",
"$",
"processor",
")",
"{",
"if",
"(",
"$",
"processor",
"->",
"shouldProcess",
"(",
"$",
"fv",
")",
")",
"{",
"$",
"processor",
"->",
"process",
"(",
"$",
"fv",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"rescanThumbnailsOnImport",
")",
"{",
"$",
"fv",
"->",
"refreshThumbnails",
"(",
"true",
")",
";",
"}",
"$",
"fv",
"->",
"releaseImagineImage",
"(",
")",
";",
"return",
"$",
"fv",
";",
"}"
] | Imports a local file into the system.
@param string $pointer The path to the file
@param string|bool $filename A custom name to give to the file. If not specified, we'll derive it from $pointer.
@param \Concrete\Core\Entity\File\File|\Concrete\Core\Tree\Node\Type\FileFolder|null|false $fr If it's a File entity we assign the newly imported FileVersion object to that File. If it's a FileFolder entiity we'll create a new File in that folder (otherwise the new File will be created in the root folder).
@param string|null $prefix the prefix to be used to store the file (if empty we'll generate a new prefix)
@return \Concrete\Core\Entity\File\Version|int the imported file version (or an error code in case of problems) | [
"Imports",
"a",
"local",
"file",
"into",
"the",
"system",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Importer.php#L251-L338 | train |
concrete5/concrete5 | concrete/src/File/Importer.php | Importer.importIncomingFile | public function importIncomingFile($filename, $fr = false)
{
$fh = $this->app->make('helper/validation/file');
if (!$fh->extension($filename)) {
return self::E_FILE_INVALID_EXTENSION;
}
$incoming = $this->app->make(Incoming::class);
$incomingStorageLocation = $incoming->getIncomingStorageLocation();
$incomingFilesystem = $incomingStorageLocation->getFileSystemObject();
$incomingPath = $incoming->getIncomingPath();
if (!$incomingFilesystem->has($incomingPath . '/' . $filename)) {
return self::E_FILE_INVALID;
}
if ($fr instanceof FileEntity) {
$destinationStorageLocation = $fr->getFileStorageLocationObject();
} else {
$destinationStorageLocation = $this->app->make(StorageLocationFactory::class)->fetchDefault();
}
$destinationFilesystem = $destinationStorageLocation->getFileSystemObject();
$prefix = $this->generatePrefix();
$fi = $this->app->make('helper/file');
$sanitizedFilename = $fi->sanitize($filename);
$cf = $this->app->make('helper/concrete/file');
$destinationPath = $cf->prefix($prefix, $sanitizedFilename);
try {
$stream = $incomingFilesystem->readStream($incomingPath . '/' . $filename);
} catch (Exception $x) {
$stream = false;
}
if ($stream === false) {
return self::E_FILE_INVALID;
}
try {
$wrote = $destinationFilesystem->writeStream($destinationPath, $stream);
} catch (Exception $x) {
$wrote = false;
}
@fclose($stream);
if ($wrote === false) {
return self::E_FILE_UNABLE_TO_STORE;
}
if (!($fr instanceof FileEntity)) {
// we have to create a new file object for this file version
$fv = File::add($sanitizedFilename, $prefix, ['fvTitle' => $filename], $destinationStorageLocation, $fr);
$fv->refreshAttributes($this->rescanThumbnailsOnImport);
foreach ($this->importProcessors as $processor) {
if ($processor->shouldProcess($fv)) {
$processor->process($fv);
}
}
} else {
// We get a new version to modify
$fv = $fr->getVersionToModify(true);
$fv->updateFile($sanitizedFilename, $prefix);
$fv->refreshAttributes($this->rescanThumbnailsOnImport);
}
return $fv;
} | php | public function importIncomingFile($filename, $fr = false)
{
$fh = $this->app->make('helper/validation/file');
if (!$fh->extension($filename)) {
return self::E_FILE_INVALID_EXTENSION;
}
$incoming = $this->app->make(Incoming::class);
$incomingStorageLocation = $incoming->getIncomingStorageLocation();
$incomingFilesystem = $incomingStorageLocation->getFileSystemObject();
$incomingPath = $incoming->getIncomingPath();
if (!$incomingFilesystem->has($incomingPath . '/' . $filename)) {
return self::E_FILE_INVALID;
}
if ($fr instanceof FileEntity) {
$destinationStorageLocation = $fr->getFileStorageLocationObject();
} else {
$destinationStorageLocation = $this->app->make(StorageLocationFactory::class)->fetchDefault();
}
$destinationFilesystem = $destinationStorageLocation->getFileSystemObject();
$prefix = $this->generatePrefix();
$fi = $this->app->make('helper/file');
$sanitizedFilename = $fi->sanitize($filename);
$cf = $this->app->make('helper/concrete/file');
$destinationPath = $cf->prefix($prefix, $sanitizedFilename);
try {
$stream = $incomingFilesystem->readStream($incomingPath . '/' . $filename);
} catch (Exception $x) {
$stream = false;
}
if ($stream === false) {
return self::E_FILE_INVALID;
}
try {
$wrote = $destinationFilesystem->writeStream($destinationPath, $stream);
} catch (Exception $x) {
$wrote = false;
}
@fclose($stream);
if ($wrote === false) {
return self::E_FILE_UNABLE_TO_STORE;
}
if (!($fr instanceof FileEntity)) {
// we have to create a new file object for this file version
$fv = File::add($sanitizedFilename, $prefix, ['fvTitle' => $filename], $destinationStorageLocation, $fr);
$fv->refreshAttributes($this->rescanThumbnailsOnImport);
foreach ($this->importProcessors as $processor) {
if ($processor->shouldProcess($fv)) {
$processor->process($fv);
}
}
} else {
// We get a new version to modify
$fv = $fr->getVersionToModify(true);
$fv->updateFile($sanitizedFilename, $prefix);
$fv->refreshAttributes($this->rescanThumbnailsOnImport);
}
return $fv;
} | [
"public",
"function",
"importIncomingFile",
"(",
"$",
"filename",
",",
"$",
"fr",
"=",
"false",
")",
"{",
"$",
"fh",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'helper/validation/file'",
")",
";",
"if",
"(",
"!",
"$",
"fh",
"->",
"extension",
"(",
"$",
"filename",
")",
")",
"{",
"return",
"self",
"::",
"E_FILE_INVALID_EXTENSION",
";",
"}",
"$",
"incoming",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"Incoming",
"::",
"class",
")",
";",
"$",
"incomingStorageLocation",
"=",
"$",
"incoming",
"->",
"getIncomingStorageLocation",
"(",
")",
";",
"$",
"incomingFilesystem",
"=",
"$",
"incomingStorageLocation",
"->",
"getFileSystemObject",
"(",
")",
";",
"$",
"incomingPath",
"=",
"$",
"incoming",
"->",
"getIncomingPath",
"(",
")",
";",
"if",
"(",
"!",
"$",
"incomingFilesystem",
"->",
"has",
"(",
"$",
"incomingPath",
".",
"'/'",
".",
"$",
"filename",
")",
")",
"{",
"return",
"self",
"::",
"E_FILE_INVALID",
";",
"}",
"if",
"(",
"$",
"fr",
"instanceof",
"FileEntity",
")",
"{",
"$",
"destinationStorageLocation",
"=",
"$",
"fr",
"->",
"getFileStorageLocationObject",
"(",
")",
";",
"}",
"else",
"{",
"$",
"destinationStorageLocation",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"StorageLocationFactory",
"::",
"class",
")",
"->",
"fetchDefault",
"(",
")",
";",
"}",
"$",
"destinationFilesystem",
"=",
"$",
"destinationStorageLocation",
"->",
"getFileSystemObject",
"(",
")",
";",
"$",
"prefix",
"=",
"$",
"this",
"->",
"generatePrefix",
"(",
")",
";",
"$",
"fi",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'helper/file'",
")",
";",
"$",
"sanitizedFilename",
"=",
"$",
"fi",
"->",
"sanitize",
"(",
"$",
"filename",
")",
";",
"$",
"cf",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'helper/concrete/file'",
")",
";",
"$",
"destinationPath",
"=",
"$",
"cf",
"->",
"prefix",
"(",
"$",
"prefix",
",",
"$",
"sanitizedFilename",
")",
";",
"try",
"{",
"$",
"stream",
"=",
"$",
"incomingFilesystem",
"->",
"readStream",
"(",
"$",
"incomingPath",
".",
"'/'",
".",
"$",
"filename",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"x",
")",
"{",
"$",
"stream",
"=",
"false",
";",
"}",
"if",
"(",
"$",
"stream",
"===",
"false",
")",
"{",
"return",
"self",
"::",
"E_FILE_INVALID",
";",
"}",
"try",
"{",
"$",
"wrote",
"=",
"$",
"destinationFilesystem",
"->",
"writeStream",
"(",
"$",
"destinationPath",
",",
"$",
"stream",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"x",
")",
"{",
"$",
"wrote",
"=",
"false",
";",
"}",
"@",
"fclose",
"(",
"$",
"stream",
")",
";",
"if",
"(",
"$",
"wrote",
"===",
"false",
")",
"{",
"return",
"self",
"::",
"E_FILE_UNABLE_TO_STORE",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"fr",
"instanceof",
"FileEntity",
")",
")",
"{",
"// we have to create a new file object for this file version",
"$",
"fv",
"=",
"File",
"::",
"add",
"(",
"$",
"sanitizedFilename",
",",
"$",
"prefix",
",",
"[",
"'fvTitle'",
"=>",
"$",
"filename",
"]",
",",
"$",
"destinationStorageLocation",
",",
"$",
"fr",
")",
";",
"$",
"fv",
"->",
"refreshAttributes",
"(",
"$",
"this",
"->",
"rescanThumbnailsOnImport",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"importProcessors",
"as",
"$",
"processor",
")",
"{",
"if",
"(",
"$",
"processor",
"->",
"shouldProcess",
"(",
"$",
"fv",
")",
")",
"{",
"$",
"processor",
"->",
"process",
"(",
"$",
"fv",
")",
";",
"}",
"}",
"}",
"else",
"{",
"// We get a new version to modify",
"$",
"fv",
"=",
"$",
"fr",
"->",
"getVersionToModify",
"(",
"true",
")",
";",
"$",
"fv",
"->",
"updateFile",
"(",
"$",
"sanitizedFilename",
",",
"$",
"prefix",
")",
";",
"$",
"fv",
"->",
"refreshAttributes",
"(",
"$",
"this",
"->",
"rescanThumbnailsOnImport",
")",
";",
"}",
"return",
"$",
"fv",
";",
"}"
] | Import a file in the default file storage location's incoming directory.
@param string $filename the name of the file in the incoming directory
@param \Concrete\Core\Entity\File\File|\Concrete\Core\Tree\Node\Type\FileFolder|null|false $fr If it's a File entity we assign the newly imported FileVersion object to that File. If it's a FileFolder entiity we'll create a new File in that folder (otherwise the new File will be created in the root folder).
@return \Concrete\Core\Entity\File\Version|int the imported file version (or an error code in case of problems) | [
"Import",
"a",
"file",
"in",
"the",
"default",
"file",
"storage",
"location",
"s",
"incoming",
"directory",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Importer.php#L348-L407 | train |
concrete5/concrete5 | concrete/src/File/Importer.php | Importer.importUploadedFile | public function importUploadedFile(UploadedFile $uploadedFile = null, $fr = false)
{
if ($uploadedFile === null) {
$result = self::E_PHP_NO_FILE;
} elseif (!$uploadedFile->isValid()) {
$result = $uploadedFile->getError();
} else {
$result = $this->import($uploadedFile->getPathname(), $uploadedFile->getClientOriginalName(), $fr);
}
return $result;
} | php | public function importUploadedFile(UploadedFile $uploadedFile = null, $fr = false)
{
if ($uploadedFile === null) {
$result = self::E_PHP_NO_FILE;
} elseif (!$uploadedFile->isValid()) {
$result = $uploadedFile->getError();
} else {
$result = $this->import($uploadedFile->getPathname(), $uploadedFile->getClientOriginalName(), $fr);
}
return $result;
} | [
"public",
"function",
"importUploadedFile",
"(",
"UploadedFile",
"$",
"uploadedFile",
"=",
"null",
",",
"$",
"fr",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"uploadedFile",
"===",
"null",
")",
"{",
"$",
"result",
"=",
"self",
"::",
"E_PHP_NO_FILE",
";",
"}",
"elseif",
"(",
"!",
"$",
"uploadedFile",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"result",
"=",
"$",
"uploadedFile",
"->",
"getError",
"(",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"import",
"(",
"$",
"uploadedFile",
"->",
"getPathname",
"(",
")",
",",
"$",
"uploadedFile",
"->",
"getClientOriginalName",
"(",
")",
",",
"$",
"fr",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Import a file received via a POST request to the default file storage location.
@param \Symfony\Component\HttpFoundation\File\UploadedFile $uploadedFile The uploaded file
@param \Concrete\Core\Entity\File\File|\Concrete\Core\Tree\Node\Type\FileFolder|null|false $fr If it's a File entity we assign the newly imported FileVersion object to that File. If it's a FileFolder entiity we'll create a new File in that folder (otherwise the new File will be created in the root folder).
@return \Concrete\Core\Entity\File\Version|int the imported file version (or an error code in case of problems)
@example
<pre><code>
$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication();
$request = $app->make(\Concrete\Core\Http\Request::class);
$importer = $app->make(\Concrete\Core\File\Importer::class);
$fv = $importer->importUploadedFile($request->files->get('field_name'));
if (is_int($fv)) {
$errorToShow = $importer->getErrorMessage($fv);
}
</code></pre> | [
"Import",
"a",
"file",
"received",
"via",
"a",
"POST",
"request",
"to",
"the",
"default",
"file",
"storage",
"location",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Importer.php#L428-L439 | train |
concrete5/concrete5 | concrete/src/File/Image/Thumbnail/ThumbnailFormatService.php | ThumbnailFormatService.getConfiguredFormat | protected function getConfiguredFormat()
{
$format = $this->config->get('concrete.misc.default_thumbnail_format');
if ($format === static::FORMAT_AUTO || $this->bitmapFormat->isFormatValid($format)) {
$result = $format;
} elseif ($format === 'jpg') { // legacy value
$result = BitmapFormat::FORMAT_JPEG;
} else {
$result = static::FORMAT_AUTO;
}
return $result;
} | php | protected function getConfiguredFormat()
{
$format = $this->config->get('concrete.misc.default_thumbnail_format');
if ($format === static::FORMAT_AUTO || $this->bitmapFormat->isFormatValid($format)) {
$result = $format;
} elseif ($format === 'jpg') { // legacy value
$result = BitmapFormat::FORMAT_JPEG;
} else {
$result = static::FORMAT_AUTO;
}
return $result;
} | [
"protected",
"function",
"getConfiguredFormat",
"(",
")",
"{",
"$",
"format",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'concrete.misc.default_thumbnail_format'",
")",
";",
"if",
"(",
"$",
"format",
"===",
"static",
"::",
"FORMAT_AUTO",
"||",
"$",
"this",
"->",
"bitmapFormat",
"->",
"isFormatValid",
"(",
"$",
"format",
")",
")",
"{",
"$",
"result",
"=",
"$",
"format",
";",
"}",
"elseif",
"(",
"$",
"format",
"===",
"'jpg'",
")",
"{",
"// legacy value",
"$",
"result",
"=",
"BitmapFormat",
"::",
"FORMAT_JPEG",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"static",
"::",
"FORMAT_AUTO",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get the configured format.
@return string One of the \Concrete\Core\File\Image\BitmapFormat::FORMAT_... constants, or ThumbnailFormatService::FORMAT_AUTO | [
"Get",
"the",
"configured",
"format",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Thumbnail/ThumbnailFormatService.php#L129-L141 | train |
concrete5/concrete5 | concrete/src/File/Type/TypeList.php | TypeList.define | public function define($extension, $name, $type, $customImporter = '', $inlineFileViewer = '', $editor = '', $pkgHandle = '')
{
$ext = explode(',', $extension);
foreach ($ext as $e) {
$this->types[strtolower($e)] = (new FileType())
->setName($name)
->setExtension($e)
->setCustomImporter($customImporter)
->setEditor($editor)
->setGenericType($type)
->setView($inlineFileViewer)
->setPackageHandle($pkgHandle);
}
} | php | public function define($extension, $name, $type, $customImporter = '', $inlineFileViewer = '', $editor = '', $pkgHandle = '')
{
$ext = explode(',', $extension);
foreach ($ext as $e) {
$this->types[strtolower($e)] = (new FileType())
->setName($name)
->setExtension($e)
->setCustomImporter($customImporter)
->setEditor($editor)
->setGenericType($type)
->setView($inlineFileViewer)
->setPackageHandle($pkgHandle);
}
} | [
"public",
"function",
"define",
"(",
"$",
"extension",
",",
"$",
"name",
",",
"$",
"type",
",",
"$",
"customImporter",
"=",
"''",
",",
"$",
"inlineFileViewer",
"=",
"''",
",",
"$",
"editor",
"=",
"''",
",",
"$",
"pkgHandle",
"=",
"''",
")",
"{",
"$",
"ext",
"=",
"explode",
"(",
"','",
",",
"$",
"extension",
")",
";",
"foreach",
"(",
"$",
"ext",
"as",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"types",
"[",
"strtolower",
"(",
"$",
"e",
")",
"]",
"=",
"(",
"new",
"FileType",
"(",
")",
")",
"->",
"setName",
"(",
"$",
"name",
")",
"->",
"setExtension",
"(",
"$",
"e",
")",
"->",
"setCustomImporter",
"(",
"$",
"customImporter",
")",
"->",
"setEditor",
"(",
"$",
"editor",
")",
"->",
"setGenericType",
"(",
"$",
"type",
")",
"->",
"setView",
"(",
"$",
"inlineFileViewer",
")",
"->",
"setPackageHandle",
"(",
"$",
"pkgHandle",
")",
";",
"}",
"}"
] | Register a file type.
@param string $extension Comma-separated list of file extensions (lower case and without leading dots)
@param string $name File type name
@param int $type Generic file type (one of the \Concrete\Core\File\Type\Type\Type::T_... constants)
@param string $customImporter The handle of the custom importer
@param string $inlineFileViewer The handle of the inline viewer
@param string $editor The hHandle of the editor
@param string $pkgHandle The handle of the owner package | [
"Register",
"a",
"file",
"type",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Type/TypeList.php#L50-L63 | train |
concrete5/concrete5 | concrete/src/File/Type/TypeList.php | TypeList.defineMultiple | public function defineMultiple(array $types)
{
foreach ($types as $type_name => $type_settings) {
array_splice($type_settings, 1, 0, $type_name);
call_user_func_array([$this, 'define'], $type_settings);
}
} | php | public function defineMultiple(array $types)
{
foreach ($types as $type_name => $type_settings) {
array_splice($type_settings, 1, 0, $type_name);
call_user_func_array([$this, 'define'], $type_settings);
}
} | [
"public",
"function",
"defineMultiple",
"(",
"array",
"$",
"types",
")",
"{",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type_name",
"=>",
"$",
"type_settings",
")",
"{",
"array_splice",
"(",
"$",
"type_settings",
",",
"1",
",",
"0",
",",
"$",
"type_name",
")",
";",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"'define'",
"]",
",",
"$",
"type_settings",
")",
";",
"}",
"}"
] | Register multiple file types.
@param array $types Keys are the type names, values are the other parameters accepted by the define() method | [
"Register",
"multiple",
"file",
"types",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Type/TypeList.php#L70-L77 | train |
concrete5/concrete5 | concrete/src/File/Type/TypeList.php | TypeList.getType | public static function getType($ext)
{
$ftl = static::getInstance();
if (strpos($ext, '.') !== false) {
// filename
$app = Application::getFacadeApplication();
$h = $app->make('helper/file');
$ext = $h->getExtension($ext);
}
$ext = strtolower($ext);
if (isset($ftl->types[$ext])) {
return $ftl->types[$ext];
} else {
$ft = new FileType(); // generic
return $ft;
}
} | php | public static function getType($ext)
{
$ftl = static::getInstance();
if (strpos($ext, '.') !== false) {
// filename
$app = Application::getFacadeApplication();
$h = $app->make('helper/file');
$ext = $h->getExtension($ext);
}
$ext = strtolower($ext);
if (isset($ftl->types[$ext])) {
return $ftl->types[$ext];
} else {
$ft = new FileType(); // generic
return $ft;
}
} | [
"public",
"static",
"function",
"getType",
"(",
"$",
"ext",
")",
"{",
"$",
"ftl",
"=",
"static",
"::",
"getInstance",
"(",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"ext",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"// filename",
"$",
"app",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"h",
"=",
"$",
"app",
"->",
"make",
"(",
"'helper/file'",
")",
";",
"$",
"ext",
"=",
"$",
"h",
"->",
"getExtension",
"(",
"$",
"ext",
")",
";",
"}",
"$",
"ext",
"=",
"strtolower",
"(",
"$",
"ext",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"ftl",
"->",
"types",
"[",
"$",
"ext",
"]",
")",
")",
"{",
"return",
"$",
"ftl",
"->",
"types",
"[",
"$",
"ext",
"]",
";",
"}",
"else",
"{",
"$",
"ft",
"=",
"new",
"FileType",
"(",
")",
";",
"// generic",
"return",
"$",
"ft",
";",
"}",
"}"
] | Can take an extension or a filename
Returns any registered information we have for the particular file type, based on its registration.
@return FileType | [
"Can",
"take",
"an",
"extension",
"or",
"a",
"filename",
"Returns",
"any",
"registered",
"information",
"we",
"have",
"for",
"the",
"particular",
"file",
"type",
"based",
"on",
"its",
"registration",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Type/TypeList.php#L115-L131 | train |
concrete5/concrete5 | concrete/src/Controller/AbstractController.php | AbstractController.getHelperObjects | public function getHelperObjects()
{
$helpers = [];
foreach ($this->helpers as $handle) {
$h = Core::make('helper/' . $handle);
$helpers[(str_replace('/', '_', $handle))] = $h;
}
return $helpers;
} | php | public function getHelperObjects()
{
$helpers = [];
foreach ($this->helpers as $handle) {
$h = Core::make('helper/' . $handle);
$helpers[(str_replace('/', '_', $handle))] = $h;
}
return $helpers;
} | [
"public",
"function",
"getHelperObjects",
"(",
")",
"{",
"$",
"helpers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"helpers",
"as",
"$",
"handle",
")",
"{",
"$",
"h",
"=",
"Core",
"::",
"make",
"(",
"'helper/'",
".",
"$",
"handle",
")",
";",
"$",
"helpers",
"[",
"(",
"str_replace",
"(",
"'/'",
",",
"'_'",
",",
"$",
"handle",
")",
")",
"]",
"=",
"$",
"h",
";",
"}",
"return",
"$",
"helpers",
";",
"}"
] | Get the the helpers that will be be automatically sent to Views as variables.
Array keys are the variable names, array values are the helper instances.
@return array | [
"Get",
"the",
"the",
"helpers",
"that",
"will",
"be",
"be",
"automatically",
"sent",
"to",
"Views",
"as",
"variables",
".",
"Array",
"keys",
"are",
"the",
"variable",
"names",
"array",
"values",
"are",
"the",
"helper",
"instances",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Controller/AbstractController.php#L158-L167 | train |
concrete5/concrete5 | concrete/src/Http/Middleware/MiddlewareStack.php | MiddlewareStack.getStack | private function getStack()
{
$processed = [];
foreach ($this->middlewareGenerator() as $middleware) {
$processed[] = $middleware;
}
$middleware = array_reverse($processed);
$stack = array_reduce($middleware, $this->getZipper(), $this->dispatcher);
return $stack;
} | php | private function getStack()
{
$processed = [];
foreach ($this->middlewareGenerator() as $middleware) {
$processed[] = $middleware;
}
$middleware = array_reverse($processed);
$stack = array_reduce($middleware, $this->getZipper(), $this->dispatcher);
return $stack;
} | [
"private",
"function",
"getStack",
"(",
")",
"{",
"$",
"processed",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"middlewareGenerator",
"(",
")",
"as",
"$",
"middleware",
")",
"{",
"$",
"processed",
"[",
"]",
"=",
"$",
"middleware",
";",
"}",
"$",
"middleware",
"=",
"array_reverse",
"(",
"$",
"processed",
")",
";",
"$",
"stack",
"=",
"array_reduce",
"(",
"$",
"middleware",
",",
"$",
"this",
"->",
"getZipper",
"(",
")",
",",
"$",
"this",
"->",
"dispatcher",
")",
";",
"return",
"$",
"stack",
";",
"}"
] | Reduce middleware into a stack of functions that each call the next
@return callable | [
"Reduce",
"middleware",
"into",
"a",
"stack",
"of",
"functions",
"that",
"each",
"call",
"the",
"next"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Http/Middleware/MiddlewareStack.php#L93-L105 | train |
concrete5/concrete5 | concrete/src/Http/Middleware/MiddlewareStack.php | MiddlewareStack.getZipper | private function getZipper()
{
$app = $this->app;
return function($last, MiddlewareInterface $middleware) use ($app) {
return $app->make(DelegateInterface::class, [$middleware, $last]);
};
} | php | private function getZipper()
{
$app = $this->app;
return function($last, MiddlewareInterface $middleware) use ($app) {
return $app->make(DelegateInterface::class, [$middleware, $last]);
};
} | [
"private",
"function",
"getZipper",
"(",
")",
"{",
"$",
"app",
"=",
"$",
"this",
"->",
"app",
";",
"return",
"function",
"(",
"$",
"last",
",",
"MiddlewareInterface",
"$",
"middleware",
")",
"use",
"(",
"$",
"app",
")",
"{",
"return",
"$",
"app",
"->",
"make",
"(",
"DelegateInterface",
"::",
"class",
",",
"[",
"$",
"middleware",
",",
"$",
"last",
"]",
")",
";",
"}",
";",
"}"
] | Get the function used to zip up the middleware
This function runs as part of the array_reduce routine and reduces the list of middlewares into a single delegate
@return callable | [
"Get",
"the",
"function",
"used",
"to",
"zip",
"up",
"the",
"middleware",
"This",
"function",
"runs",
"as",
"part",
"of",
"the",
"array_reduce",
"routine",
"and",
"reduces",
"the",
"list",
"of",
"middlewares",
"into",
"a",
"single",
"delegate"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Http/Middleware/MiddlewareStack.php#L112-L118 | train |
concrete5/concrete5 | concrete/src/Http/Middleware/MiddlewareStack.php | MiddlewareStack.middlewareGenerator | private function middlewareGenerator()
{
$middlewares = $this->middleware;
ksort($middlewares);
foreach ($middlewares as $priorityGroup) {
foreach ($priorityGroup as $middleware) {
yield $middleware;
}
}
} | php | private function middlewareGenerator()
{
$middlewares = $this->middleware;
ksort($middlewares);
foreach ($middlewares as $priorityGroup) {
foreach ($priorityGroup as $middleware) {
yield $middleware;
}
}
} | [
"private",
"function",
"middlewareGenerator",
"(",
")",
"{",
"$",
"middlewares",
"=",
"$",
"this",
"->",
"middleware",
";",
"ksort",
"(",
"$",
"middlewares",
")",
";",
"foreach",
"(",
"$",
"middlewares",
"as",
"$",
"priorityGroup",
")",
"{",
"foreach",
"(",
"$",
"priorityGroup",
"as",
"$",
"middleware",
")",
"{",
"yield",
"$",
"middleware",
";",
"}",
"}",
"}"
] | Get a generator that converts the stored priority array into a sorted flat list
@return \Generator | [
"Get",
"a",
"generator",
"that",
"converts",
"the",
"stored",
"priority",
"array",
"into",
"a",
"sorted",
"flat",
"list"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Http/Middleware/MiddlewareStack.php#L124-L134 | train |
concrete5/concrete5 | concrete/src/Localization/Localization.php | Localization.setActiveContext | public function setActiveContext($context)
{
$oldLocale = isset($this->activeContext) ? $this->contextLocales[$this->activeContext] : null;
$this->activeContext = $context;
if (!isset($this->contextLocales[$context])) {
$this->setContextLocale($context, static::BASE_LOCALE);
}
$newLocale = $this->contextLocales[$context];
if ($newLocale !== $oldLocale) {
$this->currentLocaleChanged($newLocale);
}
} | php | public function setActiveContext($context)
{
$oldLocale = isset($this->activeContext) ? $this->contextLocales[$this->activeContext] : null;
$this->activeContext = $context;
if (!isset($this->contextLocales[$context])) {
$this->setContextLocale($context, static::BASE_LOCALE);
}
$newLocale = $this->contextLocales[$context];
if ($newLocale !== $oldLocale) {
$this->currentLocaleChanged($newLocale);
}
} | [
"public",
"function",
"setActiveContext",
"(",
"$",
"context",
")",
"{",
"$",
"oldLocale",
"=",
"isset",
"(",
"$",
"this",
"->",
"activeContext",
")",
"?",
"$",
"this",
"->",
"contextLocales",
"[",
"$",
"this",
"->",
"activeContext",
"]",
":",
"null",
";",
"$",
"this",
"->",
"activeContext",
"=",
"$",
"context",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"contextLocales",
"[",
"$",
"context",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setContextLocale",
"(",
"$",
"context",
",",
"static",
"::",
"BASE_LOCALE",
")",
";",
"}",
"$",
"newLocale",
"=",
"$",
"this",
"->",
"contextLocales",
"[",
"$",
"context",
"]",
";",
"if",
"(",
"$",
"newLocale",
"!==",
"$",
"oldLocale",
")",
"{",
"$",
"this",
"->",
"currentLocaleChanged",
"(",
"$",
"newLocale",
")",
";",
"}",
"}"
] | Sets the active translation context.
@param string $context | [
"Sets",
"the",
"active",
"translation",
"context",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Localization.php#L129-L140 | train |
concrete5/concrete5 | concrete/src/Localization/Localization.php | Localization.pushActiveContext | public function pushActiveContext($newContext)
{
if ($this->activeContext !== null) {
$this->activeContextQueue[] = $this->activeContext;
}
$this->setActiveContext($newContext);
} | php | public function pushActiveContext($newContext)
{
if ($this->activeContext !== null) {
$this->activeContextQueue[] = $this->activeContext;
}
$this->setActiveContext($newContext);
} | [
"public",
"function",
"pushActiveContext",
"(",
"$",
"newContext",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"activeContext",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"activeContextQueue",
"[",
"]",
"=",
"$",
"this",
"->",
"activeContext",
";",
"}",
"$",
"this",
"->",
"setActiveContext",
"(",
"$",
"newContext",
")",
";",
"}"
] | Change the active translation context, but remember the previous one.
Useful when temporarily setting the translation context to something else than the original.
@param string $newContext The new translation context to activate (default contexts are defined by the Localization::CONTEXT_... constants).
@see Localization::popActiveContext()
@example
```php
$loc = \Localization::getInstance();
// Let's assume the current context is 'original_context'
$loc->pushActiveContext('new_context');
// Do what you want in context 'new_context'
$loc->popActiveContext();
// Now the context is 'original_context'
``` | [
"Change",
"the",
"active",
"translation",
"context",
"but",
"remember",
"the",
"previous",
"one",
".",
"Useful",
"when",
"temporarily",
"setting",
"the",
"translation",
"context",
"to",
"something",
"else",
"than",
"the",
"original",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Localization.php#L163-L169 | train |
concrete5/concrete5 | concrete/src/Localization/Localization.php | Localization.popActiveContext | public function popActiveContext()
{
if (!empty($this->activeContextQueue)) {
$oldContext = array_pop($this->activeContextQueue);
$this->setActiveContext($oldContext);
}
} | php | public function popActiveContext()
{
if (!empty($this->activeContextQueue)) {
$oldContext = array_pop($this->activeContextQueue);
$this->setActiveContext($oldContext);
}
} | [
"public",
"function",
"popActiveContext",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"activeContextQueue",
")",
")",
"{",
"$",
"oldContext",
"=",
"array_pop",
"(",
"$",
"this",
"->",
"activeContextQueue",
")",
";",
"$",
"this",
"->",
"setActiveContext",
"(",
"$",
"oldContext",
")",
";",
"}",
"}"
] | Restore the context that was active before calling pushActiveContext.
@see Localization::pushActiveContext() | [
"Restore",
"the",
"context",
"that",
"was",
"active",
"before",
"calling",
"pushActiveContext",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Localization.php#L176-L182 | train |
concrete5/concrete5 | concrete/src/Localization/Localization.php | Localization.withContext | public function withContext($context, callable $callback)
{
$this->pushActiveContext($context);
try {
return $callback();
} finally {
try {
$this->popActiveContext();
} catch (Exception $x) {
} catch (Throwable $x) {
}
}
} | php | public function withContext($context, callable $callback)
{
$this->pushActiveContext($context);
try {
return $callback();
} finally {
try {
$this->popActiveContext();
} catch (Exception $x) {
} catch (Throwable $x) {
}
}
} | [
"public",
"function",
"withContext",
"(",
"$",
"context",
",",
"callable",
"$",
"callback",
")",
"{",
"$",
"this",
"->",
"pushActiveContext",
"(",
"$",
"context",
")",
";",
"try",
"{",
"return",
"$",
"callback",
"(",
")",
";",
"}",
"finally",
"{",
"try",
"{",
"$",
"this",
"->",
"popActiveContext",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"x",
")",
"{",
"}",
"catch",
"(",
"Throwable",
"$",
"x",
")",
"{",
"}",
"}",
"}"
] | Execute a function using a specific localization context.
@param string $context The translation context to use when running $callback (default contexts are defined by the Localization::CONTEXT_... constants).
@param callable $callback
@return mixed return the result of $callback
@since concrete5 8.5.0a2 | [
"Execute",
"a",
"function",
"using",
"a",
"specific",
"localization",
"context",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Localization.php#L194-L206 | train |
concrete5/concrete5 | concrete/src/Localization/Localization.php | Localization.getTranslatorAdapter | public function getTranslatorAdapter($context)
{
if (!isset($this->contextLocales[$context])) {
// Note: Do NOT call the t() function here as it might possibly
// cause an infinte loop in case this happens with the active
// context.
throw new Exception(sprintf('Context locale has not been set for context: %s', $context));
}
$locale = $this->contextLocales[$context];
return $this->getTranslatorAdapterRepository()->getTranslatorAdapter($context, $locale);
} | php | public function getTranslatorAdapter($context)
{
if (!isset($this->contextLocales[$context])) {
// Note: Do NOT call the t() function here as it might possibly
// cause an infinte loop in case this happens with the active
// context.
throw new Exception(sprintf('Context locale has not been set for context: %s', $context));
}
$locale = $this->contextLocales[$context];
return $this->getTranslatorAdapterRepository()->getTranslatorAdapter($context, $locale);
} | [
"public",
"function",
"getTranslatorAdapter",
"(",
"$",
"context",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"contextLocales",
"[",
"$",
"context",
"]",
")",
")",
"{",
"// Note: Do NOT call the t() function here as it might possibly",
"// cause an infinte loop in case this happens with the active",
"// context.",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Context locale has not been set for context: %s'",
",",
"$",
"context",
")",
")",
";",
"}",
"$",
"locale",
"=",
"$",
"this",
"->",
"contextLocales",
"[",
"$",
"context",
"]",
";",
"return",
"$",
"this",
"->",
"getTranslatorAdapterRepository",
"(",
")",
"->",
"getTranslatorAdapter",
"(",
"$",
"context",
",",
"$",
"locale",
")",
";",
"}"
] | Gets the translator adapter object for the given context from the
translator adapter repository.
@return \Concrete\Core\Localization\Translator\TranslatorAdapterInterface
@throws Exception in case trying to fetch an adapter for an unknown
context, an exception is thrown | [
"Gets",
"the",
"translator",
"adapter",
"object",
"for",
"the",
"given",
"context",
"from",
"the",
"translator",
"adapter",
"repository",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Localization.php#L217-L228 | train |
concrete5/concrete5 | concrete/src/Localization/Localization.php | Localization.setContextLocale | public function setContextLocale($context, $locale)
{
if (isset($this->contextLocales[$context]) && $this->contextLocales[$context] == $locale) {
return;
}
$this->contextLocales[$context] = $locale;
if ($context === $this->activeContext) {
$this->currentLocaleChanged($locale);
}
} | php | public function setContextLocale($context, $locale)
{
if (isset($this->contextLocales[$context]) && $this->contextLocales[$context] == $locale) {
return;
}
$this->contextLocales[$context] = $locale;
if ($context === $this->activeContext) {
$this->currentLocaleChanged($locale);
}
} | [
"public",
"function",
"setContextLocale",
"(",
"$",
"context",
",",
"$",
"locale",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"contextLocales",
"[",
"$",
"context",
"]",
")",
"&&",
"$",
"this",
"->",
"contextLocales",
"[",
"$",
"context",
"]",
"==",
"$",
"locale",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"contextLocales",
"[",
"$",
"context",
"]",
"=",
"$",
"locale",
";",
"if",
"(",
"$",
"context",
"===",
"$",
"this",
"->",
"activeContext",
")",
"{",
"$",
"this",
"->",
"currentLocaleChanged",
"(",
"$",
"locale",
")",
";",
"}",
"}"
] | Sets the context locale for the given context as the given locale.
@param string $context
@param string $locale | [
"Sets",
"the",
"context",
"locale",
"for",
"the",
"given",
"context",
"as",
"the",
"given",
"locale",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Localization.php#L246-L255 | train |
concrete5/concrete5 | concrete/src/Localization/Localization.php | Localization.getContextLocale | public function getContextLocale($context)
{
return isset($this->contextLocales[$context]) ? $this->contextLocales[$context] : null;
} | php | public function getContextLocale($context)
{
return isset($this->contextLocales[$context]) ? $this->contextLocales[$context] : null;
} | [
"public",
"function",
"getContextLocale",
"(",
"$",
"context",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"contextLocales",
"[",
"$",
"context",
"]",
")",
"?",
"$",
"this",
"->",
"contextLocales",
"[",
"$",
"context",
"]",
":",
"null",
";",
"}"
] | Gets the context locale for the given context.
@return string|null | [
"Gets",
"the",
"context",
"locale",
"for",
"the",
"given",
"context",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Localization.php#L262-L265 | train |
concrete5/concrete5 | concrete/src/Localization/Localization.php | Localization.removeLoadedTranslatorAdapters | public function removeLoadedTranslatorAdapters()
{
foreach ($this->contextLocales as $context => $locale) {
$this->getTranslatorAdapterRepository()->removeTranslatorAdaptersWithHandle($context);
}
} | php | public function removeLoadedTranslatorAdapters()
{
foreach ($this->contextLocales as $context => $locale) {
$this->getTranslatorAdapterRepository()->removeTranslatorAdaptersWithHandle($context);
}
} | [
"public",
"function",
"removeLoadedTranslatorAdapters",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"contextLocales",
"as",
"$",
"context",
"=>",
"$",
"locale",
")",
"{",
"$",
"this",
"->",
"getTranslatorAdapterRepository",
"(",
")",
"->",
"removeTranslatorAdaptersWithHandle",
"(",
"$",
"context",
")",
";",
"}",
"}"
] | Removes all the loaded translator adapters from the translator adapter
repository. | [
"Removes",
"all",
"the",
"loaded",
"translator",
"adapters",
"from",
"the",
"translator",
"adapter",
"repository",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Localization.php#L293-L298 | train |
concrete5/concrete5 | concrete/src/Localization/Localization.php | Localization.getActiveTranslateObject | public function getActiveTranslateObject()
{
$adapter = $this->getTranslatorAdapter($this->getActiveContext());
if (is_object($adapter)) {
return $adapter->getTranslator();
}
return null;
} | php | public function getActiveTranslateObject()
{
$adapter = $this->getTranslatorAdapter($this->getActiveContext());
if (is_object($adapter)) {
return $adapter->getTranslator();
}
return null;
} | [
"public",
"function",
"getActiveTranslateObject",
"(",
")",
"{",
"$",
"adapter",
"=",
"$",
"this",
"->",
"getTranslatorAdapter",
"(",
"$",
"this",
"->",
"getActiveContext",
"(",
")",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"adapter",
")",
")",
"{",
"return",
"$",
"adapter",
"->",
"getTranslator",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Gets the translator object for the active context.
@deprecated Use translator adapters instead
@return ZendTranslator|null | [
"Gets",
"the",
"translator",
"object",
"for",
"the",
"active",
"context",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Localization.php#L307-L315 | train |
concrete5/concrete5 | concrete/src/Localization/Localization.php | Localization.getAvailableInterfaceLanguages | public static function getAvailableInterfaceLanguages()
{
$languages = [];
$fh = Core::make('helper/file');
if (file_exists(DIR_LANGUAGES)) {
$contents = $fh->getDirectoryContents(DIR_LANGUAGES);
foreach ($contents as $con) {
if (is_dir(DIR_LANGUAGES . '/' . $con) && file_exists(DIR_LANGUAGES . '/' . $con . '/LC_MESSAGES/messages.mo')) {
$languages[] = $con;
}
}
}
if (file_exists(DIR_LANGUAGES_CORE)) {
$contents = $fh->getDirectoryContents(DIR_LANGUAGES_CORE);
foreach ($contents as $con) {
if (is_dir(DIR_LANGUAGES_CORE . '/' . $con) && file_exists(DIR_LANGUAGES_CORE . '/' . $con . '/LC_MESSAGES/messages.mo') && (!in_array($con, $languages))) {
$languages[] = $con;
}
}
}
return $languages;
} | php | public static function getAvailableInterfaceLanguages()
{
$languages = [];
$fh = Core::make('helper/file');
if (file_exists(DIR_LANGUAGES)) {
$contents = $fh->getDirectoryContents(DIR_LANGUAGES);
foreach ($contents as $con) {
if (is_dir(DIR_LANGUAGES . '/' . $con) && file_exists(DIR_LANGUAGES . '/' . $con . '/LC_MESSAGES/messages.mo')) {
$languages[] = $con;
}
}
}
if (file_exists(DIR_LANGUAGES_CORE)) {
$contents = $fh->getDirectoryContents(DIR_LANGUAGES_CORE);
foreach ($contents as $con) {
if (is_dir(DIR_LANGUAGES_CORE . '/' . $con) && file_exists(DIR_LANGUAGES_CORE . '/' . $con . '/LC_MESSAGES/messages.mo') && (!in_array($con, $languages))) {
$languages[] = $con;
}
}
}
return $languages;
} | [
"public",
"static",
"function",
"getAvailableInterfaceLanguages",
"(",
")",
"{",
"$",
"languages",
"=",
"[",
"]",
";",
"$",
"fh",
"=",
"Core",
"::",
"make",
"(",
"'helper/file'",
")",
";",
"if",
"(",
"file_exists",
"(",
"DIR_LANGUAGES",
")",
")",
"{",
"$",
"contents",
"=",
"$",
"fh",
"->",
"getDirectoryContents",
"(",
"DIR_LANGUAGES",
")",
";",
"foreach",
"(",
"$",
"contents",
"as",
"$",
"con",
")",
"{",
"if",
"(",
"is_dir",
"(",
"DIR_LANGUAGES",
".",
"'/'",
".",
"$",
"con",
")",
"&&",
"file_exists",
"(",
"DIR_LANGUAGES",
".",
"'/'",
".",
"$",
"con",
".",
"'/LC_MESSAGES/messages.mo'",
")",
")",
"{",
"$",
"languages",
"[",
"]",
"=",
"$",
"con",
";",
"}",
"}",
"}",
"if",
"(",
"file_exists",
"(",
"DIR_LANGUAGES_CORE",
")",
")",
"{",
"$",
"contents",
"=",
"$",
"fh",
"->",
"getDirectoryContents",
"(",
"DIR_LANGUAGES_CORE",
")",
";",
"foreach",
"(",
"$",
"contents",
"as",
"$",
"con",
")",
"{",
"if",
"(",
"is_dir",
"(",
"DIR_LANGUAGES_CORE",
".",
"'/'",
".",
"$",
"con",
")",
"&&",
"file_exists",
"(",
"DIR_LANGUAGES_CORE",
".",
"'/'",
".",
"$",
"con",
".",
"'/LC_MESSAGES/messages.mo'",
")",
"&&",
"(",
"!",
"in_array",
"(",
"$",
"con",
",",
"$",
"languages",
")",
")",
")",
"{",
"$",
"languages",
"[",
"]",
"=",
"$",
"con",
";",
"}",
"}",
"}",
"return",
"$",
"languages",
";",
"}"
] | Gets a list of the available site interface languages. Returns an array
that where each item is a locale in format xx_XX.
@return array | [
"Gets",
"a",
"list",
"of",
"the",
"available",
"site",
"interface",
"languages",
".",
"Returns",
"an",
"array",
"that",
"where",
"each",
"item",
"is",
"a",
"locale",
"in",
"format",
"xx_XX",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Localization.php#L390-L413 | train |
concrete5/concrete5 | concrete/src/Localization/Localization.php | Localization.clearCache | public static function clearCache()
{
// cache/expensive should be used by the translator adapters.
$app = Facade::getFacadeApplication();
$app->make('cache/expensive')->getItem('zend')->clear();
// Also remove the loaded translation adapters so that old strings are
// not being used from the adapters already in memory.
$loc = static::getInstance();
$loc->removeLoadedTranslatorAdapters();
} | php | public static function clearCache()
{
// cache/expensive should be used by the translator adapters.
$app = Facade::getFacadeApplication();
$app->make('cache/expensive')->getItem('zend')->clear();
// Also remove the loaded translation adapters so that old strings are
// not being used from the adapters already in memory.
$loc = static::getInstance();
$loc->removeLoadedTranslatorAdapters();
} | [
"public",
"static",
"function",
"clearCache",
"(",
")",
"{",
"// cache/expensive should be used by the translator adapters.",
"$",
"app",
"=",
"Facade",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"app",
"->",
"make",
"(",
"'cache/expensive'",
")",
"->",
"getItem",
"(",
"'zend'",
")",
"->",
"clear",
"(",
")",
";",
"// Also remove the loaded translation adapters so that old strings are",
"// not being used from the adapters already in memory.",
"$",
"loc",
"=",
"static",
"::",
"getInstance",
"(",
")",
";",
"$",
"loc",
"->",
"removeLoadedTranslatorAdapters",
"(",
")",
";",
"}"
] | Clear the translations cache. | [
"Clear",
"the",
"translations",
"cache",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Localization.php#L465-L475 | train |
concrete5/concrete5 | concrete/src/Localization/Localization.php | Localization.currentLocaleChanged | protected function currentLocaleChanged($locale)
{
PunicData::setDefaultLocale($locale);
$app = Facade::getFacadeApplication();
if ($app->bound('director')) {
$event = new \Symfony\Component\EventDispatcher\GenericEvent();
$event->setArgument('locale', $locale);
$app->make('director')->dispatch('on_locale_load', $event);
}
} | php | protected function currentLocaleChanged($locale)
{
PunicData::setDefaultLocale($locale);
$app = Facade::getFacadeApplication();
if ($app->bound('director')) {
$event = new \Symfony\Component\EventDispatcher\GenericEvent();
$event->setArgument('locale', $locale);
$app->make('director')->dispatch('on_locale_load', $event);
}
} | [
"protected",
"function",
"currentLocaleChanged",
"(",
"$",
"locale",
")",
"{",
"PunicData",
"::",
"setDefaultLocale",
"(",
"$",
"locale",
")",
";",
"$",
"app",
"=",
"Facade",
"::",
"getFacadeApplication",
"(",
")",
";",
"if",
"(",
"$",
"app",
"->",
"bound",
"(",
"'director'",
")",
")",
"{",
"$",
"event",
"=",
"new",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"EventDispatcher",
"\\",
"GenericEvent",
"(",
")",
";",
"$",
"event",
"->",
"setArgument",
"(",
"'locale'",
",",
"$",
"locale",
")",
";",
"$",
"app",
"->",
"make",
"(",
"'director'",
")",
"->",
"dispatch",
"(",
"'on_locale_load'",
",",
"$",
"event",
")",
";",
"}",
"}"
] | To be called every time the current locale changes.
@param string $locale | [
"To",
"be",
"called",
"every",
"time",
"the",
"current",
"locale",
"changes",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Localization/Localization.php#L505-L514 | train |
concrete5/concrete5 | concrete/src/Session/SessionFactory.php | SessionFactory.createSession | public function createSession()
{
$config = $this->app['config']['concrete.session'];
$storage = $this->getSessionStorage($config);
// We have to use "build" here because we have bound this classname to this factory method
$session = $this->app->build(SymfonySession::class, [$storage]);
$session->setName(array_get($config, 'name'));
/* @TODO Remove this call. We should be able to set this against the request somewhere much higher than this */
/* At the very least we should have an observer that can track the session status and set this */
$this->app->make(\Concrete\Core\Http\Request::class)->setSession($session);
return $session;
} | php | public function createSession()
{
$config = $this->app['config']['concrete.session'];
$storage = $this->getSessionStorage($config);
// We have to use "build" here because we have bound this classname to this factory method
$session = $this->app->build(SymfonySession::class, [$storage]);
$session->setName(array_get($config, 'name'));
/* @TODO Remove this call. We should be able to set this against the request somewhere much higher than this */
/* At the very least we should have an observer that can track the session status and set this */
$this->app->make(\Concrete\Core\Http\Request::class)->setSession($session);
return $session;
} | [
"public",
"function",
"createSession",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"[",
"'concrete.session'",
"]",
";",
"$",
"storage",
"=",
"$",
"this",
"->",
"getSessionStorage",
"(",
"$",
"config",
")",
";",
"// We have to use \"build\" here because we have bound this classname to this factory method",
"$",
"session",
"=",
"$",
"this",
"->",
"app",
"->",
"build",
"(",
"SymfonySession",
"::",
"class",
",",
"[",
"$",
"storage",
"]",
")",
";",
"$",
"session",
"->",
"setName",
"(",
"array_get",
"(",
"$",
"config",
",",
"'name'",
")",
")",
";",
"/* @TODO Remove this call. We should be able to set this against the request somewhere much higher than this */",
"/* At the very least we should have an observer that can track the session status and set this */",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"\\",
"Concrete",
"\\",
"Core",
"\\",
"Http",
"\\",
"Request",
"::",
"class",
")",
"->",
"setSession",
"(",
"$",
"session",
")",
";",
"return",
"$",
"session",
";",
"}"
] | Create a new symfony session object
This method MUST NOT start the session.
@return \Symfony\Component\HttpFoundation\Session\Session
@throws \Illuminate\Contracts\Container\BindingResolutionException | [
"Create",
"a",
"new",
"symfony",
"session",
"object",
"This",
"method",
"MUST",
"NOT",
"start",
"the",
"session",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Session/SessionFactory.php#L63-L77 | train |
concrete5/concrete5 | concrete/src/Session/SessionFactory.php | SessionFactory.getDatabaseHandler | protected function getDatabaseHandler(array $config)
{
return $this->app->make(PdoSessionHandler::class, [
$this->app->make(Connection::class)->getWrappedConnection(),
[
'db_table' => 'Sessions',
'db_id_col' => 'sessionID',
'db_data_col' => 'sessionValue',
'db_time_col' => 'sessionTime',
'db_lifetime_col' => 'sessionLifeTime',
'lock_mode' => PdoSessionHandler::LOCK_ADVISORY,
],
]);
} | php | protected function getDatabaseHandler(array $config)
{
return $this->app->make(PdoSessionHandler::class, [
$this->app->make(Connection::class)->getWrappedConnection(),
[
'db_table' => 'Sessions',
'db_id_col' => 'sessionID',
'db_data_col' => 'sessionValue',
'db_time_col' => 'sessionTime',
'db_lifetime_col' => 'sessionLifeTime',
'lock_mode' => PdoSessionHandler::LOCK_ADVISORY,
],
]);
} | [
"protected",
"function",
"getDatabaseHandler",
"(",
"array",
"$",
"config",
")",
"{",
"return",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"PdoSessionHandler",
"::",
"class",
",",
"[",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"Connection",
"::",
"class",
")",
"->",
"getWrappedConnection",
"(",
")",
",",
"[",
"'db_table'",
"=>",
"'Sessions'",
",",
"'db_id_col'",
"=>",
"'sessionID'",
",",
"'db_data_col'",
"=>",
"'sessionValue'",
",",
"'db_time_col'",
"=>",
"'sessionTime'",
",",
"'db_lifetime_col'",
"=>",
"'sessionLifeTime'",
",",
"'lock_mode'",
"=>",
"PdoSessionHandler",
"::",
"LOCK_ADVISORY",
",",
"]",
",",
"]",
")",
";",
"}"
] | Create a new database session handler to handle session.
@param array $config The `concrete.session` config item
@return \Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler | [
"Create",
"a",
"new",
"database",
"session",
"handler",
"to",
"handle",
"session",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Session/SessionFactory.php#L100-L113 | train |
concrete5/concrete5 | concrete/src/Session/SessionFactory.php | SessionFactory.getMemcachedHandler | protected function getMemcachedHandler(array $config)
{
// Create new memcached instance
$memcached = $this->app->make(Memcached::class, [
'CCM_SESSION',
null,
]);
$servers = array_get($config, 'servers', []);
// Add missing servers
foreach ($this->newMemcachedServers($memcached, $servers) as $server) {
$memcached->addServer(
array_get($server, 'host'),
array_get($server, 'port'),
array_get($server, 'weight')
);
}
// Return a newly built handler
return $this->app->make(MemcachedSessionHandler::class, [
$memcached,
['prefix' => array_get($config, 'name') ?: 'CCM_SESSION'],
]);
} | php | protected function getMemcachedHandler(array $config)
{
// Create new memcached instance
$memcached = $this->app->make(Memcached::class, [
'CCM_SESSION',
null,
]);
$servers = array_get($config, 'servers', []);
// Add missing servers
foreach ($this->newMemcachedServers($memcached, $servers) as $server) {
$memcached->addServer(
array_get($server, 'host'),
array_get($server, 'port'),
array_get($server, 'weight')
);
}
// Return a newly built handler
return $this->app->make(MemcachedSessionHandler::class, [
$memcached,
['prefix' => array_get($config, 'name') ?: 'CCM_SESSION'],
]);
} | [
"protected",
"function",
"getMemcachedHandler",
"(",
"array",
"$",
"config",
")",
"{",
"// Create new memcached instance",
"$",
"memcached",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"Memcached",
"::",
"class",
",",
"[",
"'CCM_SESSION'",
",",
"null",
",",
"]",
")",
";",
"$",
"servers",
"=",
"array_get",
"(",
"$",
"config",
",",
"'servers'",
",",
"[",
"]",
")",
";",
"// Add missing servers",
"foreach",
"(",
"$",
"this",
"->",
"newMemcachedServers",
"(",
"$",
"memcached",
",",
"$",
"servers",
")",
"as",
"$",
"server",
")",
"{",
"$",
"memcached",
"->",
"addServer",
"(",
"array_get",
"(",
"$",
"server",
",",
"'host'",
")",
",",
"array_get",
"(",
"$",
"server",
",",
"'port'",
")",
",",
"array_get",
"(",
"$",
"server",
",",
"'weight'",
")",
")",
";",
"}",
"// Return a newly built handler",
"return",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"MemcachedSessionHandler",
"::",
"class",
",",
"[",
"$",
"memcached",
",",
"[",
"'prefix'",
"=>",
"array_get",
"(",
"$",
"config",
",",
"'name'",
")",
"?",
":",
"'CCM_SESSION'",
"]",
",",
"]",
")",
";",
"}"
] | Return a built Memcached session handler.
@param array $config The `concrete.session` config item
@return \Symfony\Component\HttpFoundation\Session\Storage\Handler\MemcachedSessionHandler | [
"Return",
"a",
"built",
"Memcached",
"session",
"handler",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Session/SessionFactory.php#L122-L146 | train |
concrete5/concrete5 | concrete/src/Session/SessionFactory.php | SessionFactory.getSessionStorage | private function getSessionStorage(array $config)
{
$app = $this->app;
// If we're running through command line, just early return an in-memory storage
if ($app->isRunThroughCommandLineInterface()) {
return $app->make(MockArraySessionStorage::class);
}
// Resolve the handler based on config
$handler = $this->getSessionHandler($config);
$storage = $app->make(NativeSessionStorage::class, [[], $handler]);
// Initialize the storage with some options
$options = array_get($config, 'cookie', []);
$options['gc_maxlifetime'] = array_get($config, 'max_lifetime');
if (array_get($options, 'cookie_path', false) === false) {
$options['cookie_path'] = $app['app_relative_path'] . '/';
}
$storage->setOptions($options);
return $app->make(Storage\LoggedStorage::class, [$storage]);
} | php | private function getSessionStorage(array $config)
{
$app = $this->app;
// If we're running through command line, just early return an in-memory storage
if ($app->isRunThroughCommandLineInterface()) {
return $app->make(MockArraySessionStorage::class);
}
// Resolve the handler based on config
$handler = $this->getSessionHandler($config);
$storage = $app->make(NativeSessionStorage::class, [[], $handler]);
// Initialize the storage with some options
$options = array_get($config, 'cookie', []);
$options['gc_maxlifetime'] = array_get($config, 'max_lifetime');
if (array_get($options, 'cookie_path', false) === false) {
$options['cookie_path'] = $app['app_relative_path'] . '/';
}
$storage->setOptions($options);
return $app->make(Storage\LoggedStorage::class, [$storage]);
} | [
"private",
"function",
"getSessionStorage",
"(",
"array",
"$",
"config",
")",
"{",
"$",
"app",
"=",
"$",
"this",
"->",
"app",
";",
"// If we're running through command line, just early return an in-memory storage",
"if",
"(",
"$",
"app",
"->",
"isRunThroughCommandLineInterface",
"(",
")",
")",
"{",
"return",
"$",
"app",
"->",
"make",
"(",
"MockArraySessionStorage",
"::",
"class",
")",
";",
"}",
"// Resolve the handler based on config",
"$",
"handler",
"=",
"$",
"this",
"->",
"getSessionHandler",
"(",
"$",
"config",
")",
";",
"$",
"storage",
"=",
"$",
"app",
"->",
"make",
"(",
"NativeSessionStorage",
"::",
"class",
",",
"[",
"[",
"]",
",",
"$",
"handler",
"]",
")",
";",
"// Initialize the storage with some options",
"$",
"options",
"=",
"array_get",
"(",
"$",
"config",
",",
"'cookie'",
",",
"[",
"]",
")",
";",
"$",
"options",
"[",
"'gc_maxlifetime'",
"]",
"=",
"array_get",
"(",
"$",
"config",
",",
"'max_lifetime'",
")",
";",
"if",
"(",
"array_get",
"(",
"$",
"options",
",",
"'cookie_path'",
",",
"false",
")",
"===",
"false",
")",
"{",
"$",
"options",
"[",
"'cookie_path'",
"]",
"=",
"$",
"app",
"[",
"'app_relative_path'",
"]",
".",
"'/'",
";",
"}",
"$",
"storage",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"return",
"$",
"app",
"->",
"make",
"(",
"Storage",
"\\",
"LoggedStorage",
"::",
"class",
",",
"[",
"$",
"storage",
"]",
")",
";",
"}"
] | Get a session storage object based on configuration.
@param array $config
@return \Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface | [
"Get",
"a",
"session",
"storage",
"object",
"based",
"on",
"configuration",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Session/SessionFactory.php#L167-L191 | train |
concrete5/concrete5 | concrete/src/Session/SessionFactory.php | SessionFactory.getSessionHandler | private function getSessionHandler(array $config)
{
$handler = array_get($config, 'handler', 'default');
// Build handler using a matching method "get{Type}Handler"
$method = Str::camel("get_{$handler}_handler");
if (method_exists($this, $method)) {
return $this->{$method}($config);
}
/*
* @todo Change this to return an exception if an unsupported handler is configured. This makes it easier to get
* configuration dialed in properly
*/
//throw new \RuntimeException(t('Unsupported session handler "%s"', $handler));
// Return the default session handler by default
return $this->getSessionHandler(['handler' => 'default'] + $config);
} | php | private function getSessionHandler(array $config)
{
$handler = array_get($config, 'handler', 'default');
// Build handler using a matching method "get{Type}Handler"
$method = Str::camel("get_{$handler}_handler");
if (method_exists($this, $method)) {
return $this->{$method}($config);
}
/*
* @todo Change this to return an exception if an unsupported handler is configured. This makes it easier to get
* configuration dialed in properly
*/
//throw new \RuntimeException(t('Unsupported session handler "%s"', $handler));
// Return the default session handler by default
return $this->getSessionHandler(['handler' => 'default'] + $config);
} | [
"private",
"function",
"getSessionHandler",
"(",
"array",
"$",
"config",
")",
"{",
"$",
"handler",
"=",
"array_get",
"(",
"$",
"config",
",",
"'handler'",
",",
"'default'",
")",
";",
"// Build handler using a matching method \"get{Type}Handler\"",
"$",
"method",
"=",
"Str",
"::",
"camel",
"(",
"\"get_{$handler}_handler\"",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"return",
"$",
"this",
"->",
"{",
"$",
"method",
"}",
"(",
"$",
"config",
")",
";",
"}",
"/*\n * @todo Change this to return an exception if an unsupported handler is configured. This makes it easier to get\n * configuration dialed in properly\n */",
"//throw new \\RuntimeException(t('Unsupported session handler \"%s\"', $handler));",
"// Return the default session handler by default",
"return",
"$",
"this",
"->",
"getSessionHandler",
"(",
"[",
"'handler'",
"=>",
"'default'",
"]",
"+",
"$",
"config",
")",
";",
"}"
] | Get a new session handler.
@param array $config The config from our config repository
@return \SessionHandlerInterface
@throws \RuntimeException When a configured handler does not exist | [
"Get",
"a",
"new",
"session",
"handler",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Session/SessionFactory.php#L202-L220 | train |
concrete5/concrete5 | concrete/src/Session/SessionFactory.php | SessionFactory.newMemcachedServers | private function newMemcachedServers(Memcached $memcached, array $servers)
{
$serverIndex = [];
$existingServers = $memcached->getServerList();
foreach ($existingServers as $server) {
$serverIndex[$server['host'] . ':' . $server['port']] = true;
}
foreach ($servers as $configServer) {
$server = [
'host' => array_get($configServer, 'host', ''),
'port' => array_get($configServer, 'port', 11211),
'weight' => array_get($configServer, 'weight', 0),
];
if (!isset($serverIndex[$server['host'] . ':' . $server['port']])) {
yield $server;
}
}
} | php | private function newMemcachedServers(Memcached $memcached, array $servers)
{
$serverIndex = [];
$existingServers = $memcached->getServerList();
foreach ($existingServers as $server) {
$serverIndex[$server['host'] . ':' . $server['port']] = true;
}
foreach ($servers as $configServer) {
$server = [
'host' => array_get($configServer, 'host', ''),
'port' => array_get($configServer, 'port', 11211),
'weight' => array_get($configServer, 'weight', 0),
];
if (!isset($serverIndex[$server['host'] . ':' . $server['port']])) {
yield $server;
}
}
} | [
"private",
"function",
"newMemcachedServers",
"(",
"Memcached",
"$",
"memcached",
",",
"array",
"$",
"servers",
")",
"{",
"$",
"serverIndex",
"=",
"[",
"]",
";",
"$",
"existingServers",
"=",
"$",
"memcached",
"->",
"getServerList",
"(",
")",
";",
"foreach",
"(",
"$",
"existingServers",
"as",
"$",
"server",
")",
"{",
"$",
"serverIndex",
"[",
"$",
"server",
"[",
"'host'",
"]",
".",
"':'",
".",
"$",
"server",
"[",
"'port'",
"]",
"]",
"=",
"true",
";",
"}",
"foreach",
"(",
"$",
"servers",
"as",
"$",
"configServer",
")",
"{",
"$",
"server",
"=",
"[",
"'host'",
"=>",
"array_get",
"(",
"$",
"configServer",
",",
"'host'",
",",
"''",
")",
",",
"'port'",
"=>",
"array_get",
"(",
"$",
"configServer",
",",
"'port'",
",",
"11211",
")",
",",
"'weight'",
"=>",
"array_get",
"(",
"$",
"configServer",
",",
"'weight'",
",",
"0",
")",
",",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"serverIndex",
"[",
"$",
"server",
"[",
"'host'",
"]",
".",
"':'",
".",
"$",
"server",
"[",
"'port'",
"]",
"]",
")",
")",
"{",
"yield",
"$",
"server",
";",
"}",
"}",
"}"
] | Generator for only returning hosts that aren't already added to the memcache instance.
@param \Memcached $memcached
@param array $servers The servers as described in config
@return \Generator|string[] [ $host, $port, $weight ] | [
"Generator",
"for",
"only",
"returning",
"hosts",
"that",
"aren",
"t",
"already",
"added",
"to",
"the",
"memcache",
"instance",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Session/SessionFactory.php#L230-L250 | train |
concrete5/concrete5 | concrete/src/Session/SessionFactory.php | SessionFactory.getRedisHandler | protected function getRedisHandler(array $config)
{
$options = array_get($config, 'redis', []);
// In case anyone puts the servers under redis configuration - similar to how we handle cache
$servers = array_get($options, 'servers', []);
if (empty($servers)) {
$servers = array_get($config, 'servers', []);
}
$redis = $this->getRedisInstance($servers);
if (!empty($options['database'])) {
$redis->select((int) $options['database']);
}
// In case of anyone setting prefix on the redis server directly
// Similar to how we do it on cache
$prefix = array_get($options, 'prefix', 'CCM_SESSION');
// We pass the prefix to the Redis Handler when we build it
return $this->app->make(RedisSessionHandler::class, [$redis, ['prefix' => array_get($config, 'name') ?: $prefix]]);
} | php | protected function getRedisHandler(array $config)
{
$options = array_get($config, 'redis', []);
// In case anyone puts the servers under redis configuration - similar to how we handle cache
$servers = array_get($options, 'servers', []);
if (empty($servers)) {
$servers = array_get($config, 'servers', []);
}
$redis = $this->getRedisInstance($servers);
if (!empty($options['database'])) {
$redis->select((int) $options['database']);
}
// In case of anyone setting prefix on the redis server directly
// Similar to how we do it on cache
$prefix = array_get($options, 'prefix', 'CCM_SESSION');
// We pass the prefix to the Redis Handler when we build it
return $this->app->make(RedisSessionHandler::class, [$redis, ['prefix' => array_get($config, 'name') ?: $prefix]]);
} | [
"protected",
"function",
"getRedisHandler",
"(",
"array",
"$",
"config",
")",
"{",
"$",
"options",
"=",
"array_get",
"(",
"$",
"config",
",",
"'redis'",
",",
"[",
"]",
")",
";",
"// In case anyone puts the servers under redis configuration - similar to how we handle cache",
"$",
"servers",
"=",
"array_get",
"(",
"$",
"options",
",",
"'servers'",
",",
"[",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"servers",
")",
")",
"{",
"$",
"servers",
"=",
"array_get",
"(",
"$",
"config",
",",
"'servers'",
",",
"[",
"]",
")",
";",
"}",
"$",
"redis",
"=",
"$",
"this",
"->",
"getRedisInstance",
"(",
"$",
"servers",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'database'",
"]",
")",
")",
"{",
"$",
"redis",
"->",
"select",
"(",
"(",
"int",
")",
"$",
"options",
"[",
"'database'",
"]",
")",
";",
"}",
"// In case of anyone setting prefix on the redis server directly",
"// Similar to how we do it on cache",
"$",
"prefix",
"=",
"array_get",
"(",
"$",
"options",
",",
"'prefix'",
",",
"'CCM_SESSION'",
")",
";",
"// We pass the prefix to the Redis Handler when we build it",
"return",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"RedisSessionHandler",
"::",
"class",
",",
"[",
"$",
"redis",
",",
"[",
"'prefix'",
"=>",
"array_get",
"(",
"$",
"config",
",",
"'name'",
")",
"?",
":",
"$",
"prefix",
"]",
"]",
")",
";",
"}"
] | Return a built Redis session handler.
@param array $config The `concrete.session` config item
@return \Concrete\Core\Session\Storage\Handler\RedisSessionHandler | [
"Return",
"a",
"built",
"Redis",
"session",
"handler",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Session/SessionFactory.php#L259-L279 | train |
concrete5/concrete5 | concrete/src/Session/SessionFactory.php | SessionFactory.getRedisInstance | private function getRedisInstance(array $servers)
{
if (count($servers) == 1) {
// If we only have one server in our array then we just reconnect to it
$server = $servers[0];
$redis = $this->app->make(Redis::class);
if (isset($server['socket']) && $server['socket']) {
$redis->connect($server['socket']);
} else {
$host = array_get($server, 'host', '');
$port = array_get($server, 'port', 6379);
$ttl = array_get($server, 'ttl', 0.5);
// Check for both server/host - fallback due to cache using server
$host = !empty($host) ? $host : array_get($server, 'server', '127.0.0.1');
$redis->connect($host, $port, $ttl);
}
// Authorisation is handled by just a password
if (isset($server['password'])) {
$redis->auth($server['password']);
}
} else {
$serverArray = [];
$ttl = 0.5;
foreach ($this->getRedisServers($servers) as $server) {
$serverString = $server['server'];
if (isset($server['port'])) {
$serverString .= ':' . $server['port'];
}
// We can only use one ttl for connection timeout so use the last set ttl
// isset allows for 0 - unlimited
if (!isset($server['ttl'])) {
$ttl = $server['ttl'];
}
$serverArray[] = $serverString;
}
$redis = $this->app->make(RedisArray::class, [$serverArray, ['connect_timeout' => $ttl]]);
}
return $redis;
} | php | private function getRedisInstance(array $servers)
{
if (count($servers) == 1) {
// If we only have one server in our array then we just reconnect to it
$server = $servers[0];
$redis = $this->app->make(Redis::class);
if (isset($server['socket']) && $server['socket']) {
$redis->connect($server['socket']);
} else {
$host = array_get($server, 'host', '');
$port = array_get($server, 'port', 6379);
$ttl = array_get($server, 'ttl', 0.5);
// Check for both server/host - fallback due to cache using server
$host = !empty($host) ? $host : array_get($server, 'server', '127.0.0.1');
$redis->connect($host, $port, $ttl);
}
// Authorisation is handled by just a password
if (isset($server['password'])) {
$redis->auth($server['password']);
}
} else {
$serverArray = [];
$ttl = 0.5;
foreach ($this->getRedisServers($servers) as $server) {
$serverString = $server['server'];
if (isset($server['port'])) {
$serverString .= ':' . $server['port'];
}
// We can only use one ttl for connection timeout so use the last set ttl
// isset allows for 0 - unlimited
if (!isset($server['ttl'])) {
$ttl = $server['ttl'];
}
$serverArray[] = $serverString;
}
$redis = $this->app->make(RedisArray::class, [$serverArray, ['connect_timeout' => $ttl]]);
}
return $redis;
} | [
"private",
"function",
"getRedisInstance",
"(",
"array",
"$",
"servers",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"servers",
")",
"==",
"1",
")",
"{",
"// If we only have one server in our array then we just reconnect to it",
"$",
"server",
"=",
"$",
"servers",
"[",
"0",
"]",
";",
"$",
"redis",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"Redis",
"::",
"class",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"server",
"[",
"'socket'",
"]",
")",
"&&",
"$",
"server",
"[",
"'socket'",
"]",
")",
"{",
"$",
"redis",
"->",
"connect",
"(",
"$",
"server",
"[",
"'socket'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"host",
"=",
"array_get",
"(",
"$",
"server",
",",
"'host'",
",",
"''",
")",
";",
"$",
"port",
"=",
"array_get",
"(",
"$",
"server",
",",
"'port'",
",",
"6379",
")",
";",
"$",
"ttl",
"=",
"array_get",
"(",
"$",
"server",
",",
"'ttl'",
",",
"0.5",
")",
";",
"// Check for both server/host - fallback due to cache using server",
"$",
"host",
"=",
"!",
"empty",
"(",
"$",
"host",
")",
"?",
"$",
"host",
":",
"array_get",
"(",
"$",
"server",
",",
"'server'",
",",
"'127.0.0.1'",
")",
";",
"$",
"redis",
"->",
"connect",
"(",
"$",
"host",
",",
"$",
"port",
",",
"$",
"ttl",
")",
";",
"}",
"// Authorisation is handled by just a password",
"if",
"(",
"isset",
"(",
"$",
"server",
"[",
"'password'",
"]",
")",
")",
"{",
"$",
"redis",
"->",
"auth",
"(",
"$",
"server",
"[",
"'password'",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"serverArray",
"=",
"[",
"]",
";",
"$",
"ttl",
"=",
"0.5",
";",
"foreach",
"(",
"$",
"this",
"->",
"getRedisServers",
"(",
"$",
"servers",
")",
"as",
"$",
"server",
")",
"{",
"$",
"serverString",
"=",
"$",
"server",
"[",
"'server'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"server",
"[",
"'port'",
"]",
")",
")",
"{",
"$",
"serverString",
".=",
"':'",
".",
"$",
"server",
"[",
"'port'",
"]",
";",
"}",
"// We can only use one ttl for connection timeout so use the last set ttl",
"// isset allows for 0 - unlimited",
"if",
"(",
"!",
"isset",
"(",
"$",
"server",
"[",
"'ttl'",
"]",
")",
")",
"{",
"$",
"ttl",
"=",
"$",
"server",
"[",
"'ttl'",
"]",
";",
"}",
"$",
"serverArray",
"[",
"]",
"=",
"$",
"serverString",
";",
"}",
"$",
"redis",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"RedisArray",
"::",
"class",
",",
"[",
"$",
"serverArray",
",",
"[",
"'connect_timeout'",
"=>",
"$",
"ttl",
"]",
"]",
")",
";",
"}",
"return",
"$",
"redis",
";",
"}"
] | Decides whether to return a Redis Instance or RedisArray Instance depending on the number of servers passed to it.
@param array $servers The `concrete.session.servers` or `concrete.session.redis.servers` config item
@return \Redis | \RedisArray | [
"Decides",
"whether",
"to",
"return",
"a",
"Redis",
"Instance",
"or",
"RedisArray",
"Instance",
"depending",
"on",
"the",
"number",
"of",
"servers",
"passed",
"to",
"it",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Session/SessionFactory.php#L288-L331 | train |
concrete5/concrete5 | concrete/src/Session/SessionFactory.php | SessionFactory.getRedisServers | private function getRedisServers(array $servers)
{
if (!empty($servers)) {
foreach ($servers as $server) {
if (isset($server['socket'])) {
$server = [
'server' => array_get($server, 'socket', ''),
'ttl' => array_get($server, 'ttl', null),
];
} else {
$host = array_get($server, 'host', '');
// Check for both server/host - fallback due to cache using server
$host = !empty($host) ?: array_get($server, 'server', '127.0.0.1');
$server = [
'server' => $host,
'port' => array_get($server, 'port', 11211),
'ttl' => array_get($server, 'ttl', null),
];
}
yield $server;
}
} else {
yield ['server' => '127.0.0.1', 'port' => '6379', 'ttl' => 0.5];
}
} | php | private function getRedisServers(array $servers)
{
if (!empty($servers)) {
foreach ($servers as $server) {
if (isset($server['socket'])) {
$server = [
'server' => array_get($server, 'socket', ''),
'ttl' => array_get($server, 'ttl', null),
];
} else {
$host = array_get($server, 'host', '');
// Check for both server/host - fallback due to cache using server
$host = !empty($host) ?: array_get($server, 'server', '127.0.0.1');
$server = [
'server' => $host,
'port' => array_get($server, 'port', 11211),
'ttl' => array_get($server, 'ttl', null),
];
}
yield $server;
}
} else {
yield ['server' => '127.0.0.1', 'port' => '6379', 'ttl' => 0.5];
}
} | [
"private",
"function",
"getRedisServers",
"(",
"array",
"$",
"servers",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"servers",
")",
")",
"{",
"foreach",
"(",
"$",
"servers",
"as",
"$",
"server",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"server",
"[",
"'socket'",
"]",
")",
")",
"{",
"$",
"server",
"=",
"[",
"'server'",
"=>",
"array_get",
"(",
"$",
"server",
",",
"'socket'",
",",
"''",
")",
",",
"'ttl'",
"=>",
"array_get",
"(",
"$",
"server",
",",
"'ttl'",
",",
"null",
")",
",",
"]",
";",
"}",
"else",
"{",
"$",
"host",
"=",
"array_get",
"(",
"$",
"server",
",",
"'host'",
",",
"''",
")",
";",
"// Check for both server/host - fallback due to cache using server",
"$",
"host",
"=",
"!",
"empty",
"(",
"$",
"host",
")",
"?",
":",
"array_get",
"(",
"$",
"server",
",",
"'server'",
",",
"'127.0.0.1'",
")",
";",
"$",
"server",
"=",
"[",
"'server'",
"=>",
"$",
"host",
",",
"'port'",
"=>",
"array_get",
"(",
"$",
"server",
",",
"'port'",
",",
"11211",
")",
",",
"'ttl'",
"=>",
"array_get",
"(",
"$",
"server",
",",
"'ttl'",
",",
"null",
")",
",",
"]",
";",
"}",
"yield",
"$",
"server",
";",
"}",
"}",
"else",
"{",
"yield",
"[",
"'server'",
"=>",
"'127.0.0.1'",
",",
"'port'",
"=>",
"'6379'",
",",
"'ttl'",
"=>",
"0.5",
"]",
";",
"}",
"}"
] | Generator for Redis Array.
@param array $servers The `concrete.session.servers` or `concrete.session.redis.servers` config item
@return \Generator| string[] [ $server, $port, $ttl ] | [
"Generator",
"for",
"Redis",
"Array",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Session/SessionFactory.php#L340-L364 | train |
concrete5/concrete5 | concrete/src/File/Service/Application.php | Application.serializeUploadFileExtensions | public function serializeUploadFileExtensions($types)
{
$serialized = '';
$types = preg_replace('{[^a-z0-9]}i', '', $types);
foreach ($types as $type) {
$serialized .= '*.'.$type.';';
}
//removing trailing ; unclear if multiupload will choke on that or not
$serialized = substr($serialized, 0, strlen($serialized) - 1);
return $serialized;
} | php | public function serializeUploadFileExtensions($types)
{
$serialized = '';
$types = preg_replace('{[^a-z0-9]}i', '', $types);
foreach ($types as $type) {
$serialized .= '*.'.$type.';';
}
//removing trailing ; unclear if multiupload will choke on that or not
$serialized = substr($serialized, 0, strlen($serialized) - 1);
return $serialized;
} | [
"public",
"function",
"serializeUploadFileExtensions",
"(",
"$",
"types",
")",
"{",
"$",
"serialized",
"=",
"''",
";",
"$",
"types",
"=",
"preg_replace",
"(",
"'{[^a-z0-9]}i'",
",",
"''",
",",
"$",
"types",
")",
";",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"$",
"serialized",
".=",
"'*.'",
".",
"$",
"type",
".",
"';'",
";",
"}",
"//removing trailing ; unclear if multiupload will choke on that or not",
"$",
"serialized",
"=",
"substr",
"(",
"$",
"serialized",
",",
"0",
",",
"strlen",
"(",
"$",
"serialized",
")",
"-",
"1",
")",
";",
"return",
"$",
"serialized",
";",
"}"
] | Serializes an array of strings into format suitable for multi-uploader.
example for format:
'*.flv;*.jpg;*.gif;*.jpeg;*.ico;*.docx;*.xla;*.png;*.psd;*.swf;*.doc;*.txt;*.xls;*.csv;*.pdf;*.tiff;*.rtf;*.m4a;*.mov;*.wmv;*.mpeg;*.mpg;*.wav;*.avi;*.mp4;*.mp3;*.qt;*.ppt;*.kml'
@param array $types
@return string | [
"Serializes",
"an",
"array",
"of",
"strings",
"into",
"format",
"suitable",
"for",
"multi",
"-",
"uploader",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Service/Application.php#L65-L76 | train |
concrete5/concrete5 | concrete/src/File/Service/Application.php | Application.unSerializeUploadFileExtensions | public function unSerializeUploadFileExtensions($types)
{
//split by semi-colon
$types = preg_split('{;}', $types, null, PREG_SPLIT_NO_EMPTY);
$types = preg_replace('{[^a-z0-9]}i', '', $types);
return $types;
} | php | public function unSerializeUploadFileExtensions($types)
{
//split by semi-colon
$types = preg_split('{;}', $types, null, PREG_SPLIT_NO_EMPTY);
$types = preg_replace('{[^a-z0-9]}i', '', $types);
return $types;
} | [
"public",
"function",
"unSerializeUploadFileExtensions",
"(",
"$",
"types",
")",
"{",
"//split by semi-colon",
"$",
"types",
"=",
"preg_split",
"(",
"'{;}'",
",",
"$",
"types",
",",
"null",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"$",
"types",
"=",
"preg_replace",
"(",
"'{[^a-z0-9]}i'",
",",
"''",
",",
"$",
"types",
")",
";",
"return",
"$",
"types",
";",
"}"
] | Unserializes an array of strings from format suitable for multi-uploader.
example for format:
'*.flv;*.jpg;*.gif;*.jpeg;*.ico;*.docx;*.xla;*.png;*.psd;*.swf;*.doc;*.txt;*.xls;*.csv;*.pdf;*.tiff;*.rtf;*.m4a;*.mov;*.wmv;*.mpeg;*.mpg;*.wav;*.avi;*.mp4;*.mp3;*.qt;*.ppt;*.kml'
@param string $types
@return array | [
"Unserializes",
"an",
"array",
"of",
"strings",
"from",
"format",
"suitable",
"for",
"multi",
"-",
"uploader",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Service/Application.php#L88-L95 | train |
concrete5/concrete5 | concrete/src/Validation/CSRF/Token.php | Token.getErrorMessage | public function getErrorMessage()
{
$app = Application::getFacadeApplication();
$request = $app->make(Request::class);
$ajax = $app->make(Ajax::class);
if ($ajax->isAjaxRequest($request)) {
return t("Invalid token. Please reload the page and retry.");
} else {
return t("Invalid form token. Please reload this form and submit again.");
}
} | php | public function getErrorMessage()
{
$app = Application::getFacadeApplication();
$request = $app->make(Request::class);
$ajax = $app->make(Ajax::class);
if ($ajax->isAjaxRequest($request)) {
return t("Invalid token. Please reload the page and retry.");
} else {
return t("Invalid form token. Please reload this form and submit again.");
}
} | [
"public",
"function",
"getErrorMessage",
"(",
")",
"{",
"$",
"app",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"request",
"=",
"$",
"app",
"->",
"make",
"(",
"Request",
"::",
"class",
")",
";",
"$",
"ajax",
"=",
"$",
"app",
"->",
"make",
"(",
"Ajax",
"::",
"class",
")",
";",
"if",
"(",
"$",
"ajax",
"->",
"isAjaxRequest",
"(",
"$",
"request",
")",
")",
"{",
"return",
"t",
"(",
"\"Invalid token. Please reload the page and retry.\"",
")",
";",
"}",
"else",
"{",
"return",
"t",
"(",
"\"Invalid form token. Please reload this form and submit again.\"",
")",
";",
"}",
"}"
] | Get the error message to be shown to the users when a token is not valid.
@return string | [
"Get",
"the",
"error",
"message",
"to",
"be",
"shown",
"to",
"the",
"users",
"when",
"a",
"token",
"is",
"not",
"valid",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Validation/CSRF/Token.php#L31-L41 | train |
concrete5/concrete5 | concrete/src/Validation/CSRF/Token.php | Token.output | public function output($action = '', $return = false)
{
$hash = $this->generate($action);
$token = '<input type="hidden" name="' . static::DEFAULT_TOKEN_NAME . '" value="' . $hash . '" />';
if (!$return) {
echo $token;
} else {
return $token;
}
} | php | public function output($action = '', $return = false)
{
$hash = $this->generate($action);
$token = '<input type="hidden" name="' . static::DEFAULT_TOKEN_NAME . '" value="' . $hash . '" />';
if (!$return) {
echo $token;
} else {
return $token;
}
} | [
"public",
"function",
"output",
"(",
"$",
"action",
"=",
"''",
",",
"$",
"return",
"=",
"false",
")",
"{",
"$",
"hash",
"=",
"$",
"this",
"->",
"generate",
"(",
"$",
"action",
")",
";",
"$",
"token",
"=",
"'<input type=\"hidden\" name=\"'",
".",
"static",
"::",
"DEFAULT_TOKEN_NAME",
".",
"'\" value=\"'",
".",
"$",
"hash",
".",
"'\" />'",
";",
"if",
"(",
"!",
"$",
"return",
")",
"{",
"echo",
"$",
"token",
";",
"}",
"else",
"{",
"return",
"$",
"token",
";",
"}",
"}"
] | Create the HTML code of a token.
@param string $action An optional identifier of the token
@param bool $return Set to true to return the generated code, false to print it out
@return string|void | [
"Create",
"the",
"HTML",
"code",
"of",
"a",
"token",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Validation/CSRF/Token.php#L51-L60 | train |
concrete5/concrete5 | concrete/src/Validation/CSRF/Token.php | Token.validate | public function validate($action = '', $token = null)
{
$app = Application::getFacadeApplication();
if ($token == null) {
$request = $app->make(Request::class);
$token = $request->request->get(static::DEFAULT_TOKEN_NAME);
if ($token === null) {
$token = $request->query->get(static::DEFAULT_TOKEN_NAME);
}
}
if (is_string($token)) {
$parts = explode(':', $token);
if ($parts[0] && isset($parts[1])) {
$time = $parts[0];
$hash = $parts[1];
$compHash = $this->generate($action, $time);
$now = time();
if (substr($compHash, strpos($compHash, ':') + 1) == $hash) {
$diff = $now - $time;
//hash is only valid if $diff is less than VALID_HASH_TIME_RECORD
return $diff <= static::VALID_HASH_TIME_THRESHOLD;
} else {
$logger = $app->make('log/factory')->createLogger(Channels::CHANNEL_SECURITY);
$u = new User();
$logger->debug(t('Validation token did not match'), [
'uID' => $u->getUserID(),
'action' => $action,
'time' => $time,
]);
}
}
}
return false;
} | php | public function validate($action = '', $token = null)
{
$app = Application::getFacadeApplication();
if ($token == null) {
$request = $app->make(Request::class);
$token = $request->request->get(static::DEFAULT_TOKEN_NAME);
if ($token === null) {
$token = $request->query->get(static::DEFAULT_TOKEN_NAME);
}
}
if (is_string($token)) {
$parts = explode(':', $token);
if ($parts[0] && isset($parts[1])) {
$time = $parts[0];
$hash = $parts[1];
$compHash = $this->generate($action, $time);
$now = time();
if (substr($compHash, strpos($compHash, ':') + 1) == $hash) {
$diff = $now - $time;
//hash is only valid if $diff is less than VALID_HASH_TIME_RECORD
return $diff <= static::VALID_HASH_TIME_THRESHOLD;
} else {
$logger = $app->make('log/factory')->createLogger(Channels::CHANNEL_SECURITY);
$u = new User();
$logger->debug(t('Validation token did not match'), [
'uID' => $u->getUserID(),
'action' => $action,
'time' => $time,
]);
}
}
}
return false;
} | [
"public",
"function",
"validate",
"(",
"$",
"action",
"=",
"''",
",",
"$",
"token",
"=",
"null",
")",
"{",
"$",
"app",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
";",
"if",
"(",
"$",
"token",
"==",
"null",
")",
"{",
"$",
"request",
"=",
"$",
"app",
"->",
"make",
"(",
"Request",
"::",
"class",
")",
";",
"$",
"token",
"=",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"static",
"::",
"DEFAULT_TOKEN_NAME",
")",
";",
"if",
"(",
"$",
"token",
"===",
"null",
")",
"{",
"$",
"token",
"=",
"$",
"request",
"->",
"query",
"->",
"get",
"(",
"static",
"::",
"DEFAULT_TOKEN_NAME",
")",
";",
"}",
"}",
"if",
"(",
"is_string",
"(",
"$",
"token",
")",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"':'",
",",
"$",
"token",
")",
";",
"if",
"(",
"$",
"parts",
"[",
"0",
"]",
"&&",
"isset",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
")",
"{",
"$",
"time",
"=",
"$",
"parts",
"[",
"0",
"]",
";",
"$",
"hash",
"=",
"$",
"parts",
"[",
"1",
"]",
";",
"$",
"compHash",
"=",
"$",
"this",
"->",
"generate",
"(",
"$",
"action",
",",
"$",
"time",
")",
";",
"$",
"now",
"=",
"time",
"(",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"compHash",
",",
"strpos",
"(",
"$",
"compHash",
",",
"':'",
")",
"+",
"1",
")",
"==",
"$",
"hash",
")",
"{",
"$",
"diff",
"=",
"$",
"now",
"-",
"$",
"time",
";",
"//hash is only valid if $diff is less than VALID_HASH_TIME_RECORD",
"return",
"$",
"diff",
"<=",
"static",
"::",
"VALID_HASH_TIME_THRESHOLD",
";",
"}",
"else",
"{",
"$",
"logger",
"=",
"$",
"app",
"->",
"make",
"(",
"'log/factory'",
")",
"->",
"createLogger",
"(",
"Channels",
"::",
"CHANNEL_SECURITY",
")",
";",
"$",
"u",
"=",
"new",
"User",
"(",
")",
";",
"$",
"logger",
"->",
"debug",
"(",
"t",
"(",
"'Validation token did not match'",
")",
",",
"[",
"'uID'",
"=>",
"$",
"u",
"->",
"getUserID",
"(",
")",
",",
"'action'",
"=>",
"$",
"action",
",",
"'time'",
"=>",
"$",
"time",
",",
"]",
")",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Validate a token against a given action.
Basically, we check the passed hash to see if:
a. the hash is valid. That means it computes in the time:action:pepper format
b. the time included next to the hash is within the threshold.
@param string $action The action that should be associated to the token
@param string $token The token to be validated (if empty we'll retrieve it from the current request)
@return bool | [
"Validate",
"a",
"token",
"against",
"a",
"given",
"action",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Validation/CSRF/Token.php#L113-L148 | train |
concrete5/concrete5 | concrete/src/File/Type/Inspector/FlvInspector.php | FlvInspector.parseDouble | private function parseDouble($data)
{
if (!isset($data[7])) {
throw new UnexpectedValueException();
}
$unpacked = unpack('E', $data);
return array_shift($unpacked);
} | php | private function parseDouble($data)
{
if (!isset($data[7])) {
throw new UnexpectedValueException();
}
$unpacked = unpack('E', $data);
return array_shift($unpacked);
} | [
"private",
"function",
"parseDouble",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"7",
"]",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
")",
";",
"}",
"$",
"unpacked",
"=",
"unpack",
"(",
"'E'",
",",
"$",
"data",
")",
";",
"return",
"array_shift",
"(",
"$",
"unpacked",
")",
";",
"}"
] | IEEE 754.
@param string $data
@throws UnexpectedValueException
@return float | [
"IEEE",
"754",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Type/Inspector/FlvInspector.php#L256-L264 | train |
concrete5/concrete5 | concrete/src/Application/Service/Dashboard.php | Dashboard.canRead | public function canRead()
{
$c = Page::getByPath('/dashboard', 'ACTIVE');
if ($c && !$c->isError()) {
$cp = new Permissions($c);
return $cp->canViewPage();
}
} | php | public function canRead()
{
$c = Page::getByPath('/dashboard', 'ACTIVE');
if ($c && !$c->isError()) {
$cp = new Permissions($c);
return $cp->canViewPage();
}
} | [
"public",
"function",
"canRead",
"(",
")",
"{",
"$",
"c",
"=",
"Page",
"::",
"getByPath",
"(",
"'/dashboard'",
",",
"'ACTIVE'",
")",
";",
"if",
"(",
"$",
"c",
"&&",
"!",
"$",
"c",
"->",
"isError",
"(",
")",
")",
"{",
"$",
"cp",
"=",
"new",
"Permissions",
"(",
"$",
"c",
")",
";",
"return",
"$",
"cp",
"->",
"canViewPage",
"(",
")",
";",
"}",
"}"
] | Checks to see if a user has access to the C5 dashboard.
@return bool | [
"Checks",
"to",
"see",
"if",
"a",
"user",
"has",
"access",
"to",
"the",
"C5",
"dashboard",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Service/Dashboard.php#L22-L30 | train |
concrete5/concrete5 | concrete/src/Page/Sitemap/SitemapGenerator.php | SitemapGenerator.getSiteCanonicalUrl | public function getSiteCanonicalUrl()
{
$site = $this->getPageListGenerator()->getSite();
if ($site === null) {
$result = '';
} else {
$result = (string) $site->getConfigRepository()->get('seo.canonical_url');
}
return $result;
} | php | public function getSiteCanonicalUrl()
{
$site = $this->getPageListGenerator()->getSite();
if ($site === null) {
$result = '';
} else {
$result = (string) $site->getConfigRepository()->get('seo.canonical_url');
}
return $result;
} | [
"public",
"function",
"getSiteCanonicalUrl",
"(",
")",
"{",
"$",
"site",
"=",
"$",
"this",
"->",
"getPageListGenerator",
"(",
")",
"->",
"getSite",
"(",
")",
";",
"if",
"(",
"$",
"site",
"===",
"null",
")",
"{",
"$",
"result",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"(",
"string",
")",
"$",
"site",
"->",
"getConfigRepository",
"(",
")",
"->",
"get",
"(",
"'seo.canonical_url'",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get the currently configured canonical URL of the site.
@return string | [
"Get",
"the",
"currently",
"configured",
"canonical",
"URL",
"of",
"the",
"site",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Page/Sitemap/SitemapGenerator.php#L160-L170 | train |
concrete5/concrete5 | concrete/src/Page/Sitemap/SitemapGenerator.php | SitemapGenerator.withCustomCanonicalUrl | protected function withCustomCanonicalUrl(callable $run)
{
$customCanonicalUrl = $this->getCustomSiteCanonicalUrl();
if ($customCanonicalUrl !== '') {
$siteConfig = $this->getPageListGenerator()->getSite()->getConfigRepository();
$originalSiteCanonicalUrl = $siteConfig->get('seo.canonical_url');
$siteConfig->set('seo.canonical_url', $customCanonicalUrl);
}
try {
return $run();
} finally {
if ($customCanonicalUrl !== '') {
$siteConfig->set('seo.canonical_url', $originalSiteCanonicalUrl);
}
}
} | php | protected function withCustomCanonicalUrl(callable $run)
{
$customCanonicalUrl = $this->getCustomSiteCanonicalUrl();
if ($customCanonicalUrl !== '') {
$siteConfig = $this->getPageListGenerator()->getSite()->getConfigRepository();
$originalSiteCanonicalUrl = $siteConfig->get('seo.canonical_url');
$siteConfig->set('seo.canonical_url', $customCanonicalUrl);
}
try {
return $run();
} finally {
if ($customCanonicalUrl !== '') {
$siteConfig->set('seo.canonical_url', $originalSiteCanonicalUrl);
}
}
} | [
"protected",
"function",
"withCustomCanonicalUrl",
"(",
"callable",
"$",
"run",
")",
"{",
"$",
"customCanonicalUrl",
"=",
"$",
"this",
"->",
"getCustomSiteCanonicalUrl",
"(",
")",
";",
"if",
"(",
"$",
"customCanonicalUrl",
"!==",
"''",
")",
"{",
"$",
"siteConfig",
"=",
"$",
"this",
"->",
"getPageListGenerator",
"(",
")",
"->",
"getSite",
"(",
")",
"->",
"getConfigRepository",
"(",
")",
";",
"$",
"originalSiteCanonicalUrl",
"=",
"$",
"siteConfig",
"->",
"get",
"(",
"'seo.canonical_url'",
")",
";",
"$",
"siteConfig",
"->",
"set",
"(",
"'seo.canonical_url'",
",",
"$",
"customCanonicalUrl",
")",
";",
"}",
"try",
"{",
"return",
"$",
"run",
"(",
")",
";",
"}",
"finally",
"{",
"if",
"(",
"$",
"customCanonicalUrl",
"!==",
"''",
")",
"{",
"$",
"siteConfig",
"->",
"set",
"(",
"'seo.canonical_url'",
",",
"$",
"originalSiteCanonicalUrl",
")",
";",
"}",
"}",
"}"
] | Don't use with generators!
@param callable $run | [
"Don",
"t",
"use",
"with",
"generators!"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Page/Sitemap/SitemapGenerator.php#L367-L382 | train |
concrete5/concrete5 | concrete/src/Application/Service/FileManager.php | FileManager.file | public function file($inputID, $inputName, $chooseText, $preselectedFile = null, $args = [])
{
$app = Application::getFacadeApplication();
$view = View::getInstance();
$request = $app->make(Request::class);
$vh = $app->make('helper/validation/numbers');
$view->requireAsset('core/file-manager');
$fileSelectorArguments = [
'inputName' => (string) $inputName,
'fID' => null,
'filters' => [],
];
if ($vh->integer($request->request->get($inputName))) {
$file = $app->make(EntityManagerInterface::class)->find(FileEntity::class, $request->request->get($inputName));
if ($file !== null) {
$fileSelectorArguments['fID'] = $file->getFileID();
}
} elseif ($vh->integer($preselectedFile)) {
$fileSelectorArguments['fID'] = (int) $preselectedFile;
} elseif (is_object($preselectedFile)) {
$fileSelectorArguments['fID'] = (int) $preselectedFile->getFileID();
}
if ($fileSelectorArguments['fID'] === null && (string) $chooseText !== '') {
$fileSelectorArguments['chooseText'] = (string) $chooseText;
}
if (isset($args['filters']) && is_array($args['filters'])) {
$fileSelectorArguments['filters'] = $args['filters'];
}
$fileSelectorArgumentsJson = json_encode($fileSelectorArguments);
$html = <<<EOL
<div class="ccm-file-selector" data-file-selector="{$inputID}"></div>
<script type="text/javascript">
$(function() {
$('[data-file-selector="{$inputID}"]').concreteFileSelector({$fileSelectorArgumentsJson});
});
</script>
EOL;
return $html;
} | php | public function file($inputID, $inputName, $chooseText, $preselectedFile = null, $args = [])
{
$app = Application::getFacadeApplication();
$view = View::getInstance();
$request = $app->make(Request::class);
$vh = $app->make('helper/validation/numbers');
$view->requireAsset('core/file-manager');
$fileSelectorArguments = [
'inputName' => (string) $inputName,
'fID' => null,
'filters' => [],
];
if ($vh->integer($request->request->get($inputName))) {
$file = $app->make(EntityManagerInterface::class)->find(FileEntity::class, $request->request->get($inputName));
if ($file !== null) {
$fileSelectorArguments['fID'] = $file->getFileID();
}
} elseif ($vh->integer($preselectedFile)) {
$fileSelectorArguments['fID'] = (int) $preselectedFile;
} elseif (is_object($preselectedFile)) {
$fileSelectorArguments['fID'] = (int) $preselectedFile->getFileID();
}
if ($fileSelectorArguments['fID'] === null && (string) $chooseText !== '') {
$fileSelectorArguments['chooseText'] = (string) $chooseText;
}
if (isset($args['filters']) && is_array($args['filters'])) {
$fileSelectorArguments['filters'] = $args['filters'];
}
$fileSelectorArgumentsJson = json_encode($fileSelectorArguments);
$html = <<<EOL
<div class="ccm-file-selector" data-file-selector="{$inputID}"></div>
<script type="text/javascript">
$(function() {
$('[data-file-selector="{$inputID}"]').concreteFileSelector({$fileSelectorArgumentsJson});
});
</script>
EOL;
return $html;
} | [
"public",
"function",
"file",
"(",
"$",
"inputID",
",",
"$",
"inputName",
",",
"$",
"chooseText",
",",
"$",
"preselectedFile",
"=",
"null",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"app",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"view",
"=",
"View",
"::",
"getInstance",
"(",
")",
";",
"$",
"request",
"=",
"$",
"app",
"->",
"make",
"(",
"Request",
"::",
"class",
")",
";",
"$",
"vh",
"=",
"$",
"app",
"->",
"make",
"(",
"'helper/validation/numbers'",
")",
";",
"$",
"view",
"->",
"requireAsset",
"(",
"'core/file-manager'",
")",
";",
"$",
"fileSelectorArguments",
"=",
"[",
"'inputName'",
"=>",
"(",
"string",
")",
"$",
"inputName",
",",
"'fID'",
"=>",
"null",
",",
"'filters'",
"=>",
"[",
"]",
",",
"]",
";",
"if",
"(",
"$",
"vh",
"->",
"integer",
"(",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"$",
"inputName",
")",
")",
")",
"{",
"$",
"file",
"=",
"$",
"app",
"->",
"make",
"(",
"EntityManagerInterface",
"::",
"class",
")",
"->",
"find",
"(",
"FileEntity",
"::",
"class",
",",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"$",
"inputName",
")",
")",
";",
"if",
"(",
"$",
"file",
"!==",
"null",
")",
"{",
"$",
"fileSelectorArguments",
"[",
"'fID'",
"]",
"=",
"$",
"file",
"->",
"getFileID",
"(",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"vh",
"->",
"integer",
"(",
"$",
"preselectedFile",
")",
")",
"{",
"$",
"fileSelectorArguments",
"[",
"'fID'",
"]",
"=",
"(",
"int",
")",
"$",
"preselectedFile",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"preselectedFile",
")",
")",
"{",
"$",
"fileSelectorArguments",
"[",
"'fID'",
"]",
"=",
"(",
"int",
")",
"$",
"preselectedFile",
"->",
"getFileID",
"(",
")",
";",
"}",
"if",
"(",
"$",
"fileSelectorArguments",
"[",
"'fID'",
"]",
"===",
"null",
"&&",
"(",
"string",
")",
"$",
"chooseText",
"!==",
"''",
")",
"{",
"$",
"fileSelectorArguments",
"[",
"'chooseText'",
"]",
"=",
"(",
"string",
")",
"$",
"chooseText",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"args",
"[",
"'filters'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"args",
"[",
"'filters'",
"]",
")",
")",
"{",
"$",
"fileSelectorArguments",
"[",
"'filters'",
"]",
"=",
"$",
"args",
"[",
"'filters'",
"]",
";",
"}",
"$",
"fileSelectorArgumentsJson",
"=",
"json_encode",
"(",
"$",
"fileSelectorArguments",
")",
";",
"$",
"html",
"=",
" <<<EOL\n<div class=\"ccm-file-selector\" data-file-selector=\"{$inputID}\"></div>\n<script type=\"text/javascript\">\n$(function() {\n $('[data-file-selector=\"{$inputID}\"]').concreteFileSelector({$fileSelectorArgumentsJson});\n});\n</script>\nEOL",
";",
"return",
"$",
"html",
";",
"}"
] | Sets up a form field to let users pick a file.
@param string $inputID The ID of the form field
@param string $inputName The name of the form field (the selected file ID will be posted with this name)
@param string $chooseText The text to be used to tell users "Choose a File"
@param \Concrete\Core\Entity\File\File|\Concrete\Core\Entity\File\Version|int|null $preselectedFile the pre-selected file (or its ID)
@param array $args An array with additional arguments. Supported array keys are:
<ul>
<li><code>'filters'</code><br />
A list of file filters. Every array item must have a 'field' key (with the name of the field as the value), and another field that's specific of the field.<br />
For a list of valid field identifiers, see the definition of the loadDataFromRequest method of the classes that implement \ Concrete\Core\Search\Field\FieldInterface (usually it's the requestVariables property).
</li>
</ul>A list of arrays. Each array item must have a 'field' key whose value is the name of the field, and
@return string $html
@example <code><pre>
$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication();
$filemanager = $app->make(\Concrete\Core\Application\Service\FileManager::class);
echo $filemanager->file(
'myId',
'myName',
t('Choose File'),
$preselectedFile,
[
'filters' => [
[
'field' => 'type',
'type' => \Concrete\Core\File\Type\Type::T_IMAGE,
],
[
'field' => 'extension',
'extension' => ['.png', '.jpg'],
],
],
]
)
</pre></code> | [
"Sets",
"up",
"a",
"form",
"field",
"to",
"let",
"users",
"pick",
"a",
"file",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Service/FileManager.php#L54-L97 | train |
concrete5/concrete5 | concrete/src/Application/Service/FileManager.php | FileManager.image | public function image($inputID, $inputName, $chooseText, $preselectedFile = null, $args = [])
{
return $this->fileOfType(FileType::T_IMAGE, $inputID, $inputName, $chooseText, $preselectedFile, $args);
} | php | public function image($inputID, $inputName, $chooseText, $preselectedFile = null, $args = [])
{
return $this->fileOfType(FileType::T_IMAGE, $inputID, $inputName, $chooseText, $preselectedFile, $args);
} | [
"public",
"function",
"image",
"(",
"$",
"inputID",
",",
"$",
"inputName",
",",
"$",
"chooseText",
",",
"$",
"preselectedFile",
"=",
"null",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"fileOfType",
"(",
"FileType",
"::",
"T_IMAGE",
",",
"$",
"inputID",
",",
"$",
"inputName",
",",
"$",
"chooseText",
",",
"$",
"preselectedFile",
",",
"$",
"args",
")",
";",
"}"
] | Sets up a form field to let users pick an image file.
@param string $inputID The ID of the form field
@param string $inputName The name of the form field (the selected file ID will be posted with this name)
@param string $chooseText The text to be used to tell users "Choose a File"
@param \Concrete\Core\Entity\File\File|\Concrete\Core\Entity\File\Version|int|null $preselectedFile the pre-selected file (or its ID)
@param array $args See the $args description of the <code>file</code> method
@return string $html
@see \Concrete\Core\Application\Service\FileManager::file() | [
"Sets",
"up",
"a",
"form",
"field",
"to",
"let",
"users",
"pick",
"an",
"image",
"file",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Service/FileManager.php#L112-L115 | train |
concrete5/concrete5 | concrete/src/Application/Service/FileManager.php | FileManager.video | public function video($inputID, $inputName, $chooseText, $preselectedFile = null, $args = [])
{
return $this->fileOfType(FileType::T_VIDEO, $inputID, $inputName, $chooseText, $preselectedFile, $args);
} | php | public function video($inputID, $inputName, $chooseText, $preselectedFile = null, $args = [])
{
return $this->fileOfType(FileType::T_VIDEO, $inputID, $inputName, $chooseText, $preselectedFile, $args);
} | [
"public",
"function",
"video",
"(",
"$",
"inputID",
",",
"$",
"inputName",
",",
"$",
"chooseText",
",",
"$",
"preselectedFile",
"=",
"null",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"fileOfType",
"(",
"FileType",
"::",
"T_VIDEO",
",",
"$",
"inputID",
",",
"$",
"inputName",
",",
"$",
"chooseText",
",",
"$",
"preselectedFile",
",",
"$",
"args",
")",
";",
"}"
] | Sets up a form field to let users pick a video file.
@param string $inputID The ID of the form field
@param string $inputName The name of the form field (the selected file ID will be posted with this name)
@param string $chooseText The text to be used to tell users "Choose a File"
@param \Concrete\Core\Entity\File\File|\Concrete\Core\Entity\File\Version|int|null $preselectedFile the pre-selected file (or its ID)
@param array $args See the $args description of the <code>file</code> method
@return string $html
@see \Concrete\Core\Application\Service\FileManager::file() | [
"Sets",
"up",
"a",
"form",
"field",
"to",
"let",
"users",
"pick",
"a",
"video",
"file",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Service/FileManager.php#L130-L133 | train |
concrete5/concrete5 | concrete/src/Application/Service/FileManager.php | FileManager.text | public function text($inputID, $inputName, $chooseText, $preselectedFile = null, $args = [])
{
return $this->fileOfType(FileType::T_TEXT, $inputID, $inputName, $chooseText, $preselectedFile, $args);
} | php | public function text($inputID, $inputName, $chooseText, $preselectedFile = null, $args = [])
{
return $this->fileOfType(FileType::T_TEXT, $inputID, $inputName, $chooseText, $preselectedFile, $args);
} | [
"public",
"function",
"text",
"(",
"$",
"inputID",
",",
"$",
"inputName",
",",
"$",
"chooseText",
",",
"$",
"preselectedFile",
"=",
"null",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"fileOfType",
"(",
"FileType",
"::",
"T_TEXT",
",",
"$",
"inputID",
",",
"$",
"inputName",
",",
"$",
"chooseText",
",",
"$",
"preselectedFile",
",",
"$",
"args",
")",
";",
"}"
] | Sets up a form field to let users pick a text file.
@param string $inputID The ID of your form field
@param string $inputName The name of the form field (the selected file ID will be posted with this name)
@param string $chooseText The text to be used to tell users "Choose a File"
@param \Concrete\Core\Entity\File\File|\Concrete\Core\Entity\File\Version|int|null $preselectedFile the pre-selected file (or its ID)
@param array $args See the $args description of the <code>file</code> method
@return string $html
@see \Concrete\Core\Application\Service\FileManager::file() | [
"Sets",
"up",
"a",
"form",
"field",
"to",
"let",
"users",
"pick",
"a",
"text",
"file",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Service/FileManager.php#L148-L151 | train |
concrete5/concrete5 | concrete/src/Application/Service/FileManager.php | FileManager.audio | public function audio($inputID, $inputName, $chooseText, $preselectedFile = null, $args = [])
{
return $this->fileOfType(FileType::T_AUDIO, $inputID, $inputName, $chooseText, $preselectedFile, $args);
} | php | public function audio($inputID, $inputName, $chooseText, $preselectedFile = null, $args = [])
{
return $this->fileOfType(FileType::T_AUDIO, $inputID, $inputName, $chooseText, $preselectedFile, $args);
} | [
"public",
"function",
"audio",
"(",
"$",
"inputID",
",",
"$",
"inputName",
",",
"$",
"chooseText",
",",
"$",
"preselectedFile",
"=",
"null",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"fileOfType",
"(",
"FileType",
"::",
"T_AUDIO",
",",
"$",
"inputID",
",",
"$",
"inputName",
",",
"$",
"chooseText",
",",
"$",
"preselectedFile",
",",
"$",
"args",
")",
";",
"}"
] | Sets up a form field to let users pick an audio file.
@param string $inputID The ID of your form field
@param string $inputName The name of the form field (the selected file ID will be posted with this name)
@param string $chooseText The text to be used to tell users "Choose a File"
@param \Concrete\Core\Entity\File\File|\Concrete\Core\Entity\File\Version|int|null $preselectedFile the pre-selected file (or its ID)
@param array $args See the $args description of the <code>file</code> method
@return string $html
@see \Concrete\Core\Application\Service\FileManager::file() | [
"Sets",
"up",
"a",
"form",
"field",
"to",
"let",
"users",
"pick",
"an",
"audio",
"file",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Service/FileManager.php#L166-L169 | train |
concrete5/concrete5 | concrete/src/Application/Service/FileManager.php | FileManager.doc | public function doc($inputID, $inputName, $chooseText, $preselectedFile = null, $args = [])
{
return $this->fileOfType(FileType::T_DOCUMENT, $inputID, $inputName, $chooseText, $preselectedFile, $args);
} | php | public function doc($inputID, $inputName, $chooseText, $preselectedFile = null, $args = [])
{
return $this->fileOfType(FileType::T_DOCUMENT, $inputID, $inputName, $chooseText, $preselectedFile, $args);
} | [
"public",
"function",
"doc",
"(",
"$",
"inputID",
",",
"$",
"inputName",
",",
"$",
"chooseText",
",",
"$",
"preselectedFile",
"=",
"null",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"fileOfType",
"(",
"FileType",
"::",
"T_DOCUMENT",
",",
"$",
"inputID",
",",
"$",
"inputName",
",",
"$",
"chooseText",
",",
"$",
"preselectedFile",
",",
"$",
"args",
")",
";",
"}"
] | Sets up a form field to let users pick a document file.
@param string $inputID The ID of your form field
@param string $inputName The name of the form field (the selected file ID will be posted with this name)
@param string $chooseText The text to be used to tell users "Choose a File"
@param \Concrete\Core\Entity\File\File|\Concrete\Core\Entity\File\Version|int|null $preselectedFile the pre-selected file (or its ID)
@param array $args See the $args description of the <code>file</code> method
@return string $html
@see \Concrete\Core\Application\Service\FileManager::file() | [
"Sets",
"up",
"a",
"form",
"field",
"to",
"let",
"users",
"pick",
"a",
"document",
"file",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Service/FileManager.php#L184-L187 | train |
concrete5/concrete5 | concrete/src/Application/Service/FileManager.php | FileManager.app | public function app($inputID, $inputName, $chooseText, $preselectedFile = null, $args = [])
{
return $this->fileOfType(FileType::T_APPLICATION, $inputID, $inputName, $chooseText, $preselectedFile, $args);
} | php | public function app($inputID, $inputName, $chooseText, $preselectedFile = null, $args = [])
{
return $this->fileOfType(FileType::T_APPLICATION, $inputID, $inputName, $chooseText, $preselectedFile, $args);
} | [
"public",
"function",
"app",
"(",
"$",
"inputID",
",",
"$",
"inputName",
",",
"$",
"chooseText",
",",
"$",
"preselectedFile",
"=",
"null",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"fileOfType",
"(",
"FileType",
"::",
"T_APPLICATION",
",",
"$",
"inputID",
",",
"$",
"inputName",
",",
"$",
"chooseText",
",",
"$",
"preselectedFile",
",",
"$",
"args",
")",
";",
"}"
] | Sets up a form field to let users pick a application file.
@param string $inputID The ID of your form field
@param string $inputName The name of the form field (the selected file ID will be posted with this name)
@param string $chooseText The text to be used to tell users "Choose a File"
@param \Concrete\Core\Entity\File\File|\Concrete\Core\Entity\File\Version|int|null $preselectedFile the pre-selected file (or its ID)
@param array $args See the $args description of the <code>file</code> method
@return string $html
@see \Concrete\Core\Application\Service\FileManager::file() | [
"Sets",
"up",
"a",
"form",
"field",
"to",
"let",
"users",
"pick",
"a",
"application",
"file",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Service/FileManager.php#L202-L205 | train |
concrete5/concrete5 | concrete/src/Application/Service/FileManager.php | FileManager.fileOfType | private function fileOfType($type, $inputID, $inputName, $chooseText, $preselectedFile = null, $args = [])
{
if (!is_array($args)) {
$args = [];
}
if (!isset($args['filters']) || !is_array($args['filters'])) {
$args['filters'] = [];
}
$args['filters'] = array_merge(
[
[
'field' => 'type',
'type' => (int) $type,
],
],
$args['filters']
);
return $this->file($inputID, $inputName, $chooseText, $preselectedFile, $args);
} | php | private function fileOfType($type, $inputID, $inputName, $chooseText, $preselectedFile = null, $args = [])
{
if (!is_array($args)) {
$args = [];
}
if (!isset($args['filters']) || !is_array($args['filters'])) {
$args['filters'] = [];
}
$args['filters'] = array_merge(
[
[
'field' => 'type',
'type' => (int) $type,
],
],
$args['filters']
);
return $this->file($inputID, $inputName, $chooseText, $preselectedFile, $args);
} | [
"private",
"function",
"fileOfType",
"(",
"$",
"type",
",",
"$",
"inputID",
",",
"$",
"inputName",
",",
"$",
"chooseText",
",",
"$",
"preselectedFile",
"=",
"null",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"args",
")",
")",
"{",
"$",
"args",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"args",
"[",
"'filters'",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"args",
"[",
"'filters'",
"]",
")",
")",
"{",
"$",
"args",
"[",
"'filters'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"args",
"[",
"'filters'",
"]",
"=",
"array_merge",
"(",
"[",
"[",
"'field'",
"=>",
"'type'",
",",
"'type'",
"=>",
"(",
"int",
")",
"$",
"type",
",",
"]",
",",
"]",
",",
"$",
"args",
"[",
"'filters'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"file",
"(",
"$",
"inputID",
",",
"$",
"inputName",
",",
"$",
"chooseText",
",",
"$",
"preselectedFile",
",",
"$",
"args",
")",
";",
"}"
] | Sets up a form field to let users pick a file of a specific type.
@param int $type One of the \Concrete\Core\File\Type\Type::T_... constants.
@param string $inputID The ID of your form field
@param string $inputName The name of the form field (the selected file ID will be posted with this name)
@param string $chooseText The text to be used to tell users "Choose a File"
@param \Concrete\Core\Entity\File\File|\Concrete\Core\Entity\File\Version|int|null $preselectedFile the pre-selected file (or its ID)
@param array $args See the $args description of the <code>file</code> method
@return string
@see \Concrete\Core\Application\Service\FileManager::file() | [
"Sets",
"up",
"a",
"form",
"field",
"to",
"let",
"users",
"pick",
"a",
"file",
"of",
"a",
"specific",
"type",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Application/Service/FileManager.php#L221-L240 | train |
concrete5/concrete5 | concrete/src/Tree/Tree.php | Tree.getNodeByDisplayPath | public function getNodeByDisplayPath($path)
{
$root = $this->getRootTreeNodeObject();
if ($path == '/' || !$path) {
return $root;
}
$computedPath = '';
$tree = $this;
$walk = function ($node, $computedPath) use (&$walk, &$tree, &$path) {
$node->populateDirectChildrenOnly();
if ($node->getTreeNodeID() != $tree->getRootTreeNodeID()) {
$name = $node->getTreeNodeName();
$computedPath .= '/' . $name;
}
if (strcasecmp($computedPath, $path) == 0) {
return $node;
} else {
$children = $node->getChildNodes();
foreach ($children as $child) {
$node = $walk($child, $computedPath);
if ($node !== null) {
return $node;
}
}
}
return;
};
$node = $walk($root, $computedPath);
return $node;
} | php | public function getNodeByDisplayPath($path)
{
$root = $this->getRootTreeNodeObject();
if ($path == '/' || !$path) {
return $root;
}
$computedPath = '';
$tree = $this;
$walk = function ($node, $computedPath) use (&$walk, &$tree, &$path) {
$node->populateDirectChildrenOnly();
if ($node->getTreeNodeID() != $tree->getRootTreeNodeID()) {
$name = $node->getTreeNodeName();
$computedPath .= '/' . $name;
}
if (strcasecmp($computedPath, $path) == 0) {
return $node;
} else {
$children = $node->getChildNodes();
foreach ($children as $child) {
$node = $walk($child, $computedPath);
if ($node !== null) {
return $node;
}
}
}
return;
};
$node = $walk($root, $computedPath);
return $node;
} | [
"public",
"function",
"getNodeByDisplayPath",
"(",
"$",
"path",
")",
"{",
"$",
"root",
"=",
"$",
"this",
"->",
"getRootTreeNodeObject",
"(",
")",
";",
"if",
"(",
"$",
"path",
"==",
"'/'",
"||",
"!",
"$",
"path",
")",
"{",
"return",
"$",
"root",
";",
"}",
"$",
"computedPath",
"=",
"''",
";",
"$",
"tree",
"=",
"$",
"this",
";",
"$",
"walk",
"=",
"function",
"(",
"$",
"node",
",",
"$",
"computedPath",
")",
"use",
"(",
"&",
"$",
"walk",
",",
"&",
"$",
"tree",
",",
"&",
"$",
"path",
")",
"{",
"$",
"node",
"->",
"populateDirectChildrenOnly",
"(",
")",
";",
"if",
"(",
"$",
"node",
"->",
"getTreeNodeID",
"(",
")",
"!=",
"$",
"tree",
"->",
"getRootTreeNodeID",
"(",
")",
")",
"{",
"$",
"name",
"=",
"$",
"node",
"->",
"getTreeNodeName",
"(",
")",
";",
"$",
"computedPath",
".=",
"'/'",
".",
"$",
"name",
";",
"}",
"if",
"(",
"strcasecmp",
"(",
"$",
"computedPath",
",",
"$",
"path",
")",
"==",
"0",
")",
"{",
"return",
"$",
"node",
";",
"}",
"else",
"{",
"$",
"children",
"=",
"$",
"node",
"->",
"getChildNodes",
"(",
")",
";",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"node",
"=",
"$",
"walk",
"(",
"$",
"child",
",",
"$",
"computedPath",
")",
";",
"if",
"(",
"$",
"node",
"!==",
"null",
")",
"{",
"return",
"$",
"node",
";",
"}",
"}",
"}",
"return",
";",
"}",
";",
"$",
"node",
"=",
"$",
"walk",
"(",
"$",
"root",
",",
"$",
"computedPath",
")",
";",
"return",
"$",
"node",
";",
"}"
] | Iterates through the segments in the path, to return the node at the proper display. Mostly used for export
and import.
@param $path | [
"Iterates",
"through",
"the",
"segments",
"in",
"the",
"path",
"to",
"return",
"the",
"node",
"at",
"the",
"proper",
"display",
".",
"Mostly",
"used",
"for",
"export",
"and",
"import",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Tree/Tree.php#L124-L159 | train |
concrete5/concrete5 | concrete/src/Tree/Tree.php | Tree.exportTranslations | public static function exportTranslations()
{
$translations = new Translations();
$loc = Localization::getInstance();
$loc->pushActiveContext(Localization::CONTEXT_SYSTEM);
try {
$app = Application::getFacadeApplication();
$db = $app->make('database')->connection();
$r = $db->executeQuery('select treeID from Trees order by treeID asc');
while ($row = $r->fetch()) {
try {
$tree = static::getByID($row['treeID']);
} catch (Exception $x) {
$tree = null;
}
if (isset($tree)) {
/* @var $tree Tree */
$treeName = $tree->getTreeName();
if (is_string($treeName) && ($treeName !== '')) {
$translations->insert('TreeName', $treeName);
}
$rootNode = $tree->getRootTreeNodeObject();
/* @var $rootNode TreeNode */
if (isset($rootNode)) {
$rootNode->exportTranslations($translations);
}
}
}
} catch (Exception $x) {
$loc->popActiveContext();
throw $x;
}
$loc->popActiveContext();
return $translations;
} | php | public static function exportTranslations()
{
$translations = new Translations();
$loc = Localization::getInstance();
$loc->pushActiveContext(Localization::CONTEXT_SYSTEM);
try {
$app = Application::getFacadeApplication();
$db = $app->make('database')->connection();
$r = $db->executeQuery('select treeID from Trees order by treeID asc');
while ($row = $r->fetch()) {
try {
$tree = static::getByID($row['treeID']);
} catch (Exception $x) {
$tree = null;
}
if (isset($tree)) {
/* @var $tree Tree */
$treeName = $tree->getTreeName();
if (is_string($treeName) && ($treeName !== '')) {
$translations->insert('TreeName', $treeName);
}
$rootNode = $tree->getRootTreeNodeObject();
/* @var $rootNode TreeNode */
if (isset($rootNode)) {
$rootNode->exportTranslations($translations);
}
}
}
} catch (Exception $x) {
$loc->popActiveContext();
throw $x;
}
$loc->popActiveContext();
return $translations;
} | [
"public",
"static",
"function",
"exportTranslations",
"(",
")",
"{",
"$",
"translations",
"=",
"new",
"Translations",
"(",
")",
";",
"$",
"loc",
"=",
"Localization",
"::",
"getInstance",
"(",
")",
";",
"$",
"loc",
"->",
"pushActiveContext",
"(",
"Localization",
"::",
"CONTEXT_SYSTEM",
")",
";",
"try",
"{",
"$",
"app",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"db",
"=",
"$",
"app",
"->",
"make",
"(",
"'database'",
")",
"->",
"connection",
"(",
")",
";",
"$",
"r",
"=",
"$",
"db",
"->",
"executeQuery",
"(",
"'select treeID from Trees order by treeID asc'",
")",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"r",
"->",
"fetch",
"(",
")",
")",
"{",
"try",
"{",
"$",
"tree",
"=",
"static",
"::",
"getByID",
"(",
"$",
"row",
"[",
"'treeID'",
"]",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"x",
")",
"{",
"$",
"tree",
"=",
"null",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"tree",
")",
")",
"{",
"/* @var $tree Tree */",
"$",
"treeName",
"=",
"$",
"tree",
"->",
"getTreeName",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"treeName",
")",
"&&",
"(",
"$",
"treeName",
"!==",
"''",
")",
")",
"{",
"$",
"translations",
"->",
"insert",
"(",
"'TreeName'",
",",
"$",
"treeName",
")",
";",
"}",
"$",
"rootNode",
"=",
"$",
"tree",
"->",
"getRootTreeNodeObject",
"(",
")",
";",
"/* @var $rootNode TreeNode */",
"if",
"(",
"isset",
"(",
"$",
"rootNode",
")",
")",
"{",
"$",
"rootNode",
"->",
"exportTranslations",
"(",
"$",
"translations",
")",
";",
"}",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"x",
")",
"{",
"$",
"loc",
"->",
"popActiveContext",
"(",
")",
";",
"throw",
"$",
"x",
";",
"}",
"$",
"loc",
"->",
"popActiveContext",
"(",
")",
";",
"return",
"$",
"translations",
";",
"}"
] | Export all the translations associates to every trees.
@return Translations | [
"Export",
"all",
"the",
"translations",
"associates",
"to",
"every",
"trees",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Tree/Tree.php#L255-L290 | train |
concrete5/concrete5 | concrete/src/File/Service/File.php | File.getDirectoryContents | public function getDirectoryContents($dir, $ignoreFiles = [], $recursive = false)
{
$aDir = [];
if (is_dir($dir)) {
$handle = opendir($dir);
while (($file = readdir($handle)) !== false) {
if (substr($file, 0, 1) != '.' && (!in_array($file, $ignoreFiles))) {
if (is_dir($dir . '/' . $file)) {
if ($recursive) {
$aDir = array_merge($aDir, $this->getDirectoryContents($dir . '/' . $file, $ignoreFiles, $recursive));
$file = $dir . '/' . $file;
}
$aDir[] = preg_replace("/\/\//si", '/', $file);
} else {
if ($recursive) {
$file = $dir . '/' . $file;
}
$aDir[] = preg_replace("/\/\//si", '/', $file);
}
}
}
closedir($handle);
}
return $aDir;
} | php | public function getDirectoryContents($dir, $ignoreFiles = [], $recursive = false)
{
$aDir = [];
if (is_dir($dir)) {
$handle = opendir($dir);
while (($file = readdir($handle)) !== false) {
if (substr($file, 0, 1) != '.' && (!in_array($file, $ignoreFiles))) {
if (is_dir($dir . '/' . $file)) {
if ($recursive) {
$aDir = array_merge($aDir, $this->getDirectoryContents($dir . '/' . $file, $ignoreFiles, $recursive));
$file = $dir . '/' . $file;
}
$aDir[] = preg_replace("/\/\//si", '/', $file);
} else {
if ($recursive) {
$file = $dir . '/' . $file;
}
$aDir[] = preg_replace("/\/\//si", '/', $file);
}
}
}
closedir($handle);
}
return $aDir;
} | [
"public",
"function",
"getDirectoryContents",
"(",
"$",
"dir",
",",
"$",
"ignoreFiles",
"=",
"[",
"]",
",",
"$",
"recursive",
"=",
"false",
")",
"{",
"$",
"aDir",
"=",
"[",
"]",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"handle",
"=",
"opendir",
"(",
"$",
"dir",
")",
";",
"while",
"(",
"(",
"$",
"file",
"=",
"readdir",
"(",
"$",
"handle",
")",
")",
"!==",
"false",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"file",
",",
"0",
",",
"1",
")",
"!=",
"'.'",
"&&",
"(",
"!",
"in_array",
"(",
"$",
"file",
",",
"$",
"ignoreFiles",
")",
")",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
".",
"'/'",
".",
"$",
"file",
")",
")",
"{",
"if",
"(",
"$",
"recursive",
")",
"{",
"$",
"aDir",
"=",
"array_merge",
"(",
"$",
"aDir",
",",
"$",
"this",
"->",
"getDirectoryContents",
"(",
"$",
"dir",
".",
"'/'",
".",
"$",
"file",
",",
"$",
"ignoreFiles",
",",
"$",
"recursive",
")",
")",
";",
"$",
"file",
"=",
"$",
"dir",
".",
"'/'",
".",
"$",
"file",
";",
"}",
"$",
"aDir",
"[",
"]",
"=",
"preg_replace",
"(",
"\"/\\/\\//si\"",
",",
"'/'",
",",
"$",
"file",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"recursive",
")",
"{",
"$",
"file",
"=",
"$",
"dir",
".",
"'/'",
".",
"$",
"file",
";",
"}",
"$",
"aDir",
"[",
"]",
"=",
"preg_replace",
"(",
"\"/\\/\\//si\"",
",",
"'/'",
",",
"$",
"file",
")",
";",
"}",
"}",
"}",
"closedir",
"(",
"$",
"handle",
")",
";",
"}",
"return",
"$",
"aDir",
";",
"}"
] | Returns the contents of a directory. | [
"Returns",
"the",
"contents",
"of",
"a",
"directory",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Service/File.php#L39-L64 | train |
concrete5/concrete5 | concrete/src/File/Service/File.php | File.unfilename | public function unfilename($filename)
{
$parts = $this->splitFilename($filename);
$txt = Core::make('helper/text');
/* @var $txt \Concrete\Core\Utility\Service\Text */
return $txt->unhandle($parts[0] . $parts[1]);
} | php | public function unfilename($filename)
{
$parts = $this->splitFilename($filename);
$txt = Core::make('helper/text');
/* @var $txt \Concrete\Core\Utility\Service\Text */
return $txt->unhandle($parts[0] . $parts[1]);
} | [
"public",
"function",
"unfilename",
"(",
"$",
"filename",
")",
"{",
"$",
"parts",
"=",
"$",
"this",
"->",
"splitFilename",
"(",
"$",
"filename",
")",
";",
"$",
"txt",
"=",
"Core",
"::",
"make",
"(",
"'helper/text'",
")",
";",
"/* @var $txt \\Concrete\\Core\\Utility\\Service\\Text */",
"return",
"$",
"txt",
"->",
"unhandle",
"(",
"$",
"parts",
"[",
"0",
"]",
".",
"$",
"parts",
"[",
"1",
"]",
")",
";",
"}"
] | Removes the extension of a filename, uncamelcases it.
@param string $filename
@return string | [
"Removes",
"the",
"extension",
"of",
"a",
"filename",
"uncamelcases",
"it",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Service/File.php#L72-L79 | train |
concrete5/concrete5 | concrete/src/File/Service/File.php | File.copyAll | public function copyAll($source, $target, $mode = null)
{
if (is_dir($source)) {
if ($mode == null) {
@mkdir($target, Config::get('concrete.filesystem.permissions.directory'));
@chmod($target, Config::get('concrete.filesystem.permissions.directory'));
} else {
@mkdir($target, $mode);
@chmod($target, $mode);
}
$d = dir($source);
while (false !== ($entry = $d->read())) {
if (substr($entry, 0, 1) === '.') {
continue;
}
$Entry = $source . '/' . $entry;
if (is_dir($Entry)) {
$this->copyAll($Entry, $target . '/' . $entry, $mode);
continue;
}
copy($Entry, $target . '/' . $entry);
if ($mode == null) {
@chmod($target . '/' . $entry, $this->getCreateFilePermissions($target)->file);
} else {
@chmod($target . '/' . $entry, $mode);
}
}
$d->close();
} else {
if ($mode == null) {
$mode = $this->getCreateFilePermissions(dirname($target))->file;
}
copy($source, $target);
chmod($target, $mode);
}
} | php | public function copyAll($source, $target, $mode = null)
{
if (is_dir($source)) {
if ($mode == null) {
@mkdir($target, Config::get('concrete.filesystem.permissions.directory'));
@chmod($target, Config::get('concrete.filesystem.permissions.directory'));
} else {
@mkdir($target, $mode);
@chmod($target, $mode);
}
$d = dir($source);
while (false !== ($entry = $d->read())) {
if (substr($entry, 0, 1) === '.') {
continue;
}
$Entry = $source . '/' . $entry;
if (is_dir($Entry)) {
$this->copyAll($Entry, $target . '/' . $entry, $mode);
continue;
}
copy($Entry, $target . '/' . $entry);
if ($mode == null) {
@chmod($target . '/' . $entry, $this->getCreateFilePermissions($target)->file);
} else {
@chmod($target . '/' . $entry, $mode);
}
}
$d->close();
} else {
if ($mode == null) {
$mode = $this->getCreateFilePermissions(dirname($target))->file;
}
copy($source, $target);
chmod($target, $mode);
}
} | [
"public",
"function",
"copyAll",
"(",
"$",
"source",
",",
"$",
"target",
",",
"$",
"mode",
"=",
"null",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"source",
")",
")",
"{",
"if",
"(",
"$",
"mode",
"==",
"null",
")",
"{",
"@",
"mkdir",
"(",
"$",
"target",
",",
"Config",
"::",
"get",
"(",
"'concrete.filesystem.permissions.directory'",
")",
")",
";",
"@",
"chmod",
"(",
"$",
"target",
",",
"Config",
"::",
"get",
"(",
"'concrete.filesystem.permissions.directory'",
")",
")",
";",
"}",
"else",
"{",
"@",
"mkdir",
"(",
"$",
"target",
",",
"$",
"mode",
")",
";",
"@",
"chmod",
"(",
"$",
"target",
",",
"$",
"mode",
")",
";",
"}",
"$",
"d",
"=",
"dir",
"(",
"$",
"source",
")",
";",
"while",
"(",
"false",
"!==",
"(",
"$",
"entry",
"=",
"$",
"d",
"->",
"read",
"(",
")",
")",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"entry",
",",
"0",
",",
"1",
")",
"===",
"'.'",
")",
"{",
"continue",
";",
"}",
"$",
"Entry",
"=",
"$",
"source",
".",
"'/'",
".",
"$",
"entry",
";",
"if",
"(",
"is_dir",
"(",
"$",
"Entry",
")",
")",
"{",
"$",
"this",
"->",
"copyAll",
"(",
"$",
"Entry",
",",
"$",
"target",
".",
"'/'",
".",
"$",
"entry",
",",
"$",
"mode",
")",
";",
"continue",
";",
"}",
"copy",
"(",
"$",
"Entry",
",",
"$",
"target",
".",
"'/'",
".",
"$",
"entry",
")",
";",
"if",
"(",
"$",
"mode",
"==",
"null",
")",
"{",
"@",
"chmod",
"(",
"$",
"target",
".",
"'/'",
".",
"$",
"entry",
",",
"$",
"this",
"->",
"getCreateFilePermissions",
"(",
"$",
"target",
")",
"->",
"file",
")",
";",
"}",
"else",
"{",
"@",
"chmod",
"(",
"$",
"target",
".",
"'/'",
".",
"$",
"entry",
",",
"$",
"mode",
")",
";",
"}",
"}",
"$",
"d",
"->",
"close",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"mode",
"==",
"null",
")",
"{",
"$",
"mode",
"=",
"$",
"this",
"->",
"getCreateFilePermissions",
"(",
"dirname",
"(",
"$",
"target",
")",
")",
"->",
"file",
";",
"}",
"copy",
"(",
"$",
"source",
",",
"$",
"target",
")",
";",
"chmod",
"(",
"$",
"target",
",",
"$",
"mode",
")",
";",
"}",
"}"
] | Recursively copies all items in the source directory or file to the target directory.
@param string $source Source dir/file to copy
@param string $target Place to copy the source
@param int $mode What to chmod the file to | [
"Recursively",
"copies",
"all",
"items",
"in",
"the",
"source",
"directory",
"or",
"file",
"to",
"the",
"target",
"directory",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Service/File.php#L88-L127 | train |
concrete5/concrete5 | concrete/src/File/Service/File.php | File.removeAll | public function removeAll($source, $inc = false)
{
if (!is_dir($source)) {
return false;
}
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($source, \FilesystemIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($iterator as $path) {
if ($path->isDir()) {
if (!@rmdir($path->__toString())) {
return false;
}
} else {
if (!@unlink($path->__toString())) {
return false;
}
}
}
if ($inc) {
if (!@rmdir($source)) {
return false;
}
}
return true;
} | php | public function removeAll($source, $inc = false)
{
if (!is_dir($source)) {
return false;
}
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($source, \FilesystemIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($iterator as $path) {
if ($path->isDir()) {
if (!@rmdir($path->__toString())) {
return false;
}
} else {
if (!@unlink($path->__toString())) {
return false;
}
}
}
if ($inc) {
if (!@rmdir($source)) {
return false;
}
}
return true;
} | [
"public",
"function",
"removeAll",
"(",
"$",
"source",
",",
"$",
"inc",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"source",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"iterator",
"=",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"new",
"\\",
"RecursiveDirectoryIterator",
"(",
"$",
"source",
",",
"\\",
"FilesystemIterator",
"::",
"SKIP_DOTS",
")",
",",
"\\",
"RecursiveIteratorIterator",
"::",
"CHILD_FIRST",
")",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"path",
"->",
"isDir",
"(",
")",
")",
"{",
"if",
"(",
"!",
"@",
"rmdir",
"(",
"$",
"path",
"->",
"__toString",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"@",
"unlink",
"(",
"$",
"path",
"->",
"__toString",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"inc",
")",
"{",
"if",
"(",
"!",
"@",
"rmdir",
"(",
"$",
"source",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Removes all files from within a specified directory.
@param string $source Directory
@param bool $inc Remove the passed directory as well or leave it alone
@return bool Whether the methods succeeds or fails | [
"Removes",
"all",
"files",
"from",
"within",
"a",
"specified",
"directory",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Service/File.php#L185-L214 | train |
concrete5/concrete5 | concrete/src/File/Service/File.php | File.forceDownload | public function forceDownload($file)
{
session_write_close();
ob_clean();
header('Content-type: application/octet-stream');
$filename = basename($file);
header("Content-Disposition: attachment; filename=\"$filename\"");
header('Content-Length: ' . filesize($file));
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Transfer-Encoding: binary");
header("Content-Encoding: plainbinary");
// This code isn't ready yet. It will allow us to no longer force download
/*
$h = Core::make('helper/mime');
$mimeType = $h->mimeFromExtension($this->getExtension($file));
header('Content-type: ' . $mimeType);
*/
$buffer = '';
$chunk = 1024 * 1024;
$handle = fopen($file, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, $chunk);
echo $buffer;
}
fclose($handle);
exit;
} | php | public function forceDownload($file)
{
session_write_close();
ob_clean();
header('Content-type: application/octet-stream');
$filename = basename($file);
header("Content-Disposition: attachment; filename=\"$filename\"");
header('Content-Length: ' . filesize($file));
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Transfer-Encoding: binary");
header("Content-Encoding: plainbinary");
// This code isn't ready yet. It will allow us to no longer force download
/*
$h = Core::make('helper/mime');
$mimeType = $h->mimeFromExtension($this->getExtension($file));
header('Content-type: ' . $mimeType);
*/
$buffer = '';
$chunk = 1024 * 1024;
$handle = fopen($file, 'rb');
if ($handle === false) {
return false;
}
while (!feof($handle)) {
$buffer = fread($handle, $chunk);
echo $buffer;
}
fclose($handle);
exit;
} | [
"public",
"function",
"forceDownload",
"(",
"$",
"file",
")",
"{",
"session_write_close",
"(",
")",
";",
"ob_clean",
"(",
")",
";",
"header",
"(",
"'Content-type: application/octet-stream'",
")",
";",
"$",
"filename",
"=",
"basename",
"(",
"$",
"file",
")",
";",
"header",
"(",
"\"Content-Disposition: attachment; filename=\\\"$filename\\\"\"",
")",
";",
"header",
"(",
"'Content-Length: '",
".",
"filesize",
"(",
"$",
"file",
")",
")",
";",
"header",
"(",
"\"Pragma: public\"",
")",
";",
"header",
"(",
"\"Expires: 0\"",
")",
";",
"header",
"(",
"\"Cache-Control: must-revalidate, post-check=0, pre-check=0\"",
")",
";",
"header",
"(",
"\"Cache-Control: private\"",
",",
"false",
")",
";",
"header",
"(",
"\"Content-Transfer-Encoding: binary\"",
")",
";",
"header",
"(",
"\"Content-Encoding: plainbinary\"",
")",
";",
"// This code isn't ready yet. It will allow us to no longer force download",
"/*\n $h = Core::make('helper/mime');\n $mimeType = $h->mimeFromExtension($this->getExtension($file));\n header('Content-type: ' . $mimeType);\n */",
"$",
"buffer",
"=",
"''",
";",
"$",
"chunk",
"=",
"1024",
"*",
"1024",
";",
"$",
"handle",
"=",
"fopen",
"(",
"$",
"file",
",",
"'rb'",
")",
";",
"if",
"(",
"$",
"handle",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"while",
"(",
"!",
"feof",
"(",
"$",
"handle",
")",
")",
"{",
"$",
"buffer",
"=",
"fread",
"(",
"$",
"handle",
",",
"$",
"chunk",
")",
";",
"echo",
"$",
"buffer",
";",
"}",
"fclose",
"(",
"$",
"handle",
")",
";",
"exit",
";",
"}"
] | Takes a path to a file and sends it to the browser, streaming it, and closing the HTTP connection afterwards. Basically a force download method.
@param stings $file | [
"Takes",
"a",
"path",
"to",
"a",
"file",
"and",
"sends",
"it",
"to",
"the",
"browser",
"streaming",
"it",
"and",
"closing",
"the",
"HTTP",
"connection",
"afterwards",
".",
"Basically",
"a",
"force",
"download",
"method",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Service/File.php#L221-L257 | train |
concrete5/concrete5 | concrete/src/File/Service/File.php | File.getTemporaryDirectory | public function getTemporaryDirectory()
{
$temp = Config::get('concrete.filesystem.temp_directory');
if ($temp && @is_dir($temp)) {
return $temp;
}
if (!is_dir(DIR_FILES_UPLOADED_STANDARD . '/tmp')) {
@mkdir(DIR_FILES_UPLOADED_STANDARD . '/tmp', Config::get('concrete.filesystem.permissions.directory'));
@chmod(DIR_FILES_UPLOADED_STANDARD . '/tmp', Config::get('concrete.filesystem.permissions.directory'));
@touch(DIR_FILES_UPLOADED_STANDARD . '/tmp/index.html');
}
if (is_dir(DIR_FILES_UPLOADED_STANDARD . '/tmp') && is_writable(DIR_FILES_UPLOADED_STANDARD . '/tmp')) {
return DIR_FILES_UPLOADED_STANDARD . '/tmp';
}
if ($temp = getenv('TMP')) {
return str_replace(DIRECTORY_SEPARATOR, '/', $temp);
}
if ($temp = getenv('TEMP')) {
return str_replace(DIRECTORY_SEPARATOR, '/', $temp);
}
if ($temp = getenv('TMPDIR')) {
return str_replace(DIRECTORY_SEPARATOR, '/', $temp);
}
$temp = @tempnam(__FILE__, '');
if (file_exists($temp)) {
unlink($temp);
return str_replace(DIRECTORY_SEPARATOR, '/', dirname($temp));
}
} | php | public function getTemporaryDirectory()
{
$temp = Config::get('concrete.filesystem.temp_directory');
if ($temp && @is_dir($temp)) {
return $temp;
}
if (!is_dir(DIR_FILES_UPLOADED_STANDARD . '/tmp')) {
@mkdir(DIR_FILES_UPLOADED_STANDARD . '/tmp', Config::get('concrete.filesystem.permissions.directory'));
@chmod(DIR_FILES_UPLOADED_STANDARD . '/tmp', Config::get('concrete.filesystem.permissions.directory'));
@touch(DIR_FILES_UPLOADED_STANDARD . '/tmp/index.html');
}
if (is_dir(DIR_FILES_UPLOADED_STANDARD . '/tmp') && is_writable(DIR_FILES_UPLOADED_STANDARD . '/tmp')) {
return DIR_FILES_UPLOADED_STANDARD . '/tmp';
}
if ($temp = getenv('TMP')) {
return str_replace(DIRECTORY_SEPARATOR, '/', $temp);
}
if ($temp = getenv('TEMP')) {
return str_replace(DIRECTORY_SEPARATOR, '/', $temp);
}
if ($temp = getenv('TMPDIR')) {
return str_replace(DIRECTORY_SEPARATOR, '/', $temp);
}
$temp = @tempnam(__FILE__, '');
if (file_exists($temp)) {
unlink($temp);
return str_replace(DIRECTORY_SEPARATOR, '/', dirname($temp));
}
} | [
"public",
"function",
"getTemporaryDirectory",
"(",
")",
"{",
"$",
"temp",
"=",
"Config",
"::",
"get",
"(",
"'concrete.filesystem.temp_directory'",
")",
";",
"if",
"(",
"$",
"temp",
"&&",
"@",
"is_dir",
"(",
"$",
"temp",
")",
")",
"{",
"return",
"$",
"temp",
";",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"DIR_FILES_UPLOADED_STANDARD",
".",
"'/tmp'",
")",
")",
"{",
"@",
"mkdir",
"(",
"DIR_FILES_UPLOADED_STANDARD",
".",
"'/tmp'",
",",
"Config",
"::",
"get",
"(",
"'concrete.filesystem.permissions.directory'",
")",
")",
";",
"@",
"chmod",
"(",
"DIR_FILES_UPLOADED_STANDARD",
".",
"'/tmp'",
",",
"Config",
"::",
"get",
"(",
"'concrete.filesystem.permissions.directory'",
")",
")",
";",
"@",
"touch",
"(",
"DIR_FILES_UPLOADED_STANDARD",
".",
"'/tmp/index.html'",
")",
";",
"}",
"if",
"(",
"is_dir",
"(",
"DIR_FILES_UPLOADED_STANDARD",
".",
"'/tmp'",
")",
"&&",
"is_writable",
"(",
"DIR_FILES_UPLOADED_STANDARD",
".",
"'/tmp'",
")",
")",
"{",
"return",
"DIR_FILES_UPLOADED_STANDARD",
".",
"'/tmp'",
";",
"}",
"if",
"(",
"$",
"temp",
"=",
"getenv",
"(",
"'TMP'",
")",
")",
"{",
"return",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"'/'",
",",
"$",
"temp",
")",
";",
"}",
"if",
"(",
"$",
"temp",
"=",
"getenv",
"(",
"'TEMP'",
")",
")",
"{",
"return",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"'/'",
",",
"$",
"temp",
")",
";",
"}",
"if",
"(",
"$",
"temp",
"=",
"getenv",
"(",
"'TMPDIR'",
")",
")",
"{",
"return",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"'/'",
",",
"$",
"temp",
")",
";",
"}",
"$",
"temp",
"=",
"@",
"tempnam",
"(",
"__FILE__",
",",
"''",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"temp",
")",
")",
"{",
"unlink",
"(",
"$",
"temp",
")",
";",
"return",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"'/'",
",",
"dirname",
"(",
"$",
"temp",
")",
")",
";",
"}",
"}"
] | Returns the full path to the temporary directory.
@return string | [
"Returns",
"the",
"full",
"path",
"to",
"the",
"temporary",
"directory",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Service/File.php#L264-L297 | train |
concrete5/concrete5 | concrete/src/File/Service/File.php | File.sanitize | public function sanitize($file)
{
// Let's build an ASCII-only version of name, to avoid filesystem-specific encoding issues.
$asciiName = Core::make('helper/text')->asciify($file);
// Let's keep only letters, numbers, underscore and dots.
$asciiName = trim(preg_replace(["/[\\s]/", "/[^0-9A-Z_a-z-.]/"], ["_", ""], $asciiName));
// Trim underscores at start and end
$asciiName = trim($asciiName, '_');
if (!strlen(str_replace('.', '', $asciiName))) {
// If the resulting name is empty (or we have only dots in it)
$asciiName = md5($file);
} elseif (preg_match('/^\.\w+$/', $asciiName)) {
// If the resulting name is only composed by the file extension
$asciiName = md5($file) . $asciiName;
}
return $asciiName;
} | php | public function sanitize($file)
{
// Let's build an ASCII-only version of name, to avoid filesystem-specific encoding issues.
$asciiName = Core::make('helper/text')->asciify($file);
// Let's keep only letters, numbers, underscore and dots.
$asciiName = trim(preg_replace(["/[\\s]/", "/[^0-9A-Z_a-z-.]/"], ["_", ""], $asciiName));
// Trim underscores at start and end
$asciiName = trim($asciiName, '_');
if (!strlen(str_replace('.', '', $asciiName))) {
// If the resulting name is empty (or we have only dots in it)
$asciiName = md5($file);
} elseif (preg_match('/^\.\w+$/', $asciiName)) {
// If the resulting name is only composed by the file extension
$asciiName = md5($file) . $asciiName;
}
return $asciiName;
} | [
"public",
"function",
"sanitize",
"(",
"$",
"file",
")",
"{",
"// Let's build an ASCII-only version of name, to avoid filesystem-specific encoding issues.",
"$",
"asciiName",
"=",
"Core",
"::",
"make",
"(",
"'helper/text'",
")",
"->",
"asciify",
"(",
"$",
"file",
")",
";",
"// Let's keep only letters, numbers, underscore and dots.",
"$",
"asciiName",
"=",
"trim",
"(",
"preg_replace",
"(",
"[",
"\"/[\\\\s]/\"",
",",
"\"/[^0-9A-Z_a-z-.]/\"",
"]",
",",
"[",
"\"_\"",
",",
"\"\"",
"]",
",",
"$",
"asciiName",
")",
")",
";",
"// Trim underscores at start and end",
"$",
"asciiName",
"=",
"trim",
"(",
"$",
"asciiName",
",",
"'_'",
")",
";",
"if",
"(",
"!",
"strlen",
"(",
"str_replace",
"(",
"'.'",
",",
"''",
",",
"$",
"asciiName",
")",
")",
")",
"{",
"// If the resulting name is empty (or we have only dots in it)",
"$",
"asciiName",
"=",
"md5",
"(",
"$",
"file",
")",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/^\\.\\w+$/'",
",",
"$",
"asciiName",
")",
")",
"{",
"// If the resulting name is only composed by the file extension",
"$",
"asciiName",
"=",
"md5",
"(",
"$",
"file",
")",
".",
"$",
"asciiName",
";",
"}",
"return",
"$",
"asciiName",
";",
"}"
] | Cleans up a filename and returns the cleaned up version.
@param string $file
@return string | [
"Cleans",
"up",
"a",
"filename",
"and",
"returns",
"the",
"cleaned",
"up",
"version",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Service/File.php#L370-L387 | train |
concrete5/concrete5 | concrete/src/File/Service/File.php | File.replaceExtension | public function replaceExtension($filename, $extension)
{
$parts = $this->splitFilename($filename);
$newFilename = $parts[0] . $parts[1];
if (is_string($extension) && ($extension !== '')) {
$newFilename .= '.' . $extension;
}
return $newFilename;
} | php | public function replaceExtension($filename, $extension)
{
$parts = $this->splitFilename($filename);
$newFilename = $parts[0] . $parts[1];
if (is_string($extension) && ($extension !== '')) {
$newFilename .= '.' . $extension;
}
return $newFilename;
} | [
"public",
"function",
"replaceExtension",
"(",
"$",
"filename",
",",
"$",
"extension",
")",
"{",
"$",
"parts",
"=",
"$",
"this",
"->",
"splitFilename",
"(",
"$",
"filename",
")",
";",
"$",
"newFilename",
"=",
"$",
"parts",
"[",
"0",
"]",
".",
"$",
"parts",
"[",
"1",
"]",
";",
"if",
"(",
"is_string",
"(",
"$",
"extension",
")",
"&&",
"(",
"$",
"extension",
"!==",
"''",
")",
")",
"{",
"$",
"newFilename",
".=",
"'.'",
".",
"$",
"extension",
";",
"}",
"return",
"$",
"newFilename",
";",
"}"
] | Takes a path and replaces the files extension in that path with the specified extension.
@param string $filename
@param string $extension
@return string | [
"Takes",
"a",
"path",
"and",
"replaces",
"the",
"files",
"extension",
"in",
"that",
"path",
"with",
"the",
"specified",
"extension",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Service/File.php#L439-L448 | train |
concrete5/concrete5 | concrete/src/File/Service/File.php | File.isSamePath | public function isSamePath($path1, $path2)
{
$path1 = str_replace(DIRECTORY_SEPARATOR, '/', $path1);
$path2 = str_replace(DIRECTORY_SEPARATOR, '/', $path2);
// Check if OS is case insensitive
$checkFile = strtoupper(__FILE__);
if ($checkFile === __FILE__) {
$checkFile = strtolower(__FILE__);
}
if (@is_file($checkFile)) {
$same = (strcasecmp($path1, $path2) === 0) ? true : false;
} else {
$same = ($path1 === $path2) ? true : false;
}
return $same;
} | php | public function isSamePath($path1, $path2)
{
$path1 = str_replace(DIRECTORY_SEPARATOR, '/', $path1);
$path2 = str_replace(DIRECTORY_SEPARATOR, '/', $path2);
// Check if OS is case insensitive
$checkFile = strtoupper(__FILE__);
if ($checkFile === __FILE__) {
$checkFile = strtolower(__FILE__);
}
if (@is_file($checkFile)) {
$same = (strcasecmp($path1, $path2) === 0) ? true : false;
} else {
$same = ($path1 === $path2) ? true : false;
}
return $same;
} | [
"public",
"function",
"isSamePath",
"(",
"$",
"path1",
",",
"$",
"path2",
")",
"{",
"$",
"path1",
"=",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"'/'",
",",
"$",
"path1",
")",
";",
"$",
"path2",
"=",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"'/'",
",",
"$",
"path2",
")",
";",
"// Check if OS is case insensitive",
"$",
"checkFile",
"=",
"strtoupper",
"(",
"__FILE__",
")",
";",
"if",
"(",
"$",
"checkFile",
"===",
"__FILE__",
")",
"{",
"$",
"checkFile",
"=",
"strtolower",
"(",
"__FILE__",
")",
";",
"}",
"if",
"(",
"@",
"is_file",
"(",
"$",
"checkFile",
")",
")",
"{",
"$",
"same",
"=",
"(",
"strcasecmp",
"(",
"$",
"path1",
",",
"$",
"path2",
")",
"===",
"0",
")",
"?",
"true",
":",
"false",
";",
"}",
"else",
"{",
"$",
"same",
"=",
"(",
"$",
"path1",
"===",
"$",
"path2",
")",
"?",
"true",
":",
"false",
";",
"}",
"return",
"$",
"same",
";",
"}"
] | Checks if two path are the same, considering directory separator and OS case sensitivity.
@param string $path1
@param string $path2
@return bool | [
"Checks",
"if",
"two",
"path",
"are",
"the",
"same",
"considering",
"directory",
"separator",
"and",
"OS",
"case",
"sensitivity",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Service/File.php#L458-L474 | train |
concrete5/concrete5 | concrete/src/File/Service/File.php | File.makeExecutable | public function makeExecutable($file, $who = 'all')
{
if (!is_file($file)) {
throw new Exception(t('File %s could not be found.', $file));
}
$perms = @fileperms($file);
if ($perms === false) {
throw new Exception(t('Unable to retrieve the permissions of the file %s', $file));
}
$currentMode = $perms & 0777;
switch ($who) {
case 'user':
$newMode = $currentMode | (1 << 0);
break;
case 'group':
$newMode = $currentMode | (1 << 3);
break;
case 'all':
$newMode = $currentMode | (1 << 6);
break;
default:
throw new Exception(t('Bad parameter: %s', '$who'));
}
if ($currentMode !== $newMode) {
if (@chmod($file, $newMode) === false) {
throw new Exception(t('Unable to set the permissions of the file %s', $file));
}
}
} | php | public function makeExecutable($file, $who = 'all')
{
if (!is_file($file)) {
throw new Exception(t('File %s could not be found.', $file));
}
$perms = @fileperms($file);
if ($perms === false) {
throw new Exception(t('Unable to retrieve the permissions of the file %s', $file));
}
$currentMode = $perms & 0777;
switch ($who) {
case 'user':
$newMode = $currentMode | (1 << 0);
break;
case 'group':
$newMode = $currentMode | (1 << 3);
break;
case 'all':
$newMode = $currentMode | (1 << 6);
break;
default:
throw new Exception(t('Bad parameter: %s', '$who'));
}
if ($currentMode !== $newMode) {
if (@chmod($file, $newMode) === false) {
throw new Exception(t('Unable to set the permissions of the file %s', $file));
}
}
} | [
"public",
"function",
"makeExecutable",
"(",
"$",
"file",
",",
"$",
"who",
"=",
"'all'",
")",
"{",
"if",
"(",
"!",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"t",
"(",
"'File %s could not be found.'",
",",
"$",
"file",
")",
")",
";",
"}",
"$",
"perms",
"=",
"@",
"fileperms",
"(",
"$",
"file",
")",
";",
"if",
"(",
"$",
"perms",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"t",
"(",
"'Unable to retrieve the permissions of the file %s'",
",",
"$",
"file",
")",
")",
";",
"}",
"$",
"currentMode",
"=",
"$",
"perms",
"&",
"0777",
";",
"switch",
"(",
"$",
"who",
")",
"{",
"case",
"'user'",
":",
"$",
"newMode",
"=",
"$",
"currentMode",
"|",
"(",
"1",
"<<",
"0",
")",
";",
"break",
";",
"case",
"'group'",
":",
"$",
"newMode",
"=",
"$",
"currentMode",
"|",
"(",
"1",
"<<",
"3",
")",
";",
"break",
";",
"case",
"'all'",
":",
"$",
"newMode",
"=",
"$",
"currentMode",
"|",
"(",
"1",
"<<",
"6",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"Exception",
"(",
"t",
"(",
"'Bad parameter: %s'",
",",
"'$who'",
")",
")",
";",
"}",
"if",
"(",
"$",
"currentMode",
"!==",
"$",
"newMode",
")",
"{",
"if",
"(",
"@",
"chmod",
"(",
"$",
"file",
",",
"$",
"newMode",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"t",
"(",
"'Unable to set the permissions of the file %s'",
",",
"$",
"file",
")",
")",
";",
"}",
"}",
"}"
] | Try to set the executable bit of a file.
@param string $file The full path
@param string $who One of 'user', 'group', 'all'
@throws Exception Throws an exception in case of errors | [
"Try",
"to",
"set",
"the",
"executable",
"bit",
"of",
"a",
"file",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Service/File.php#L484-L512 | train |
concrete5/concrete5 | concrete/src/Attribute/Category/UserCategory.php | UserCategory.saveFromRequest | protected function saveFromRequest(Key $key, Request $request)
{
$key->setAttributeKeyDisplayedOnProfile((string) $request->request->get('uakProfileDisplay') == 1);
$key->setAttributeKeyEditableOnProfile((string) $request->request->get('uakProfileEdit') == 1);
$key->setAttributeKeyRequiredOnProfile((string) $request->request->get('uakProfileEditRequired') == 1);
$key->setAttributeKeyEditableOnRegister((string) $request->request->get('uakRegisterEdit') == 1);
$key->setAttributeKeyRequiredOnRegister((string) $request->request->get('uakRegisterEditRequired') == 1);
$key->setAttributeKeyDisplayedOnMemberList((string) $request->request->get('uakMemberListDisplay') == 1);
// Actually save the changes to the database
$this->entityManager->flush();
return $key;
} | php | protected function saveFromRequest(Key $key, Request $request)
{
$key->setAttributeKeyDisplayedOnProfile((string) $request->request->get('uakProfileDisplay') == 1);
$key->setAttributeKeyEditableOnProfile((string) $request->request->get('uakProfileEdit') == 1);
$key->setAttributeKeyRequiredOnProfile((string) $request->request->get('uakProfileEditRequired') == 1);
$key->setAttributeKeyEditableOnRegister((string) $request->request->get('uakRegisterEdit') == 1);
$key->setAttributeKeyRequiredOnRegister((string) $request->request->get('uakRegisterEditRequired') == 1);
$key->setAttributeKeyDisplayedOnMemberList((string) $request->request->get('uakMemberListDisplay') == 1);
// Actually save the changes to the database
$this->entityManager->flush();
return $key;
} | [
"protected",
"function",
"saveFromRequest",
"(",
"Key",
"$",
"key",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"key",
"->",
"setAttributeKeyDisplayedOnProfile",
"(",
"(",
"string",
")",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'uakProfileDisplay'",
")",
"==",
"1",
")",
";",
"$",
"key",
"->",
"setAttributeKeyEditableOnProfile",
"(",
"(",
"string",
")",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'uakProfileEdit'",
")",
"==",
"1",
")",
";",
"$",
"key",
"->",
"setAttributeKeyRequiredOnProfile",
"(",
"(",
"string",
")",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'uakProfileEditRequired'",
")",
"==",
"1",
")",
";",
"$",
"key",
"->",
"setAttributeKeyEditableOnRegister",
"(",
"(",
"string",
")",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'uakRegisterEdit'",
")",
"==",
"1",
")",
";",
"$",
"key",
"->",
"setAttributeKeyRequiredOnRegister",
"(",
"(",
"string",
")",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'uakRegisterEditRequired'",
")",
"==",
"1",
")",
";",
"$",
"key",
"->",
"setAttributeKeyDisplayedOnMemberList",
"(",
"(",
"string",
")",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'uakMemberListDisplay'",
")",
"==",
"1",
")",
";",
"// Actually save the changes to the database",
"$",
"this",
"->",
"entityManager",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"key",
";",
"}"
] | Update the user attribute key with the data received from POST.
@param \Concrete\Core\Entity\Attribute\Key\UserKey $key The user attribute key to be updated
@param \Symfony\Component\HttpFoundation\Request $request The request containing the posted data
@return \Concrete\Core\Entity\Attribute\Key\UserKey | [
"Update",
"the",
"user",
"attribute",
"key",
"with",
"the",
"data",
"received",
"from",
"POST",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Attribute/Category/UserCategory.php#L237-L248 | train |
concrete5/concrete5 | concrete/src/Foundation/Queue/QueueService.php | QueueService.get | public function get($name, array $additionalConfig = [])
{
$adapter = new DatabaseQueueAdapter([
'connection' => $this->connection,
]);
$config = array_merge(
[
'name' => $name,
],
$additionalConfig
);
return new ZendQueue($adapter, $config);
} | php | public function get($name, array $additionalConfig = [])
{
$adapter = new DatabaseQueueAdapter([
'connection' => $this->connection,
]);
$config = array_merge(
[
'name' => $name,
],
$additionalConfig
);
return new ZendQueue($adapter, $config);
} | [
"public",
"function",
"get",
"(",
"$",
"name",
",",
"array",
"$",
"additionalConfig",
"=",
"[",
"]",
")",
"{",
"$",
"adapter",
"=",
"new",
"DatabaseQueueAdapter",
"(",
"[",
"'connection'",
"=>",
"$",
"this",
"->",
"connection",
",",
"]",
")",
";",
"$",
"config",
"=",
"array_merge",
"(",
"[",
"'name'",
"=>",
"$",
"name",
",",
"]",
",",
"$",
"additionalConfig",
")",
";",
"return",
"new",
"ZendQueue",
"(",
"$",
"adapter",
",",
"$",
"config",
")",
";",
"}"
] | Get a queue by name.
@param string $name The queue name
@param array $additionalConfig additional configuration to be passed to the Zend Queue
@return \ZendQueue\Queue | [
"Get",
"a",
"queue",
"by",
"name",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Foundation/Queue/QueueService.php#L35-L48 | train |
concrete5/concrete5 | concrete/controllers/single_page/dashboard/reports/page_changes.php | PageChanges.getWriter | private function getWriter()
{
return $this->app->make(
PageActivityExporter::class, [
'writer' => $this->app->make(WriterFactory::class)
->createFromPath('php://output', 'w'),
]
);
} | php | private function getWriter()
{
return $this->app->make(
PageActivityExporter::class, [
'writer' => $this->app->make(WriterFactory::class)
->createFromPath('php://output', 'w'),
]
);
} | [
"private",
"function",
"getWriter",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"PageActivityExporter",
"::",
"class",
",",
"[",
"'writer'",
"=>",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"WriterFactory",
"::",
"class",
")",
"->",
"createFromPath",
"(",
"'php://output'",
",",
"'w'",
")",
",",
"]",
")",
";",
"}"
] | Get the writer that will create the CSV.
@return \Concrete\Core\Csv\Export\PageActivityExporter | [
"Get",
"the",
"writer",
"that",
"will",
"create",
"the",
"CSV",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/controllers/single_page/dashboard/reports/page_changes.php#L47-L55 | train |
concrete5/concrete5 | concrete/controllers/single_page/dashboard/reports/page_changes.php | PageChanges.getVersionList | private function getVersionList()
{
/* @var \Concrete\Core\Form\Service\Widget\DateTime $dt */
$dt = $this->app->make('helper/form/date_time');
$startDate = $dt->translate('startDate', null, true);
$endDate = $dt->translate('endDate', null, true);
$versionList = new GlobalVersionList();
$versionList->sortByDateApprovedDesc();
if ($startDate !== null) {
$versionList->filterByApprovedAfter($startDate);
}
if ($endDate !== null) {
$versionList->filterByApprovedBefore($endDate);
}
return $versionList;
} | php | private function getVersionList()
{
/* @var \Concrete\Core\Form\Service\Widget\DateTime $dt */
$dt = $this->app->make('helper/form/date_time');
$startDate = $dt->translate('startDate', null, true);
$endDate = $dt->translate('endDate', null, true);
$versionList = new GlobalVersionList();
$versionList->sortByDateApprovedDesc();
if ($startDate !== null) {
$versionList->filterByApprovedAfter($startDate);
}
if ($endDate !== null) {
$versionList->filterByApprovedBefore($endDate);
}
return $versionList;
} | [
"private",
"function",
"getVersionList",
"(",
")",
"{",
"/* @var \\Concrete\\Core\\Form\\Service\\Widget\\DateTime $dt */",
"$",
"dt",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'helper/form/date_time'",
")",
";",
"$",
"startDate",
"=",
"$",
"dt",
"->",
"translate",
"(",
"'startDate'",
",",
"null",
",",
"true",
")",
";",
"$",
"endDate",
"=",
"$",
"dt",
"->",
"translate",
"(",
"'endDate'",
",",
"null",
",",
"true",
")",
";",
"$",
"versionList",
"=",
"new",
"GlobalVersionList",
"(",
")",
";",
"$",
"versionList",
"->",
"sortByDateApprovedDesc",
"(",
")",
";",
"if",
"(",
"$",
"startDate",
"!==",
"null",
")",
"{",
"$",
"versionList",
"->",
"filterByApprovedAfter",
"(",
"$",
"startDate",
")",
";",
"}",
"if",
"(",
"$",
"endDate",
"!==",
"null",
")",
"{",
"$",
"versionList",
"->",
"filterByApprovedBefore",
"(",
"$",
"endDate",
")",
";",
"}",
"return",
"$",
"versionList",
";",
"}"
] | Get the item list object.
@return \Concrete\Core\Page\Collection\Version\GlobalVersionList | [
"Get",
"the",
"item",
"list",
"object",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/controllers/single_page/dashboard/reports/page_changes.php#L62-L82 | train |
concrete5/concrete5 | concrete/blocks/autonav/nav_item.php | NavItem.isActive | public function isActive(&$c)
{
if ($c) {
$cID = ($c->getCollectionPointerID() > 0) ? $c->getCollectionPointerOriginalID() : $c->getCollectionID();
return $cID == $this->cID;
}
} | php | public function isActive(&$c)
{
if ($c) {
$cID = ($c->getCollectionPointerID() > 0) ? $c->getCollectionPointerOriginalID() : $c->getCollectionID();
return $cID == $this->cID;
}
} | [
"public",
"function",
"isActive",
"(",
"&",
"$",
"c",
")",
"{",
"if",
"(",
"$",
"c",
")",
"{",
"$",
"cID",
"=",
"(",
"$",
"c",
"->",
"getCollectionPointerID",
"(",
")",
">",
"0",
")",
"?",
"$",
"c",
"->",
"getCollectionPointerOriginalID",
"(",
")",
":",
"$",
"c",
"->",
"getCollectionID",
"(",
")",
";",
"return",
"$",
"cID",
"==",
"$",
"this",
"->",
"cID",
";",
"}",
"}"
] | Determines whether this nav item is the current page the user is on.
@param \Concrete\Core\Page\Page $c The page object for the current page
@return bool | [
"Determines",
"whether",
"this",
"nav",
"item",
"is",
"the",
"current",
"page",
"the",
"user",
"is",
"on",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/blocks/autonav/nav_item.php#L58-L65 | train |
concrete5/concrete5 | concrete/blocks/autonav/nav_item.php | NavItem.getTarget | public function getTarget()
{
if ($this->cPointerExternalLink != '') {
if ($this->cPointerExternalLinkNewWindow) {
return '_blank';
}
}
$_c = $this->getCollectionObject();
if (is_object($_c)) {
return $_c->getAttribute('nav_target');
}
return '';
} | php | public function getTarget()
{
if ($this->cPointerExternalLink != '') {
if ($this->cPointerExternalLinkNewWindow) {
return '_blank';
}
}
$_c = $this->getCollectionObject();
if (is_object($_c)) {
return $_c->getAttribute('nav_target');
}
return '';
} | [
"public",
"function",
"getTarget",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cPointerExternalLink",
"!=",
"''",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cPointerExternalLinkNewWindow",
")",
"{",
"return",
"'_blank'",
";",
"}",
"}",
"$",
"_c",
"=",
"$",
"this",
"->",
"getCollectionObject",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"_c",
")",
")",
"{",
"return",
"$",
"_c",
"->",
"getAttribute",
"(",
"'nav_target'",
")",
";",
"}",
"return",
"''",
";",
"}"
] | Returns a target for the nav item. | [
"Returns",
"a",
"target",
"for",
"the",
"nav",
"item",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/blocks/autonav/nav_item.php#L80-L94 | train |
concrete5/concrete5 | concrete/blocks/autonav/nav_item.php | NavItem.getURL | public function getURL()
{
if ($this->cPointerExternalLink != '') {
$link = $this->cPointerExternalLink;
} elseif ($this->cPath) {
$link = $this->cPath;
} elseif ($this->cID == Page::getHomePageID()) {
$link = DIR_REL . '/';
} else {
$link = DIR_REL . '/' . DISPATCHER_FILENAME . '?cID=' . $this->cID;
}
return $link;
} | php | public function getURL()
{
if ($this->cPointerExternalLink != '') {
$link = $this->cPointerExternalLink;
} elseif ($this->cPath) {
$link = $this->cPath;
} elseif ($this->cID == Page::getHomePageID()) {
$link = DIR_REL . '/';
} else {
$link = DIR_REL . '/' . DISPATCHER_FILENAME . '?cID=' . $this->cID;
}
return $link;
} | [
"public",
"function",
"getURL",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cPointerExternalLink",
"!=",
"''",
")",
"{",
"$",
"link",
"=",
"$",
"this",
"->",
"cPointerExternalLink",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"cPath",
")",
"{",
"$",
"link",
"=",
"$",
"this",
"->",
"cPath",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"cID",
"==",
"Page",
"::",
"getHomePageID",
"(",
")",
")",
"{",
"$",
"link",
"=",
"DIR_REL",
".",
"'/'",
";",
"}",
"else",
"{",
"$",
"link",
"=",
"DIR_REL",
".",
"'/'",
".",
"DISPATCHER_FILENAME",
".",
"'?cID='",
".",
"$",
"this",
"->",
"cID",
";",
"}",
"return",
"$",
"link",
";",
"}"
] | Gets a URL that will take the user to this particular page. Checks against concrete.seo.url_rewriting, the page's path, etc..
@return string $url | [
"Gets",
"a",
"URL",
"that",
"will",
"take",
"the",
"user",
"to",
"this",
"particular",
"page",
".",
"Checks",
"against",
"concrete",
".",
"seo",
".",
"url_rewriting",
"the",
"page",
"s",
"path",
"etc",
".."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/blocks/autonav/nav_item.php#L101-L114 | train |
concrete5/concrete5 | concrete/src/File/Image/Thumbnail/Path/Resolver.php | Resolver.getPath | public function getPath(Version $file_version, ThumbnailVersion $thumbnail)
{
/** @var File $file */
$file = $file_version->getFile();
$format = $this->formatService->getFormatForFile($file_version);
$file_id = $file->getFileID();
$storage_location = $file->getFileStorageLocationObject();
$configuration = $storage_location->getConfigurationObject();
$version_id = $file_version->getFileVersionID();
$storage_location_id = $storage_location->getID();
$thumbnail_handle = $thumbnail->getHandle();
$defer = $configuration instanceof DeferredConfigurationInterface;
// Get the path from the storage
$path = $this->getStoredThumbnailPath(
$file_id,
$version_id,
$storage_location_id,
$thumbnail_handle,
$format
);
// If we don't have a stored path already, lets determine one and store it
if (!$path) {
$path = $this->determineThumbnailPath($file_version, $thumbnail, $storage_location, $configuration, $format);
if ($path) {
$this->storeThumbnailPath($path, $file_id, $version_id, $storage_location_id, $thumbnail_handle, $format, !$defer);
}
}
// Pass the path to the "getBuiltThumbnailPath" method which will alter the path if it wants to
$realPath = $this->getBuiltThumbnailPath($path, $file_version, $thumbnail, $storage_location, $configuration, $format);
// If the "getBuiltThumbnailPath" method didn't alter the path, lLet's let the configuration resolve the path now
if ($path == $realPath && $defer) {
try {
$realPath = $this->getPathFromConfiguration($realPath, $configuration);
} catch (\InvalidArgumentException $e) {
// Unable to resolve the path from the configuration object, lets return the real path
}
}
return $realPath;
} | php | public function getPath(Version $file_version, ThumbnailVersion $thumbnail)
{
/** @var File $file */
$file = $file_version->getFile();
$format = $this->formatService->getFormatForFile($file_version);
$file_id = $file->getFileID();
$storage_location = $file->getFileStorageLocationObject();
$configuration = $storage_location->getConfigurationObject();
$version_id = $file_version->getFileVersionID();
$storage_location_id = $storage_location->getID();
$thumbnail_handle = $thumbnail->getHandle();
$defer = $configuration instanceof DeferredConfigurationInterface;
// Get the path from the storage
$path = $this->getStoredThumbnailPath(
$file_id,
$version_id,
$storage_location_id,
$thumbnail_handle,
$format
);
// If we don't have a stored path already, lets determine one and store it
if (!$path) {
$path = $this->determineThumbnailPath($file_version, $thumbnail, $storage_location, $configuration, $format);
if ($path) {
$this->storeThumbnailPath($path, $file_id, $version_id, $storage_location_id, $thumbnail_handle, $format, !$defer);
}
}
// Pass the path to the "getBuiltThumbnailPath" method which will alter the path if it wants to
$realPath = $this->getBuiltThumbnailPath($path, $file_version, $thumbnail, $storage_location, $configuration, $format);
// If the "getBuiltThumbnailPath" method didn't alter the path, lLet's let the configuration resolve the path now
if ($path == $realPath && $defer) {
try {
$realPath = $this->getPathFromConfiguration($realPath, $configuration);
} catch (\InvalidArgumentException $e) {
// Unable to resolve the path from the configuration object, lets return the real path
}
}
return $realPath;
} | [
"public",
"function",
"getPath",
"(",
"Version",
"$",
"file_version",
",",
"ThumbnailVersion",
"$",
"thumbnail",
")",
"{",
"/** @var File $file */",
"$",
"file",
"=",
"$",
"file_version",
"->",
"getFile",
"(",
")",
";",
"$",
"format",
"=",
"$",
"this",
"->",
"formatService",
"->",
"getFormatForFile",
"(",
"$",
"file_version",
")",
";",
"$",
"file_id",
"=",
"$",
"file",
"->",
"getFileID",
"(",
")",
";",
"$",
"storage_location",
"=",
"$",
"file",
"->",
"getFileStorageLocationObject",
"(",
")",
";",
"$",
"configuration",
"=",
"$",
"storage_location",
"->",
"getConfigurationObject",
"(",
")",
";",
"$",
"version_id",
"=",
"$",
"file_version",
"->",
"getFileVersionID",
"(",
")",
";",
"$",
"storage_location_id",
"=",
"$",
"storage_location",
"->",
"getID",
"(",
")",
";",
"$",
"thumbnail_handle",
"=",
"$",
"thumbnail",
"->",
"getHandle",
"(",
")",
";",
"$",
"defer",
"=",
"$",
"configuration",
"instanceof",
"DeferredConfigurationInterface",
";",
"// Get the path from the storage",
"$",
"path",
"=",
"$",
"this",
"->",
"getStoredThumbnailPath",
"(",
"$",
"file_id",
",",
"$",
"version_id",
",",
"$",
"storage_location_id",
",",
"$",
"thumbnail_handle",
",",
"$",
"format",
")",
";",
"// If we don't have a stored path already, lets determine one and store it",
"if",
"(",
"!",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"determineThumbnailPath",
"(",
"$",
"file_version",
",",
"$",
"thumbnail",
",",
"$",
"storage_location",
",",
"$",
"configuration",
",",
"$",
"format",
")",
";",
"if",
"(",
"$",
"path",
")",
"{",
"$",
"this",
"->",
"storeThumbnailPath",
"(",
"$",
"path",
",",
"$",
"file_id",
",",
"$",
"version_id",
",",
"$",
"storage_location_id",
",",
"$",
"thumbnail_handle",
",",
"$",
"format",
",",
"!",
"$",
"defer",
")",
";",
"}",
"}",
"// Pass the path to the \"getBuiltThumbnailPath\" method which will alter the path if it wants to",
"$",
"realPath",
"=",
"$",
"this",
"->",
"getBuiltThumbnailPath",
"(",
"$",
"path",
",",
"$",
"file_version",
",",
"$",
"thumbnail",
",",
"$",
"storage_location",
",",
"$",
"configuration",
",",
"$",
"format",
")",
";",
"// If the \"getBuiltThumbnailPath\" method didn't alter the path, lLet's let the configuration resolve the path now",
"if",
"(",
"$",
"path",
"==",
"$",
"realPath",
"&&",
"$",
"defer",
")",
"{",
"try",
"{",
"$",
"realPath",
"=",
"$",
"this",
"->",
"getPathFromConfiguration",
"(",
"$",
"realPath",
",",
"$",
"configuration",
")",
";",
"}",
"catch",
"(",
"\\",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"// Unable to resolve the path from the configuration object, lets return the real path",
"}",
"}",
"return",
"$",
"realPath",
";",
"}"
] | Get the path for a file version
@param Version $file_version
@param ThumbnailVersion $thumbnail
@return null|string | [
"Get",
"the",
"path",
"for",
"a",
"file",
"version"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Thumbnail/Path/Resolver.php#L53-L96 | train |
concrete5/concrete5 | concrete/src/File/Image/Thumbnail/Path/Resolver.php | Resolver.getStoredThumbnailPath | protected function getStoredThumbnailPath($file_id, $version_id, $storage_location_id, $thumbnail_handle, $format)
{
$builder = $this->connection->createQueryBuilder();
$query = $builder
->select('path')->from('FileImageThumbnailPaths', 'p')
->where('p.fileID = :file')
->andWhere('p.fileVersionID = :version')
->andWhere('p.storageLocationID = :storage')
->andWhere('p.thumbnailTypeHandle = :thumbnail')
->andWhere('p.thumbnailFormat = :format')
->setParameters(array(
'file' => $file_id,
'version' => $version_id,
'storage' => $storage_location_id,
'thumbnail' => $thumbnail_handle,
'format' => $format,
))->execute();
if ($query->rowCount()) {
return $query->fetchColumn();
}
return null;
} | php | protected function getStoredThumbnailPath($file_id, $version_id, $storage_location_id, $thumbnail_handle, $format)
{
$builder = $this->connection->createQueryBuilder();
$query = $builder
->select('path')->from('FileImageThumbnailPaths', 'p')
->where('p.fileID = :file')
->andWhere('p.fileVersionID = :version')
->andWhere('p.storageLocationID = :storage')
->andWhere('p.thumbnailTypeHandle = :thumbnail')
->andWhere('p.thumbnailFormat = :format')
->setParameters(array(
'file' => $file_id,
'version' => $version_id,
'storage' => $storage_location_id,
'thumbnail' => $thumbnail_handle,
'format' => $format,
))->execute();
if ($query->rowCount()) {
return $query->fetchColumn();
}
return null;
} | [
"protected",
"function",
"getStoredThumbnailPath",
"(",
"$",
"file_id",
",",
"$",
"version_id",
",",
"$",
"storage_location_id",
",",
"$",
"thumbnail_handle",
",",
"$",
"format",
")",
"{",
"$",
"builder",
"=",
"$",
"this",
"->",
"connection",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"query",
"=",
"$",
"builder",
"->",
"select",
"(",
"'path'",
")",
"->",
"from",
"(",
"'FileImageThumbnailPaths'",
",",
"'p'",
")",
"->",
"where",
"(",
"'p.fileID = :file'",
")",
"->",
"andWhere",
"(",
"'p.fileVersionID = :version'",
")",
"->",
"andWhere",
"(",
"'p.storageLocationID = :storage'",
")",
"->",
"andWhere",
"(",
"'p.thumbnailTypeHandle = :thumbnail'",
")",
"->",
"andWhere",
"(",
"'p.thumbnailFormat = :format'",
")",
"->",
"setParameters",
"(",
"array",
"(",
"'file'",
"=>",
"$",
"file_id",
",",
"'version'",
"=>",
"$",
"version_id",
",",
"'storage'",
"=>",
"$",
"storage_location_id",
",",
"'thumbnail'",
"=>",
"$",
"thumbnail_handle",
",",
"'format'",
"=>",
"$",
"format",
",",
")",
")",
"->",
"execute",
"(",
")",
";",
"if",
"(",
"$",
"query",
"->",
"rowCount",
"(",
")",
")",
"{",
"return",
"$",
"query",
"->",
"fetchColumn",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Get the stored path for a file.
@param int $file_id
@param int $version_id
@param int $storage_location_id
@param string $thumbnail_handle
@param string $format
@return null|string | [
"Get",
"the",
"stored",
"path",
"for",
"a",
"file",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Thumbnail/Path/Resolver.php#L125-L148 | train |
concrete5/concrete5 | concrete/src/File/Image/Thumbnail/Path/Resolver.php | Resolver.storeThumbnailPath | protected function storeThumbnailPath($path, $file_id, $version_id, $storage_location_id, $thumbnail_handle, $format, $isBuilt = true)
{
try {
$this->connection->insert('FileImageThumbnailPaths', array(
'path' => $path,
'fileID' => $file_id,
'fileVersionID' => $version_id,
'storageLocationID' => $storage_location_id,
'thumbnailTypeHandle' => $thumbnail_handle,
'thumbnailFormat' => $format,
'isBuilt' => $isBuilt ? 1 : 0
));
} catch (InvalidFieldNameException $e) {
// User needs to run the database upgrade routine
} catch (UniqueConstraintViolationException $e) {
// We tried to generate a thumbnail for something we already generated (race condition)
}
} | php | protected function storeThumbnailPath($path, $file_id, $version_id, $storage_location_id, $thumbnail_handle, $format, $isBuilt = true)
{
try {
$this->connection->insert('FileImageThumbnailPaths', array(
'path' => $path,
'fileID' => $file_id,
'fileVersionID' => $version_id,
'storageLocationID' => $storage_location_id,
'thumbnailTypeHandle' => $thumbnail_handle,
'thumbnailFormat' => $format,
'isBuilt' => $isBuilt ? 1 : 0
));
} catch (InvalidFieldNameException $e) {
// User needs to run the database upgrade routine
} catch (UniqueConstraintViolationException $e) {
// We tried to generate a thumbnail for something we already generated (race condition)
}
} | [
"protected",
"function",
"storeThumbnailPath",
"(",
"$",
"path",
",",
"$",
"file_id",
",",
"$",
"version_id",
",",
"$",
"storage_location_id",
",",
"$",
"thumbnail_handle",
",",
"$",
"format",
",",
"$",
"isBuilt",
"=",
"true",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"connection",
"->",
"insert",
"(",
"'FileImageThumbnailPaths'",
",",
"array",
"(",
"'path'",
"=>",
"$",
"path",
",",
"'fileID'",
"=>",
"$",
"file_id",
",",
"'fileVersionID'",
"=>",
"$",
"version_id",
",",
"'storageLocationID'",
"=>",
"$",
"storage_location_id",
",",
"'thumbnailTypeHandle'",
"=>",
"$",
"thumbnail_handle",
",",
"'thumbnailFormat'",
"=>",
"$",
"format",
",",
"'isBuilt'",
"=>",
"$",
"isBuilt",
"?",
"1",
":",
"0",
")",
")",
";",
"}",
"catch",
"(",
"InvalidFieldNameException",
"$",
"e",
")",
"{",
"// User needs to run the database upgrade routine",
"}",
"catch",
"(",
"UniqueConstraintViolationException",
"$",
"e",
")",
"{",
"// We tried to generate a thumbnail for something we already generated (race condition)",
"}",
"}"
] | Store a path against a storage location for a file version and a thumbnail handle and format
@param string $path
@param int $file_id
@param int $version_id
@param int $storage_location_id
@param string $thumbnail_handle
@param string $format
@param bool $isBuilt Have we had the configuration generate the path yet | [
"Store",
"a",
"path",
"against",
"a",
"storage",
"location",
"for",
"a",
"file",
"version",
"and",
"a",
"thumbnail",
"handle",
"and",
"format"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Thumbnail/Path/Resolver.php#L160-L177 | train |
concrete5/concrete5 | concrete/src/File/Image/Thumbnail/Path/Resolver.php | Resolver.determineThumbnailPath | protected function determineThumbnailPath(Version $file_version, ThumbnailVersion $thumbnail, StorageLocation $storage, ConfigurationInterface $configuration, $format)
{
if ($thumbnail->shouldExistFor($file_version->getAttribute('width'), $file_version->getAttribute('height'), $file_version->getFile())) {
$path = $thumbnail->getFilePath($file_version, $format);
if ($configuration instanceof DeferredConfigurationInterface) {
// Lets defer getting the path from the configuration until we know we need to
return $path;
}
return $configuration->getRelativePathToFile($path);
}
} | php | protected function determineThumbnailPath(Version $file_version, ThumbnailVersion $thumbnail, StorageLocation $storage, ConfigurationInterface $configuration, $format)
{
if ($thumbnail->shouldExistFor($file_version->getAttribute('width'), $file_version->getAttribute('height'), $file_version->getFile())) {
$path = $thumbnail->getFilePath($file_version, $format);
if ($configuration instanceof DeferredConfigurationInterface) {
// Lets defer getting the path from the configuration until we know we need to
return $path;
}
return $configuration->getRelativePathToFile($path);
}
} | [
"protected",
"function",
"determineThumbnailPath",
"(",
"Version",
"$",
"file_version",
",",
"ThumbnailVersion",
"$",
"thumbnail",
",",
"StorageLocation",
"$",
"storage",
",",
"ConfigurationInterface",
"$",
"configuration",
",",
"$",
"format",
")",
"{",
"if",
"(",
"$",
"thumbnail",
"->",
"shouldExistFor",
"(",
"$",
"file_version",
"->",
"getAttribute",
"(",
"'width'",
")",
",",
"$",
"file_version",
"->",
"getAttribute",
"(",
"'height'",
")",
",",
"$",
"file_version",
"->",
"getFile",
"(",
")",
")",
")",
"{",
"$",
"path",
"=",
"$",
"thumbnail",
"->",
"getFilePath",
"(",
"$",
"file_version",
",",
"$",
"format",
")",
";",
"if",
"(",
"$",
"configuration",
"instanceof",
"DeferredConfigurationInterface",
")",
"{",
"// Lets defer getting the path from the configuration until we know we need to",
"return",
"$",
"path",
";",
"}",
"return",
"$",
"configuration",
"->",
"getRelativePathToFile",
"(",
"$",
"path",
")",
";",
"}",
"}"
] | Determine the path for a file version thumbnail based on the storage location
NOTE: If you're wanting to change how file paths are determined, a better method
to override would be `->getBuiltThumbnailPath()`
@param \Concrete\Core\Entity\File\Version $file_version
@param \Concrete\Core\File\Image\Thumbnail\Type\Version $thumbnail
@param \Concrete\Core\Entity\File\StorageLocation\StorageLocation $storage
@param \Concrete\Core\File\StorageLocation\Configuration\ConfigurationInterface $configuration
@param string $format
@return string|null | [
"Determine",
"the",
"path",
"for",
"a",
"file",
"version",
"thumbnail",
"based",
"on",
"the",
"storage",
"location"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Thumbnail/Path/Resolver.php#L192-L204 | train |
concrete5/concrete5 | concrete/src/File/Image/Thumbnail/Path/Resolver.php | Resolver.getBuiltThumbnailPath | protected function getBuiltThumbnailPath($path, Version $file_version, ThumbnailVersion $thumbnail, StorageLocation $storage, ConfigurationInterface $configuration, $format)
{
return $path;
} | php | protected function getBuiltThumbnailPath($path, Version $file_version, ThumbnailVersion $thumbnail, StorageLocation $storage, ConfigurationInterface $configuration, $format)
{
return $path;
} | [
"protected",
"function",
"getBuiltThumbnailPath",
"(",
"$",
"path",
",",
"Version",
"$",
"file_version",
",",
"ThumbnailVersion",
"$",
"thumbnail",
",",
"StorageLocation",
"$",
"storage",
",",
"ConfigurationInterface",
"$",
"configuration",
",",
"$",
"format",
")",
"{",
"return",
"$",
"path",
";",
"}"
] | An access point for overriding how paths are built
@param $path
@param \Concrete\Core\Entity\File\Version $file_version
@param \Concrete\Core\File\Image\Thumbnail\Type\Version $thumbnail
@param \Concrete\Core\Entity\File\StorageLocation\StorageLocation $storage
@param \Concrete\Core\File\StorageLocation\Configuration\ConfigurationInterface $configuration
@param string $format
@return mixed | [
"An",
"access",
"point",
"for",
"overriding",
"how",
"paths",
"are",
"built"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Thumbnail/Path/Resolver.php#L216-L219 | train |
concrete5/concrete5 | concrete/src/File/Image/Thumbnail/Path/Resolver.php | Resolver.getPathFromConfiguration | protected function getPathFromConfiguration($path, ConfigurationInterface $configuration)
{
if ($configuration->hasRelativePath()) {
return $configuration->getRelativePathToFile($path);
}
if ($configuration->hasPublicURL()) {
return $configuration->getPublicURLToFile($path);
}
throw new \InvalidArgumentException('Thumbnail configuration doesn\'t support Paths or URLs');
} | php | protected function getPathFromConfiguration($path, ConfigurationInterface $configuration)
{
if ($configuration->hasRelativePath()) {
return $configuration->getRelativePathToFile($path);
}
if ($configuration->hasPublicURL()) {
return $configuration->getPublicURLToFile($path);
}
throw new \InvalidArgumentException('Thumbnail configuration doesn\'t support Paths or URLs');
} | [
"protected",
"function",
"getPathFromConfiguration",
"(",
"$",
"path",
",",
"ConfigurationInterface",
"$",
"configuration",
")",
"{",
"if",
"(",
"$",
"configuration",
"->",
"hasRelativePath",
"(",
")",
")",
"{",
"return",
"$",
"configuration",
"->",
"getRelativePathToFile",
"(",
"$",
"path",
")",
";",
"}",
"if",
"(",
"$",
"configuration",
"->",
"hasPublicURL",
"(",
")",
")",
"{",
"return",
"$",
"configuration",
"->",
"getPublicURLToFile",
"(",
"$",
"path",
")",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Thumbnail configuration doesn\\'t support Paths or URLs'",
")",
";",
"}"
] | Get the path from a configuration object
@param string $path
@param \Concrete\Core\File\StorageLocation\Configuration\ConfigurationInterface $configuration
@return string | [
"Get",
"the",
"path",
"from",
"a",
"configuration",
"object"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/Image/Thumbnail/Path/Resolver.php#L227-L238 | train |
concrete5/concrete5 | concrete/src/Page/Type/Type.php | Type.canPublishPageTypeBeneathPage | public function canPublishPageTypeBeneathPage(\Concrete\Core\Page\Page $page)
{
$target = $this->getPageTypePublishTargetObject();
if (is_object($target)) {
return $target->canPublishPageTypeBeneathTarget($this, $page);
}
} | php | public function canPublishPageTypeBeneathPage(\Concrete\Core\Page\Page $page)
{
$target = $this->getPageTypePublishTargetObject();
if (is_object($target)) {
return $target->canPublishPageTypeBeneathTarget($this, $page);
}
} | [
"public",
"function",
"canPublishPageTypeBeneathPage",
"(",
"\\",
"Concrete",
"\\",
"Core",
"\\",
"Page",
"\\",
"Page",
"$",
"page",
")",
"{",
"$",
"target",
"=",
"$",
"this",
"->",
"getPageTypePublishTargetObject",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"target",
")",
")",
"{",
"return",
"$",
"target",
"->",
"canPublishPageTypeBeneathTarget",
"(",
"$",
"this",
",",
"$",
"page",
")",
";",
"}",
"}"
] | Returns true if pages of the current type are allowed beneath the passed parent page.
@param \Concrete\Core\Page\Page $page | [
"Returns",
"true",
"if",
"pages",
"of",
"the",
"current",
"type",
"are",
"allowed",
"beneath",
"the",
"passed",
"parent",
"page",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Page/Type/Type.php#L1122-L1128 | train |
concrete5/concrete5 | concrete/src/Area/GlobalArea.php | GlobalArea.deleteByName | public static function deleteByName($arHandle)
{
$db = Loader::db();
$db->Execute('select cID from Areas where arHandle = ? and arIsGlobal = 1', [$arHandle]);
$db->Execute('delete from Areas where arHandle = ? and arIsGlobal = 1', [$arHandle]);
} | php | public static function deleteByName($arHandle)
{
$db = Loader::db();
$db->Execute('select cID from Areas where arHandle = ? and arIsGlobal = 1', [$arHandle]);
$db->Execute('delete from Areas where arHandle = ? and arIsGlobal = 1', [$arHandle]);
} | [
"public",
"static",
"function",
"deleteByName",
"(",
"$",
"arHandle",
")",
"{",
"$",
"db",
"=",
"Loader",
"::",
"db",
"(",
")",
";",
"$",
"db",
"->",
"Execute",
"(",
"'select cID from Areas where arHandle = ? and arIsGlobal = 1'",
",",
"[",
"$",
"arHandle",
"]",
")",
";",
"$",
"db",
"->",
"Execute",
"(",
"'delete from Areas where arHandle = ? and arIsGlobal = 1'",
",",
"[",
"$",
"arHandle",
"]",
")",
";",
"}"
] | Note that this function does not delete the global area's stack.
You probably want to call the "delete" method of the Stack model instead.
@param string $arHandle | [
"Note",
"that",
"this",
"function",
"does",
"not",
"delete",
"the",
"global",
"area",
"s",
"stack",
".",
"You",
"probably",
"want",
"to",
"call",
"the",
"delete",
"method",
"of",
"the",
"Stack",
"model",
"instead",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Area/GlobalArea.php#L137-L142 | train |
concrete5/concrete5 | concrete/src/Area/GlobalArea.php | GlobalArea.deleteEmptyAreas | public static function deleteEmptyAreas()
{
$app = Application::getFacadeApplication();
$siteService = $app->make(SiteService::class);
$multilingualSectionIDs = [];
$sites = $siteService->getList();
foreach ($sites as $site) {
$multilingualSectionIDs = array_merge(MultilingualSection::getIDList($site));
}
$multilingualSections = [];
foreach (array_unique($multilingualSectionIDs) as $multilingualSectionID) {
$multilingualSections[] = MultilingualSection::getByID($multilingualSectionID);
}
$stackList = new StackList();
$stackList->filterByGlobalAreas();
/** @var \Concrete\Core\Page\Stack\Stack[] $globalAreaStacks */
$globalAreaStacks = $stackList->getResults();
foreach ($globalAreaStacks as $stack) {
$stackAlternatives = [];
if ($stack->isNeutralStack()) {
$stackAlternatives[] = $stack;
} else {
$stackAlternatives[] = $stack->getNeutralStack();
}
foreach ($multilingualSections as $multilingualSection) {
$stackAlternative = $stackAlternatives[0]->getLocalizedStack($multilingualSection);
if ($stackAlternative !== null) {
$stackAlternatives[] = $stackAlternative;
}
}
$hasBlocks = false;
foreach ($stackAlternatives as $stackAlternative) {
// get list of all available page versions, we only delete areas if they never had any content
$versionList = new VersionList($stackAlternative);
$versions = $versionList->get();
foreach ($versions as $version) {
$pageVersion = Page::getByID($version->getCollectionID(), $version->getVersionID());
$totalBlocks = count($pageVersion->getBlockIDs());
if ($totalBlocks > 0) {
$hasBlocks = true;
break 2;
}
}
}
if (!$hasBlocks) {
$stackAlternatives[0]->delete();
}
}
} | php | public static function deleteEmptyAreas()
{
$app = Application::getFacadeApplication();
$siteService = $app->make(SiteService::class);
$multilingualSectionIDs = [];
$sites = $siteService->getList();
foreach ($sites as $site) {
$multilingualSectionIDs = array_merge(MultilingualSection::getIDList($site));
}
$multilingualSections = [];
foreach (array_unique($multilingualSectionIDs) as $multilingualSectionID) {
$multilingualSections[] = MultilingualSection::getByID($multilingualSectionID);
}
$stackList = new StackList();
$stackList->filterByGlobalAreas();
/** @var \Concrete\Core\Page\Stack\Stack[] $globalAreaStacks */
$globalAreaStacks = $stackList->getResults();
foreach ($globalAreaStacks as $stack) {
$stackAlternatives = [];
if ($stack->isNeutralStack()) {
$stackAlternatives[] = $stack;
} else {
$stackAlternatives[] = $stack->getNeutralStack();
}
foreach ($multilingualSections as $multilingualSection) {
$stackAlternative = $stackAlternatives[0]->getLocalizedStack($multilingualSection);
if ($stackAlternative !== null) {
$stackAlternatives[] = $stackAlternative;
}
}
$hasBlocks = false;
foreach ($stackAlternatives as $stackAlternative) {
// get list of all available page versions, we only delete areas if they never had any content
$versionList = new VersionList($stackAlternative);
$versions = $versionList->get();
foreach ($versions as $version) {
$pageVersion = Page::getByID($version->getCollectionID(), $version->getVersionID());
$totalBlocks = count($pageVersion->getBlockIDs());
if ($totalBlocks > 0) {
$hasBlocks = true;
break 2;
}
}
}
if (!$hasBlocks) {
$stackAlternatives[0]->delete();
}
}
} | [
"public",
"static",
"function",
"deleteEmptyAreas",
"(",
")",
"{",
"$",
"app",
"=",
"Application",
"::",
"getFacadeApplication",
"(",
")",
";",
"$",
"siteService",
"=",
"$",
"app",
"->",
"make",
"(",
"SiteService",
"::",
"class",
")",
";",
"$",
"multilingualSectionIDs",
"=",
"[",
"]",
";",
"$",
"sites",
"=",
"$",
"siteService",
"->",
"getList",
"(",
")",
";",
"foreach",
"(",
"$",
"sites",
"as",
"$",
"site",
")",
"{",
"$",
"multilingualSectionIDs",
"=",
"array_merge",
"(",
"MultilingualSection",
"::",
"getIDList",
"(",
"$",
"site",
")",
")",
";",
"}",
"$",
"multilingualSections",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_unique",
"(",
"$",
"multilingualSectionIDs",
")",
"as",
"$",
"multilingualSectionID",
")",
"{",
"$",
"multilingualSections",
"[",
"]",
"=",
"MultilingualSection",
"::",
"getByID",
"(",
"$",
"multilingualSectionID",
")",
";",
"}",
"$",
"stackList",
"=",
"new",
"StackList",
"(",
")",
";",
"$",
"stackList",
"->",
"filterByGlobalAreas",
"(",
")",
";",
"/** @var \\Concrete\\Core\\Page\\Stack\\Stack[] $globalAreaStacks */",
"$",
"globalAreaStacks",
"=",
"$",
"stackList",
"->",
"getResults",
"(",
")",
";",
"foreach",
"(",
"$",
"globalAreaStacks",
"as",
"$",
"stack",
")",
"{",
"$",
"stackAlternatives",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"stack",
"->",
"isNeutralStack",
"(",
")",
")",
"{",
"$",
"stackAlternatives",
"[",
"]",
"=",
"$",
"stack",
";",
"}",
"else",
"{",
"$",
"stackAlternatives",
"[",
"]",
"=",
"$",
"stack",
"->",
"getNeutralStack",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"multilingualSections",
"as",
"$",
"multilingualSection",
")",
"{",
"$",
"stackAlternative",
"=",
"$",
"stackAlternatives",
"[",
"0",
"]",
"->",
"getLocalizedStack",
"(",
"$",
"multilingualSection",
")",
";",
"if",
"(",
"$",
"stackAlternative",
"!==",
"null",
")",
"{",
"$",
"stackAlternatives",
"[",
"]",
"=",
"$",
"stackAlternative",
";",
"}",
"}",
"$",
"hasBlocks",
"=",
"false",
";",
"foreach",
"(",
"$",
"stackAlternatives",
"as",
"$",
"stackAlternative",
")",
"{",
"// get list of all available page versions, we only delete areas if they never had any content",
"$",
"versionList",
"=",
"new",
"VersionList",
"(",
"$",
"stackAlternative",
")",
";",
"$",
"versions",
"=",
"$",
"versionList",
"->",
"get",
"(",
")",
";",
"foreach",
"(",
"$",
"versions",
"as",
"$",
"version",
")",
"{",
"$",
"pageVersion",
"=",
"Page",
"::",
"getByID",
"(",
"$",
"version",
"->",
"getCollectionID",
"(",
")",
",",
"$",
"version",
"->",
"getVersionID",
"(",
")",
")",
";",
"$",
"totalBlocks",
"=",
"count",
"(",
"$",
"pageVersion",
"->",
"getBlockIDs",
"(",
")",
")",
";",
"if",
"(",
"$",
"totalBlocks",
">",
"0",
")",
"{",
"$",
"hasBlocks",
"=",
"true",
";",
"break",
"2",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"hasBlocks",
")",
"{",
"$",
"stackAlternatives",
"[",
"0",
"]",
"->",
"delete",
"(",
")",
";",
"}",
"}",
"}"
] | Searches for global areas without any blocks in it and deletes them.
This will have a positive impact on the performance as every global area is rendered for every page. | [
"Searches",
"for",
"global",
"areas",
"without",
"any",
"blocks",
"in",
"it",
"and",
"deletes",
"them",
".",
"This",
"will",
"have",
"a",
"positive",
"impact",
"on",
"the",
"performance",
"as",
"every",
"global",
"area",
"is",
"rendered",
"for",
"every",
"page",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Area/GlobalArea.php#L148-L202 | train |
concrete5/concrete5 | concrete/src/Foundation/EnvironmentDetector.php | EnvironmentDetector.detectConsoleEnvironment | protected function detectConsoleEnvironment($environments, array $args)
{
// First we will check if an environment argument was passed via console arguments
// and if it was that automatically overrides as the environment. Otherwise, we
// will check the environment as a "web" request like a typical HTTP request.
if (!is_null($value = $this->getEnvironmentArgument($args))) {
return head(array_slice(explode('=', $value), 1));
}
} | php | protected function detectConsoleEnvironment($environments, array $args)
{
// First we will check if an environment argument was passed via console arguments
// and if it was that automatically overrides as the environment. Otherwise, we
// will check the environment as a "web" request like a typical HTTP request.
if (!is_null($value = $this->getEnvironmentArgument($args))) {
return head(array_slice(explode('=', $value), 1));
}
} | [
"protected",
"function",
"detectConsoleEnvironment",
"(",
"$",
"environments",
",",
"array",
"$",
"args",
")",
"{",
"// First we will check if an environment argument was passed via console arguments",
"// and if it was that automatically overrides as the environment. Otherwise, we",
"// will check the environment as a \"web\" request like a typical HTTP request.",
"if",
"(",
"!",
"is_null",
"(",
"$",
"value",
"=",
"$",
"this",
"->",
"getEnvironmentArgument",
"(",
"$",
"args",
")",
")",
")",
"{",
"return",
"head",
"(",
"array_slice",
"(",
"explode",
"(",
"'='",
",",
"$",
"value",
")",
",",
"1",
")",
")",
";",
"}",
"}"
] | Set the application environment from command-line arguments.
@param mixed $environments
@param array $args
@return string | [
"Set",
"the",
"application",
"environment",
"from",
"command",
"-",
"line",
"arguments",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Foundation/EnvironmentDetector.php#L67-L75 | train |
concrete5/concrete5 | concrete/src/File/FileList.php | FileList.filterByStorageLocation | public function filterByStorageLocation($storageLocation) {
if ($storageLocation instanceof \Concrete\Core\Entity\File\StorageLocation\StorageLocation) {
$this->filterByStorageLocationID($storageLocation->getID());
} elseif (!is_object($storageLocation)) {
$this->filterByStorageLocationID($storageLocation);
} else {
throw new Exception(t('Invalid file storage location.'));
}
} | php | public function filterByStorageLocation($storageLocation) {
if ($storageLocation instanceof \Concrete\Core\Entity\File\StorageLocation\StorageLocation) {
$this->filterByStorageLocationID($storageLocation->getID());
} elseif (!is_object($storageLocation)) {
$this->filterByStorageLocationID($storageLocation);
} else {
throw new Exception(t('Invalid file storage location.'));
}
} | [
"public",
"function",
"filterByStorageLocation",
"(",
"$",
"storageLocation",
")",
"{",
"if",
"(",
"$",
"storageLocation",
"instanceof",
"\\",
"Concrete",
"\\",
"Core",
"\\",
"Entity",
"\\",
"File",
"\\",
"StorageLocation",
"\\",
"StorageLocation",
")",
"{",
"$",
"this",
"->",
"filterByStorageLocationID",
"(",
"$",
"storageLocation",
"->",
"getID",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"!",
"is_object",
"(",
"$",
"storageLocation",
")",
")",
"{",
"$",
"this",
"->",
"filterByStorageLocationID",
"(",
"$",
"storageLocation",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"t",
"(",
"'Invalid file storage location.'",
")",
")",
";",
"}",
"}"
] | Filter the files by their storage location using a storage location object.
@param \Concrete\Core\Entity\File\StorageLocation\StorageLocation|int $storageLocation storage location object | [
"Filter",
"the",
"files",
"by",
"their",
"storage",
"location",
"using",
"a",
"storage",
"location",
"object",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/FileList.php#L169-L177 | train |
concrete5/concrete5 | concrete/src/File/FileList.php | FileList.filterByStorageLocationID | public function filterByStorageLocationID($fslID)
{
$fslID = (int) $fslID;
$this->query->andWhere('f.fslID = :fslID');
$this->query->setParameter('fslID', $fslID);
} | php | public function filterByStorageLocationID($fslID)
{
$fslID = (int) $fslID;
$this->query->andWhere('f.fslID = :fslID');
$this->query->setParameter('fslID', $fslID);
} | [
"public",
"function",
"filterByStorageLocationID",
"(",
"$",
"fslID",
")",
"{",
"$",
"fslID",
"=",
"(",
"int",
")",
"$",
"fslID",
";",
"$",
"this",
"->",
"query",
"->",
"andWhere",
"(",
"'f.fslID = :fslID'",
")",
";",
"$",
"this",
"->",
"query",
"->",
"setParameter",
"(",
"'fslID'",
",",
"$",
"fslID",
")",
";",
"}"
] | Filter the files by their storage location using a storage location id.
@param int $fslID storage location id | [
"Filter",
"the",
"files",
"by",
"their",
"storage",
"location",
"using",
"a",
"storage",
"location",
"id",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/FileList.php#L184-L189 | train |
concrete5/concrete5 | concrete/src/File/FileList.php | FileList.filterByTags | public function filterByTags($tags)
{
$this->query->andWhere(
$this->query->expr()->andX(
$this->query->expr()->like('fv.fvTags', ':tags')
)
);
$this->query->setParameter('tags', '%' . $tags . '%');
} | php | public function filterByTags($tags)
{
$this->query->andWhere(
$this->query->expr()->andX(
$this->query->expr()->like('fv.fvTags', ':tags')
)
);
$this->query->setParameter('tags', '%' . $tags . '%');
} | [
"public",
"function",
"filterByTags",
"(",
"$",
"tags",
")",
"{",
"$",
"this",
"->",
"query",
"->",
"andWhere",
"(",
"$",
"this",
"->",
"query",
"->",
"expr",
"(",
")",
"->",
"andX",
"(",
"$",
"this",
"->",
"query",
"->",
"expr",
"(",
")",
"->",
"like",
"(",
"'fv.fvTags'",
",",
"':tags'",
")",
")",
")",
";",
"$",
"this",
"->",
"query",
"->",
"setParameter",
"(",
"'tags'",
",",
"'%'",
".",
"$",
"tags",
".",
"'%'",
")",
";",
"}"
] | Filters by "tags" only.
@param string $tags | [
"Filters",
"by",
"tags",
"only",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/File/FileList.php#L292-L300 | train |
concrete5/concrete5 | concrete/src/Install/PreconditionService.php | PreconditionService.getPreconditions | public function getPreconditions($includeWebPreconditions = true)
{
$result = [];
foreach ($this->getAllPreconditions() as $instance) {
if (!$instance instanceof OptionsPreconditionInterface) {
if ($includeWebPreconditions || !$instance instanceof WebPreconditionInterface) {
$result[] = $instance;
}
}
}
return $result;
} | php | public function getPreconditions($includeWebPreconditions = true)
{
$result = [];
foreach ($this->getAllPreconditions() as $instance) {
if (!$instance instanceof OptionsPreconditionInterface) {
if ($includeWebPreconditions || !$instance instanceof WebPreconditionInterface) {
$result[] = $instance;
}
}
}
return $result;
} | [
"public",
"function",
"getPreconditions",
"(",
"$",
"includeWebPreconditions",
"=",
"true",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getAllPreconditions",
"(",
")",
"as",
"$",
"instance",
")",
"{",
"if",
"(",
"!",
"$",
"instance",
"instanceof",
"OptionsPreconditionInterface",
")",
"{",
"if",
"(",
"$",
"includeWebPreconditions",
"||",
"!",
"$",
"instance",
"instanceof",
"WebPreconditionInterface",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"instance",
";",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Get the pre-configuration preconditions.
@param bool $includeWebPreconditions
@return PreconditionInterface[] | [
"Get",
"the",
"pre",
"-",
"configuration",
"preconditions",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Install/PreconditionService.php#L47-L59 | train |
concrete5/concrete5 | concrete/src/Install/PreconditionService.php | PreconditionService.getOptionsPreconditions | public function getOptionsPreconditions()
{
$result = [];
foreach ($this->getAllPreconditions() as $instance) {
if ($instance instanceof OptionsPreconditionInterface) {
$result[] = $instance;
}
}
return $result;
} | php | public function getOptionsPreconditions()
{
$result = [];
foreach ($this->getAllPreconditions() as $instance) {
if ($instance instanceof OptionsPreconditionInterface) {
$result[] = $instance;
}
}
return $result;
} | [
"public",
"function",
"getOptionsPreconditions",
"(",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getAllPreconditions",
"(",
")",
"as",
"$",
"instance",
")",
"{",
"if",
"(",
"$",
"instance",
"instanceof",
"OptionsPreconditionInterface",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"instance",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Get the post-configuration preconditions.
@return OptionsPreconditionInterface[] | [
"Get",
"the",
"post",
"-",
"configuration",
"preconditions",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Install/PreconditionService.php#L66-L76 | train |
concrete5/concrete5 | concrete/src/Install/PreconditionService.php | PreconditionService.getPreconditionByHandle | public function getPreconditionByHandle($handle)
{
$list = $this->config->get('install.preconditions');
if (!isset($list[$handle])) {
throw new Exception(sprintf('Unable to find an install precondition with handle %s', $handle));
}
if (!$list[$handle]) {
throw new Exception(sprintf('The precondition with handle %s is disabled', $handle));
}
$className = $list[$handle];
$instance = $this->getPreconditionByClassName($className);
return $instance;
} | php | public function getPreconditionByHandle($handle)
{
$list = $this->config->get('install.preconditions');
if (!isset($list[$handle])) {
throw new Exception(sprintf('Unable to find an install precondition with handle %s', $handle));
}
if (!$list[$handle]) {
throw new Exception(sprintf('The precondition with handle %s is disabled', $handle));
}
$className = $list[$handle];
$instance = $this->getPreconditionByClassName($className);
return $instance;
} | [
"public",
"function",
"getPreconditionByHandle",
"(",
"$",
"handle",
")",
"{",
"$",
"list",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'install.preconditions'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"list",
"[",
"$",
"handle",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Unable to find an install precondition with handle %s'",
",",
"$",
"handle",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"list",
"[",
"$",
"handle",
"]",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'The precondition with handle %s is disabled'",
",",
"$",
"handle",
")",
")",
";",
"}",
"$",
"className",
"=",
"$",
"list",
"[",
"$",
"handle",
"]",
";",
"$",
"instance",
"=",
"$",
"this",
"->",
"getPreconditionByClassName",
"(",
"$",
"className",
")",
";",
"return",
"$",
"instance",
";",
"}"
] | Get a precondition given its handle.
@param string $handle the precondition handle
@throws Exception
@return PreconditionInterface | [
"Get",
"a",
"precondition",
"given",
"its",
"handle",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Install/PreconditionService.php#L87-L100 | train |
concrete5/concrete5 | concrete/src/Install/PreconditionService.php | PreconditionService.getPreconditionByClassName | public function getPreconditionByClassName($className)
{
if (!class_exists($className, true)) {
throw new Exception(sprintf('The precondition class %s does not exist', $className));
}
$result = $this->app->make($className);
if (!$result instanceof PreconditionInterface) {
throw new Exception(sprintf('The class %1$s should implement the interface %2$s', $className, PreconditionInterface::class));
}
return $result;
} | php | public function getPreconditionByClassName($className)
{
if (!class_exists($className, true)) {
throw new Exception(sprintf('The precondition class %s does not exist', $className));
}
$result = $this->app->make($className);
if (!$result instanceof PreconditionInterface) {
throw new Exception(sprintf('The class %1$s should implement the interface %2$s', $className, PreconditionInterface::class));
}
return $result;
} | [
"public",
"function",
"getPreconditionByClassName",
"(",
"$",
"className",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
",",
"true",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'The precondition class %s does not exist'",
",",
"$",
"className",
")",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"$",
"className",
")",
";",
"if",
"(",
"!",
"$",
"result",
"instanceof",
"PreconditionInterface",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'The class %1$s should implement the interface %2$s'",
",",
"$",
"className",
",",
"PreconditionInterface",
"::",
"class",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get a precondition given its fully-qualified class name.
@param string $className the fully-qualified class name of the precondition
@throws Exception
@return PreconditionInterface | [
"Get",
"a",
"precondition",
"given",
"its",
"fully",
"-",
"qualified",
"class",
"name",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Install/PreconditionService.php#L111-L122 | train |
concrete5/concrete5 | concrete/src/Install/PreconditionService.php | PreconditionService.getAllPreconditions | private function getAllPreconditions()
{
$result = [];
$list = $this->config->get('install.preconditions');
foreach ($list as $className) {
if ($className) {
$result[] = $this->getPreconditionByClassName($className);
}
}
return $result;
} | php | private function getAllPreconditions()
{
$result = [];
$list = $this->config->get('install.preconditions');
foreach ($list as $className) {
if ($className) {
$result[] = $this->getPreconditionByClassName($className);
}
}
return $result;
} | [
"private",
"function",
"getAllPreconditions",
"(",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"list",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'install.preconditions'",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"className",
")",
"{",
"if",
"(",
"$",
"className",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"this",
"->",
"getPreconditionByClassName",
"(",
"$",
"className",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Get all the defined preconditions, of any kind.
@return PreconditionInterface[] | [
"Get",
"all",
"the",
"defined",
"preconditions",
"of",
"any",
"kind",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Install/PreconditionService.php#L129-L140 | train |
concrete5/concrete5 | concrete/src/Controller/Controller.php | Controller.getThemeViewTemplate | public function getThemeViewTemplate()
{
if (isset($this->view)) {
$templateFromView = $this->view->getViewTemplateFile();
}
if (isset($this->themeViewTemplate) && $templateFromView == FILENAME_THEMES_VIEW) {
return $this->themeViewTemplate;
}
if (!isset($templateFromView)) {
$templateFromView = FILENAME_THEMES_VIEW;
}
return $templateFromView;
} | php | public function getThemeViewTemplate()
{
if (isset($this->view)) {
$templateFromView = $this->view->getViewTemplateFile();
}
if (isset($this->themeViewTemplate) && $templateFromView == FILENAME_THEMES_VIEW) {
return $this->themeViewTemplate;
}
if (!isset($templateFromView)) {
$templateFromView = FILENAME_THEMES_VIEW;
}
return $templateFromView;
} | [
"public",
"function",
"getThemeViewTemplate",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"view",
")",
")",
"{",
"$",
"templateFromView",
"=",
"$",
"this",
"->",
"view",
"->",
"getViewTemplateFile",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"themeViewTemplate",
")",
"&&",
"$",
"templateFromView",
"==",
"FILENAME_THEMES_VIEW",
")",
"{",
"return",
"$",
"this",
"->",
"themeViewTemplate",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"templateFromView",
")",
")",
"{",
"$",
"templateFromView",
"=",
"FILENAME_THEMES_VIEW",
";",
"}",
"return",
"$",
"templateFromView",
";",
"}"
] | Returns the wrapper file that holds the content of the view. Usually view.php
@return string | [
"Returns",
"the",
"wrapper",
"file",
"that",
"holds",
"the",
"content",
"of",
"the",
"view",
".",
"Usually",
"view",
".",
"php"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Controller/Controller.php#L45-L60 | train |
concrete5/concrete5 | concrete/src/Install/InstallerOptions.php | InstallerOptions.getServerTimeZone | public function getServerTimeZone($fallbackToDefault)
{
$timeZoneId = $this->getServerTimeZoneId();
if ($timeZoneId === '') {
if (!$fallbackToDefault) {
throw new UserMessageException(t('The server time zone has not been defined.'));
}
$timeZoneId = @date_default_timezone_get() ?: 'UTC';
}
try {
$result = new DateTimeZone($timeZoneId);
} catch (Exception $x) {
$result = null;
}
if ($result === null) {
throw new UserMessageException(t('Invalid server time zone: %s', $timeZoneId));
}
return $result;
} | php | public function getServerTimeZone($fallbackToDefault)
{
$timeZoneId = $this->getServerTimeZoneId();
if ($timeZoneId === '') {
if (!$fallbackToDefault) {
throw new UserMessageException(t('The server time zone has not been defined.'));
}
$timeZoneId = @date_default_timezone_get() ?: 'UTC';
}
try {
$result = new DateTimeZone($timeZoneId);
} catch (Exception $x) {
$result = null;
}
if ($result === null) {
throw new UserMessageException(t('Invalid server time zone: %s', $timeZoneId));
}
return $result;
} | [
"public",
"function",
"getServerTimeZone",
"(",
"$",
"fallbackToDefault",
")",
"{",
"$",
"timeZoneId",
"=",
"$",
"this",
"->",
"getServerTimeZoneId",
"(",
")",
";",
"if",
"(",
"$",
"timeZoneId",
"===",
"''",
")",
"{",
"if",
"(",
"!",
"$",
"fallbackToDefault",
")",
"{",
"throw",
"new",
"UserMessageException",
"(",
"t",
"(",
"'The server time zone has not been defined.'",
")",
")",
";",
"}",
"$",
"timeZoneId",
"=",
"@",
"date_default_timezone_get",
"(",
")",
"?",
":",
"'UTC'",
";",
"}",
"try",
"{",
"$",
"result",
"=",
"new",
"DateTimeZone",
"(",
"$",
"timeZoneId",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"x",
")",
"{",
"$",
"result",
"=",
"null",
";",
"}",
"if",
"(",
"$",
"result",
"===",
"null",
")",
"{",
"throw",
"new",
"UserMessageException",
"(",
"t",
"(",
"'Invalid server time zone: %s'",
",",
"$",
"timeZoneId",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get the server time zone instance.
@param bool $fallbackToDefault Fallback to the default one if the time zone is not defined?
@throws UserMessageException
@return DateTimeZone | [
"Get",
"the",
"server",
"time",
"zone",
"instance",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Install/InstallerOptions.php#L352-L371 | train |
concrete5/concrete5 | concrete/src/Install/InstallerOptions.php | InstallerOptions.load | public function load()
{
if (!$this->filesystem->isFile(DIR_CONFIG_SITE . '/site_install.php')) {
throw new UserMessageException(t('File %s could not be found.', DIRNAME_APPLICATION . '/' . DIRNAME_CONFIG . '/site_install.php'));
}
if (!$this->filesystem->isFile(DIR_CONFIG_SITE . '/site_install_user.php')) {
throw new UserMessageException(t('File %s could not be found.', DIRNAME_APPLICATION . '/' . DIRNAME_CONFIG . '/site_install_user.php'));
}
$siteInstall = $this->filesystem->getRequire(DIR_CONFIG_SITE . '/site_install.php');
if (!is_array($siteInstall)) {
throw new UserMessageException(t('The file %s contains invalid data.', DIRNAME_APPLICATION . '/' . DIRNAME_CONFIG . '/site_install.php'));
}
$siteInstallUser = @$this->filesystem->getRequire(DIR_CONFIG_SITE . '/site_install_user.php');
if (is_array($siteInstallUser)) {
$siteInstallUser += [
'startingPointHandle' => '',
'uiLocaleId' => '',
'serverTimeZone' => '',
];
} else {
if (!(
defined('INSTALL_USER_EMAIL')
&& defined('INSTALL_USER_PASSWORD_HASH')
&& defined('SITE')
&& defined('SITE_INSTALL_LOCALE')
)) {
throw new UserMessageException(t('The file %s contains invalid data.', DIRNAME_APPLICATION . '/' . DIRNAME_CONFIG . '/site_install_user.php'));
}
$siteInstallUser = [
'userEmail' => INSTALL_USER_EMAIL,
'userPasswordHash' => INSTALL_USER_PASSWORD_HASH,
'startingPointHandle' => defined('INSTALL_STARTING_POINT') ? INSTALL_STARTING_POINT : '',
'siteName' => SITE,
'siteLocaleId' => SITE_INSTALL_LOCALE,
'uiLocaleId' => defined('APP_INSTALL_LANGUAGE') ? APP_INSTALL_LANGUAGE : '',
'serverTimeZone' => defined('INSTALL_TIMEZONE') ? INSTALL_TIMEZONE : '',
];
}
$this
->setPrivacyPolicyAccepted($siteInstallUser['privacyPolicy'])
->setConfiguration($siteInstall)
->setUserEmail($siteInstallUser['userEmail'])
->setUserPasswordHash($siteInstallUser['userPasswordHash'])
->setStartingPointHandle($siteInstallUser['startingPointHandle'])
->setSiteName($siteInstallUser['siteName'])
->setSiteLocaleId($siteInstallUser['siteLocaleId'])
->setUiLocaleId($siteInstallUser['uiLocaleId'])
->setServerTimeZoneId($siteInstallUser['serverTimeZone'])
;
} | php | public function load()
{
if (!$this->filesystem->isFile(DIR_CONFIG_SITE . '/site_install.php')) {
throw new UserMessageException(t('File %s could not be found.', DIRNAME_APPLICATION . '/' . DIRNAME_CONFIG . '/site_install.php'));
}
if (!$this->filesystem->isFile(DIR_CONFIG_SITE . '/site_install_user.php')) {
throw new UserMessageException(t('File %s could not be found.', DIRNAME_APPLICATION . '/' . DIRNAME_CONFIG . '/site_install_user.php'));
}
$siteInstall = $this->filesystem->getRequire(DIR_CONFIG_SITE . '/site_install.php');
if (!is_array($siteInstall)) {
throw new UserMessageException(t('The file %s contains invalid data.', DIRNAME_APPLICATION . '/' . DIRNAME_CONFIG . '/site_install.php'));
}
$siteInstallUser = @$this->filesystem->getRequire(DIR_CONFIG_SITE . '/site_install_user.php');
if (is_array($siteInstallUser)) {
$siteInstallUser += [
'startingPointHandle' => '',
'uiLocaleId' => '',
'serverTimeZone' => '',
];
} else {
if (!(
defined('INSTALL_USER_EMAIL')
&& defined('INSTALL_USER_PASSWORD_HASH')
&& defined('SITE')
&& defined('SITE_INSTALL_LOCALE')
)) {
throw new UserMessageException(t('The file %s contains invalid data.', DIRNAME_APPLICATION . '/' . DIRNAME_CONFIG . '/site_install_user.php'));
}
$siteInstallUser = [
'userEmail' => INSTALL_USER_EMAIL,
'userPasswordHash' => INSTALL_USER_PASSWORD_HASH,
'startingPointHandle' => defined('INSTALL_STARTING_POINT') ? INSTALL_STARTING_POINT : '',
'siteName' => SITE,
'siteLocaleId' => SITE_INSTALL_LOCALE,
'uiLocaleId' => defined('APP_INSTALL_LANGUAGE') ? APP_INSTALL_LANGUAGE : '',
'serverTimeZone' => defined('INSTALL_TIMEZONE') ? INSTALL_TIMEZONE : '',
];
}
$this
->setPrivacyPolicyAccepted($siteInstallUser['privacyPolicy'])
->setConfiguration($siteInstall)
->setUserEmail($siteInstallUser['userEmail'])
->setUserPasswordHash($siteInstallUser['userPasswordHash'])
->setStartingPointHandle($siteInstallUser['startingPointHandle'])
->setSiteName($siteInstallUser['siteName'])
->setSiteLocaleId($siteInstallUser['siteLocaleId'])
->setUiLocaleId($siteInstallUser['uiLocaleId'])
->setServerTimeZoneId($siteInstallUser['serverTimeZone'])
;
} | [
"public",
"function",
"load",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"filesystem",
"->",
"isFile",
"(",
"DIR_CONFIG_SITE",
".",
"'/site_install.php'",
")",
")",
"{",
"throw",
"new",
"UserMessageException",
"(",
"t",
"(",
"'File %s could not be found.'",
",",
"DIRNAME_APPLICATION",
".",
"'/'",
".",
"DIRNAME_CONFIG",
".",
"'/site_install.php'",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"filesystem",
"->",
"isFile",
"(",
"DIR_CONFIG_SITE",
".",
"'/site_install_user.php'",
")",
")",
"{",
"throw",
"new",
"UserMessageException",
"(",
"t",
"(",
"'File %s could not be found.'",
",",
"DIRNAME_APPLICATION",
".",
"'/'",
".",
"DIRNAME_CONFIG",
".",
"'/site_install_user.php'",
")",
")",
";",
"}",
"$",
"siteInstall",
"=",
"$",
"this",
"->",
"filesystem",
"->",
"getRequire",
"(",
"DIR_CONFIG_SITE",
".",
"'/site_install.php'",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"siteInstall",
")",
")",
"{",
"throw",
"new",
"UserMessageException",
"(",
"t",
"(",
"'The file %s contains invalid data.'",
",",
"DIRNAME_APPLICATION",
".",
"'/'",
".",
"DIRNAME_CONFIG",
".",
"'/site_install.php'",
")",
")",
";",
"}",
"$",
"siteInstallUser",
"=",
"@",
"$",
"this",
"->",
"filesystem",
"->",
"getRequire",
"(",
"DIR_CONFIG_SITE",
".",
"'/site_install_user.php'",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"siteInstallUser",
")",
")",
"{",
"$",
"siteInstallUser",
"+=",
"[",
"'startingPointHandle'",
"=>",
"''",
",",
"'uiLocaleId'",
"=>",
"''",
",",
"'serverTimeZone'",
"=>",
"''",
",",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"(",
"defined",
"(",
"'INSTALL_USER_EMAIL'",
")",
"&&",
"defined",
"(",
"'INSTALL_USER_PASSWORD_HASH'",
")",
"&&",
"defined",
"(",
"'SITE'",
")",
"&&",
"defined",
"(",
"'SITE_INSTALL_LOCALE'",
")",
")",
")",
"{",
"throw",
"new",
"UserMessageException",
"(",
"t",
"(",
"'The file %s contains invalid data.'",
",",
"DIRNAME_APPLICATION",
".",
"'/'",
".",
"DIRNAME_CONFIG",
".",
"'/site_install_user.php'",
")",
")",
";",
"}",
"$",
"siteInstallUser",
"=",
"[",
"'userEmail'",
"=>",
"INSTALL_USER_EMAIL",
",",
"'userPasswordHash'",
"=>",
"INSTALL_USER_PASSWORD_HASH",
",",
"'startingPointHandle'",
"=>",
"defined",
"(",
"'INSTALL_STARTING_POINT'",
")",
"?",
"INSTALL_STARTING_POINT",
":",
"''",
",",
"'siteName'",
"=>",
"SITE",
",",
"'siteLocaleId'",
"=>",
"SITE_INSTALL_LOCALE",
",",
"'uiLocaleId'",
"=>",
"defined",
"(",
"'APP_INSTALL_LANGUAGE'",
")",
"?",
"APP_INSTALL_LANGUAGE",
":",
"''",
",",
"'serverTimeZone'",
"=>",
"defined",
"(",
"'INSTALL_TIMEZONE'",
")",
"?",
"INSTALL_TIMEZONE",
":",
"''",
",",
"]",
";",
"}",
"$",
"this",
"->",
"setPrivacyPolicyAccepted",
"(",
"$",
"siteInstallUser",
"[",
"'privacyPolicy'",
"]",
")",
"->",
"setConfiguration",
"(",
"$",
"siteInstall",
")",
"->",
"setUserEmail",
"(",
"$",
"siteInstallUser",
"[",
"'userEmail'",
"]",
")",
"->",
"setUserPasswordHash",
"(",
"$",
"siteInstallUser",
"[",
"'userPasswordHash'",
"]",
")",
"->",
"setStartingPointHandle",
"(",
"$",
"siteInstallUser",
"[",
"'startingPointHandle'",
"]",
")",
"->",
"setSiteName",
"(",
"$",
"siteInstallUser",
"[",
"'siteName'",
"]",
")",
"->",
"setSiteLocaleId",
"(",
"$",
"siteInstallUser",
"[",
"'siteLocaleId'",
"]",
")",
"->",
"setUiLocaleId",
"(",
"$",
"siteInstallUser",
"[",
"'uiLocaleId'",
"]",
")",
"->",
"setServerTimeZoneId",
"(",
"$",
"siteInstallUser",
"[",
"'serverTimeZone'",
"]",
")",
";",
"}"
] | Load the configuration options from file.
@throws UserMessageException | [
"Load",
"the",
"configuration",
"options",
"from",
"file",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Install/InstallerOptions.php#L388-L437 | train |
concrete5/concrete5 | concrete/src/Install/InstallerOptions.php | InstallerOptions.save | public function save()
{
$render = new Renderer($this->configuration);
$siteInstall = $render->render();
$render = new Renderer([
'userEmail' => $this->getUserEmail(),
'userPasswordHash' => $this->getUserPasswordHash(),
'startingPointHandle' => $this->getStartingPointHandle(),
'siteName' => $this->getSiteName(),
'siteLocaleId' => $this->getSiteLocaleId(),
'uiLocaleId' => $this->getUiLocaleId(),
'serverTimeZone' => $this->getServerTimeZoneId(),
'privacyPolicy' => $this->isPrivacyPolicyAccepted()
]);
$siteInstallUser = $render->render();
if (@$this->filesystem->put(DIR_CONFIG_SITE . '/site_install.php', $siteInstall) === false) {
throw new UserMessageException(t('Failed to write to file %s', DIRNAME_APPLICATION . '/' . DIRNAME_CONFIG . '/site_install.php'));
}
OpCache::clear(DIR_CONFIG_SITE . '/site_install_user.php');
if (@$this->filesystem->put(DIR_CONFIG_SITE . '/site_install_user.php', $siteInstallUser) === false) {
throw new UserMessageException(t('Failed to write to file %s', DIRNAME_APPLICATION . '/' . DIRNAME_CONFIG . '/site_install_user.php'));
}
OpCache::clear(DIR_CONFIG_SITE . '/site_install_user.php');
} | php | public function save()
{
$render = new Renderer($this->configuration);
$siteInstall = $render->render();
$render = new Renderer([
'userEmail' => $this->getUserEmail(),
'userPasswordHash' => $this->getUserPasswordHash(),
'startingPointHandle' => $this->getStartingPointHandle(),
'siteName' => $this->getSiteName(),
'siteLocaleId' => $this->getSiteLocaleId(),
'uiLocaleId' => $this->getUiLocaleId(),
'serverTimeZone' => $this->getServerTimeZoneId(),
'privacyPolicy' => $this->isPrivacyPolicyAccepted()
]);
$siteInstallUser = $render->render();
if (@$this->filesystem->put(DIR_CONFIG_SITE . '/site_install.php', $siteInstall) === false) {
throw new UserMessageException(t('Failed to write to file %s', DIRNAME_APPLICATION . '/' . DIRNAME_CONFIG . '/site_install.php'));
}
OpCache::clear(DIR_CONFIG_SITE . '/site_install_user.php');
if (@$this->filesystem->put(DIR_CONFIG_SITE . '/site_install_user.php', $siteInstallUser) === false) {
throw new UserMessageException(t('Failed to write to file %s', DIRNAME_APPLICATION . '/' . DIRNAME_CONFIG . '/site_install_user.php'));
}
OpCache::clear(DIR_CONFIG_SITE . '/site_install_user.php');
} | [
"public",
"function",
"save",
"(",
")",
"{",
"$",
"render",
"=",
"new",
"Renderer",
"(",
"$",
"this",
"->",
"configuration",
")",
";",
"$",
"siteInstall",
"=",
"$",
"render",
"->",
"render",
"(",
")",
";",
"$",
"render",
"=",
"new",
"Renderer",
"(",
"[",
"'userEmail'",
"=>",
"$",
"this",
"->",
"getUserEmail",
"(",
")",
",",
"'userPasswordHash'",
"=>",
"$",
"this",
"->",
"getUserPasswordHash",
"(",
")",
",",
"'startingPointHandle'",
"=>",
"$",
"this",
"->",
"getStartingPointHandle",
"(",
")",
",",
"'siteName'",
"=>",
"$",
"this",
"->",
"getSiteName",
"(",
")",
",",
"'siteLocaleId'",
"=>",
"$",
"this",
"->",
"getSiteLocaleId",
"(",
")",
",",
"'uiLocaleId'",
"=>",
"$",
"this",
"->",
"getUiLocaleId",
"(",
")",
",",
"'serverTimeZone'",
"=>",
"$",
"this",
"->",
"getServerTimeZoneId",
"(",
")",
",",
"'privacyPolicy'",
"=>",
"$",
"this",
"->",
"isPrivacyPolicyAccepted",
"(",
")",
"]",
")",
";",
"$",
"siteInstallUser",
"=",
"$",
"render",
"->",
"render",
"(",
")",
";",
"if",
"(",
"@",
"$",
"this",
"->",
"filesystem",
"->",
"put",
"(",
"DIR_CONFIG_SITE",
".",
"'/site_install.php'",
",",
"$",
"siteInstall",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"UserMessageException",
"(",
"t",
"(",
"'Failed to write to file %s'",
",",
"DIRNAME_APPLICATION",
".",
"'/'",
".",
"DIRNAME_CONFIG",
".",
"'/site_install.php'",
")",
")",
";",
"}",
"OpCache",
"::",
"clear",
"(",
"DIR_CONFIG_SITE",
".",
"'/site_install_user.php'",
")",
";",
"if",
"(",
"@",
"$",
"this",
"->",
"filesystem",
"->",
"put",
"(",
"DIR_CONFIG_SITE",
".",
"'/site_install_user.php'",
",",
"$",
"siteInstallUser",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"UserMessageException",
"(",
"t",
"(",
"'Failed to write to file %s'",
",",
"DIRNAME_APPLICATION",
".",
"'/'",
".",
"DIRNAME_CONFIG",
".",
"'/site_install_user.php'",
")",
")",
";",
"}",
"OpCache",
"::",
"clear",
"(",
"DIR_CONFIG_SITE",
".",
"'/site_install_user.php'",
")",
";",
"}"
] | Save the configuration options to file.
@throws UserMessageException | [
"Save",
"the",
"configuration",
"options",
"to",
"file",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Install/InstallerOptions.php#L444-L467 | train |
concrete5/concrete5 | concrete/src/Page/View/PageView.php | PageView.setCustomPageTheme | public function setCustomPageTheme(PageTheme $pt)
{
$this->themeObject = $pt;
$this->themePkgHandle = $pt->getPackageHandle();
} | php | public function setCustomPageTheme(PageTheme $pt)
{
$this->themeObject = $pt;
$this->themePkgHandle = $pt->getPackageHandle();
} | [
"public",
"function",
"setCustomPageTheme",
"(",
"PageTheme",
"$",
"pt",
")",
"{",
"$",
"this",
"->",
"themeObject",
"=",
"$",
"pt",
";",
"$",
"this",
"->",
"themePkgHandle",
"=",
"$",
"pt",
"->",
"getPackageHandle",
"(",
")",
";",
"}"
] | Called from previewing functions, this lets us override the page's theme with one of our own choosing. | [
"Called",
"from",
"previewing",
"functions",
"this",
"lets",
"us",
"override",
"the",
"page",
"s",
"theme",
"with",
"one",
"of",
"our",
"own",
"choosing",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Page/View/PageView.php#L50-L54 | train |
concrete5/concrete5 | concrete/controllers/panel/detail/page/attributes.php | Attributes.add_attribute | public function add_attribute()
{
$allowed = $this->assignment->getAttributesAllowedArray();
$ak = CollectionAttributeKey::getByID($_REQUEST['akID']);
if (is_object($ak) && in_array($ak->getAttributeKeyID(), $allowed)) {
$obj = $this->getAttributeJSONRepresentation($ak, 'add');
$obj->pending = true;
$obj->assets = array();
$ag = ResponseAssetGroup::get();
foreach ($ag->getAssetsToOutput() as $position => $assets) {
foreach ($assets as $asset) {
if (is_object($asset)) {
// have to do a check here because we might be included a dumb javascript call like i18n_js
$obj->assets[$asset->getAssetType()][] = $asset->getAssetURL();
}
}
}
Loader::helper('ajax')->sendResult($obj);
}
} | php | public function add_attribute()
{
$allowed = $this->assignment->getAttributesAllowedArray();
$ak = CollectionAttributeKey::getByID($_REQUEST['akID']);
if (is_object($ak) && in_array($ak->getAttributeKeyID(), $allowed)) {
$obj = $this->getAttributeJSONRepresentation($ak, 'add');
$obj->pending = true;
$obj->assets = array();
$ag = ResponseAssetGroup::get();
foreach ($ag->getAssetsToOutput() as $position => $assets) {
foreach ($assets as $asset) {
if (is_object($asset)) {
// have to do a check here because we might be included a dumb javascript call like i18n_js
$obj->assets[$asset->getAssetType()][] = $asset->getAssetURL();
}
}
}
Loader::helper('ajax')->sendResult($obj);
}
} | [
"public",
"function",
"add_attribute",
"(",
")",
"{",
"$",
"allowed",
"=",
"$",
"this",
"->",
"assignment",
"->",
"getAttributesAllowedArray",
"(",
")",
";",
"$",
"ak",
"=",
"CollectionAttributeKey",
"::",
"getByID",
"(",
"$",
"_REQUEST",
"[",
"'akID'",
"]",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"ak",
")",
"&&",
"in_array",
"(",
"$",
"ak",
"->",
"getAttributeKeyID",
"(",
")",
",",
"$",
"allowed",
")",
")",
"{",
"$",
"obj",
"=",
"$",
"this",
"->",
"getAttributeJSONRepresentation",
"(",
"$",
"ak",
",",
"'add'",
")",
";",
"$",
"obj",
"->",
"pending",
"=",
"true",
";",
"$",
"obj",
"->",
"assets",
"=",
"array",
"(",
")",
";",
"$",
"ag",
"=",
"ResponseAssetGroup",
"::",
"get",
"(",
")",
";",
"foreach",
"(",
"$",
"ag",
"->",
"getAssetsToOutput",
"(",
")",
"as",
"$",
"position",
"=>",
"$",
"assets",
")",
"{",
"foreach",
"(",
"$",
"assets",
"as",
"$",
"asset",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"asset",
")",
")",
"{",
"// have to do a check here because we might be included a dumb javascript call like i18n_js",
"$",
"obj",
"->",
"assets",
"[",
"$",
"asset",
"->",
"getAssetType",
"(",
")",
"]",
"[",
"]",
"=",
"$",
"asset",
"->",
"getAssetURL",
"(",
")",
";",
"}",
"}",
"}",
"Loader",
"::",
"helper",
"(",
"'ajax'",
")",
"->",
"sendResult",
"(",
"$",
"obj",
")",
";",
"}",
"}"
] | Retrieve attribute HTML to inject into the other view. | [
"Retrieve",
"attribute",
"HTML",
"to",
"inject",
"into",
"the",
"other",
"view",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/controllers/panel/detail/page/attributes.php#L161-L180 | train |
concrete5/concrete5 | concrete/src/Express/Export/EntryList/CsvWriter.php | CsvWriter.insertEntryList | public function insertEntryList(EntryList $list)
{
$list = clone $list;
$this->writer->insertAll($this->projectList($list));
} | php | public function insertEntryList(EntryList $list)
{
$list = clone $list;
$this->writer->insertAll($this->projectList($list));
} | [
"public",
"function",
"insertEntryList",
"(",
"EntryList",
"$",
"list",
")",
"{",
"$",
"list",
"=",
"clone",
"$",
"list",
";",
"$",
"this",
"->",
"writer",
"->",
"insertAll",
"(",
"$",
"this",
"->",
"projectList",
"(",
"$",
"list",
")",
")",
";",
"}"
] | Insert all data from the passed EntryList
@param \Concrete\Core\Express\EntryList $list | [
"Insert",
"all",
"data",
"from",
"the",
"passed",
"EntryList"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Express/Export/EntryList/CsvWriter.php#L40-L44 | train |
concrete5/concrete5 | concrete/src/Express/Export/EntryList/CsvWriter.php | CsvWriter.projectList | private function projectList(EntryList $list)
{
$headers = array_keys(iterator_to_array($this->getHeaders($list->getEntity())));
$statement = $list->deliverQueryObject()->execute();
foreach ($statement as $result) {
if ($entry = $list->getResult($result)) {
yield $this->orderedEntry(iterator_to_array($this->projectEntry($entry)), $headers);
}
}
} | php | private function projectList(EntryList $list)
{
$headers = array_keys(iterator_to_array($this->getHeaders($list->getEntity())));
$statement = $list->deliverQueryObject()->execute();
foreach ($statement as $result) {
if ($entry = $list->getResult($result)) {
yield $this->orderedEntry(iterator_to_array($this->projectEntry($entry)), $headers);
}
}
} | [
"private",
"function",
"projectList",
"(",
"EntryList",
"$",
"list",
")",
"{",
"$",
"headers",
"=",
"array_keys",
"(",
"iterator_to_array",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
"$",
"list",
"->",
"getEntity",
"(",
")",
")",
")",
")",
";",
"$",
"statement",
"=",
"$",
"list",
"->",
"deliverQueryObject",
"(",
")",
"->",
"execute",
"(",
")",
";",
"foreach",
"(",
"$",
"statement",
"as",
"$",
"result",
")",
"{",
"if",
"(",
"$",
"entry",
"=",
"$",
"list",
"->",
"getResult",
"(",
"$",
"result",
")",
")",
"{",
"yield",
"$",
"this",
"->",
"orderedEntry",
"(",
"iterator_to_array",
"(",
"$",
"this",
"->",
"projectEntry",
"(",
"$",
"entry",
")",
")",
",",
"$",
"headers",
")",
";",
"}",
"}",
"}"
] | A generator that takes an EntryList and converts it to CSV rows
@param \Concrete\Core\Express\EntryList $list
@return \Generator | [
"A",
"generator",
"that",
"takes",
"an",
"EntryList",
"and",
"converts",
"it",
"to",
"CSV",
"rows"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Express/Export/EntryList/CsvWriter.php#L51-L61 | train |
concrete5/concrete5 | concrete/src/Express/Export/EntryList/CsvWriter.php | CsvWriter.projectEntry | private function projectEntry(Entry $entry)
{
$date = $entry->getDateCreated();
if ($date) {
yield 'ccm_date_created' => $this->dateFormatter->formatCustom(\DateTime::ATOM, $date);
} else {
yield 'ccm_date_created' => null;
}
$attributes = $entry->getAttributes();
foreach ($attributes as $attribute) {
yield $attribute->getAttributeKey()->getAttributeKeyHandle() => $attribute->getPlainTextValue();
}
} | php | private function projectEntry(Entry $entry)
{
$date = $entry->getDateCreated();
if ($date) {
yield 'ccm_date_created' => $this->dateFormatter->formatCustom(\DateTime::ATOM, $date);
} else {
yield 'ccm_date_created' => null;
}
$attributes = $entry->getAttributes();
foreach ($attributes as $attribute) {
yield $attribute->getAttributeKey()->getAttributeKeyHandle() => $attribute->getPlainTextValue();
}
} | [
"private",
"function",
"projectEntry",
"(",
"Entry",
"$",
"entry",
")",
"{",
"$",
"date",
"=",
"$",
"entry",
"->",
"getDateCreated",
"(",
")",
";",
"if",
"(",
"$",
"date",
")",
"{",
"yield",
"'ccm_date_created'",
"=>",
"$",
"this",
"->",
"dateFormatter",
"->",
"formatCustom",
"(",
"\\",
"DateTime",
"::",
"ATOM",
",",
"$",
"date",
")",
";",
"}",
"else",
"{",
"yield",
"'ccm_date_created'",
"=>",
"null",
";",
"}",
"$",
"attributes",
"=",
"$",
"entry",
"->",
"getAttributes",
"(",
")",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
")",
"{",
"yield",
"$",
"attribute",
"->",
"getAttributeKey",
"(",
")",
"->",
"getAttributeKeyHandle",
"(",
")",
"=>",
"$",
"attribute",
"->",
"getPlainTextValue",
"(",
")",
";",
"}",
"}"
] | Turn an Entry into an array
@param \Concrete\Core\Entity\Express\Entry $entry
@return array | [
"Turn",
"an",
"Entry",
"into",
"an",
"array"
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Express/Export/EntryList/CsvWriter.php#L86-L99 | train |
concrete5/concrete5 | concrete/src/Package/PackageService.php | PackageService.getAvailablePackages | public function getAvailablePackages($onlyNotInstalled = true)
{
$dh = $this->application->make('helper/file');
$packages = $dh->getDirectoryContents(DIR_PACKAGES);
if ($onlyNotInstalled) {
$handles = $this->getInstalledHandles();
$packages = array_diff($packages, $handles);
}
if (count($packages) > 0) {
$packagesTemp = [];
// get package objects from the file system
foreach ($packages as $p) {
if (file_exists(DIR_PACKAGES . '/' . $p . '/' . FILENAME_CONTROLLER)) {
$pkg = $this->getClass($p);
if (!empty($pkg)) {
$packagesTemp[] = $pkg;
}
}
}
$packages = $packagesTemp;
}
return $packages;
} | php | public function getAvailablePackages($onlyNotInstalled = true)
{
$dh = $this->application->make('helper/file');
$packages = $dh->getDirectoryContents(DIR_PACKAGES);
if ($onlyNotInstalled) {
$handles = $this->getInstalledHandles();
$packages = array_diff($packages, $handles);
}
if (count($packages) > 0) {
$packagesTemp = [];
// get package objects from the file system
foreach ($packages as $p) {
if (file_exists(DIR_PACKAGES . '/' . $p . '/' . FILENAME_CONTROLLER)) {
$pkg = $this->getClass($p);
if (!empty($pkg)) {
$packagesTemp[] = $pkg;
}
}
}
$packages = $packagesTemp;
}
return $packages;
} | [
"public",
"function",
"getAvailablePackages",
"(",
"$",
"onlyNotInstalled",
"=",
"true",
")",
"{",
"$",
"dh",
"=",
"$",
"this",
"->",
"application",
"->",
"make",
"(",
"'helper/file'",
")",
";",
"$",
"packages",
"=",
"$",
"dh",
"->",
"getDirectoryContents",
"(",
"DIR_PACKAGES",
")",
";",
"if",
"(",
"$",
"onlyNotInstalled",
")",
"{",
"$",
"handles",
"=",
"$",
"this",
"->",
"getInstalledHandles",
"(",
")",
";",
"$",
"packages",
"=",
"array_diff",
"(",
"$",
"packages",
",",
"$",
"handles",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"packages",
")",
">",
"0",
")",
"{",
"$",
"packagesTemp",
"=",
"[",
"]",
";",
"// get package objects from the file system",
"foreach",
"(",
"$",
"packages",
"as",
"$",
"p",
")",
"{",
"if",
"(",
"file_exists",
"(",
"DIR_PACKAGES",
".",
"'/'",
".",
"$",
"p",
".",
"'/'",
".",
"FILENAME_CONTROLLER",
")",
")",
"{",
"$",
"pkg",
"=",
"$",
"this",
"->",
"getClass",
"(",
"$",
"p",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"pkg",
")",
")",
"{",
"$",
"packagesTemp",
"[",
"]",
"=",
"$",
"pkg",
";",
"}",
"}",
"}",
"$",
"packages",
"=",
"$",
"packagesTemp",
";",
"}",
"return",
"$",
"packages",
";",
"}"
] | Get the package controllers of the available packages.
@param bool $onlyNotInstalled true to get the controllers of not installed packages, false to get all the package controllers
@return \Concrete\Core\Package\Package[] | [
"Get",
"the",
"package",
"controllers",
"of",
"the",
"available",
"packages",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Package/PackageService.php#L100-L124 | train |
concrete5/concrete5 | concrete/src/Package/PackageService.php | PackageService.getLocalUpgradeablePackages | public function getLocalUpgradeablePackages()
{
$packages = $this->getAvailablePackages(false);
$upgradeables = [];
foreach ($packages as $p) {
$entity = $this->getByHandle($p->getPackageHandle());
if ($entity) {
if (version_compare($p->getPackageVersion(), $entity->getPackageVersion(), '>')) {
$p->pkgCurrentVersion = $entity->getPackageVersion();
$upgradeables[] = $p;
}
}
}
return $upgradeables;
} | php | public function getLocalUpgradeablePackages()
{
$packages = $this->getAvailablePackages(false);
$upgradeables = [];
foreach ($packages as $p) {
$entity = $this->getByHandle($p->getPackageHandle());
if ($entity) {
if (version_compare($p->getPackageVersion(), $entity->getPackageVersion(), '>')) {
$p->pkgCurrentVersion = $entity->getPackageVersion();
$upgradeables[] = $p;
}
}
}
return $upgradeables;
} | [
"public",
"function",
"getLocalUpgradeablePackages",
"(",
")",
"{",
"$",
"packages",
"=",
"$",
"this",
"->",
"getAvailablePackages",
"(",
"false",
")",
";",
"$",
"upgradeables",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"packages",
"as",
"$",
"p",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"getByHandle",
"(",
"$",
"p",
"->",
"getPackageHandle",
"(",
")",
")",
";",
"if",
"(",
"$",
"entity",
")",
"{",
"if",
"(",
"version_compare",
"(",
"$",
"p",
"->",
"getPackageVersion",
"(",
")",
",",
"$",
"entity",
"->",
"getPackageVersion",
"(",
")",
",",
"'>'",
")",
")",
"{",
"$",
"p",
"->",
"pkgCurrentVersion",
"=",
"$",
"entity",
"->",
"getPackageVersion",
"(",
")",
";",
"$",
"upgradeables",
"[",
"]",
"=",
"$",
"p",
";",
"}",
"}",
"}",
"return",
"$",
"upgradeables",
";",
"}"
] | Get the controllers of packages that have newer versions in the local packages directory than those which are in the Packages table.
This means they're ready to be upgraded.
@return \Concrete\Core\Package\Package[] | [
"Get",
"the",
"controllers",
"of",
"packages",
"that",
"have",
"newer",
"versions",
"in",
"the",
"local",
"packages",
"directory",
"than",
"those",
"which",
"are",
"in",
"the",
"Packages",
"table",
".",
"This",
"means",
"they",
"re",
"ready",
"to",
"be",
"upgraded",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Package/PackageService.php#L132-L147 | train |
concrete5/concrete5 | concrete/src/Package/PackageService.php | PackageService.getInstalledHandles | public function getInstalledHandles()
{
$query = 'select p.pkgHandle from \\Concrete\\Core\\Entity\\Package p';
$r = $this->entityManager->createQuery($query);
$result = $r->getArrayResult();
$handles = [];
foreach ($result as $r) {
$handles[] = $r['pkgHandle'];
}
return $handles;
} | php | public function getInstalledHandles()
{
$query = 'select p.pkgHandle from \\Concrete\\Core\\Entity\\Package p';
$r = $this->entityManager->createQuery($query);
$result = $r->getArrayResult();
$handles = [];
foreach ($result as $r) {
$handles[] = $r['pkgHandle'];
}
return $handles;
} | [
"public",
"function",
"getInstalledHandles",
"(",
")",
"{",
"$",
"query",
"=",
"'select p.pkgHandle from \\\\Concrete\\\\Core\\\\Entity\\\\Package p'",
";",
"$",
"r",
"=",
"$",
"this",
"->",
"entityManager",
"->",
"createQuery",
"(",
"$",
"query",
")",
";",
"$",
"result",
"=",
"$",
"r",
"->",
"getArrayResult",
"(",
")",
";",
"$",
"handles",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"r",
")",
"{",
"$",
"handles",
"[",
"]",
"=",
"$",
"r",
"[",
"'pkgHandle'",
"]",
";",
"}",
"return",
"$",
"handles",
";",
"}"
] | Get the handles of all the installed packages.
@return string[] | [
"Get",
"the",
"handles",
"of",
"all",
"the",
"installed",
"packages",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Package/PackageService.php#L154-L165 | train |
concrete5/concrete5 | concrete/src/Package/PackageService.php | PackageService.getRemotelyUpgradeablePackages | public function getRemotelyUpgradeablePackages()
{
$packages = $this->getInstalledList();
$upgradeables = [];
foreach ($packages as $p) {
if (version_compare($p->getPackageVersion(), $p->getPackageVersionUpdateAvailable(), '<')) {
$upgradeables[] = $p;
}
}
return $upgradeables;
} | php | public function getRemotelyUpgradeablePackages()
{
$packages = $this->getInstalledList();
$upgradeables = [];
foreach ($packages as $p) {
if (version_compare($p->getPackageVersion(), $p->getPackageVersionUpdateAvailable(), '<')) {
$upgradeables[] = $p;
}
}
return $upgradeables;
} | [
"public",
"function",
"getRemotelyUpgradeablePackages",
"(",
")",
"{",
"$",
"packages",
"=",
"$",
"this",
"->",
"getInstalledList",
"(",
")",
";",
"$",
"upgradeables",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"packages",
"as",
"$",
"p",
")",
"{",
"if",
"(",
"version_compare",
"(",
"$",
"p",
"->",
"getPackageVersion",
"(",
")",
",",
"$",
"p",
"->",
"getPackageVersionUpdateAvailable",
"(",
")",
",",
"'<'",
")",
")",
"{",
"$",
"upgradeables",
"[",
"]",
"=",
"$",
"p",
";",
"}",
"}",
"return",
"$",
"upgradeables",
";",
"}"
] | Get the controllers of the packages that have an upgraded version available in the marketplace.
@return \Concrete\Core\Package\Package[] | [
"Get",
"the",
"controllers",
"of",
"the",
"packages",
"that",
"have",
"an",
"upgraded",
"version",
"available",
"in",
"the",
"marketplace",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Package/PackageService.php#L172-L183 | train |
concrete5/concrete5 | concrete/src/Package/PackageService.php | PackageService.bootPackageEntityManager | public function bootPackageEntityManager(Package $p, $clearCache = false)
{
$configUpdater = new EntityManagerConfigUpdater($this->entityManager);
$providerFactory = new PackageProviderFactory($this->application, $p);
$provider = $providerFactory->getEntityManagerProvider();
$configUpdater->addProvider($provider);
if ($clearCache) {
$cache = $this->entityManager->getConfiguration()->getMetadataCacheImpl();
if ($cache) {
$cache->flushAll();
}
}
} | php | public function bootPackageEntityManager(Package $p, $clearCache = false)
{
$configUpdater = new EntityManagerConfigUpdater($this->entityManager);
$providerFactory = new PackageProviderFactory($this->application, $p);
$provider = $providerFactory->getEntityManagerProvider();
$configUpdater->addProvider($provider);
if ($clearCache) {
$cache = $this->entityManager->getConfiguration()->getMetadataCacheImpl();
if ($cache) {
$cache->flushAll();
}
}
} | [
"public",
"function",
"bootPackageEntityManager",
"(",
"Package",
"$",
"p",
",",
"$",
"clearCache",
"=",
"false",
")",
"{",
"$",
"configUpdater",
"=",
"new",
"EntityManagerConfigUpdater",
"(",
"$",
"this",
"->",
"entityManager",
")",
";",
"$",
"providerFactory",
"=",
"new",
"PackageProviderFactory",
"(",
"$",
"this",
"->",
"application",
",",
"$",
"p",
")",
";",
"$",
"provider",
"=",
"$",
"providerFactory",
"->",
"getEntityManagerProvider",
"(",
")",
";",
"$",
"configUpdater",
"->",
"addProvider",
"(",
"$",
"provider",
")",
";",
"if",
"(",
"$",
"clearCache",
")",
"{",
"$",
"cache",
"=",
"$",
"this",
"->",
"entityManager",
"->",
"getConfiguration",
"(",
")",
"->",
"getMetadataCacheImpl",
"(",
")",
";",
"if",
"(",
"$",
"cache",
")",
"{",
"$",
"cache",
"->",
"flushAll",
"(",
")",
";",
"}",
"}",
"}"
] | Initialize the entity manager for a package.
@param \Concrete\Core\Package\Package $p The controller of package
@param bool $clearCache Should the entity metadata cache be emptied? | [
"Initialize",
"the",
"entity",
"manager",
"for",
"a",
"package",
"."
] | c54c94e4eb6d45696fed85a5b8b415f70ea677b8 | https://github.com/concrete5/concrete5/blob/c54c94e4eb6d45696fed85a5b8b415f70ea677b8/concrete/src/Package/PackageService.php#L191-L203 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.