コード例 #1
0
function open_framework_form_system_theme_settings_alter(&$form, &$form_state)
{
    // Responsive Behavior
    $form['responsive_container'] = array('#type' => 'fieldset', '#title' => t('Responsive'), '#description' => t('Use these settings to adjust the responsive behavior.'), '#collapsible' => TRUE, '#collapsed' => FALSE);
    $form['responsive_container']['content_order_classes'] = array('#type' => 'radios', '#title' => t('Content order in mobile'), '#default_value' => theme_get_setting('content_order_classes'), '#options' => array('' => t('Show first sidebar content before main content - <strong><em>Default</em></strong>'), 'content-first ' => t('Show main content before sidebar content')));
    // Page Layout
    $form['layout_container'] = array('#type' => 'fieldset', '#title' => t('Layout'), '#description' => t('Use these settings to adjust the page layout.'), '#collapsible' => TRUE, '#collapsed' => FALSE);
    $form['layout_container']['front_heading_classes'] = array('#type' => 'radios', '#title' => t('Page heading'), '#default_value' => theme_get_setting('front_heading_classes'), '#options' => array('' => t('Hide heading on front page - <strong><em>Default</em></strong>'), 'show-title ' => t('Show heading on front page')));
    $form['layout_container']['breadcrumb_classes'] = array('#type' => 'radios', '#title' => t('Breadcrumbs'), '#default_value' => theme_get_setting('breadcrumb_classes'), '#options' => array('' => t('Hide breadcrumbs - <strong><em>Default</em></strong>'), 'show-breadcrumb ' => t('Show breadcrumbs')));
    // Background Section
    $form['background_container'] = array('#type' => 'fieldset', '#title' => t('Background Images'), '#description' => t('Use these settings to select different background images.'), '#collapsible' => TRUE, '#collapsed' => FALSE);
    // Body Background Image
    $form['background_container']['body_bg_type'] = array('#type' => 'radios', '#title' => t('Body background image type'), '#default_value' => theme_get_setting('body_bg_type'), '#options' => array('' => t('Wallpaper pattern - <strong><em>Default</em></strong>'), 'photobg ' => t('Photo image')));
    $form['background_container']['body_bg_classes'] = array('#type' => 'radios', '#title' => t('Body background image'), '#default_value' => theme_get_setting('body_bg_classes'), '#options' => array('' => t('None - <strong><em>Default</em></strong>'), 'bodybg ' => t('Use my image (upload below):')));
    // Default path for image
    $body_bg_path = theme_get_setting('body_bg_path');
    if (file_uri_scheme($body_bg_path) == 'public') {
        $body_bg_path = file_uri_target($body_bg_path);
    }
    // Helpful text showing the file name, disabled to avoid the user thinking it can be used for any purpose.
    $form['background_container']['body_bg_path'] = array('#type' => 'hidden', '#title' => 'Path to background image', '#default_value' => $body_bg_path);
    if (!empty($body_bg_path)) {
        $form['background_container']['body_bg_preview'] = array('#markup' => !empty($body_bg_path) ? theme('image', array('path' => theme_get_setting('body_bg_path'))) : '');
    }
    // Upload field
    $form['background_container']['body_bg_upload'] = array('#type' => 'file', '#title' => 'Upload background image', '#description' => 'You can upload the following image file types: *.jpg, *.gif, or *.png');
    // Border Style
    $form['border_container'] = array('#type' => 'fieldset', '#title' => t('Borders'), '#description' => t('Use these settings to change the border style.'), '#collapsible' => TRUE, '#collapsed' => FALSE);
    $form['border_container']['border_classes'] = array('#type' => 'radios', '#title' => t('Border style for content section'), '#default_value' => theme_get_setting('border_classes'), '#options' => array('' => t('No borders - <strong><em>Default</em></strong>'), 'borders' => t('Show borders')));
    $form['border_container']['corner_classes'] = array('#type' => 'radios', '#title' => t('Corner style'), '#default_value' => theme_get_setting('corner_classes'), '#options' => array('' => t('Straight corners - <strong><em>Default</em></strong>'), 'roundedcorners' => t('Rounded corners (not supported in Internet Explorer 8 or below)')));
    // Attach custom submit handler to the form
    $form['#submit'][] = 'open_framework_settings_submit';
    $form['#validate'][] = 'open_framework_settings_validate';
}
コード例 #2
0
/**
 * Implements theme_settings().
 */
