예제 #1
0
/**
 * Converts youtube / vimeo URLs into things we can embed
 * @param  string $video_url a well formed youtube/vimeo direct URL.
 * @return string            the address that's valid for embed codes.
 */
function _foundation_access_video_url($video_url)
{
    // account for the broken form of embed code from youtube
    if (strpos($video_url, 'youtube') && !strpos($video_url, 'embed')) {
        $tmp = drupal_parse_url($video_url);
        $yvid = '';
        // check for youtube url vs embed
        if (isset($tmp['query']['v'])) {
            $yvid = $tmp['query']['v'];
            return 'https://www.youtube.com/embed/' . $yvid;
        }
    }
    // account for the broken form of embed code from vimeo
    if (strpos($video_url, 'vimeo') && !strpos($video_url, 'player')) {
        // rip out from embed based url
        $vpath = explode('/', $video_url);
        $part = array_pop($vpath);
        // drop the autoplay property cause it conflicts with what we're doing
        $part = str_replace('autoplay=1', '', $part);
        return 'https://player.vimeo.com/video/' . $part;
    }
    // didn't know what to do or it was already well formed
    return $video_url;
}
 /**
  * Initializes and executes a cURL request.
  *
  * @param $curl_options
  *   An associative array of cURL options to set, where the keys are constants
  *   defined by the cURL library. For a list of valid options, see
  *   http://www.php.net/manual/function.curl-setopt.php
  * @param $redirect
  *   FALSE if this is an initial request, TRUE if this request is the result
  *   of a redirect.
  *
  * @return
  *   The content returned from the call to curl_exec().
  *
  * @see curlInitialize()
  */
 protected function curlExec($curl_options, $redirect = FALSE)
 {
     $this->curlInitialize();
     if (!empty($curl_options[CURLOPT_URL])) {
         // Forward XDebug activation if present.
         if (isset($_COOKIE['XDEBUG_SESSION'])) {
             $options = drupal_parse_url($curl_options[CURLOPT_URL]);
             $options += array('query' => array());
             $options['query'] += array('XDEBUG_SESSION_START' => $_COOKIE['XDEBUG_SESSION']);
             $curl_options[CURLOPT_URL] = url($options['path'], $options);
         }
         // cURL incorrectly handles URLs with a fragment by including the
         // fragment in the request to the server, causing some web servers
         // to reject the request citing "400 - Bad Request". To prevent
         // this, we strip the fragment from the request.
         // TODO: Remove this for Drupal 8, since fixed in curl 7.20.0.
         if (strpos($curl_options[CURLOPT_URL], '#')) {
             $original_url = $curl_options[CURLOPT_URL];
             $curl_options[CURLOPT_URL] = strtok($curl_options[CURLOPT_URL], '#');
         }
     }
     $url = empty($curl_options[CURLOPT_URL]) ? curl_getinfo($this->curlHandle, CURLINFO_EFFECTIVE_URL) : $curl_options[CURLOPT_URL];
     if (!empty($curl_options[CURLOPT_POST])) {
         // This is a fix for the Curl library to prevent Expect: 100-continue
         // headers in POST requests, that may cause unexpected HTTP response
         // codes from some webservers (like lighttpd that returns a 417 error
         // code). It is done by setting an empty "Expect" header field that is
         // not overwritten by Curl.
         $curl_options[CURLOPT_HTTPHEADER][] = 'Expect:';
     }
     curl_setopt_array($this->curlHandle, $this->additionalCurlOptions + $curl_options);
     if (!$redirect) {
         // Reset headers, the session ID and the redirect counter.
         $this->session_id = NULL;
         $this->headers = array();
         $this->redirect_count = 0;
     }
     $content = curl_exec($this->curlHandle);
     $status = curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE);
     // cURL incorrectly handles URLs with fragments, so instead of
     // letting cURL handle redirects we take of them ourselves to
     // to prevent fragments being sent to the web server as part
     // of the request.
     // TODO: Remove this for Drupal 8, since fixed in curl 7.20.0.
     if (in_array($status, array(300, 301, 302, 303, 305, 307)) && $this->redirect_count < variable_get('simpletest_maximum_redirects', 5)) {
         if ($this->drupalGetHeader('location')) {
             $this->redirect_count++;
             $curl_options = array();
             $curl_options[CURLOPT_URL] = $this->drupalGetHeader('location');
             $curl_options[CURLOPT_HTTPGET] = TRUE;
             return $this->curlExec($curl_options, TRUE);
         }
     }
     $this->drupalSetContent($content, isset($original_url) ? $original_url : curl_getinfo($this->curlHandle, CURLINFO_EFFECTIVE_URL));
     $message_vars = array('!method' => !empty($curl_options[CURLOPT_NOBODY]) ? 'HEAD' : (empty($curl_options[CURLOPT_POSTFIELDS]) ? 'GET' : 'POST'), '@url' => isset($original_url) ? $original_url : $url, '@status' => $status, '!length' => format_size(strlen($this->drupalGetContent())));
     $message = t('!method @url returned @status (!length).', $message_vars);
     $this->assertTrue($this->drupalGetContent() !== FALSE, $message, t('Browser'));
     return $this->drupalGetContent();
 }
