Ejemplo n.º 1
1
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;
    }
}
Ejemplo n.º 2
1
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;
    }
}
Ejemplo n.º 3
0
 /**
  * {@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'] = '';
     }
 }
Ejemplo n.º 4
0
/**
 * 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;
    }
}
 /**
  * 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())));
 }
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>';
    }
}
 /**
  * {@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'])));
     }
 }
Ejemplo n.º 8
0
 /**
  * {@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'] = '';
     }
 }
Ejemplo n.º 9
0
 /**
  * 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.');
 }
 /**
  * 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.');
 }
Ejemplo n.º 11
0
 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();
 }
Ejemplo n.º 12
0
 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');
 }
 /**
  * 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.');
 }
 /**
  * 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;
 }
Ejemplo n.º 15
0
 /**
  * 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.');
 }
Ejemplo n.º 16
0
 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');
 }
Ejemplo n.º 17
0
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);
        }
    }
}
Ejemplo n.º 18
0
 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;
 }
Ejemplo n.º 19
0
/**
 * 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');
}
Ejemplo n.º 20
0
 /**
  * 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;
 }
Ejemplo n.º 21
0
 /**
  * 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.');
 }
Ejemplo n.º 22
0
 /**
  * Load a single file and ensure that the correct values are returned.
  */
 function testSingleValues()
 {
     // Create a new file entity from scratch so we know the values.
     $file = $this->createFile('druplicon.txt', NULL, 'public');
     $by_fid_file = file_load($file->id());
     $this->assertFileHookCalled('load');
     $this->assertTrue(is_object($by_fid_file), 'file_load() returned an object.');
     $this->assertEqual($by_fid_file->id(), $file->id(), 'Loading by fid got the same fid.', 'File');
     $this->assertEqual($by_fid_file->getFileUri(), $file->getFileUri(), 'Loading by fid got the correct filepath.', 'File');
     $this->assertEqual($by_fid_file->getFilename(), $file->getFilename(), 'Loading by fid got the correct filename.', 'File');
     $this->assertEqual($by_fid_file->getMimeType(), $file->getMimeType(), 'Loading by fid got the correct MIME type.', 'File');
     $this->assertEqual($by_fid_file->isPermanent(), $file->isPermanent(), 'Loading by fid got the correct status.', 'File');
     $this->assertTrue($by_fid_file->file_test['loaded'], 'file_test_file_load() was able to modify the file during load.');
 }
Ejemplo n.º 23
0
 /**
  * Creates a file, then tests the tokens generated from it.
  */
 function testFileTokenReplacement()
 {
     $node_storage = $this->container->get('entity.manager')->getStorage('node');
     $token_service = \Drupal::token();
     $language_interface = \Drupal::languageManager()->getCurrentLanguage();
     // Create file field.
     $type_name = 'article';
     $field_name = 'field_' . strtolower($this->randomMachineName());
     $this->createFileField($field_name, 'node', $type_name);
     $test_file = $this->getTestFile('text');
     // Coping a file to test uploads with non-latin filenames.
     $filename = drupal_dirname($test_file->getFileUri()) . '/текстовый файл.txt';
     $test_file = file_copy($test_file, $filename);
     // Create a new node with the uploaded file.
     $nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
     // Load the node and the file.
     $node_storage->resetCache(array($nid));
     $node = $node_storage->load($nid);
     $file = file_load($node->{$field_name}->target_id);
     // Generate and test sanitized tokens.
     $tests = array();
     $tests['[file:fid]'] = $file->id();
     $tests['[file:name]'] = String::checkPlain($file->getFilename());
     $tests['[file:path]'] = String::checkPlain($file->getFileUri());
     $tests['[file:mime]'] = String::checkPlain($file->getMimeType());
     $tests['[file:size]'] = format_size($file->getSize());
     $tests['[file:url]'] = String::checkPlain(file_create_url($file->getFileUri()));
     $tests['[file:created]'] = format_date($file->getCreatedTime(), 'medium', '', NULL, $language_interface->getId());
     $tests['[file:created:short]'] = format_date($file->getCreatedTime(), 'short', '', NULL, $language_interface->getId());
     $tests['[file:changed]'] = format_date($file->getChangedTime(), 'medium', '', NULL, $language_interface->getId());
     $tests['[file:changed:short]'] = format_date($file->getChangedTime(), 'short', '', NULL, $language_interface->getId());
     $tests['[file:owner]'] = String::checkPlain(user_format_name($this->adminUser));
     $tests['[file:owner:uid]'] = $file->getOwnerId();
     // Test to make sure that we generated something for each token.
     $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
     foreach ($tests as $input => $expected) {
         $output = $token_service->replace($input, array('file' => $file), array('langcode' => $language_interface->getId()));
         $this->assertEqual($output, $expected, format_string('Sanitized file token %token replaced.', array('%token' => $input)));
     }
     // Generate and test unsanitized tokens.
     $tests['[file:name]'] = $file->getFilename();
     $tests['[file:path]'] = $file->getFileUri();
     $tests['[file:mime]'] = $file->getMimeType();
     $tests['[file:size]'] = format_size($file->getSize());
     foreach ($tests as $input => $expected) {
         $output = $token_service->replace($input, array('file' => $file), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE));
         $this->assertEqual($output, $expected, format_string('Unsanitized file token %token replaced.', array('%token' => $input)));
     }
 }
 protected function setUp()
 {
     parent::setUp();
     $this->fieldName = 'field_image';
     // Create the image field.
     $this->createImageField($this->fieldName, 'article');
     // Set the RDF mapping for the new field.
     rdf_get_mapping('node', 'article')->setFieldMapping($this->fieldName, array('properties' => array('og:image'), 'mapping_type' => 'rel'))->setBundleMapping(array('types' => array()))->save();
     // Get the test image that simpletest provides.
     $image = current($this->drupalGetTestFiles('image'));
     // Save a node with the image.
     $nid = $this->uploadNodeImage($image, $this->fieldName, 'article', $this->randomMachineName());
     $this->node = Node::load($nid);
     $this->file = file_load($this->node->{$this->fieldName}->target_id);
 }
