Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's
Author Message
Raven
Site Admin/Owner


Joined: Aug 27, 2002
Posts: 17086

PostPosted: Sat Sep 18, 2004 11:19 pm Reply with quote

A while back I wrote this little script to allow certain topics to be read by registered users only. Let me know if it still works Wink
Code:
<?

/**************************************************************************/
/* Place this file in your includes folder.                               */
/* This will restrict the selected topics to registered users.            */
/*                                                                        */
/* Assign Topic ID's to be restricted by adding this code for each Topic. */
/* As in                                                                  */
/*    $restrictedTopics[] = 1;                                            */
/*    $restrictedTopics[] = 5;                                            */
/* The above 2 lines would restrict topic 1 and 5.                        */
/* Next, add a case() statement for each blocked topic, or let them all   */
/* default to $hometext.  That way you can assign a separate Text Message */
/* for each blocked Topic.                                                */
/*                                                                        */
/* Next, dependent on what version of nuke you are using, you will add    */
/* this line:                                                             */
/*   include("includes/restrictedTopics.php");                            */
/* to modules/News/index.php and modules/News/article.php                 */
/*                                                                        */
/* In index.php, find these lines (around line 91):                       */
/*       $notes = stripslashes($notes);                                    */
/*       $introcount = strlen($hometext);                                  */
/* and change them to:                                                    */
/*       $notes = stripslashes($notes);                                    */
/*      include("includes/restrictedTopics.php");                         */
/*       $introcount = strlen($hometext);                                */
/*                                                                        */
/* Likewise, in article.php find these lines (around line 60):            */
/*       $ratings = $row[ratings];                                        */
/*       if ($aid == "") {                                                */
/* and change them to:                                                    */
/*       $ratings = $row[ratings];                                        */
/*       include("includes/restrictedTopics.php");                        */
/*       if ($aid == "") {                                                */
/*                                                                        */
/* That should do it!                                                     */
/**************************************************************************/

$restrictedTopics[] = 1;
if (!is_admin($admin) AND !is_user($user) AND in_array($topic,$restrictedTopics)) {
   switch($topic) {
      case (1):
         $hometext = 'Only registered users may view this story.';
      break;

      default:
         $hometext = 'Only registered users may view this story.';
      break;
   }
   $notes = '';
   $bodytext = '';
   $articlecomm = -1;
   $fullcount = -1;
   $acomm = -1;
   $c_count = -1;
}
?>
 
View user's profile Send private message
spcdata
Regular
Regular


Joined: Jan 24, 2004
Posts: 81
Location: Sweden

PostPosted: Sun Sep 19, 2004 9:11 am Reply with quote

Hi Raven!

I have tested this on nuke 7.5 and it works just fine Wink

It's a good one Exclamation

_________________
/spcdata 
View user's profile Send private message Send e-mail Visit poster's website
spcdata
PostPosted: Sun Sep 19, 2004 9:53 am Reply with quote

I forget...there is a litle change in news/index.php

Look like this now:

Code:
$notes = stripslashes($row['notes']);

    include("includes/restrictedTopics.php");
        $acomm = intval($row['acomm']);
        $score = intval($row['score']);
        $ratings = intval($row['ratings']);
        if ($catid > 0) {
            $row2 = $db->sql_fetchrow($db->sql_query("SELECT title FROM ".$prefix."_stories_cat WHERE catid='$catid'"));
            $cattitle = stripslashes(check_html($row2['title'], "nohtml"));
        }
        getTopics($s_sid);
        formatTimestamp($time);
        $subject = stripslashes(check_html($subject, "nohtml"));
        $introcount = strlen($hometext);


But it does not matter i you put it after "$notes" or directly above "$introcount"
 
Raven
PostPosted: Sun Sep 19, 2004 10:00 am Reply with quote

Great! Thanks!
 
bfnuke
Hangin' Around


Joined: Feb 01, 2006
Posts: 43

PostPosted: Fri Feb 10, 2006 1:20 pm Reply with quote

this would be perfect for what I want to do to restrict topics. I just tested on the 7.6 distro, but it doesnt' seem to work. Maybe I put it in the wrong place.. Raven, can you check to see if it still works Wink
 