/**
 * Define the preset add/edit form.
 *
 * @see current_search_add_item_submit()
 * @see current_search_settings_form_submit()
 * @ingroup forms
 */
function current_search_settings_form(&$form, &$form_state)
{
    $item =& $form_state['item'];
    $form['info']['#weight'] = -30;
    if (empty($item->settings)) {
        $item->settings = current_search_get_defaults();
    }
    // NOTE: We need to add the #id in order for the machine_name to work.
    $form['info']['label'] = array('#id' => 'edit-label', '#title' => t('Name'), '#type' => 'textfield', '#default_value' => $item->label, '#description' => t('The human-readable name of the current search block configuration.'), '#required' => TRUE, '#maxlength' => 255, '#size' => 30);
    $form['info']['name'] = array('#type' => 'machine_name', '#default_value' => $item->name, '#maxlength' => 32, '#machine_name' => array('exists' => 'current_search_config_exists', 'source' => array('info', 'label')), '#disabled' => 'clone' != $form_state['form type'] && !empty($item->name), '#description' => t('The machine readable name of the current search block configuration. This value can only contain letters, numbers, and underscores.'));
    $form['info']['searcher'] = array('#type' => 'select', '#title' => t('Search page'), '#options' => current_search_get_searcher_options(), '#description' => t('The search page this configuration will be active on.'), '#default_value' => current_search_get_default_searcher(), '#access' => empty($item->name));
    // Hide the standard buttons.
    $form['buttons']['#access'] = FALSE;
    // Add our custom buttons.
    $form['actions'] = array('#type' => 'actions', '#weight' => -100);
    // Gets destination from query string which is set when the page is navigated
    // to via a contextual link. Builds messages based on where user came from.
    if (isset($_GET['destination']) && !url_is_external($_GET['destination'])) {
        $submit_text = t('Save and go back to search page');
        $cancel_title = t('Return to the search page without saving configuration changes.');
        $url = drupal_parse_url($_GET['destination']);
    } else {
        $submit_text = t('Save and go back to list');
        $cancel_title = t('Return to the list without saving configuration changes.');
        $url = array();
    }
    $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save and edit'));
    // Do not show the button if the page was navigated to via a contextual link
    // because it would redirect the user back to the search page.
    $form['actions']['submit_list'] = array('#type' => 'submit', '#value' => $submit_text);
    $form['actions']['cancel'] = array('#type' => 'link', '#title' => t('Cancel'), '#href' => !$url ? 'admin/config/search/current_search' : $url['path'], '#options' => !$url ? array() : array('query' => $url['query']), '#attributes' => array('title' => $cancel_title));
    if (empty($item->name)) {
        $description = t('Add a new current search block configuration.');
    } else {
        $description = t('Add new items to the current search block or configure existing ones.');
    }
    $form['description'] = array('#prefix' => '<div class="current-search-description">', '#suffix' => '</div>', '#markup' => $description, '#weight' => -90);
    drupal_add_css(drupal_get_path('module', 'current_search') . '/current_search.css');
    // If we are creating the configuration, only display the basic config items.
    // Otherwise set the breadcrumb due to possible bug in CTools Export UI.
    if (empty($form['info']['name']['#default_value'])) {
        return;
    }
    // Gets list of plugins, sanitizes label for output.
    $plugins = array_map('check_plain', current_search_get_plugins());
    ////
    ////
    //// Add plugin section
    ////
    ////
    $form['plugins_title'] = array('#type' => 'item', '#title' => t('Add item to block'));
    $form['plugins'] = array('#tree' => TRUE, '#prefix' => '<div class="clearfix">', '#suffix' => '</div>');
    $form['plugins']['plugin'] = array('#type' => 'select', '#title' => t('Type'), '#options' => $plugins, '#prefix' => '<div class="current-search-setting current-search-plugin">', '#suffix' => '</div>');
    $form['plugins']['item_label'] = array('#title' => t('Name'), '#type' => 'textfield', '#default_value' => '', '#required' => FALSE, '#size' => 30, '#prefix' => '<div class="current-search-setting current-search-label">', '#suffix' => '</div>');
    $form['plugins']['item_name'] = array('#type' => 'machine_name', '#default_value' => '', '#maxlength' => 32, '#machine_name' => array('exists' => 'current_search_item_exists', 'source' => array('plugins', 'item_label')), '#required' => FALSE, '#description' => t('The machine readable name of the item being added to the current search block. This value can only contain letters, numbers, and underscores.'));
    $form['plugins']['actions'] = array('#type' => 'actions', '#prefix' => '<div class="current-search-setting current-search-button">', '#suffix' => '</div>');
    $form['plugins']['actions']['add_item'] = array('#type' => 'submit', '#value' => t('Add item'), '#submit' => array('current_search_add_item_submit'), '#validate' => array('current_search_add_item_validate'));
    ////
    ////
    //// Sort settings
    ////
    ////
    // Ensure the theme function is available after upgrading to 7.x-1.3. A cache
    // clear is all that is needed to fix the broken sort table, however this hack
    // ensures that the theme function is available without having to do so.
    // @todo Remove this in later versions of the module.
    // @see http://drupal.org/node/1795556
    module_load_include('inc', 'current_search', 'current_search.theme');
    $form['plugin_sort'] = array('#type' => 'item', '#access' => !empty($item->settings['items']), '#title' => t('Item display order'), '#theme' => 'current_search_sort_settings_table', '#current_search' => $item->settings, '#tree' => TRUE);
    // Builds checkbox options and weight dropboxes.
    foreach ($item->settings['items'] as $name => $settings) {
        $form['plugin_sort'][$name]['item'] = array('#markup' => check_plain($settings['label']));
        $form['plugin_sort'][$name]['remove'] = array('#type' => 'link', '#title' => t('Remove item'), '#href' => 'admin/config/search/current_search/item/' . $item->name . '/delete/' . $name);
        $form['plugin_sort'][$name]['weight'] = array('#type' => 'weight', '#title' => t('Weight for @title', array('@title' => $settings['label'])), '#title_display' => 'invisible', '#delta' => 50, '#default_value' => isset($settings['weight']) ? $settings['weight'] : 0, '#attributes' => array('class' => array('current-search-sort-weight')));
    }
    ////
    ////
    //// Filter settings
    ////
    ////
    $form['plugin_settings_title'] = array('#type' => 'item', '#access' => !empty($item->settings['items']), '#title' => t('Item settings'));
    $form['plugin_settings'] = array('#type' => 'vertical_tabs', '#tree' => TRUE);
    // Builds table, adds settings to vertical tabs.
    $has_settings = FALSE;
    foreach ($item->settings['items'] as $name => $settings) {
        if ($class = ctools_plugin_load_class('current_search', 'items', $settings['id'], 'handler')) {
            $plugin = new $class($name, $item);
            // Initializes vertical tab for the item's settings.
            $form['plugin_settings'][$name] = array('#type' => 'fieldset', '#title' => check_plain($settings['label']), '#group' => 'settings', '#tree' => TRUE);
            $form['plugin_settings'][$name]['id'] = array('#type' => 'value', '#value' => $settings['id']);
            $form['plugin_settings'][$name]['label'] = array('#type' => 'value', '#value' => $settings['label']);
            // Gets settings from plugin.
            $plugin->settingsForm($form['plugin_settings'][$name], $form_state);
            $has_settings = TRUE;
        }
    }
    // Removes fieldset if there aren't any settings.
    if (!$has_settings) {
        unset($form['plugin_settings']);
    }
    ////
    ////
    //// Advanced settings
    ////
    ////
    $form['advanced_settings_title'] = array('#type' => 'item', '#title' => t('Advanced settings'));
    $form['advanced_settings'] = array('#tree' => TRUE);
    // This setting was originally intended as a way for site builders to enable
    // the current search block on pages where no keywords were submitted by the
    // end user, which is known as an "empty search". The display settings were
    // expanded beyond empty searches at http://drupal.org/node/1779670 leaving
    // us with the unfortunate "empty_searches" key which no longer reflects what
    // this setting does.
    $form['advanced_settings']['empty_searches'] = array('#type' => 'radios', '#title' => t('Display settings'), '#options' => array(CURRENT_SEARCH_DISPLAY_KEYS => t('Display only when keywords are entered.'), CURRENT_SEARCH_DISPLAY_ALWAYS => t('Display on empty searches where no keywords are entered.'), CURRENT_SEARCH_DISPLAY_FILTERS => t('Display only when one or more facet items are active.'), CURRENT_SEARCH_DISPLAY_KEYS_FILTERS => t('Display when either keywords are entered one or more facet items are active.')), '#default_value' => $item->settings['advanced']['empty_searches'], '#description' => t('This setting determines when the current search block will be displayed.'));
}
 /**
  * Assert that URL fragment exists.
  */
 protected function assertUrlFragment($fragment, $url = NULL)
 {
     if (!$url) {
         $url = $this->getUrl();
     }
     $url_parsed = drupal_parse_url($url);
     if (!empty($url_parsed['fragment'])) {
         return $this->assertEqual($fragment, $url_parsed['fragment'], format_string('URL fragment %fragment exists', ['%fragment' => $fragment]));
     } else {
         $this->fail(format_string('URL fragment %fragment does not exist', ['%fragment' => $fragment]));
         return FALSE;
     }
 }