Ejemplo n.º 25
0
 /**
  * Prepares the parameters to publish to Facebook, this means settings any
  * field or destination dependent configuration.
  */
 protected function publishParameterPrepare(&$publication)
 {
     parent::publishParameterPrepare($publication);
     // Add facebook support for uploading files
     $this->setFileUploadSupport(true);
     // Add @ in front of upload URL
     if (!empty($publication['params']['source'])) {
         $image = $publication['params']['source'];
         $uri = empty($image['uri']) ? file_load($image['fid'])->uri : $image['uri'];
         $publication['params']['source'] = '@' . drupal_realpath($uri);
         if (empty($publication['params']['name']) && !empty($image['title'])) {
             $publication['params']['name'] = check_plain($image['title']);
         }
     }
 }
Ejemplo n.º 26
0
function faces_form_system_theme_settings_alter(&$form, $form_state)
{
    $form['tag_desc'] = array('#type' => 'textarea', '#title' => t('Home Page Body Text'), '#default_value' => theme_get_setting('tag_desc'), '#description' => t("Text for the content in home page"));
    $form['banner_image'] = array('#title' => t('New Launch Banner Image'), '#type' => 'managed_file', '#description' => t('Upload New Launch Banner Image'), '#default_value' => variable_get('banner_image'), '#upload_location' => 'public://');
    $form['banner-image-link-text'] = array('#type' => 'textfield', '#title' => t('New Launch Banner Link text'), '#default_value' => theme_get_setting('banner-image-link-text'), '#description' => t("Text for New Launch Banner Link"));
    $form['banner-image-link-url'] = array('#type' => 'textfield', '#title' => t('New Launch Banner Link URL'), '#default_value' => theme_get_setting('banner-image-link-url'), '#description' => t("URL for New Launch Banner Link "));
    $form['banner-image-link-desc'] = array('#type' => 'textfield', '#title' => t('New Launch Banner Link Description'), '#default_value' => theme_get_setting('banner-image-link-desc'), '#description' => t("URL for New Launch Banner Link Description"));
    $form['footer_logo'] = array('#title' => t('Footer Logo'), '#type' => 'managed_file', '#description' => t('Upload Footer logo here'), '#default_value' => variable_get('footer_logo'), '#upload_location' => 'public://');
    $form['social_links'] = array('#type' => 'fieldset', '#title' => t('Social Icon Links'), '#description' => t("Enter Facebook URL"), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['social_links']['facebook_url'] = array('#type' => 'textfield', '#title' => t('Facebook URL'), '#default_value' => theme_get_setting('facebook_url'), '#description' => t("Enter Facebook URL"));
    $form['social_links']['twitter_url'] = array('#type' => 'textfield', '#title' => t('Twitter URL'), '#default_value' => theme_get_setting('twitter_url'), '#description' => t("Enter Facebook URL"));
    $form['social_links']['instagram_url'] = array('#type' => 'textfield', '#title' => t('Instagram URL'), '#default_value' => theme_get_setting('instagram_url'), '#description' => t("Enter Instagram URL"));
    $form['social_links']['pintrest_url'] = array('#type' => 'textfield', '#title' => t('Pintrest URL'), '#default_value' => theme_get_setting('pintrest_url'), '#description' => t("Enter Pintrest URL"));
    $form['social_links']['googleplus_url'] = array('#type' => 'textfield', '#title' => t('GPLUS Url'), '#default_value' => theme_get_setting('googleplus_url'), '#description' => t("Enter GPLUS URL"));
    $file = file_load($form_state['values']['footer_logo']);
}
Ejemplo n.º 27
0
/**
 * Submit handler for system_theme_settings().
 */
function sizzle_form_system_theme_settings_submit($form, &$form_state)
{
    $values = $form_state['values'];
    // Save images.
    foreach ($values as $name => $value) {
        if (preg_match('/_image$/', $name)) {
            if (!empty($values[$name])) {
                $file = file_load($values[$name]);
                $file->status = FILE_STATUS_PERMANENT;
                file_save($file);
                file_usage_add($file, 'sizzle', 'theme', 1);
                variable_set($name, $file->fid);
            }
        }
    }
}
Ejemplo n.º 28
0
function puzzle_settings_form_submit(&$form, &$form_state)
{
    $image_fid = $form_state['values']['background_image'];
    $image = file_load($image_fid);
    if (is_object($image)) {
        // Check to make sure that the file is set to be permanent.
        if ($image->status == 0) {
            // Update the status.
            $image->status = FILE_STATUS_PERMANENT;
            // Save the update.
            file_save($image);
            // Add a reference to prevent warnings.
            file_usage_add($image, 'puzzle', 'theme', 1);
        }
    }
}
Ejemplo n.º 29
0
 function testFileSave()
 {
     // Create a new file entity.
     $file = File::create(array('uid' => 1, 'filename' => 'druplicon.txt', 'uri' => 'public://druplicon.txt', 'filemime' => 'text/plain', '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.
     $uppercase_values = array('uid' => 1, 'filename' => 'DRUPLICON.txt', 'uri' => 'public://DRUPLICON.txt', 'filemime' => 'text/plain', 'status' => FILE_STATUS_PERMANENT);
     $uppercase_file = File::create($uppercase_values);
     file_put_contents($uppercase_file->getFileUri(), 'hello world');
     $violations = $uppercase_file->validate();
     $this->assertEqual(count($violations), 0, 'No violations when adding an URI with an existing filename in upper case.');
     $uppercase_file->save();
     // Ensure the database URI uniqueness constraint is triggered.
     $uppercase_file_duplicate = File::create($uppercase_values);
     file_put_contents($uppercase_file_duplicate->getFileUri(), 'hello world');
     $violations = $uppercase_file_duplicate->validate();
     $this->assertEqual(count($violations), 1);
     $this->assertEqual($violations[0]->getMessage(), t('The file %value already exists. Enter a unique file URI.', ['%value' => $uppercase_file_duplicate->getFileUri()]));
     // Ensure that file URI entity queries are case sensitive.
     $fids = \Drupal::entityQuery('file')->condition('uri', $uppercase_file->getFileUri())->execute();
     $this->assertEqual(1, count($fids));
     $this->assertEqual(array($uppercase_file->id() => $uppercase_file->id()), $fids);
 }
Ejemplo n.º 30
0
/**
 * Helper function; Return the markup of the profile image by the next logic:
 * When there is no profile picture the node display the uploaded image.
 * When there is no uploaded image display the default image.
 *
 * @param string $size
 *  Determine the size of the profile picture. Optional values: small or big.
 *
 * @return string
 *  The markup of the image.
 */
function hwpi_basetheme_profile_default_image($size = 'small')
{
    if (variable_get('os_profiles_disable_default_image', FALSE)) {
        return '<div class="no-default-image"></div>';
    }
    if ($custom_default_image = variable_get('os_profiles_default_image_file', 0)) {
        // Use custom default image.
        $image_file = file_load($custom_default_image);
        $path = $image_file->uri;
        $options = array('path' => $path, 'style_name' => 'profile_thumbnail');
        return '<div class="field-name-field-person-photo">' . theme('image_style', $options) . '</div>';
    }
    // Use default image.
    $image = $size == 'small' ? 'person-default-image.png' : 'person-default-image-big.png';
    $path = variable_get('os_person_default_image', drupal_get_path('theme', 'hwpi_basetheme') . '/images/' . $image);
    return '<div class="field-name-field-person-photo">' . theme('image', array('path' => $path)) . '</div>';
}