Must have post to see links

Started by Android4Life, April 06, 2012, 11:00:08 AM

Previous topic - Next topic

ascaland

Quote from: Marcus Forsberg on April 08, 2012, 03:08:00 PM
Does this work?

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 :)),
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)',
),


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,
$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + ($quoted == false ? 1 : 7));
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

Thanks to Frank with GC Webhosting for giving me the best hosting I could ask for!
Best customer support you could ask for!

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.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

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.

Suki

Oh yeah, I just grabbed the first Subs attached and didn't check if the tags had any code added, my bad :P
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Tomy Tran

What will be happened if something like class or id is put in the middle of <a and href, for example: <a id="adslink" href="

Suki

You can easily modify the regex to accept that.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Tomy Tran

I want to block it in all case, if I change for id, user can add class, I am not good at regex :(

Suki

If you check the regex, it already does take care of things like id or class,  it would be weird if someone puts a class="" before the href, it can be done, but it's not that frequent.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Tomy Tran

some advertisers will try to do different to have his backlink, thanks anyway.

Advertisement: