Please login or register.

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

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

ad_267

  • Jr. Member
  • **
  • Karma: 7
  • Posts: 57
[MOD] Users only articles
« on: November 09, 2007, 08:58:17 AM »

This mod adds the option to make certain articles viewable by logged in users only. If someone is not logged in a message is displayed instead. This message is only displayed once in a category.

Backup first.

New database column required:
Code: [Select]
ALTER TABLE articles ADD COLUMN usersonly CHAR(3);
In language variables add:
Code: [Select]
// BEGIN MOD USERS ONLY
$l['no_access'] = '<p>Sorry, you need to be logged in as a registered member to access this page.</p>';
$l['usersonly'] = 'Only logged in users can acces this article';
// END MOD USERS ONLY

In function center

Under:
Code: [Select]
$link = '<a href="'.db('website');Add:
Code: [Select]
// BEGIN MOD USERS ONLY
$no_access_displayed = false;
// END MOD USERS ONLY

Under:
Code: [Select]
$infoline = $r['displayinfo'] == 'YES' ? true : false;Add:
Code: [Select]
// BEGIN MOD USERS ONLY
$usersonly = $r['usersonly'] == 'YES' ? true : false;
// END MOD USERS ONLY

Under:
Code: [Select]
$title = $r['title'];Add:
Code: [Select]
//BEGIN MOD USERS ONLY
if ($_SESSION[db('website').'Logged_In'] == token() || !$usersonly) {
//END MOD USERS ONLY

(changed by keyrocks) Under this next string, there are 2 closing curly-brackets (only the first one shown here):
Code: [Select]
## MULTI_USER
else if ($_SESSION[db('website').'Logged_In'] == token() && get_identity($_SESSION['id'], 'level') < '3') {echo '<p>'.$edit_link.'</p>';} // modded for MULTI_USER
## END MULTI_USER
}
(changed by keyrocks) After the first closing curly-bracket, add:
Code: [Select]
// BEGIN MOD USERS ONLY
} else {
if (!$no_access_displayed) { // else if (!$no_access_displayed) {
echo l('no_access');
$no_access_displayed = true;
}
}
// END MOD USERS ONLY

In function form_articles

Under:
Code: [Select]
$frm_allow_edit = $r['allow_edit'] == 'YES' ? 'ok' : '';Add:
Code: [Select]
// BEGIN MOD USERS ONLY
$frm_usersonly = $r['usersonly'] == 'YES' ? 'ok' : '';
// END MOD USERS ONLY

Under:
Code: [Select]
$frm_allow_edit = '';Add:
Code: [Select]
// BEGIN MOD USERS ONLY
$frm_usersonly = '';
// END MOD USERS ONLY

Under:
Code: [Select]
if ($contents != 'extra_new' && $edit_option != '2') {
echo html_input('text', 'description_meta', 'dm', $frm_meta_desc, l('description_meta'), '', '', '', '', '', '', '', '', '', '');
echo html_input('text', 'keywords_meta', 'km', $frm_meta_key, l('keywords_meta'), '', '', '', '', '', '', '', '', '', '');
Add:
Code: [Select]
// BEGIN MOD USERS ONLY
echo html_input('checkbox', 'usersonly', 'uo', 'YES', l('usersonly'), '', '', '', '', $frm_usersonly, '', '', '', '', '');
// END MOD USERS ONLY

In function processing

Under:
Code: [Select]
$allow_edit = $_POST['allow_edit'] == 'on' ? 'YES' : 'NO';Add:
Code: [Select]
//BEGIN MOD USERS ONLY
$usersonly = $_POST['usersonly'] == 'on' ? 'YES' : 'NO';
//END MOD USERS ONLY

Change:
Code: [Select]
mysql_query("INSERT INTO ".db('prefix')."articles(title, seftitle, text, date, category, position, displaytitle, displayinfo, commentable, published, description_meta, keywords_meta, author_id, allow_edit) VALUES('$title', '$seftitle', '$text', '$date', '$category', '$position', '$display_title', '$display_info', '$commentable', '$publish_article', '$description_meta', '$keywords_meta', '".$_SESSION['id']."', '$allow_edit')");To:
Code: [Select]
// MODIFIED BY MOD USERS ONLY
mysql_query("INSERT INTO ".db('prefix')."articles(title, seftitle, text, date, category, position, displaytitle, displayinfo, commentable, published, description_meta, keywords_meta, author_id, allow_edit, usersonly) VALUES('$title', '$seftitle', '$text', '$date', '$category', '$position', '$display_title', '$display_info', '$commentable', '$publish_article', '$description_meta', '$keywords_meta', '".$_SESSION['id']."', '$allow_edit', '$usersonly')");

Change:
Code: [Select]
mysql_query("UPDATE ".db('prefix')."articles SET title='$title', seftitle = '$seftitle', text = '$text',".$future." category = '$category', position = '$position', displaytitle = '$display_title', displayinfo = '$display_info', commentable = '$commentable', published = '$publish_article', description_meta = '$description_meta', keywords_meta = '$keywords_meta', allow_edit = '$allow_edit' WHERE id = '$id' LIMIT 1;");To:
Code: [Select]
// MODIFIED BY MOD USERS ONLY
mysql_query("UPDATE ".db('prefix')."articles SET title='$title', seftitle = '$seftitle', text = '$text',".$future." category = '$category', position = '$position', displaytitle = '$display_title', displayinfo = '$display_info', commentable = '$commentable', published = '$publish_article', description_meta = '$description_meta', keywords_meta = '$keywords_meta', allow_edit = '$allow_edit', usersonly = '$usersonly' WHERE id = '$id' LIMIT 1;");



« Last Edit: January 15, 2011, 06:58:24 PM by Keyrocks »
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: [MOD] Users only articles
« Reply #1 on: November 09, 2007, 03:22:18 PM »

Thanks for this one AD. Just when I think I have my revised MEMU package ready to upload... along comes another worthwhile mod to add in. I'll have to try this out today.  :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: [MOD] Users only articles
« Reply #2 on: November 09, 2007, 04:20:05 PM »

I hope you don't mind... I ran into a snag with this mod. It wouldn't run until I made a couple of minor patches as noted above in green.  ;)
It works fine with these changes.
« Last Edit: November 09, 2007, 05:14:15 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

ad_267

  • Jr. Member
  • **
  • Karma: 7
  • Posts: 57
Re: [MOD] Users only articles
« Reply #3 on: November 09, 2007, 08:42:12 PM »

No I don't mind at all. That was my fault, I missed them when I was copying my code into the post. Thanks Keyrocks

Edit: Actually I think I did copy it out how I had it, but it was working fine for me. Oh well never mind.

Edit again: I should really figure out what's going on before I post  reply. But yes I must have missed out some curly brackets in my post. I should have compared my modified version to the original to make sure I had everything right.

Yup I just missed out one curly bracket after

Code: [Select]
elseif (!$no_access_displayed) {
echo l('no_access');
$no_access_displayed = true;
}
from the original post

But your modification works just the same so doesn't matter  :)
« Last Edit: November 09, 2007, 08:59:47 PM by ad_267 »
Logged

crm

  • Newbie
  • *
  • Karma: 1
  • Posts: 26
    • planetmayfield.com
Re: [MOD] Users only articles
« Reply #4 on: January 17, 2008, 09:26:45 PM »

First I would like to say that this is an excellent mod.  I used it on my site until I move to KeyRocks MEMU mod that is Modular.  I have noticed in MEMU that he uses this mod and there seems to be a bug associated with it.  I have added to the sNews 1.6 MEMU thread, and I thought I would add it here too.

When using this mod it works great except when it is RSS.  Now I do not know much about the backend of RSS but I have found that when using this, all of the USER ONLY articles show up in the RSS Feeds for sNews.

Is there a work around for this?
Logged
Endlessly banging my head against the keyboard.

ad_267

  • Jr. Member
  • **
  • Karma: 7
  • Posts: 57
Re: [MOD] Users only articles
« Reply #5 on: February 15, 2008, 08:14:57 AM »

Hi crm,

Sorry I didn't even think about RSS when I was writing this mod as the website I wrote it for didn't use an RSS feed.

To get this to work you would probably need to modify the rss_contents function.

