![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
![[community profile]](https://www.dreamwidth.org/img/silk/identity/community.png)
I've been reading S2 documentation like crazy, and I'm pretty sure the answer is 'no' but I'm going to throw out the question anyway:
Is there any possible way to call functions from a different view than the one you're currently on? For example, the EntryPage class has a function print_comments. But what if I want to print the subjects of the 5 latest comments on the Recent view (maybe in the sidebar)? The RecentPage class doesn't include that function, so I'm assuming there's no way to call it unless the core was rewritten to add it into RecentPage and allow it to take parameters so it knows which comments to pull back. Am I correct in that assumption?
I'll gladly take the question elsewhere if this isn't the right place. Any direction would be so much appreciated.
Is there any possible way to call functions from a different view than the one you're currently on? For example, the EntryPage class has a function print_comments. But what if I want to print the subjects of the 5 latest comments on the Recent view (maybe in the sidebar)? The RecentPage class doesn't include that function, so I'm assuming there's no way to call it unless the core was rewritten to add it into RecentPage and allow it to take parameters so it knows which comments to pull back. Am I correct in that assumption?
I'll gladly take the question elsewhere if this isn't the right place. Any direction would be so much appreciated.
no subject
Date: 2009-05-06 07:01 am (UTC)You're pretty much correct here. You'd have to do some fancy coding in the RecentPage class to have it retrieve comment subjects for each entry on the page. The EntryPage class is only concerned with a single entry, so it's pretty clear what comments it's looking for, but the RecentPage class isn't built to display any comments, so it's not designed to even care about them beyond how many there are.
It's an interesting idea. Do you mean the 5 most recent comments per entry, or the 5 most recent comments on any entry on the page? The latter would be a little trickier, because you'd have to find probably the five most recent comments on each entry, then sort for which of all those are the five absolute most recent.
no subject
Date: 2009-05-06 04:32 pm (UTC)For simplicity sake, let's say it's not limited to 5. Say I want to print all the comment subjects for all the entries on the recent page, like the page summary module. Say I don't even want to break them out into the sidebar, but make them into a hierarchy like:
1st post subject
- 1st post text
- 1st comment subject
- 2nd comment subject
2nd post subject
- etc
I don't mind hacking together some messy coding, but I keep looking at how view-specific the core is and thinking it isn't possible.
Flimsy Suggestion
Date: 2009-05-06 08:03 am (UTC)Look through the Entries[] array of your current instance of the RecentPage class and get the titles of the comments from the Comments[] array in those entries until you have five of them. Build in a flow control statement to stop after five (so you don't search every entry needlessly) and also one to handle an instance of no comments (this covers instances where there are no entries yet, or a page full of entries that don't have any comments).
When I glanced at the language reference for S2, I didn't see a simple way to do this because there isn't an until loop or even a while. You have to make up some kind of bastardized foreach. :( Maybe you can write an if statement that calls return when it finds it has collected five comments.
You might be able to use this function from Haven as a template. It's not the greatest example of code, but I hope it'll get your brain working in the right direction:
Re: Flimsy Suggestion
Date: 2009-05-06 04:35 pm (UTC)My code snippet is similar. I'm using the print_module_pagesummary method as an example, since it prints either the post subjects or the comment subjects depending which page it's called from. I assume to get comment subjects, I would have to put another foreach inside foreach var Entry in the RecentPage section. However...
RecentPage contains Entry, which contains class CommentInfo, which doesn't include any of the content of the comments, just how many there are, whether they're screened, etc. It's the EntryPage class itself that contains class Comments, which does include the comment content. I guess I'm blindly looking for the bridge between the two or if there is one.
Re: Flimsy Suggestion
Date: 2009-05-06 06:08 pm (UTC)Re: Flimsy Suggestion
Date: 2009-05-06 06:37 pm (UTC)Re: Flimsy Suggestion
Date: 2009-05-06 06:46 pm (UTC)no subject
Date: 2009-05-06 04:06 pm (UTC)no subject
Date: 2009-05-06 04:44 pm (UTC)Looking at a community like ask_me_anything, they must use an external service and the API to update their sidebar stats (for example, "Popular Posts"). I guess I'll look in that direction next.
no subject
Date: 2009-05-06 05:49 pm (UTC)However, that only shows the number of comments made on the entry, not the time the last comment was made, or the actual comment metadata/text.
If my guess is correct, and they're doing it with pure s2, then the more accurate description of the information is "most popular posts on the front page/from the first 20 entries", though "of the past hour" probably works given the popularity of the community.
no subject
Date: 2009-05-06 06:50 pm (UTC)The reason I think they're using an external service is because the comment count in the sidebar sometimes lags behind the actual comment count. Also, not all of the popular posts appear on the front page. That makes me think they're scraping the content intermittently somehow and then auto-updating the sidebar.
No idea at this point how that works. Once all the S2 and API documentation is done, will it be clear to me? ;)
no subject
Date: 2009-05-06 06:52 pm (UTC)no subject
Date: 2009-05-07 09:26 pm (UTC)no subject
Date: 2009-05-07 02:28 am (UTC)no subject
Date: 2009-05-07 02:37 am (UTC)(though you can make a new class that extends an existing class).
But I'm afraid I don't see the connection with my comment, and I'm worried that I'm giving the wrong impression of what is/is not possible, somehow.
no subject
Date: 2009-05-07 02:48 am (UTC)no subject
Date: 2009-05-07 02:58 am (UTC)no subject
Date: 2009-05-07 03:05 am (UTC)no subject
Date: 2009-05-07 03:09 am (UTC)no subject
Date: 2009-05-07 03:13 am (UTC)