本文整理汇总了PHP中file_load函数的典型用法代码示例。如果您正苦于以下问题:PHP file_load函数的具体用法?PHP file_load怎么用?PHP file_load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了file_load函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: value
/**
* {@inheritdoc}
*/
public static function value(array &$element, &$input, FormStateInterface $form_state)
{
if (isset($input['filefield_imce']['file_path']) && $input['filefield_imce']['file_path'] != '') {
$instance = entity_load('field_config', $element['#entity_type'] . '.' . $element['#bundle'] . '.' . $element['#field_name']);
$field_settings = $instance->getSettings();
$scheme = $field_settings['uri_scheme'];
$wrapper = \Drupal::service('stream_wrapper_manager')->getViaScheme($scheme);
$file_directory_prefix = $scheme == 'private' ? 'system/files' : $wrapper->getDirectoryPath();
$uri = preg_replace('/^' . preg_quote(base_path() . $file_directory_prefix . '/', '/') . '/', $scheme . '://', $input['filefield_imce']['file_path']);
// Resolve the file path to an FID.
$fid = db_select('file_managed', 'f')->condition('uri', rawurldecode($uri))->fields('f', array('fid'))->execute()->fetchField();
if ($fid) {
$file = file_load($fid);
if (filefield_sources_element_validate($element, $file)) {
if (!in_array($file->id(), $input['fids'])) {
$input['fids'][] = $file->id();
}
}
} else {
$form_state->setError($element, t('The selected file could not be used because the file does not exist in the database.'));
}
// No matter what happens, clear the value from the file path field.
$input['filefield_imce']['file_path'] = '';
}
}
开发者ID:shrimala,项目名称:filefield_sources,代码行数:28,代码来源:Imce.php
示例2: _os_files_deprivatize_file
/**
* Moves a private managed file to the public directory.
*/
function _os_files_deprivatize_file($fid)
{
$file = file_load($fid);
// Builds new public path.
$dest_uri = str_replace('private://', 'public://', $file->uri);
$dest_path = _os_files_deprivatize_get_dest_path($dest_uri);
// Creates the destination folder if it doesn't exist.
if (!is_dir($dest_path)) {
// Creates the folder.
drupal_mkdir($dest_path, NULL, TRUE);
}
$moved_file = @file_move($file, $dest_uri);
if ($moved_file) {
drush_log(dt('File @name moved successfully.', array('@name' => $file->filename)), 'success');
} else {
drush_log(dt('Error moving file @name.', array('@name' => $file->filename)), 'error');
return FALSE;
}
$file->uri = $moved_file->uri;
$file_moved = file_save($file);
if (isset($file_moved->fid)) {
drush_log(dt('[O] File @name updated successfully.', array('@name' => $file->filename)), 'success');
return TRUE;
} else {
drush_log(dt('[!] Error updating file @name.', array('@name' => $file->filename)), 'error');
return FALSE;
}
}
开发者ID:aleph-n,项目名称:opencholar,代码行数:31,代码来源:deprivatize.php
示例3: gevent_service
function gevent_service()
{
global $calendar;
$info = libraries_load('google-api-php-client');
if (!$info['loaded']) {
drupal_set_message(t('Can`t authenticate with google as library is missing check Status report or Readme for requirements, download from') . l('https://github.com/google/google-api-php-client/archive/master.zip', 'https://github.com/google/google-api-php-client/archive/master.zip'), 'error');
return FALSE;
}
$client_email = variable_get('gapps_service_client_email');
$file = file_load(variable_get('gapps_service_private_key'));
$private_key = file_get_contents(drupal_realpath($file->uri));
$user_to_impersonate = variable_get('gevent_admin');
$scopes = array('https://www.googleapis.com/auth/calendar');
$credentials = new Google_Auth_AssertionCredentials($client_email, $scopes, $private_key, 'notasecret', 'http://oauth.net/grant_type/jwt/1.0/bearer', $user_to_impersonate);
$client = new Google_Client();
$client->setApplicationName('Drupal gevent module');
$client->setAssertionCredentials($credentials);
while ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
}
$calendar = new Google_Service_Calendar($client);
$_SESSION['gevent_access_token'] = $client->getAccessToken();
if ($_SESSION['gevent_access_token']) {
return $calendar;
} else {
return NULL;
}
}
开发者ID:fosstp,项目名称:drupal4school,代码行数:28,代码来源:gevent.api.php
示例4: gapps_service
function gapps_service($domain)
{
global $directory;
$info = libraries_load('google-api-php-client');
if (!$info['loaded']) {
drupal_set_message(t('Can`t authenticate with google as library is missing check Status report or Readme for requirements, download from') . l('https://github.com/google/google-api-php-client/archive/master.zip', 'https://github.com/google/google-api-php-client/archive/master.zip'), 'error');
return FALSE;
}
$client_email = variable_get('gapps_service_client_email');
$file = file_load(variable_get('gapps_service_private_key'));
$private_key = file_get_contents(drupal_realpath($file->uri));
if ($domain == 'teacher') {
$user_to_impersonate = variable_get('gapps_teacher_admin');
} else {
$user_to_impersonate = variable_get('gapps_student_admin');
}
$scopes = array('https://www.googleapis.com/auth/admin.directory.orgunit', 'https://www.googleapis.com/auth/admin.directory.group', 'https://www.googleapis.com/auth/admin.directory.group.member', 'https://www.googleapis.com/auth/admin.directory.user', 'https://www.googleapis.com/auth/admin.directory.user.alias');
$credentials = new Google_Auth_AssertionCredentials($client_email, $scopes, $private_key);
$credentials->sub = $user_to_impersonate;
$client = new Google_Client();
$client->setApplicationName('Drupal gapps module');
$client->setAssertionCredentials($credentials);
while ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($credentials);
}
$directory = new Google_Service_Directory($client);
$_SESSION['gapps_' . $domain . '_access_token'] = $client->getAccessToken();
if ($_SESSION['gapps_' . $domain . '_access_token']) {
return $directory;
} else {
return NULL;
}
}
开发者ID:fosstp,项目名称:drupal4school,代码行数:33,代码来源:gapps.api.php
示例5: testUploadPath
/**
* Tests the normal formatter display on node display.
*/
function testUploadPath()
{
$field_name = strtolower($this->randomMachineName());
$type_name = 'article';
$this->createFileField($field_name, 'node', $type_name);
$test_file = $this->getTestFile('text');
// Create a new node.
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
// Check that the file was uploaded to the file root.
$node = node_load($nid, TRUE);
$node_file = file_load($node->{$field_name}->target_id);
$this->assertPathMatch('public://' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri())));
// Change the path to contain multiple subdirectories.
$this->updateFileField($field_name, $type_name, array('file_directory' => 'foo/bar/baz'));
// Upload a new file into the subdirectories.
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
// Check that the file was uploaded into the subdirectory.
$node = node_load($nid, TRUE);
$node_file = file_load($node->{$field_name}->target_id, TRUE);
$this->assertPathMatch('public://foo/bar/baz/' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path.', array('%file' => $node_file->getFileUri())));
// Check the path when used with tokens.
// Change the path to contain multiple token directories.
$this->updateFileField($field_name, $type_name, array('file_directory' => '[current-user:uid]/[current-user:name]'));
// Upload a new file into the token subdirectories.
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
// Check that the file was uploaded into the subdirectory.
$node = node_load($nid, TRUE);
$node_file = file_load($node->{$field_name}->target_id);
// Do token replacement using the same user which uploaded the file, not
// the user running the test case.
$data = array('user' => $this->admin_user);
$subdirectory = \Drupal::token()->replace('[user:uid]/[user:name]', $data);
$this->assertPathMatch('public://' . $subdirectory . '/' . $test_file->getFilename(), $node_file->getFileUri(), format_string('The file %file was uploaded to the correct path with token replacements.', array('%file' => $node_file->getFileUri())));
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:37,代码来源:FileFieldPathTest.php
示例6: _myu_user_dropdown
function _myu_user_dropdown()
{
global $user;
global $language;
$items = array();
if ($user->uid === 0) {
$login_link = l('<span>' . t('Login') . '</span>', '', array('attributes' => array('class' => 'login dropdown-toggle', 'data-toggle' => 'modal'), 'fragment' => 'login', 'external' => TRUE, 'html' => TRUE));
return '<ul class="menu nav navbar-nav user"><li class="dropdown dropdown-user">' . $login_link . '</li></ul>';
} else {
$username = '';
if (!empty($user->picture)) {
$fid = $user->picture;
$file = file_load($fid);
$username = theme('image_style', array('path' => $file->uri, 'style_name' => '29x29', 'attributes' => array('class' => 'img-circle')));
}
$username .= '<span class="username username-hide-on-mobile">' . format_username($GLOBALS['user']) . '</span><i class="fa fa-angle-down"></i>';
$username_link = l($username, 'javascript:;', array('html' => TRUE, 'language' => $language, 'external' => TRUE, 'attributes' => array('class' => 'dropdown-toggle', 'data-close-others' => 'true', 'data-hover' => 'dropdown', 'data-toggle' => 'dropdown')));
$user_menu = menu_tree('user-menu');
foreach ($user_menu as $menu_link) {
if (isset($menu_link['#original_link'])) {
$items[] = l($menu_link['#original_link']['title'], $menu_link['#original_link']['href'], array('language' => $language));
}
}
$user_menu_list = theme('item_list', array('items' => $items, 'type' => 'ul', 'attributes' => array('class' => 'dropdown-menu dropdown-menu-default')));
return '<ul class="menu nav navbar-nav user"><li class="dropdown dropdown-user">' . $username_link . $user_menu_list . '</li></ul>';
}
}
开发者ID:verbruggenalex,项目名称:mediayoutubeupload,代码行数:27,代码来源:page.vars.php
示例7: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
$values = $form_state->getValues();
$entry = array('gid' => $values['gid'], 'title' => $values['title'], 'description' => $values['description'], 'time_zone' => $values['time_zone'], 'parent_gid' => empty($values['parent_gid']) ? NULL : $values['parent_gid']);
// If logo fid is changed, delete old and set new for permanent status.
$logo_fid = isset($values['logo_fid'][0]) ? $values['logo_fid'][0] : NULL;
$old_logo_fid = $values['old_logo_fid'];
if (!empty($logo_fid) && $logo_fid != $old_logo_fid) {
// Set old file for removal.
$file = file_load($old_logo_fid);
if ($file) {
\Drupal::service('file.usage')->delete($file, 'ea_groupings', 'group', $values['gid']);
}
// Add file permanently.
$file = file_load($logo_fid);
if ($file) {
$file->status = FILE_STATUS_PERMANENT;
$file->save();
\Drupal::service('file.usage')->add($file, 'ea_groupings', 'group', $values['gid']);
}
// Add new fid to entry.
$entry['logo_fid'] = $logo_fid;
}
// Save the submitted entry.
$return = EAGroupingsStorage::update($entry);
if ($return) {
drupal_set_message(t('Updated @title', array('@title' => $entry['title'])));
}
}
开发者ID:Roensby,项目名称:effective-activism-old,代码行数:32,代码来源:EAGroupingsEditForm.php
示例8: value
/**
* {@inheritdoc}
*/
public static function value(array &$element, &$input, FormStateInterface $form_state)
{
if (isset($input['filefield_reference']['autocomplete']) && strlen($input['filefield_reference']['autocomplete']) > 0 && $input['filefield_reference']['autocomplete'] != FILEFIELD_SOURCE_REFERENCE_HINT_TEXT) {
$matches = array();
if (preg_match('/\\[fid:(\\d+)\\]/', $input['filefield_reference']['autocomplete'], $matches)) {
$fid = $matches[1];
if ($file = file_load($fid)) {
// Remove file size restrictions, since the file already exists on
// disk.
if (isset($element['#upload_validators']['file_validate_size'])) {
unset($element['#upload_validators']['file_validate_size']);
}
// Check that the user has access to this file through
// hook_download().
if (!$file->access('download')) {
$form_state->setError($element, t('You do not have permission to use the selected file.'));
} elseif (filefield_sources_element_validate($element, (object) $file, $form_state)) {
if (!in_array($file->id(), $input['fids'])) {
$input['fids'][] = $file->id();
}
}
} else {
$form_state->setError($element, t('The referenced file could not be used because the file does not exist in the database.'));
}
}
// No matter what happens, clear the value from the autocomplete.
$input['filefield_reference']['autocomplete'] = '';
}
}
开发者ID:shrimala,项目名称:filefield_sources,代码行数:32,代码来源:Reference.php
示例9: testInUse
/**
* Tries deleting a file that is in use.
*/
function testInUse()
{
$file = $this->createFile();
$file_usage = $this->container->get('file.usage');
$file_usage->add($file, 'testing', 'test', 1);
$file_usage->add($file, 'testing', 'test', 1);
$file_usage->delete($file, 'testing', 'test', 1);
$usage = $file_usage->listUsage($file);
$this->assertEqual($usage['testing']['test'], array(1 => 1), 'Test file is still in use.');
$this->assertTrue(file_exists($file->getFileUri()), 'File still exists on the disk.');
$this->assertTrue(file_load($file->id()), 'File still exists in the database.');
// Clear out the call to hook_file_load().
file_test_reset();
$file_usage->delete($file, 'testing', 'test', 1);
$usage = $file_usage->listUsage($file);
$this->assertFileHooksCalled(array('load', 'update'));
$this->assertTrue(empty($usage), 'File usage data was removed.');
$this->assertTrue(file_exists($file->getFileUri()), 'File still exists on the disk.');
$file = file_load($file->id());
$this->assertTrue($file, 'File still exists in the database.');
$this->assertTrue($file->isTemporary(), 'File is temporary.');
file_test_reset();
// Call file_cron() to clean up the file. Make sure the changed timestamp
// of the file is older than the system.file.temporary_maximum_age
// configuration value.
db_update('file_managed')->fields(array('changed' => REQUEST_TIME - ($this->config('system.file')->get('temporary_maximum_age') + 1)))->condition('fid', $file->id())->execute();
\Drupal::service('cron')->run();
// file_cron() loads
$this->assertFileHooksCalled(array('delete'));
$this->assertFalse(file_exists($file->getFileUri()), 'File has been deleted after its last usage was removed.');
$this->assertFalse(file_load($file->id()), 'File was removed from the database.');
}
开发者ID:RealLukeMartin,项目名称:drupal8tester,代码行数:35,代码来源:DeleteTest.php
示例10: testFileFieldRSSContent
/**
* Tests RSS enclosure formatter display for RSS feeds.
*/
function testFileFieldRSSContent()
{
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$field_name = strtolower($this->randomMachineName());
$type_name = 'article';
$field_settings = array('display_field' => '1', 'display_default' => '1');
$field_settings = array('description_field' => '1');
$widget_settings = array();
$this->createFileField($field_name, 'node', $type_name, $field_settings, $field_settings, $widget_settings);
// RSS display must be added manually.
$this->drupalGet("admin/structure/types/manage/{$type_name}/display");
$edit = array("display_modes_custom[rss]" => '1');
$this->drupalPostForm(NULL, $edit, t('Save'));
// Change the format to 'RSS enclosure'.
$this->drupalGet("admin/structure/types/manage/{$type_name}/display/rss");
$edit = array("fields[{$field_name}][type]" => 'file_rss_enclosure');
$this->drupalPostForm(NULL, $edit, t('Save'));
// Create a new node with a file field set. Promote to frontpage
// needs to be set so this node will appear in the RSS feed.
$node = $this->drupalCreateNode(array('type' => $type_name, 'promote' => 1));
$test_file = $this->getTestFile('text');
// Create a new node with the uploaded file.
$nid = $this->uploadNodeFile($test_file, $field_name, $node->id());
// Get the uploaded file from the node.
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id);
// Check that the RSS enclosure appears in the RSS feed.
$this->drupalGet('rss.xml');
$uploaded_filename = str_replace('public://', '', $node_file->getFileUri());
$test_element = sprintf('<enclosure url="%s" length="%s" type="%s" />', file_create_url("public://{$uploaded_filename}", array('absolute' => TRUE)), $node_file->getSize(), $node_file->getMimeType());
$this->assertRaw($test_element, 'File field RSS enclosure is displayed when viewing the RSS feed.');
}
开发者ID:RealLukeMartin,项目名称:drupal8tester,代码行数:36,代码来源:FileFieldRSSContentTest.php
示例11: testFileSave
function testFileSave()
{
// Create a new file entity.
$file = entity_create('file', array('uid' => 1, 'filename' => 'druplicon.txt', 'uri' => 'public://druplicon.txt', 'filemime' => 'text/plain', 'created' => 1, 'changed' => 1, 'status' => FILE_STATUS_PERMANENT));
file_put_contents($file->getFileUri(), 'hello world');
// Save it, inserting a new record.
$file->save();
// Check that the correct hooks were called.
$this->assertFileHooksCalled(array('insert'));
$this->assertTrue($file->id() > 0, 'A new file ID is set when saving a new file to the database.', 'File');
$loaded_file = file_load($file->id());
$this->assertNotNull($loaded_file, 'Record exists in the database.');
$this->assertEqual($loaded_file->isPermanent(), $file->isPermanent(), 'Status was saved correctly.');
$this->assertEqual($file->getSize(), filesize($file->getFileUri()), 'File size was set correctly.', 'File');
$this->assertTrue($file->getChangedTime() > 1, 'File size was set correctly.', 'File');
$this->assertEqual($loaded_file->langcode->value, 'en', 'Langcode was defaulted correctly.');
// Resave the file, updating the existing record.
file_test_reset();
$file->status->value = 7;
$file->save();
// Check that the correct hooks were called.
$this->assertFileHooksCalled(array('load', 'update'));
$this->assertEqual($file->id(), $file->id(), 'The file ID of an existing file is not changed when updating the database.', 'File');
$this->assertTrue($file->getChangedTime() >= $file->getChangedTime(), "Timestamp didn't go backwards.", 'File');
$loaded_file = file_load($file->id());
$this->assertNotNull($loaded_file, 'Record still exists in the database.', 'File');
$this->assertEqual($loaded_file->isPermanent(), $file->isPermanent(), 'Status was saved correctly.');
$this->assertEqual($loaded_file->langcode->value, 'en', 'Langcode was saved correctly.');
// Try to insert a second file with the same name apart from case insensitivity
// to ensure the 'uri' index allows for filenames with different cases.
$file = entity_create('file', array('uid' => 1, 'filename' => 'DRUPLICON.txt', 'uri' => 'public://DRUPLICON.txt', 'filemime' => 'text/plain', 'created' => 1, 'changed' => 1, 'status' => FILE_STATUS_PERMANENT));
file_put_contents($file->getFileUri(), 'hello world');
$file->save();
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:34,代码来源:SaveTest.php
示例12: testTaxonomyImageAccess
public function testTaxonomyImageAccess()
{
$user = $this->drupalCreateUser(array('administer site configuration', 'administer taxonomy', 'access user profiles'));
$this->drupalLogin($user);
// Create a term and upload the image.
$files = $this->drupalGetTestFiles('image');
$image = array_pop($files);
$edit['name[0][value]'] = $this->randomMachineName();
$edit['files[field_test_0]'] = drupal_realpath($image->uri);
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save'));
$this->drupalPostForm(NULL, ['field_test[0][alt]' => $this->randomMachineName()], t('Save'));
$terms = entity_load_multiple_by_properties('taxonomy_term', array('name' => $edit['name[0][value]']));
$term = reset($terms);
$this->assertText(t('Created new term @name.', array('@name' => $term->getName())));
// Create a user that should have access to the file and one that doesn't.
$access_user = $this->drupalCreateUser(array('access content'));
$no_access_user = $this->drupalCreateUser();
$image = file_load($term->field_test->target_id);
$this->drupalLogin($access_user);
$this->drupalGet(file_create_url($image->getFileUri()));
$this->assertResponse(200, 'Private image on term is accessible with right permission');
$this->drupalLogin($no_access_user);
$this->drupalGet(file_create_url($image->getFileUri()));
$this->assertResponse(403, 'Private image on term not accessible without right permission');
}
开发者ID:nstielau,项目名称:drops-8,代码行数:25,代码来源:TaxonomyImageTest.php
示例13: testFileFieldRSSContent
/**
* Tests RSS enclosure formatter display for RSS feeds.
*/
function testFileFieldRSSContent()
{
$field_name = strtolower($this->randomMachineName());
$type_name = 'article';
$field_settings = array('display_field' => '1', 'display_default' => '1');
$instance_settings = array('description_field' => '1');
$widget_settings = array();
$this->createFileField($field_name, 'node', $type_name, $field_settings, $instance_settings, $widget_settings);
// RSS display must be added manually.
$this->drupalGet("admin/structure/types/manage/{$type_name}/display");
$edit = array("display_modes_custom[rss]" => '1');
$this->drupalPostForm(NULL, $edit, t('Save'));
// Change the format to 'RSS enclosure'.
$this->drupalGet("admin/structure/types/manage/{$type_name}/display/rss");
$edit = array("fields[{$field_name}][type]" => 'file_rss_enclosure');
$this->drupalPostForm(NULL, $edit, t('Save'));
// Create a new node with a file field set. Promote to frontpage
// needs to be set so this node will appear in the RSS feed.
$node = $this->drupalCreateNode(array('type' => $type_name, 'promote' => 1));
$test_file = $this->getTestFile('text');
// Create a new node with the uploaded file.
$nid = $this->uploadNodeFile($test_file, $field_name, $node->id());
// Get the uploaded file from the node.
$node = node_load($nid, TRUE);
$node_file = file_load($node->{$field_name}->target_id);
// Check that the RSS enclosure appears in the RSS feed.
$this->drupalGet('rss.xml');
$uploaded_filename = str_replace('public://', '', $node_file->getFileUri());
$test_element = array('key' => 'enclosure', 'value' => "", 'attributes' => array('url' => url("{$this->public_files_directory}/{$uploaded_filename}", array('absolute' => TRUE)), 'length' => $node_file->getSize(), 'type' => $node_file->getMimeType()));
$this->assertRaw(format_xml_elements(array($test_element)), 'File field RSS enclosure is displayed when viewing the RSS feed.');
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:34,代码来源:FileFieldRSSContentTest.php
示例14: viewEntity
/**
* Overrides \RestfulEntityBase::viewEntity().
*
* Always return the current user.
*/
public function viewEntity($entity_id)
{
$account = $this->getAccount();
$me = parent::viewEntity($account->uid);
$me['picture'] = $account->picture ? file_create_url($account->picture->uri) : file_create_url(file_load(variable_get('default_user_picture_fid'))->uri);
return $me;
}
开发者ID:Gizra,项目名称:negawatt-server,代码行数:12,代码来源:NegawattMeResource.class.php
示例15: testPrivateFile
/**
* Tests file access for file uploaded to a private node.
*/
function testPrivateFile()
{
$type_name = 'article';
$field_name = strtolower($this->randomName());
$this->createFileField($field_name, 'node', $type_name, array('uri_scheme' => 'private'));
// Create a field with no view access. See
// field_test_entity_field_access().
$no_access_field_name = 'field_no_view_access';
$this->createFileField($no_access_field_name, 'node', $type_name, array('uri_scheme' => 'private'));
$test_file = $this->getTestFile('text');
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name, TRUE, array('private' => TRUE));
$node = node_load($nid, TRUE);
$node_file = file_load($node->{$field_name}->target_id);
// Ensure the file can be downloaded.
$this->drupalGet(file_create_url($node_file->getFileUri()));
$this->assertResponse(200, 'Confirmed that the generated URL is correct by downloading the shipped file.');
$this->drupalLogOut();
$this->drupalGet(file_create_url($node_file->getFileUri()));
$this->assertResponse(403, 'Confirmed that access is denied for the file without the needed permission.');
// Test with the field that should deny access through field access.
$this->drupalLogin($this->admin_user);
$nid = $this->uploadNodeFile($test_file, $no_access_field_name, $type_name, TRUE, array('private' => TRUE));
$node = node_load($nid, TRUE);
$node_file = file_load($node->{$no_access_field_name}->target_id);
// Ensure the file cannot be downloaded.
$this->drupalGet(file_create_url($node_file->getFileUri()));
$this->assertResponse(403, 'Confirmed that access is denied for the file without view field access permission.');
}
开发者ID:alnutile,项目名称:drunatra,代码行数:31,代码来源:FilePrivateTest.php
示例16: __construct
function __construct()
{
$this->pl = new pointLocation();
$this->polygonDurham = file_load(__DIR__ . '/polygons/durham', 'serialize');
$this->polygonLondon = file_load(__DIR__ . '/polygons/london', 'serialize');
$this->polygonCanterbury = file_load(__DIR__ . '/polygons/canterbury', 'serialize');
$this->polygonHatfield = file_load(__DIR__ . '/polygons/hatfield', 'serialize');
}
开发者ID:m1ke,项目名称:easy-site-utils,代码行数:8,代码来源:test_functions_map.php
示例17: az_commercial_settings_form_submit
function az_commercial_settings_form_submit(&$form, $form_state)
{
$image_fid = $form_state['values']['main_background'];
$image = file_load($image_fid);
if (is_object($image)) {
if ($image->status == 0) {
$image->status = FILE_STATUS_PERMANENT;
file_save($image);
file_usage_add($image, 'az_gov', 'theme', 1);
}
}
}
开发者ID:ehazell,项目名称:AZDWR,代码行数:12,代码来源:theme-settings.php
示例18: addFile
private static function addFile($imageFileId, $moduleName, $fieldName)
{
/* if our file is already in use, then we don't need to re-do this and increase the count */
$count = db_query('SELECT `count` FROM {file_usage} WHERE fid=:fid', array('fid' => $imageFileId))->fetchField();
$file = file_load($imageFileId);
if (empty($count)) {
$file->status = FILE_STATUS_PERMANENT;
file_save($file);
file_usage_add($file, $moduleName, $fieldName, $imageFileId);
}
return $file;
}
开发者ID:poupouxios,项目名称:drupal-resume,代码行数:12,代码来源:ImageHelper.php
示例19: townsquare_bootstrap_preprocess_page
/**
* Implements theme_preprocess_page().
*/
function townsquare_bootstrap_preprocess_page(&$vars)
{
global $user;
$vars['primary_local_tasks'] = menu_primary_local_tasks();
$vars['secondary_local_tasks'] = menu_secondary_local_tasks();
// The following menu stuff is lame
foreach ($vars['main_menu'] as $item => $options) {
$vars['main_menu'][$item]['html'] = TRUE;
$vars['main_menu'][$item]['attributes']['id'] = 'menu-link-' . drupal_clean_css_identifier($options['href']);
}
$admin_menu = menu_tree_all_data('management');
$children = array_pop($admin_menu);
if ($children) {
foreach ($children['below'] as $key => $value) {
$children['below'][$key]['below'] = array();
}
$vars['admin_menu'] = menu_tree_output($children['below']);
}
// Add user picture if logged in
if ($user->uid) {
$vars['user_name'] = check_plain($user->name);
if (!empty($user->picture)) {
if (is_numeric($user->picture)) {
$user->picture = file_load($user->picture);
}
if (!empty($user->picture->uri)) {
$filepath = $user->picture->uri;
}
} elseif (variable_get('user_picture_default', '')) {
$filepath = variable_get('user_picture_default', '');
}
if (isset($filepath)) {
$alt = t("@user's picture", array('@user' => format_username($user)));
if (module_exists('image') && file_valid_uri($filepath) && ($style = variable_get('user_picture_style', ''))) {
$vars['user_picture'] = theme('image_style', array('style_name' => $style, 'path' => $filepath, 'alt' => $alt, 'title' => $alt));
} else {
$vars['user_picture'] = theme('image', array('path' => $filepath, 'alt' => $alt, 'title' => $alt));
}
} else {
$vars['user_picture'] = '<i class="icon-user"></i>';
}
} else {
unset($vars['secondary_menu']);
$vars['login'] = drupal_get_form('user_login_block');
}
// Add Bootstrap
$path = libraries_get_path('bootstrap');
drupal_add_css($path . '/css/bootstrap.css');
drupal_add_css($path . '/css/bootstrap-responsive.css');
drupal_add_js($path . '/js/bootstrap.js');
$path = libraries_get_path('font-awesome');
drupal_add_css($path . '/css/font-awesome.css');
}
开发者ID:nningego,项目名称:townsquare,代码行数:56,代码来源:template.php
示例20: listOrderPackages
/**
* Displays a list of an order's packaged products.
*
* @param \Drupal\uc_order\OrderInterface $uc_order
* The order.
*
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse
* A render array, or a redirect response if there are no packaged products.
*/
public function listOrderPackages(OrderInterface $uc_order)
{
$shipping_type_options = uc_quote_shipping_type_options();
$header = array($this->t('Package ID'), $this->t('Products'), $this->t('Shipping type'), $this->t('Package type'), $this->t('Shipment ID'), $this->t('Tracking number'), $this->t('Labels'), $this->t('Actions'));
$rows = array();
$result = db_query('SELECT package_id FROM {uc_packages} WHERE order_id = :id', [':id' => $uc_order->id()]);
while ($package_id = $result->fetchField()) {
$package = Package::load($package_id);
$row = array();
// Package ID.
$row[] = array('data' => array('#plain_text' => $package->package_id));
$product_list = array();
$result2 = db_query('SELECT op.order_product_id, pp.qty, op.title, op.model FROM {uc_packaged_products} pp LEFT JOIN {uc_order_products} op ON op.order_product_id = pp.order_product_id WHERE pp.package_id = :id', [':id' => $package->package_id]);
foreach ($result2 as $product) {
$product_list[] = $product->qty . ' x ' . $product->model;
}
// Products.
$row[] = array('data' => array('#theme' => 'item_list', '#items' => $product_list));
// Shipping type.
$row[] = isset($shipping_type_options[$package->shipping_type]) ? $shipping_type_options[$package->shipping_type] : strtr($package->shipping_type, '_', ' ');
// Package type.
$row[] = array('data' => array('#plain_text' => $package->pkg_type));
// Shipment ID.
$row[] = isset($package->sid) ? Link::createFromRoute($package->sid, 'uc_fulfillment.view_shipment', ['uc_order' => $uc_order->id(), 'shipment_id' => $package->sid])->toString() : '';
// Tracking number.
$row[] = isset($package->tracking_number) ? array('data' => array('#plain_text' => $package->tracking_number)) : '';
if ($package->label_image && ($image = file_load($package->label_image))) {
$package->label_image = $image;
} else {
unset($package->label_image);
}
// Shipping label.
if (isset($package->sid) && isset($package->label_image)) {
$method = db_query('SELECT shipping_method FROM {uc_shipments} WHERE sid = :sid', [':sid' => $package->sid])->fetchField();
$row[] = Link::fromTextAndUrl("image goes here", Url::fromUri('base:admin/store/orders/' . $uc_order->id() . '/shipments/labels/' . $method . '/' . $package->label_image->uri, ['uc_order' => $uc_order->id(), 'method' => $method, 'image_uri' => $package->label_image->uri]))->toString();
} else {
$row[] = '';
}
// Operations.
$ops = array('#type' => 'operations', '#links' => array('edit' => array('title' => $this->t('Edit'), 'url' => Url::fromRoute('uc_fulfillment.edit_package', ['uc_order' => $uc_order->id(), 'package_id' => $package->package_id])), 'ship' => array('title' => $this->t('Ship'), 'url' => Url::fromRoute('uc_fulfillment.new_shipment', ['uc_order' => $uc_order->id()], ['query' => ['pkgs' => $package->package_id]])), 'delete' => array('title' => $this->t('Delete'), 'url' => Url::fromRoute('uc_fulfillment.delete_package', ['uc_order' => $uc_order->id(), 'package_id' => $package->package_id]))));
if ($package->sid) {
$ops['#links']['cancel'] = array('title' => $this->t('Cancel'), 'url' => Url::fromRoute('uc_fulfillment.cancel_package', ['uc_order' => $uc_order->id(), 'package_id' => $package->package_id]));
}
$row[] = array('data' => $ops);
$rows[] = $row;
}
if (empty($rows)) {
drupal_set_message($this->t("This order's products have not been organized into packages."), 'warning');
return $this->redirect('uc_fulfillment.new_package', ['uc_order' => $uc_order->id()]);
}
$build['packages'] = array('#theme' => 'table', '#header' => $header, '#rows' => $rows);
return $build;
}
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:62,代码来源:PackageController.php
注:本文中的file_load函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论