Welcome to Geeklog, Anonymous Monday, November 25 2024 @ 04:10 pm EST

Geeklog Forums

gsmap function for 1.5.0


Status: offline

Chase

Forum User
Regular Poster
Registered: 03/14/08
Posts: 110
Location:Karachi, Pakistan
I had very painfull installtion because of how gsmap function was dealing link categories.
now fixed.

now my site is not broken and and xml is being produced.

put the following in phpblock_gsmap.php
which goes in systems/custom directory (unless you have some other way of using it.)

Text Formatted Code

<?php

// +---------------------------------------------------------------------------+
// | Google Sitemap Generator 0.1.3 for Geeklog - The Ultimate Weblog          |
// +---------------------------------------------------------------------------+
// | phpblock_gsmap.php                                                        |
// |                                                                           |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2006 by the following authors:                              |
// |                                                                           |
// | Authors: mystral-kk  - geeklog AT mystral-kk DOT net                      |
// +---------------------------------------------------------------------------+
// |                                                                           |
// | This program is free software; you can redistribute it and/or             |
// | modify it under the terms of the GNU General Public License               |
// | as published by the Free Software Foundation; either version 2            |
// | of the License, or (at your option) any later version.                    |
// |                                                                           |
// | This program is distributed in the hope that it will be useful,           |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
// | GNU General Public License for more details.                              |
// |                                                                           |
// | You should have received a copy of the GNU General Public License         |
// | along with this program; if not, write to the Free Software Foundation,   |
// | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
// |                                                                           |
// +---------------------------------------------------------------------------+
//
// $Id$

// This script creates a sitemap for your site based on "Sitemaps XML format"
// published at sitemaps.org (http://www.sitemaps.org).  The sitemap is valid
// as a Google sitemap.

// ==============================================
//   SETTINGS
// ==============================================

$GSMAP_CONF = array();

// The path to the sitemap file.  This file must be in the TOP DIRECTORY of
// your site and WRITABLE FROM THE WEB SERVER.

$GSMAP_CONF['sitemap_name'] = 'sitemap.xml';

// Items to be included into the sitemap (true = include / false = exclude)

$GSMAP_CONF['include_story']       = true;
$GSMAP_CONF['include_staticpage']  = true;
$GSMAP_CONF['include_link']        = true;
$GSMAP_CONF['include_forum_topic'] = true;

// What type of static pages to be included into the sitemap
// 0 = all pages
// 1 = only pages to be displayed in the center block
// 2 = only pages ** NOT ** not to be displayed in the center block (default)

$GSMAP_CONF['staticpage_type'] = 2;

// ============================================================================
//   DO NOT MODIFY THE LINES BELOW UNLESS YOU KNOW WHAT YOU ARE GOING TO DO
// ============================================================================

if ( !defined( 'LB' ) )
{
        define( 'LB', "\n" );
}

// @para: $t = UNIX Timestamp
// @return: string - 'YYYY-MM-DD'

function GSMAP_formatTime( $t )
{
        return date( 'Y-m-d', $t );
}

function GSMAP_checkURL( $url )
{
        $url = str_replace( '&amp;', '&', $url );
        $url = htmlspecialchars( $url, ENT_QUOTES ); // '&' -> '&amp;'
        return $url;
}

function GSMAP_makeEntry( $url, $lastmod )
{
        $retval  = '<url>' . LB;
        $retval .= '<loc>' . GSMAP_checkURL( $url ) . '</loc>' . LB;
        $retval .= '<lastmod>' . GSMAP_formatTime( $lastmod ) . '</lastmod>' . LB;
        $retval .= '</url>' . LB;
        return $retval;
}

// Return stories

