Exemplo n.º 1
0
        echo "<h1>404 Not found</h1>";
        exit;
    };
    $DirectusMedia = new TableGateway('directus_files', $ZendDb);
    $media = $DirectusMedia->select(function ($select) use($id) {
        $select->where->equalTo('id', $id);
        $select->limit(1);
    });
    if (0 == $media->count()) {
        return $notFound();
    }
    $media = $media->current();
    if ($filename != $media['name']) {
        $correctUrl = $app->urlFor('media_proxy_file', array('id' => $id, 'format' => $format, 'filename' => $media['name']));
        return $app->redirect($correctUrl);
    }
    $StorageAdapters = new DirectusStorageAdaptersTableGateway($acl, $ZendDb);
    $storage = $StorageAdapters->find($media['storage_adapter']);
    $params = @json_decode($storage['params'], true);
    $params = empty($params) ? array() : $params;
    $storage['params'] = $params;
    $MediaStorage = \Directus\Files\Storage\Storage::getStorage($storage);
    header('Content-type: ' . $media['type']);
    echo $MediaStorage->getFileContents($media['name'], $storage['destination']);
    exit;
    // Prevent Slim from overriding our headers
})->conditions(array('id' => '\\d+'))->name('media_proxy_file');
foreach (glob("client_auth_proxies/*.php") as $filename) {
    require_once $filename;
}
$app->run();
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']) {
    throw new \RuntimeException("Fatal: THUMBNAIL storage adapter: only FileSystemAdapter is currently supported by this script");
}
$thumbnailStorageAdapter = $storageAdaptersById[$thumbnailStorageAdapterSettings['id']];
$tempStorageAdapterResultSet = $StorageAdapters->fetchByUniqueRoles(array('TEMP'));
Exemplo n.º 3
0
 * UPLOAD COLLECTION
 */
$app->post("/{$v}/upload/?", function () use($params, $requestPayload, $app, $acl, $ZendDb) {
    // $Transfer = new Files\Transfer();
    $Storage = new Files\Storage\Storage();
    $result = array();
    foreach ($_FILES as $file) {
        // $fileData = $Transfer->acceptFile($file['tmp_name'], $file['name']);
        $fileData = array('caption' => '', 'tags' => '', 'location' => '');
        $fileData = array_merge($fileData, $Storage->acceptFile($file['tmp_name'], $file['name']));
        $result[] = array('type' => $fileData['type'], 'name' => $fileData['name'], 'title' => $fileData['title'], 'tags' => $fileData['tags'], 'caption' => $fileData['caption'], 'location' => $fileData['location'], 'charset' => $fileData['charset'], 'size' => $fileData['size'], 'width' => $fileData['width'], 'height' => $fileData['height'], 'date_uploaded' => $fileData['date_uploaded'] . ' UTC', 'storage_adapter' => $fileData['storage_adapter']);
    }
    JsonView::render($result);
});
$app->post("/{$v}/upload/link/?", function () use($params, $requestPayload, $app, $acl, $ZendDb) {
    $Storage = new Files\Storage\Storage();
    $result = array();
    if (isset($_POST['link'])) {
        $fileData = array('caption' => '', 'tags' => '', 'location' => '');
        $fileData = array_merge($fileData, $Storage->acceptLink($_POST['link']));
        $result[] = array('type' => $fileData['type'], 'name' => $fileData['name'], 'title' => $fileData['title'], 'tags' => $fileData['tags'], 'caption' => $fileData['caption'], 'location' => $fileData['location'], 'charset' => $fileData['charset'], 'size' => $fileData['size'], 'width' => $fileData['width'], 'height' => $fileData['height'], 'url' => isset($fileData['url']) ? $fileData['url'] : '', 'data' => isset($fileData['data']) ? $fileData['data'] : null);
    }
    JsonView::render($result);
});
$app->get("/{$v}/messages/rows/?", function () use($params, $requestPayload, $app, $acl, $ZendDb) {
    $currentUser = Auth::getUserInfo();
    if (isset($_GET['max_id'])) {
        $messagesRecipientsTableGateway = new DirectusMessagesRecipientsTableGateway($acl, $ZendDb);
        $ids = $messagesRecipientsTableGateway->getMessagesNewerThan($_GET['max_id'], $currentUser['id']);
        if (sizeof($ids) > 0) {
            $messagesTableGateway = new DirectusMessagesTableGateway($acl, $ZendDb);
Exemplo n.º 4
0
 /**
  * @param string $table
  * @param array $recordData
  * @return bool
  */
 public function copyFiles($tableName, &$recordData)
 {
     $schemaArray = TableSchema::getSchemaArray($tableName);
     foreach ($schemaArray as $column) {
         $colName = $column['id'];
         // Ignore absent values & non-arrays
         if (!isset($recordData[$colName]) || !is_array($recordData[$colName])) {
             continue;
         }
         $foreignRow = $recordData[$colName];
         $colUiType = $column['ui'];
         // $isManyToOne = (array_key_exists('relationship', $column) &&
         //     $column['relationship']['type'] == 'MANYTOONE'
         // );
         // $isManyToMany = (array_key_exists('relationship', $column) &&
         //     $column['relationship']['type'] == 'MANYTOMANY'
         // );
         $foreignTableName = $column['relationship']['table_related'];
         // @todo: rewrite this
         if ($foreignTableName === 'directus_files') {
             // Update/Add foreign record
             $Storage = new Files\Storage\Storage();
             if (count(array_filter($foreignRow, 'is_array')) == count($foreignRow)) {
                 $index = 0;
                 foreach ($foreignRow as $row) {
                     if (!isset($row['data'][$this->primaryKeyFieldName]) && isset($row['data']['data'])) {
                         $recordData[$colName][$index]['data'] = $Storage->saveData($row['data']['data'], $row['data']['name']);
                     }
                     unset($recordData[$colName][$index]['data']['data']);
                     $index++;
                 }
             } else {
                 if (!isset($foreignRow[$this->primaryKeyFieldName]) && isset($foreignRow['data'])) {
                     $recordData[$colName] = $Storage->saveData($foreignRow['data'], $foreignRow['name']);
                 }
                 unset($recordData[$colName]['data']);
             }
         }
     }
     return true;
 }