|
Tempo fa ho avuto la necessità di scrivere un generatore di Google Sitemaps per un forum phpBB, versione 2, hostato su Aruba.it con hosting Windows, che usa MySQL come Database. Il Forum ha sempre funzionato senza problemi, tranne l'impossibilità di usare il mod_rewrite per le URL. Al momento di dover generare la Sitemap mi sono trovato davanti al problema di doverla gestire con codice ASP. Ho preso allora spunto dal codice di un Sitemap Generator preesistente, per modificarlo leggermente e adattarlo al forum phpBB. Il mio codice prende tutti i forum e genera i link a tutti i post, non tiene in considerazione forum nascosti o bloccati. Inoltre, come detto sopra, non c'è riscrittura delle URL in quanto il forum gira su Hosting Windows 'MODIFICA IN BASE ALLA TUA CONNESSIONE <!--#include file="MyConnections.asp" --> <% MAXURLS_PER_SITEMAP = 50000 'MODIFICA IL PERCORSO DEL TUO SITO FORUM baseurl="http://www.yoursite.com/Forum/viewtopic.php?t="
strsql = "SELECT * FROM phpbb_topics"
utcOffset=1 response.ContentType = "text/xml" response.write "<?xml version='1.0' encoding='UTF-8'?>" response.write "<urlset xmlns='http://www.google.com/schemas/sitemap/0.84'>"
Set conn = Server.CreateObject("ADODB.Connection") conn.Open MM_conn_MySql_STRING Set rs = Server.CreateObject("ADODB.Recordset") rs.Open strsql, conn
Do while not rs.eof if URLS<MAXURLS_PER_SITEMAP then id_page=(rs("topic_id")) filelmdate=date() priority=1 if not isdate(filelmdate) then filelmdate=now() filedate=iso8601date(filelmdate,utcOffset) if priority="" or priority>1.0 then priority="1.0" response.write "<url><loc>"&(baseurl&id_page)&"</loc><lastmod>"&filedate&"</lastmod> <priority>"&priority&"</priority></url>" URLS=URLS+1 Response.Flush rs.movenext end if Loop response.write "</urlset>"
rs.Close Set rs = Nothing conn.Close Set conn = Nothing
Function iso8601date(dLocal,utcOffset) Dim d ' convert local time into UTC d = DateAdd("H",-1 * utcOffset,dLocal) iso8601date = Year(d) & "-" & Right("0" & Month(d),2) & "-" & Right("0" & Day(d),2) & "T" & _ Right("0" & Hour(d),2) & ":" & Right("0" & Minute(d),2) & ":" & Right("0" & Second(d),2) & "Z"
End Function
%> Inserite questo codice in una pagina .asp nella radice del sito, genererà una Sitemap compatibile con gli standard di Google, inseritela in Google Webmaster Tools e il gioco è fatto
|