function GSMAP_getStory()
{
    global $_CONF, $_TABLES, $GSMAP_CONF;

        $retval = '';
        if ( !$GSMAP_CONF['include_story'] )
        {
                return $retval;
        }
       
        $sql = "SELECT sid, date FROM {$_TABLES['stories']} WHERE (date <= NOW()) AND (draft_flag = 0) AND (perm_anon >= 2) ORDER BY date DESC";
        $result = DB_query( $sql );
       
        $baseurl = $_CONF['site_url'] . '/article.php';
        while ( $A = DB_fetchArray( $result ) )
        {
                $lastmod = strtotime( $A['date'] );
                if ( $_CONF['url_rewrite'] )
                {
                        $url = $baseurl . '/';
                }
                else
                {
                        $url = $baseurl . '?story=';
                }
                $url .= $A['sid'];
                $retval .= GSMAP_makeEntry($url, $lastmod);
        }
       
        return $retval;
}

// Return static pages

function GSMAP_getStaticPage()
{
    global $_CONF, $_PLUGINS, $_TABLES, $GSMAP_CONF;
       
        $retval = '';
        if ( !$GSMAP_CONF['include_staticpage'] || !in_array( 'staticpages', $_PLUGINS ) )
        {
                return $retval;
        }
       
        // Set up which type of static pages to pick up
        if ( !isset( $GSMAP_CONF['staticpage_type'] ) )
        {
                $GSMAP_CONF['staticpage_type'] = 0;
        }
        $sql = "SELECT sp_id, sp_date FROM {$_TABLES['staticpage']} WHERE ";
        if ( $GSMAP_CONF['staticpage_type'] == 1 )
        {
                $sql .= "(sp_centerblock <> 0) AND ";
        }
        else if ( $GSMAP_CONF['staticpage_type'] == 2 )
        {
                $sql .= "(sp_centerblock = 0) AND ";
        }
        $sql .= "(perm_anon >= 2) ORDER BY sp_date DESC";
        $result = DB_query( $sql );
       
        $baseurl = $_CONF['site_url'] . '/staticpages/index.php';
        while ( $A = DB_fetchArray( $result ) )
        {
                $lastmod = strtotime( $A['sp_date'] );
                if ( $_CONF['url_rewrite'] )
                {
                        $url = $baseurl . '/';
                }
                else
                {
                        $url = $baseurl . '?page=';
                }
                $url .= $A['sp_id'];
                $retval .= GSMAP_makeEntry( $url, $lastmod );
        }
       
        return $retval;
}

// Return links

function GSMAP_getLink()
{
    global $_CONF, $_PLUGINS, $_TABLES, $GSMAP_CONF;
       
        $retval = '';
        if ( !$GSMAP_CONF['include_link'] || !in_array( 'links', $_PLUGINS ) )
        {
                return $retval;
        }
       
        // Retrieve categories and their last modified dates
        $cats = array();
        $sql = "SELECT lid, cid, date FROM {$_TABLES['links']} WHERE (perm_anon >= 2)";
        $result = DB_query( $sql );
        while ( $A = DB_fetchArray( $result ) )
        {
                $category = $A['cid'];
                $lastmod  = strtotime($A['date']);
                if ( !in_array( $category, $cats ) )
                {
                        $cats[$category] = $lastmod;
                }
                else
                {
                        if ( $cats[$category] < $lastmod )
                        {
                                $cats[$category] = $lastmod;
                        }
                }
        }
       
        foreach ( $cats as $cat => $lastmod )
        {
                $url = $_CONF['site_url'] . '/links/index.php?category=' . urlencode( $cat );
                $retval .= GSMAP_makeEntry( $url, $lastmod );
        }
       
        return $retval;
}

// Return forum topics

function GSMAP_getForumTopic()
{
    global $_CONF, $_PLUGINS, $_TABLES, $GSMAP_CONF;
       
        $retval = '';
        if ( !$GSMAP_CONF['include_forum_topic'] || !in_array( 'forum', $_PLUGINS ) )
        {
                return $retval;
        }
       
        // Collect ids of forums open to all users (grp_id = 2)
        $sql = "SELECT forum_id FROM {$_TABLES['gf_forums']} WHERE ( grp_id = 2 )";
        $result = DB_query( $sql );
        $forum_ids = array();
        while ( $A = DB_fetchArray( $result ) )
        {
                $forum_ids[] = $A['forum_id'];
        }
       
        $sql = "SELECT id, forum, lastupdated FROM {$_TABLES['gf_topic']}"
             . " WHERE ( pid = 0 ) AND ( forum in ( " . implode(',', $forum_ids) . " ) )";
        $result = DB_query( $sql );
       
        while ( $A = DB_fetchArray( $result ) )
        {
                $url = $_CONF['site_url'] . '/forum/viewtopic.php?forum=' . $A['forum'] . '&amp;showtopic=' . $A['id'];
                $retval .= GSMAP_makeEntry( $url, $A['lastupdated'] );
        }
       
        return $retval;
}

