Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 [2]

Author Topic: [MOD] Users only articles  (Read 11206 times)

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: [MOD] Users only articles
« Reply #15 on: January 24, 2011, 10:28:42 PM »

Thanks Keyrocks, I have found the problem. Using find and replace can get you into trouble sometimes!! I had put part of the code in the categories form function which has the same code in many places.

Glad you found it Alks....  :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

cashio

  • Newbie
  • *
  • Karma: 0
  • Posts: 2
Re: [MOD] Users only articles
« Reply #16 on: February 05, 2012, 01:15:15 AM »

Is it possible to hide from visitors links to users only articles from sidebar (new articles & comments), archives, site map and search, as well as links to pages in the menu, so as to be visible only after login?

How can this be done? Ready code, is more than a welcome  ;)
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: [MOD] Users only articles
« Reply #17 on: February 05, 2012, 04:26:49 PM »

Is it possible to hide from visitors links to users only articles from sidebar (new articles & comments), archives, site map and search, as well as links to pages in the menu, so as to be visible only after login? How can this be done? Ready code, is more than a welcome  ;)

Yes, and it is quite easy to do. This solution will apply for any sNews17MU package as well as a single-user package, though the only purpose of doing it with a single-user package would be to keep specific content visible only to the admins who have access through the one admin account.

In any index.php (template) file, which contains the function-tags to bring in the dynamic content generated by their respective functions, we just need to 'wrap' whatever we want visible only to logged-in users with a bit of PHP script to check and see if the person is logged in before showing it.

In the index.php file that comes with a default sNews package, must of the code in it is in HTML, and the PHP function-tags are wrapped (in between) opening & closing PHP tags so the PHP will be parsed by the server.

menu_articles(0,5); for example... in the index.php file is nested inside some HTML like this:
First, the title is contained in the HTML H3 tags, followed by the opening UL tag. Then, the opening PHP tag, followed by the function-tag (for the articles menu) followed by the closing PHP tag, and back to html with the closing UL tag.
Code: [Select]

<h3>New Posts</h3>
<ul>
<?php menu_articles(0,10); ?>
</ul>


So we want to wrap all of that with the PHP script we'll use to check whether or not the user is logged in. If the user is logged in, it will be visible and, if not, it will not be visible.

While we're at it, converting the HTML for this into PHP at the same time will eliminate the need to start and stop PHP several times.... so this block of script replaces the HTML parts as well, and the comments explain what does what:
Code: [Select]
<?php

// Session check - is the site visitor logged in?
if ($_SESSION[_SITE.'Logged_In']) {
// generate the block title and open the UL container
echo '<h3>New Posts</h3><ul>';
// function-tag generates the article posts menu
menu_articles(0,10);
// closes the UL container
echo '</ul>';
// Ends the session check

?>


This same check can be applied to any elements within the index.php file.

Other Content Display Options:
This same script could be used to limit access to any number of elements on the home page.

With a minor modification, we can also use to to display a separate splash page to non-logged site visitors, and only the fully-functioning home page to logged-in viewers. Here's an example:
Code: [Select]
<?php

// Session check - is the site visitor logged in?
if ($_SESSION[_SITE.'Logged_In']) {
// Put in here all content elements logged-in viewers should seethe block title and open the UL container

} else { // If not logged in,
// show the site visitor the customized splash page
splash_page(); // a function somewhere to generate custom splash page content
// Ends the session check

?>

« Last Edit: February 05, 2012, 06:28:04 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU
Pages: 1 [2]