Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: Un-published Articles & Pages displayed by link-to only  (Read 2845 times)

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Un-published Articles & Pages displayed by link-to only
« on: October 07, 2009, 10:06:11 pm »

This very simple mod came about when Patric Ahlqvist wanted to be able to insert a link into one article or page and have that link display an "Un-published" article or page.

By default, if you un-check the "Publish Now" check-box (in sNews 1.7) when publishing or editing an article or page, a link to it in any published content will not work (page not found error is returned) because the content is not meant to be available when it is "Un-published".

This took me some time to figure out because I had not become familiar with the way sNews 1.7 database queries work. Once I understood them, it was too easy. So... if you want to be able to use text-links in published content, that will lead to un-published content, follow me.

Search snews.php for: // Admin content
This section is what excludes "un-published" content from being displayed. It does this using three variables - $pub_a and $pub_c and $pub_x that determine what gets included within the Queries (to the articles table) that follow it. The comments I've included in this section (below) tell the story.

Code: [Select]
<?php

// Admin content
if (_ADMIN) { // IF ADMIN IS LOGGED IN AND VIEWING CONTENT
# VALUES FOR ALL 3 VARIABLES ARE EMPTY - INCLUDE NOTHING - ADMIN SEES ALL.
$pub_a ''$pub_c ''$pub_x '';
} else { # IF THE VIEWER IS NOT LOGGED (a visitor)
# NEXT STRING: ONLY PUBLISHED CONTENT (1) IS AVAILABLE.
$pub_a ' AND a.published = 1';
$pub_c ' AND c.published =\'YES\'';
$pub_x ' AND x.published =\'YES\'';
}

?>


The above block of code says:
If the Admin is logged in and viewing content, the values for all 3 variables (used in the queries that follow it) are empty (no conditions). Otherwise (for non-logged site visitors), all 3 have values (as noted), and the value for $pub_a causes the queries to only retrieve content that has a "published" value of "1" from the articles table.

Mod script updated: Oct.26.09: All we need to do is change the value for $pub_a so that it will allow both "published" (with a published value of "1")  and "un-published" (with a published value of "0") articles or pages to display when a text-link to it is clicked from within any other published article or page. Replacing the default section (above) with this one (below) does the trick (comments included for reference purposes):

Code: [Select]
<?php

// Admin content
 if (_ADMIN) {
                
$pub_a ''$pub_c ''$pub_x '';
} else {
        #MOD: Only Un-published (0) & published (1) contents are retrieved for admin-posted link connections.
$pub_a ' AND a.published IN (0,1)';
# DEFAULT - Only published content (1) is retrieved for admin-posted link connections.
// $pub_a = ' AND a.published = 1';
$pub_c ' AND c.published =\'YES\'';
$pub_x ' AND x.published =\'YES\'';
}

?>


IMPORTANT NOTE: Fellow Dude Joost pointed out that I had neglected to explain what happens when you use this mod... so here's the explanation. Search engines (like Google) will index your un-published articles and pages when you use links to them in published articles and pages... so... you do not want to put any information in them (like photos of naked people for example) that you do not want indexed and available to site visitors.

This change does not affect links in articles menus. When an article is set to "un-published", its text links are not visible in the articles menus. However, I discovered that text-links to pages in the pages menu still remain visible to non-logged visitors when a page is set to "un-published". We want these treated same as article menu links - not visible. Another small mod is required.

In function pages, search for - $qwr = !_ADMIN ? ' AND visible=\'YES\'' : ''; - it is the second string after the function starts, right under the global string. To exclude un-published page text-links from the pages menu, Replace it with:

Code: [Select]
<?php

# Patch: Excludes un-published page links from pages menu viewed by non-logged visitors.
$qwr = !_ADMIN ' AND visible=\'YES\' AND published = 1' '';

?>


NOTE: Un-published page links will still be visible in the pages menu to the Admin when logged in.
           (These minor mods were tested only in a localhost environment. Online testing yet to be done - will post a link here to the demo once ready.)
« Last Edit: October 28, 2009, 12:59:23 am by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: Un-published Articles & Pages displayed by link-to only
« Reply #1 on: October 14, 2009, 04:24:46 pm »

Tested online - OK.
Links to un-published articles and pages work fine. Test links are in the top of Article Five at Key's 1.7 vanilla demo.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
Re: Un-published Articles & Pages displayed by link-to only
« Reply #2 on: October 15, 2009, 04:56:57 pm »

Soooooo goodie, goodie, goodie ;) Like this enormously. Thanks Key's.
Logged
"It's only dead fish that goes with the flow... "
Updated

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
Re: Un-published Articles & Pages displayed by link-to only
« Reply #3 on: October 18, 2009, 10:08:53 am »

Insane'ly nice modification, Doug... Exactly, on the dot, precise... Just what I needed, many thanks, mate...
Logged
"It's only dead fish that goes with the flow... "
Updated

Rui Mendes

  • Development,Testing, Support
  • Hero Member
  • *****
  • Karma: 195
  • Posts: 1009
  • sNews1.7
    • Comunidade Portuguesa
Re: Un-published Articles & Pages displayed by link-to only
« Reply #4 on: October 04, 2010, 03:21:47 pm »

Hello dudes.

Doug I think is missing something in your demo:
You saw 4 articles in categories "Doug Cat One(4)", but user can see only 3 articles (Article Two,Article Three and Article Four)

I suspect you comment out this line
Quote
function categories() {
   global $categorySEF;
   $qwr = !_ADMIN ? ' AND a.visible=\'YES\'' : '';
...

Or need change code (red text)
Quote
if (s('num_categories') == 'on') {
      $count = ', COUNT(DISTINCT a.id) as total';
      $join = 'LEFT OUTER JOIN '._PRE.'articles'.' AS a
         ON (a.category = c.id AND a.position = 1  AND a.published IN (0,1)'.$qwr.')';
« Last Edit: October 04, 2010, 03:25:11 pm by Rui Mendes »
Logged
Need a Job on Europe. Linkdin - Facebook / Group

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: Un-published Articles & Pages displayed by link-to only
« Reply #5 on: October 04, 2010, 09:42:56 pm »

@ Rui...
I did not have pagination enabled... when it is not enabled in the SETTINGS => CONTENTS panel, you only see the first 3 articles even if there are more than 3 in the category. It appears to be OK now with pagination enabled.
$qwr = !_ADMIN ? ' AND a.visible=\'YES\'' : ''; is not disabled in function categories() and the query string is still a.published = 1
« Last Edit: October 04, 2010, 09:46:04 pm by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

roie

  • Newbie
  • *
  • Karma: 1
  • Posts: 32
Re: Un-published Articles & Pages displayed by link-to only
« Reply #6 on: October 15, 2010, 12:15:14 am »

thanks :) haven't been here for a while, nice to see sNews is still getting updates
Logged