function nuboot_radix_form_system_theme_settings_alter(&$form, &$form_state)
{
    // Ensure this include file is loaded when the form is rebuilt from the cache.
    $form_state['build_info']['files']['form'] = drupal_get_path('theme', 'default') . '/theme-settings.php';
    // Add theme settings here.
    $form['nuboot_radix_theme_settings'] = array('#title' => t('Theme Settings'), '#type' => 'fieldset');
    // Copyright.
    $copyright = theme_get_setting('copyright');
    $form['nuboot_radix_theme_settings']['copyright'] = array('#title' => t('Copyright'), '#type' => 'text_format', '#format' => 'html', '#default_value' => isset($copyright['value']) ? $copyright['value'] : t('Powered by <a href="http://nucivic.com/dkan">DKAN</a>, a project of <a href="http://nucivic.com">NuCivic</a>'));
    // Hero fieldset.
    $form['hero'] = array('#type' => 'fieldset', '#title' => t('Hero Unit'), '#group' => 'general');
    // Default path for image.
    $hero_path = theme_get_setting('hero_path');
    if (file_uri_scheme($hero_path) == 'public') {
        $hero_path = file_uri_target($hero_path);
    }
    // Helpful text showing the file name, non-editable.
    $form['hero']['hero_path'] = array('#type' => 'textfield', '#title' => 'Path to front page background image', '#default_value' => $hero_path, '#disabled' => TRUE);
    // Upload field.
    $form['hero']['hero_upload'] = array('#type' => 'file', '#title' => 'Upload a new photo for the hero unit', '#description' => t('<p>The hero unit is the large featured area located on the front page. 
      This theme supplies a default background image for this area. You may upload a different 
      photo here and it will replace the default background image.</p><p>Max. file size: 2 MB
      <br>Recommended pixel size: 1920 x 400<br>Allowed extensions: .png .jpg .jpeg</p>'), '#upload_validators' => array('file_validate_extensions' => array('png jpg jpeg')));
    // Attach custom submit handler to the form.
    $form['#submit'][] = 'nuboot_radix_settings_submit';
    // Return the additional form widgets.
    return $form;
}
コード例 #3
0
ファイル: file.api.php プロジェクト: aWEBoLabs/taxi
/**
 * Alter the URL to a file.
 *
 * This hook is called from file_create_url(), and  is called fairly
 * frequently (10+ times per page), depending on how many files there are in a
 * given page.
 * If CSS and JS aggregation are disabled, this can become very frequently
 * (50+ times per page) so performance is critical.
 *
 * This function should alter the URI, if it wants to rewrite the file URL.
 *
 * @param $uri
 *   The URI to a file for which we need an external URL, or the path to a
 *   shipped file.
 */
function hook_file_url_alter(&$uri)
{
    $user = \Drupal::currentUser();
    // User 1 will always see the local file in this example.
    if ($user->id() == 1) {
        return;
    }
    $cdn1 = 'http://cdn1.example.com';
    $cdn2 = 'http://cdn2.example.com';
    $cdn_extensions = array('css', 'js', 'gif', 'jpg', 'jpeg', 'png');
    // Most CDNs don't support private file transfers without a lot of hassle,
    // so don't support this in the common case.
    $schemes = array('public');
    $scheme = file_uri_scheme($uri);
    // Only serve shipped files and public created files from the CDN.
    if (!$scheme || in_array($scheme, $schemes)) {
        // Shipped files.
        if (!$scheme) {
            $path = $uri;
        } else {
            $wrapper = \Drupal::service('stream_wrapper_manager')->getViaScheme($scheme);
            $path = $wrapper->getDirectoryPath() . '/' . file_uri_target($uri);
        }
        // Clean up Windows paths.
        $path = str_replace('\\', '/', $path);
        // Serve files with one of the CDN extensions from CDN 1, all others from
        // CDN 2.
        $pathinfo = pathinfo($path);
        if (isset($pathinfo['extension']) && in_array($pathinfo['extension'], $cdn_extensions)) {
            $uri = $cdn1 . '/' . $path;
        } else {
            $uri = $cdn2 . '/' . $path;
        }
    }
}
コード例 #4
0
ファイル: ThemeTest.php プロジェクト: nstielau/drops-8
 /**
  * Test the theme settings form.
  */
 function testThemeSettings()
 {
     // Ensure invalid theme settings form URLs return a proper 404.
     $this->drupalGet('admin/appearance/settings/bartik');
     $this->assertResponse(404, 'The theme settings form URL for a uninstalled theme could not be found.');
     $this->drupalGet('admin/appearance/settings/' . $this->randomMachineName());
     $this->assertResponse(404, 'The theme settings form URL for a non-existent theme could not be found.');
     // Specify a filesystem path to be used for the logo.
     $file = current($this->drupalGetTestFiles('image'));
     $file_relative = strtr($file->uri, array('public:/' => PublicStream::basePath()));
     $default_theme_path = 'core/themes/classy';
     $supported_paths = array($file->uri => array('form' => file_uri_target($file->uri), 'src' => file_create_url($file->uri)), file_uri_target($file->uri) => array('form' => file_uri_target($file->uri), 'src' => file_create_url($file->uri)), $file_relative => array('form' => $file_relative, 'src' => file_create_url($file->uri)), 'core/misc/druplicon.png' => array('form' => 'core/misc/druplicon.png', 'src' => $GLOBALS['base_url'] . '/' . 'core/misc/druplicon.png'), $default_theme_path . '/logo.svg' => array('form' => $default_theme_path . '/logo.svg', 'src' => $GLOBALS['base_url'] . '/' . $default_theme_path . '/logo.svg'));
     foreach ($supported_paths as $input => $expected) {
         $edit = array('default_logo' => FALSE, 'logo_path' => $input);
         $this->drupalPostForm('admin/appearance/settings', $edit, t('Save configuration'));
         $this->assertNoText('The custom logo path is invalid.');
         $this->assertFieldByName('logo_path', $expected['form']);
         // Verify logo path examples.
         $elements = $this->xpath('//div[contains(@class, :item)]/div[@class=:description]/code', array(':item' => 'form-item-logo-path', ':description' => 'description'));
         // Expected default values (if all else fails).
         $implicit_public_file = 'logo.svg';
         $explicit_file = 'public://logo.svg';
         $local_file = $default_theme_path . '/logo.svg';
         // Adjust for fully qualified stream wrapper URI in public filesystem.
         if (file_uri_scheme($input) == 'public') {
             $implicit_public_file = file_uri_target($input);
             $explicit_file = $input;
             $local_file = strtr($input, array('public:/' => PublicStream::basePath()));
         } elseif (file_uri_scheme($input) !== FALSE) {
             $explicit_file = $input;
         } elseif ($input == file_uri_target($file->uri)) {
             $implicit_public_file = $input;
             $explicit_file = 'public://' . $input;
             $local_file = PublicStream::basePath() . '/' . $input;
         }
         $this->assertEqual((string) $elements[0], $implicit_public_file);
         $this->assertEqual((string) $elements[1], $explicit_file);
         $this->assertEqual((string) $elements[2], $local_file);
         // Verify the actual 'src' attribute of the logo being output.
         $this->drupalGet('');
         $elements = $this->xpath('//header/a[@rel=:rel]/img', array(':rel' => 'home'));
         $this->assertEqual((string) $elements[0]['src'], $expected['src']);
     }
     $unsupported_paths = array('public://whatever.png', 'private://whatever.png', 'temporary://whatever.png', 'public:/whatever.png', '://whatever.png', ':whatever.png', 'public://', 'whatever.png', PublicStream::basePath() . '/whatever.png', '/' . PublicStream::basePath() . '/whatever.png', 'core/misc/whatever.png', '/core/misc/whatever.png', drupal_realpath($file->uri));
     $this->drupalGet('admin/appearance/settings');
     foreach ($unsupported_paths as $path) {
         $edit = array('default_logo' => FALSE, 'logo_path' => $path);
         $this->drupalPostForm(NULL, $edit, t('Save configuration'));
         $this->assertText('The custom logo path is invalid.');
     }
     // Upload a file to use for the logo.
     $edit = array('default_logo' => FALSE, 'logo_path' => '', 'files[logo_upload]' => drupal_realpath($file->uri));
     $this->drupalPostForm('admin/appearance/settings', $edit, t('Save configuration'));
     $fields = $this->xpath($this->constructFieldXpath('name', 'logo_path'));
     $uploaded_filename = 'public://' . $fields[0]['value'];
     $this->drupalGet('');
     $elements = $this->xpath('//header/a[@rel=:rel]/img', array(':rel' => 'home'));
     $this->assertEqual($elements[0]['src'], file_create_url($uploaded_filename));
 }
コード例 #5
0
ファイル: file.class.php プロジェクト: chhavi/playbox
 /**
  * Overrides LinkitSearchPluginEntity::createGroup().
  */
 function createGroup($entity)
 {
     // The the standard group name.
     $group = parent::createGroup($entity);
     // Add the scheme.
     if ($this->conf['group_by_scheme']) {
         // Get all stream wrappers.
         $stream_wrapper = file_get_stream_wrappers();
         $group .= ' - ' . $stream_wrapper[file_uri_scheme($entity->uri)]['name'];
     }
     return $group;
 }
コード例 #6
0
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $element = [];
     $settings = $this->getSettings();
     foreach ($items as $delta => $item) {
         $file = File::load($item->target_id);
         $metadata = isset($item->data) ? unserialize($item->data) : array();
         $scheme = file_uri_scheme($file->getFileUri());
         $provider = $this->providerManager->loadProviderFromStream($scheme, $file, $metadata);
         $element[$delta] = $provider->renderEmbedCode($settings);
     }
     return $element;
 }
コード例 #7
0
 /**
  * Test the file_unmanaged_save_data() function.
  */
 function testFileSaveData()
 {
     $contents = $this->randomMachineName(8);
     $this->settingsSet('file_chmod_file', 0777);
     // No filename.
     $filepath = file_unmanaged_save_data($contents);
     $this->assertTrue($filepath, 'Unnamed file saved correctly.');
     $this->assertEqual(file_uri_scheme($filepath), file_default_scheme(), "File was placed in Drupal's files directory.");
     $this->assertEqual($contents, file_get_contents($filepath), 'Contents of the file are correct.');
     // Provide a filename.
     $filepath = file_unmanaged_save_data($contents, 'public://asdf.txt', FILE_EXISTS_REPLACE);
     $this->assertTrue($filepath, 'Unnamed file saved correctly.');
     $this->assertEqual('asdf.txt', drupal_basename($filepath), 'File was named correctly.');
     $this->assertEqual($contents, file_get_contents($filepath), 'Contents of the file are correct.');
     $this->assertFilePermissions($filepath, 0777);
 }
コード例 #8
0
ファイル: theme-settings.php プロジェクト: EWB/grh
function academy_form_system_theme_settings_alter(&$form, &$form_state)
{
    // Container fieldset
    $form['bg_image'] = array('#type' => 'fieldset', '#title' => t('Background image (must be tileable PNG)'));
    // Default path for image
    $bg_path = theme_get_setting('bg_path');
    if (file_uri_scheme($bg_path) == 'public') {
        $bg_path = file_uri_target($bg_path);
    }
    // Helpful text showing the file name, disabled to avoid the user thinking it can be used for any purpose.
    $form['bg_image']['bg_path'] = array('#type' => 'textfield', '#title' => 'Path to background image', '#default_value' => $bg_path, '#disabled' => TRUE);
    // Upload field
    $form['bg_image']['bg_upload'] = array('#type' => 'file', '#title' => 'Upload background image', '#description' => 'Upload a new image for the background.');
    // Attach custom submit handler to the form
    $form['#submit'][] = 'academy_settings_submit';
}
コード例 #9
0
/**
 * Implements hook_form_system_theme_settings_alter().
 */
function nuboot_form_system_theme_settings_alter(&$form, &$form_state)
{
    // Hero fieldset.
    $form['hero'] = array('#type' => 'fieldset', '#title' => t('Hero Unit'), '#group' => 'general');
    // Default path for image.
    $hero_path = theme_get_setting('hero_path');
    if (file_uri_scheme($hero_path) == 'public') {
        $hero_path = file_uri_target($hero_path);
    }
    // Helpful text showing the file name, non-editable.
    $form['hero']['hero_path'] = array('#type' => 'textfield', '#title' => 'Path to front page hero unit background image', '#default_value' => $hero_path, '#disabled' => TRUE);
    // Upload field.
    $form['hero']['hero_upload'] = array('#type' => 'file', '#title' => 'Upload a photo for the hero unit background image', '#description' => 'Upload a new image for the hero region background.', '#upload_validators' => array('file_validate_extensions' => array('png jpg jpeg')));
    // Attach custom submit handler to the form.
    $form['#submit'][] = 'nuboot_settings_submit';
}
コード例 #10
0
ファイル: theme-settings.php プロジェクト: ehazell/AZDWR
function agency_1_form_system_theme_settings_alter(&$form, &$form_state)
{
    //Add the css to fix the color module's goofy form
    drupal_add_css(drupal_get_path('theme', 'agency_1') . '/css/colors-admin.css');
    //Fix color module rendering of new colors added to .inc file
    agency_1_theme_settings_add_new_colors();
    /*
     * Sliver show/hide
     */
    $show_sliver = isset($theme_settings['show_sliver']) ? $theme_settings['show_sliver'] : NULL;
    //Add the checkbox to the form
    $form['sliver'] = array('#type' => 'fieldset', '#title' => t('Sliver banner settings'), '#description' => t('If toggled on, the sliver banner will be displayed.'), '#attributes' => array('class' => array('theme-settings-bottom')));
    $form['sliver']['show_sliver'] = array('#type' => 'checkbox', '#title' => t('Display the sliver banner'), '#default_value' => theme_get_setting('show_sliver'), '#tree' => FALSE, '#description' => t('Check here if you want the theme to display the sliver banner.'));
    /*
     * Background Image
     */
    $background_path = isset($theme_settings['background_path']) ? $theme_settings['background_path'] : NULL;
    // If $background_path is a public:// URI, display the path relative to the files directory. (Stream wrappers are not end-user friendly)
    if (file_uri_scheme($background_path) == 'public') {
        $background_path = file_uri_target($background_path);
    }
    //Add the background image fields to the form
    $form['background_image'] = array('#type' => 'fieldset', '#title' => t('Background image settings'), '#description' => t('If toggled on, the following background will be displayed.'), '#attributes' => array('class' => array('theme-settings-bottom')));
    $form['background_image']['default_background'] = array('#type' => 'checkbox', '#title' => t('Use the default background'), '#default_value' => theme_get_setting('default_background'), '#tree' => FALSE, '#description' => t('Check here if you want the theme to use the background supplied with it.'));
    $form['background_image']['settings'] = array('#type' => 'container', '#states' => array('invisible' => array('input[name="default_background"]' => array('checked' => TRUE))));
    $form['background_image']['settings']['background_path'] = array('#type' => 'textfield', '#title' => t('Path to custom background'), '#description' => t('The path to the file you would like to use as your background file instead of the default background.'), '#default_value' => theme_get_setting('background_path'));
    $form['background_image']['settings']['background_file'] = array('#type' => 'file', '#title' => t('Upload background image'), '#maxlength' => 40, '#description' => t("If you don't have direct file access to the server, use this field to upload your background image."), '#element_validate' => array('_agency_1_theme_settings_validate'));
    //Toggle display of the branding block in the footer
    $form['footer_branding'] = array('#type' => 'fieldset', '#title' => t('Footer Branding settings'), '#description' => t('If toggled on, the branding block will be displayed.'), '#attributes' => array('class' => array('theme-settings-bottom')));
    $form['footer_branding']['display_footer_branding'] = array('#type' => 'checkbox', '#title' => t('Display the branding block in the footer'), '#default_value' => theme_get_setting('display_footer_branding'), '#tree' => FALSE, '#description' => t('Check here if you want to display the branding  block in the footer.'));
    //Capture the information for the Contact Us section in the footer
    $form['footer_contact_us'] = array('#type' => 'fieldset', '#title' => t('Footer "Contact Us" settings'), '#description' => t('If toggled on, the Contact Us block will be displayed.'), '#attributes' => array('class' => array('theme-settings-bottom')));
    $form['footer_contact_us']['display_footer_contact'] = array('#type' => 'checkbox', '#title' => t('Display the Contact Us block in the footer'), '#default_value' => theme_get_setting('display_footer_contact'), '#tree' => FALSE, '#description' => t('Check here if you want to display the Contact Us block in the footer.'));
    $form['footer_contact_us']['settings'] = array('#type' => 'container', '#states' => array('invisible' => array('input[name="display_footer_contact"]' => array('checked' => FALSE))));
    $form['footer_contact_us']['settings']['footer_contact_us_title'] = array('#type' => 'textfield', '#title' => t('Title'), '#description' => t('Title for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_title'));
    $form['footer_contact_us']['settings']['footer_contact_us_title_link'] = array('#type' => 'textfield', '#title' => t('Title Link'), '#description' => t('Link for the title in the Contact Us block. (Recommend linking to the contact form.)'), '#default_value' => theme_get_setting('footer_contact_us_title_link'));
    $form['footer_contact_us']['settings']['footer_contact_us_agency_title'] = array('#type' => 'textfield', '#title' => t('Agency Title'), '#description' => t('Agency title for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_agency_title'));
    $form['footer_contact_us']['settings']['footer_contact_us_address_1'] = array('#type' => 'textfield', '#title' => t('Address Line 1'), '#description' => t('Address line 1 for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_address_1'));
    $form['footer_contact_us']['settings']['footer_contact_us_address_2'] = array('#type' => 'textfield', '#title' => t('Address Line 2'), '#description' => t('Address line 2 for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_address_2'));
    $form['footer_contact_us']['settings']['footer_contact_us_phone'] = array('#type' => 'textfield', '#title' => t('Phone Number'), '#description' => t('Phone number for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_phone'));
    $form['footer_contact_us']['settings']['footer_contact_us_fax'] = array('#type' => 'textfield', '#title' => t('Fax Number'), '#description' => t('Fax number for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_fax'));
    $form['footer_contact_us']['settings']['footer_contact_us_map_link'] = array('#type' => 'textfield', '#title' => t('Map Link'), '#description' => t('Link for the map in the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_map_link'));
    $form['footer_contact_us']['settings']['footer_contact_us_map_path'] = array('#type' => 'textfield', '#title' => t('Path to map image'), '#description' => t('The path to the file you would like to use as your map image. (150px x 150px)'), '#default_value' => theme_get_setting('footer_contact_us_map_path'));
    $form['footer_contact_us']['settings']['footer_contact_us_map_image'] = array('#type' => 'file', '#title' => t('Upload map image'), '#maxlength' => 40, '#description' => t("Use this field to upload your map image. (150px x 150px.  Will be resized if necessary.)"), '#element_validate' => array('_agency_1_theme_settings_map'));
    //End Contact Us
    return $form;
}
コード例 #11
0
/**
 * Implementation of hook_form_system_theme_settings_alter() 
 */
function locke_form_system_theme_settings_alter(&$form, &$form_state)
{
    // Ensure this include file is loaded when the form is rebuilt from the cache.
    $form_state['build_info']['files']['form'] = drupal_get_path('theme', 'locke') . '/theme-settings.php';
    // Add theme settings here.
    $form['locke_theme_settings'] = array('#title' => t('Theme Settings'), '#type' => 'fieldset');
    // Copyright.
    $copyright = theme_get_setting('copyright');
    $form['locke_theme_settings']['copyright'] = array('#title' => t('Copyright'), '#type' => 'text_format', '#format' => $copyright['format'], '#default_value' => $copyright['value'] ? $copyright['value'] : t('Drupal is a registered trademark of Dries Buytaert.'));
    // Update the "Toogle Display" to something clearer
    $form['theme_settings']['#title'] = t('Theme Display Settings');
    // Change Weighting of Default Setting Fields
    $form['theme_settings']['#weight'] = 20;
    $form['logo']['#weight'] = 30;
    $form['favicon']['#weight'] = 40;
    // Define the contact information fieldset
    $form['contact_information'] = array('#type' => 'fieldset', '#title' => t('Contact Information in Footer'));
    // Define the phone number
    $form['contact_information']['phone'] = array('#type' => 'textfield', '#title' => t('Phone Number'), '#default_value' => theme_get_setting('phone'));
    // Define your fax number
    $form['contact_information']['fax'] = array('#type' => 'textfield', '#title' => t('Fax Number'), '#default_value' => theme_get_setting('fax'));
    // Define your address
    $form['contact_information']['address'] = array('#type' => 'textarea', '#title' => t('Address'), '#rows' => 3, '#default_value' => theme_get_setting('address'));
    // Define the social media links
    $form['social_media'] = array('#type' => 'fieldset', '#title' => t('Social Media Links in Footer'));
    // Define the twitter link
    $form['social_media']['twitter_link'] = array('#type' => 'textfield', '#title' => 'Twitter', '#default_value' => theme_get_setting('twitter_link'));
    // Define the facebook link
    $form['social_media']['facebook_link'] = array('#type' => 'textfield', '#title' => 'Facebook', '#default_value' => theme_get_setting('facebook_link'));
    // Define the youtube link
    $form['social_media']['youtube_link'] = array('#type' => 'textfield', '#title' => 'YouTube', '#default_value' => theme_get_setting('youtube_link'));
    // Update the image settings to include seal
    $form['logo']['#title'] = 'Image settings';
    $default_seal = theme_get_setting('default_seal');
    $form['logo']['default_seal'] = array('#type' => 'checkbox', '#title' => t('Use the default seal'), '#tree' => FALSE, '#description' => t('Check here if you want the theme to use the seal supplied with it'), '#default_value' => empty($default_seal) ? 0 : 1);
    $seal_path = theme_get_setting('seal_path');
    // If $seal_path is a public:// URI, display the path relative to the files
    // directory; stream wrappers are not end-user friendly.
    if (file_uri_scheme($seal_path) == 'public') {
        $seal_path = file_uri_target($seal_path);
    }
    $form['logo']['seal_settings'] = array('#type' => 'container', '#states' => array('invisible' => array('input[name="default_seal"]' => array('checked' => TRUE))), 'seal_path' => array('#type' => 'textfield', '#title' => 'Path to custom seal', '#description' => 'The path to the file you would like to use as your seal file instead of the default seal.', '#default_value' => $seal_path), 'seal_upload' => array('#type' => 'file', '#title' => 'Upload logo image', '#maxlength' => 40, '#description' => 'If you don\'t have direct file access to the server, use this field to upload your seal.'));
    $form['#submit'][] = 'locke_theme_settings_submit';
    $form['#validate'][] = 'locke_theme_settings_validate';
}
コード例 #12
0
ファイル: SaveDataTest.php プロジェクト: 318io/318-io
 /**
  * Test file_save_data() when replacing an existing file.
  */
 function testExistingReplace()
 {
     // Setup a file to overwrite.
     $existing = $this->createFile();
     $contents = $this->randomMachineName(8);
     $result = file_save_data($contents, $existing->getFileUri(), FILE_EXISTS_REPLACE);
     $this->assertTrue($result, 'File saved successfully.');
     $this->assertEqual('public', file_uri_scheme($result->getFileUri()), "File was placed in Drupal's files directory.");
     $this->assertEqual($result->getFilename(), $existing->getFilename(), 'Filename was set to the basename of the existing file, rather than preserving the original name.');
     $this->assertEqual($contents, file_get_contents($result->getFileUri()), 'Contents of the file are correct.');
     $this->assertEqual($result->getMimeType(), 'application/octet-stream', 'A MIME type was set.');
     $this->assertTrue($result->isPermanent(), "The file's status was set to permanent.");
     // Check that the correct hooks were called.
     $this->assertFileHooksCalled(array('load', 'update'));
     // Verify that the existing file was re-used.
     $this->assertSameFile($existing, $result);
     // Verify that what was returned is what's in the database.
     $this->assertFileUnchanged($result, File::load($result->id()));
 }
コード例 #13
0
ファイル: GDToolkitWebP.php プロジェクト: andrewl/andrewlnet
 /**
  * {@inheritdoc}
  */
 public function save($destination)
 {
     $scheme = file_uri_scheme($destination);
     // Work around lack of stream wrapper support in imagejpeg() and imagepng().
     if ($scheme && file_stream_wrapper_valid_scheme($scheme)) {
         // If destination is not local, save image to temporary local file.
         $local_wrappers = file_get_stream_wrappers(STREAM_WRAPPERS_LOCAL);
         if (!isset($local_wrappers[$scheme])) {
             $permanent_destination = $destination;
             $destination = drupal_tempnam('temporary://', 'gd_');
         }
         // Convert stream wrapper URI to normal path.
         $destination = drupal_realpath($destination);
     }
     switch ($this->getType()) {
         case GDToolkitWebP::IMAGETYPE_WEBP:
             $function = 'imagewebp';
             break;
         default:
             $function = 'image' . image_type_to_extension($this->getType(), FALSE);
             break;
     }
     if (!function_exists($function)) {
         return FALSE;
     }
     if ($this->getType() == IMAGETYPE_JPEG) {
         $success = $function($this->getResource(), $destination, $this->configFactory->get('system.image.gd')->get('jpeg_quality'));
     } else {
         // Always save PNG images with full transparency.
         if ($this->getType() == IMAGETYPE_PNG) {
             imagealphablending($this->getResource(), FALSE);
             imagesavealpha($this->getResource(), TRUE);
         }
         $success = $function($this->getResource(), $destination);
     }
     // Move temporary local file to remote destination.
     if (isset($permanent_destination) && $success) {
         return (bool) file_unmanaged_move($destination, $permanent_destination, FILE_EXISTS_REPLACE);
     }
     return $success;
 }
コード例 #14
0
function SFT_preprocess_html(&$vars)
{
    // theme option variables
    $vars['content_order_classes'] = !empty($vars['content_order_classes']) ? $vars['content_order_classes'] : theme_get_setting('content_order_classes');
    $vars['front_heading_classes'] = !empty($vars['front_heading_classes']) ? $vars['front_heading_classes'] : theme_get_setting('front_heading_classes');
    $vars['breadcrumb_classes'] = !empty($vars['breadcrumb_classes']) ? $vars['breadcrumb_classes'] : theme_get_setting('breadcrumb_classes');
    $vars['border_classes'] = !empty($vars['border_classes']) ? $vars['border_classes'] : theme_get_setting('border_classes');
    $vars['corner_classes'] = !empty($vars['corner_classes']) ? $vars['corner_classes'] : theme_get_setting('corner_classes');
    $vars['body_bg_type'] = !empty($vars['body_bg_type']) ? $vars['body_bg_type'] : theme_get_setting('body_bg_type');
    $vars['body_bg_classes'] = !empty($vars['body_bg_classes']) ? $vars['body_bg_classes'] : theme_get_setting('body_bg_classes');
    $vars['body_bg_path'] = !empty($vars['body_bg_path']) ? $vars['body_bg_path'] : theme_get_setting('body_bg_path');
    $vars['font_awesome_version'] = !empty($vars['font_awesome_version']) ? $vars['font_awesome_version'] : theme_get_setting('font_awesome_version');
    // Variables
    $content_order_classes = $vars['content_order_classes'];
    $front_heading_classes = $vars['front_heading_classes'];
    $breadcrumb_classes = $vars['breadcrumb_classes'];
    $border_classes = $vars['border_classes'];
    $corner_classes = $vars['corner_classes'];
    $body_bg_type = $vars['body_bg_type'];
    $body_bg_classes = $vars['body_bg_classes'];
    $body_bg_path = $vars['body_bg_path'];
    // Default path for body background image
    if (file_uri_scheme($body_bg_path) == 'public') {
        $body_bg_path = file_create_url($body_bg_path);
    }
    // If body background image is enabled, add following style to body
    if (!empty($body_bg_classes)) {
        drupal_add_css('body {background: url(' . $body_bg_path . ') repeat top left;}', array('group' => CSS_THEME, 'type' => 'inline', 'media' => 'screen', 'preprocess' => FALSE, 'weight' => '9999'));
    }
    // Add body class based on style selected
    $vars['classes_array'][] = $vars['body_bg_type'];
    $vars['classes_array'][] = $vars['body_bg_classes'];
    $vars['classes_array'][] = $vars['content_order_classes'];
    $vars['classes_array'][] = $vars['front_heading_classes'];
    $vars['classes_array'][] = $vars['breadcrumb_classes'];
    $vars['classes_array'][] = $vars['border_classes'];
    $vars['classes_array'][] = $vars['corner_classes'];
}
コード例 #15
0
 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     // load widget settings
     $field_definition = $this->fieldDefinition;
     $entity_form_display = entity_get_form_display($field_definition->getTargetEntityTypeId(), $field_definition->getTargetBundle(), 'default');
     $widget = $entity_form_display->getRenderer($field_definition->getName());
     $widget_settings = $widget->getSettings();
     $element = [];
     foreach ($items as $delta => $item) {
         $file = File::load($item->target_id);
         $metadata = isset($item->data) ? unserialize($item->data) : array();
         $scheme = file_uri_scheme($file->getFileUri());
         $provider = $this->providerManager->loadProviderFromStream($scheme, $file, $metadata, $widget_settings);
         $url = FALSE;
         if ($this->getSetting('link_image_to') == static::LINK_CONTENT) {
             $url = $items->getEntity()->urlInfo();
         } elseif ($this->getSetting('link_image_to') == static::LINK_PROVIDER) {
             $url = Url::fromUri(file_create_url($file->getFileUri()));
         }
         $element[$delta] = $provider->renderThumbnail($this->getSetting('image_style'), $url);
     }
     return $element;
 }