// Create a sitemap for your site based on "Sitemaps XML format" published at
// sitemaps.org (http://www.sitemaps.org).

function phpblock_gsmap()
{
    global $_CONF, $_PLUGINS, $_TABLES, $GSMAP_CONF;
       
        // Header
        $gsmap  = '<?xml version="1.0" encoding="UTF-8"?>' . LB;
        $gsmap .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . LB;
       
        // Collect contents
        $gsmap .= GSMAP_getStory();
        $gsmap .= GSMAP_getStaticPage();
        $gsmap .= GSMAP_getLink();
        $gsmap .= GSMAP_getForumTopic();
       
        // Footer
        $gsmap .= '</urlset>' . LB;
       
        // Convert carriage returns and encode the stuff in UTF-8N
        $gsmap = str_replace( array( "\r\n", "\n\r", "\r" ), "\n", $gsmap );
        if ( function_exists( 'mb_convert_encoding' ) )
        {
                $gsmap = mb_convert_encoding( $gsmap, 'UTF-8' );
        }
       
        // Write the sitemap into file
        $path = $_CONF['path_html'] . $GSMAP_CONF['sitemap_name'];
        if ( file_exists( $path ) && !is_writable( $path ) )
        {
                @chmod( $path, 0666 );
        }
        clearstatcache();
       
        $fh = fopen( $path, "wb" );
        if ( $fh !== false )
        {
                $bytes = fwrite( $fh, $gsmap );
                if ( $bytes === false || $bytes != strlen( $gsmap ) )
                {
                        COM_errorLog( "GSMAP: couldn't write into the sitemap.\nPath: " . $_CONF['path_html'] . $GSMAP_CONF['sitemap_name'] );
                }
                @fclose( $fh );
                @touch( $path );
                @chmod( $path, 0644 );
        }
        else
        {
                COM_errorLog( "GSMAP: couldn't open the sitemap for writing data.\nPath: " . $_CONF['path_html'] . $GSMAP_CONF['sitemap_name'] );
        }
}

?>


 

--
http://TazaKino.com - Pakistani News
Where YOU report the news
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Or better yet, just replace:

1)
Text Formatted Code
        $sql = "SELECT lid, category, date FROM {$_TABLES['links']} WHERE (perm_anon >= 2)";

with
Text Formatted Code

// custom code - start
        if (VERSION < 1.5)
                   $cat_field = 'category';
        else
                   $cat_field = 'cid';  
        $sql = "SELECT lid, $cat_field, date FROM {$_TABLES['links']} WHERE (perm_anon >= 2)";
// custom code - end
 

2)
Text Formatted Code
                $category = $A['category'];

with
Text Formatted Code

// custom code - start
                $category = $A[$cat_field];
// custom code - end
 


3) Not related, but that's more like it:

I've also cancelled the "you must create an empty file" requirement by changing
Text Formatted Code
        if ( file_exists( $path ) && !is_writable( $path ) )

to
Text Formatted Code
// custom code - start
        if ( !file_exists( $path ))
                  fopen($path, 'w');
// custom code - end
        if ( file_exists( $path ) && !is_writable( $path ) )


Now if only we can get the author to do all of that.
 Quote

Status: offline

LWC

Forum User
Full Member
Registered: 02/19/04
Posts: 818
Since this function supports neither topics nor media items, someone (me?) should add support for either.
 Quote

All times are EST. The time is now 04:10 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content