Skip to content

Commit

Permalink
Adding target blank for external links
Browse files Browse the repository at this point in the history
  • Loading branch information
Yannick243 committed Jan 9, 2024
1 parent c1f144e commit 276d979
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion modules/core/message_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function format_msg_text($str, $output_mod, $links=true) {
$str = preg_replace("/(&(?!amp)[^;]+;)/", " $1", $str);
if ($links) {
$link_regex = "/((http|ftp|rtsp)s?:\/\/(%[[:digit:]A-Fa-f][[:digit:]A-Fa-f]|[-_\.!~\*';\/\?#:@&=\+$,%[:alnum:]])+)/m";
$str = preg_replace($link_regex, "<a href=\"$1\">$1</a>", $str);
$str = preg_replace($link_regex, "<a href=\"$1\" target=\"_blank\" rel=\"noopener\">$1</a>", $str);
}
$str = preg_replace("/ (&[^;]+;)/", "$1", $str);
$str = str_replace('<wbr>', '&#160;<wbr>', $str);
Expand Down
10 changes: 5 additions & 5 deletions modules/developer/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ protected function output() {
return '<div class="dev_content"><div class="content_title">'.$this->trans('Developer Documentation').'</div>'.
'<div class="long_text">'.
'There is not a lot of documentation yet, but there are a few resources available online. First is the module overview page at our website intended for developers interested in creating module sets.'.
'<br /><br />&nbsp;&nbsp;&nbsp;<a href="http://cypht.org/modules.html">http://cypht.org/modules.html</a>'.
'<br /><br />Code Documentation for Cypht is auto-generated using <a href="http://www.apigen.org/">Apigen</a> and while '.
'<br /><br />&nbsp;&nbsp;&nbsp;<a href="http://cypht.org/modules.html" target="_blank" rel="noopener">http://cypht.org/modules.html</a>'.
'<br /><br />Code Documentation for Cypht is auto-generated using <a href="http://www.apigen.org/" target="_blank" rel="noopener">Apigen</a> and while '.
'not yet complete, has a lot of useful information'.
'<br /><br />&nbsp;&nbsp;&nbsp;<a href="http://cypht.org/docs/code_docs/index.html">http://cypht.org/docs/code_docs/index.html</a>'.
'<br /><br />&nbsp;&nbsp;&nbsp;<a href="http://cypht.org/docs/code_docs/index.html" target="_blank" rel="noopener">http://cypht.org/docs/code_docs/index.html</a>'.
'<br /><br />Finally there is a "hello world" module with lots of comments included in the project download and browsable at github'.
'<br /><br />&nbsp;&nbsp;&nbsp;<a href="https://github.com/cypht-org/cypht/tree/master/modules/hello_world">https://github.com/cypht-org/cypht/tree/master/modules/hello_world</a>'.
'<br /><br />&nbsp;&nbsp;&nbsp;<a href="https://github.com/cypht-org/cypht/tree/master/modules/hello_world" target="_blank" rel="noopener">https://github.com/cypht-org/cypht/tree/master/modules/hello_world</a>'.
'</div></div>';
}
}
Expand Down Expand Up @@ -180,7 +180,7 @@ protected function output() {
'<tr><th>Zend version</th><td>'.$server_info['zend_version'].'</td></tr>'.
'<tr><th>SAPI</th><td>'.$server_info['sapi'].'</td></tr>'.
'<tr><th>Enabled Modules</th><td>'.str_replace(',', ', ', implode(',', $this->get('router_module_list'))).'</td></tr>'.
'<tr><th>Git version</th><td>'.$server_info['branch_name'].' at revision <a href="'.$server_info['commit_url'].'">'.$server_info['commit_hash'].'</a> ('.$server_info['commit_date'].')</td></tr>'.
'<tr><th>Git version</th><td>'.$server_info['branch_name'].' at revision <a href="'.$server_info['commit_url'].'" target="_blank" rel="noopener">'.$server_info['commit_hash'].'</a> ('.$server_info['commit_date'].')</td></tr>'.
'</table></div>';
}
return '';
Expand Down
6 changes: 3 additions & 3 deletions modules/github/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -782,14 +782,14 @@ function github_parse_headers($data, $output_mod) {

if (array_key_exists('actor', $data) && array_key_exists('login', $data['actor'])) {
$from = $data['actor']['login'];
$from_link = sprintf(' - <a href="https://github.com/%s">https://github.com/%s</a>', $output_mod->html_safe($from), $output_mod->html_safe($from));
$from_link = sprintf(' - <a href="https://github.com/%s" target="_blank" rel="noopener">https://github.com/%s</a>', $output_mod->html_safe($from), $output_mod->html_safe($from));
}
else {
$from = '[No From]';
}
if (array_key_exists('repo', $data) && array_key_exists('name', $data['repo'])) {
$name = $data['repo']['name'];
$repo_link = sprintf(' - <a href="https://github.com/%s">https://github.com/%s</a>', $output_mod->html_safe($name), $output_mod->html_safe($name));
$repo_link = sprintf(' - <a href="https://github.com/%s" target="_blank" rel="noopener">https://github.com/%s</a>', $output_mod->html_safe($name), $output_mod->html_safe($name));
}
else {
$name = '[No Repo]';
Expand Down Expand Up @@ -837,7 +837,7 @@ function github_parse_payload($data, $output_mod) {
}
if (array_key_exists('url', $vals) && array_key_exists('sha', $vals)) {
$url = str_replace(array('commits', 'https://api.github.com/repos'), array('commit', 'https://github.com'), $vals['url']);
$res .= sprintf('<div class="github_link"><a href="%s">%s</a></div>',
$res .= sprintf('<div class="github_link"><a href="%s" target="_blank" rel="noopener">%s</a></div>',
$output_mod->html_safe($url), $output_mod->html_safe($vals['sha']));
}
$res .= '</div>';
Expand Down
2 changes: 1 addition & 1 deletion modules/nasa/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected function output() {
'" alt="'.$this->trans('Picture of the day').'" /></div>';
}
elseif ($data['media_type'] == 'video' && array_key_exists('url', $data)) {
$res .= '<div class="apod_video"><a href="'.$this->html_safe($data['url']).'">YouTube</a></div>';
$res .= '<div class="apod_video"><a href="'.$this->html_safe($data['url']).'" target="_blank" rel="noopener">YouTube</a></div>';
}
}
elseif (array_key_exists('url', $data) && preg_match("/jpg$/i", $data['url'])) {
Expand Down
2 changes: 1 addition & 1 deletion modules/nux/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class Hm_Output_nux_dev_news extends Hm_Output_Module {
protected function output() {
$res = '<div class="nux_dev_news"><div class="nux_title">'.$this->trans('Development Updates').'</div><table>';
foreach ($this->get('nux_dev_news', array()) as $vals) {
$res .= sprintf('<tr><td><a href="https://github.com/cypht-org/cypht/commit/%s">%s</a>'.
$res .= sprintf('<tr><td><a href="https://github.com/cypht-org/cypht/commit/%s" target="_blank" rel="noopener">%s</a>'.
'</td><td class="msg_date">%s</td><td>%s</td><td>%s</td></tr>',
$this->html_safe($vals['hash']),
$this->html_safe($vals['shash']),
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/modules/core/message_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function test_format_msg_image() {
public function test_format_msg_text() {
$mod = new Hm_Output_Test(array('foo' => 'bar', 'bar' => 'foo'), array('bar'));
$this->assertEquals("foo<br />\nbar<br />", format_msg_text("foo\nbar", $mod));
$this->assertEquals('<a href="http://foo.com">http://foo.com</a><br />', format_msg_text('http://foo.com', $mod));
$this->assertEquals('<a href="http://foo.com">http://foo.com</a>]<br />', format_msg_text('http://foo.com]', $mod));
$this->assertEquals('<a href="http://foo.com" target="_blank" rel="noopener">http://foo.com</a><br />', format_msg_text('http://foo.com', $mod));
$this->assertEquals('<a href="http://foo.com" target="_blank" rel="noopener">http://foo.com</a>]<br />', format_msg_text('http://foo.com]', $mod));
}
/**
* @preserveGlobalState disabled
Expand Down

0 comments on commit 276d979

Please sign in to comment.