To get the user only articles to not show up at all in RSS you could modify this line in the rss_contents function:
Code: [Select]
$query = "articles WHERE position = 1 AND published = 1 ORDER BY date";and change it to:
Code: [Select]
$query = "articles WHERE position = 1 AND published = 1 and usersonly != 'YES' ORDER BY date";
To hide the article contents but show that there is a new article available you could try this:
Under
Code: [Select]
switch($rss_item) {

case 'rss-articles':

case 'rss-pages':

$date = date('D, d M Y H:i:s +0000', strtotime($r['date']));
You could add:
Code: [Select]
$usersonly = $r['usersonly'] == 'YES' ? true : false;
Then change this line (which is only a few lines below):
Code: [Select]
$text = $r['text'];To this:
Code: [Select]
$text = $usersonly ? l('usersonly') : $r['text'];
I haven't tested this so I'm not 100% sure it'll work correctly but I think this should do what you want.
This doesn't affect what comments are displayed in the rss-comments feed, and if you want to change that it might require a bit more work.
Logged

crm

  • Newbie
  • *
  • Karma: 1
  • Posts: 26
    • planetmayfield.com
Re: [MOD] Users only articles
« Reply #6 on: February 15, 2008, 08:12:38 PM »

I haven't tested this so I'm not 100% sure it'll work correctly but I think this should do what you want.
This doesn't affect what comments are displayed in the rss-comments feed, and if you want to change that it might require a bit more work.

Awesome, thanks ad_s67!  I have not had a chance to revisit this.  Hopefully I will have some time over the weekend and report my results back here.  I will be looking at the comments as well.
Logged
Endlessly banging my head against the keyboard.

ad_267

  • Jr. Member
  • **
  • Karma: 7
  • Posts: 57
Re: [MOD] Users only articles
« Reply #7 on: February 16, 2008, 12:16:55 AM »

To change the comments you could try changing
Code: [Select]
$query = "comments WHERE approved = 'True' $articleId ORDER BY id"; in function rss_contents

To:
Code: [Select]
$query = "comments WHERE approved = 'True' $articleId AND articleid IN (SELECT id FROM articles WHERE usersonly != 'YES') ORDER BY id";
This should just not show any comments from user only articles.
But again I haven't tested this and I haven't done any work before with the RSS functions so I'm not sure about exactly how they work
Logged

azad

  • Newbie
  • *
  • Karma: 0
  • Posts: 21
Re: [MOD] Users only articles
« Reply #8 on: April 03, 2008, 09:01:52 AM »

Hi ad_267

i have a test site on sNews i wanna functionality like your MOD, but i don't wanna Users only articles, i just want a user specific article MOD.

where one user can't view other user articles, only Administrator can view all user' articles.

can u write or edit your this beautiful MOD for me, may be you just put some line of cod in your mode for my requirement.

It's not easy for me without you and other sNews's friends.

i am newbie in CMS and PHP, i have too many tasks in a day.

thank you
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: [MOD] Users only articles
« Reply #9 on: June 18, 2008, 10:51:33 PM »

@ azad...
I do not have an answer for your request at this time... but I have adapted this Mod so that it now makes Category titles and text-links to articles invisible to viewers who are not logged in (visible only to logged-in users) for sNews 1.6MU. It was not too difficult to adapt and works very well... which means it is no longer necessary to have a "no access" message displaying through the center() function.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

azad

  • Newbie
  • *
  • Karma: 0
  • Posts: 21
Re: [MOD] Users only articles
« Reply #10 on: August 12, 2008, 10:46:23 AM »

@ azad...
I do not have an answer for your request at this time... but I have adapted this Mod so that it now makes Category titles and text-links to articles invisible to viewers who are not logged in (visible only to logged-in users) for sNews 1.6MU. It was not too difficult to adapt and works very well... which means it is no longer necessary to have a "no access" message displaying through the center() function.

thanks Key rock
Logged

cyberderf

  • Newbie
  • *
  • Karma: -2
  • Posts: 36
Re: [MOD] Users only articles
« Reply #11 on: February 09, 2009, 06:55:29 AM »

Great mod!!!!!

How can this be adapted so 1.7 version ?
Logged

alks

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 53
Re: [MOD] Users only articles
« Reply #12 on: January 24, 2011, 12:27:41 PM »

I have implemented this mod and it works well,

Just a quicky... it seams that every time you edit a user page / article you have to select the tick box from the customize menu 'Only logged in users can access this article'  to protect it. Is there a way to make it so that once ticked it remains selected until you de-select that option? (like the other options do?)

thanks,
Logged

Keyrocks

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

it seams that every time you edit a user page / article you have to select the tick box from the customize menu 'Only logged in users can access this article'  to protect it. Is there a way to make it so that once ticked it remains selected until you de-select that option? (like the other options do?)

If you have followed all of the instructions in the lead post you should not have this problem. If the check-box was checked when an article was created, then the useronly value for that article (in the articles table of your d-base) will be YES. If it is YES, then the check-box should be checked when you have the article up in the Edit panel. and, as long as you leave it checked, the value will again be saved as YES.

The string that brings the YES value in is $frm_usersonly = $r['usersonly'] == 'YES' ? 'ok' : '';
.... and it should be located in the // ARTICLES FORM function (in snewsMU.php)
.... just under the $frm_allow_edit = $r['allow_edit'] == 'YES' ? 'ok' : ''; string.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

alks

  • Jr. Member
  • **
  • Karma: 0
  • Posts: 53
Re: [MOD] Users only articles
« Reply #14 on: January 24, 2011, 09:08:25 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.
Logged
Pages: [1] 2