예제 #5
0
 /**
  * @Then /^I should still have retained search filters$/
  */
 public function iShouldStillHaveRetainedSearchFilters()
 {
     $url = $this->getSession()->getCurrentUrl();
     $parsed_url = drupal_parse_url($url);
     // Check if we still have ...
     // Topic: 'Earth'
     // Search term: 'Nobel'
     if (empty($parsed_url['query']['search_api_views_fulltext']) || 'Nobel' != $parsed_url['query']['search_api_views_fulltext'] || empty($parsed_url['query']['f']['0']) || 'c4m_vocab_topic:1' != $parsed_url['query']['f']['0']) {
         throw new \Exception("I am not on table view retaining filters and search\n        term.");
     }
 }
// session_start(). As a result, session_destroy() in User::logout() function
// throws an error. Although this does not affect RedTest execution or even
// session handling, it's better to not let Drupal throw this error in the first
// place.
/*if (empty($_SERVER['SERVER_SOFTWARE'])) {
  drupal_override_server_variables(array('SERVER_SOFTWARE' => 'RedTest'));
}*/
drupal_override_server_variables();
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
global $test_setting_variable;
$test_setting_variable = parse_ini_file(DRUPAL_ROOT . "/tests/configuration.ini", TRUE);
Patchwork\redefine('drupal_goto', function ($path = '', array $options = array(), $http_response_code = 302) {
    // A destination in $_GET always overrides the function arguments.
    // We do not allow absolute URLs to be passed via $_GET, as this can be an attack vector.
    if (isset($_GET['destination']) && !url_is_external($_GET['destination'])) {
        $destination = drupal_parse_url($_GET['destination']);
        $path = $destination['path'];
        $options['query'] = $destination['query'];
        $options['fragment'] = $destination['fragment'];
    }
    // In some cases modules call drupal_goto(current_path()). We need to ensure
    // that such a redirect is not to an external URL.
    if ($path === current_path() && empty($options['external']) && url_is_external($path)) {
        // Force url() to generate a non-external URL.
        $options['external'] = FALSE;
    }
    drupal_alter('drupal_goto', $path, $options, $http_response_code);
    global $drupal_goto;
    $drupal_goto['path'] = $path;
    $drupal_goto['options'] = $options;
    $drupal_goto['http_response_code'] = $http_response_code;
예제 #7
0
파일: Extension.php 프로젝트: tfd7/tfd7
function tfd_url($item, $options = array())
{
    if (is_numeric($item)) {
        $ret = url('node/' . $item, (array) $options);
    } else {
        $parsed = drupal_parse_url($item);
        $options += $parsed;
        $ret = url($parsed['path'], (array) $options);
    }
    return check_url($ret);
}
예제 #8
0
function badm_form_after_build(&$form, &$form_state)
{
    $isHorizontal = isset($form['#form_horizontal']) && $form['#form_horizontal'];
    $form['#form_horizontal'] = $isHorizontal;
    _badm_form_horizontal_set($form, $isHorizontal);
    if ($isHorizontal) {
        $form['#attributes']['class'][] = 'form-horizontal';
    }
    // Alter the confirm form, because Drupal is stupid.
    if ('confirm_form' === $form['#theme']) {
        $question = drupal_get_title();
        if ($item = menu_get_item()) {
            if (empty($item['title'])) {
                drupal_set_title(t("Confirmation"));
            } else {
                drupal_set_title($item['title']);
            }
        }
        $question = ['#prefix' => '<p class="lead"><strong>', '#markup' => $question, '#suffix' => '</strong></p>', '#weight' => -100];
        array_unshift($form, $question);
    }
    // We have to do 2 passes...
    $vertical_tabs = [];
    _badm_vertical_tabs_find($form, $vertical_tabs);
    _badm_vertical_tabs_recursion($form, $vertical_tabs);
    if (isset($form['actions']) && isset($_GET['destination']) && !isset($form['actions']['cancel']) && !isset($form['cancel'])) {
        $destination = drupal_parse_url($_GET['destination']);
        $path = $destination['path'];
        $form['actions']['cancel'] = ['#markup' => l("Cancel", $path, ['query' => $destination['query'], 'fragment' => $destination['fragment'], 'attributes' => ['class' => ['btn', 'btn-default']]]), '#weight' => 100];
    }
    return $form;
}