Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Ravens PHP Scripts And Web Hosting Forum Index -> RN Enhancement Requests and Suggestions
Author Message
dad7732
RavenNuke(tm) Development Team



Joined: Mar 18, 2007
Posts: 1242

PostPosted: Mon Oct 01, 2007 6:25 pm Reply with quote

Couldn't find anything searching or in the FAQ's, etc and hope this is in the right place.

When adding a story the new one goes at the top (default). I would like it to go at the bottom instead. I've seen a lot of fixes but none work for 7.6 editing the mainfile.php file. What is the fix for 7.6? Thanks.

I also suggest that this be added to the admin preferences for the "News" or "Topic" module - the ability for the admin to place stories wherever we want.

Thanks, Jay
 
View user's profile Send private message
Dawg
RavenNuke(tm) Development Team



Joined: Nov 07, 2003
Posts: 928

PostPosted: Mon Oct 01, 2007 7:37 pm Reply with quote

One of the questions would be.....How would it work when you hit 20 or 100 stories?

Dawg
 
View user's profile Send private message
dad7732







PostPosted: Mon Oct 01, 2007 7:48 pm Reply with quote

Fair question seeing as how I didn't mention it ...

There will be a maximum of 10 stories added/edited by admin, not the users.

Thanks, Jay
 
CodyG
Life Cycles Becoming CPU Cycles



Joined: Jan 02, 2003
Posts: 714
Location: Vancouver Island

PostPosted: Mon Oct 01, 2007 7:56 pm Reply with quote

When it comes to story placement, I've been known to be found mucking around with the sid in the stories table. It is a limited solution which works if I want to make a previous story float to the top by giving it a higher sid.

To put the story at the bottom you would have to have a lower sid, which means putting AUTO INCREMENT in reverse, (which likely isn't possible?) and eventually it will reach 0 anyways. So the concept doesn't work backwards.

Have a happy ravennuking day! I know I did. RavensScripts

_________________
"We want to see if life is ubiquitous." D.Goldin 
View user's profile Send private message
PHrEEkie
Subject Matter Expert



Joined: Feb 23, 2004
Posts: 358

PostPosted: Mon Oct 01, 2007 11:49 pm Reply with quote

Well, here we go... elegant solution or not, this works ! Razz

You will be modifying /modules/News/index.php

Search for the section:
Code:
function theindex($new_topic=0)


In my RN default news index, this is at line 40.

Let's talk logic and theory. Right now, each news story is formatted within a WHILE loop based on the results of a SQL Fetch. The row with all of the individual story elements are fetched, then sent to the function themeindex for formatting. We will break up this loop into 2 parts.

Part one fetches all of the required individual news elements and stores them in a new array. We then reverse ksort that array. Lastly, we use a foreach construct to send each element on to the formatting function.

No other changes to Nuke should be necessary. SID doesn't matter, number of stories on the page shouldn't matter, and user defined number of stories should still function as well (although I will admit that I did NOT thoroughly test this hack under all the above conditions). All stories will be viewed in order from bottom to top, as I interpreted this request to be...

So, starting at around line 130, here's the original section:

Code:
    if ($score != 0) {

        $rated = substr($score / $ratings, 0, 4);
        } else {
            $rated = 0;
        }
        $morelink .= ' | '._SCORE." $rated";
        $morelink .= ')';
        $morelink = str_replace(' |  | ', ' | ', $morelink);
        $morelink = str_replace('( | ', '(', $morelink); //RN0000646
        themeindex($aid, $informant, $datetime, $title, $counter, $topic, $hometext, $notes, $morelink, $topicname, $topicimage, $topictext);
    }
    include_once('footer.php');


Modified code:

Code:
    if ($score != 0) {

        $rated = substr($score / $ratings, 0, 4);
        } else {
            $rated = 0;
        }
        $morelink .= ' | '._SCORE." $rated";
        $morelink .= ')';
        $morelink = str_replace(' |  | ', ' | ', $morelink);
        $morelink = str_replace('( | ', '(', $morelink); //RN0000646
        $news_stories[] = array( 'aid' => $aid,
                                 'informant'  => $informant,
                                 'datetime'   => $datetime,
                                 'title'      => $title,
                                 'counter'    => $counter,
                                 'topic'      => $topic,
                                 'hometext'   => $hometext,
                                 'notes'      => $notes,
                                 'morelink'   => $morelink,
                                 'topicname'  => $topicname,
                                 'topicimage' => $topicimage,
                                 'topictext'  => $topictext
                               );
    }
    krsort($news_stories);
    foreach ($news_stories as $story) {
      themeindex($story[aid], $story[informant], $story[datetime], $story[title], $story[counter], $story[topic], $story[hometext],
                 $story[notes], $story[morelink], $story[topicname], $story[topicimage], $story[topictext]);
    }
    include_once('footer.php');


Load up your main site URL and see if that works for you...

Hello Gaylen my dear friend... I do hope your are well. Very Happy

Hello Chatserv... I bow in respect to the God of Nuke sanitization!

Hi Bob and everyone else... it's been awhile... Wink

PHrEEk
 
View user's profile Send private message
fkelly
Former Moderator in Good Standing



Joined: Aug 30, 2005
Posts: 3312
Location: near Albany NY

PostPosted: Tue Oct 02, 2007 10:48 am Reply with quote

I don't get it. KRSORT, according to the manual, sorts an array by key in reverse order. You have a bunch of keys in the example you cite, but I don't see sid in there at all. Am I missing it?

More to the point, I'm not sure the array is needed at all. If you want the stories sorted reverse order why not just take this code:

Code:
    $result = $db->sql_query('SELECT sid, catid, aid, title, time, hometext, bodytext, comments, counter, topic, informant, notes, acomm, score, ratings FROM '.$prefix.'_stories '."$qdb $querylang".' ORDER BY sid DESC LIMIT '.$oPaginator->getStartRow().','.$storynum);


and change the DESC to ASC.

I personally don't think that's a good solution either except for very limited circumstances. I certainly wouldn't want 3 year old stories on my site appearing first.

To really solve this problem we need to add a sort_order field to the stories table and then change the program(s) to use that ... probably we should sort by sort_order and then sid. Of course this also would mean changing the news input screens to allow a sort_order to be input and then you'd probably want to give some visual display of what the current sort order is so the person putting the news in could see where it fits. And you'd have to figure out whether you want a user submitting an article to be able to determine the sort order or whether that's up to the admin on approving the article. There would probably be other ramifications as well: we'd need to look at the old articles block and really any other place that references the sid field from the stories table.
 
View user's profile Send private message Visit poster's website
PHrEEkie







PostPosted: Tue Oct 02, 2007 11:19 am Reply with quote

fkelly wrote:
I don't get it. KRSORT, according to the manual, sorts an array by key in reverse order. You have a bunch of keys in the example you cite, but I don't see sid in there at all. Am I missing it?


Look at how the array news_stories is built...

news_stories[] = array

Which means news_stories[0] will contain another array in it with story #1, news_stories[1] will contain another array in it with story #2, etc, all the way through the number of stories defined by storynum. The krsort call then reverses all of the story arrays from 0-x to x-0 (all the while not changing ANY of the data held within the inner array), and then we can process them one at a time based on their new ordering.

fkelly wrote:
More to the point, I'm not sure the array is needed at all. If you want the stories sorted reverse order why not just take this code:

[snip ... ]

and change the DESC to ASC.

I personally don't think that's a good solution either except for very limited circumstances. I certainly wouldn't want 3 year old stories on my site appearing first.


Yah, you basically answered your own question there... your newest story would not appear at the bottom once your number of stories exceeded storynum.

fkelly wrote:
To really solve this problem we need to add a sort_order field to the stories table and then change the program(s) to use that ... probably we should sort by sort_order and then sid. Of course this also would mean changing the news input screens to allow a sort_order to be input and then you'd probably want to give some visual display of what the current sort order is so the person putting the news in could see where it fits. And you'd have to figure out whether you want a user submitting an article to be able to determine the sort order or whether that's up to the admin on approving the article. There would probably be other ramifications as well: we'd need to look at the old articles block and really any other place that references the sid field from the stories table.


Well, you kinda lost me there, but nonetheless, making the desired output that difficult is unnecessary here. It is always best to try and solve a request without altering any Nuke tables whatsoever. This was a fairly simple request, the changed code is very small and limited to one section of the file, and there should be no adverse effect on any other section of Nuke or how it works. Upgrading Nuke or applying patches most likely won't break anything. Adding back a snippet of custom code is much easier to deal with than a table crashig with a MySQL INSERT statement that no longer matches the number of fields. In a db intensive piece of software like Nuke, altering a table has far-reaching ramifications to say the least. You will be altering an awful lot of code and chasing bugs for days.

A complete and full ability to move any story anywhere in the sort wouldn't be difficult, really. When you are in Nuke admin and select Blocks management, you get those up/down arrows to move the blocks. The exact same process could be used to move stories up and down at will.

PHrEEk
 
fkelly







PostPosted: Tue Oct 02, 2007 12:35 pm Reply with quote

Okay, I see how your array is built within the while loop, then when the loop ends you sort it with ksort. But why not just change the initial SQL to order by sid ascending? Isn't that the same thing? And yes, you would limit the stories presented to the last $storynum but they would likely be the oldest $storynum stories in your system. I know that was the initial "requirement" that started this thread ... it just seems odd and not very useful to me. To be able to "arrange" the stories in some admin determined sequence could be useful. We are in agreement that it would be a significant change and would take a lot of debugging to get right.

There have been other threads on news module requirements that we would want to revisit before undertaking this kind of change. In Ravennuke we've tried (and succeeded in) keeping the table structures consistent with base PHPnuke to a very large extent. However, there is going to come a point (IMHO) where we need to make a break to improve the functionality without twisting ourselves all around with hacks.
 
PHrEEkie







PostPosted: Tue Oct 02, 2007 1:28 pm Reply with quote

fkelly wrote:
Okay, I see how your array is built within the while loop, then when the loop ends you sort it with ksort. But why not just change the initial SQL to order by sid ascending? Isn't that the same thing?


No, changing the SQL would not be desired here. If I understand the OP's request correctly, he wants the [storynum] number of NEWEST stories displayed upside-down (bottom to top). The SQL fetch based on SID and then sorted ASC would pull the OLDEST stories. They would be correctly ordered to display upside-down, but we don't want the oldest stories, so correct order or not, this SQL fetch is not going to work.

As usual, there are many ways to approach a fetch and then to format the results. Mine listed is only one way...

I have not thought about it hard enough to say for sure, but it seems fairly assured that you could not pull out the x number of NEWEST stories backwards within one SQL statement. The only choice I saw that was quick and convenient was to pull the x number of newest stories into a temporary array, re-sort them backwards, and move on with the formatting. The job must be split into two separate parts.

It would be a good programming challenge to see the different ways to approach this. Do me a favor and apply the hack (backup your news index.php first). Load your page. Does it not work? There is no extra SQL overhead, and the loading of an array real quick adds next to nothing... so the page should not be degraded in speed whatsoever. It's realistically a core nuke call, only the order of the formatting is switched.

fkelly wrote:
And yes, you would limit the stories presented to the last $storynum but they would likely be the oldest $storynum stories in your system. I know that was the initial "requirement" that started this thread ... it just seems odd and not very useful to me.


LOL! Odd... agreed... but 'usefulness' is in the eye of the requestor. I judge not, just try to accomodate within my abilities. Cool

fkelly wrote:
However, there is going to come a point (IMHO) where we need to make a break to improve the functionality without twisting ourselves all around with hacks.


Well, this is less of a workaround, or even hack really... it's a direct edit towards formatted output. No matter if you even designed a new CMS from scratch, some webmaster will want to change how things are output, that is normal and expected. The need to break and go ahead towards altering tables and such, I will agree with you that it is time to do so. I believe Nuke is very near it's EOL based on FB's programming skills. In order to continue growth, implementations of AJAX and more than likely a port of Vbulletin would serve well. At a minimum, the community needs to see a port fairly soon with the new gen phpBB, or Nuke is dead within 2 years.

Regards,
PHrEEk
 
fkelly







PostPosted: Tue Oct 02, 2007 6:35 pm Reply with quote

I will try your hack when I get a chance but it does look to me like it should work (and I'm willing to take your word that it does). I've been working on improving the efficiency of the SQL statements in news/index.php for the next maintenance release of Ravennuke and I've written up something for us to look at for future releases. I'll try to find time to post it in the Forums too, but I don't want to hijack this thread for that purpose. I will just say that FB does a lot of unnecessary SQL calls in News but "fixing" that is something that will require more testing than we probably have time for right now.

Sorry I didn't catch on to everything you were saying right away, it sometimes takes me an iteration or two.
 
Display posts from previous:       
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Ravens PHP Scripts And Web Hosting Forum Index -> RN Enhancement Requests and Suggestions

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©