public function __construct() { $acl = Bootstrap::get('acl'); $adapter = Bootstrap::get('ZendDb'); $this->filesystem = Bootstrap::get('filesystem'); $config = Bootstrap::get('config'); $this->config = $config['filesystem'] ?: []; // Fetch files settings $Settings = new DirectusSettingsTableGateway($acl, $adapter); $this->filesSettings = $Settings->fetchCollection('files', array('storage_adapter', 'storage_destination', 'thumbnail_storage_adapter', 'thumbnail_storage_destination', 'thumbnail_size', 'thumbnail_quality', 'thumbnail_crop_enabled')); }
public function __construct() { $this->acl = Bootstrap::get('acl'); $this->adapter = Bootstrap::get('ZendDb'); // Fetch files settings $Settings = new DirectusSettingsTableGateway($this->acl, $this->adapter); $this->filesSettings = $Settings->fetchCollection('files', array('storage_adapter', 'storage_destination', 'thumbnail_storage_adapter', 'thumbnail_storage_destination', 'thumbnail_size', 'thumbnail_quality', 'thumbnail_crop_enabled')); // Initialize Storage Adapters $StorageAdapters = new DirectusStorageAdaptersTableGateway($this->acl, $this->adapter); $adapterRoles = array('DEFAULT', 'THUMBNAIL', 'TEMP'); $storage = $StorageAdapters->fetchByUniqueRoles($adapterRoles); if (count($storage) !== count($adapterRoles)) { throw new \RuntimeException(__CLASS__ . ' expects adapter settings for these default adapter roles: ' . implode(',', $adapterRoles)); } $this->FilesStorage = self::getStorage($storage['DEFAULT']); $this->ThumbnailStorage = self::getStorage($storage['THUMBNAIL']); $this->storageAdaptersByRole = $storage; }
/** * @return \Directus\Embed\EmbedManager */ private static function embedManager() { $embedManager = new EmbedManager(); $acl = static::get('acl'); $adapter = static::get('ZendDb'); // Fetch files settings $SettingsTable = new DirectusSettingsTableGateway($acl, $adapter); try { $settings = $SettingsTable->fetchCollection('files', ['thumbnail_size', 'thumbnail_quality', 'thumbnail_crop_enabled']); } catch (\Exception $e) { $settings = []; $log = static::get('log'); $log->warn($e); } $providers = ['\\Directus\\Embed\\Provider\\VimeoProvider', '\\Directus\\Embed\\Provider\\YoutubeProvider']; $path = implode(DIRECTORY_SEPARATOR, [BASE_PATH, 'customs', 'embeds', '*.php']); foreach (glob($path) as $filename) { $providers[] = '\\Directus\\Embed\\Provider\\' . basename($filename, '.php'); } foreach ($providers as $providerClass) { $provider = new $providerClass($settings); $embedManager->register($provider); } return $embedManager; }
array_push($column_settings, $col); } $TableGateway->updateCollection($column_settings); } $UiOptions = new DirectusUiTableGateway($acl, $ZendDb); $response = $UiOptions->fetchOptions($table, $column, $ui); if (!$response) { $app->response()->setStatus(404); $response = ['message' => __t('unable_to_find_column_x_options_for_x', ['column' => $column, 'ui' => $ui]), 'success' => false]; } JsonView::render($response); })->via('GET', 'POST', 'PUT'); $app->notFound(function () use($app, $acl, $ZendDb) { $app->response()->header('Content-Type', 'text/html; charset=utf-8'); $settingsTable = new DirectusSettingsTableGateway($acl, $ZendDb); $settings = $settingsTable->fetchCollection('global'); $projectName = isset($settings['project_name']) ? $settings['project_name'] : 'Directus'; $projectLogoURL = '/assets/img/directus-logo-flat.svg'; if (isset($settings['cms_thumbnail_url']) && $settings['cms_thumbnail_url']) { $projectLogoURL = $settings['cms_thumbnail_url']; } $data = ['project_name' => $projectName, 'project_logo' => $projectLogoURL]; $app->render('errors/404.twig.html', $data); }); /** * Run the Router */ if (isset($_GET['run_api_router']) && $_GET['run_api_router']) { // Run Slim $app->response()->header('Content-Type', 'application/json; charset=utf-8'); $app->run();
private function getInstagramSettings() { $acl = Bootstrap::get('acl'); $ZendDb = Bootstrap::get('ZendDb'); $SettingsTableGateway = new DirectusSettingsTableGateway($acl, $ZendDb); $requiredKeys = ['instagram_oauth_access_token', 'instagram_client_id']; return $SettingsTableGateway->fetchCollection('social', $requiredKeys); }
use Directus\Db\TableGateway\AclAwareTableGateway; use Directus\Db\TableGateway\DirectusSettingsTableGateway; use Directus\Db\TableGateway\DirectusStorageAdaptersTableGateway; use Directus\Files\Thumbnail; use Zend\Db\TableGateway\TableGateway; require 'directusLoader.php'; function out($string) { echo "{$string}\n"; } $supportedExtensions = array('jpg', 'jpeg', 'png', 'gif'); out("Running script with the following supported extensions: " . implode(", ", $supportedExtensions)); $db = \Directus\Bootstrap::get('ZendDb'); $acl = \Directus\Bootstrap::get('acl'); $Settings = new DirectusSettingsTableGateway($acl, $db); $filesSettings = $Settings->fetchCollection('media', array('storage_adapter', 'storage_destination', 'thumbnail_storage_adapter', 'thumbnail_storage_destination', 'thumbnail_size', 'thumbnail_quality', 'thumbnail_crop_enabled')); $StorageAdapters = new DirectusStorageAdaptersTableGateway($acl, $db); $storageAdaptersById = $StorageAdapters->fetchAllWithIdKeys(); foreach ($storageAdaptersById as $id => $storageAdapter) { $storageAdaptersById[$id] = \Directus\Files\Storage\Storage::getStorage($storageAdapter); } out("\nLoaded " . count($storageAdaptersById) . " storage adapters."); $DirectusMedia = new TableGateway('directus_files', $db); $mediaRecords = $DirectusMedia->select(); out("Found " . $mediaRecords->count() . " Directus media records."); $thumbnailStorageAdapterResultSet = $StorageAdapters->fetchByUniqueRoles(array('THUMBNAIL')); if (1 != count($thumbnailStorageAdapterResultSet)) { throw new \RuntimeException("Fatal: exactly one storage adapter with role THUMBNAIL is required"); } $thumbnailStorageAdapterSettings = array_pop($thumbnailStorageAdapterResultSet); if ('FileSystemAdapter' != $thumbnailStorageAdapterSettings['adapter_name']) {
/** * Construct CodeBird Twitter API Client * @return \Codebird\Codebird */ private static function codebird() { $acl = self::get('acl'); $db = self::get('ZendDb'); // Social settings $SettingsTableGateway = new DirectusSettingsTableGateway($acl, $db); $requiredKeys = array('twitter_consumer_key', 'twitter_consumer_secret', 'twitter_oauth_token', 'twitter_oauth_token_secret'); $socialSettings = $SettingsTableGateway->fetchCollection('social', $requiredKeys); // Codebird initialization \Codebird\Codebird::setConsumerKey($socialSettings['twitter_consumer_key'], $socialSettings['twitter_consumer_secret']); $cb = \Codebird\Codebird::getInstance(); $cb->setToken($socialSettings['twitter_oauth_token'], $socialSettings['twitter_oauth_token_secret']); return $cb; }
//Used to grab thumbs from temp and put to thumbs use Directus\Db\TableGateway\DirectusSettingsTableGateway; use Directus\Db\TableGateway\DirectusStorageAdaptersTableGateway; use Directus\Files\Thumbnail; use Zend\Db\TableGateway\TableGateway; require 'directusLoader.php'; function out($string) { echo "{$string}\n"; } $supportedExtensions = ['jpg', 'jpeg', 'png', 'gif']; out('Running script with the following supported extensions: ' . implode(', ', $supportedExtensions)); $db = \Directus\Bootstrap::get('ZendDb'); $acl = \Directus\Bootstrap::get('acl'); $Settings = new DirectusSettingsTableGateway($acl, $db); $filesSettings = $Settings->fetchCollection('media', ['thumbnail_size', 'thumbnail_quality', 'thumbnail_crop_enabled']); $StorageAdapters = new DirectusStorageAdaptersTableGateway($acl, $db); $storageAdaptersById = $StorageAdapters->fetchAllWithIdKeys(); foreach ($storageAdaptersById as $id => $storageAdapter) { // @TODO: fix this, this class was removed time ago. $storageAdaptersById[$id] = \Directus\Files\Storage\Storage::getStorage($storageAdapter); } out("\nLoaded " . count($storageAdaptersById) . ' storage adapters.'); $DirectusMedia = new TableGateway('directus_files', $db); $mediaRecords = $DirectusMedia->select(); out('Found ' . $mediaRecords->count() . ' Directus media records.'); $thumbnailStorageAdapterResultSet = $StorageAdapters->fetchByUniqueRoles(['THUMBNAIL']); if (1 != count($thumbnailStorageAdapterResultSet)) { throw new \RuntimeException('Fatal: exactly one storage adapter with role THUMBNAIL is required'); } $thumbnailStorageAdapterSettings = array_pop($thumbnailStorageAdapterResultSet);