sNews Forum

Previous sNews versions => sNews 1.5 RC and pre-release => sNews 1.5 RC version => Topic started by: celebro on October 06, 2006, 08:57:08 pm

Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: celebro on October 06, 2006, 08:57:08 pm
=========================================
[MOD] ARTICLE SORTING 0.1b - sNews 1.5.26
=========================================

Description:
Ability to display Articles in any chosen order. This is still being worked on but it works so far. So I figured I post it thanks to mika for showing  me the light. All these modifications are done on a fresh vanilla install. This has been written from the top down. So as you add code, the line  numbers reference the modified version thats why I include the original format followed by the  modified version. I will make further modifications to this once the bugs have been cleaned out and this has been cleaned up a bit.

(http://img91.imageshack.us/img91/8840/editarticlezt5.png)

Usage:
Assign a order value when creating the article 0-X.  0 Being the first article 1,2,3 etc.. follows the order. Duplicate entries will be displayed in the order created. *Hint*: Use 0 for static/fixed articles.

Todo/Modify:
- Ability to turn this on or off within a language
  variable, defaulting to default 'id ASC'
  eg: l['artorder_switch'] = 'ON'; // chose ON or OFF



Warning:
**********************************************************************
BACKUP YOUR SNEWS.PHP AND DATABASE!! THIS HAS NOT BEEN FULLY TESTED.
IF IT DELETES YOUR DATA YOUR OUT OF LUCK. DO IT NOW!
**********************************************************************


Modifications:

1. We need to add an extra field to the articles table to hold our sort order. I recommend doing this in phpMyAdmin. Or if your trying it out on a fresh install use this for the articles table in your MySQL database.

Code: [Select]
CREATE TABLE articles (
id int(11) primary key auto_increment,
title varchar(100) default NULL,
seftitle varchar(100) default NULL,
`text` longtext,
`date` datetime default NULL,
category int(8) NOT NULL default '0',
position int(6) default NULL,
displaytitle char(3) NOT NULL default 'YES',
displayinfo char(3) NOT NULL default 'YES',
commentable varchar(5) NOT NULL default '',
published int(3) NOT NULL default '1',
description_meta varchar(100) default NULL,
keywords_meta varchar(100) default NULL,
artorder int(11)
);
2. // LANGUAGE VARIABLES line 41:

Code: [Select]
$l['cat_listSEF'] = 'home,archives,contact,sitemap,rss,gallery,login,administration,add_category,add_article,article_new,side_new,page_new,categories,articles,extra_contents,pages,settings,files,logout,artorder'; //SEF links of the hardcoded categoriesreplace with:
Code: [Select]
$l['cat_listSEF'] = 'home,archives,contact,sitemap,rss,gallery,login,administration,add_category,add_article,article_new,side_new,page_new,categories,articles,extra_contents,pages,settings,files,logout,artorder'; //SEF links of the hardcoded categoriesnote: not sure if this was needed or not but it wouldn't hurt I suppose.

3. // DISPLAY PAGES line 337:
Code: [Select]
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 ORDER BY id";replace with:
Code: [Select]
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 ORDER BY artorder ASC";4. // EXTRA CONTENT line 355:
Code: [Select]
$query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) = '2' AND published = 1 ORDER BY id DESC";replace with:
Code: [Select]
$query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) = '2' AND published = 1 ORDER BY artorder ASC";5. // CENTER line 440:
Code: [Select]
$query_articles .= " AND position <> 3 ORDER BY date DESC";replace with:
Code: [Select]
$query_articles .= " AND position <> 3 ORDER BY artorder ASC";6. // CENTER line 642:
Code: [Select]
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 AND published = '1' ORDER BY id";replace with:
Code: [Select]
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 AND published = '1' ORDER BY artorder ASC";7. // MENU ARTICLES line 720:
Code: [Select]
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND published = 1 ORDER BY id DESC LIMIT $start, $size";\replace with:
Code: [Select]
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND published = 1 ORDER BY artorder ASC LIMIT $start, $size";8. // ARTICLES FORM line 1115:
Code: [Select]
$frm_publish = $r['published'] == 1 ? 'ok' : '';add below:
Code: [Select]
$artorder = $r['artorder'];9. // ARTICLES FORM line 1134:
Code: [Select]
$frm_display_info = ($contents == 'side_new') ? '' : 'ok';add below:
Code: [Select]
$artorder = $r['artorder'];* Note: I am not 100% sure this is actual correct syntax for how it should be referenced.
10. // ARTICLES FORM line 1160:
Code: [Select]
echo '

