Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: [MOD] Additional Article Position Options  (Read 6880 times)

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
[MOD] Additional Article Position Options
« on: June 11, 2006, 08:51:17 pm »

Introduction: - revised June 20/06
-----------------------------------
My original objective in this exercise was to see if sNews could be modified to list several product containers in one specific Category's page(s)... say Products... as sort of a lite e-commerce option. It could also be used to create a Classifieds Category as well.

This involved several modifications including a css-styled container that the items would display in. The style of the container can be changed to suit the look of any template, and will display an image with the title and text combined.

There are several steps involved, beginning first with the need to make the existing left and right position functions category-dependent, so that items posted in left, right or our new position, will display only within the chosen category page(s). All the mods are done in snews.php unless otherwise noted.

New Article Position Option for Products Category
-----------------------------------------------------------------
Revised: June 20/06

Step 1 - Mod left and right functions to make them category-dependent.
We need to replace the first $query in each of these functions with 2 new lines. The reference for this mod is in Luka's post at: http://www.solucija.com/forum/viewtopic.php?pid=3789#p3789. So, in each function, replace
Quote
function left() {
$query = "SELECT * FROM " .s('prefix'). "articles WHERE position = 5 AND published = 1 ORDER BY id DESC";
with this:
Quote
function left() {
    $seftitle = get_id('category');
    $query = "SELECT id FROM " .s('prefix'). "categories WHERE seftitle = '$seftitle'";
    $result = mysql_query($query);
    while ($r = mysql_fetch_array($result)) { $categoryid = $r['id'];    }
    $query = "SELECT * FROM " .s('prefix'). "articles WHERE position = 5 AND published = 1 AND category = '$categoryid' ORDER BY id DESC";
//  $query = "SELECT * FROM " .s('prefix'). "articles WHERE position = 5 AND published = 1 ORDER BY id DESC";
Note- that we have left the original $query string in place, but commented out, in case we want to revert back to the pre-mod state again for some reason. Make sure you change the word "left" to "right" in the 1st line for the right function.
-------------------------------------------------------------------------------------------------

Step 2 - Mod function menu_items.
This mod is supposed to make items displayed in the menu list on a given Category page specific to that Category. The reference for this mod is in Luka's post at: http://www.solucija.com/forum/viewtopic.php?pid=1278#p1278. So, in the function menu_items (in snews.php), replace
Quote
function menu_items() {
   echo "<ul class='menu'>";
   echo "<li><a href='" .s('website'). "archives/'>" .l('archives'). "</a></li>";
   $query = "SELECT * FROM " .s('prefix'). "articles WHERE position = 3 ORDER BY id";
with this:
Quote
function menu_items() {
   echo "<ul class='menu'>";
   echo "<li><a href='" .s('website'). "archives/'>" .l('archives'). "</a></li>";
   // next 2 lines replace line below to make menu display category-specific.
   $category = $_GET['category'];
        $query = "SELECT * FROM " .s('prefix'). "articles WHERE position = 3 AND category = '$category' ORDER BY id ASC";
//   $query = "SELECT * FROM " .s('prefix'). "articles WHERE position = 3 ORDER BY id";
Note- Again, we have left the original $query string in place, but commented out, in case we want to revert back to the pre-mod state.
June 25/06 - this mod in function menu_items does not appear to list a category's article titles specifically on that category page's menu items list... the title shows in the new articles list on all category pages including Home. This functionality is being added to sNews V1.5 - we may need to wait for 1.5 to have this working as intended.
-------------------------------------------------------------------------------------------------

Step 3 - Add new Position Option to Admin's New Article Position Options area.
To create our new Position Option, we will be creating a new Position Function later on. The function can have any name you choose, but in this example, we're calling it custom15 and this number is used in most of the mods. The reason for this is explained further down in this post after the mods section.
In snews.php, find:
Quote
function new_article()
Scroll down a bit till you come to:
Quote
<fieldset>
   <legend><? echo l('position'); ?></legend>
Below that are 4 lines that display the four position options in the Postion section of the New Article Admin Panel. To create a 5th option, copy the last line and paste it directly below the 4th one. Change the value number to "15", and in <? echo l('right'); ?></p> at the end of the string, change 'right' to 'products'. This adds your new option radio button and descriptive text to the Options panel.
--------------------------------------------------------------------------------------------------

Step 4 - Add a Language definition for Custom 15. In snews.php, search for 'right' in the language definitions. Under that, copy and paste the following:
Quote
$l['products'] = "Post Item on Products Category Page.";
--------------------------------------------------------------------------------------------------

Step 5 - Create a new Position Function. The function below was cloned from either function left or function right - they are structurally the same. It includes Luka's mod that made the left & right functions category-dependent in Step 1 above. It was then re-arranged and modded a bit, so copy it and paste it below function left or right in snews.php.
Quote
/*--------------
   CUSTOM 15
----------------*/
function custom15() {
    $seftitle = get_id('category'); //get title of the chosen category
    $query = "SELECT id FROM " .s('prefix'). "categories WHERE seftitle = '$seftitle'"; // select category name from categories table
    $result = mysql_query($query);
    while ($r = mysql_fetch_array($result)) { $categoryid = $r['id'];    }
    $query = "SELECT * FROM " .s('prefix'). "articles WHERE position = 15 AND published = 1 AND category = '$categoryid' ORDER BY id DESC";
   $result = mysql_query($query);
     while ($r = mysql_fetch_array($result)) {
     echo "<div class=\"custom15\">"; // our styled item container
     // if text is not limited, show full article - else - limit text to limit chosen
   if ($r['textlimit'] == 0) { $textlimit = 999000; } else { $textlimit = $r['textlimit']; }
      // if item has a title, display the title
       if ($r['displaytitle'] == "YES") { echo "<h2>". $r['title'] ."</h2>"; }
   // if item has an image, display the image under title, to left of text
   if ($r['image'] <> "") { ?>
      <div class="image">
      <img src="<? echo s('website') .s('image_folder'); ?>/<? echo $r['image']; ?>" alt="<? echo $r['title']; ?>" />
      </div> <? }
       // PHP files inclusion routine
   $fulltext = $r['text'];
   $findme  = "[include]";
   $pos = strpos($fulltext, $findme);
   $findme  = "[/include]";
   $pos2 = strpos($fulltext, $findme);
   $file = substr($fulltext, $pos + 9, $pos2 - 9);
   if ($pos2 > 0) {
      $text = str_replace("[include]", "|&|", $fulltext);
      $text = str_replace("[/include]", "|&|", $text);
      $text = explode("|&|", $text);
      $num = count($text);
      for ($i = 0; ; $i++) {
         if ($i == $num) {
         break;
               }
      if (strpos($text[$i], '.php') === false AND strpos($text[$i], '.txt') === false AND strpos($text[$i], '.inc') === false) {
      echo substr(stripslashes($text[$i]), 0, $textlimit);
      } else {
      include $text[$i];
      }}} else {
      echo substr(stripslashes($fulltext), 0, $textlimit);
          }
   // if admin is logged in, display the edit links line..........
       if (isset($_SESSION['Logged_In'])) { echo l('edit'). " [ <a href='" .s('website'). "index.php?action=simpleedit&id=$r[id]'>". l('simple') ."</a> <img src='" .s('website'). "images/arrow.gif' alt='|' /> <a href='" .s('website'). "index.php?action=advancededit&id=$r[id]'>". l('advanced') ."</a> ] <img src='" .s('website'). "images/arrow.gif' alt='|' /> <a href='index.php?action=process&task=delete&id=". $r['id'] ."'".if_javascript_on(" onclick='return confirm(\"".l('warning_delete')."\");'",'return').">". l('delete_article') ."</a></div>"; }
   }
}
Step 6 - In index.php, add the new function call statement.
Find the <? center() ?> function-call that displays whatever is assigned to center position. Below it, paste in the new function-call for our new function - <? custom15(); ?> so items set to position on the Products Category page will display there.
--------------------------------------------------------------------------------------------------

Step 7 - Add the new item container styles to your css stylesheet.
Again, this container is styled for my example site. You can play with the styles to color your container as you wish. These classes are already inserted into function custom15 to wrap the function's displayed content within the container template.
If you upload a thumbnail-sized image using the Image Upload Panel, you can choose the image to include with your item title and text, and the image will be positioned under the title with the text flowing beside the image and under it.
Quote
/*============ Custom 15 container classs =================== */
.custom15 {
   /* width: 450px; */
   padding: 8px;
        background-color: #ede3e5;
        border: 1px solid #7a021c;
}
.custom15 h2 {
   font-family: Arial, Helvetica, sans-serif;
   font-size: 15px;
   font-weight: bold;
   color: #7a021c;
   padding: 0 0 4px 0;
   margin: 0 0 10px 0; /* top - right - bottom - left */
}
And... if your stylesheet doesn't have an image class yet, you'll need it. This aligns the image so text flows around it, and lets you set padding on any of the 4 sides. copy and paste the following above or below the classes you just inserted (above):
Quote
.image {
   float: left;
   padding: 0 10px 0 0; /* top - right - bottom - left */
   border: 0;
}
--------------------------------------------------------------------------------------------------

After you've uploaded your changes to your domain, go into your Admin panel and create a short article and choose the Products Page position, save, and see where it displays. It should be working. :)


=====================================================

Value Number Assignment

There are currently four article position options, as we found in function new_article. Each of those options is assigned a position ID number. When you publish an article, the details of your post are stored in the articles table in the database. The number assigned to each option is defined within the option function, as we just learned in Step 3 above.

Number Assignment in sNews 1.4 - after adding our new Custom 15 - are:
-------------------------------------------
1   - Center articles
2   - right articles
3   - title in categories
15 - Custom 15
5   - Left articles

Number Assignment in snews 1.5 - why we use No. 15 above...
As Luka points out in his post below, he has already added several new positioning options to sNews 1.5, which we are all waiting for... hehe. So, to ensure this mod does not conflict with sNews 1.5 when it comes out... and leave room so Luka can assign a few other options in the near future...  we'll start this modding at number 15. But - if you want more room, you can replace all references to 15 with any double-digit number - like 30 or 40 or 50 - and start making up your own positioning options from there. Position creation appears almost limitless. Using the same steps above, we could then create CSS classes for any number of specific uses into which each option would display.

=======================================================

Additional Mods to Complete the Picture

1. We would also want to add the mod described here http://www.solucija.com/forum/viewtopic.php?id=213&p=1 so that our Products Category would have several pages to display products on. This mod may not be working bug-free, but there is hope that Luka has added it to the soon-to-be-released sNews V1.5.

2. To give sNews a lite e-commerce option, we will also need to create an add-on (functions in a separate included .php file) so that customers to the site could choose to add any number of product items to a shopping cart list, have the price of their choices shown, and have it totalled up (with applicable taxes) on an order form for customer approval and final submission.

3. Then we would need to integrate this with an online auto-payment system - like PayPal and/or WorldPay, so customers can pay for their order on your site on final order submission... and the payment goes directly to your business bank account.

I've taken this as far as I can for now. If anyone else has some time to work on E-Commerce Lite addons for sNews, please have a go at it. :)
« Last Edit: December 01, 2007, 02:17:24 am by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Luka

  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 36
  • Posts: 1717
    • http://www.snewscms.com
[MOD] Additional Article Position Options
« Reply #1 on: June 11, 2006, 09:02:39 pm »

Excellent idea keyrocks! We'll just need to develope this idea further as in 1.5 positions are slightly different:

Position number assignment:

1 - Center
2 - Right
3 - Page
4 - Unpublished
5 - Left
6 - Category dependant left article
7 - Category dependant right article
8 - Category dependant Page
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
[MOD] Additional Article Position Options
« Reply #2 on: June 11, 2006, 09:10:49 pm »

OK Luka - so - can we assume that we could then create more position options using option numbers above number 8... and can we also assume that numbering could be double-digit - like 10 thru to 20 - even though that would be a bit unrealistic?
Added: Yes, assigning double digit position numbers do not appear to be a problem... just tried number 12 and it continues to function fine.

When will you have version 1.5 ready for testing? We are all looking forward to it.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Luka

  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 36
  • Posts: 1717
    • http://www.snewscms.com
[MOD] Additional Article Position Options
« Reply #3 on: June 11, 2006, 09:15:37 pm »

Well we could also make a field in form x,y which would mean position, dependancy and something else we came up with.

sNews 1.5 is kinda ready but buggy and needs some testing. I can't tell when I'll release it for testing, but it'll be soon enough :)
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
[MOD] Additional Article Position Options
« Reply #4 on: June 12, 2006, 03:05:17 am »

Testing Results: test page link removed - no longer available.

I created a new category - Products. Then created a new article in Products. I've also wrapped the article in a CSS container to give it some definition during testing. In index.php, this container is wrapped in a 2nd
following the 1st which contains the center articles.

Problem One: I would have expected the Products article to display only on the Products category page. But it also displays at the bottom of the Home page as well.
Question: How can we have it display ONLY on the category page PRODUCTS?
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
[MOD] Additional Article Position Options
« Reply #5 on: June 18, 2006, 08:45:21 pm »

i've just tested your code with the same result...
the main "problem" lies inside functions left/right/custom15 - they are category independent. those functions should have category variable passed along with them to work "properly"

is this a bug or a blueprint/implementation error... or maybe those left & right functions are created intentionaly for displaying "static" content? Luka can answer this...
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
[MOD] Additional Article Position Options
« Reply #6 on: June 18, 2006, 11:34:16 pm »

Gee mika... I never thought of that. OK - yes - the center function places an article specifically on one category page only. However, Luka appears to have something in mind... as noted above:
Quote
Well we could also make a field in form x,y which would mean position, dependancy and something else we came up with.
I am sure he has the solution, but we need to give him time to get V1.5 out for testing.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
[MOD] Additional Article Position Options
« Reply #7 on: June 19, 2006, 08:06:48 am »

take a look here... i think that this problem of ours has been solved
edit: ...been searching the forum - > analyzerx's solucija was here all the time right under our noses ;)
edit2: and luka's too :D -> here and here
(we should search the forum more often...)
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
[MOD] Additional Article Position Options
« Reply #8 on: June 19, 2006, 02:46:50 pm »

Exellent search results Mika! I did not come across these in my search. Oddly enough, these were the exact two things I was focusing on towards the end of last evening and I was going to start experimenting this morning (it's now 8:46 a.m. my time) Luka's two posts seem to have the answers. This may turn out to be a simple mod after all! :)
Final Results, June 20/06:
Mika - yes - Luka's mods did the trick. It is now functioning the way I envisioned. I have revised the top post in this string with the updates so that the whole thing should function as intended for anyone using it. Once again... thanks for your help on the search! :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
[MOD] Additional Article Position Options
« Reply #9 on: June 19, 2006, 02:48:37 pm »

*thumbs-up*
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version