Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

phpBB - Force links to open in new page

Status
Not open for further replies.

kwunder

Technical User
Jun 2, 2001
860
0
0
GB
Hi,

I have NO knowledge of php at all for starters !

I guy I know is running a forum and need to implement a way of forcing any links in user posts to open in a new page - rather than have the link direct you away from the site.

He has sent me the following code and thinks there is a part of it that can be modified to acheive the above.

Can anyone advise please ?
Many thanks in advance.

<!-- BEGIN forumrow -->
<!-- IF forumrow.S_IS_CAT or forumrow.S_FIRST_ROW or forumrow.S_NO_CAT -->

<br />
<div class="forabg">
<div class="inner"><span class="corners-top"><span></span></span>


<ul class="topiclist">
<li class="header">
<dl class="icon">
<dt><!-- IF forumrow.S_IS_CAT --><a href="{forumrow.U_VIEWFORUM}">{forumrow.FORUM_NAME}</a><!-- ELSE -->{L_FORUM}<!-- ENDIF --></dt>
<dd class="lastpost"><span>{L_LAST_POST}</span></dd>
<dd class="topics">{L_TOPICS}</dd>
<dd class="posts">{L_POSTS}</dd>
</dl>
</li>
</ul>
<span class="corners-bottom"><span></span></span></div>
</div>

<!-- ENDIF -->

<ul class="topiclist">
<!-- IF not forumrow.S_IS_CAT -->
<div class="navbar">
<div class="inner"><span class="corners-top"><span></span></span>
<dl class="icon" style="background-image: url({forumrow.FORUM_FOLDER_IMG_SRC}); background-repeat: no-repeat;">
<dt title="{forumrow.FORUM_FOLDER_IMG_ALT}">
<!-- IF forumrow.FORUM_IMAGE --><span class="forum-image">{forumrow.FORUM_IMAGE}</span><!-- ENDIF -->

<a href="{forumrow.U_VIEWFORUM}" class="forumtitle">{forumrow.FORUM_NAME}</a><br />
{forumrow.FORUM_DESC}
<!-- IF forumrow.MODERATORS -->
<br /><strong>{forumrow.L_MODERATOR_STR}:</strong> {forumrow.MODERATORS}
<!-- ENDIF -->
<!-- IF forumrow.SUBFORUMS and forumrow.S_LIST_SUBFORUMS --><br /><strong>{forumrow.L_SUBFORUM_STR}</strong> {forumrow.SUBFORUMS}<!-- ENDIF -->
</dt>

<!-- IF forumrow.CLICKS -->
<dd class="redirect"><span>{L_REDIRECTS}: {forumrow.CLICKS}</span></dd>
<!-- ELSEIF not forumrow.S_IS_LINK -->
<dd class="lastpost"><span>
<!-- IF forumrow.LAST_POST_TIME --><dfn>{L_LAST_POST}</dfn><a href="{forumrow.U_LAST_POST}" title="{forumrow.LAST_POST_SUBJECT}">{forumrow.LAST_POST_SHORTENED_SUBJECT}</a> {L_POST_BY_AUTHOR} {forumrow.LAST_POSTER_FULL}
<a href="{forumrow.U_LAST_POST}">{LAST_POST_IMG}</a> <br />{L_POSTED_ON_DATE} {forumrow.LAST_POST_TIME}<!-- ELSE -->{L_NO_POSTS}<!-- ENDIF --></span>

</dd>
<dd class="topics">{forumrow.TOPICS} <dfn>{L_TOPICS}</dfn></dd>
<dd class="posts">{forumrow.POSTS} <dfn>{L_POSTS}</dfn></dd>
<!-- ENDIF -->
</dl>
<span class="corners-bottom"><span></span></span></div>
</div>

<!-- ENDIF -->
<div style="height:2px;"></div>

<!-- BEGINELSE -->
<div class="panel">
<div class="inner"><span class="corners-top"><span></span></span>
<strong>{L_NO_FORUMS}</strong>
<span class="corners-bottom"><span></span></span></div>
</div>

<!-- END forumrow -->
</ul>
 
Is this PHP or ASP.net? I'm not seeing any PHP tags and the syntax looks different. I'm new to PHP as well though.
 
not really php.

Code:
<a [red]target="_blank"[/red] href="

make the change to the various links you need to open elsewhere.
 
Hi

I am afraid that will not solve it. The OP mentioned "links in user posts", for that the BBCode parser should be modified, not the page template.


Feherke.
 
doh.

easiest solution is in javascript unless the OP wants to get his hands dirty with the bbcode parser.
 
Thanks for the replies so far guys !

How can javascript be used to solve it ?

It's rather embarrasing - but I've never heard of bbcode parser !
 
novice60 said:
Is this PHP or ASP.net? I'm not seeing any PHP tags and the syntax looks different. I'm new to PHP as well though.

Neither. It is phpbb template code, the uppercase words are replaced with values when the template is parsed through the forum scripts.


Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
This lookos promising...

How can I tell if his forum is subsilver / prosilver or acidtech etc ?

Many thanks !
 
Apparently, the forum uses a modified template.
From the link given above to the kb article, I can't see the line of code that requires changing on our template ?

 
In jquery id do something like this

Code:
$('document').ready(function(){
$('dd.posts a, dd.lastpost a').prop('target', '_blank');
});

Assuming of course that the posts themselves are all in the dd with the post or lastpost class. The mod might better be done inside the post template itself. If the op can supply that we could help with some php code there. (perhaps even using the very cool phpquery port of jquery)
 
