BLOG:CMS :: Support Forum

Support Forum for BLOG:CMS

You are not logged in.

  • Index
  •  » Plugins
  •  » Search blog with Google (Like hulan.info)

#1 26.12.2007 23:08

statiq
BLOG:CMS Junior
From: Seattle, WA
Registered: 03.07.2007
Posts: 37
Website

Search blog with Google (Like hulan.info)

Radek-
Can you describe how you were able to make your search engine work as it does on your site? I would love to use this method as it is wonderful.


:: StatiQ is running BLOG:CMS 4.2.0 ::

Offline

 

#2 02.01.2008 19:57

Radek Hulán
Site Admin
From: Prague, Czech Republic
Registered: 17.03.2004
Posts: 2509
Website

Re: Search blog with Google (Like hulan.info)

Just register at http://www.google.com/coop/manage/cse/ and Google will create the code for you...


--= BLOG:CMS developer =--

Offline

 

#3 03.01.2008 00:20

statiq
BLOG:CMS Junior
From: Seattle, WA
Registered: 03.07.2007
Posts: 37
Website

Re: Search blog with Google (Like hulan.info)

Pretty dang easy. Wow. Just have to get better search results using FancyURLs


:: StatiQ is running BLOG:CMS 4.2.0 ::

Offline

 

#4 03.01.2008 02:00

Radek Hulán
Site Admin
From: Prague, Czech Republic
Registered: 17.03.2004
Posts: 2509
Website

Re: Search blog with Google (Like hulan.info)

It helps to have a SiteMap and upload it here:

https://www.google.com/webmasters/tools … &pli=1

This is the code for NP_SitemapExporter.php:

Code:

<?php

class NP_SitemapExporter extends NucleusPlugin {

   /* ==========================================================================================
    * SitemapExporter for Nucleus
    *
    * Copyright 2005 by Niels Leenheer
    * ==========================================================================================
    * This program is free software and open source 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  or visit
    * http://www.gnu.org/licenses/gpl.html
    * ==========================================================================================
    */


    function getName() {
        return 'SitemapExporter';
    }

    function getAuthor()  {
        return 'Niels Leenheer';
    }

    function getURL() {
        return 'http://www.rakaz.nl/nucleus/extra/plugins';
    }

    function getVersion() {
        return '0.3';
    }

    function getDescription() {
        return 'This plugin provides a sitemap for your website. Google Sitemap URL: ' . $this->_sitemapURL('google') . ', Yahoo! Sitemap URL: ' . $this->_sitemapURL('yahoo');
    }
    
    function getEventList() {
        return array('PostAddItem');
    }
    
    function supportsFeature($feature) {
        switch($feature) {
            case 'SqlTablePrefix':
                return 1;
            default:
                return 0;
        }
    }

