/** * Implements template_preprocess_page(). */ function locke_preprocess_page(&$variables, $hook) { // Add copyright to theme. if ($copyright = theme_get_setting('copyright')) { $variables['copyright'] = check_markup($copyright['value'], $copyright['format']); } // Setup the search box functionality $search_box_form = drupal_get_form('search_form'); $search_box_form['basic']['keys']['#title'] = ''; $search_box_form['basic']['keys']['#attributes'] = array('placeholder' => 'Search'); $search_box_form['basic']['submit']['#value'] = t('Go'); $search_box = drupal_render($search_box_form); $variables['search_box'] = user_access('search content') ? $search_box : NULL; // Setup the contact information $variables['contact_information']['site_name'] = variable_get('site_name'); $variables['contact_information']['address'] = _filter_autop(theme_get_setting('address')); $variables['contact_information']['phone'] = theme_get_setting('phone'); $variables['contact_information']['fax'] = theme_get_setting('fax'); // Setup the social links $social_links = array(); if (module_exists('openacademy_news')) { $social_links[] = l('Read', 'rss.xml', array('attributes' => array('class' => 'rss-link'))); } if ($twitter_link = theme_get_setting('twitter_link')) { $social_links[] = l('Follow', $twitter_link, array('attributes' => array('class' => 'twitter-link'))); } if ($youtube_link = theme_get_setting('youtube_link')) { $social_links[] = l('Watch', $youtube_link, array('attributes' => array('class' => 'youtube-link'))); } if ($facebook_link = theme_get_setting('facebook_link')) { $social_links[] = l('Friend', $facebook_link, array('attributes' => array('class' => 'facebook-link'))); } $variables['social_links'] = theme('item_list', array('items' => $social_links)); // Define the university seal if (theme_get_setting('seal_path') && !theme_get_setting('default_seal')) { $seal_path = theme_get_setting('seal_path'); $variables['seal'] = file_create_url($seal_path); } else { $variables['seal'] = '/' . path_to_theme() . '/assets/images/seal.png'; } }
/** * Tests the line break filter. */ function testLineBreakFilter() { // Get FilterAutoP object. $filter = $this->filters['filter_autop']; // Since the line break filter naturally needs plenty of newlines in test // strings and expectations, we're using "\n" instead of regular newlines // here. $tests = array("aaa\nbbb\n\nccc" => array("<p>aaa<br />\nbbb</p>\n<p>ccc</p>" => TRUE), "<script>aaa\nbbb\n\nccc</script>\n<style>aaa\nbbb\n\nccc</style>\n<pre>aaa\nbbb\n\nccc</pre>\n<object>aaa\nbbb\n\nccc</object>\n<iframe>aaa\nbbb\n\nccc</iframe>\n" => array("<script>aaa\nbbb\n\nccc</script>" => TRUE, "<style>aaa\nbbb\n\nccc</style>" => TRUE, "<pre>aaa\nbbb\n\nccc</pre>" => TRUE, "<object>aaa\nbbb\n\nccc</object>" => TRUE, "<iframe>aaa\nbbb\n\nccc</iframe>" => TRUE), "One. <!-- comment --> Two.\n<!--\nThree.\n-->\n" => array('<!-- comment -->' => TRUE, "<!--\nThree.\n-->" => TRUE), '<p><div> </div></p>' => array("<p>\n<div> </div>\n</p>" => TRUE), '<div><p> </p></div>' => array("<div>\n</div>" => TRUE), '<blockquote><pre>aaa</pre></blockquote>' => array("<blockquote><pre>aaa</pre></blockquote>" => TRUE), "<pre>aaa\nbbb\nccc</pre>\nddd\neee" => array("<pre>aaa\nbbb\nccc</pre>" => TRUE, "<p>ddd<br />\neee</p>" => TRUE), "aaa<!--comment-->\n\nbbb\n\nccc\n\nddd<!--comment\nwith linebreak-->\n\neee\n\nfff" => array("<p>aaa</p>\n<!--comment--><p>\nbbb</p>\n<p>ccc</p>\n<p>ddd</p>" => TRUE, "<!--comment\nwith linebreak--><p>\neee</p>\n<p>fff</p>" => TRUE), "<pre>aaa\nbbb<!-- comment -->\n\nccc</pre>\nddd" => array("<pre>aaa\nbbb<!-- comment -->\n\nccc</pre>" => TRUE), "<iframe>aaa</iframe>\n\n" => array("<p><iframe>aaa</iframe></p>" => FALSE)); $this->assertFilteredString($filter, $tests); // Very long string hitting PCRE limits. $limit = max(ini_get('pcre.backtrack_limit'), ini_get('pcre.recursion_limit')); $source = $this->randomMachineName($limit); $result = _filter_autop($source); $success = $this->assertEqual($result, '<p>' . $source . "</p>\n", 'Line break filter can process very long strings.'); if (!$success) { $this->verbose("\n" . $source . "\n<hr />\n" . $result); } }
/** * {@inheritdoc} */ public function process($text, $langcode) { return new FilterProcessResult(_filter_autop($text)); }
/** * Load and render a help topic. * * @param string $module * Name of the module. * @param string $topic * Name of the topic. * @todo port the drupal_alter functionality. * * @return string * Returns formatted topic. */ public function viewTopic($module, $topic, $is_modal = false) { $file_info = $this->advanced_help->getTopicFileInfo($module, $topic); if ($file_info) { $info = $this->advanced_help->getTopic($module, $topic); $file = "{$file_info['path']}/{$file_info['file']}"; $build = [ '#type' => 'markup', ]; if (!empty($info['css'])) { $build['#attached']['library'][] = $info['module'] . '/' . $info['css']; } $build['#markup'] = file_get_contents($file); if (isset($info['readme file']) && $info['readme file']) { $ext = pathinfo($file, PATHINFO_EXTENSION); if ('md' == $ext && $this->advanced_help->isMarkdownFilterEnabled()) { libraries_load('php-markdown', 'markdown-extra'); $build['#markup'] = '<div class="advanced-help-topic">' . Xss::filterAdmin(\Michelf\MarkdownExtra::defaultTransform($build['#markup'])) . '</div>'; } else { $readme = ''; if ('md' == $ext) { $readme .= '<p>' . $this->t('If you install the !module module, the text below will be filtered by the module, producing rich text.', [ '!module' => $this->l($this->t('Markdown filter'), Url::fromUri('https://www.drupal.org/project/markdown'), ['attributes' => ['title' => $this->t('Link to project.')]]) ]) . '</p>'; } $readme .= '<div class="advanced-help-topic"><pre class="readme">' . SafeMarkup::checkPlain($build['#markup']) . '</pre></div>'; $build['#markup'] = $readme; } return $build['#markup']; } // Change 'topic:' to the URL for another help topic. preg_match('/&topic:([^"]+)&/', $build['#markup'], $matches); if (isset($matches[1]) && preg_match('/[\w\-]\/[\w\-]+/', $matches[1])) { list($umodule, $utopic) = explode('/', $matches[1]); $path = new Url('advanced_help.help', ['module' => $umodule, 'topic' => $utopic]); $build['#markup'] = preg_replace('/&topic:([^"]+)&/', $path->toString(), $build['#markup']); } global $base_path; // Change 'path:' to the URL to the base help directory. $build['#markup'] = str_replace('&path&', $base_path . $info['path'] . '/', $build['#markup']); // Change 'trans_path:' to the URL to the actual help directory. $build['#markup'] = str_replace('&trans_path&', $base_path . $file_info['path'] . '/', $build['#markup']); // Change 'base_url:' to the URL to the site. $build['#markup'] = preg_replace('/&base_url&([^"]+)"/', $base_path . '$1' . '"', $build['#markup']); // Run the line break filter if requested. if (!empty($info['line break'])) { // Remove the header since it adds an extra <br /> to the filter. $build['#markup'] = preg_replace('/^<!--[^\n]*-->\n/', '', $build['#markup']); $build['#markup'] = _filter_autop($build['#markup']); } if (!empty($info['navigation']) && !$is_modal) { $topics = $this->advanced_help->getTopics(); $topics = $this->getTopicHierarchy($topics); if (!empty($topics[$module][$topic]['children'])) { $items = $this->getTree($topics, $topics[$module][$topic]['children']); $links = [ '#theme' => 'item_list', '#items' => $items ]; $build['#markup'] .= \Drupal::service('renderer')->render($links, FALSE); } list($parent_module, $parent_topic) = $topics[$module][$topic]['_parent']; if ($parent_topic) { $parent = $topics[$module][$topic]['_parent']; $up = new Url('advanced_help.help', ['module' => $parent[0], 'topic' => $parent[1]]); } else { $up = new Url('advanced_help.module_index', ['module' => $module]); } $siblings = $topics[$parent_module][$parent_topic]['children']; uasort($siblings, [$this, 'helpUasort']); $prev = $next = NULL; $found = FALSE; foreach ($siblings as $sibling) { list($sibling_module, $sibling_topic) = $sibling; if ($found) { $next = $sibling; break; } if ($sibling_module == $module && $sibling_topic == $topic) { $found = TRUE; continue; } $prev = $sibling; } if ($prev || $up || $next) { $navigation = '<div class="help-navigation clear-block">'; if ($prev) { $navigation .= $this->l('«« ' . $topics[$prev[0]][$prev[1]]['title'], new Url('advanced_help.help', ['module' => $prev[0], 'topic' => $prev[1]], ['attributes' => ['class' => 'help-left']])); } if ($up) { $navigation .= $this->l($this->t('Up'), $up->setOption('attributes', ['class' => ($prev) ? 'help-up' : 'help-up-noleft'])); } if ($next) { $navigation .= $this->l($topics[$next[0]][$next[1]]['title'] . ' »»', new Url('advanced_help.help', ['module' => $next[0], 'topic' => $next[1]], ['attributes' => ['class' => 'help-right']])); } $navigation .= '</div>'; $build['#markup'] .= $navigation; } } $build['#markup'] = '<div class="advanced-help-topic">' . $build['#markup'] . '</div>'; // drupal_alter('advanced_help_topic', $output, $popup); return $build; } }