コード例 #16
0
function hosting_form_system_theme_settings_alter(&$form, &$form_state)
{
    $contact_icon = theme_get_setting('contact_icon');
    if (file_uri_scheme($contact_icon) == 'public') {
        $contact_icon = file_uri_target($contact_icon);
    }
    drupal_add_css(drupal_get_path('theme', 'hosting') . '/css/theme-settings.css');
    // Contact
    $form['contact'] = array('#type' => 'fieldset', '#title' => 'Contact Setting', '#group' => 'drupaloss_settings', '#weight' => 100);
    // Contact MAP
    /*
    $form['contact']['contactmap'] = array(
        '#type' => 'fieldset',
        '#title' => '<div class="plus"></div><h3 class="options_heading">Contact Map</h3>',
    );
    */
    // Contact MAP Address
    $contact_address = theme_get_setting('contact_address');
    $form['contact']['contact_address'] = array('#type' => 'text_format', '#title' => t('Company Address'), '#default_value' => isset($contact_address['value']) ? $contact_address['value'] : '', '#format' => isset($contact_address['format']) ? $contact_address['format'] : 'filtered_html');
    // Contact MAP Phone
    $form['contact']['contact_phone'] = array('#type' => 'textfield', '#title' => t('Company Telephone'), '#default_value' => theme_get_setting('contact_phone'));
    // Company Name
    $form['contact']['contact_mail'] = array('#type' => 'textfield', '#title' => t('Company Email'), '#default_value' => theme_get_setting('contact_mail'));
    // Website
    $form['contact']['contact_website'] = array('#type' => 'textfield', '#title' => 'Website', '#default_value' => theme_get_setting('contact_website'));
    // Contact MAP Lat
    $form['contact']['contactmap_lat'] = array('#type' => 'textfield', '#title' => 'Lat', '#description' => t('Lat google map'), '#default_value' => theme_get_setting('contactmap_lat'));
    // Contact MAP Long
    $form['contact']['contactmap_long'] = array('#type' => 'textfield', '#title' => 'Long', '#description' => t('Long google map'), '#default_value' => theme_get_setting('contactmap_long'));
    $form['contact']['contact_icon'] = array('#type' => 'textfield', '#title' => 'Path to Contact Icon', '#default_value' => $contact_icon, '#disabled' => TRUE);
    $form['contact']['contact_icon_upload'] = array('#type' => 'file', '#title' => 'Upload maker icon', '#description' => 'Google map maker icon.');
    $form['contact']['style_map_google'] = array('#type' => 'textarea', '#title' => 'Style map google', '#description' => 'Copy code map google "Javascript style array" in web ' . l('Style google', 'http://snazzymaps.com/', array('attributes' => array('target' => '_blank'))), '#rows' => 20, '#default_value' => theme_get_setting('style_map_google'));
    $text_map = theme_get_setting('text_map_tip');
    $form['contact']['text_map_tip'] = array('#type' => 'text_format', '#title' => t('Text Map'), '#default_value' => isset($text_map['value']) ? $text_map['value'] : '', '#description' => t('This text show tip on map'), '#format' => isset($text_map['format']) ? $text_map['format'] : 'filtered_html');
    // Submit Button
    $form['#submit'][] = 'hosting_themes_settings_submit';
}
コード例 #17
0
ファイル: SettingsForm.php プロジェクト: eloiv/botafoc.cat
  /**
   * {@inheritdoc}
   */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    $values = $form_state->getValues();
    $scheme = file_uri_scheme($values['temp_location']);
    if (!$scheme) {
      $form_state->setErrorByName('temp_location', t('Invalid file location. You must include a file stream wrapper (e.g., public://).'));

      return FALSE;
    }

    $file_system = \Drupal::service('file_system');
    if (!$file_system->validScheme($scheme)) {
      $form_state->setErrorByName('temp_location', t('Invalid file stream wrapper.'));

      return FALSE;
    }

    if ((!is_dir($values['temp_location']) || !is_writable($values['temp_location'])) && !file_prepare_directory($values['temp_location'], FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
      $form_state->setErrorByName('temp_location', t('File location can not be created or is not writable.'));

      return FALSE;
    }

    return TRUE;
  }
