Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [MOD] Additional Article Position Options 2.0 for sNews 1.6  (Read 7957 times)

Dom

  • Full Member
  • ***
  • Karma: 5
  • Posts: 166
    • domdelimar.com

Revision: 22 July 2007 (added a link to downloadable, already modified snews.php files)

Mod version: 2.0.0
For sNews version 1.6.0
Example: leading text on this page is the content of additional article position which can be accomplished with this mod.

It all started with keyrocks' post about creating a new article position in sNews 1.4 which you could then use for really anything - as keyrocks points out: "to list several product containers in one specific Category's page(s)... say Products... as sort of a lite e-commerce option"
Or any other extra content for a specific category or page, like for example a category description above the list of articles (like I use it on the above example page) or a small square box with a short announcement somewhere on top of your page...

Encouraged with a success in 1.4 I thought it couldn't be that hard to pull this off in 1.5.
And it took me awhile before I figured out how some things worked in 1.5 and I think it was worth the trouble as I did figure out (I think ;)) how some things work, eventually, and I even learned many new PHP functions :D
Also, I think I have finally learned to place ";" at the end of each PHP line... :P

And now I had to update this mod for the newest version of sNews, sNews 1.6.0.

In making of this mod I went down this route:
I had an intention to use the extra() function as a template for any subsequent article position I'd like to have on my website because while default extra content in sNews is really useful, I could only add it in one place on my website layout. And I needed different extra contents to be on different places in my website's layout and that was only possible by duplicating sNews default extra function to make a new extra function.

Note that these are really short step-by-step instructions of everything you need to change in your snews.php to get a new article position. You can even download the snews.php file taken from the fresh install of the sNews 1.6 (dev. ver. 1.6.0 Stable) and already modified to include this mod from domdelimar.com if you don't want to follow these instructions.

Here, changes are always shown in blue color.
Unless otherwise noted, all the work is done in your snews.php file. There is no need to modify the MySQL database.
I don't guarantee anything so make sure you BACKUP your website just in case...

OK, shall we?

Find the extra function [search for: function extra], and right below that function paste this code:
Quote
function second_extra($styleit = 0, $classname = '', $idname= '') {
   $categorySEF = get_id('category');
   $categoryId = (check_category($categorySEF) == true || empty($categorySEF) || $categorySEF == l('home_sef')) ? 0 : retrieve('id', 'categories', 'seftitle', $categorySEF);
   $pageSEF = get_id('article');
   $pageId = (empty($categorySEF)) ? 0 : retrieve('id', 'articles', 'seftitle', $pageSEF);
   $query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) = '9' AND published = 1 ORDER BY id DESC";
   $result = mysql_query($query);
   while ($r = mysql_fetch_array($result)) {
      $pos = $r['position']; $pos_depend = substr($pos, 1, 1); $pos_artID = substr($pos, 2);
      switch (true) {
         case ($pos_depend == 0 && $categoryId == 0): $print = true; break;
         case ($pos_depend == 1 && $categoryId == $pos_artID): $print = true; break;
         case ($pos_depend == 2 && $pageId == $pos_artID): $print = true; $category = -1; break;
         case ($pos_depend != '2' && $r['category'] == -1): $print = true; break; default: $print = false;
      }
      if ($print == true) {
         if ($styleit == 1) {
            $container ='<div';
            $container .= !empty($classname) ? ' class="'.$classname.'"' : '';
            $container .= !empty($idname) ? ' id="'.$idname.'"' : '';
            $container .= '>';
            echo $container;
         }
         echo $r['displaytitle'] == 'YES' ? '<h3>'.$r['title'].'</h3>' : '';
         file_include($r['text'], 9999000);
         echo $_SESSION[db('website').'Logged_In'] == token() ? '<p><a href="'.db('website').'index.php?action=admin_article&id='.$r['id'].'" title="'.l('edit').' '.$r['seftitle'].'">'.l('edit').'</a></p>' : '';
         if ($styleit == 1) {echo '</div>';}
}}}
This is actually a copy of the function extra with minor changes shown in blue color.

Short explanation: after you apply this mod and every time you create a Second Extra Content, it will be denoted with a position field value (in MySQL database) starting with number 9. In default sNews 1.6 there are three positions: position field with value of 1 denotes an article, position field with a value of 3 denotes a page and a position field with a value which starts with number 2 denotes an extra content.

