AJAX Recent Topics

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

Previous topic - Next topic

SlammedDime

You have to edit both, the template and the source file.  Looks like you have the template right, but the source file (BoardIndex.php) needs to be modified too, to perform the SQL query and setup the $context variable.
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

qubbah

How can i make this code to show the latest post in the top not at the bottom?

//recent post
   
   
   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="', $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>';

SlammedDime

I don't understand the question... the latests topics do show at the top, that's the purpose of the mod.
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

qubbah

ok thank u...

how we make when user click the latest post it go to the last real post of that topic not the first post?

SlammedDime

It should be going to the newest post in the topic that that particular user hasn't read yet.  So if there are 5 posts the user hasn't read, it will go to the 5th last post.  If there is only one post the user hasn't read (the last one), that's where it will go.
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

qubbah

Quote from: SlammedDime on August 07, 2008, 03:44:56 PM
It should be going to the newest post in the topic that that particular user hasn't read yet.  So if there are 5 posts the user hasn't read, it will go to the 5th last post.  If there is only one post the user hasn't read (the last one), that's where it will go.

I think i have a problem because when i click Post Subject it is going to the first post for that topic.
If the topic have 20 post, its going to the first post not to the 20.

It is not same when i click last_post.gif its go to the reallast post.

SlammedDime

Sorry for the confustion, you weren't really clear on what you were clicking before, but Yea, that's how it's supposed to work.  I wouldn't recommend changing it as if search engines get ahold of that page, it could provide an easy way for them to grab latest topics on your site.  If you still want, I'll look at the code and let you know how to change it up.
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

qubbah

Quote from: SlammedDime on August 07, 2008, 06:58:32 PM
Sorry for the confustion, you weren't really clear on what you were clicking before, but Yea, that's how it's supposed to work.  I wouldn't recommend changing it as if search engines get ahold of that page, it could provide an easy way for them to grab latest topics on your site.  If you still want, I'll look at the code and let you know how to change it up.

TQ... i will wait for it...

CrimsonSun99

Will there be an update for 2.0.4?

SlammedDime

It shouldn't require one, you are welcome to try to install it.  I will update it however to fix a bug in the SQL query that caused it to lag on large boards, so I would probably wait for that update (perhaps in the next 30 minutes).
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

SlammedDime

SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

tridirk

I like this idea a lot.  But I when I try and install it via the package installer, I get an error message, and am advised not to install it.
Learning SMF..... Thanks for your help!

SlammedDime

I can't really help much if you don't let me know which version of SMF you're running and what file shows the error (or in the case of 2.0, which edit fails).  If you do have 1.1.6, please attach whatever file failed also.
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

tridirk

Hi, Sorry... version 1.1.5

and the error
Learning SMF..... Thanks for your help!

SlammedDime

The manual install instructions are available on the download page for the mod, look at the instructions for index.template.php, there are only two very simple instructions for that file.  Install the mod, ignorning the errors, then go into index.template.php and make the changes prescribed in the instructions.
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

CrimsonSun99

Thank you very much for the update, my users love your mod.

tridirk

Quote from: SlammedDime on September 19, 2008, 02:20:18 PM
The manual install instructions are available on the download page for the mod, look at the instructions for index.template.php, there are only two very simple instructions for that file.  Install the mod, ignorning the errors, then go into index.template.php and make the changes prescribed in the instructions.

Thank you I will give it a go.  I like the idea very much, thanks for setting it up.
Learning SMF..... Thanks for your help!

F4r4Zm0In

I am using smf 1.1.6, using "classic" theme which comes with the default smf installation

while installing AJAX Recent Topics       1.0.1

i have got this >>

QuoteError in Package Installation
Type      Action      Description
1.     Execute Modification     ./index.php     Test successful
2.     Execute Modification     ./Sources/Recent.php     Test successful
3.     Execute Modification     ./Themes/classic/index.template.php     Test failed
4.     Execute Modification     ./Themes/classic/languages/Modifications.english.php     Test successful
5.     Execute Modification     ./Themes/classic/Recent.template.php     Test successful
6.     Execute Modification     ./Themes/classic/Settings.template.php     Test successful
7.     Execute Code     add_settings_1_1.php   

any ideas ???
---------------------
Not Just Another Forum
---------------------

SlammedDime

From my post above...
Quote from: SlammedDime on September 19, 2008, 02:20:18 PM
The manual install instructions are available on the download page for the mod, look at the instructions for index.template.php, there are only two very simple instructions for that file.  Install the mod, ignorning the errors, then go into index.template.php and make the changes prescribed in the instructions.
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

matasanos

other ajax mod that ROCKS!!

THANKS
working fine

Advertisement: