[Snippet] Convert magic_urls to code tags V1 + V2

Little Mods and Snips 2

[Snippet] Convert magic_urls to code tags V1 + V2

Postby Sekuro » 21 Apr 2012, 13:55

Convert magic_urls to code tags V1

V1 converts all external links in a post without [url] tags grouped into code box.

Demo: http://4seven.bplaced.net/forum/3/viewtopic.php?p=72#p72

Screen:

url_to_code.png
url_to_code.png (5.41 KiB) Viewed 1309 times

Note:
Bcs. of technical reasons the code box was append to the bottom of each posting.
Altering the message directly seems not to work, bcs. it gives wired results,
if a normal code box with links is also present. May another provide a trick,
but after some tests this seems the only solution to get rid of this behaviour.

Instruction

open

viewtopic.php

find

Code: Select all
    // Parse the message and subject
    $message = censor_text($row['post_text']);


before add

Code: Select all
// URLs to Code / 4seven / 2012
$url_code  = '';

if (strpos($row['post_text'], 'postlink') !== false){

preg_match_all('#<a(.*?)class="postlink"(.*?)>(.*?)<\/a>#is', $row['post_text'], $message_urls);

$row['post_text'] = preg_replace('#<a(.*?)class="postlink"(.*?)>(.*?)<\/a>#is', '', $row['post_text']);

// var_dump($message_urls);

if (!empty($message_urls[0])){

$url_code .= '<dl class="codebox"><dt>' . $user->lang['CODE'] . ': <a href="#" onclick="selectCode(this); return false;">' . $user->lang['SELECT_ALL_CODE'] . '</a></dt><dd><code>';

foreach(
$message_urls[0] as $mess_urls){
$url_code .= preg_replace('#<a(.*?)class="postlink"(.*?)>(.*?)<\/a>#is', '$3<br />', $mess_urls);
}

$url_code .= '</code></dd></dl>';

}}
// URLs to Code Block / 4seven / 2012          


find

Code: Select all
        'MESSAGE'            => $message,


after add

Code: Select all
        'MESSAGE'            => $message . $url_code,
Mod-Bot / Service-Team
User avatar
Sekuro

Tiptop

Tiptop
 
Posts: 241
Joined: 11 Feb 2008, 11:49
 
Resolution: 1440x900



Re: [Snippet] Convert magic_urls to code tags V1 + V2

Postby Sekuro » 21 Apr 2012, 17:01

Convert magic_urls to code tags V2

V2 converts all external links in a post without [url] tags into its own code box.

Screen:
url_code_v2.png
url_code_v2.png (5.65 KiB) Viewed 1288 times

Instruction

open

viewtopic.php

find

Code: Select all
    // Parse the message and subject
    $message = censor_text($row['post_text']);


before add

Code: Select all
$row['post_text'] = preg_replace('#<a(.*?)class="postlink"(.*?)>(.*?)<\/a>#is', '<dl class="codebox"><dt>' . $user->lang['CODE'] . ': <a href="#" onclick="selectCode(this); return false;">' . $user->lang['SELECT_ALL_CODE'] . '</a></dt><dd><code>$3</code></dd></dl>', $row['post_text']); 
Mod-Bot / Service-Team
User avatar
Sekuro

Tiptop

Tiptop
 
Posts: 241
Joined: 11 Feb 2008, 11:49
 
Resolution: 1440x900



Return to Snip Cl@ss II

Who is online

Users browsing this forum: No registered users and 2 guests

cron