View user's profile Send private message
Raven
PostPosted: Mon Feb 13, 2006 10:27 pm Reply with quote

I tested it and it works perfectly Smile
 
dingfelder
Hangin' Around


Joined: Jan 18, 2005
Posts: 45
Location: New Zealand

PostPosted: Sat Mar 25, 2006 2:39 am Reply with quote

can this be made to work with specific user groups instead of just registered users?
 
View user's profile Send private message Visit poster's website
Raven
PostPosted: Sat Mar 25, 2006 5:14 am Reply with quote

Probably. You'd have to read the groups table and match that back to the users.
 
mercman
Regular
Regular


Joined: Nov 29, 2006
Posts: 64
Location: TN, USA

PostPosted: Sat Apr 12, 2008 9:54 am Reply with quote

Hi all!
Does anyone know if this has been updated for use with the new v2.20.x distro?
I'd love to be able to set news articles for viewing by my registered users only.

_________________
-Merc 
View user's profile Send private message Visit poster's website
Raven
PostPosted: Sat Apr 12, 2008 2:36 pm Reply with quote

This was never a part of any distro, so the answer is no. If you're after an all or nothing approach, you could just make a generic module to show in Home and add a link to your News module for registered users only.
 
mercman
PostPosted: Sat Apr 12, 2008 2:39 pm Reply with quote

Raven,
Thanks for the reply!

Making a generic module is just a "leeetle bit" beyond me at this point. worship
 
Raven
PostPosted: Sat Apr 12, 2008 3:01 pm Reply with quote

It could be any module. In other words, place one of your other modules in Home via the Administrator Control Panel and allow all to view it. The make your News module visible in Modules block and set the Who Can View to Registered Users Only.


Last edited by Raven on Sat Apr 12, 2008 5:12 pm; edited 1 time in total 
mercman
PostPosted: Sat Apr 12, 2008 3:34 pm Reply with quote

Hmm... interesting idea.
I'll have to try it on my beta site.
Thanks!
 
mercman
PostPosted: Sun Apr 13, 2008 7:09 pm Reply with quote

Raven,
You are a genius!! worship
Thank you for pointing me in the right direction.

First, I created a module with a simple vertical marquee message.
This worked fine, but I already had a "Anonymous Users Only" block for this message and I got tired of looking at it, and figured my members would as well.

Idea Then comes this bright idea Idea

What about an empty module??
If it worked, I could keep my message blocks in place (the one indicated above for Anonymous Users Only and the one for Registered Users Only), remove the News module from Home and restrict it, place the 'empty' module in Home and the changes would otherwise be transparent!!!
So I created my index.php using this code:

Code:


<?php

if (!defined('MODULE_FILE')) die('You can\'t access this file directly...');
define('INDEX_FILE', true);
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
include("header.php");
$index = 0;
include("footer.php");

?>

Dropped the index.php into a folder named "Front Door", dropped the folder into my nukeroot/modules folder, went into the admin menu and activated the 'Front Door' module and put it into Home, and finally set the News module to Restricted Users Only.


Works Like A Charm!
I've not seen a single error in any theme, and no empty tables on the Home page!!

See it Only registered users can see links on this board! Get registered or login!
 
Raven
PostPosted: Sun Apr 13, 2008 8:17 pm Reply with quote

Very nice! Cheers

Image
 
montego
Site Admin


Joined: Aug 29, 2004
Posts: 9456
Location: Arizona

PostPosted: Sun Apr 13, 2008 9:08 pm Reply with quote

This is funny because I just committed a change this weekend for the upcoming 2.3.0 release of RavenNuke(tm) to allow index.php to take module permissions into account even when they are in home. So, you could still set News as your Home module, but set it as Registered Users Only (there is a slight trick to doing that, but since 2.3.0 isn't due out for awhile, why divulge now - lol). Anonymous users would then not see the main module content (i.e., News) until they logged in.

_________________
Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! 
View user's profile Send private message Visit poster's website
mercman
PostPosted: Mon Apr 14, 2008 11:34 am Reply with quote

Very Happy
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> How To's

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©