UBB.Dev
Custom Islands.

More and more news websites are presenting the topics of interest in various ways and they are eye catching.

We have Popular Topics
But its very static as popular get more popular if there in a visible list. If this became Popular topics today or this week then its would be more interesting to use and follow.

Most Read : Today / This Week
Would in my opinion be a good addition to the Post islands.

Most Replied : This Week
Would also engage users and members to get involved.

I cant do advanced code so I wonder if the idea could gain any momentum ?
Yeahhhh I got it to work smile

Very easy and frustrating to know that a dead duck feature is now very active again.

Ive set mine up to look up 1 day.
I'm sure there is a more "1 day" way of doing this but hey ho.

Find file
/cache_builders/popular_topics.php


PHP Code

<?php
// Script Version 7.5.8

if (!defined('UBB_MAIN_PROGRAM')) {
exit;
}
//-------------------------
$topic_created = strtotime('-1 days'); // ADD THIS
//-------------------------
// Need to move this into the config
$limit = 10;

// Exclude forums?
$notin = "";
if (
$config['EXCLUDE_POPULAR']) {
$notin = "and f.FORUM_ID not in ({$config['EXCLUDE_POPULAR']})";
}
// end if

$query = "
SELECT t.TOPIC_SUBJECT, t.TOPIC_VIEWS, t.POST_ID
FROM
{$config['TABLE_PREFIX']}TOPICS t,
{$config['TABLE_PREFIX']}POSTS p,
{$config['TABLE_PREFIX']}FORUMS f,
{$config['TABLE_PREFIX']}USERS u
WHERE t.FORUM_ID = f.FORUM_ID
AND t.TOPIC_IS_APPROVED = 1
AND t.TOPIC_LAST_POST_ID = p.POST_ID
AND t.TOPIC_LAST_POSTER_ID = u.USER_ID
AND t.TOPIC_CREATED_TIME >=
$topic_created
$notin
ORDER BY t.TOPIC_VIEWS DESC
LIMIT
$limit
"
;
$sth = $dbh -> do_query($query,__LINE__,__FILE__);
$topics = array();
$i = 0;
while(list(
$sub,$views,$pid) = $dbh -> fetch_array($sth)) {
$topics[$i]['subject'] = $sub;
$topics[$i]['views'] = $views;
$topics[$i]['post'] = $pid;
$i++;
}
// end while

$smarty->assign("topics",$topics);

$island = $smarty->fetch("island_popular_topics.tpl");

lock_and_write("{$config['FULL_PATH']}/cache/popular_topics.php",$island);

@
chmod("{$config['FULL_PATH']}/cache/popular_topics.php",0666);

?>




Ive added these two lines

PHP Code
//-------------------------
$topic_created = strtotime('-1 days'); // ADD THIS
//-------------------------


PHP Code
AND t.TOPIC_CREATED_TIME >= $topic_created // ADD into the SQL Query 

Use the control panel settings to tweak the Excluded Forums and Cache time.
Part 2 weekly Most popular (well last 7 days).
And Ive hijacked a existing island so cache is still valid and working. And you can control the cache time from the control panel.

Whats involved ?

We hijack Top Posters island as its static and boring.
We add a New Language text for the island.
Update the Language file so Top posters is renamed to Weekly Popular.
We duplicate and exiting tpl file and add a tiny tweak.

* * * * * * * * * *
NOTICE : I'm no expert on this so will say its probably can be improved on but Its above my pay grade lol.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

You can do this Live if you do not have "Top Posters Island" on view.

1. find /cache_builders
2. Look for the following files.

popular_topics.php (its the file from my first hack above).
top_posters.php

make a backup of top_posters.php

Open both files and copy the contents from popular_topics.php into top_posters.php

We need to edit a couple of lines in top_posters.php


Change the -1 to -7
Code
//-------------------------
$topic_created = strtotime('-1 days'); // ADD THIS
//-------------------------

Scroll to the bottom of the file.

Code
$smarty->assign("topics",$topics);

$island = $smarty->fetch("island_popular_topics.tpl");

lock_and_write("{$config['FULL_PATH']}/cache/popular_topics.php",$island);

@chmod("{$config['FULL_PATH']}/cache/popular_topics.php",0666);

change to

Code
$smarty->assign("topics",$topics);

$island = $smarty->fetch("island_popular_topics_week.tpl");

lock_and_write("{$config['FULL_PATH']}/cache/top_posters.php",$island);

@chmod("{$config['FULL_PATH']}/cache/top_posters.php",0666);

Close and Save.

3. Next we create a new tpl file.

Navigate to templates/default
find island_popular_topics.tpl

copy and paste to make a new file called island_popular_topics_week.tpl

You should now have these two files

island_popular_topics_week.tpl
island_popular_topics.tpl

open up the island_popular_topics_week.tpl

we need to modify 1 line in there for the language file update.

find
Code
<?php echo $ubbt_lang['POPULAR_TOPICS'] ?>
and change to
Code
<?php echo $ubbt_lang['POPULAR_TOPICS_WEEK'] ?>

save and close

Make sure your do not have "Top Posters" island active just yet.

Upload the files as there are only changes in the control panel to make now.


UBB Control panel.

language editor search for popular and then click on edit (it should land you at portal_islands.php)

Dont copy and paste the text from POPULAR_TOPICS as it will kill your island as its not parsing in to the language editor properly but this is the work around.

at the bottom empty spaces

KEY
POPULAR_TOPICS_WEEK
Description just put a . (Full stop).
Then update and it will update with out an issue.
You can now copy and paste the similar text from the POPULAR_TOPICS description field and update.

Almost there.

Control panel Portal Layout. Over to the right side click on External view.
It will probably show the original top posters.
Clear the cache.
Go back and click on external view and you should now see the weekly most viewed topics.


FINAL
is just house work really.
Portal Settings update the cache setting for "Top posters"
Language file editor do searches to edit the control panel display from "Top Posters" to "Weekly most popular".

I think that's all of it.

* You can modify the island files in the cache builders to change the limits on how many should be visible for faster or slower forums.

Why re invent the wheel when its been half done.


G !
Feel free to tidy this post / topic smile

Enjoy !
thumbsup
thumbsup thumbsup
Im please to confirm this works with 7.6.1.1 (patched).

I'ts been a while as you can see from the date I added this one with my limited knowledge.

Ive added a few Language File Tweaks I have made, this may confuse or simplify for you ?
For me it simplified as I could follow.

Code


Most Read (Views 24hrs).

Language Files
Search - change - KEY
Search "Popular Topics" change to "Most Read" (POPULAR_TOPICS)
Search "Popular Topics" Change to "Views 24hrs" (POPULAR_TOPIC VIEWS)
Search "Popular Topics" change to "Popular Topics (24hrs)" (popular_topics)
Search "Popular Topics" change to "Exclude Popular Topics (24hrs) In These Forums" (POPULAR)
Search "Popular Topics" change to "Popular Topics (24hrs)" (popular_topics)

---
Most Read (Views 7days)
language File Search "Popular Topics" (portal_islands.php)
create a new KEY (POPULAR_TOPICS_WEEK) and new STRING "Popular Topics"

create POPULAR_TOPICS_VIEWS_WEEK and a new STRING "Views 7days"

I hope one day that this could find its way into a stock release wink

The beauty with this is that you can select and de-select the forums to be show,

The one thing i could not work out ?

Moving a listed topic in the 24hr island. It would show up twice with a count starting from zero.
So i would make sure the link would be deleted in 24hrs..
Not sure how to get around that one .....
If you move without leaving a pointer its just fine.

Enjoy

Attached picture popular-7days.PNG
Attached picture popular-24hrs.PNG
© UBB.Developers