コード例 #18
0
 /**
  * Provides a wrapper for file_uri_scheme() to allow unit testing.
  *
  * Returns the scheme of a URI (e.g. a stream).
  *
  * @param string $uri
  *   A stream, referenced as "scheme://target"  or "data:target".
  *
  * @see file_uri_target()
  *
  * @todo: Remove when https://www.drupal.org/node/2050759 is in.
  *
  * @return string
  *   A string containing the name of the scheme, or FALSE if none. For
  *   example, the URI "public://example.txt" would return "public".
  */
 protected function fileUriScheme($uri)
 {
     return file_uri_scheme($uri);
 }
コード例 #19
0
 /**
  * Test the scheme functions.
  */
 function testGetValidStreamScheme()
 {
     $this->assertEqual('foo', file_uri_scheme('foo://pork//chops'), 'Got the correct scheme from foo://asdf');
     $this->assertTrue(file_stream_wrapper_valid_scheme(file_uri_scheme('public://asdf')), 'Got a valid stream scheme from public://asdf');
     $this->assertFalse(file_stream_wrapper_valid_scheme(file_uri_scheme('foo://asdf')), 'Did not get a valid stream scheme from foo://asdf');
 }
コード例 #20
0
 /**
  * {@inheritdoc}
  */
 public function getViaUri($uri)
 {
     $scheme = file_uri_scheme($uri);
     return $this->getWrapper($scheme, $uri);
 }
コード例 #21
0
 /**
  * Test use of a default image with an image field.
  */
 function testImageFieldDefaultImage()
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = $this->container->get('renderer');
     $node_storage = $this->container->get('entity.manager')->getStorage('node');
     // Create a new image field.
     $field_name = strtolower($this->randomMachineName());
     $this->createImageField($field_name, 'article');
     // Create a new node, with no images and verify that no images are
     // displayed.
     $node = $this->drupalCreateNode(array('type' => 'article'));
     $this->drupalGet('node/' . $node->id());
     // Verify that no image is displayed on the page by checking for the class
     // that would be used on the image field.
     $this->assertNoPattern('<div class="(.*?)field--name-' . strtr($field_name, '_', '-') . '(.*?)">', 'No image displayed when no image is attached and no default image specified.');
     $cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
     $this->assertTrue(!preg_match('/ image_style\\:/', $cache_tags_header), 'No image style cache tag found.');
     // Add a default image to the public image field.
     $images = $this->drupalGetTestFiles('image');
     $alt = $this->randomString(512);
     $title = $this->randomString(1024);
     $edit = array('files[settings_default_image_uuid]' => drupal_realpath($images[0]->uri), 'settings[default_image][alt]' => $alt, 'settings[default_image][title]' => $title);
     $this->drupalPostForm("admin/structure/types/manage/article/fields/node.article.{$field_name}/storage", $edit, t('Save field settings'));
     // Clear field definition cache so the new default image is detected.
     \Drupal::entityManager()->clearCachedFieldDefinitions();
     $field_storage = FieldStorageConfig::loadByName('node', $field_name);
     $default_image = $field_storage->getSetting('default_image');
     $file = \Drupal::entityManager()->loadEntityByUuid('file', $default_image['uuid']);
     $this->assertTrue($file->isPermanent(), 'The default image status is permanent.');
     $image = array('#theme' => 'image', '#uri' => $file->getFileUri(), '#alt' => $alt, '#title' => $title, '#width' => 40, '#height' => 20);
     $default_output = str_replace("\n", NULL, $renderer->renderRoot($image));
     $this->drupalGet('node/' . $node->id());
     $this->assertCacheTag($file->getCacheTags()[0]);
     $cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
     $this->assertTrue(!preg_match('/ image_style\\:/', $cache_tags_header), 'No image style cache tag found.');
     $this->assertRaw($default_output, 'Default image displayed when no user supplied image is present.');
     // Create a node with an image attached and ensure that the default image
     // is not displayed.
     // Create alt text for the image.
     $alt = $this->randomMachineName();
     $nid = $this->uploadNodeImage($images[1], $field_name, 'article', $alt);
     $node_storage->resetCache(array($nid));
     $node = $node_storage->load($nid);
     $file = $node->{$field_name}->entity;
     $image = array('#theme' => 'image', '#uri' => $file->getFileUri(), '#width' => 40, '#height' => 20, '#alt' => $alt);
     $image_output = str_replace("\n", NULL, $renderer->renderRoot($image));
     $this->drupalGet('node/' . $nid);
     $this->assertCacheTag($file->getCacheTags()[0]);
     $cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
     $this->assertTrue(!preg_match('/ image_style\\:/', $cache_tags_header), 'No image style cache tag found.');
     $this->assertNoRaw($default_output, 'Default image is not displayed when user supplied image is present.');
     $this->assertRaw($image_output, 'User supplied image is displayed.');
     // Remove default image from the field and make sure it is no longer used.
     $edit = array('settings[default_image][uuid][fids]' => 0);
     $this->drupalPostForm("admin/structure/types/manage/article/fields/node.article.{$field_name}/storage", $edit, t('Save field settings'));
     // Clear field definition cache so the new default image is detected.
     \Drupal::entityManager()->clearCachedFieldDefinitions();
     $field_storage = FieldStorageConfig::loadByName('node', $field_name);
     $default_image = $field_storage->getSetting('default_image');
     $this->assertFalse($default_image['uuid'], 'Default image removed from field.');
     // Create an image field that uses the private:// scheme and test that the
     // default image works as expected.
     $private_field_name = strtolower($this->randomMachineName());
     $this->createImageField($private_field_name, 'article', array('uri_scheme' => 'private'));
     // Add a default image to the new field.
     $edit = array('files[settings_default_image_uuid]' => drupal_realpath($images[1]->uri), 'settings[default_image][alt]' => $alt, 'settings[default_image][title]' => $title);
     $this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $private_field_name . '/storage', $edit, t('Save field settings'));
     // Clear field definition cache so the new default image is detected.
     \Drupal::entityManager()->clearCachedFieldDefinitions();
     $private_field_storage = FieldStorageConfig::loadByName('node', $private_field_name);
     $default_image = $private_field_storage->getSetting('default_image');
     $file = \Drupal::entityManager()->loadEntityByUuid('file', $default_image['uuid']);
     $this->assertEqual('private', file_uri_scheme($file->getFileUri()), 'Default image uses private:// scheme.');
     $this->assertTrue($file->isPermanent(), 'The default image status is permanent.');
     // Create a new node with no image attached and ensure that default private
     // image is displayed.
     $node = $this->drupalCreateNode(array('type' => 'article'));
     $image = array('#theme' => 'image', '#uri' => $file->getFileUri(), '#alt' => $alt, '#title' => $title, '#width' => 40, '#height' => 20);
     $default_output = str_replace("\n", NULL, $renderer->renderRoot($image));
     $this->drupalGet('node/' . $node->id());
     $this->assertCacheTag($file->getCacheTags()[0]);
     $cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
     $this->assertTrue(!preg_match('/ image_style\\:/', $cache_tags_header), 'No image style cache tag found.');
     $this->assertRaw($default_output, 'Default private image displayed when no user supplied image is present.');
 }