    function doAction($type)
    {
        global $CONF, $manager;

        if ($type == 'google' || $type == 'yahoo' || $type == 'googlemobile')
        {
            $sitemap = array();
            
            $skinadd = '';
            if ($type == 'googlemobile') {
                $type = 'google';
                $skinadd = '?skinid='.$this->getOption('MobileSkinid');
            }
            
            $blog_res = sql_query('
                SELECT 
                    *
                FROM 
                    '.sql_table('blog').' 
            ');
            
            while ($blog = sql_fetch_array($blog_res))
            {
                if ($this->getBlogOption($blog['bnumber'], 'IncludeSitemap') == 'yes')
                {
                    $timestamp = time();
                    
                    $tz = date('O', $timestamp);
                    $tz = substr($tz, 0, 3) . ':' . substr($tz, 3, 2);    
                    
                    if ($blog['bnumber'] != $CONF['DefaultBlog']) {
                        $sitemap[] = array(
                            'loc'   => $this->_prepareLink($blog['bnumber'], createBlogidLink($blog['bnumber'])),
                            'lastmod' => gmdate('Y-m-d\TH:i:s', $timestamp) . $tz,
                            'priority' => '1.0',
                            'changefreq' => 'hourly'
                        );
                    }
                    else
                    {
                        $sitemap[] = array(
                            'loc'   => $blog['burl'],
                            'lastmod' => gmdate('Y-m-d\TH:i:s', $timestamp) . $tz,
                            'priority' => '1.0',
                            'changefreq' => 'hourly'
                        );
                    }
                    
                    $item_res = sql_query('
                        SELECT 
                            *,
                            UNIX_TIMESTAMP(itime) AS timestamp
                        FROM 
                            '.sql_table('item').' 
                        WHERE
                            iblog = '.$blog['bnumber'].' AND
                            idraft = 0
                        ORDER BY 
                            inumber DESC
                    ');
                    
                    while ($item = sql_fetch_array($item_res))
                    {
                        $tz = date('O', $item['timestamp']);
                        $tz = substr($tz, 0, 3) . ':' . substr($tz, 3, 2);    
                        
                        if (time() - $item['timestamp'] < 86400 * 2)
                            $fq = 'hourly';
                        elseif (time() - $item['timestamp'] < 86400 * 14)
                            $fq = 'daily'; 
                        elseif (time() - $item['timestamp'] < 86400 * 62)
                            $fq = 'weekly';
                        else
                            $fq = 'monthly';
                        
                        $sitemap[] = array(
                            'loc' => $this->_prepareLink($blog['bnumber'], createItemLink($item['inumber']).$skinadd),
                            'lastmod' => gmdate('Y-m-d\TH:i:s', $item['timestamp']) . $tz,
                            'priority' => '1.0',
                            'changefreq' => $fq
                        );
                    }
                }
            }        
            
            $manager->notify('SiteMap', array ('sitemap' => & $sitemap));
            
            if ($type == 'google')
            {
                header ("Content-type: application/xml");
                echo "<?xml version='1.0' encoding='UTF-8'?>\n";
                // echo "<urlset xmlns='http://www.google.com/schemas/sitemap/0.84' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd'>\n";
                echo "<urlset xmlns='http://www.google.com/schemas/sitemap/0.84'>\n";
                
                while (list(,$url) = each($sitemap))
                {
                    echo "\t<url>\n";
                    
                    while (list($key,$value) = each($url))
                    {
                        echo "\t\t<" . $key . ">" . htmlspecialchars($value, ENT_QUOTES) . "</" . $key . ">\n";
                    }
                    
                    echo "\t</url>\n";
                }
                
                echo "</urlset>\n";
            }
            else
            {
                header ("Content-type: text/plain");
                while (list(,$url) = each($sitemap))
                {
                    echo $url['loc'] . "\n";
                }
            }
        }
    }
    
    function _prepareLink($blogid, $url) {
        global $manager, $CONF;
        
        if (substr($url, 0, 7) == 'http://')
        {
            return $url;
        }
        else
        {
            $b = & $manager->getBlog($blogid);
            
            if ($CONF['URLMode'] == 'pathinfo')
                return $b->getURL() . substr($url, 1);
            else
                return $b->getURL() . ($CONF['Self'] == '' ? 'index.php' : $CONF['Self']) . $url;
        }
    }
    
    function _sitemapURL($type = 'google') {
        global $CONF;
        
        if ($type == 'google' && $this->getOption('GoogleSitemapURL') != '')
            return $this->getOption('GoogleSitemapURL');
        elseif ($type == 'yahoo' && $this->getOption('YahooSitemapURL') != '')
            return $this->getOption('YahooSitemapURL');
        else
            return $CONF['ActionURL'] . '?action=plugin&name=SitemapExporter&type=' . $type;
    }
    
    function event_PostAddItem(&$data) {
        if ($this->getOption('PingGoogle') == 'yes')
        {
            $url = 'http://www.google.com/webmasters/sitemaps/ping?sitemap=' . 
                   urlencode($this->_sitemapURL());
            
            $fp = @fopen($url, 'r');
            @fclose($fp);
        }
    }

    function install() {
        $this->createOption('PingGoogle', 'Ping Google after adding a new item', 'yesno', 'yes');
        $this->createOption('GoogleSitemapURL', 'Alternative Google Sitemap URL', 'text', '');
        $this->createOption('YahooSitemapURL', 'Alternative Yahoo! Sitemap URL', 'text', '');
        $this->createBlogOption('IncludeSitemap', 'Include this blog in the Sitemap Exporter', 'yesno', 'yes');
        $this->createOption('MobileSkinid', 'Google mobile skinid', 'text', '20');
    }
}        


?>

--= BLOG:CMS developer =--

Offline

 

#5 08.01.2008 20:15

statiq
BLOG:CMS Junior
From: Seattle, WA
Registered: 03.07.2007
Posts: 37
Website

Re: Search blog with Google (Like hulan.info)

Do I need to do anything with the SiteMap php file? Or just create a sitemap from the google sitemap tools and then upload it?  I tried this already, but checked and I  apparently have used a wrong format, so Ill give another go later. But if there is another step i need to follow with that php function that would be good to know.

Thanks Radek.


:: StatiQ is running BLOG:CMS 4.2.0 ::

Offline

 
  • Index
  •  » Plugins
  •  » Search blog with Google (Like hulan.info)

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson

TOPlist