Customizing SMF > SMF Coding Discussion
Must have post to see links
Anthony`:
--- Quote from: Marcus Forsberg on April 08, 2012, 03:08:00 PM ---Does this work?
--- End quote ---
I havn't looked at what you or Suki have done, but when I tried doing this I got far enough as to removing the actual anchor tag and replacing it with text, but the contents of the actual address is still leftover. Here's what I did by modifying the BB code (would use hooks but too lazy for that :)),
--- Code: --- array(
'tag' => 'url',
'type' => 'unparsed_content',
'content' => '<a href="$1" class="bbc_link" target="_blank">$1</a>',
'validate' => create_function('&$tag, &$data, $disabled', '
$data = strtr($data, array(\'<br />\' => \'\'));
if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
$data = \'http://\' . $data;
'),
),
array(
'tag' => 'url',
'type' => 'unparsed_equals',
'before' => '<a href="$1" class="bbc_link" target="_blank">',
'after' => '</a>',
'validate' => create_function('&$tag, &$data, $disabled', '
global $user_info;
if (strpos($data, \'http://\') !== 0 && strpos($data, \'https://\') !== 0)
$data = \'http://\' . $data;
if ($user_info[\'posts\'] < 10) {
$data = \'\';
$tag[\'before\'] = \'You must have over 10 posts to see links!\';
$tag[\'after\'] = \'\';
}
'),
'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
'disabled_after' => ' ($1)',
),
--- End code ---
Now again, my issue was I still had left over BB code (to be precise, after debugging I had {my input here}[/url]). So unless he feels like doing some customization outside the BB code, that gets done here,
--- Code: ---$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + ($quoted == false ? 1 : 7));
--- End code ---
Specifically where the second substr is called.
Marcus Forsberg:
I have no idea what Suki has done, I just fixed the parse error, changed from 10 to 2, and made sure the edits are applied to both iurl and url tags. I have no clue if it works or anything. :P
Android4Life:
--- Quote from: Marcus Forsberg on April 08, 2012, 03:08:00 PM ---Does this work?
--- End quote ---
That is working great thanks!
Suki:
I just replaced all instance of anchor tags
if ($user_info['posts'] < 10)
$message = preg_replace('#<a href="(.*?)</a>#i', 'Sorry, you need 10 posts to see this link', $message);
So instead of modifying directly the tags, lets wait until all the parsing is done and then do a preg_replace for all links, it seems to me the easiest way.
Marcus Forsberg:
I realised that a while after posting that file. Thing is though, you never removed the edits to the tags so it's now both editing the tags and the buffer, heh. :P Not that it's a real issue, it works.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version