Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
live627 authored Oct 6, 2023
1 parent 2d6cd1a commit 111acef
Show file tree
Hide file tree
Showing 5 changed files with 501 additions and 0 deletions.
82 changes: 82 additions & 0 deletions topic-count-in-profiles/Subs-TCIP.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

class TCIP
{
public static function profile_areas(&$profile_areas)
{
$profile_areas['info']['areas']['summary']['function'] = function(int $memID)
{
global $context, $modSettings, $txt, $user_profile;

summary($memID);
loadLanguage('TCIP');
$context['sub_template'] = 'summary';

// They haven't even been registered for a full day!?
$days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24));
if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1)
$context['member']['topics_per_day'] = $txt['not_applicable'];
else
$context['member']['topics_per_day'] = comma_format($context['member']['topics'] / $days_registered, 3);

$context['tcip_show_topic_count'] = !empty($modSettings['tcip_show_topic_count']);
$context['tcip_show_participated_count'] = !empty($modSettings['tcip_show_participated_count']);
};
}

public static function profile_stats(int $memID)
{
global $context, $modSettings, $smcFunc, $user_info;

$result = $smcFunc['db_query']('user_activity_by_time', '
SELECT
HOUR(FROM_UNIXTIME(poster_time + {int:time_offset})) AS hour,
COUNT(*)
FROM (
SELECT poster_time, id_msg
FROM {db_prefix}messages AS m
JOIN {db_prefix}topics AS t ON m.id_msg = t.id_first_msg
WHERE id_member = {int:current_member}
ORDER BY id_msg DESC
LIMIT 1001
) a
GROUP BY hour',
array(
'current_member' => $memID,
'time_offset' => $user_info['time_offset'] * 3600,
)
);
$maxPosts = $realPosts = 0;
$num_topics_by_time = array();
$context['topics_by_time'] = array();
while ([$hour, $num] = $smcFunc['db_fetch_row']($result))
{
$maxPosts = max($num, $maxPosts);
$realPosts += $num;

$num_topics_by_time[$hour] = $num;
}
$smcFunc['db_free_result']($result);

if ($maxPosts > 0)
for ($hour = 0; $hour < 24; $hour++)
{
$context['topics_by_time'][$hour] = array(
'hour' => $hour,
'hour_format' => stripos($user_info['time_format'], '%p') === false ? $hour : date('g a', mktime($hour)),
'posts' => 0,
'posts_percent' => 0,
'relative_percent' => 0,
'is_last' => $hour == 23,
);

if (isset($num_topics_by_time[$hour]))
{
$context['topics_by_time'][$hour]['posts'] = $num_topics_by_time[$hour];
$context['topics_by_time'][$hour]['posts_percent'] = round(($num_topics_by_time[$hour] * 100) / $realPosts);
$context['topics_by_time'][$hour]['relative_percent'] = round(($num_topics_by_time[$hour] * 100) / $maxPosts);
}
}
loadLanguage('TCIP');
}
}
10 changes: 10 additions & 0 deletions topic-count-in-profiles/TCIP.english.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

$txt['profile_topics_started'] = 'Topics started';
$txt['profile_topics_participated'] = 'Topics participated in';
$txt['tcip_title'] = 'Topic Count in Profiles';
$txt['tcip_enabled'] = 'Enable Topic Count in Profiles';
$txt['tcip_show_topic_count'] = 'Show topics started';
$txt['tcip_show_participated_count'] = 'Show topics participated in';
$txt['tcip_posts'] = 'POSTS';
$txt['tcip_topics'] = 'TOPICS';
225 changes: 225 additions & 0 deletions topic-count-in-profiles/install20.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
<?xml version="1.0"?>
<!DOCTYPE modification SYSTEM "http://www.simplemachines.org/xml/modification">
<modification xmlns="http://www.simplemachines.org/xml/modification" xmlns:smf="http://www.simplemachines.org/">
<id>runic:Topic_Count_In_Profile</id>
<version>2.1</version>

<file name="$sourcedir/Load.php">
<operation>
<search position="after"><![CDATA[ if (!empty($new_loaded_ids) && $set !== 'minimal')]]></search>
<add><![CDATA[ // if this is the user's profile screen, also grab the count of topics they've made
if (!empty($new_loaded_ids) && $set == 'profile')
{
$request = $smcFunc['db_query']('', '
SELECT id_member_started, COUNT( id_topic ) AS topics
FROM {db_prefix}topics
WHERE id_member_started' . (count($new_loaded_ids) == 1 ? ' = {int:loaded_ids}' : ' IN ({array_int:loaded_ids})') . '
GROUP BY id_member_started',
array(
'loaded_ids' => count($new_loaded_ids) == 1 ? $new_loaded_ids[0] : $new_loaded_ids,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
$user_profile[$row['id_member_started']]['topics'] = $row['topics'];
$smcFunc['db_free_result']($request);
$request = $smcFunc['db_query']('', '
SELECT id_member, COUNT(DISTINCT id_topic) AS topic_count
FROM {db_prefix}messages
WHERE id_member' . (count($new_loaded_ids) == 1 ? ' = {int:loaded_ids}' : ' IN ({array_int:loaded_ids})') . '
GROUP BY id_member',
array(
'loaded_ids' => count($new_loaded_ids) == 1 ? $new_loaded_ids[0] : $new_loaded_ids,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
$user_profile[$row['id_member']]['topic_count'] = $row['topic_count'];
$smcFunc['db_free_result']($request);
}
]]></add>
</operation>
<operation>
<search position="before"><![CDATA['real_posts' => $profile['posts'],]]></search>
<add><![CDATA[
'topics' => (isset($profile['topics']) ? comma_format($profile['topics']) : 0),
'topic_count' => (isset($profile['topic_count']) ? comma_format($profile['topic_count']) : 0),]]></add>
</operation>
</file>

<file name="$sourcedir/Profile-View.php">
<operation>
<search position="before"><![CDATA[ if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1)
$context['member']['posts_per_day'] = $txt['not_applicable'];
else
$context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
]]></search>
<add><![CDATA[
if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1)
$context['member']['topics_per_day'] = $txt['not_applicable'];
else
$context['member']['topics_per_day'] = comma_format($context['member']['topics'] / $days_registered, 3);
loadLanguage('TCIP');
]]></add>
</operation>
<operation>
<search position="before"><![CDATA[ // Posting activity by time.
$result = $smcFunc['db_query']('user_activity_by_time', '
SELECT
HOUR(FROM_UNIXTIME(poster_time + {int:time_offset})) AS hour,
COUNT(*) AS post_count
FROM {db_prefix}messages
WHERE id_member = {int:current_member}' . ($modSettings['totalMessages'] > 100000 ? '
AND id_topic > {int:top_ten_thousand_topics}' : '') . '
GROUP BY hour',
array(
'current_member' => $memID,
'top_ten_thousand_topics' => $modSettings['totalTopics'] - 10000,
'time_offset' => (($user_info['time_offset'] + $modSettings['time_offset']) * 3600),
)
);
$maxPosts = 0;
$context['posts_by_time'] = array();
while ($row = $smcFunc['db_fetch_assoc']($result))
{
// Cast as an integer to remove the leading 0.
$row['hour'] = (int) $row['hour'];
if ($row['post_count'] > $maxPosts)
$maxPosts = $row['post_count'];
$context['posts_by_time'][$row['hour']] = array(
'hour' => $row['hour'],
'posts_percent' => $row['post_count']
);
}
$smcFunc['db_free_result']($result);
if ($maxPosts > 0)
for ($hour = 0; $hour < 24; $hour++)
{
if (!isset($context['posts_by_time'][$hour]))
$context['posts_by_time'][$hour] = array(
'hour' => $hour,
'posts_percent' => 0,
);
else
$context['posts_by_time'][$hour]['posts_percent'] = round(($context['posts_by_time'][$hour]['posts_percent'] * 100) / $maxPosts);
}
// Put it in the right order.
ksort($context['posts_by_time']);
]]></search>
<add><![CDATA[
// Posting [topic] activity by time.
$result = $smcFunc['db_query']('user_activity_by_time', '
SELECT
HOUR(FROM_UNIXTIME(m.poster_time + {int:time_offset})) AS hour,
COUNT(m.id_msg) AS post_count
FROM {db_prefix}messages AS m, {db_prefix}topics AS t
WHERE m.id_member = {int:current_member} AND m.id_msg = t.id_first_msg' . ($modSettings['totalMessages'] > 100000 ? '
AND m.id_topic > {int:top_ten_thousand_topics}' : '') . '
GROUP BY hour',
array(
'current_member' => $memID,
'top_ten_thousand_topics' => $modSettings['totalTopics'] - 10000,
'time_offset' => (($user_info['time_offset'] + $modSettings['time_offset']) * 3600),
)
);
$maxPosts = 0;
$context['topics_by_time'] = array();
while ($row = $smcFunc['db_fetch_assoc']($result))
{
// Cast as an integer to remove the leading 0.
$row['hour'] = (int) $row['hour'];
if ($row['post_count'] > $maxPosts)
$maxPosts = $row['post_count'];
$context['topics_by_time'][$row['hour']] = array(
'hour' => $row['hour'],
'posts_percent' => $row['post_count']
);
}
$smcFunc['db_free_result']($result);
if ($maxPosts > 0)
for ($hour = 0; $hour < 24; $hour++)
{
if (!isset($context['topics_by_time'][$hour]))
$context['topics_by_time'][$hour] = array(
'hour' => $hour,
'posts_percent' => 0,
);
else
$context['topics_by_time'][$hour]['posts_percent'] = round(($context['topics_by_time'][$hour]['posts_percent'] * 100) / $maxPosts);
}
loadLanguage('TCIP');
// Put it in the right order.
ksort($context['topics_by_time']);
]]></add>
</operation>
</file>

<file name="$themedir/Profile.template.php">
<operation>
<search position="before"><![CDATA[<dd>', $context['member']['posts'], ' (', $context['member']['posts_per_day'], ' ', $txt['posts_per_day'], ')</dd>';]]></search>
<add><![CDATA[
echo '
<dt>', $txt['profile_topics_started'], ': </dt>
<dd>', $context['member']['topics'], ' (', $context['member']['topics_per_day'], ' ', $txt['posts_per_day'], ')</dd>
<dt>', $txt['profile_topics_participated'], ': </dt>
<dd>', $context['member']['topic_count'], '</dd>';
]]></add>
</operation>
<operation>
<search position="replace"><![CDATA[// Otherwise do!
else
{
echo '
<dl class="stats">';
// The labels.
foreach ($context['posts_by_time'] as $time_of_day)
echo '
<dt>', date('g a', mktime($time_of_day['hour'])), '</dt>
<dd class="statsbar">', !empty($time_of_day['posts_percent']) ? '<span class="left"></span><div style="width: ' . $time_of_day['posts_percent'] . 'px;" class="stats_bar"></div><span class="right"></span><span class="righttext">' . $time_of_day['posts_percent'] . '%</span>' : '', '</dd>';
echo '
</dl>';]]></search>
<add><![CDATA[
// Otherwise do!
else
{
echo '
<p align="center"><b>', $txt['tcip_posts'] ,'</b></p>
<dl class="stats">';
// The labels.
foreach ($context['posts_by_time'] as $time_of_day)
echo '
<dt>', date('g a', mktime($time_of_day['hour'])), '</dt>
<dd class="statsbar">', !empty($time_of_day['posts_percent']) ? '<span class="left"></span><div style="width: ' . $time_of_day['posts_percent'] . 'px;" class="stats_bar"></div><span class="right"></span><span class="righttext">' . $time_of_day['posts_percent'] . '%</span>' : '', '</dd>';
echo '
</dl>
<p align="center"><br /><b>', $txt['tcip_topics'] ,'</b></p>
<dl class="stats">';
// The labels.
foreach ($context['topics_by_time'] as $time_of_day)
echo '
<dt>', date('g a', mktime($time_of_day['hour'])), '</dt>
<dd class="statsbar">', !empty($time_of_day['posts_percent']) ? '<span class="left"></span><div style="width: ' . $time_of_day['posts_percent'] . 'px;" class="stats_bar"></div><span class="right"></span><span class="righttext">' . $time_of_day['posts_percent'] . '%</span>' : '', '</dd>';
echo '
</dl>';
]]></add>
</operation>
</file>
</modification>
Loading

0 comments on commit 111acef

Please sign in to comment.