Now, let's add some admin language variables that we'll need later:
Search for: #SYSTEM VARIABLES
And just a line above the #SYSTEM VARIABLES, add these three admin language variables, like this:
Quote
    $l['second_extra_contents'] = 'Second Extra contents';
    $l['second_extra_new'] = 'New Second Extra Contents';
    $l['second_side'] = 'Second Extra contents';

   
    #SYSTEM VARIABLES (not to be translated)
We're not over yet with the language variables...
Just two lines below  #SYSTEM VARIABLES, you'll notice a long line that starts with:
Quote
$l['cat_listSEF'] =
We need to add the following 2 new values at the end of that long array of variables:
Quote
second_extra_new and
second_extra_contents
If you didn't tamper with this line before, you can just replace it completely with this one: (I had to break this line into 3 lines so it wouldn't break the layout of this forum page and you should put it back together once you paste it in your snews.php file)
Quote
$l['cat_listSEF'] = $l['home_sef'].',archive,contact,sitemap,rss-articles,rss-pages,rss-comments,
login,administration,admin_category,admin_article,article_new,extra_new,page_new,categories,
articles,extra_contents,pages,settings,files,logout,second_extra_new,second_extra_contents'; //SEF links of the hardcoded categories
Now we need to change the function center().
Search for function center().
In center function find this line:
Quote
case 'extra_contents': admin_articles('extra_view'); return; break;
Right below this line add the following:
Quote
case 'second_extra_contents': admin_articles('second_extra_view'); return; break;
Just a few lines below, you'll see this line:
Quote
case 'extra_new': form_articles('extra_new'); return; break;
Now, below this line add the following line:
Quote
case 'second_extra_new': form_articles('second_extra_new'); return; break;
Then, several lines below, you'll find this line that says:
Quote
$query_articles = "SELECT * FROM ".db('prefix')."articles WHERE published = 1 AND SUBSTRING(position, 1, 1) != '2'";
We need to extend this line a bit to look like this:
Quote
$query_articles = "SELECT * FROM ".db('prefix')."articles WHERE published = 1 AND SUBSTRING(position, 1, 1) != '2' AND SUBSTRING(position, 1, 1) != '9'";
That's all we need to do with the center function.

Next thing you do, locate function search(). Once you locate it, several lines inside from the start of this function, you'll find this line:
Quote
$query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) != '2' AND published = 1 AND";
We need to modify this line to look like this:
Quote
$query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) != '2' AND SUBSTRING(position, 1, 1) != '9' AND published = 1 AND";
Now search for: function stats($field, $position)
This function starts with:
Quote
if (!empty($position)) {$pos = $position == 2 ? " WHERE ...
Well, it needs to start like this (I really wasn't sure about this but it worked at the end so I might have not done a bad job modifying this function):
Quote
if (!empty($position)) {$pos = $position == (2 || 9) ? " WHERE ...
Can you see the difference? - change it accordingly.

Now search for function administration()
In this function locate the following line:
Quote
if (stats('articles',2) > 0) {echo $link.'extra_contents/" title="'.l('view').'">'.l('view').'</a>';}
Now, right after this line, add this chunk of code:
Quote
echo '</p>';
      echo '<p>'.l('second_extra_contents').': <a href="second_extra_new/" title="'.l('add_new').'">'.l('add_new').'</a>';
      if (stats('articles',9) > 0) {echo $link.'second_extra_contents/" title="'.l('view').'">'.l('view').'</a>';}
Next thing you do is search for the function form_articles($contents). In this function we'll do the most of our modifying...

First find the part of the code that starts with switch ($edit_option). It looks like this:
Quote
switch ($edit_option) {
                case 1: $frm_fieldset = l('edit').' '.l('article'); $frm_position1 = 'selected="selected"'; break;
                case 2: $frm_fieldset = l('edit').' '.l('extra_contents'); $frm_position2 = 'selected="selected"'; break;
                case 3: $frm_fieldset = l('edit').' '.l('page'); $frm_position3 = 'selected="selected"'; break;
            }
Just after the case 3: line, insert this line of code:
Quote
case 9: $frm_fieldset = l('edit').' '.l('second_extra_contents'); $frm_position9 = 'selected="selected"'; break;
There's another switch several lines below, which starts with switch ($contents). Similarly to the last switch, we'll add one more case line:
Quote
    case 'second_extra_new': $frm_fieldset = l('second_extra_new'); $pos = 9; $frm_position9 = 'selected="selected"'; break;
Just nine lines below this switch statement, there's another line we need to modify...
Quote
$frm_display_info = ($contents == 'extra_new') ? '' : 'ok';
... to look like this:
Quote
$frm_display_info = ($contents == 'extra_new' || $contents == 'second_extra_new') ? '' : 'ok';
Two lines below, a very similar thing. This is the line:
Quote
$frm_commentable = ($contents == 'extra_new' || $contents == 'page_new') ? '' : 'ok';
And it needs to be modified so it looks like this:
Quote
$frm_commentable = ($contents == 'extra_new' || $contents == 'second_extra_new' || $contents == 'page_new') ? '' : 'ok';
If you scroll a bit more down, you'll notice this chunk of code:
Quote
if ($contents == 'extra_new' || $edit_option == 2) {
            echo '<div style="display: none;">';
            html_input('text', 'seftitle', 'as', $frm_sef_title, l('sef_title'), '', '', '', '', '', '', '', '', '', '');
            echo '</div>';
        }
You need to change the first line of this chunk of code to this:
Quote
if ($contents == 'extra_new' || $edit_option == 2 || $contents == 'second_extra_new' || $edit_option == 9) {
Next, find this part of the code a little bit further below:
Quote
if ($contents != 'page_new' && $edit_option != 3) {
Two lines below, you'll find this line:
Quote
echo ($contents == 'extra_new' || $edit_option == 2) ?  l('appear_category') : l('category');
which needs to be changed into this:
Quote
echo ($contents == 'extra_new' || $edit_option == 2 || $contents == 'second_extra_new' || $edit_option == 9) ?  l('appear_category') : l('category');
Two lines below, almost the same thing. The line which starts with
Quote
if ($contents == 'extra_new' || $edit_option == 2) {echo '<option value="-1"'
needs to be changed into:
Quote
if ($contents == 'extra_new' || $edit_option == 2 || $contents == 'second_extra_new' || $edit_option == 9) {echo '<option value="-1"'.($article_category == -1 ? ' selected="selected"' : '').'>'.l('all').'</option>';}
The line after that one also needs to be changed. It's a line that starts with:
Quote
echo '<option value="0"'.(($article_category == 0 && $contents != 'extra_new') ?
and it needs to be modified like this:
Quote
echo '<option value="0"'.(($article_category == 0 && $contents != 'extra_new' && $contents != 'second_extra_new') ? ' selected="selected"' : '').'>'.l('home').'</option>';
Now, several lines below, there's another if statement. It starts like this:
Quote
if ($contents == 'extra_new' || $edit_option == 2) {
                echo '<p id="def_page"><label for="dp">'.l('appear_page').':</label>
<select name="define_page" id="dp">';
First line of that if statement needs to be changed to this:
Quote
if ($contents == 'extra_new' || $edit_option == 2 || $contents == 'second_extra_new' || $edit_option == 9) {
Third line of the same if statement,
Quote
echo '<option value="0"'.($edit_option != '2' ? ' selected="selected"' : '').'>'.l('all').'</option>';
needs to look like this now:
Quote
echo '<option value="0"'.($edit_option != '2' && $edit_option != '9' ? ' selected="selected"' : '').'>'.l('all').'</option>';
Oh my... just a little more... and we're done!

If you scroll down just a little bit more you'll notice this chunk of code:
Quote
if (!empty($id)) {
      echo '<p><label for="pos">'.l('position').':</label>
<select name="position" id="pos">';
      echo '<option value="1"'.$frm_position1.'>'.l('center').'</option>';
      echo '<option value="2"'.$frm_position2.'>'.l('side').'</option>';
      echo '<option value="3"'.$frm_position3.'>'.l('display_page').'</option>';
      echo '</select></p>';
   }
After the line starting with
Quote
echo '<option value="3"
insert the following line of code:
Quote
echo '<option value="9"'.$frm_position9.'>'.l('second_side').'</option>';
Then just a few lines below you'll notice one if statement:
Quote
if ($contents != 'extra_new' && $edit_option != '2') {
            echo html_input('text', ...
You need to change only the first line of it into this:
Quote
if ($contents != 'extra_new' && $edit_option != '2' && $contents != 'second_extra_new' && $edit_option != '9') {
Hmm, after this one, there's another one:
Quote
if ($contents != 'extra_new' && $edit_option != '2') {
            echo html_input('checkbox', ...
Again, change just the first line of it into this:
Quote
if ($contents != 'extra_new' && $edit_option != '2' && $contents != 'second_extra_new' && $edit_option != '9') {
Finally, we're done with this function. Sorry, not yet with the whole script - just 6 more little changes... smile

Search for: function admin_articles($contents)
You see the switch ($contents) { line there followed by 3 case lines?
You just need to add the fourth case line (after the third one):
Quote
case 'second_extra_view': $title = l('second_extra_contents'); $subquery = "WHERE SUBSTRING(position,1,1) = '9'"; break;
Now we need to fiddle with function processing()...
First, inside the function processing(), we find a line of code that says:
Quote
if ($position == 2) {$position = $_POST['cat_dependant'] == 'on' ? 21 : 2;}
And after this line of code, we insert this one:
Quote
elseif ($position == 9) {$position = $_POST['cat_dependant'] == 'on' ? 91 : 9;}
Now search for case 'admin_article' inside function processing()
This is the code you should see:
Quote
case 'admin_article';
                if (substr($position, 0, 1) == 2) {
                    $category = $_POST['define_category'];
                    $page = $_POST['define_page'];
                    if ($category != -1) {$position = '21'.$category;}
                    else if ($page != 0) {$position = '22'.$page; $category = -1;}
                }
Immediately after this code insert the following snippet of the code:
Quote
elseif (substr($position, 0, 1) == 9) {
                    $category = $_POST['define_category'];
                    $page = $_POST['define_page'];
                    if ($category != -1) {$position = '91'.$category;}
                    else if ($page != 0) {$position = '92'.$page; $category = -1;}
                }
Finally, just a little bit further below you will find the LAST part of snews.php file that we need to change. Whooaa!!
It's this code:
Quote
$pos = substr($position, 0, 1);
      switch ($pos) {case 1: $link = 'articles'; break; case 2: $link = 'extra_contents'; break; case 3: $link = 'pages'; break;}
The line starting with switch ($pos) needs to be changed into the following:
Quote
switch ($pos) {case 1: $link = 'articles/'; break; case 2: $link = 'extra_contents/'; break; case 3: $link = 'pages/'; break; case 9: $link = 'second_extra_contents/'; break;}
All that is left to do now is decide where you'd want this new extra content to be shown on your website.
For example, I put mine right above the center function call (in index.php):
Quote
<div id="left">
                <? second_extra(); ?>
                <? center(); ?>
            </div>
But you can place yours anywhere else.

Log into your Admin area and there should be something new under Extra contents:
Second Extra Content or whatever you called it. Try adding a new Second Extra Content now!

Please report here if anything seems out of place or not working. I think I've tested it enough to say it should work fine now.
« Last Edit: August 29, 2007, 03:39:11 PM by Dom »
Logged

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 955
[MOD] Additional Article Position Options 2.0 for sNews 1.6
« Reply #1 on: July 22, 2007, 09:17:34 PM »

Wow ... this one isn't for faint-hearted people, is it Dom ;)

Anyway, instructive write-up, will be handy, thanx  :D
Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4957
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
[MOD] Additional Article Position Options 2.0 for sNews 1.6
« Reply #2 on: July 23, 2007, 12:07:41 PM »

Whuhaaaaaaa, DOM !!! Long time no see. Welcome back (or have you just been lurking the forums for a while), it's nice to see you again. Quite a MOD. I've been waiting for this one. Thanks, mo'n.
Logged
My sNews site
"It's only dead fish that goes with the flow... "
Updated, online again - Free designs

Dom

  • Full Member
  • ***
  • Karma: 5
  • Posts: 166
    • domdelimar.com
[MOD] Additional Article Position Options 2.0 for sNews 1.6
« Reply #3 on: July 24, 2007, 10:30:14 AM »

Thank you guys

Unfortunately busy summer this year keeps me form even lurking the forums but I set my mind to change that in the future because I miss this community a lot...
Logged

Keyrocks

  • Doug
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 451
  • Posts: 6230
  • Semantically Challenged
    • snews.ca
[MOD] Additional Article Position Options 2.0 for sNews 1.6
« Reply #4 on: July 30, 2007, 10:23:36 PM »

Hi DOM...
There is one string which was in the 1.5 (default) snews.php file and was not in the 1.6 (default) snews.php file. And I notice that you haven't included it as the last mod string in your mod above. It was the last mod line in function processing. The default string in 1.5 was:
Code: [Select]
$link = (substr($position, 0, 1) != '2') ? find_cat_sef($category).'/'.retrieve('seftitle', 'articles', 'id', $id).'/' : (find_cat_sef($category) != s('home_sef') ? find_cat_sef($category).'/' : '');and the modded string for second extra in 1.5 was:
Code: [Select]
$link = ((substr($position, 0, 1) != '2') && (substr($position, 0, 1) != '9')) ? find_cat_sef($category).'/'.retrieve('seftitle', 'articles', 'id', $id).'/' : (find_cat_sef($category) != s('home_sef') ? find_cat_sef($category).'/' : '');Without it in 1.6...  the "Back" link does not lead back to the article itself, but to the content list string with the "Edit - View" links. I have included it in my modded file so that the "Back" link (after saving) leads back to the article itself.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Dom

  • Full Member
  • ***
  • Karma: 5
  • Posts: 166
    • domdelimar.com
[MOD] Additional Article Position Options 2.0 for sNews 1.6
« Reply #5 on: August 07, 2007, 03:24:34 AM »

Hi keyrocks,

Actually, that line missing in sNews 1.6 is an improvement over sNews 1.5 because if you think about it...

If we're talking about extra contents' here, they don't have a dedicated URL like normal articles and pages do.
In that case, the "Back" link (that you see after successfully editing an extra content) bringing you to the "Extra content View - Edit" page is the correct behavior.

If I try applying your solution it proves my point because the same "Back" link brings me to "Content not found" page.
Logged

Keyrocks

  • Doug
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 451
  • Posts: 6230
  • Semantically Challenged
    • snews.ca
[MOD] Additional Article Position Options 2.0 for sNews 1.6
« Reply #6 on: August 07, 2007, 02:12:09 PM »

Thanks for clarifying that DOM. :)
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
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4957
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
Re: [MOD] Additional Article Position Options 2.0 for sNews 1.6
« Reply #7 on: November 22, 2007, 09:40:49 AM »

Well, I think this was my ten'th implementation of this bugger ;)

Still want the, on HOME put extras, not to show on other categories... :(
Logged
My sNews site
"It's only dead fish that goes with the flow... "
Updated, online again - Free designs

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4957
  • I'm a self-made man and worships my creator.
    • p-ahlqvist.com
Re: [MOD] Additional Article Position Options 2.0 for sNews 1.6
« Reply #8 on: November 22, 2007, 09:55:37 AM »

Thoughts...

This line offered by Doug in his Dos extra MOD:
Code: [Select]
$link = ((substr($position, 0, 1) != '2') && (substr($position, 0, 1) != '9') && (substr($position, 0, 1) != '8')) ? find_cat_sef($category).'/'.retrieve('seftitle', 'articles', 'id', $id).'/' : (find_cat_sef($category) != s('home_sef') ? find_cat_sef($category).'/' : '');

Makes no backlink at all in my copy, and it adds a lot of slashes to the article. And Dom's snippet.

Code: [Select]
$link = (substr($position, 0, 1) != '2') ? find_cat_sef($category).'/'.retrieve('seftitle', 'articles', 'id', $id) : (find_cat_sef($category) != s('home_sef') ? find_cat_sef($category) : '');

offers a backling, but a non-working one... it leads me back to the "sorry, no such article, try the F***ing search function, you numbnut"

Is there a way of either changing this line to a working backling or possible non-link with no adding of slashes ?
Logged
My sNews site
"It's only dead fish that goes with the flow... "
Updated, online again - Free designs