sNews Forum

Previous sNews versions => sNews 1.5 Final => Mods/addons => Topic started by: Dom on September 22, 2006, 10:25:26 PM

Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Dom on September 22, 2006, 10:25:26 PM
Revision: 5 January 2007 (just a little cosmetic patch, nothing serious)
Revision: 31 December 2006 (fixed bug in search function; instructions updated)
Revision: 8 December 2006 (compatible with sNews 1.5.30 Stable)
Revision: 26 October 2006 (made it compatible with sNews 1.5 RC2, fixed some mistakes in instructions - overview in the post below)

Mod version: 1.0.2
For sNews version 1.5
Example: please see the post following this one.

It all started with keyrocks' post (http://snewscms.com/forum/index.php?topic=1083.0) 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 articles list or an announcement in the same place...

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 work now 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 put ";" at the end of each PHP line... ;)

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 make.

So shall we start with the extra() function then?

Note first 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.5 Stable, developers version 1.5.30, already modified with this mod from domdelimar.com (http://domdelimar.com/snews/additional-article-position-options-mod-snews/) if you don't want to follow these instructions.

Unless otherwise noted, all the work is done in your snews.php file. I don't guarantee anything so make sure to BACKUP your existing snews.php file just in case...

OK...

Find the extra function [search for: function extra()], and right below that function paste this code:

Quote
function second_extra() {
   $categorySEF = get_id('category');
   $categoryId = (check_category($categorySEF) == true || empty($categorySEF) || $categorySEF == s('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) {
         echo $r['displaytitle'] == 'YES' ? '<h3>'.$r['title'].'</h3>' : '';
         file_include($r['text'], 99990000);
         echo $_SESSION[db('website').'Logged_In'] == 'True' ? '<p><a href="'.db('website').'index.php?action=admin_article&id='.$r['id'].'" title="'.l('edit').' '.$r['seftitle'].'">'.l('edit').'</a></p>' : '';
}}}
This is actually a copy of the function extra() with minor changes shown in blue color.

Short explanation: our new position will be denoted with a position string which starts with number nine (9). In default sNews 1.5 there are three positions: position value of 1 denotes this is an article, position value of 3 denotes a page and position value which starts with number 2 denotes this is extra content. Luka, mika - did I get that right?

Now, let's add some admin language variables that we'll need later:
Search for: #ADMINISTRATION LANGUAGE VARIABLES
At the end of admin. language variables, before
Quote
} return $l[$variable];
add three more variables:
Quote
$l['second_extra_contents'] = 'Second Extra contents';
$l['second_extra_new'] = 'New Second Extra Contents';
$l['second_side'] = 'Second Extra contents';
Now we need to change the function center().
Search for function center().
In center function find this line:
Quote
case 'extra_contents': if (isset($_SESSION[db('website').'Logged_In'])) {admin_articles('extra_view');} break;
Right below this line add the following:
Quote
case 'second_extra_contents': if (isset($_SESSION[db('website').'Logged_In'])) {admin_articles('second_extra_view');} break;
Just a few lines below, you'll see this line:
Quote
case 'extra_new': if (isset($_SESSION[db('website').'Logged_In'])) {form_articles('extra_new');} break;
Below this line add the following:
Quote
case 'second_extra_new': if (isset($_SESSION[db('website').'Logged_In'])) {form_articles('second_extra_new');} break;
Then, several lines below, you'll find the line that says:
Quote
$query_articles = "SELECT * FROM ".db('prefix')."articles WHERE published = 1 AND SUBSTRING(position, 1, 1) != '2'";
You need to change that whole line with the following one:
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(). Several lines down, inside this function, you'll find this line:

Quote
$query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) != '2' AND published = 1 AND";
And replace it with this one:
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 find this line:
Quote
if (stats('articles',2) > 0) {echo $link.'extra_contents/" title="'.l('view').'">'.l('view').'</a>';}
Now, after this line, add this 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 modding...

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, enter this line:
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 change:
Quote
$frm_display_info = ($contents == 'extra_new') ? '' : 'ok';
We need to change it completely with 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 changed with this one:
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 with:
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>';}
Next line 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 completely replaced with:
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 [if ($contents == 'extra_new' || $edit_option == 2) {] 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 a chunk of code which starts with:
Quote
if (!empty($id)) {
Five (5) lines down is this line:
Quote
echo '</select></p>';
Before that line insert this 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') {
      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') {
      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. Just 6 more little changes... :)

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:
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 we find a line of code that says:
Quote
if ($position == 2) {$position = $_POST['cat_dependant'] == 'on' ? 21 : 2;}
And after this line insert this:
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;}
         }
Just a little bit further below you will find this code:

Quote
switch(true) {
                  case(isset($_POST['add_article'])):
                  mysql_query("INSERT INTO ".db('prefix')."articles(title, seftitle, text, date, category, position, displaytitle, displayinfo, commentable, published, description_meta, keywords_meta) VALUES('$title', '$seftitle', '$text', '$date', '$category', '$position', '$display_title', '$display_info', '$commentable', '$publish_article', '$description_meta', '$keywords_meta')");
                  $pos = substr($position, 0, 1);
                  switch ($pos) {case 1: $link = 'articles/'; break; case 2: $link = 'extra_contents/'; break; case 3: $link = 'pages/'; break;}
You see this last line starting with switch ($pos) ?
It needs to be changed completely with 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;}
And just 4 lines further down, you'll find a line which starts with

Quote
$link = (substr($position, 0, 1) != '2')
This start should look like this:

Quote
$link = ((substr($position, 0, 1) != '2') && (substr($position, 0, 1) != '9'))
Or the whole line if you wish, should look like this:

Quote
$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).'/' : '');
Finally, just several lines below is the LAST part of snews.php file that we need to change. Whooaa!!

This is the code you will see:

Quote
$pos = substr($position, 0, 1);
                  switch ($pos) {case 1: $link = 'articles/'; break; case 2: $link = 'extra_contents/'; break; case 3: $link = 'pages/'; break;}
Replace the second line (switch...) with this:

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>
Log into your Admin area and there should be something new under Pages:
Second Extra Content or whatever you called it. Try adding a new Second Extra Content now!

Optional: you may want this extra content to be more visible and for example place it in a nice floating box with a different background than your page background.

Here's what you do:
Locate your new extra content function... and change the following part
Quote
if ($print == true) {
         echo $r['displaytitle'] == 'YES' ? '<h3>'.$r['title'].'</h3>' : '';
         file_include($r['text'], 99990000);
         echo $_SESSION[db('website').'Logged_In'] == 'True' ? '<p><a href="'.db('website').'index.php?action=admin_article&id='.$r['id'].'" title="'.l('edit').' '.$r['seftitle'].'">'.l('edit').'</a></p>' : '';
into this:
Quote
if ($print == true) {
         echo "<div class='second_extra'>";
         echo $r['displaytitle'] == 'YES' ? '<h3>'.$r['title'].'</h3>' : '';
         file_include($r['text'], 99990000);
         echo $_SESSION[db('website').'Logged_In'] == 'True' ? '<p><a href="'.db('website').'index.php?action=admin_article&id='.$r['id'].'" title="'.l('edit').' '.$r['seftitle'].'">'.l('edit').'</a></p>' : '';
         echo "</div>";
To accomplish what I wanted to accomplish I'd add this class into my .css file:
Quote
.second_extra {
float:right;
width:40%;
border:1px solid #ccc;
background:#f5f5f5;
padding: 1em;
margin: 0 0 1em 1em;
}
I added some margins and padding definitions so it all integrates nicely between any text the center function shows. Also, width will make sure this box doesn't expand across all of the available screen space.
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Dom on September 22, 2006, 10:27:53 PM
OK, I just followed my instructions prior to posting them here (to kind of bug test them) and added this mod to my main sNews 1.5 site (been working with a testing site until now) and everything went as it should.
I added an introductory text for my sNews category as an extra content which will show above any article links on that category index page.
You can check it out at: http://domdelimar.com/snews/
If you see "Requested contents does not exist" just below this introductory text it means I haven't added any article to this category yet. But that's where the links to articles come anyway.
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Dom on September 22, 2006, 10:38:16 PM
I just realized... in order for this extra content to be treated as a category introductory text (as I wanted it to behave), it should only show up on the category index page, and as it is now it will show up even on articles in this category.

This is because of how the extra() function was built in the first place. It just needs a little modification which I also figured out how to do but forgot to mention it here.

Come to think about it, I'll post it as a separate mod... it makes sense.

EDIT: here it is: http://www.solucija.com/forum/viewtopic.php?pid=13940
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Keyrocks on September 23, 2006, 04:01:31 PM
Congratulations Dom - it is great to see the positioning technique being explored further in sNews 1.5.
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Andre Griffin on October 26, 2006, 06:24:41 AM
It seems that some names have been changed in RC2? like extra_view instead of side_view? is this going to matter?
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Keyrocks on October 26, 2006, 04:09:03 PM
That was the only change I noticed when I looked thu the snews.php file yesterday. My guess is that Mika changed the name of the function in RC2 to make it more relevant... since the extra can be used anywhere you place the php statement... not just in a "side" position. Mike could confirm this.
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Dom on October 26, 2006, 05:43:36 PM
I have simply changed all instances of side_new and side_view into extra_new and extra_view.
Also, the processing function has been considerably changed, that is improved it seems to me (less code). We all know some redundant code from v1.4 has been removed but there have been other changes as well so I had to change these instructions accordingly.

And because of that change in processing function one little change has happened in old (v1.5 RC1) extra() function so don't get yourself caught with the copy of the old version of function extra() to use it for second_extra in 1.5 RC2 like I did. :)
Nothing serious will happen if you do, it's just that the little 'Edit' link which shows under your content when you're logged in - simply won't work. Huh! It took me some time to figure this one out... :rolleyes: So check out the function second_extra() in the first post and make sure you made changes to your code correctly (changes are marked with blue color).

I have also discovered I made a little mistake in my instructions:
Where I said you should add in your index.php, that should have been (notice the semicolon) - although, it seems it will work either way.
And, it was sooo embarrassing to discover I failed a simple task of copy and paste so you could have seen like 20 question marks in a row in my original post. Yikes! [sidenote: how come this forum doesn't have an 'embarrassed' smiley?]

I think everything is OK with the instructions now and I've tried to apply them on my testing site and it looks like everything works like it should. You can see the example here: http://domdelimar.com/testing/sNews1.5RC2/

And let me know if it works for you.
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Patric Ahlqvist on December 05, 2006, 07:10:14 PM
Ok... It's a fact - I'm in love with you aswell, Dom. I will respond gently to your approaches :lol: This works wonders...
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: piXelatedEmpire on December 06, 2006, 01:28:39 AM
Quote from: Patric
Ok... It's a fact - I'm in love with you aswell, Dom. I will respond gently to your approaches :lol: This works wonders...
Did you have to make any changes to Dom's instructions for 1.5 stable Patric?
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Patric Ahlqvist on December 06, 2006, 07:37:08 AM
I haven't got the stable version tested with this yet... My declaration of love was regarding this mod in the "almost stable version" 1.5.29... I was planning to try it on the 1.5.30 today... if I only get time ;) But as the 1.5.29 was in fact the stable one with just a few glitches, I suppose it would turn out good... We'll see..

So, I'll have to get back to you on this...
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Keyrocks on December 06, 2006, 08:05:39 PM
Does this Mod work with 1.5 Stable Version?
Yes... it does. We should say Thanks Dom! Well done!
I just finished adding it into my current project, porting Luka's Internet Sharing Template to sNews 1.5.30. It appears to be working wonderfully. Adding this mod into 1.5 is a lengthy and tedious process, compared to my similar mod for 1.4. It took me a little longer as I changed the name of the function to extra_right to publish content into a right column container in this particular template.
Again... Dom... Well Done! ")
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Mika on December 06, 2006, 08:14:56 PM
*I've been reading & testing mods all day... and I definitely need a new keyboard. This one (http://www.hammond-organ.com/Product/XK1.htm) would do just fine. Thanks! :D *

Yes, you guys* rock, but really rock :)

__________
* dom, philmoz, serpantin an others (that's a pretty long list ;)) - sNews is much better just because of you!
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Keyrocks on December 06, 2006, 08:21:40 PM
Quote from: Mika
*I've been reading & testing mods all day... and I definitely need a new keyboard. This one (http://www.hammond-organ.com/Product/XK1.htm) would do just fine. Thanks! :D *
Now I wouldn't mind finding that under the Christmas tree on Christmas morning! It would sit right nicely on top of my M3 and give me a triple decker! :)
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Fred K on December 06, 2006, 09:57:40 PM
Quote from: Mika
This one (http://www.hammond-organ.com/Product/XK1.htm)
I want one! I want one! Iwant one! :lol:
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Dom on December 08, 2006, 11:19:24 PM
Hello everybody!
I've been away for quite some time from this forum... and missed you all!
Patric emailed me the other day and I promised I'll take a look at this mod but everything looks fine.

I'm very glad there's no more work needed to make this mod work with the latest release 'cause just as keyrocks pointed out about adding this mod that it is "a lengthy and tedious process", it ain't no easier bug testing it and getting it to work in the first place.

But the most tedious and lengthy has actually shown to be the process of writing the documentation... arrrgh, I know I promised you guys to outline everything I did to make this mod but I can't get to finish it in a reasonable timeframe so I've decided to just let everybody download the latest sNews version with this mod already integrated. Should have come up with this sooner, d'oh!
You can download it from domdelimar.com (http://domdelimar.com/snews/additional-article-position-options-mod-snews/) - I left comments in places where I changed the code, they won't be much useful to anybody from an informational point of view but at least you can see where the code has been changed if you wish.


P.S. Mika, maybe if you're working all day in front of your computer, you could benefit from using this (http://www.ultimatebackstore.com/product-exec/product_id/286/pn/Highly%20Adjustable%20Aeron%20Chair%20with%20Graphite%20Frame) - I know I would! This one (http://www.ultimatebackstore.com/product-exec/product_id/189/pn/Executive%20Aeron%20Chair) wouldn't hurt either... :D
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Keyrocks on December 08, 2006, 11:30:28 PM
Quote from: Dom
P.S. Mika, maybe if you're working all day in front of your computer, you could benefit from using this (http://www.ultimatebackstore.com/product-exec/product_id/286/pn/Highly%20Adjustable%20Aeron%20Chair%20with%20Graphite%20Frame) - I know I would! This one (http://www.ultimatebackstore.com/product-exec/product_id/189/pn/Executive%20Aeron%20Chair) wouldn't hurt either... :D
Wow... neat chairs... for a wheelbarrow of moolah. I'll have to stick with my $89.00 special. :)
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: david on December 18, 2006, 02:35:33 PM
so easy,
keep up the good work!

I added the last line so I can see the title of second extra contents in admin:

Code: [Select]
#ADMINISTRATION LANGUAGE VARIABLES
#administration
$l['administration'] = 'Admin';
$l['articles'] = 'Articles';
$l['extra_contents'] = 'Extra contents';
$l['pages'] = 'Pages';
$l['second_extra_contents'] = 'Extra contents 2';
next: what to copy/paste and modify to have a 3d content?
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Dom on December 20, 2006, 10:00:17 PM
I'm glad you found this useful and easy to apply. :)

That line you mention, BTW, should already be added at the end of all admin. language variables if you followed the instructions. So now you probably have two $l['second_extra_contents'] variables, not sure what this brings but if you wanted to have some other name for your 2nd extra content than the one I've chosen, sure you can change the value of any language variable.

About the 3rd extra function - it shouldn't be complicated and you should just replicate the steps but bare in mind you have to use another position instead of the position 9.

You see, default sNews has Articles, Pages and Extra Content which all differ in their position values: every entry in database (in table articles) with a position value of 1 is Article. If position value is 3, sNews will see it as a Page and if the position value starts with a number 2 (which can be followed by two or no additional digits) then sNews knows this entry has to be treated as Extra Content.

So the modified extra function (which shows Extra content just like function center shows Articles) has been renamed to second_extra and given the number 9 - so every entry in database that has the position value starting with number 9 (remember, the nature of extra content is that it can have up to three digits as a position value, unlike Article and Pages) will be treated as our NEW extra content, whatever we name it.

(I hope I haven't made any false claims here, but I'm sure people will correct me if I have.)

Why I chose number nine? Because I was afraid to use a two digit number. :) Can any of the PHP gurus tell me what consequences would a two digit number have here? Could it be done without further modifying the sNews engine?

Anyway, if you're about to build another extra function, I'd suggest you use number 8, to make your life easier in case any future version of sNews occupies more places (so far only places 1, 2 and 3 are "occupied").

Actually I went and quickly added the third extra function for you in a fresh snews.php file which you can download from here (http://domdelimar.com/goodies/snews.zip) right now and test it.
I didn't have time to thoroughly test it but from a quick test I conducted it seems fine. Hope you can test it and use it if everything works as it should. If something doesn't work as it should, let me know. But before you do anything, backup your existing snews.php file and your MySQL database. ;)

EDIT: Sorry, wrong link posted - has been corrected.
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Keyrocks on December 20, 2006, 10:18:33 PM
A note about using double-digit position numbers: When I created the custom positions mod for 1.4, I also tested use of double-digits and it worked OK. I assume this doesn't present a problem because the ID number column in the articles table will accept 2 numbers as easily as one... and as long as the number used is also defined in all function-related strings throughout the snews.php file... they ought to work with it. I haven't tried a double-digit yet in 1.5 but it shouldn't be hard to test - just change all the 9s 10 20 or something to see what happens.
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: david on December 20, 2006, 10:20:42 PM
Dom, thank you for your kind reply and clear explanation
I see there is an xmas gift to download. :D
I'm so tired now and tomorrow will be very busy,
I will let you know in the next days

thanks
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Datu Puti on December 21, 2006, 01:28:12 PM
Thanks for the 3rd extra function Dom.. should prove useful.. i was looking at making extra_right extra_left extra_top extra_bottom..  :cool:
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Dom on December 23, 2006, 03:12:05 PM
Techyg, you're welcome. I still haven't thoroughly tested it and hope it works as it should.

Keyrocks, I don't have much time at the moment but I'm going to test this later. I don't know what led me to believe this wouldn't work as easily so that I haven't even tested it before...

Ilocoskid, I'm not sure what consequences this can bring, probably the reduction in speed if you have a really large snews.php file - I suggest you seek advice from someone more experienced with PHP than I am about this.

But if I were you, I'd ask myself whether I could accomplish whatever I want to accomplish without an extra function. You usually need an additional extra function if you want to present some manually inserted content at a different place in your website layout and all your existing extra functions are used to present something else at other places in your website layout.
Here's one example that I can think of now where you could use one of your extra functions but don't really have to: If you want to have AdSense boxes at the bottom of all of your articles. If you don't have that many articles, you can use the include function and include a file containing the AdSense code in each and every one of them.
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Dom on December 31, 2006, 10:12:24 PM
Hmmm, nobody noticed this so far but it escaped me as well.
It appears I have left out the modification of the search function which is made so that the extra content doesn't show up in the search results. Since we added another extra content function here, the same logic should be applied and it also shouldn't show up in search results.

So, in your snews.php first locate "function search()".
Several lines down, inside this function, you'll find this line:
Quote
$query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) != '2' AND published = 1 AND";
And replace it with this one (notice the change in blue):
Quote
$query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) != '2' AND SUBSTRING(position, 1, 1) != '9' AND published = 1 AND";
If somebody tries to open one of your extra content from inside your search results page, they will just see "Content not found", so I advise you to apply this mod.

P.S. Original post modified with this addition.
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Keyrocks on January 01, 2007, 12:04:26 AM
Thanks Dom, appreciated. I had not tested the search on my added extra content yet. :)
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Datu Puti on January 01, 2007, 07:50:05 AM
Fantastic work as usual Dom.. just a quick question.. i downloaded the snews.php file that you made available with the third extra function.. does the above patch fix it as well?
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: brauck on January 01, 2007, 10:45:02 AM
Thanks Dom  ;)
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Dom on January 01, 2007, 05:51:37 PM
Yes, I modified all the files I made available for download as well. If you downloaded it again after my last post then you have the latest patch included. (Quick test (applies only for this file (http://domdelimar.com/goodies/snews.zip)): line 853 says as follows: "// Third: modified the following line:")
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Dom on January 01, 2007, 06:03:56 PM
Quote from: ilocoskid
Fantastic work as usual Dom.. just a quick question.. i downloaded the snews.php file that you made available with the third extra function.. does the above patch fix it as well?
Oh, sorry. Only now I realized what you asked me... :)

No, that patch is only for the snews.php with the second extra function. If you downloaded the snews.php file with the third extra function as well, then you should do something similar to apply this patch:

In your snews.php first locate "function search()". Inside this function, find this line:
Quote
$query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) != '2' AND published = 1 AND";
And replace it with this one (notice the change in blue):
Quote
$query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) != '2' AND SUBSTRING(position, 1, 1) != '8' AND SUBSTRING(position, 1, 1) != '9' AND published = 1 AND";
Once again, note the above patch is only for you if you have two additional extra functions inside your sNews. Following the instructions inside the first post of this topic will only equip you with one additional extra function.
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Datu Puti on January 02, 2007, 03:52:07 PM
Great DOM.. thnx

 :cool:
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: piXelatedEmpire on January 05, 2007, 07:52:18 AM
ok, so I finally went ahead and installed this MOD, your instructions are FLAWLESS by the way :D

