示例#1
0
 /**
  * Get Hook Emitter
  *
  * @return Emitter
  */
 private static function hookEmitter()
 {
     $emitter = new Emitter();
     $emitter->addAction('application.error', function ($e) {
         $log = Bootstrap::get('log');
         $log->error($e);
     });
     $emitter->addAction('table.insert.directus_groups', function ($data) {
         $acl = Bootstrap::get('acl');
         $zendDb = Bootstrap::get('zendDb');
         $privilegesTable = new DirectusPrivilegesTableGateway($acl, $zendDb);
         $privilegesTable->insertPrivilege(['group_id' => $data['id'], 'allow_view' => 1, 'allow_add' => 0, 'allow_edit' => 1, 'allow_delete' => 0, 'allow_alter' => 0, 'table_name' => 'directus_users', 'read_field_blacklist' => 'token', 'write_field_blacklist' => 'group,token']);
     });
     return $emitter;
 }
示例#2
0
 /**
  * Get Hook Emitter
  *
  * @return Emitter
  */
 private static function hookEmitter()
 {
     $emitter = new Emitter();
     $emitter->addAction('application.error', function ($e) {
         $log = Bootstrap::get('log');
         $log->error($e);
     });
     $emitter->addAction('table.insert.directus_groups', function ($data) {
         $acl = Bootstrap::get('acl');
         $zendDb = Bootstrap::get('zendDb');
         $privilegesTable = new DirectusPrivilegesTableGateway($acl, $zendDb);
         $privilegesTable->insertPrivilege(['group_id' => $data['id'], 'allow_view' => 1, 'allow_add' => 0, 'allow_edit' => 1, 'allow_delete' => 0, 'allow_alter' => 0, 'table_name' => 'directus_users', 'read_field_blacklist' => 'token', 'write_field_blacklist' => 'group,token']);
     });
     $emitter->addFilter('table.insert:before', function ($tableName, $data) {
         if ($tableName == 'directus_files') {
             unset($data['data']);
             $data['user'] = AuthProvider::getUserInfo('id');
         }
         return $data;
     });
     // Add file url and thumb url
     $emitter->addFilter('table.select', function ($result, $selectState) {
         if ($selectState['table'] == 'directus_files') {
             $fileRows = $result->toArray();
             $files = new \Directus\Files\Files();
             foreach ($fileRows as &$row) {
                 $config = Bootstrap::get('config');
                 $fileURL = $config['filesystem']['root_url'];
                 $thumbnailURL = $config['filesystem']['root_thumb_url'];
                 $thumbnailFilenameParts = explode('.', $row['name']);
                 $thumbnailExtension = array_pop($thumbnailFilenameParts);
                 $row['url'] = $fileURL . '/' . $row['name'];
                 if (in_array($thumbnailExtension, ['tif', 'tiff', 'psd', 'pdf'])) {
                     $thumbnailExtension = 'jpg';
                 }
                 $thumbnailFilename = $row['id'] . '.' . $thumbnailExtension;
                 $row['thumbnail_url'] = $thumbnailURL . '/' . $thumbnailFilename;
                 // filename-ext-100-100-true.jpg
                 // @TODO: This should be another hook listener
                 $row['thumbnail_url'] = null;
                 $filename = implode('.', $thumbnailFilenameParts);
                 if ($row['type'] == 'embed/vimeo') {
                     $oldThumbnailFilename = $row['name'] . '-vimeo-220-124-true.jpg';
                 } else {
                     $oldThumbnailFilename = $filename . '-' . $thumbnailExtension . '-160-160-true.jpg';
                 }
                 // 314551321-vimeo-220-124-true.jpg
                 // hotfix: there's not thumbnail for this file
                 if ($files->exists('thumbs/' . $oldThumbnailFilename)) {
                     $row['thumbnail_url'] = $thumbnailURL . '/' . $oldThumbnailFilename;
                 }
                 if ($files->exists('thumbs/' . $thumbnailFilename)) {
                     $row['thumbnail_url'] = $thumbnailURL . '/' . $thumbnailFilename;
                 }
                 $embedManager = Bootstrap::get('embedManager');
                 $provider = $embedManager->getByType($row['type']);
                 $row['html'] = null;
                 if ($provider) {
                     $row['html'] = $provider->getCode($row);
                 }
             }
             $filesArrayObject = new \ArrayObject($fileRows);
             $result->initialize($filesArrayObject->getIterator());
         }
         return $result;
     });
     return $emitter;
 }