';
add below:
Code: [Select]
echo '

';
html_input('text', 'artorder', 'ao', $artorder, 'Article Order', 'style_me', '', '', '', '', '', '', '', '', '');
echo '

';
11. // ARTICLES FORM line 1189:
Code: [Select]
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 ORDER BY id ASC";replace with:
Code: [Select]
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 ORDER BY artorder ASC";12. // ARTICLES - ADMIN LIST line 1249 [optional]:
If you want the Articles listed in the Admin panel to be ordered as you requested
Code: [Select]
$query = "SELECT * FROM ".db('prefix')."articles $subquery ORDER BY date DESC";replace with:
Code: [Select]
$query = "SELECT * FROM ".db('prefix')."articles $subquery ORDER BY artorder ASC";13. /*** PROCESSING (CATEGORIES, CONTENTS, COMMENTS) ***/ line 1319:
Code: [Select]
$date = date('Y-m-d H:i:s');add below:
Code: [Select]
$artorder = $_POST['artorder'];14. /*** PROCESSING (CATEGORIES, CONTENTS, COMMENTS) ***/ line 1350:
Code: [Select]
$article_limit = $_POST['article_limit'];add below:
Code: [Select]
$artorder = $_POST['artorder'];15. /*** PROCESSING (CATEGORIES, CONTENTS, COMMENTS) ***/ line 1477:
Code: [Select]
$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')";replace with:
Code: [Select]
$query = "INSERT INTO ".db('prefix')."articles(title, seftitle, text, date, category, position, displaytitle, displayinfo, commentable, published, description_meta, keywords_meta, artorder) VALUES('$title', '$seftitle', '$text', '$date', '$category', '$position', '$display_title', '$display_info', '$commentable', '$publish_article', '$description_meta', '$keywords_meta', $artorder)";16. /*** PROCESSING (CATEGORIES, CONTENTS, COMMENTS) ***/ line 1519:
Code: [Select]
mysql_query($query." keywords_meta='$keywords_meta' ".$query_end);add below:
Code: [Select]
mysql_query($query." artorder='$artorder' ".$query_end);
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: celebro on October 08, 2006, 05:07:23 pm
Anyone given this a go? Interested in feedback and how well this has gone with any other modifications anyone has done to their snews.php.
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: Patric Ahlqvist on October 08, 2006, 05:20:03 pm
I must say that this looks really nice, Cel-man. I haven't tested it, nor will I test this or anything else modwise until the stable release is out... Call me lazy, but I wanna do my own redesign to celebrate the birth of version 1.5 before I do anything else... But then... then, I'm really gonna pimp my install ;)
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: Keyrocks on October 08, 2006, 06:40:09 pm
I am doing the same as Patric - waiting for the stable release before working on mods and addons for it. Once the stable release has arrived, I will certainly test this one - for sure. :)
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: celebro on October 08, 2006, 11:12:28 pm
:) Cool, I guess I will wait and see maybe this gets added in.
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: Keyrocks on October 09, 2006, 12:53:23 am
Quote from: celebro
:) Cool, I guess I will wait and see maybe this gets added in.
I don't think it will get added in to the next release... as Luka and Mika are dedicated to keeping the size of the snews.php file to less than 100KB in size... that is their constant target. Considering they really re-worked the code to quite a high level of efficiencly in 1.5 over 1.4... and added significant flexibility to the system, I have a feeling there is very little head-room for more rationalization in snews.php.

But - again, it WOULD be nice to have this ADDED IN to the current revision, that is for sure. Let's hope Luka and Mika agree. :)
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: Mika on October 09, 2006, 01:13:07 am
LOL, that 100Kb limit has already been explained (http://www.solucija.com/forum/viewtopic.php?pid=13441#p13441).
I don't think that this mod will be included in RC2 but in stable release... perhaps... maybe... I dunno... okay, I'm convinced (hopefully not convicted by the beer keeper (http://www.solucija.com/forum/viewtopic.php?pid=13470#p13470). again :D )
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: celebro on October 09, 2006, 02:41:28 am
Quote from: keyrocks
Quote from: celebro
:) Cool, I guess I will wait and see maybe this gets added in.
I don't think it will get added in to the next release... as Luka and Mika are dedicated to keeping the size of the snews.php file to less than 100KB in size... that is their constant target. Considering they really re-worked the code to quite a high level of efficiencly in 1.5 over 1.4... and added significant flexibility to the system, I have a feeling there is very little head-room for more rationalization in snews.php.

But - again, it WOULD be nice to have this ADDED IN to the current revision, that is for sure. Let's hope Luka and Mika agree. :)
This is not technically an addition this is a rework of the current code (replaced lines), at most 5 lines are added extra which are also very minimal and necessary only to add a new Text field to the articles section.

Quote from: mika
OL, that 100Kb limit has already been explained.
I don't think that this mod will be included in RC2 but in stable release... perhaps... maybe... I dunno... okay, I'm convinced (hopefully not convicted by the beer keeper. again  )
That's cool if not this modification I hope this is added into sNews (stable).. can you toss an old dog some kind of ETA on RC2/BETA2 heh? Although I believe most of the bugs that have been found have had a solution and been moded/fixed so how significant is RC2 actually going to be? Are there other planned features additions?
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: Mika on October 09, 2006, 07:44:41 am
optimistic version:
as soon as I finish changelog ;)

the other version:
both Luka & I have to finish our college duties for this term first (exams etc... :( )
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: Keyrocks on October 09, 2006, 02:44:44 pm
Quote from: mika
both Luka & I have to finish our college duties for this term first (exams etc... :( )
I didn't realize you and Luka were still in the 'formal' education mode... that makes me feel even more ancient age-wise. My last college days were about 35 years ago, and a short 4-week stint in university (over 2 years, 1990-91) with several essays spread in between. You are wise to keep your education a top priority while you are young, as life... kids, mortgages, car payments and college educations... will get in the way once you get started on that path. :) What is your major (and minor) subject(s)?
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: Patric Ahlqvist on October 09, 2006, 03:23:21 pm
Whuaaaa, Key's... I'm currently investigating the possibilities to actually go to "school" again... newly becoming 40 ;) I feel alive, re-youth'ed if one may say so :lol:. Only hope I get in at a suiteable "program"...

Cross your fingers for me ;)
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: Mika on October 09, 2006, 03:29:54 pm
my major is computer science, and minor are several IT economy courses
Luka has telecommunication as his major

my "formal" education is over, however this is the other way of studying - steady job along with afternoon classes at the local university (I don't know how do you call it over there, but here I have an extraordinary student status*)

[couple of days ago I've had an english language exam - 45 minutes of pure torture, but after that (graded with a B, hehe) I've realized that my major foreign language has been improved significantly, thx to this forum and all of you, guys'n'gals :) ]

______________
* our department of science and education fully supports students only if they're under 25 and unemployed...I obviously don't fit in those rules :| so I'm forced to finance it on my own
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: Keyrocks on October 09, 2006, 05:27:19 pm
Quote from: mika
1. my "formal" education is over, however this is the other way of studying - steady job along with afternoon classes at the local university (I don't know how do you call it over there, but here I have an extraordinary student status*)

2. Couple of days ago I've had an english language exam - 45 minutes of pure torture, but after that (graded with a B, hehe)

3. Our department of science and education fully supports students only if they're under 25 and unemployed...I obviously don't fit in those rules :| so I'm forced to finance it on my own
1. In Canada - it's just called "Adult Student".
2. You are doing very well with English - congratulations!
3. In Ontario, Canada, primary (grades 1 to 8) and secondary (grades 9 to 12) is fully government-funded. College and University... the student and/or parents must pay tuition, books and resources, and... if attending college or university in another town or city... the cost of "room and board". This can cost up to $20,000 per year and more. New students can get a "Student Loan" from the provincial government at low or no interest that must be paid back. Adult students are on their own but can get some support if they are unemployed for a long time.
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: heathrowintl on October 10, 2006, 04:49:44 am
well celebro...i am quite impressed that you have answered by question and will definitely test it out/give it a go...and give you some feedback.

thanks again
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: heathrowintl on October 10, 2006, 05:24:00 am
notes while implementing...
change 7 which is on 740...for me was 720

perhaps i misunderstood what the mod would achieve...but i had 8 pages of articles and the very first one i wrote became the newest article...and the very most recentest article was at the bottom of the last page...never the less...the reason i wanted the mod for repositioning the extra content...but editing the article order had no effect...

the implementation in itself went fine and the instructions were very good! (they are a pain to write!) any ideas...sorry if this i not useful
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: celebro on October 10, 2006, 06:44:58 am
Quote from: heathrowintl
notes while implementing...
change 7 which is on 740...for me was 720
You are right, it should be 720 I have updated the mod.

Quote from: heathrowintl
perhaps i misunderstood what the mod would achieve...but i had 8 pages of articles and the very first one i wrote became the newest article...and the very most recentest article was at the bottom of the last page
First thanks for trying it,...

I am going to assume the issues you have mentioned are the following

- When you first created your new article did you give it a value? If you dont give it a value the default would be 0 or none meaning the first article, still ordered by the date created newest to oldest.  

- Second when you created your second article I assume you gave it the order "1" all your previous articles do not have an order value so The first one you created becomes the newest article followed by every other article which does not have a order value (sorted by date created). Then 1 becomes the last article. This is how it is supposed to work.

You would have to give all your articles a order value to get to order them as you want them. So you have to edit all your articles to the order you want them in.

Quote from: heathrowintl
the implementation in itself went fine and the instructions were very good! (they are a pain to write!) any ideas...sorry if this i not useful
Your are right, I personally do not like how the forum does the whole code thing, I will re-write this to be plain text and also include an external link to a text file.
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: heathrowintl on October 10, 2006, 07:37:41 am
you've done a good job! im going to give it another try soon...would perhaps a useful way of using it be to set every article i currently have to say a value of 10...and have it also as the default value...but when i want to have an article higher up give it a 9...or something.

if they all have the same priority (eg 0)...does it not sort by newest article by date?
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: celebro on October 10, 2006, 07:59:23 am
Quote from: heathrowintl
you've done a good job! im going to give it another try soon...would perhaps a useful way of using it be to set every article i currently have to say a value of 10...and have it also as the default value...but when i want to have an article higher up give it a 9...or something.

if they all have the same priority (eg 0)...does it not sort by newest article by date?
I never assumed someone would have 8 pages of articles more like 10-20 so they could easily sort out the articles. 1,...,20 etc.

I dont know how to go about implementing something that will grab all the articles you previously had and assign them a value. If I come up with something I will surely post it here.

My only idea right now is if you have access to phpmyadmin, which would be faster I believe and add a value of maybe 10 to your previous articles or go in them one by one in the administration section and assign them a value of 10 manually.

And to answer your final question yes, it sorts them by date, not really though!, it actually sorts them by the order which they were created in the database which is still by date kinda. :)
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: heathrowintl on October 10, 2006, 08:59:44 am
i used php myadmin to originally alter the database and modify the articles table...i am testing it on my live blog...but i dont care!

i think its a real simple sql command to change a value for all records...dont you stress about that!!
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: Mika on October 10, 2006, 10:10:30 am
Manual sorting is done on categories part: there are usually just a few of them so I think that is a good approach. however, that way of sorting cannot be applied to articles because someone might have 8 pages of them or even more. I surely plan to have lots of articles :) in the near future, and that behaviour is time consuming.

I've been thinking of this problem: what's the most logical way of sorting web contents? What are the user's expectations? The date is the most probable solution because our lives and actions in general are somewhat time determined (ok, this is just my personal yada-yada :D but you get the picture). Other examples are: alphabetical order, size, type etc... Right now I don't see how manual 'randomization' could solve this problem. Or am I missing the bigger picture?

There's another way, applied as comments sorting feature in 1.5: time is used (table "date") as an anchor and asc/desc as ordering behaviour. That course of action can be expanded (http://www.solucija.com/forum/viewtopic.php?id=1434) for articles sorting -> user could choose data type (id, date, alphabet...) and asc/desc rule to set the articles order.
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: celebro on October 10, 2006, 01:43:37 pm
If article sorting is introduced in the begining I don't really see a problem from what you mentioned above.

In my notes for this modification I originally had the idea of having "up and down" buttons during the administrative article listing inside the (article - > "view") section next to each article. Or maybe within a table where you can easily see the articles and move them up or down, Ill see what I can do in implementing this once the 1.5 stable is release.  

Regardless of the approach when you have 8 pages of articles lets say a tutorial, and you write 10 articles and all of the sudden you have to insert one article in between those...

You have to redo/retype/recopy every single article in the order you want them, which is how this modification came about :( it will save you an extreme amount of time.
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: Mika on October 10, 2006, 03:17:07 pm
you have a site with tutorials? what are you waiting for, mate? give us a link :)

ontopic:
i see your point now, sorry that took me so long... on the other hand, why not open up an additional field in the article form to edit 'misplaced' article's id and then set ordering by id? I suppose that way you'll get less code, smaller db and more control over ordering... or not? :D
Title: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: Keyrocks on May 13, 2007, 06:56:13 pm
There hasn't been any action on this topic for some time.
I applied this MOD to a 1.5.31 project today in the hope that it would help me re-arrange articles within each category... which would be the ideal way of doing it when you use categories as drop-down menus (as this particular project does). It was not possible in its current form (above) but some additional tweaking brought it to life.

Here's the project:
---------------------------------
I have several test articles in five categories. The category-names are displayed in a horizontal nav bar... and mousing over each category-name causes the article link-list for that category to open vertically below it. Clicking on an article-link then takes you to the article.

Yes! Yes! Yes!
With some tweaking... this MOD DOES work well in conjuction with Onlip's Drop-down Menu Mod (http://www.solucija.com/forum/viewtopic.php?pid=23839#p23839) which works with Philmoz's Categories Mod (http://snewscms.com/forum/index.php?topic=2533.0)
in 1.5.31. I assume it will work (with some tweaking) in 1.6 due to be out in a few days.

Results:
-----------------
The assigned article order is stored in the new artorder column in the articles table in the dbase. By default, every article is assigned an order of "0", which then causes all articles to be listed by the default method... which is by the order of the date they were originally posted on.

1. All articles that were posted before adding this mod can now be assigned an order number from the Article Admin Panel.

2. If you plan to have lots of articles per category, then you would use number blocks for each category that won't overlap into the number block for the next category. Let's say you want to stick with a limit of 30 articles for each of 5 categories, then you would use 1 to 30 for the first category... 31 to 60 for the second... 61 to 90 for the third... and 91 to 120 for the 4th... and 121 to 150 for the 5th. I have tested positioning numbers with five digits (such as 11223) so you could... in theory... have more than 10,000 articles and (I suppose) up to 99,999 articles on an sNews site... and be able to sort them using this method... though I can't imagine having that many articles listed in a drop-down menu! :)

The full, updated mod is now available here (http://snewscms.com/forum/index.php?topic=4470.0).
Title: Re: [MOD] Article sorting v0.1b (sNews 1.5RC1)
Post by: Keyrocks on August 23, 2007, 11:47:11 pm
Has anyone managed to get this mod working in 1.6? Tried it today and, for some reason, it stops new content from being saved to the database tables. (I may have missed a 1.6 change along the way... needs more exploration).