1 question tho, how do I edit this MOD so that the second Extra contents, when implemented, does not display in the admin panel? (see screenshot below)
(http://img119.imageshack.us/img119/3899/2ndextracontentpy6.jpg) (http://imageshack.us)
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: piXelatedEmpire on January 05, 2007, 08:05:26 AM
For those interested, I also slightly changed the positioning of the 'second Extra contents' link in the Admin panel so that it appears directly underneath the 'Extra contents' link.  Seems to make more sense to me to have it here.  To do this:

follow Dom's instructions until you get to this part:
Quote from: Dom
Now search for function administration()
At this stage, find this line:
Code: [Select]
if (stats('articles',2) > 0) {echo $link.'extra_contents/" title="'.l('view').'">'.l('view').'';}and directly below it add this code:
Code: [Select]
echo '

';
    echo '

'.l('second_extra_contents').': '.l('add_new').'';
if (stats('articles',9) > 0) {echo $link.'second_extra_contents/" title="'.l('view').'">'.l('view').'';}
That's it!  Your admin panel should now look something like this:
(http://img119.imageshack.us/img119/6000/2ndextracontentgn4.jpg) (http://imageshack.us)

I know I know, not much of a change, but maybe someone will find it useful!

Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Dom on January 05, 2007, 03:20:46 PM
Incidentally, just yesterday I've placed one Second Extra Content on my testing site for the first time on the homepage and that's exactly what's been bothering me so I was thinking... do we want to move it completely out of our sight when we're logged in? I don't think so. Maybe a JavaScript toggle function would be great here to just hide it, with a way to quickly show it again.

That was the initial thought and after I accomplished this I realized we don't need a quick fix here and that I'd be more satisfied if Extra Content made to show up on homepage wouldn't show up on admin pages, wouldn't you agree?

Now, let's just say this was a bit confusing and I've been looking at 'case' lines in original extra function all along but the solucija was lying somewhere else...

Let's look at some facts first (was working with original Extra Content from sNews here):
Fact 1: created Extra Content to show on Home category
Fact 2: Extra Content now has position value 210 and category value 0
Fact 3: Extra Content shows on the following pages: homepage, Articles and Pages under home category & of course on all hard-coded pages
Fact 4: Mika's explanation from snews-commented.php says that if the position value starts with '21', then that's a category dependent Extra Content

For me, when I created and applied this mod it made sense that if I wanted to show a category introductory text, it should not be visible on all the pages 'below' that category as well. So I modified my extra function a bit more which is explained here (http://www.solucija.com/forum/viewtopic.php?id=1764) as another mod.

Now, it looks like I covered all the cases but the case when the category that an extra content is dependent on is Home category. Reason for this is that I didn't know how to do it. Ha! :/

Fact 5: applying this other mod (http://www.solucija.com/forum/viewtopic.php?id=1764) makes the Extra content show on the following pages: homepage, all hard-coded pages BUT not on Articles and Pages 'below' the Home category

I guess my other mod does work in some extent, it's just that I disregarded the hard-coded pages, which should be treated the same as Article and Pages (this is not going to sNews developers, as it's valid just for this modification) and that is if I want to show extra content on category index page, just as on the Homepage, I don't want it to be visible on other pages below that category (including other Articles, Pages and all hard-coded pages).

The 'problem' lies here:

$categoryId variable inside extra function is set to '0' whether the page is hard-coded or "home", either way. Basically, that way extra function sees hard-coded pages as if they were the Homepage. We need to set $categoryId to '0' ONLY when category is home:

Find this line inside your extra function:
Quote
$categoryId = (check_category($categorySEF) == true || empty($categorySEF) || $categorySEF == s('home_sef')) ? 0 : retrieve('id', 'categories', 'seftitle', $categorySEF);
And replace it with the following one:
Quote
$categoryId = (empty($categorySEF) || $categorySEF == s('home_sef')) ? 0 : retrieve('id', 'categories', 'seftitle', $categorySEF);
Fact 6: when I apply the above solucija, Extra content shows on the following pages, hmm, on the following page: homepage - success! Finally. ;)

Question 1: Does this have any other side effects on the way extra function should work? I haven't seen any so far.  :D
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Dom on January 05, 2007, 03:22:46 PM
Oh, BTW Adam, your other comment about the position of the 'second Extra contents' link in the Admin panel makes sense. I'll update my first post (and files immediately after that) ASAP. Gotta run now. Thanks!
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Datu Puti on January 05, 2007, 09:15:37 PM
Dom u got a clean snews.php file with the third extra function updated, for download?
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Dom on January 05, 2007, 10:56:45 PM
Hi ilocoskid, everything looks fine from my side - I tried downloading all the files and they all contain full snews.php files - snews.php with the third extra function pre-installed you should download from http://domdelimar.com/goodies/snews.zip (http://domdelimar.com/goodies/snews.zip). Could it be that you tired downloading exactly at the moment that I've been uploading it today? It happens sometimes to me when I try to re-load my homepage and the snews.php is still being uploaded to server. Other than that I don't know what it could be.
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Dom on January 05, 2007, 11:01:21 PM
Hmm, I've just checked the error log and found some strange errors (to me at least, because I don't exactly know what they mean) and I suspect this was you trying to download that file:

[20-Dec-2006 22:02:46] PHP Warning:  Zend Optimizer does not support this version of PHP - please upgrade to the latest version of Zend Optimizer in Unknown on line 0
[20-Dec-2006 22:02:46] PHP Warning:  mysql_connect() [function.mysql-connect]: Access denied for user 'username'@'localhost' (using password: YES) in /****/public_html/goodies/snews.php.download on line 1687
[20-Dec-2006 22:02:46] PHP Warning:  mysql_select_db() [function.mysql-select-db]: Access denied for user '****'@'localhost' (using password: NO) in /****/public_html/goodies/snews.php.download on line 1688
[20-Dec-2006 22:02:46] PHP Warning:  mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /****/public_html/goodies/snews.php.download on line 1688
[20-Dec-2006 22:06:00] PHP Warning:  Zend Optimizer does not support this version of PHP - please upgrade to the latest version of Zend Optimizer in Unknown on line 0
[20-Dec-2006 22:06:31] PHP Warning:  Zend Optimizer does not support this version of PHP - please upgrade to the latest version of Zend Optimizer in Unknown on line 0
[20-Dec-2006 22:09:14] PHP Warning:  Zend Optimizer does not support this version of PHP - please upgrade to the latest version of Zend Optimizer in Unknown on line 0

Try with the simple right-click and the "Save As.." on the link from my previous post.
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Datu Puti on January 06, 2007, 06:12:32 PM
ok dom.. thnx.. i haven't downloaded anything until just now.. thnx again..
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Dom on January 07, 2007, 07:48:25 PM
Answer to my question: Does this (http://www.solucija.com/forum/viewtopic.php?pid=20493#p20493) have any other side effects on the way extra function should work? - is: YES!

Sorry, I hoped that this solved the problem but it didn't.
I completely forgot about the things like when you search, use the contact form or write a comment - after each of these actions the result is brought onto your homepage. OK, it's not really your homepage content shown, but the address bar says you're on the homepage. And the extra content just gets in way there.

Choosing a Page to behave as Home Page instead isn't a solucija because it then kills the purpose of having an extra content on Home Page, along with whatever the center function shows (one or a number of latest articles).

So... I need some help now... pretty please...
The only solucija I see is to have sNews show the result of the mentioned actions (search, comment posting and using contact form) on URLs other than homepage URL. Any other ideas?

Until we solve this, the mod 'Showing extra content only on category index (http://www.solucija.com/forum/viewtopic.php?id=1764)' is useless for extra content dependent on homepage category. Hmm, I'd better move this problem at this topic... so if you have a suggestion or a solucija, come here (http://www.solucija.com/forum/viewtopic.php?id=1764).
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Pavel on June 17, 2007, 01:21:00 AM
Can someone please create this mod for sNews 1.6?  ;)
Title: [MOD] Additional Article Position Options (sNews 1.5)
Post by: Dom on July 08, 2007, 06:09:43 PM
Hi, I have finally had an opportunity to dedicate some time to this problem.

And it was about time I deal with this - busy offline schedule and the situation I'm currently in (as explained on my website (http://domdelimar.com/)) didn't allow me to do it before.

It turns out I didn't even need the time I anticipated I will need. ;)

Anyway, let's get down to it.
So far I have migrated my website from 1.5.31 to 1.6.0. Yes, I haven't even been able to find some time to do that until now.
Anyway, since I have this mod on my site, I have had the opportunity to see why you might be having problems after migrating yourself (given that you have kept this mod after the upgrade). The only problem I noticed was that I couldn't view existing nor create new Second Extra Contents through Admin area.

Oh, boy did I ponder on this one... and it's so easy... after one figures it out ;)

I just had to add 'second_extra_new' and 'second_extra_contents' as hard-coded categories in SYSTEM VARIABLES, like this:

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
(*Note that I had to cut this line of code into three lines of code just for it to show up correctly on this forum - in your snews.php file this is only one line of code.)

And it took me two hours of going through various functions to figure that out.

Other than not being able to view Second Extra Content from admin area and create a new one, is there anything else not working as it should, Pavel?

I now have to go through the old instructions and see if most of it is good for the new version of sNews. Then I'll make a separate post with instructions for 1.6.0. Expect that in a few days.