本文整理汇总了PHP中drupal_realpath函数的典型用法代码示例。如果您正苦于以下问题:PHP drupal_realpath函数的具体用法?PHP drupal_realpath怎么用?PHP drupal_realpath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了drupal_realpath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSlideTest
/**
* Add a new slide and ensure that it was created successfully.
*/
function testSlideTest()
{
// Check to ensure that the slider is not displayed.
$this->drupalGet('<front>');
$this->assertNoRaw('//div[@id="slider"]', 'There is no slider on the front page.');
// Load the slider slides administration page.
$this->drupalGet('admin/structure/nivo-slider');
$this->assertResponse(200, t('The privileged user can access the slider slides administration page.'));
$file = $this->getTestImage();
// Create five new slide.
for ($i = 0; $i <= 5; $i++) {
$edit = array();
$edit['files[upload]'] = drupal_realpath($file->uri);
$this->drupalPost('admin/structure/nivo-slider', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
}
// Check to ensure that the slider is displayed.
$this->drupalGet('<front>');
$elements = $this->xpath('//div[@id="slider"]');
$this->assertEqual(count($elements), 1, t('There is exactly one slider on the front page.'));
// Delete the five existing slides.
for ($i = 5; $i <= 0; $i--) {
$edit = array();
$edit["images[{$i}][delete]"] = TRUE;
$this->drupalPost('admin/structure/nivo-slider', $edit, t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
}
}
示例2: testCommentPreview
/**
* Tests comment preview.
*/
function testCommentPreview()
{
// As admin user, configure comment settings.
$this->drupalLogin($this->adminUser);
$this->setCommentPreview(DRUPAL_OPTIONAL);
$this->setCommentForm(TRUE);
$this->setCommentSubject(TRUE);
$this->setCommentSettings('default_mode', CommentManagerInterface::COMMENT_MODE_THREADED, 'Comment paging changed.');
$this->drupalLogout();
// Login as web user and add a user picture.
$this->drupalLogin($this->webUser);
$image = current($this->drupalGetTestFiles('image'));
$edit['files[user_picture_0]'] = drupal_realpath($image->uri);
$this->drupalPostForm('user/' . $this->webUser->id() . '/edit', $edit, t('Save'));
// As the web user, fill in the comment form and preview the comment.
$edit = array();
$edit['subject[0][value]'] = $this->randomMachineName(8);
$edit['comment_body[0][value]'] = $this->randomMachineName(16);
$this->drupalPostForm('node/' . $this->node->id(), $edit, t('Preview'));
// Check that the preview is displaying the title and body.
$this->assertTitle(t('Preview comment | Drupal'), 'Page title is "Preview comment".');
$this->assertText($edit['subject[0][value]'], 'Subject displayed.');
$this->assertText($edit['comment_body[0][value]'], 'Comment displayed.');
// Check that the title and body fields are displayed with the correct values.
$this->assertFieldByName('subject[0][value]', $edit['subject[0][value]'], 'Subject field displayed.');
$this->assertFieldByName('comment_body[0][value]', $edit['comment_body[0][value]'], 'Comment field displayed.');
// Check that the user picture is displayed.
$this->assertFieldByXPath("//article[contains(@class, 'preview')]//div[contains(@class, 'user-picture')]//img", NULL, 'User picture displayed.');
}
示例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;
}
}
示例4: testFileCheckLocalDirectoryHandling
/**
* Test local directory handling functions.
*/
function testFileCheckLocalDirectoryHandling()
{
$site_path = $this->container->get('site.path');
$directory = $site_path . '/files';
// Check a new recursively created local directory for correct file system
// permissions.
$parent = $this->randomMachineName();
$child = $this->randomMachineName();
// Files directory already exists.
$this->assertTrue(is_dir($directory), t('Files directory already exists.'), 'File');
// Make files directory writable only.
$old_mode = fileperms($directory);
// Create the directories.
$parent_path = $directory . DIRECTORY_SEPARATOR . $parent;
$child_path = $parent_path . DIRECTORY_SEPARATOR . $child;
$this->assertTrue(drupal_mkdir($child_path, 0775, TRUE), t('No error reported when creating new local directories.'), 'File');
// Ensure new directories also exist.
$this->assertTrue(is_dir($parent_path), t('New parent directory actually exists.'), 'File');
$this->assertTrue(is_dir($child_path), t('New child directory actually exists.'), 'File');
// Check that new directory permissions were set properly.
$this->assertDirectoryPermissions($parent_path, 0775);
$this->assertDirectoryPermissions($child_path, 0775);
// Check that existing directory permissions were not modified.
$this->assertDirectoryPermissions($directory, $old_mode);
// Check creating a directory using an absolute path.
$absolute_path = drupal_realpath($directory) . DIRECTORY_SEPARATOR . $this->randomMachineName() . DIRECTORY_SEPARATOR . $this->randomMachineName();
$this->assertTrue(drupal_mkdir($absolute_path, 0775, TRUE), 'No error reported when creating new absolute directories.', 'File');
$this->assertDirectoryPermissions($absolute_path, 0775);
}
示例5: 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');
}
示例6: testUserTokens
function testUserTokens()
{
// Add a user picture to the account.
$image = current($this->drupalGetTestFiles('image'));
$edit = array('files[user_picture_0]' => drupal_realpath($image->uri));
$this->drupalPostForm('user/' . $this->account->id() . '/edit', $edit, t('Save'));
$storage = \Drupal::entityManager()->getStorage('user');
// Load actual user data from database.
$storage->resetCache();
$this->account = $storage->load($this->account->id());
$this->assertTrue(!empty($this->account->user_picture->target_id), 'User picture uploaded.');
$picture = ['#theme' => 'user_picture', '#account' => $this->account];
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$user_tokens = array('picture' => $renderer->render($picture), 'picture:fid' => $this->account->user_picture->target_id, 'picture:size-raw' => 125, 'ip-address' => NULL, 'roles' => implode(', ', $this->account->getRoles()));
$this->assertTokens('user', array('user' => $this->account), $user_tokens);
// Remove the simpletest-created user role.
$roles = $this->account->getRoles();
$this->account->removeRole(end($roles));
$this->account->save();
// Remove the user picture field and reload the user.
FieldStorageConfig::loadByName('user', 'user_picture')->delete();
$storage->resetCache();
$this->account = $storage->load($this->account->id());
$user_tokens = array('picture' => NULL, 'picture:fid' => NULL, 'ip-address' => NULL, 'roles' => 'authenticated', 'roles:keys' => (string) DRUPAL_AUTHENTICATED_RID);
$this->assertTokens('user', array('user' => $this->account), $user_tokens);
// The ip address token should work for the current user token type.
$tokens = array('ip-address' => \Drupal::request()->getClientIp());
$this->assertTokens('current-user', array(), $tokens);
$anonymous = new AnonymousUserSession();
$tokens = array('roles' => 'anonymous', 'roles:keys' => (string) DRUPAL_ANONYMOUS_RID);
$this->assertTokens('user', array('user' => $anonymous), $tokens);
}
示例7: generateImage
/**
* Private function for creating a random image.
*
* This function only works with the GD toolkit. ImageMagick is not supported.
*/
protected function generateImage($extension = 'png', $min_resolution, $max_resolution)
{
if ($tmp_file = drupal_tempnam('temporary://', 'imagefield_')) {
$destination = $tmp_file . '.' . $extension;
file_unmanaged_move($tmp_file, $destination, FILE_CREATE_DIRECTORY);
$min = explode('x', $min_resolution);
$max = explode('x', $max_resolution);
$width = rand((int) $min[0], (int) $max[0]);
$height = rand((int) $min[1], (int) $max[1]);
// Make an image split into 4 sections with random colors.
$im = imagecreate($width, $height);
for ($n = 0; $n < 4; $n++) {
$color = imagecolorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
$x = $width / 2 * ($n % 2);
$y = $height / 2 * (int) ($n >= 2);
imagefilledrectangle($im, $x, $y, $x + $width / 2, $y + $height / 2, $color);
}
// Make a perfect circle in the image middle.
$color = imagecolorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255));
$smaller_dimension = min($width, $height);
$smaller_dimension = $smaller_dimension % 2 ? $smaller_dimension : $smaller_dimension;
imageellipse($im, $width / 2, $height / 2, $smaller_dimension, $smaller_dimension, $color);
$save_function = 'image' . ($extension == 'jpg' ? 'jpeg' : $extension);
$save_function($im, drupal_realpath($destination));
return $destination;
}
}
示例8: 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;
}
}
示例9: createNodeWithFile
/**
* Helper to create a node and upload a file to it.
*/
protected function createNodeWithFile($file_type = 'image', $multivalue = TRUE, $add_title_caption = TRUE)
{
$file = current($this->drupalGetTestFiles($file_type));
$edit = array('title[0][value]' => 'Test Juicebox Gallery Node', 'files[' . $this->instFieldName . '_0]' . ($multivalue ? '[]' : '') => drupal_realpath($file->uri));
$this->drupalPostForm('node/add/' . $this->instBundle, $edit, t('Save and publish'));
// Get ID of the newly created node from the current URL.
$matches = array();
preg_match('/node\\/([0-9]+)/', $this->getUrl(), $matches);
if (isset($matches[1])) {
$nid = $matches[1];
// Now re-edit the node to add title and caption values for the newly
// uploaded image. This could probably also be done above with
// DrupalWebTestCase::drupalPostAJAX(), but this works too.
$edit = array('body[0][value]' => 'Some body content on node ' . $nid . ' <strong>with formatting</strong>');
if ($add_title_caption) {
if ($this->instFieldType == 'image') {
$edit[$this->instFieldName . '[0][title]'] = 'Some title text for field ' . $this->instFieldName . ' on node ' . $nid;
$edit[$this->instFieldName . '[0][alt]'] = 'Some alt text for field ' . $this->instFieldName . ' on node ' . $nid . ' <strong>with formatting</strong>';
}
if ($this->instFieldType == 'file') {
$edit[$this->instFieldName . '[0][description]'] = 'Some description text for field ' . $this->instFieldName . ' on node ' . $nid . ' <strong>with formatting</strong>';
}
}
$this->drupalPostForm('node/' . $nid . '/edit', $edit, t('Save and keep published'));
// Clear some caches for good measure and save the node object for
// reference during tests.
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$node_storage->resetCache(array($nid));
$this->node = $node_storage->load($nid);
return TRUE;
}
return FALSE;
}
示例10: urlToFileEntity
protected function urlToFileEntity($url)
{
$url = urldecode(DRUPAL_ROOT . EntityPathHelper::normalizeUrl($url));
if (file_exists($url)) {
// Get the filename.
$filename = pathinfo($url, PATHINFO_FILENAME) . '.' . pathinfo($url, PATHINFO_EXTENSION);
$filesize = filesize($url);
$files = db_select('file_managed', 'f')->fields('f', array('fid', 'uri', 'filesize'))->condition('filename', $filename)->condition('filesize', $filesize)->execute();
$found_fid = -1;
while ($row = $files->fetch()) {
$result_uri = drupal_realpath($row->uri);
if ($result_uri == drupal_realpath($url)) {
$found_fid = $row->fid;
break;
}
}
if ($found_fid !== -1) {
return Entity::load($found_fid, 'file');
} else {
// Create the file entity.
if ($contents = file_get_contents($url)) {
$public_files_directory = DRUPAL_ROOT . '/' . variable_get('file_public_path', conf_path() . '/files') . '/';
$schema_url = 'public://' . str_replace($public_files_directory, '', $url);
// This will basically re-create the same file with the same filename, so we don't
// need to check to see if the file already exists because we don't care to replace
// the file with itself.
$file = file_save_data($contents, $schema_url, FILE_EXISTS_REPLACE);
return Entity::load($file->fid, 'file');
}
}
}
return false;
}
示例11: HOOK_builder_content_export_alter
/** This is for Export content, we may alter $content, and $zip file before user download it
* Hook_builder_content_export($zip , $content)
*/
function HOOK_builder_content_export_alter(&$zip, &$content)
{
if ($content['module'] == 'builder' && $content['delta'] == 'image') {
if (!empty($content['settings']['image'])) {
$file = file_load($content['settings']['image']);
$filename = $file->filename;
$zip->addFile(drupal_realpath($file->uri), $filename);
}
}
}
示例12: testImport
/**
* Tests importing configuration.
*/
function testImport()
{
// Verify access to the config upload form.
$this->drupalGet('admin/config/development/configuration/full/import');
$this->assertResponse(200);
// Attempt to upload a non-tar file.
$text_file = current($this->drupalGetTestFiles('text'));
$edit = array('files[import_tarball]' => drupal_realpath($text_file->uri));
$this->drupalPostForm('admin/config/development/configuration/full/import', $edit, t('Upload'));
$this->assertText(t('Could not extract the contents of the tar file'));
}
示例13: testFileUpload
/**
* Tests that the autocomplete input element does not cause ajax fatal.
*/
public function testFileUpload()
{
$user1 = $this->drupalCreateUser(array('access content', "create {$this->referencingType} content"));
$this->drupalLogin($user1);
$test_file = current($this->drupalGetTestFiles('text'));
$edit['files[file_field_0]'] = drupal_realpath($test_file->uri);
$this->drupalPostForm('node/add/' . $this->referencingType, $edit, 'Upload');
$this->assertResponse(200);
$edit = array('title[0][value]' => $this->randomMachineName(), 'test_field[0][target_id]' => $this->nodeId);
$this->drupalPostForm(NULL, $edit, 'Save');
$this->assertResponse(200);
}
示例14: manual_import_archive
/**
* Manually imports an archive XML file.
*
* @param array &$form The brafton config form.
* @param object $form_state The current state of the brafton config form.
*
* @return void
*/
static function manual_import_archive(array &$form, FormStateInterface $form_state)
{
$file_value = $form_state->getValue('brafton_archive_file');
$file_id = $file_value[0];
$file = file_load($file_id);
$file_uri = $file->getFileUri();
$file_url = drupal_realpath($file_uri);
// $article_loader = new \Drupal\brafton_importer\Model\BraftonArticleLoader();
// $article_loader->import_articles($file_url);
$controller = new \Drupal\brafton_importer\Controller\BraftonImporterController();
$controller->import_articles($file_url);
}
示例15: testNodeDisplay
/**
* Tests normal formatter display on node display.
*/
function testNodeDisplay()
{
$field_name = strtolower($this->randomMachineName());
$type_name = 'article';
$field_storage_settings = array('display_field' => '1', 'display_default' => '1', 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
$field_settings = array('description_field' => '1');
$widget_settings = array();
$this->createFileField($field_name, 'node', $type_name, $field_storage_settings, $field_settings, $widget_settings);
// Create a new node *without* the file field set, and check that the field
// is not shown for each node display.
$node = $this->drupalCreateNode(array('type' => $type_name));
// Check file_default last as the assertions below assume that this is the
// case.
$file_formatters = array('file_table', 'file_url_plain', 'hidden', 'file_default');
foreach ($file_formatters as $formatter) {
$edit = array("fields[{$field_name}][type]" => $formatter);
$this->drupalPostForm("admin/structure/types/manage/{$type_name}/display", $edit, t('Save'));
$this->drupalGet('node/' . $node->id());
$this->assertNoText($field_name, format_string('Field label is hidden when no file attached for formatter %formatter', array('%formatter' => $formatter)));
}
$test_file = $this->getTestFile('text');
// Create a new node with the uploaded file.
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
// Check that the default formatter is displaying with the file name.
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$node_storage->resetCache(array($nid));
$node = $node_storage->load($nid);
$node_file = file_load($node->{$field_name}->target_id);
$file_link = array('#theme' => 'file_link', '#file' => $node_file);
$default_output = drupal_render($file_link);
$this->assertRaw($default_output, 'Default formatter displaying correctly on full node view.');
// Turn the "display" option off and check that the file is no longer displayed.
$edit = array($field_name . '[0][display]' => FALSE);
$this->drupalPostForm('node/' . $nid . '/edit', $edit, t('Save and keep published'));
$this->assertNoRaw($default_output, 'Field is hidden when "display" option is unchecked.');
// Add a description and make sure that it is displayed.
$description = $this->randomMachineName();
$edit = array($field_name . '[0][description]' => $description, $field_name . '[0][display]' => TRUE);
$this->drupalPostForm('node/' . $nid . '/edit', $edit, t('Save and keep published'));
$this->assertText($description);
// Test that fields appear as expected after during the preview.
// Add a second file.
$name = 'files[' . $field_name . '_1][]';
$edit[$name] = drupal_realpath($test_file->getFileUri());
// Uncheck the display checkboxes and go to the preview.
$edit[$field_name . '[0][display]'] = FALSE;
$edit[$field_name . '[1][display]'] = FALSE;
$this->drupalPostForm("node/{$nid}/edit", $edit, t('Preview'));
$this->clickLink(t('Back to content editing'));
$this->assertRaw($field_name . '[0][display]', 'First file appears as expected.');
$this->assertRaw($field_name . '[1][display]', 'Second file appears as expected.');
}