News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Give message when guest clicks on URL

Started by SwapsRulez, June 12, 2008, 12:51:14 AM

Previous topic - Next topic

SwapsRulez

Hi guys, i want to hide the links from the guest, but i want to tell them that there is a link, but you need to register to see the link through alert of the javascript, but i'm unable to do that. it makes my forum blank.
I'm using SMF 2.0 Beta 3. Here is my forum

http://www.project-bb.org/

If anyone needs, i will provide a test account.

Actually i was trying to do this..

   array(
            'tag' => 'iurl',
            'type' => 'unparsed_content',
            'content' => $user_info['is_guest'] ? '<a href="#" class="bbc_link new_win" onclick="alert('You need to login or register to see the link. Thank you.')">$1</a>' : '<a href="$1" class="bbc_link">$1</a>',
            'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
         ),
         array(
            'tag' => 'iurl',
            'type' => 'unparsed_equals',
            'before' => $user_info['is_guest'] ? '<a href="#" class="bbc_link new_win" onclick="alert('You need to login or register to see the link. Thank you.')">$1</a><div style="visibility:hidden">' : '<a href="$1" class="bbc_link">',
            'after' => $user_info['is_guest'] ?  '</div>' : '</a>',
            'validate' => create_function('&$tag, &$data, $disabled', '
               if (substr($data, 0, 1) == \'#\')
                  $data = \'#post_\' . substr($data, 1);'),
            'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
            'disabled_after' => $user_info['is_guest'] ?  '' :  ' ($1)',
         ),


Can anyone tell me how to write this in proper way, its wrong at the time. I dont know how to write php code, but still i tried at my best. But still not working. Any help is much appreciated.

Thanks in advance :) Waiting for a sweet solution.
Project-BB.org : Educational Forum For Engineering, Diploma & Technical Students

The Engineering, Diploma & All technical students lounge for Free Projects, Seminars, Syllabus, Question Papers, College Assignments, Placement Papers, E-Books, Company Information & other technical stuffs.

Oldiesmann

You need to escape the initial single quotes due to the single quotes in the javascript string.

Try this:

   array(
            'tag' => 'iurl',
            'type' => 'unparsed_content',
            'content' => $user_info['is_guest'] ? \'<a href="#" class="bbc_link new_win" onclick="alert('You need to login or register to see the link. Thank you.')">$1</a>\' : '<a href="$1" class="bbc_link">$1</a>',
            'validate' => create_function('&$tag, &$data, $disabled', '$data = strtr($data, array(\'<br />\' => \'\'));'),
         ),
         array(
            'tag' => 'iurl',
            'type' => 'unparsed_equals',
            'before' => $user_info['is_guest'] ? \'<a href="#" class="bbc_link new_win" onclick="alert('You need to login or register to see the link. Thank you.')">$1</a><div style="visibility:hidden">\' : '<a href="$1" class="bbc_link">',
            'after' => $user_info['is_guest'] ?  '</div>' : '</a>',
            'validate' => create_function('&$tag, &$data, $disabled', '
               if (substr($data, 0, 1) == \'#\')
                  $data = \'#post_\' . substr($data, 1);'),
            'disallow_children' => array('email', 'ftp', 'url', 'iurl'),
            'disabled_after' => $user_info['is_guest'] ?  '' :  ' ($1)',
         ),
Michael Eshom
Christian Metal Fans

spearfish

Are you sure about that Oldies?  I was under the impression that escaping a quote meant PHP won't recognize it.... and if you escape the quote telling it to interpret a string literal....
I'm predicting a parse error, although you have more experience than me.

I'd try this if Oldies' solution fails:

'before' => $user_info['is_guest'] ? '<a href="#" class="bbc_link new_win" onclick="alert(\'You need to login or register to see the link. Thank you.\')">$1</a><div style="visibility:hidden">' : '<a href="$1" class="bbc_link">',

karlbenson

You need to escape the single quotes.
Not the outer ones, but those INSIDE related to your javascript.

SwapsRulez

Solved through spearfish's method. But it was my guess that's why i've done it myself. But havent done through oldies way, therefore dont know if its working or not ?

btw is this legal with google to hide the URL in such a way for guests ?
Project-BB.org : Educational Forum For Engineering, Diploma & Technical Students

The Engineering, Diploma & All technical students lounge for Free Projects, Seminars, Syllabus, Question Papers, College Assignments, Placement Papers, E-Books, Company Information & other technical stuffs.

spearfish

If anything it'll just piss of the people you're linking to.

Google spiders with no cookies.... so it just won't pick up on the links.

SwapsRulez

Project-BB.org : Educational Forum For Engineering, Diploma & Technical Students

The Engineering, Diploma & All technical students lounge for Free Projects, Seminars, Syllabus, Question Papers, College Assignments, Placement Papers, E-Books, Company Information & other technical stuffs.

karlbenson

As long as you don't treat spiders any differently to guests, there shouldn't be an issue.

SwapsRulez

Quote from: karlbenson on June 13, 2008, 09:39:02 PM
As long as you don't treat spiders any differently to guests, there shouldn't be an issue.

I'm not getting :(
Project-BB.org : Educational Forum For Engineering, Diploma & Technical Students

The Engineering, Diploma & All technical students lounge for Free Projects, Seminars, Syllabus, Question Papers, College Assignments, Placement Papers, E-Books, Company Information & other technical stuffs.

spearfish

Then you probably won't run into any problem :P

A large part of Google's formula for page rank is the number of links that a site receives from other sites.  You're fine as long as you don't put in any code that detects spiders and lets them see links when guests can't.... they might mistake you for a link farm (somebody who sells tons and tons of links on his site to other people to boost their page rank - usually these links aren't visible to users).

Advertisement: