SimplePortal

Customization => Blocks and Modifications => Block Requests => Topic started by: dopeitspaul on August 07, 2014, 03:34:57 AM

Title: Recent Post block auto refresh
Post by: dopeitspaul on August 07, 2014, 03:34:57 AM
Hey everyone I requested this mod on simple machine forum but I was redirected to post the request on this forum.

I want to know how I can make my recent post auto refresh instead of manually refreshing the page to get the recent post updated.

Simliar to this
https://www.youtube.com/watch?v=mTaR1HgFKjE

Can anyone help me? Thanks!
Title: Re: Recent Post block auto refresh
Post by: Chen Zhen on August 07, 2014, 09:22:10 AM
Yes this is possible.
For now I have made something that will work for you that I may develop further at some point.
Please follow these steps:


Custom PHP block code:
Code: [Select]
$_SESSION['blockID'] = 11;
$file = 'recent_posts.php';

global $boarddir;
require_once($boarddir . '/' . $file);

echo '
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>setInterval(function() {$("#sp_recent_reload_' . $_SESSION['blockID'] . '").load("' . $file . '")}, 60000);</script>';




What you do is configure the custom PHP block (shown above) where you want it to appear
 on your forum (leave this block enabled).
You will have to adjust the disabled posts/topics block settings to what is desired for display.

Regards.
Title: Re: Recent Post block auto refresh
Post by: dopeitspaul on August 07, 2014, 01:15:03 PM
It works but theres a problem. It won't stop refreshing! The it keeps showing the refreshing icon and won't stop

here's the image of the icon I'm talking about
Title: Re: Recent Post block auto refresh
Post by: dopeitspaul on August 07, 2014, 01:55:27 PM
Update, now sometimes the index page won't load.

You think theres a way to make only the <div> of that block auto refresh instead of the whole page?

Title: Re: Recent Post block auto refresh
Post by: Chen Zhen on August 07, 2014, 03:57:20 PM
It does not refresh the entire page. The jQuery code within the block only reloads the php file which does the db query and then displays the data.
Either you did not follow instructions correctly or perhaps there is something else on the page conflicting with the jQuery load somehow.

I just tested this locally and on my live forum whereas it works fine.
I adjusted the attached file slightly since I had the db query for the block misconfigured slightly which is now fixed. Although this would not have caused the issue you describe as it was merely setting the necessary variables as defaults before my fix. I also adjusted the block code to refresh every 60000 mS which is less strain on the server.
Try the new file attachment & block code. 

Note that this:
Code: [Select]
$_SESSION['blockID'] = 11;

.. from the example has to be set to your specific block_id and not 11 (unless it happens to be that block_id).
Title: Re: Recent Post block auto refresh
Post by: dopeitspaul on August 07, 2014, 05:54:04 PM
It works! Thanks!

I got a couple more questions.

- How can I remove this (circled in purple). Not a huge when of it. I know theres gonna be some topic titles with a long name. Is it possible to set a character limit on the block. For example, when a character exceeds the limit it ends up as [...] instead?

(http://i218.photobucket.com/albums/cc263/xguillotinezx/phpbb/Screenshot2014-08-07at24356PM_zps793f7367.png)




- And I was wondering if I could add the poster's avatar on the very left side of the block? Was thinking I should add like a 25px x 25px avatar icon.


Please let me know, appreciate all the help so far thanks!
Title: Re: Recent Post block auto refresh
Post by: Chen Zhen on August 07, 2014, 06:43:38 PM
I'll post back with an adjustment to show the avatar when I have time later tonight.
To get rid of the scroll bar edit the custom PHP block and on the bottom right corner you will see an input titled Custom Body Style.
Put the following css attribute code in that input and save the block again:
Code: [Select]
overflow: hidden;

Regards.
Title: Re: Recent Post block auto refresh
Post by: Chen Zhen on August 08, 2014, 12:13:01 AM
Use the file I attached to this post and this new block code:
Code: [Select]
$_SESSION['blockID'] = 20;
$_SESSION['avatar_height'] = 25;
$_SESSION['avatar_width'] = 25;
$seconds_delay = 60;

$file = 'recent_posts.php';

global $boarddir, $context;
require_once($boarddir . '/' . $file);
$delay = !empty($seconds_delay) ? ((int)$seconds_delay * 1000) : 60000;
echo '
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>setInterval(function() {$("#sp_recent_reload_' . $_SESSION['blockID'] . '").load("' . $file . '")}, ', $delay, ');</script>';




You now enter the image dimensions and the delay time (in seconds) within the block code shown above.  For this example I selected 25 x 25 (px) for the avatar images and a 60 second delay time.
Do not forget to adjust $_SESSION['blockID'].
If the height or width is set to 0 or not included it will not display any user avatars.


Regards.
Title: Re: Recent Post block auto refresh
Post by: dopeitspaul on August 08, 2014, 01:49:28 AM
Somehow it's not working. I put the attachment file on my ftp and overwrote it on the old file. Then made a php block with the id too.

It keeps saying
"Database error in block code. Please check the code."
Title: Re: Recent Post block auto refresh
Post by: Chen Zhen on August 08, 2014, 09:20:58 AM
I made a minor typo in the block code from the previous post.
Also I added another condition in the php file although Imo it wasn't entirely necessary.
Try to use what is posted in that block code now and the newer file.

Regards.
Title: Re: Recent Post block auto refresh
Post by: dopeitspaul on August 08, 2014, 01:54:33 PM
It's working thanks!

But the aligning has one thing overlapping the other.
I noticed on the php file I downloaded. There were some class in the file like <td class="sp_recent_info sp_right">, and <td class="sp_recent_icon sp_center">

Where in the css files can I edit those? I even tried adding my own div class on the file but nothing happened

Also is there a way I can add a character limit on the topic title followed by a "..."?
Title: Re: Recent Post block auto refresh
Post by: Chen Zhen on August 08, 2014, 03:20:05 PM

For the compact view (side block) I attempted to use some css to center the avatar compared to the text to the right if it however I only tested this in the Chrome browser. You can adjust the em measurement to a lesser amount or omit the css for the avatar altogether.

Within the php file look for this:
Code: [Select]
<span style="position: relative;bottom: -0.5em;">

Either change it to ie. -0.2em or perhaps just omit the css and change it to:
Code: [Select]
<span>

Omitting the css for that span container will cause the bottom of the image to be aligned with the text beside it.

Regards.
Title: Re: Recent Post block auto refresh
Post by: Chen Zhen on August 08, 2014, 03:32:32 PM
Here is another block code & file with some adjustments.
The newer file will now use the SMF default theme's post icon in place of an avatar when a user does not have one selected. Imo it is aesthetically more sound that way.

Code: [Select]
$_SESSION['blockID'] = 20;
$_SESSION['avatar_height'] = 25;
$_SESSION['avatar_width'] = 25;
$seconds_delay = 60;

$file = 'recent_posts.php';

global $boarddir, $context;
require_once($boarddir . '/' . $file);
$delay = !empty($seconds_delay) ? ((int)$seconds_delay * 1000) : 60000;
echo '
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>setInterval(function() {$("#sp_recent_reload_' . $_SESSION['blockID'] . '").load("' . $file . '")}, ', $delay, ');</script>';
Title: Re: Recent Post block auto refresh
Post by: dopeitspaul on August 08, 2014, 04:33:49 PM
How can I align the Topic, Name, and Time, and move it more on the right?


In the php file I was playing around with this.

Code: [Select]
(!empty($avatar[$item['poster']['id']]) ? '<span style="position: relative;bottom: -0.1em;">' . $avatar[$item['poster']['id']] . '&nbsp;</span>' : ''), '<a href="', $item['href'], '">', $item['subject'], '</a> <span class="smalltext">', $txt['by'], ' ', $item['poster']['link'], $item['new'] ? '' : ' <a href="' . $scripturl . '?topic=' . $item['topic'] . '.msg' . $item['new_from'] . ';topicseen#new" rel="nofollow"><img src="' . $settings['lang_images_url'] . '/new.gif" alt="' . $txt['new'] . '" border="0" /></a>', '<br />[', $item['time'], ']</span><br />', empty($item['is_last']) ? '<hr />' : '';

I removed the "span class" and changed it to "span style" and then I started adding some css codes in it but nothing happened. I thought it would work because you were allowed to do it in regards to the avatar.

Anyway here's how it looks like

(http://i218.photobucket.com/albums/cc263/xguillotinezx/phpbb/Screenshot2014-08-08at11335PM_zps6689b655.png)

Here's an idea of how I wanted it to look like

(http://i218.photobucket.com/albums/cc263/xguillotinezx/phpbb/sample_zpsccd62637.png)

Is there a way I can add my own css codes to the Title, Name, and Date in order for me to make this happen?
Title: Re: Recent Post block auto refresh
Post by: Chen Zhen on August 08, 2014, 06:25:29 PM
You need to display the compact block html in a table or use css elements to mimic one.
Also your example posted at SMF uses the text of Re: and not Topic: and does not include the time. 
Is the image you gave in the last post the exact specifics of what you request?

I am assuming you are using this in a side block (compact view). Do you have side blocks on either side of your forum or just on one side? The reason I ask this is because the example you posted at SMF  has blocks only on the right side and limits topic/subject length for aesthetics. If you want it to appear like this then I need to know how many characters to limit it to or perhaps I can include that integer at the start of your block code which you can adjust.

If you have just right blocks and I limit the character length for the lines containing the topic and member those lines that exceed the limit will be finished with three dots ( ... ). However this will not look proper for the date/time display if that occurs. May I suggest a different date/time format? If I make it slashes for that, how do you want it displayed? d/m/y ??
Title: Re: Recent Post block auto refresh
Post by: dopeitspaul on August 08, 2014, 08:01:15 PM
You need to display the compact block html in a table or use css elements to mimic one.
Is the image you gave in the last post the exact specifics of what you request?

Alright, how do I do that?
And not exactly as the image above. I put the example below


Quote
I am assuming you are using this in a side block (compact view). Do you have side blocks on either side of your forum or just on one side? The reason I ask this is because the example you posted at SMF  has blocks only on the right side and limits topic/subject length for aesthetics. If you want it to appear like this then I need to know how many characters to limit it to or perhaps I can include that integer at the start of your block code which you can adjust.

I'm only using the right side block for the recent post. And yeah, can you just intergrate the character limit on the block code. Here's the link to my forum: http://indieraptalk.com/forum/

Quote
If you have just right blocks and I limit the character length for the lines containing the topic and member those lines that exceed the limit will be finished with three dots ( ... ). However this will not look proper for the date/time display if that occurs. May I suggest a different date/time format? If I make it slashes for that, how do you want it displayed? d/m/y ??

You think it's possible to just show the Day and the hours? 
Here's an example:

a   Re: SimplePortal...
v   By: Dopeitspaul
y   Monday | 4:00PM

And when it says the days like "monday" "tuesday" etc, can you make it bold too just like when "today" is displayed.

Thanks!

Take your time, I feel bad for asking all of these request

Title: Re: Recent Post block auto refresh
Post by: Chen Zhen on August 08, 2014, 08:21:59 PM

Quote
a   Re: SimplePortal...
v   By: Dopeitspaul
y   Monday | 4:00PM

What is a, v and y ??
Is that literally what you want?
Title: Re: Recent Post block auto refresh
Post by: dopeitspaul on August 08, 2014, 08:31:45 PM

Quote
a   Re: SimplePortal...
v   By: Dopeitspaul
y   Monday | 4:00PM

What is a, v and y ??
Is that literally what you want?

Haha sorry, it's just an example of the height of the avatar. "avy"
Title: Re: Recent Post block auto refresh
Post by: Chen Zhen on August 08, 2014, 08:45:33 PM
A new file is attached along with the block code shown below.

PHP Block code:
Code: [Select]
$_SESSION['blockID'] = 20;
$_SESSION['avatar_height'] = 25;
$_SESSION['avatar_width'] = 25;
$_SESSION['char_limit'] = 30;
$seconds_delay = 60;

$file = 'recent_posts.php';

global $boarddir, $context;
require_once($boarddir . '/' . $file);
$delay = !empty($seconds_delay) ? ((int)$seconds_delay * 1000) : 60000;
echo '
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>setInterval(function() {$("#sp_recent_reload_' . $_SESSION['blockID'] . '").load("' . $file . '")}, ', $delay, ');</script>';

You can adjust that character limit at the top of the block code. For this example I used a 30 character limit (for topic name and author name) which you can adjust to what works best for your forum.

Regards.
Title: Re: Recent Post block auto refresh
Post by: dopeitspaul on August 08, 2014, 09:35:36 PM
Thanks! The aligning looks great.

There's a couple problems I noticed though. Somehow when I post for today, the day says "Wednesday" instead of "today". But the old post that aren't from today is accurate though.

And I tested it out if it would auto refresh but somehow its not doing it. I have one tab open waiting for it to refresh while I have another tab making a post but nothings happening. I even waited 60 seconds just like the code says too.
Title: Re: Recent Post block auto refresh
Post by: Chen Zhen on August 08, 2014, 11:02:25 PM
Here is a new block code & a new file is attached.

PHP Block Code:
Code: [Select]
/* adjustable variables */

$block_id = 11;
$avatar_height = 25;
$avatar_width = 25;
$char_limit = 25;
$seconds_delay = 60;

$file = 'recent_posts.php';

/* do not edit below this line */
global $boarddir, $context;
list($_SESSION['blockID'], $_SESSION['avatar_height'], $_SESSION['avatar_width'], $_SESSION['char_limit']) = array($block_id, $avatar_height, $avatar_width, $char_limit);
require_once($boarddir . '/' . $file);
$delay = !empty($seconds_delay) ? ((int)$seconds_delay * 1000) : 60000;

echo '
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">setInterval(function() {$("#sp_recent_reload_' . $block_id . '").load("' . $file . '")}, ', $delay, ');</script>';



Use the file I attached as is without altering it to see if it functions properly.

Regards.
Title: Re: Recent Post block auto refresh
Post by: Chen Zhen on August 09, 2014, 12:14:57 AM

 :0 The text of "at" within the date variable was giving an incorrect value when I used strtotime on it because those characters were not escaped.
Anyhow, I have fixed the file. Try the attachment to the last post again as I have recently updated it.
Title: Re: Recent Post block auto refresh
Post by: dopeitspaul on August 09, 2014, 12:40:30 AM
^ Thanks I was going to mention about the time but you fixed it.

I don't know why but before you uploaded the new file the auto refresh was working fine. But then the new file you just uploaded, it stopped auto refreshing again. I didn't change anything in the php file either.
Title: Re: Recent Post block auto refresh
Post by: Chen Zhen on August 09, 2014, 12:47:15 AM

I updated the previous file again so it says "Today at ..." when someone hovers on the date.
I just tested this and it is working fine for me atm.

Regards.
Title: Re: Recent Post block auto refresh
Post by: dopeitspaul on August 09, 2014, 02:35:33 AM
Everythings looking good thanks !

Do you happen to know why the time messes up whenever I try to edit the php? I tried editing and then each time showed was "Wednesday 4:00pm"

I backspace all the words I typed and have it back to normal but the time is still messed up.

The only solution was to download the php file again, and put it in the ftp.

I never knew things like that can happen. First time experiencing it.
Title: Re: Recent Post block auto refresh
Post by: dopeitspaul on August 12, 2014, 01:04:00 PM
Help, this is the time error I was talking about.

Wednesday 4:00PM just started appearing on my site

(http://i218.photobucket.com/albums/cc263/xguillotinezx/phpbb/Screenshot2014-08-12at100046AM_zps5a2316ab.png)
Title: Re: Recent Post block auto refresh
Post by: Chen Zhen on August 12, 2014, 04:13:59 PM
dopeitspaul,

  Imo the php file code is being adjusted & causing the issue. This does not occur if you use the file I provided without changing it. Ii is difficult to keep posting new files as you periodically change your preference for the date format and/or title/hover format which I have witnessed by checking up on your site.
 
Title: Re: Recent Post block auto refresh
Post by: dopeitspaul on August 12, 2014, 05:47:35 PM
God damn, I screwed up. Sorry. Now the title of the topic is screwed up too. I tried downloading your attachment again but still resulted the same. Can you attach the same file but with some changes?

(http://i218.photobucket.com/albums/cc263/xguillotinezx/phpbb/Screenshot2014-08-12at23250PM_zps9a13362c.png)

First row with the title topic, can you make the font size 11px and bold?

Second row with the author, can you make the font size 10px?

Third row with the date, can you the font size 10px? This time without the bold and the "|" inbetween.

And can you remove the "<hr />" line.
As you can see here I removed the line. I replaced it with a <br /> but I'm not even sure if that did anything

(http://i218.photobucket.com/albums/cc263/xguillotinezx/phpbb/Screenshot2014-08-12at24147PM_zps4676ab2c.png)

If you can re upload it again, I promise I won't touch the file ever. Thanks!
Title: Re: Recent Post block auto refresh
Post by: Chen Zhen on August 12, 2014, 06:44:30 PM
Quote
Imo the php file code is being adjusted & causing the issue. This does not occur if you use the file I provided without changing it.


  You can edit your own files and what I meant was that your issues with the display do not appear to be caused by what I have posted. I have been testing the same file for days now on live & local installs.
 
Title: Re: Recent Post block auto refresh
Post by: Chen Zhen on August 12, 2014, 07:27:59 PM
  The auto refresh of the block appears to be working when I test it.
For testing I seem to have no issues with the display date for today or any other day thus far.
Here is another file that may resolve the date display issue.
Title: Re: Recent Post block auto refresh
Post by: Chen Zhen on August 12, 2014, 07:45:29 PM
I can see you are attempting to manually edit the title display of the time.
Imo you are editing $item['time'] directly? This could be why it is not display properly for you.
The file in the last post has been updated yet again.

I edited the display & title to what you are attempting to change it to.
Use the following lines of code to change the formats:
Code: [Select]
if (stripos($item['time'], 'today') !== false)
{
$display = 'Today ' . date('h:i A', strtotime($item['time']));
$display_title = 'Today ' . date('h:i A', strtotime($item['time']));
}
else
{
$display = date('l h:i A', strtotime($item['time']));
$display_title = date('M d, Y / D h:i A', strtotime($item['time']));
}

Here is a link regarding PHP date syntax:
http://php.net/manual/en/function.date.php
Title: Re: Recent Post block auto refresh
Post by: dopeitspaul on August 12, 2014, 09:33:46 PM
Sorry for some reason, nothing changed.
I'm currently using the attachment you recently uploaded.

Here's what the code looks like regarding the time

(http://i218.photobucket.com/albums/cc263/xguillotinezx/phpbb/Screenshot2014-08-12at61426PM_zps9b8cf8fe.png)

I have no idea why the date on the yellow block is displayed like that when I hover my mouse on that date. I just noticed it when taking this screen shot.


What I noticed before. Is that if I replaced a line with something else. The line that I replaced, will sometimes reappear whenever I open the file up again. Only sometimes though. Like for example I put the file you recently attached to my ftp replacing the old. But somehow it still had this code when I opened it.

Code: [Select]
foreach ($items as $item)
{
if (strpos($item['time'], $txt['today']) !== false)
$day = 'Today';
else
$day = date('l', strtotime(strip_tags($item['time'])));

$item['time'] = str_replace(array('<strong>', '</strong>'), '', $item['time']);
echo '

But I copy all from your recently uploaded file and pasted it on the php file in ftp. And the screenshot you see is the result. So maybe there's something wrong with my file since that glitch happens?

Here's an attachment of my php
Title: Re: Recent Post block auto refresh
Post by: Chen Zhen on August 12, 2014, 09:39:02 PM
Quote
But I copy all from your recently uploaded file and pasted it on the php file in ftp. And the screenshot you see is the result. So maybe there's something wrong with my file since that glitch happens?

  Are you saying you are manually copying the actual code or the file itself? This statement sounds as though you are copying the code from the file into another. If you are using a proper editor like Notepad++ (NOT notepad) that would be ok I suppose but is not necessary. You should be downloading the file and then uploading that file to your main forum directory.

  If you attempted to copy/paste/edit the actual code with an improper editor this would cause character code issues and will not work properly. Also I changed the file since last you download it so you should d/l it yet again.
 
Title: Re: Recent Post block auto refresh
Post by: dopeitspaul on August 12, 2014, 10:07:39 PM
Yeah, I upload your attachment to my ftp. But sometimes, right when I open the file without any edits, the file might still have some codes from the old file. But this only happens sometimes though. I just thought of telling you this because maybe it was the reason why this problem is happening.

Anyway, I uploaded the file you just attached. Its still the same result. Damnit  :dead:

Title: Re: Recent Post block auto refresh
Post by: Chen Zhen on August 12, 2014, 10:21:35 PM

It is my fault for using the time index from the array instead of the timestamp.
The format I was attempting to convert from $item['time'] was returning as false (rendering the Epoch start which is Wed, Dec 31, 1969) because it could not understand the commas within that particular date format. I did not realize the array contains the actual timestamp which is what should be used. My apologies for that .. I should have printed the full array prior to this to notice it.

Try the attachment to this file which should work for you now.
Title: Re: Recent Post block auto refresh
Post by: dopeitspaul on August 12, 2014, 10:36:24 PM
It's working now, thanks!

Will get back to you if anything happens. Not gonna bother touching the file
SimplePortal 2.3.8 © 2008-2024, SimplePortal