public function testSanitizeTitle() { $title = 'this is a text example'; $this->assertEquals('this-is-a-text-example', Formatting::sanitize_title_with_dashes($title)); $title = 'this–is—a text example'; $this->assertEquals('this-is-a-text-example', Formatting::sanitize_title_with_dashes($title, '', 'save')); }
public function acceptFile($localFile, $targetFileName) { $settings = $this->filesSettings; $fileData = $this->FilesStorage->getUploadInfo($localFile); // Generate thumbnail if image $thumbnailTempName = null; $info = pathinfo($targetFileName); if (in_array($info['extension'], array('jpg', 'jpeg', 'png', 'gif', 'tif', 'tiff', 'psd', 'pdf'))) { $img = Thumbnail::generateThumbnail($localFile, $info['extension'], $settings['thumbnail_size'], $settings['thumbnail_crop_enabled']); if ($img) { $thumbnailTempName = tempnam(sys_get_temp_dir(), 'DirectusThumbnail'); Thumbnail::writeImage($info['extension'], $thumbnailTempName, $img, $settings['thumbnail_quality']); } } // Push original file $filesAdapter = $this->storageAdaptersByRole['TEMP']; $finalPath = $this->FilesStorage->acceptFile($localFile, $targetFileName, $filesAdapter['destination']); $fileData['name'] = basename($finalPath); $fileData['title'] = Formatting::fileNameToFileTitle($fileData['name']); $fileData['date_uploaded'] = gmdate('Y-m-d H:i:s'); $fileData['storage_adapter'] = $filesAdapter['id']; // Push thumbnail file if applicable (if image) with prefix THUMB_ if (!is_null($thumbnailTempName)) { $info = pathinfo($fileData['name']); if (in_array($info['extension'], array('tif', 'tiff', 'pdf', 'psd'))) { $this->ThumbnailStorage->acceptFile($thumbnailTempName, 'THUMB_' . $info['filename'] . '.jpg', $filesAdapter['destination']); } else { $this->ThumbnailStorage->acceptFile($thumbnailTempName, 'THUMB_' . $fileData['name'], $filesAdapter['destination']); } } return $fileData; }
/** * Underscore to camelcase table name to namespaced table gateway classname, * e.g. directus_users => \Directus\Db\TableGateway\DirectusUsersTableGateway */ public static function makeTableGatewayFromTableName($acl, $table, $adapter) { $tableGatewayClassName = Formatting::underscoreToCamelCase($table) . "TableGateway"; $tableGatewayClassName = __NAMESPACE__ . "\\{$tableGatewayClassName}"; if (class_exists($tableGatewayClassName)) { return new $tableGatewayClassName($acl, $adapter); } return new self($acl, $table, $adapter); }
/** * HELPER FUNCTIONS */ public static function makeRowGatewayFromTableName($acl, $table, $adapter, $pkFieldName = 'id') { // Underscore to camelcase table name to namespaced row gateway classname, // e.g. directus_users => \Directus\Db\RowGateway\DirectusUsersRowGateway $rowGatewayClassName = Formatting::underscoreToCamelCase($table) . "RowGateway"; $rowGatewayClassName = __NAMESPACE__ . "\\{$rowGatewayClassName}"; if (class_exists($rowGatewayClassName)) { return new $rowGatewayClassName($acl, $pkFieldName, $table, $adapter); } return new self($acl, $pkFieldName, $table, $adapter); }
/** * @param $table * @param $adapter * @param string $primaryKeyColumn * * @return BaseRowGateway */ public static function makeRowGatewayFromTableNameSkipAcl($table, $adapter, $primaryKeyColumn = 'id') { // Underscore to camelcase table name to namespaced row gateway classname, // e.g. directus_users => \Directus\Db\RowGateway\DirectusUsersRowGateway $rowGatewayClassName = Formatting::underscoreToCamelCase($table) . 'RowGateway'; $rowGatewayClassName = __NAMESPACE__ . '\\' . $rowGatewayClassName; if (class_exists($rowGatewayClassName)) { return new $rowGatewayClassName($primaryKeyColumn, $table, $adapter); } return new self($primaryKeyColumn, $table, $adapter); }
/** * Creates a new file for Directus Media * * @param string $filePath * @param string $targetName * * @return Array file info */ private function processUpload($filePath, $targetName) { // set true as $filePath it's outside adapter path // $filePath is on a temporary php directory $fileData = $this->getFileInfo($filePath, true); $mediaPath = $this->filesystem->getPath(); $fileData['title'] = Formatting::fileNameToFileTitle($targetName); $targetName = $this->getFileName($targetName); $finalPath = rtrim($mediaPath, '/') . '/' . $targetName; $data = file_get_contents($filePath); $this->emitter->run('files.saving', ['name' => $targetName, 'size' => strlen($data)]); $this->filesystem->getAdapter()->write($targetName, $data); $this->emitter->run('files.saving:after', ['name' => $targetName, 'size' => strlen($data)]); $fileData['name'] = basename($finalPath); $fileData['date_uploaded'] = DateUtils::now(); $fileData['storage_adapter'] = $this->config['adapter']; return $fileData; }
public function testUnderscoreToCamelCase() { $this->assertEquals(Formatting::underscoreToCamelCase('hello_world'), 'HelloWorld'); }
/** * Creates a new file for Directus Media * * @param string $filePath * @param string $targetName * * @return Array file info */ private function processUpload($filePath, $targetName) { // set true as $filePath it's outside adapter path // $filePath is on a temporary php directory $fileData = $this->getFileInfo($filePath, true); $mediaPath = $this->filesystem->getPath(); $fileData['title'] = Formatting::fileNameToFileTitle($targetName); $targetName = $this->getFileName($targetName); $finalPath = rtrim($mediaPath, '/') . '/' . $targetName; $this->filesystem->getAdapter()->write($targetName, file_get_contents($filePath)); $fileData['name'] = basename($finalPath); $fileData['date_uploaded'] = gmdate('Y-m-d H:i:s'); $fileData['storage_adapter'] = $this->config['adapter']; return $fileData; }