News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

AJAX Recent Topics

Started by live627, July 08, 2008, 07:15:38 PM

Previous topic - Next topic

vladok

author, SMF2.0 RC2.0 released almost 2 months ago. When you plan to update your mod?

Furqon

Quote from: vladok on December 26, 2009, 12:21:48 PM
author, SMF2.0 RC2.0 released almost 2 months ago. When you plan to update your mod?

Just Emulate Package into SMF 2.0 Beta 4

It's running well on SMF 2.0 RC2

ScopeXL

Question,

I am using the code below to insert the recent topics into a block for TinyPortal and am successful, however when the list populates it lists the topics Oldest to Newest (newest being on the bottom) And then as new posts are posted and the AJAX updates, the new posts are placed on top. How do I get this to sort from newest on top to oldest on bottom (like how it works in index.php?action=recenttopics) This is my block code for TinyPortal (its direct from Recent.template.php)


   echo '
      <div class="tborder" ', $context['browser']['needs_size_fix'] && !$context['browser']['is_ie6'] ? 'style="width: 100%;"' : '', '>
         <table border="0" width="100%" cellspacing="0" cellpadding="4" class="bordercolor" id="topicTable">
            <tr>';

   // Are there actually any topics to show?
   echo '
               <td width="15%" class="catbg3"><strong>', $txt['smf82'], '</strong></td>
               <td class="catbg3"><strong>', $txt[118], '</strong></td>
               <td width="50" class="catbg3" align="center"><strong>', $txt[110], '</strong></td>
               <td width="150" class="catbg3" align="center"><strong>', $txt[109], '</strong></td>
               <td width="150" class="catbg3" align="center"><strong>', $txt[22], '</strong></td>
               <td width="16" class="catbg3"></td>';

   // No topics.... just say, "sorry bub".
   if (empty($context['topics']))
      echo '
            </tr>
            <tr id="no_topics">
               <td class="windowbg2" width="100%" colspan="6"><strong>', $txt[151], '</strong></td>';

   echo '
            </tr>';
   
   foreach ($context['topics'] as $topic)
   {
      echo '
            <tr class="windowbg2" id="topic_', $topic['id'], '">
               <td class="smalltext" style="padding-left: 10px; border-bottom: 1px solid rgb(204, 204, 204);">', $topic['board']['link'], '</td>
               <td style="padding-left: 10px; border-bottom: 1px solid rgb(204, 204, 204);">', $topic['link'], '</td>
               <td align="center" class="smalltext" style="border-bottom: 1px solid rgb(204, 204, 204);">', $topic['replies'], '</td>
               <td align="center" class="smalltext" style="border-bottom: 1px solid rgb(204, 204, 204);">', $topic['firstPoster']['link'], '<br />', $topic['firstPoster']['time'], '</td>
               <td align="center" class="smalltext" style="border-bottom: 1px solid rgb(204, 204, 204);">', $topic['lastPoster']['link'], '<br />', $topic['lastPoster']['time'], '</td>
               <td align="center" style="border-bottom: 1px solid rgb(204, 204, 204);"><a href="http://www.bnetweb.org/', $topic['lastPost']['href'], '"><img src="', $settings['images_url'], '/icons/last_post.gif" alt="', $txt[111], '" title="', $txt[111], '" /></a></td>
            </tr>';
   }
   
   echo '
         </table>
      </div>';
   
   // Now for all of the javascript stuff
   echo '
      <script language="Javascript" type="text/javascript"><!-- // -->
         var last_post = ', (!empty($context['last_post_time']) ? $context['last_post_time'] : 0), ';
         var time_interval = ', $settings['number_recent_topics_interval'] * 1000, ';
         var max_topics = ', $settings['number_recent_topics'], ';
         
         var interval_id = setInterval( "getTopics()", time_interval);

         function getTopics()
         {
            if (window.XMLHttpRequest)
               getXMLDocument("', $scripturl, '?action=recenttopics;latest=" + last_post + ";xml", gotTopics);
            else
               clearInterval(interval_id);
         }
         
         function gotTopics(XMLDoc)
         {
            var updated_time = XMLDoc.getElementsByTagName("smf")[0].getElementsByTagName("lastTime")[0];
            var topics = XMLDoc.getElementsByTagName("smf")[0].getElementsByTagName("topic");
            var topic, id_topic, board, subject, replies, firstPost, lastPost, link;
            var myTable = document.getElementById("topicTable"), oldRow, myRow, myCell, myData, rowCount;
           
            // If this exists, we have at least one updated/new topic
            if (updated_time)
            {
               // Update the last post time
               last_post = updated_time.childNodes[0].nodeValue;
               
               // No Messages message?  Ditch it!
               // Note, this should only happen if there are literally zero topics
               // on the board when a user visits this page.
               if (document.getElementById("no_topics") != null)
                  myTable.deleteRow(-1);
               
               // If the topic is already in the list, remove it
               for (var i = 0; i < topics.length; i++)
               {
                  topic = XMLDoc.getElementsByTagName("smf")[0].getElementsByTagName("topic")[i];
                  id_topic = topic.getElementsByTagName("id")[0].childNodes[0].nodeValue;
                  if ((oldRow = document.getElementById("topic_" + id_topic)) != null)
                     myTable.deleteRow(oldRow.rowIndex);
               }
               
               // Are we going to exceed the maximum topic count allowed?
               while (((myTable.rows.length - 1 + topics.length) - max_topics) > 0)
                  myTable.deleteRow(-1);
               
               // Now start the insertion
               for (var i = 0; i < topics.length; i++)
               {
                  // Lets get all of our data
                  topic = XMLDoc.getElementsByTagName("smf")[0].getElementsByTagName("topic")[i];
                  id_topic = topic.getElementsByTagName("id")[0].childNodes[0].nodeValue;
                  board = topic.getElementsByTagName("board")[0].childNodes[0].nodeValue;
                  subject = topic.getElementsByTagName("subject")[0].childNodes[0].nodeValue;
                  replies = topic.getElementsByTagName("replies")[0].childNodes[0].nodeValue;
                  firstPost = topic.getElementsByTagName("first")[0].childNodes[0].nodeValue;
                  lastPost = topic.getElementsByTagName("last")[0].childNodes[0].nodeValue;
                  link = topic.getElementsByTagName("lastLink")[0].childNodes[0].nodeValue;
                 
                  // Now to create the new row...
                  myRow = myTable.insertRow(1);
                  myRow.id = "topic_" + id_topic;
                  myRow.className = "windowbg";
                 
                  // First the Board
                  myCell = myRow.insertCell(-1);
                  myCell.className = "smalltext";
                  myCell.style.paddingLeft = "10px";
                  myCell.style.borderBottom = "1px solid rgb(204, 204, 204)";
                  setInnerHTML(myCell, board);
                 
                  // Then subject
                  myCell = myRow.insertCell(-1);
                  myCell.style.paddingLeft = "10px";
                  myCell.style.borderBottom = "1px solid rgb(204, 204, 204)";
                  setInnerHTML(myCell, subject);
                 
                  // replies
                  myCell = myRow.insertCell(-1);
                  myCell.className = "smalltext";
                  myCell.align = "center"
                  myCell.style.borderBottom = "1px solid rgb(204, 204, 204)";
                  setInnerHTML(myCell, replies);
                 
                  // first post
                  myCell = myRow.insertCell(-1);
                  myCell.className = "smalltext";
                  myCell.align = "center"
                  myCell.style.borderBottom = "1px solid rgb(204, 204, 204)";
                  setInnerHTML(myCell, firstPost);
                 
                  // last post
                  myCell = myRow.insertCell(-1);
                  myCell.className = "smalltext";
                  myCell.align = "center"
                  myCell.style.borderBottom = "1px solid rgb(204, 204, 204)";
                  setInnerHTML(myCell, lastPost);
                 
                  // last post
                  myCell = myRow.insertCell(-1);
                  myCell.align = "center"
                  myCell.style.borderBottom = "1px solid rgb(204, 204, 204)";
                  setInnerHTML(myCell, link);
               }
            }
         }
      // ]]></script>';

synicfan

Quote from: SlammedDime on August 14, 2009, 06:15:39 PM
I've already fixed it for the next version, but due to template changes for 2.0 RC2, a new version won't be released until after that.

does this mean there wont be a SMF2.0 RC2 compatible release?
Are you just going to wait till the next SMF RC is released?

I used your mod on 1.x but Im now using 2.0RC2
thanks!

K4EEO

this seems to work well enough with rc3.. still has the same layout issues as it did with rc2

<div class="navigate_section"> prints out twice.. but i can live with that.

i still wonder why SMF doesn't have this function in the base install.. it seems like an essential feature for any proper forum.

TechPrince

#165
Here is the fixed package for the error mentioned above for RC3

I am facing a different problem, topics are not updating using ajax, IE gave error Message: 'getElementsByTagName(...).0' is null or not an object on the line. Problem is from the Action/SubAction SEF URL Mod.      

var updated_time = XMLDoc.getElementsByTagName("smf")[0].getElementsByTagName("lastTime")[0];

Arantor

Erm, SlammedDime historically has asked people not to upload edited versions of his mods... you can probably expect him to ask you to remove it...
Holder of controversial views, all of which my own.


K4EEO


depth

Quote from: Studio1031 on March 11, 2010, 11:01:23 PMi still wonder why SMF doesn't have this function in the base install.. it seems like an essential feature for any proper forum.

I can not agree any more!!!!

/Christian

Arantor

Also don't forget that as forums grow this will get slower and slower and consume more of the server runtime. I dread to think about it running here.
Holder of controversial views, all of which my own.


YaPaY

First of all, thank you the coder for great mod.

I'm using this mode with RC3, but I need this mode to convert to last topics instead last post section on home page of my forum.

Is there anybody did this, how?

Thanks,

TechPrince

Action SEF URL's causing incorrect url generation,

getXMLDocument("', $scripturl, '?action=recenttopics;latest=" +last_post+ ";xml", gotTopics);

Action SEF URL = "http://localhost/index.php/action,recenttopics/latest,.html" instead of "http://localhost/index.php/action,recenttopics/latest,123456/xml.html"

Then recent topics will not update due to this issue.

live627

the xml bit is required methinks

agent47

I'm using this mod on RC3 and it's working perfectly although since my site is running on Tiny Portal I need to get this display the recent topics on the frontpage. Can someone kindly tell me how that's done, I would greatly appreciate it.

PortaMx is probably the best SMF portal!

live627

Grab the code from the mod and paste it in a custom PHP block... I'm not familiar with TP and have no time to look into it ATM

~DS~

Dream Portal? Or is it already there? :P
"There is no god, and that's the simple truth. If every trace of any single religion were wiped out and nothing were passed on, it would never be created exactly that way again. There might be some other nonsense in its place, but not that exact nonsense. If all of science were wiped out, it would still be true and someone would find a way to figure it all out again."
~Penn Jillette – God, NO! – 2011

live627

* live627 wonders if a DP custom module is implied here

~DS~

Quote from: live627 on September 30, 2010, 06:22:34 PM
* live627 wonders if a DP custom module is implied here
Your mod...into a custom module or better yet already build-in recent topics with ajax enable option. ;)
"There is no god, and that's the simple truth. If every trace of any single religion were wiped out and nothing were passed on, it would never be created exactly that way again. There might be some other nonsense in its place, but not that exact nonsense. If all of science were wiped out, it would still be true and someone would find a way to figure it all out again."
~Penn Jillette – God, NO! – 2011

carinaking

The message time isn't updated correctly - If you don't refresh the recent topics page, the "xx minutes ago" thing doesn't update itself (except for the new topics that popup). Eventually, you'll have a full page with "0 minutes ago". (I know this because I've changed the target of "new post" link to a new window)
_________________
Hence you must select your hxxp:www.carinadresses.com/wedding-accessories.html [nonactive] only after selecting the theme of your wedding.

live627

Let's see. You have Relative Dates installed, right?

Advertisement: