vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   How to create your own vBulletin-powered page! (uses vB templates) (https://vborg.vbsupport.ru/showthread.php?t=62164)

Micaiah 05-13-2010 05:33 PM

Is there a way to block custom pages like these from guests being able to view them unless they log in? with having the link to the pages in the navbar as well?

Simon Lloyd 05-14-2010 01:53 PM

Quote:

Originally Posted by Micaiah (Post 2036513)
Is there a way to block custom pages like these from guests being able to view them unless they log in? with having the link to the pages in the navbar as well?

Just use an if condition in the template like this:
HTML Code:

<if condition="$show['member']">
ALL YOUR CONTENT HERE
<else />
<tr>
<td>
<h2>You need to be registered or logged in to view this page</h2>
</td>
</tr>
</if>


cellarius 05-14-2010 02:17 PM

It's not a good idea to do this on the template level. Just add this at the top of your custom code in the php file:
PHP Code:

    if (!$vbulletin->userinfo['userid'])
    {
        
print_no_permission();
        exit();
    } 


Micaiah 05-14-2010 10:04 PM

ahh excellent thank you very much ^_^

Simon Lloyd 05-16-2010 06:52 AM

Quote:

Originally Posted by cellarius (Post 2036947)
It's not a good idea to do this on the template level. Just add this at the top of your custom code in the php file:
PHP Code:

    if (!$vbulletin->userinfo['userid'])
    {
        
print_no_permission();
        exit();
    } 


Cellarius, why is it not a good idea to manage it at template level?, doing it with a template conditional means that it's easily manipulated later by admins...etc rather than having to access server files, unless i'm missing a security flaw or something?

cellarius 05-16-2010 07:11 AM

First and foremost: Performance. Why run the whole file, go through the whole variable/template registering and rendering process etc. just to show nothing in the end?

Next, you break UI consistency by not using the usual way of handling such errors: You need to code your error message yourself instead of using the standard no permissions message, which is phrased and thus works with multi language environments.

Last, but not least: There is a standard procedure in vB to do this, and that's the way I did it. Just look at the original files. And if there is a standard way, it should be used.

Anyway, I really don't follow your argumentation - how often do your Admins need to change which usergroups get access to a custom page? This does not seem like a weekly operation to me, does it? This is a set it and forget it decision, is it not?

Arsov14 05-16-2010 07:37 AM

Dont work for me :(
http://pic.mk/images/untitl1273999606.jpg

cellarius 05-16-2010 08:07 AM

Your php code does not get parsed. Make sure your file has the .php extension and starts with <?php.

Simon Lloyd 05-16-2010 08:41 AM

Quote:

Originally Posted by cellarius (Post 2037763)
First and foremost: Performance. Why run the whole file, go through the whole variable/template registering and rendering process etc. just to show nothing in the end?

Next, you break UI consistency by not using the usual way of handling such errors: You need to code your error message yourself instead of using the standard no permissions message, which is phrased and thus works with multi language environments.

Last, but not least: There is a standard procedure in vB to do this, and that's the way I did it. Just look at the original files. And if there is a standard way, it should be used.

Anyway, I really don't follow your argumentation - how often do your Admins need to change which usergroups get access to a custom page? This does not seem like a weekly operation to me, does it? This is a set it and forget it decision, is it not?

Cellarius, don't get me wrong, i'm no coder by any means, it's just thats the way i have always (not too many times) done it. As for the whole admin's....etc changing things, i was purely talking from ease of operation for myself, i have used a similar conditional to allow certain usergroups to view some content, then when i have added usergroups it made it ease for me to find and change. I wasn't questioning your method & capability, just asking for information as to why, now that i know i would implement that, but it does make it difficult for adding or removing usergroups access.

--------------- Added [DATE]1274003452[/DATE] at [TIME]1274003452[/TIME] ---------------

Could it be incorporated in a pluggin where you can state which templates cannot be accessed?

Could you also tell me how to do this in a php statement?
<if condition="is_member_of($vbulletin->userinfo, array(1, 2, 3))">.

cellarius 05-16-2010 08:51 AM

Quote:

Originally Posted by Simon Lloyd (Post 2037801)
Cellarius, don't get me wrong, i'm no coder by any means, it's just thats the way i have always (not too many times) done it.

Of course you are free to do so if you prefer that method, I just don't think it should be recommended, as it just is not how it is done in vB and does have drawbacks.
Quote:

As for the whole admin's....etc changing things, i was purely talking from ease of operation for myself, i have used a similar conditional to allow certain usergroups to view some content, then when i have added usergroups it made it ease for me to find and change.
Then it would be still better to add an AdminCP setting where you can add/change those usergroups easily. You still would have to remember to do it, and a code fragment at the top of a php file seems not harder to find than a conditional in a template, IMHO.
Quote:

I wasn't questioning your method & capability,
I did not take it that way. :)
Quote:

just asking for information as to why, now that i know i would implement that, but it does make it difficult for adding or removing usergroups access.
As I said: Not really. Opening a php file and changing the code there is not really harder than editing a template. If you don't want to do that, set up an AdminCP setting for it. That would probably be the most comfortable way.


All times are GMT. The time now is 08:42 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02436 seconds
  • Memory Usage 1,757KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_html_printable
  • (2)bbcode_php_printable
  • (7)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (4)pagenav_pagelinkrel
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete