Advertisement:

Author Topic: Sitemap for 2.0  (Read 2676 times)

Offline Owdy

  • SMF Fossil
  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,633
  • Gender: Male
  • W00t!
    • janoloferiksson on LinkedIn
    • @jaoler on Twitter
Sitemap for 2.0
« on: August 27, 2008, 04:42:13 PM »
Has anyomne updated [Unknown]'s sitemap for SMF 2.0?

Code: [Select]
<?php

require_once('SSI.php');

if (
$modSettings['smfVersion'] < '1.1')
ob_start('ob_sessrewrite');

header('Content-Type: text/plain');

echo 
'<?xml version="1.0" encoding="UTF-8"?' '>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">'
;

$request db_query("
SELECT posterTime
FROM 
{$db_prefix}messages
WHERE ID_MSG >= " 
. ($modSettings['maxMsgID'] - 30) . "
ORDER BY ID_MSG DESC
LIMIT 10"
__FILE____LINE__);
$latest_post_times = array(time());
while (
$row mysql_fetch_assoc($request))
$latest_post_times[] = $row['posterTime'];
mysql_free_result($request);

$request db_query("
SELECT ID_BOARD
FROM 
{$db_prefix}boards"__FILE____LINE__);
$boards = array();
while (
$row mysql_fetch_assoc($request))
{
$request2 db_query("
SELECT posterTime
FROM 
{$db_prefix}messages
WHERE ID_BOARD = 
$row[ID_BOARD]. ($modSettings['totalMessages'] > 100000 "
AND ID_MSG >= " 
. ($modSettings['maxMsgID'] * 0.5) : '') . "
ORDER BY ID_MSG DESC
LIMIT 10"
__FILE____LINE__);
$board_post_times = array(time());
while ($row2 mysql_fetch_assoc($request2))
$board_post_times[] = $row2['posterTime'];
mysql_free_result($request2);

$boards[] = array(
'id' => $row['ID_BOARD'],
'times' => $board_post_times,
);
}
mysql_free_result($request);

$request db_query("
SELECT ID_TOPIC
FROM 
{$db_prefix}topics
ORDER BY numViews + numReplies DESC
LIMIT 20"
__FILE____LINE__);
$topics = array();
while (
$row mysql_fetch_assoc($request))
{
$request2 db_query("
SELECT posterTime
FROM 
{$db_prefix}messages
WHERE ID_TOPIC = 
$row[ID_TOPIC]
ORDER BY ID_MSG DESC
LIMIT 10"
__FILE____LINE__);
$topic_post_times = array(time());
while ($row2 mysql_fetch_assoc($request2))
$topic_post_times[] = $row2['posterTime'];
mysql_free_result($request2);

$topics[] = array(
'id' => $row['ID_TOPIC'],
'times' => $topic_post_times,
);
}
mysql_free_result($request);

$request db_query("
SELECT ID_MEMBER
FROM 
{$db_prefix}members
ORDER BY totalTimeLoggedIn DESC
LIMIT 20"
__FILE____LINE__);
$members = array();
while (
$row mysql_fetch_assoc($request))
{
$request2 db_query("
SELECT posterTime
FROM 
{$db_prefix}messages
WHERE ID_MEMBER = 
$row[ID_MEMBER]. ($modSettings['totalMessages'] > 100000 "
AND ID_MSG >= " 
. ($modSettings['maxMsgID'] * 0.5) : '') . "
ORDER BY ID_MSG DESC
LIMIT 10"
__FILE____LINE__);
$member_post_times = array(time());
while ($row2 mysql_fetch_assoc($request2))
$member_post_times[] = $row2['posterTime'];
mysql_free_result($request2);

$members[] = array(
'id' => $row['ID_MEMBER'],
'times' => $member_post_times,
);
}
mysql_free_result($request);

// First, the forum URL.  Highest priority!
echo '
<url>
<loc>'
$scripturl'</loc>
<lastmod>'
posts_max_time($latest_post_times), '</lastmod>
<changefreq>'
posts_to_freq($latest_post_times), '</changefreq>
<priority>1.0</priority>
</url>'
;

// Now the boards!
foreach ($boards as $board)
{
echo '
<url>
<loc>'
$scripturl'?board='$board['id'], '.0</loc>
<lastmod>'
posts_max_time($board['times']), '</lastmod>
<changefreq>'
posts_to_freq($board['times']), '</changefreq>
<priority>'
posts_to_priority(0.8$board['times']), '</priority>
</url>'
;
}

// Popular topics too...
foreach ($topics as $topic)
{
echo '
<url>
<loc>'
$scripturl'?topic='$topic['id'], '.0</loc>
<lastmod>'
posts_max_time($topic['times']), '</lastmod>
<changefreq>'
posts_to_freq($topic['times']), '</changefreq>
<priority>'
posts_to_priority(0.7$board['times']), '</priority>
</url>'
;
}


echo 
'
</urlset>'
;

function 
posts_max_time($post_times)
{
if (empty($post_times) || count($post_times) == 1)
return gmstrftime('%Y-%m-%dT%H:%M:%S+00:00'time() - 3600 24 10);

return gmstrftime('%Y-%m-%dT%H:%M:%S+00:00'max($post_times));
}

function 
posts_to_priority($base$post_times)
{
if (empty($post_times) || count($post_times) == 1)
return sprintf('%1.1f'$base);

$s = (max($post_times) - min($post_times)) / count($post_times);

if ($s 3600 24)
$mod 0.1;
else
$mod 0;

return sprintf('%1.1f'$base $mod);
}

function 
posts_to_freq($post_times)
{
if (empty($post_times) || count($post_times) == 1)
return 'yearly';

$s = (max($post_times) - min($post_times)) / count($post_times);

// Changes more often than every hour.
if ($s 3600)
return 'always';
elseif ($s 3600 12)
return 'hourly';
elseif ($s 3600 24 4)
return 'daily';
else
return 'monthly';
}

?>

I belive that db_query part is changed?
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Offline Owdy

  • SMF Fossil
  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,633
  • Gender: Male
  • W00t!
    • janoloferiksson on LinkedIn
    • @jaoler on Twitter
Re: Sitemap for 2.0
« Reply #1 on: October 12, 2008, 04:15:56 PM »
Sorry, but bump.
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Offline metallica48423

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,842
  • Gender: Male
  • Professional Multislacker!
    • Zentendo
Re: Sitemap for 2.0
« Reply #2 on: October 12, 2008, 05:31:01 PM »
theres a bit more to it than that.

If i can get some time i might take a crack at rewriting it, but i'm very busy being lazy at the moment :P
Justin O'Leary
Ex-Project Manager
Ex-Lead Support Specialist

Quote
Microsoft wants us to "Imagine life without walls"...
I say, "If there are no walls, who needs Windows?"

Useful Links:
Online Manual!
How to Help us Help you   
Search
Settings Repair Tool
     

Offline Owdy

  • SMF Fossil
  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 15,633
  • Gender: Male
  • W00t!
    • janoloferiksson on LinkedIn
    • @jaoler on Twitter
Re: Sitemap for 2.0
« Reply #3 on: October 12, 2008, 05:33:32 PM »
Ok, thanks M!
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Offline rsw686

  • Sophist Member
  • *****
  • Posts: 1,008
    • The Reptile File
Re: Sitemap for 2.0
« Reply #4 on: October 12, 2008, 06:03:02 PM »
I rewrote it for my SMF 2.0 Beta 3 forum. The first version was just a rewrite, which builds it on the fly, and the second was a package, which builds the sitemap using the scheduled tasks to save resources.

http://wgnrs.dynalias.com/smf2/sitemap.php
http://wgnrs.dynalias.com/smf2/sitemap_1.0.zip
The Reptile File
Everything reptile for anyone reptile friendly

Aquaria Talk
Community for freshwater and saltwater aquariums enthusiasts

Offline SlammedDime

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 10,280
  • School of Air Ride
    • matt.zuba on Facebook
    • @mattzuba on Twitter
Re: Sitemap for 2.0
« Reply #5 on: October 12, 2008, 06:55:39 PM »
Could always use my mod... The only thing that differs in it is priority of links.  I'm working on re-doing that in the next 2.0 release of the mod.
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

Offline metallica48423

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,842
  • Gender: Male
  • Professional Multislacker!
    • Zentendo
Re: Sitemap for 2.0
« Reply #6 on: October 12, 2008, 06:58:04 PM »
Well.. I got it updated... but there's a problem with it as well.  The PROBLEM with it is, is that this mod doesn't seem to care whether the board is supposed to be viewable by guests or not.    I did also fix a bug in unknown's version regarding dividing an odd integer in half and then trying to pass it to a query.

Might i suggest SlammedDime's sitemap mod?
http://custom.simplemachines.org/mods/index.php?mod=755

In any case, here's what I have for the updated script, even if it *is* useless, I was happy i was able to get it updated :)

Code: [Select]
<?php

require_once('SSI.php');

// Need this globaled for the new query structure
global $smcFunc;

if (
$modSettings['smfVersion'] < '1.1')
ob_start('ob_sessrewrite');

header('Content-Type: text/plain');

echo 
'<?xml version="1.0" encoding="UTF-8"?' '>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">'
;

$request $smcFunc['db_query']('''
SELECT poster_time
FROM {db_prefix}messages
WHERE id_msg >= {int:query_where}
ORDER BY id_msg DESC
LIMIT 10'
,
array(
'query_where' => $modSettings['maxMsgID'] - 30,
)
);

$latest_post_times = array(time());

while (
$row $smcFunc['db_fetch_assoc']($request))
$latest_post_times[] = $row['poster_time'];

$smcFunc['db_free_result']($request);

$request $smcFunc['db_query']('''
SELECT id_board
FROM {db_prefix}boards'
,
array(
)
);

$boards = array();
while (
$row $smcFunc['db_fetch_assoc']($request))
{
$request2 $smcFunc['db_query']('''
SELECT poster_time
FROM {db_prefix}messages
WHERE id_board = {int:query_where} 
AND id_msg >= {int:query_and}
ORDER BY id_msg DESC
LIMIT 10'
,
array(
'query_where' => $row['id_board'],
'query_and' => ($modSettings['totalMessages'] > 100000 ? (floor($modSettings['maxMsgID'] * 0.5)) : 0),
)
);

$board_post_times = array(time());
while ($row2 $smcFunc['db_fetch_assoc']($request2))
$board_post_times[] = $row2['posterTime'];

$smcFunc['db_free_result']($request2);

$boards[] = array(
'id' => $row['id_board'],
'times' => $board_post_times,
);
}
$smcFunc['db_free_result']($request);

$request $smcFunc['db_query']('''
SELECT id_topic
FROM {db_prefix}topics
ORDER BY num_views + num_replies DESC
LIMIT 20'
,
array(
)
);

$topics = array();
while (
$row $smcFunc['db_fetch_assoc']($request))
{
$request2 $smcFunc['db_query']('''
SELECT poster_time
FROM {db_prefix}messages
WHERE id_topic = {int:topic}
ORDER BY id_msg DESC
LIMIT 10'
,
array(
'topic' => $row['id_topic']
)
);
   
$topic_post_times = array(time());
while ($row2 $smcFunc['db_fetch_assoc']($request2))
$topic_post_times[] = $row2['poster_time'];

$smcFunc['db_free_result']($request2);

$topics[] = array(
'id' => $row['id_topic'],
'times' => $topic_post_times,
   );
}
$smcFunc['db_free_result']($request);

$request $smcFunc['db_query']('''
SELECT id_member
FROM {db_prefix}members
ORDER BY total_time_logged_in DESC
LIMIT 20'
,
array(
)
);

$members = array();
while (
$row $smcFunc['db_fetch_assoc']($request))
{
$request2 $smcFunc['db_query']('''
SELECT poster_time
FROM {db_prefix}messages
WHERE id_member = {int:query_where} 
AND id_msg >= {int:query_and}
ORDER BY id_msg DESC
LIMIT 10'
,
array(
'query_where' => $row['id_member'],
'query_and' => ($modSettings['totalMessages'] > 100000 ? (floor($modSettings['maxMsgID'] * 0.5)) : 0),
)
);

$member_post_times = array(time());
while ($row2 $smcFunc['db_fetch_assoc']($request2))
$member_post_times[] = $row2['poster_time'];
      
$smcFunc['db_free_result']($request2);

$members[] = array(
'id' => $row['id_member'],
'times' => $member_post_times,
);
}
$smcFunc['db_free_result']($request);

// First, the forum URL.  Highest priority!
echo '
   <url>
      <loc>'
$scripturl'</loc>
      <lastmod>'
posts_max_time($latest_post_times), '</lastmod>
      <changefreq>'
posts_to_freq($latest_post_times), '</changefreq>
      <priority>1.0</priority>
   </url>'
;

// Now the boards!
foreach ($boards as $board)
{
   echo 
'
   <url>
      <loc>'
$scripturl'?board='$board['id'], '.0</loc>
      <lastmod>'
posts_max_time($board['times']), '</lastmod>
      <changefreq>'
posts_to_freq($board['times']), '</changefreq>
      <priority>'
posts_to_priority(0.8$board['times']), '</priority>
   </url>'
;
}

// Popular topics too...
foreach ($topics as $topic)
{
   echo 
'
   <url>
      <loc>'
$scripturl'?topic='$topic['id'], '.0</loc>
      <lastmod>'
posts_max_time($topic['times']), '</lastmod>
      <changefreq>'
posts_to_freq($topic['times']), '</changefreq>
      <priority>'
posts_to_priority(0.7$board['times']), '</priority>
   </url>'
;
}


echo 
'
</urlset>'
;

function 
posts_max_time($post_times)
{
   if (empty(
$post_times) || count($post_times) == 1)
      return 
gmstrftime('%Y-%m-%dT%H:%M:%S+00:00'time() - 3600 24 10);

   return 
gmstrftime('%Y-%m-%dT%H:%M:%S+00:00'max($post_times));
}

function 
posts_to_priority($base$post_times)
{
   if (empty(
$post_times) || count($post_times) == 1)
      return 
sprintf('%1.1f'$base);

   
$s = (max($post_times) - min($post_times)) / count($post_times);

   if (
$s 3600 24)
      
$mod 0.1;
   else
      
$mod 0;

   return 
sprintf('%1.1f'$base $mod);
}

function 
posts_to_freq($post_times)
{
   if (empty(
$post_times) || count($post_times) == 1)
      return 
'yearly';

   
$s = (max($post_times) - min($post_times)) / count($post_times);

   
// Changes more often than every hour.
   
if ($s 3600)
      return 
'always';
   elseif (
$s 3600 12)
      return 
'hourly';
   elseif (
$s 3600 24 4)
      return 
'daily';
   else
      return 
'monthly';
}

?>


« Last Edit: October 12, 2008, 07:00:30 PM by metallica48423 »
Justin O'Leary
Ex-Project Manager
Ex-Lead Support Specialist

Quote
Microsoft wants us to "Imagine life without walls"...
I say, "If there are no walls, who needs Windows?"

Useful Links:
Online Manual!
How to Help us Help you   
Search
Settings Repair Tool