コード例 #22
0
ファイル: ImageStyle.php プロジェクト: anatalsceo/en-classe
 /**
  * {@inheritdoc}
  */
 public function buildUrl($path, $clean_urls = NULL)
 {
     $uri = $this->buildUri($path);
     // The token query is added even if the
     // 'image.settings:allow_insecure_derivatives' configuration is TRUE, so
     // that the emitted links remain valid if it is changed back to the default
     // FALSE. However, sites which need to prevent the token query from being
     // emitted at all can additionally set the
     // 'image.settings:suppress_itok_output' configuration to TRUE to achieve
     // that (if both are set, the security token will neither be emitted in the
     // image derivative URL nor checked for in
     // \Drupal\image\ImageStyleInterface::deliver()).
     $token_query = array();
     if (!\Drupal::config('image.settings')->get('suppress_itok_output')) {
         // The passed $path variable can be either a relative path or a full URI.
         $original_uri = file_uri_scheme($path) ? file_stream_wrapper_uri_normalize($path) : file_build_uri($path);
         $token_query = array(IMAGE_DERIVATIVE_TOKEN => $this->getPathToken($original_uri));
     }
     if ($clean_urls === NULL) {
         // Assume clean URLs unless the request tells us otherwise.
         $clean_urls = TRUE;
         try {
             $request = \Drupal::request();
             $clean_urls = RequestHelper::isCleanUrl($request);
         } catch (ServiceNotFoundException $e) {
         }
     }
     // If not using clean URLs, the image derivative callback is only available
     // with the script path. If the file does not exist, use url() to ensure
     // that it is included. Once the file exists it's fine to fall back to the
     // actual file path, this avoids bootstrapping PHP once the files are built.
     if ($clean_urls === FALSE && file_uri_scheme($uri) == 'public' && !file_exists($uri)) {
         $directory_path = file_stream_wrapper_get_instance_by_uri($uri)->getDirectoryPath();
         return url($directory_path . '/' . file_uri_target($uri), array('absolute' => TRUE, 'query' => $token_query));
     }
     $file_url = file_create_url($uri);
     // Append the query string with the token, if necessary.
     if ($token_query) {
         $file_url .= (strpos($file_url, '?') !== FALSE ? '&' : '?') . UrlHelper::buildQuery($token_query);
     }
     return $file_url;
 }
コード例 #23
0
ファイル: theme-settings.php プロジェクト: reasonat/pukka
/**
 * Restore Theme settings
 */
function md_boom_multi_restore_theme_settings($form, &$form_state)
{
    variable_set('theme_md_boom_multi_settings', array());
    if ($restore_file = file_save_upload('restore_file_upload')) {
        $file_content = file_get_contents($restore_file->uri);
        $restore_settings = drupal_json_decode(base64_decode(unserialize($file_content)));
        variable_set('theme_md_boom_multi_settings', $restore_settings);
        cache_clear_all();
        drupal_set_message(t('All your theme settings have been restored'));
    } elseif ($restore_file_path = $form_state['values']['restore_file_path']) {
        $restore_file_scheme = file_uri_scheme($restore_file_path);
        if ($restore_file_scheme == 'http' || $restore_file_scheme == 'https') {
            $restore_file_url = rawurldecode($restore_file_path);
            $restore_file_content = file_get_contents($restore_file_url);
            $restore_settings = drupal_json_decode(base64_decode(unserialize($restore_file_content)));
            variable_set('theme_md_boom_multi_settings', $restore_settings);
            cache_clear_all();
            drupal_set_message(t('All your theme settings have been restored'));
        } else {
            $restore_file_content = file_get_contents($restore_file_path);
            $restore_settings = drupal_json_decode(base64_decode(unserialize($restore_file_content)));
            variable_set('theme_md_boom_multi_settings', $restore_settings);
            cache_clear_all();
            drupal_set_message(t('All your theme settings have been restored'));
        }
    }
}
コード例 #24
0
ファイル: theme-settings.php プロジェクト: pantasio/hdso
/**
 * Implements hook_form_system_theme_settings_alter()
 */
function jollyany_form_system_theme_settings_alter(&$form, &$form_state)
{
    $contact_icon = theme_get_setting('contact_icon');
    if (file_uri_scheme($contact_icon) == 'public') {
        $contact_icon = file_uri_target($contact_icon);
    }
    // Main settings wrapper
    $form['options'] = array('#type' => 'vertical_tabs', '#default_tab' => 'defaults', '#weight' => '-10', '#attached' => array('css' => array(drupal_get_path('theme', 'jollyany') . '/css/theme-options.css')));
    // ----------- General -----------
    $form['options']['general'] = array('#type' => 'fieldset', '#title' => t('General'));
    // Breadcrumbs
    $form['options']['general']['breadcrumbs'] = array('#type' => 'checkbox', '#title' => 'Show Breadcrumbs', '#default_value' => theme_get_setting('breadcrumbs'));
    // Contact MAP
    $form['options']['general']['contactmap'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Contact Map</h3>');
    // Company Name
    $form['options']['general']['contactmap']['contactmap_title'] = array('#type' => 'textfield', '#title' => 'Company Name', '#default_value' => theme_get_setting('contactmap_title'));
    // Website
    $form['options']['general']['contactmap']['contactmap_website'] = array('#type' => 'textfield', '#title' => 'Website', '#default_value' => theme_get_setting('contactmap_website'));
    // Contact MAP Address
    $form['options']['general']['contactmap']['contactmap_address'] = array('#type' => 'textarea', '#title' => 'Address', '#default_value' => theme_get_setting('contactmap_address'));
    // Contact MAP Phone
    $form['options']['general']['contactmap']['contactmap_phone'] = array('#type' => 'textfield', '#title' => 'Telephone', '#default_value' => theme_get_setting('contactmap_phone'));
    // Contact MAP Lat
    $form['options']['general']['contactmap']['contactmap_lat'] = array('#type' => 'textfield', '#title' => 'Lat', '#default_value' => theme_get_setting('contactmap_lat'));
    // Contact MAP Long
    $form['options']['general']['contactmap']['contactmap_long'] = array('#type' => 'textfield', '#title' => 'Long', '#default_value' => theme_get_setting('contactmap_long'));
    $form['options']['general']['contactmap']['contact_icon'] = array('#type' => 'textfield', '#title' => 'Path to Contact Icon', '#default_value' => $contact_icon, '#disabled' => TRUE);
    $form['options']['general']['contactmap']['contact_icon_upload'] = array('#type' => 'file', '#title' => 'Upload Contact Icon', '#description' => 'Upload a new Contact Icon.');
    // -------- SEO ---------
    $form['options']['general']['seo'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">SEO</h3>');
    // SEO Title
    $form['options']['general']['seo']['seo_title'] = array('#type' => 'textfield', '#title' => 'Title', '#default_value' => theme_get_setting('seo_title'));
    // SEO Description
    $form['options']['general']['seo']['seo_description'] = array('#type' => 'textarea', '#title' => 'Description', '#default_value' => theme_get_setting('seo_description'));
    // SEO Keywords
    $form['options']['general']['seo']['seo_keywords'] = array('#type' => 'textarea', '#title' => 'Keywords', '#default_value' => theme_get_setting('seo_keywords'));
    // ----------- Layout -----------
    $form['options']['layout'] = array('#type' => 'fieldset', '#title' => t('Layout'));
    // ------ Page Layout Settings ------
    $form['options']['layout']['page'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Page Layout Settings</h3>');
    //Page Layout Container
    $form['options']['layout']['page']['page_style1'] = array('#type' => 'textarea', '#title' => 'Page Style: Boxed Layout - Topbar (Example Home Version 7)', '#default_value' => theme_get_setting('page_style1'));
    //Page Layout Container
    $form['options']['layout']['page']['page_style2'] = array('#type' => 'textarea', '#title' => 'Page Style: Boxed Layout (Example Home Version 8)', '#default_value' => theme_get_setting('page_style2'));
    //Page Layout Container
    $form['options']['layout']['page']['page_onepage'] = array('#type' => 'textarea', '#title' => 'Page Style: One Page', '#default_value' => theme_get_setting('page_onepage'));
    //Page Layout Container
    $form['options']['layout']['page']['page_only_content'] = array('#type' => 'textarea', '#title' => 'Page Style: Only content Layout (Example 404 page)', '#default_value' => theme_get_setting('page_only_content'));
    // ------ Header Settings ------
    $form['options']['layout']['header'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Header Page Settings</h3>');
    $form['options']['layout']['header']['header_1'] = array('#type' => 'textarea', '#title' => 'Page With Header Style 1', '#default_value' => theme_get_setting('header_1'));
    $form['options']['layout']['header']['header_2'] = array('#type' => 'textarea', '#title' => 'Page With Header Style 2', '#default_value' => theme_get_setting('header_2'));
    $form['options']['layout']['header']['header_3'] = array('#type' => 'textarea', '#title' => 'Page With Header Style 3', '#default_value' => theme_get_setting('header_3'));
    // ------ Footer Settings ------
    $form['options']['layout']['footer'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Footer Page Settings</h3>');
    $form['options']['layout']['footer']['footer_1'] = array('#type' => 'textarea', '#title' => 'Page With Footer Style 1', '#default_value' => theme_get_setting('footer_1'));
    $form['options']['layout']['footer']['footer_2'] = array('#type' => 'textarea', '#title' => 'Page With Footer Style 2', '#default_value' => theme_get_setting('footer_2'));
    $form['options']['layout']['footer']['footer_3'] = array('#type' => 'textarea', '#title' => 'Page With Footer Style 3', '#default_value' => theme_get_setting('footer_3'));
    // -------- Projects Layout Settings ----------
    $form['options']['layout']['projects'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Projects Page Layout</h3>');
    // View Project Text Button
    $form['options']['layout']['projects']['project_text_button'] = array('#type' => 'textfield', '#title' => 'View Project Text Button', '#default_value' => theme_get_setting('project_text_button'));
    $form['options']['layout']['projects']['projects_fulllayout'] = array('#type' => 'textarea', '#title' => 'Projects Page Style: Full Layout', '#default_value' => theme_get_setting('projects_fulllayout'));
    // Projects Layout
    /*$form['options']['layout']['projects']['projects_layout'] = array(
           '#type' => 'radios',
           '#title' => 'Select a projects layout:',
           '#default_value' => theme_get_setting('projects_layout'),
           '#options' => array(
               '2_columns' => '2 Columns',
               '3_columns' => '3 Columns',
               '4_columns' => '4 Columns (default)',
    		'2_columns_boxed' => '2 Columns Boxed',
               '3_columns_boxed' => '3 Columns Boxed',
               '4_columns_boxed' => '4 Columns Boxed',
    		'3_columns_full' => '3 Columns Full Width',
               '4_columns_full' => '4 Columns Full Width',
               '6_columns_full' => '6 Columns Full Width',
           ),
       );*/
    // ------- Blog Layout Settings ----------
    /*$form['options']['layout']['blog'] = array(
            '#type' => 'fieldset',
            '#title' => '<div class="plus"></div><h3 class="options_heading">Blog Page Layout</h3>',
        );
    	
        // Blog Layout
        $form['options']['layout']['blog']['blog_layout'] = array(
            '#type' => 'radios',
            '#title' => 'Select a blog layout:',
            '#default_value' => theme_get_setting('blog_layout'),
            '#options' => array(
                'sidebar_right' => 'Sidebar Right (default)',
                'full_width' => 'Full Width',
            ),
        );*/
    /*
    // --------- Contact Layout Settings ----------
        $form['options']['layout']['contact'] = array(
            '#type' => 'fieldset',
            '#title' => '<div class="plus"></div><h3 class="options_heading">Contact Page Layout</h3>',
        );
    
        // Contact Layout
        $form['options']['layout']['contact']['contact_layout'] = array(
            '#type' => 'radios',
            '#title' => 'Select a contact layout:',
            '#default_value' => theme_get_setting('contact_layout'),
            '#options' => array(
                'contact-1' => 'Contact 1 (default)',
                'contact-2' => 'Contact 2',
                'contact-3' => 'Contact 3',
            ),
        );
    */
    // ----------- Design  Settings -----------
    $form['options']['design'] = array('#type' => 'fieldset', '#title' => 'Design');
    // Switcher
    $form['options']['design']['switcher'] = array('#type' => 'checkbox', '#title' => 'Show Switcher Control', '#default_value' => theme_get_setting('switcher'));
    // Layout Option
    $form['options']['design']['layout_style'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Layout Style</h3>');
    $form['options']['design']['layout_style']['layout_option'] = array('#type' => 'radios', '#title' => 'Select a layout style:', '#default_value' => theme_get_setting('layout_option'), '#options' => array('boxed' => 'Boxed', 'fullwidth' => 'Full Width (default)'));
    // Header Option
    $form['options']['design']['header_style'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Header Style</h3>');
    // Header Option
    $form['options']['design']['header_style']['header_option'] = array('#type' => 'radios', '#title' => 'Select a header style option:', '#default_value' => theme_get_setting('header_option'), '#options' => array('header_default' => 'Header Default', 'header1' => 'Header 1', 'header2' => 'Header 2', 'header3' => 'Header 3'));
    // Footer Option
    $form['options']['design']['footer_style'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Footer Style</h3>');
    // Footer Option
    $form['options']['design']['footer_style']['footer_option'] = array('#type' => 'radios', '#title' => 'Select a footer style option:', '#default_value' => theme_get_setting('footer_option'), '#options' => array('footer_default' => 'Footer Default', 'footer1' => 'Footer 1', 'footer2' => 'Footer 2', 'footer3' => 'Footer 3'));
    // Color Option
    $form['options']['design']['color'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Color</h3>');
    // Color Scheme Option
    $form['options']['design']['color']['color_scheme'] = array('#type' => 'select', '#title' => 'Color Scheme', '#default_value' => theme_get_setting('color_scheme'), '#options' => array('blue' => 'Blue', 'green' => 'Green', 'light-blue' => 'Light Blue', 'light-green' => 'Light Green', 'orange' => 'Orange', 'green' => 'Green', 'purple' => 'Purple', 'red' => 'Red', 'tael' => 'Tael', 'violet' => 'Violet', 'yellow' => 'Yellow (default)'));
    // Background Option
    $form['options']['design']['background'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">Background</h3>');
    // Background Color Option
    $form['options']['design']['background']['background_style'] = array('#type' => 'radios', '#title' => 'Select a background style:', '#default_value' => theme_get_setting('background_style'), '#options' => array('light' => 'Light (default)', 'dark' => 'Dark'));
    // CSS
    $form['options']['design']['css'] = array('#type' => 'fieldset', '#title' => '<div class="plus"></div><h3 class="options_heading">CSS</h3>');
    // User CSS
    $form['options']['design']['css']['user_css'] = array('#type' => 'textarea', '#title' => 'Add your own CSS', '#default_value' => theme_get_setting('user_css'));
    // Submit Button
    $form['#submit'][] = 'jollyany_settings_submit';
}
コード例 #25
0
  /**
   * An adaptation of file_save_upload() that includes more verbose errors.
   *
   * @param string $source
   *   A string specifying the filepath or URI of the uploaded file to save.
   *
   * @return stdClass
   *   The saved file object.
   *
   * @throws \RestfulBadRequestException
   * @throws \RestfulServiceUnavailable
   *
   * @see file_save_upload()
   */
  protected function fileSaveUpload($source) {
    static $upload_cache;

    $account = $this->getAccount();
    $options = $this->getPluginKey('options');

    $validators = $options['validators'];
    $destination = $options['scheme'] . "://";
    $replace = $options['replace'];

    // Return cached objects without processing since the file will have
    // already been processed and the paths in _FILES will be invalid.
    if (isset($upload_cache[$source])) {
      return $upload_cache[$source];
    }

    // Make sure there's an upload to process.
    if (empty($_FILES['files']['name'][$source])) {
      return NULL;
    }

    // Check for file upload errors and return FALSE if a lower level system
    // error occurred. For a complete list of errors:
    // See http://php.net/manual/features.file-upload.errors.php.
    switch ($_FILES['files']['error'][$source]) {
      case UPLOAD_ERR_INI_SIZE:
      case UPLOAD_ERR_FORM_SIZE:
        $message = format_string('The file %file could not be saved, because it exceeds %maxsize, the maximum allowed size for uploads.', array('%file' => $_FILES['files']['name'][$source], '%maxsize' => format_size(file_upload_max_size())));
        throw new \RestfulBadRequestException($message);

      case UPLOAD_ERR_PARTIAL:
      case UPLOAD_ERR_NO_FILE:
        $message = format_string('The file %file could not be saved, because the upload did not complete.', array('%file' => $_FILES['files']['name'][$source]));
        throw new \RestfulBadRequestException($message);

      case UPLOAD_ERR_OK:
        // Final check that this is a valid upload, if it isn't, use the
        // default error handler.
        if (is_uploaded_file($_FILES['files']['tmp_name'][$source])) {
          break;
        }

      // Unknown error
      default:
        $message = format_string('The file %file could not be saved. An unknown error has occurred.', array('%file' => $_FILES['files']['name'][$source]));
        throw new \RestfulServiceUnavailable($message);
    }

    // Begin building file object.
    $file = new stdClass();
    $file->uid      = $account->uid;
    $file->status   = 0;
    $file->filename = trim(drupal_basename($_FILES['files']['name'][$source]), '.');
    $file->uri      = $_FILES['files']['tmp_name'][$source];
    $file->filemime = file_get_mimetype($file->filename);
    $file->filesize = $_FILES['files']['size'][$source];

    $extensions = '';
    if (isset($validators['file_validate_extensions'])) {
      if (isset($validators['file_validate_extensions'][0])) {
        // Build the list of non-munged extensions if the caller provided them.
        $extensions = $validators['file_validate_extensions'][0];
      }
      else {
        // If 'file_validate_extensions' is set and the list is empty then the
        // caller wants to allow any extension. In this case we have to remove the
        // validator or else it will reject all extensions.
        unset($validators['file_validate_extensions']);
      }
    }
    else {
      // No validator was provided, so add one using the default list.
      // Build a default non-munged safe list for file_munge_filename().
      $extensions = 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp';
      $validators['file_validate_extensions'] = array();
      $validators['file_validate_extensions'][0] = $extensions;
    }

    if (!empty($extensions)) {
      // Munge the filename to protect against possible malicious extension hiding
      // within an unknown file type (ie: filename.html.foo).
      $file->filename = file_munge_filename($file->filename, $extensions);
    }

    // Rename potentially executable files, to help prevent exploits (i.e. will
    // rename filename.php.foo and filename.php to filename.php.foo.txt and
    // filename.php.txt, respectively). Don't rename if 'allow_insecure_uploads'
    // evaluates to TRUE.
    if (!variable_get('allow_insecure_uploads', 0) && preg_match('/\.(php|pl|py|cgi|asp|js)(\.|$)/i', $file->filename) && (substr($file->filename, -4) != '.txt')) {
      $file->filemime = 'text/plain';
      $file->uri .= '.txt';
      $file->filename .= '.txt';
      // The .txt extension may not be in the allowed list of extensions. We have
      // to add it here or else the file upload will fail.
      if (!empty($extensions)) {
        $validators['file_validate_extensions'][0] .= ' txt';

        // Unlike file_save_upload() we don't need to let the user know that
        // for security reasons, your upload has been renamed, since RESTful
        // will return the file name in the response.
      }
    }

    // If the destination is not provided, use the temporary directory.
    if (empty($destination)) {
      $destination = 'temporary://';
    }

    // Assert that the destination contains a valid stream.
    $destination_scheme = file_uri_scheme($destination);
    if (!$destination_scheme || !file_stream_wrapper_valid_scheme($destination_scheme)) {
      $message = format_string('The file could not be uploaded, because the destination %destination is invalid.', array('%destination' => $destination));
      throw new \RestfulServiceUnavailable($message);
    }

    $file->source = $source;
    // A URI may already have a trailing slash or look like "public://".
    if (substr($destination, -1) != '/') {
      $destination .= '/';
    }
    $file->destination = file_destination($destination . $file->filename, $replace);
    // If file_destination() returns FALSE then $replace == FILE_EXISTS_ERROR and
    // there's an existing file so we need to bail.
    if ($file->destination === FALSE) {
      $message = format_string('The file %source could not be uploaded because a file by that name already exists in the destination %directory.', array('%source' => $source, '%directory' => $destination));
      throw new \RestfulServiceUnavailable($message);
    }

    // Add in our check of the the file name length.
    $validators['file_validate_name_length'] = array();

    // Call the validation functions specified by this function's caller.
    $errors = file_validate($file, $validators);

    // Check for errors.
    if (!empty($errors)) {
      $message = format_string('The specified file %name could not be uploaded.', array('%name' => $file->filename));
      if (count($errors) > 1) {
        $message .= theme('item_list', array('items' => $errors));
      }
      else {
        $message .= ' ' . array_pop($errors);
      }

      throw new \RestfulServiceUnavailable($message);
    }

    // Move uploaded files from PHP's upload_tmp_dir to Drupal's temporary
    // directory. This overcomes open_basedir restrictions for future file
    // operations.
    $file->uri = $file->destination;
    if (!drupal_move_uploaded_file($_FILES['files']['tmp_name'][$source], $file->uri)) {
      watchdog('file', 'Upload error. Could not move uploaded file %file to destination %destination.', array('%file' => $file->filename, '%destination' => $file->uri));
      $message = 'File upload error. Could not move uploaded file.';
      throw new \RestfulServiceUnavailable($message);
    }

    // Set the permissions on the new file.
    drupal_chmod($file->uri);

    // If we are replacing an existing file re-use its database record.
    if ($replace == FILE_EXISTS_REPLACE) {
      $existing_files = file_load_multiple(array(), array('uri' => $file->uri));
      if (count($existing_files)) {
        $existing = reset($existing_files);
        $file->fid = $existing->fid;
      }
    }

    // If we made it this far it's safe to record this file in the database.
    if ($file = file_save($file)) {
      // Add file to the cache.
      $upload_cache[$source] = $file;
      return $file;
    }

    // Something went wrong, so throw a general exception.
    throw new \RestfulServiceUnavailable('Unknown error has occurred.');
  }
コード例 #26
0
ファイル: theme-settings.php プロジェクト: ehazell/AZDWR
function comm_form_system_theme_settings_alter(&$form, &$form_state)
{
    //Add the css to fix the color module's goofy form
    drupal_add_css(drupal_get_path('theme', 'comm') . '/css/colors-admin.css');
    //Fix color module rendering of new colors added to .inc file
    comm_theme_settings_add_new_colors();
    /*
     * Sliver show/hide
     */
    $show_sliver = isset($theme_settings['show_sliver']) ? $theme_settings['show_sliver'] : NULL;
    //Add the checkbox to the form
    $form['sliver'] = array('#type' => 'fieldset', '#title' => t('Sliver banner settings'), '#description' => t('If toggled on, the sliver banner will be displayed.'), '#attributes' => array('class' => array('theme-settings-bottom')));
    $form['sliver']['show_sliver'] = array('#type' => 'checkbox', '#title' => t('Display the sliver banner'), '#default_value' => theme_get_setting('show_sliver'), '#tree' => FALSE, '#description' => t('Check here if you want the theme to display the sliver banner.'));
    /*
       $form['flyout_logo'] = array(
       '#type' => 'fieldset',
       '#title' => t('Flyout Menu Logo'),
       '#description' => t('If toggled on, the sliver banner will be displayed.'),
       '#attributes' => array('class' => array('theme-settings-bottom')),
       );
       $form['flyout_logo']['show_logo'] = array(
       '#type' => 'checkbox',
       '#title' => t('Display the Flyout Logo'),
       '#default_value' => theme_get_setting('show_logo'),
       '#tree' => FALSE,
       '#description' => t('Check here if you want the theme to display the sliver banner.')
       );*/
    /*
     * Background Image
     */
    $background_path = isset($theme_settings['background_path']) ? $theme_settings['background_path'] : NULL;
    // If $background_path is a public:// URI, display the path relative to the files directory. (Stream wrappers are not end-user friendly)
    if (file_uri_scheme($background_path) == 'public') {
        $background_path = file_uri_target($background_path);
    }
    //Add the background image fields to the form
    $form['background_image'] = array('#type' => 'fieldset', '#title' => t('Background image settings'), '#description' => t('If toggled on, the following background will be displayed.'), '#attributes' => array('class' => array('theme-settings-bottom')));
    $form['background_image']['default_background'] = array('#type' => 'checkbox', '#title' => t('Use the default background'), '#default_value' => theme_get_setting('default_background'), '#tree' => FALSE, '#description' => t('Check here if you want the theme to use the background supplied with it.'));
    $form['background_image']['settings'] = array('#type' => 'container', '#states' => array('invisible' => array('input[name="default_background"]' => array('checked' => TRUE))));
    $form['background_image']['settings']['background_path'] = array('#type' => 'textfield', '#title' => t('Path to custom background'), '#description' => t('The path to the file you would like to use as your background file instead of the default background.'), '#default_value' => theme_get_setting('background_path'));
    $form['background_image']['settings']['background_file'] = array('#type' => 'file', '#title' => t('Upload background image'), '#maxlength' => 40, '#description' => t("If you don't have direct file access to the server, use this field to upload your background image."), '#element_validate' => array('_comm_theme_settings_validate'));
    /*
       // Flyout Text that displays below the menu
       $form['flyout_nav'] = array(
       '#type' => 'fieldset',
       '#title' => t('Flyout Nav Menu Text'),
       '#description' => t('If toggled on, the following text will be displayed.'),
       '#attributes' => array('class' => array('theme-flyout-nav')),
       );
       $form['flyout_nav']['use_flyout_text'] = array(
       '#type' => 'checkbox',
       '#title' => t('Use the text below in the flyout menu.'),
       '#default_value' => theme_get_setting('use_flyout_text'),
       '#tree' => FALSE,
       '#description' => t('Check here if you want to display the text.')
       );
       $flyout_nav_text = theme_get_setting('flyout_nav_text');
       $form['flyout_nav']['flyout_nav_text'] = array(
       '#type' => 'text_format',
       '#title' => t('Flyout text Area'),
       '#default_value' => $flyout_nav_text['value'],
       '#format' => $flyout_nav_text['format'],
       );*/
    //Toggle display of the branding block in the footer
    /*
       $form['footer_branding'] = array(
       '#type' => 'fieldset',
       '#title' => t('Footer Branding settings'),
       '#description' => t('If toggled on, the branding block will be displayed.'),
       '#attributes' => array('class' => array('theme-settings-bottom')),
       );
       $form['footer_branding']['display_footer_branding'] = array(
       '#type' => 'checkbox',
       '#title' => t('Display the branding block in the footer'),
       '#default_value' => theme_get_setting('display_footer_branding'),
       '#tree' => FALSE,
       '#description' => t('Check here if you want to display the branding  block in the footer.')
       );*/
    //Capture the information for the Contact Us section in the footer
    $form['footer_contact_us'] = array('#type' => 'fieldset', '#title' => t('Flyout "Contact Us" settings'), '#description' => t('If toggled on, the Contact Us block will be displayed.'), '#attributes' => array('class' => array('theme-settings-bottom')));
    $form['footer_contact_us']['display_footer_contact'] = array('#type' => 'checkbox', '#title' => t('Display the Contact Us block in the flyout region.'), '#default_value' => theme_get_setting('display_footer_contact'), '#tree' => FALSE, '#description' => t('Check here if you want to display the Contact Us block in the flyout region.'));
    $form['footer_contact_us']['settings'] = array('#type' => 'container', '#states' => array('invisible' => array('input[name="display_footer_contact"]' => array('checked' => FALSE))));
    $form['footer_contact_us']['settings']['footer_contact_us_title'] = array('#type' => 'textfield', '#title' => t('Title'), '#description' => t('Title for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_title'));
    $form['footer_contact_us']['settings']['footer_contact_us_title_link'] = array('#type' => 'textfield', '#title' => t('Title Link'), '#description' => t('Link for the title in the Contact Us block. (Recommend linking to the contact form.)'), '#default_value' => theme_get_setting('footer_contact_us_title_link'));
    $form['footer_contact_us']['settings']['footer_contact_us_comm_title'] = array('#type' => 'textfield', '#title' => t('Agency Title'), '#description' => t('Commercial title for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_comm_title'));
    $form['footer_contact_us']['settings']['footer_contact_us_address_1'] = array('#type' => 'textfield', '#title' => t('Address Line 1'), '#description' => t('Address line 1 for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_address_1'));
    $form['footer_contact_us']['settings']['footer_contact_us_address_2'] = array('#type' => 'textfield', '#title' => t('Address Line 2'), '#description' => t('Address line 2 for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_address_2'));
    $form['footer_contact_us']['settings']['footer_contact_us_phone'] = array('#type' => 'textfield', '#title' => t('Phone Number'), '#description' => t('Phone number for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_phone'));
    $form['footer_contact_us']['settings']['footer_contact_us_fax'] = array('#type' => 'textfield', '#title' => t('Fax Number'), '#description' => t('Fax number for the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_fax'));
    $form['footer_contact_us']['settings']['footer_contact_us_map_link'] = array('#type' => 'textfield', '#title' => t('Map Link'), '#description' => t('Link for the map in the Contact Us block.'), '#default_value' => theme_get_setting('footer_contact_us_map_link'));
    $form['footer_contact_us']['settings']['footer_contact_us_map_path'] = array('#type' => 'textfield', '#title' => t('Path to map image'), '#description' => t('The path to the file you would like to use as your map image. (150px x 150px)'), '#default_value' => theme_get_setting('footer_contact_us_map_path'));
    $form['footer_contact_us']['settings']['footer_contact_us_map_image'] = array('#type' => 'file', '#title' => t('Upload map image'), '#maxlength' => 40, '#description' => t("Use this field to upload your map image. (150px x 150px.  Will be resized if necessary.)"), '#element_validate' => array('_comm_theme_settings_map'));
    //End Contact Us
    //Sticky Nav Block
    $sticky_nav_path = isset($theme_settings['sticky_nav_path']) ? $theme_settings['sticky_nav_path'] : NULL;
    // If $sticky_nav_path is a public:// URI, display the path relative to the files directory. (Stream wrappers are not end-user friendly)
    if (file_uri_scheme($sticky_nav_path) == 'public') {
        $sticky_nav_path = file_uri_target($sticky_nav_path);
    }
    //Add the sticky_nav image fields to the form
    $form['sticky_nav_image'] = array('#type' => 'fieldset', '#title' => t('Sticky Nav Menu Logo settings'), '#description' => t('The Sticky Nav is the top bar that contains links and menu icon.'), '#attributes' => array('class' => array('theme-sticky-nav')));
    $form['sticky_nav_image']['use_sticky_nav'] = array('#type' => 'checkbox', '#title' => t('Use a logo for the sticky nav.'), '#default_value' => theme_get_setting('use_sticky_nav'), '#tree' => FALSE, '#description' => t('Check here if you want to display this image in the sticky nav.'));
    $form['sticky_nav_image']['settings']['sticky_nav_path'] = array('#type' => 'textfield', '#title' => t('Path to custom sticky nav icon'), '#description' => t('The path to the file you would like to use as your sticky nav logo file.'), '#default_value' => theme_get_setting('sticky_nav_path'));
    $form['sticky_nav_image']['settings']['sticky_nav_file'] = array('#type' => 'file', '#title' => t('Upload background image'), '#maxlength' => 40, '#description' => t("If you don't have direct file access to the server, use this field to upload your logo."), '#element_validate' => array('_comm_theme_settings_flyout'));
    $stickyMobile = theme_get_setting('sticky_nav_mobile');
    if ($stickyMobile != null) {
        $form['sticky_nav_image']['sticky_nav_mobile'] = array('#type' => 'radios', '#title' => t('When to display the sticky nav.'), '#default_value' => theme_get_setting('sticky_nav_mobile'), '#options' => array(1 => 'Display the Sticky Nav only in mobile display', 0 => 'Display the Sticky Nav in desktop and mobile displays'));
    } else {
        $form['sticky_nav_image']['sticky_nav_mobile'] = array('#type' => 'radios', '#title' => t('When to display the sticky nav.'), '#default_value' => 1, '#options' => array(1 => 'Display the Sticky Nav only in mobile display', 0 => 'Display the Sticky Nav in desktop and mobile displays'));
    }
    //End Sticky Nav Block
    return $form;
}
コード例 #27
0
ファイル: ThemeTest.php プロジェクト: frankcr/sftw8
 /**
  * Test the theme settings form.
  */
 function testThemeSettings()
 {
     // Ensure invalid theme settings form URLs return a proper 404.
     $this->drupalGet('admin/appearance/settings/bartik');
     $this->assertResponse(404, 'The theme settings form URL for a uninstalled theme could not be found.');
     $this->drupalGet('admin/appearance/settings/' . $this->randomMachineName());
     $this->assertResponse(404, 'The theme settings form URL for a non-existent theme could not be found.');
     $this->assertTrue(\Drupal::service('theme_installer')->install(['stable']));
     $this->drupalGet('admin/appearance/settings/stable');
     $this->assertResponse(404, 'The theme settings form URL for a hidden theme is unavailable.');
     // Specify a filesystem path to be used for the logo.
     $file = current($this->drupalGetTestFiles('image'));
     $file_relative = strtr($file->uri, array('public:/' => PublicStream::basePath()));
     $default_theme_path = 'core/themes/classy';
     $supported_paths = array($file->uri => array('form' => file_uri_target($file->uri), 'src' => file_url_transform_relative(file_create_url($file->uri))), file_uri_target($file->uri) => array('form' => file_uri_target($file->uri), 'src' => file_url_transform_relative(file_create_url($file->uri))), $file_relative => array('form' => $file_relative, 'src' => file_url_transform_relative(file_create_url($file->uri))), 'core/misc/druplicon.png' => array('form' => 'core/misc/druplicon.png', 'src' => base_path() . 'core/misc/druplicon.png'), $default_theme_path . '/logo.svg' => array('form' => $default_theme_path . '/logo.svg', 'src' => base_path() . $default_theme_path . '/logo.svg'));
     foreach ($supported_paths as $input => $expected) {
         $edit = array('default_logo' => FALSE, 'logo_path' => $input);
         $this->drupalPostForm('admin/appearance/settings', $edit, t('Save configuration'));
         $this->assertNoText('The custom logo path is invalid.');
         $this->assertFieldByName('logo_path', $expected['form']);
         // Verify logo path examples.
         $elements = $this->xpath('//div[contains(@class, :item)]/div[@class=:description]/code', array(':item' => 'js-form-item-logo-path', ':description' => 'description'));
         // Expected default values (if all else fails).
         $implicit_public_file = 'logo.svg';
         $explicit_file = 'public://logo.svg';
         $local_file = $default_theme_path . '/logo.svg';
         // Adjust for fully qualified stream wrapper URI in public filesystem.
         if (file_uri_scheme($input) == 'public') {
             $implicit_public_file = file_uri_target($input);
             $explicit_file = $input;
             $local_file = strtr($input, array('public:/' => PublicStream::basePath()));
         } elseif (file_uri_scheme($input) !== FALSE) {
             $explicit_file = $input;
         } elseif ($input == file_uri_target($file->uri)) {
             $implicit_public_file = $input;
             $explicit_file = 'public://' . $input;
             $local_file = PublicStream::basePath() . '/' . $input;
         }
         $this->assertEqual((string) $elements[0], $implicit_public_file);
         $this->assertEqual((string) $elements[1], $explicit_file);
         $this->assertEqual((string) $elements[2], $local_file);
         // Verify the actual 'src' attribute of the logo being output in a site
         // branding block.
         $this->drupalPlaceBlock('system_branding_block', ['region' => 'header']);
         $this->drupalGet('');
         $elements = $this->xpath('//header//a[@rel=:rel]/img', array(':rel' => 'home'));
         $this->assertEqual((string) $elements[0]['src'], $expected['src']);
     }
     $unsupported_paths = array('public://whatever.png', 'private://whatever.png', 'temporary://whatever.png', 'public:/whatever.png', '://whatever.png', ':whatever.png', 'public://', 'whatever.png', PublicStream::basePath() . '/whatever.png', '/' . PublicStream::basePath() . '/whatever.png', 'core/misc/whatever.png', '/core/misc/whatever.png', drupal_realpath($file->uri));
     $this->drupalGet('admin/appearance/settings');
     foreach ($unsupported_paths as $path) {
         $edit = array('default_logo' => FALSE, 'logo_path' => $path);
         $this->drupalPostForm(NULL, $edit, t('Save configuration'));
         $this->assertText('The custom logo path is invalid.');
     }
     // Upload a file to use for the logo.
     $edit = array('default_logo' => FALSE, 'logo_path' => '', 'files[logo_upload]' => drupal_realpath($file->uri));
     $this->drupalPostForm('admin/appearance/settings', $edit, t('Save configuration'));
     $fields = $this->xpath($this->constructFieldXpath('name', 'logo_path'));
     $uploaded_filename = 'public://' . $fields[0]['value'];
     $this->drupalPlaceBlock('system_branding_block', ['region' => 'header']);
     $this->drupalGet('');
     $elements = $this->xpath('//header//a[@rel=:rel]/img', array(':rel' => 'home'));
     $this->assertEqual($elements[0]['src'], file_url_transform_relative(file_create_url($uploaded_filename)));
     $this->container->get('theme_handler')->install(array('bartik'));
     // Ensure only valid themes are listed in the local tasks.
     $this->drupalPlaceBlock('local_tasks_block', ['region' => 'header']);
     $this->drupalGet('admin/appearance/settings');
     $theme_handler = \Drupal::service('theme_handler');
     $this->assertLink($theme_handler->getName('classy'));
     $this->assertLink($theme_handler->getName('bartik'));
     $this->assertNoLink($theme_handler->getName('stable'));
     // If a hidden theme is an admin theme it should be viewable.
     \Drupal::configFactory()->getEditable('system.theme')->set('admin', 'stable')->save();
     \Drupal::service('router.builder')->rebuildIfNeeded();
     $this->drupalPlaceBlock('local_tasks_block', ['region' => 'header', 'theme' => 'stable']);
     $this->drupalGet('admin/appearance/settings');
     $this->assertLink($theme_handler->getName('stable'));
     $this->drupalGet('admin/appearance/settings/stable');
     $this->assertResponse(200, 'The theme settings form URL for a hidden theme that is the admin theme is available.');
 }
コード例 #28
0
ファイル: ThemeSettingsForm.php プロジェクト: ddrozdik/dmaps
 /**
  * Helper function for the system_theme_settings form.
  *
  * Attempts to validate normal system paths, paths relative to the public files
  * directory, or stream wrapper URIs. If the given path is any of the above,
  * returns a valid path or URI that the theme system can display.
  *
  * @param string $path
  *   A path relative to the Drupal root or to the public files directory, or
  *   a stream wrapper URI.
  * @return mixed
  *   A valid path that can be displayed through the theme system, or FALSE if
  *   the path could not be validated.
  */
 protected function validatePath($path)
 {
     // Absolute local file paths are invalid.
     if (drupal_realpath($path) == $path) {
         return FALSE;
     }
     // A path relative to the Drupal root or a fully qualified URI is valid.
     if (is_file($path)) {
         return $path;
     }
     // Prepend 'public://' for relative file paths within public filesystem.
     if (file_uri_scheme($path) === FALSE) {
         $path = 'public://' . $path;
     }
     if (is_file($path)) {
         return $path;
     }
     return FALSE;
 }
コード例 #29
0
 /**
  * Test the scheme functions.
  */
 function testGetValidStreamScheme()
 {
     $this->assertEqual('foo', file_uri_scheme('foo://pork//chops'), 'Got the correct scheme from foo://asdf');
     $this->assertEqual('data', file_uri_scheme('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='), 'Got the correct scheme from a data URI.');
     $this->assertFalse(file_uri_scheme('foo/bar.txt'), 'foo/bar.txt is not a valid stream.');
     $this->assertTrue(file_stream_wrapper_valid_scheme(file_uri_scheme('public://asdf')), 'Got a valid stream scheme from public://asdf');
     $this->assertFalse(file_stream_wrapper_valid_scheme(file_uri_scheme('foo://asdf')), 'Did not get a valid stream scheme from foo://asdf');
 }
コード例 #30
0
ファイル: UploadFetcher.php プロジェクト: alnutile/drunatra
 /**
  * {@inheritdoc}
  */
 public function validateConfigurationForm(array &$form, array &$form_state)
 {
     $values =& $form_state['values']['fetcher']['configuration'];
     $values['directory'] = trim($values['directory']);
     $values['allowed_extensions'] = trim($values['allowed_extensions']);
     // Validate the URI scheme of the upload directory.
     $scheme = file_uri_scheme($values['directory']);
     if (!$scheme || !in_array($scheme, $this->getSchemes())) {
         form_error($form['fetcher_configuration']['directory'], $this->t('Please enter a valid scheme into the directory location.'));
         // Return here so that attempts to create the directory below don't throw
         // warnings.
         return;
     }
     // Ensure that the upload directory exists.
     if (!file_prepare_directory($values['directory'], FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
         form_error($form['fetcher_configuration']['directory'], $this->t('The chosen directory does not exist and attempts to create it failed.'));
     }
 }