Right. Lateest news is...

The custom template is based on 1thank, and was created for later versions of PHBBB3.

The

<a class="forumlink" href="{forumrow.U_VIEWFORUM}">{forumrow.FORUM_NAME}</a>

line is does not exist.

Thanks for your continued advice.
 
Show us the foun post template. We can't be expected to help you in a vacuum.
 
JUst to reitterate - I have no knowledge of how any of this works. The forum belongs to a friend.
Can you explain what a "foun post template is please ?"

I've asked my froend if he can send me a copy of the unmodified template in case that is what you meant...
 
forum post template (iphone troubles).

this should do it (load jquery first of course)
Code:
$[COLOR=#990000 ]([/color][COLOR=#FF0000 ]'document'[/color][COLOR=#990000 ]).[/color][b][COLOR=#000000 ]ready[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#0000FF ]function[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
 $[COLOR=#990000 ]([/color][COLOR=#FF0000 ]'.postbody a'[/color][COLOR=#990000 ]).[/color][b][COLOR=#000000 ]prop[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'target'[/color][COLOR=#990000 ],[/color] [COLOR=#FF0000 ]'_blank'[/color][COLOR=#990000 ]);[/color]
[COLOR=#FF0000 ]}[/color][COLOR=#990000 ]);[/color]

this is not xhtml compliant, however. another way (compliant) is this

Code:
$[COLOR=#990000 ]([/color][COLOR=#FF0000 ]'document'[/color][COLOR=#990000 ]).[/color][b][COLOR=#000000 ]ready[/color][/b][COLOR=#990000 ]([/color][b][COLOR=#0000FF ]function[/color][/b][COLOR=#990000 ]()[/color][COLOR=#FF0000 ]{[/color]
 $[COLOR=#990000 ]([/color][COLOR=#FF0000 ]'.postbody a'[/color][COLOR=#990000 ]).[/color][b][COLOR=#000000 ]on[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'click'[/color][COLOR=#990000 ],[/color] [b][COLOR=#0000FF ]function[/color][/b][COLOR=#990000 ]([/color]e[COLOR=#990000 ])[/color][COLOR=#FF0000 ]{[/color] 
[tab] e[COLOR=#990000 ].[/color][b][COLOR=#000000 ]preventDefault[/color][/b][COLOR=#990000 ]();[/color] 
[tab] window[COLOR=#990000 ].[/color][b][COLOR=#000000 ]open[/color][/b][COLOR=#990000 ]([/color]$[COLOR=#990000 ]([/color][b][COLOR=#0000FF ]this[/color][/b][COLOR=#990000 ]).[/color][b][COLOR=#000000 ]prop[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'href'[/color][COLOR=#990000 ]));[/color]
[tab] [b][COLOR=#0000FF ]return[/color][/b] [b][COLOR=#0000FF ]false[/color][/b][COLOR=#990000 ];[/color]
 [COLOR=#FF0000 ]}[/color][COLOR=#990000 ]);[/color]
[COLOR=#FF0000 ]}[/color][COLOR=#990000 ]);[/color]

for a php solution you would be better off posting in a phpbb forum if you get no answers here (but see below ...).

the code above changes only the links in the user generated content (i.e. the posts themselves). it does not change the general forum links.

i had a brief look at the phpbb code. you would need to edit the code that handles autodetection of urls (functions-content.php). then edit the bbcode parser in the template and finally edit the function that parses the content before storage (includes/functions.php). at least. and this would only fix for new posts.

another php alternative is to run all output through a filter. easily done in pure php. not sure how easy it is to hook an output filter in phpbb and possibly a big performance hit. probably you would do this in viewtopic.php by adding a line after $message = censor_text($row['post_text']);. i'd do this using phpquery probably (just because i like it).

Code:
[i][COLOR=#9A1900 ]//assuming that phpQuery is in scope[/color][/i]
[b][COLOR=#000080 ]require_once[/color][/b] [COLOR=#FF0000 ]'phpQuery.php'[/color][COLOR=#990000 ];[/color]
[COLOR=#009900 ]$_doc[/color] [COLOR=#990000 ]=[/color] phpQuery[COLOR=#990000 ]::[/color][b][COLOR=#000000 ]newDocumentXHTML[/color][/b][COLOR=#990000 ]([/color][COLOR=#009900 ]$message[/color][COLOR=#990000 ],[/color] [COLOR=#009900 ]$charset[/color] [COLOR=#990000 ]=[/color] [COLOR=#FF0000 ]'utf-8'[/color][COLOR=#990000 ]);[/color]
[COLOR=#009900 ]$_doc[/color][COLOR=#990000 ][[/color][COLOR=#FF0000 ]'a'[/color][COLOR=#990000 ]]->[/color][b][COLOR=#000000 ]attr[/color][/b][COLOR=#990000 ]([/color][COLOR=#FF0000 ]'target'[/color][COLOR=#990000 ],[/color][COLOR=#FF0000 ]'_blank'[/color][COLOR=#990000 ]);[/color]
[COLOR=#009900 ]$message[/color] [COLOR=#990000 ]=[/color] [COLOR=#009900 ]$_doc[/color][COLOR=#990000 ];[/color]
(nb again non-xhtml compliant but the only way i know to force new windows when javascript is turned off, which is what we are protecting for by doing the filtering server-side).

and another "plain" php method might be to use a preg_replace callback on the $message variable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top