Osclass forums

Development => Plugins => Topic started by: telecomseva on August 22, 2012, 10:25:22 pm

Title: SOLVED : sitemap not working properly
Post by: telecomseva on August 22, 2012, 10:25:22 pm
hi,

i m facing problem in sitemap.

it shows wrong url.

like:
 <url>
        <loc>http://ads.muquam.com/search/category,/country,India/region,Rajasthan/city,Ajmer/</loc>
        <lastmod>2012-08-22</lastmod>
        <changefreq>hourly</changefreq>
    </url>
       
<url>
        <loc>http://ads.muquam.com/search/country,India/region,Maharashtra/city,Pune/</loc>
        <lastmod>2012-08-22</lastmod>
        <changefreq>hourly</changefreq>
    </url>

both url shows error,
HTTP Error 500 (Internal Server Error)

i have figure out problem in 1st url but not able to resolve problem.
http://ads.muquam.com/search/category,/country,India/region,Rajasthan/city,Ajmer/

this red mark comma is the problem in url.

can any body help me out to resolve this issue.

thanks
Title: Re: sitemap not working properly
Post by: telecomseva on August 25, 2012, 06:23:23 pm
please somebody help me.

i m facing problem in sitemap.
Title: Re: sitemap not working properly
Post by: ipuck on August 26, 2012, 05:15:55 am
I don't think he plugin is working at all. I installed it in my site and the site map only show about 5 links and I have over 200 posts.
Title: Re: sitemap not working properly
Post by: thune on August 29, 2012, 03:09:40 am
I agree. It doesn't seem to work and the links is not SEF and the sitemap.xml is not updated since I installed it. I think this plugin will do more harm than good...
Title: Re: sitemap not working properly
Post by: bandsinasia on August 29, 2012, 04:24:28 pm
I was able to make it work by modifying it and commenting out a large part of the code.
With this, I'm able to generate links for every category and items in my site.
This is in /oc-content/plugins/sitemap_generator/index.php

You can see my generated sitemap here: http://www.bandsinasia.com/ph/sitemap.xml (http://www.bandsinasia.com/ph/sitemap.xml)
Code: [Select]
while ( osc_has_categories() ) {
       
       sitemap_add_url(osc_search_category_url(), date('Y-m-d'), 'hourly', osc_category_name());
       foreach(osc_get_category_items() as $items){
        $title = osc_sanitizeString($items['s_title']);
        $id = $items['fk_i_item_id'];
        $url = osc_search_category_url().'/'.$title.'_'.$id;
        sitemap_add_url($url, date('Y-m-d'), 'hourly');
       }
       if (osc_count_subcategories() > 0){
           
           while ( osc_has_subcategories() ) {
               
                sitemap_add_url(osc_search_category_url(), date('Y-m-d'), 'hourly', osc_category_name());
               
                foreach(osc_get_category_items() as $items){
                    $title = osc_sanitizeString($items['s_title']);
                    $id = $items['fk_i_item_id'];
                    $url = osc_search_category_url().'/'.$title.'_'.$id;
                    sitemap_add_url($url, date('Y-m-d'), 'hourly');
                   }
            }
           
        }
       
    }
    /*foreach($categories as $c) {
        $search = new Search();
        $search->addCategory($c['pk_i_id']);
        if($search->count()>=$min) {
            sitemap_add_url(osc_search_url(array('sCategory' => $c['pk_i_id'])), date('Y-m-d'), 'hourly');
            foreach($c['categories'] as $sc){
                $search = new Search();
                $search->addCategory($sc['pk_i_id']);
                if($search->count()>=$min) {
                    sitemap_add_url(osc_search_url(array('sCategory' => $sc['pk_i_id'])), date('Y-m-d'), 'hourly');
                    foreach($countries as $country) {
                        if(count($countries)>1) {
                            $search = new Search();
                            $search->addCategory($sc['pk_i_id']);
                            $search->addCountry($country['pk_c_code']);
                            if($search->count()>$min) {
                                sitemap_add_url(osc_search_url(array('sCategory' => $sc['pk_i_id'], 'sCountry' => $country['s_name'])), date('Y-m-d'), 'hourly');
                            }
                        }
                        $regions = Region::newInstance()->getByCountry($country['pk_c_code']);
                        foreach($regions as $region) {
                            $search = new Search();
                            $search->addCategory($sc['pk_i_id']);
                            $search->addCountry($country['pk_c_code']);
                            $search->addRegion($region['pk_i_id']);
                            if($search->count()>$min) {
                                sitemap_add_url(osc_search_url(array('sCategory' => osc_category_id(), 'sCountry' => $country['s_name'], 'sRegion' => $region['s_name'])), date('Y-m-d'), 'hourly');
                                $cities = City::newInstance()->getByRegion($region['pk_i_id']);
                                foreach($cities as $city) {
                                    $search = new Search();
                                    $search->addCategory($sc['pk_i_id']);
                                    $search->addCountry($country['pk_c_code']);
                                    $search->addRegion($region['pk_i_id']);
                                    $search->addCity($city['pk_i_id']);
                                    if($search->count()>$min) {
                                        sitemap_add_url(osc_search_url(array('sCategory' => osc_category_id(), 'sCountry' => $country['s_name'], 'sRegion' => $region['s_name'], 'sCity' => $city['s_name'])), date('Y-m-d'), 'hourly');
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }*/

Go to /oc-includes/osclass/helpers/hCategories.php
and then add this function at the bottom of the file before "?>"
Code: [Select]
    function osc_get_category_items(){
        $conn = getConnection() ;
        $items = $conn->osc_dbFetchResults("SELECT a.s_title, a.fk_i_item_id
            FROM %st_item_description a
            JOIN %st_item b ON a.fk_i_item_id = b.pk_i_id
            AND b.fk_i_category_id = %d", DB_TABLE_PREFIX, DB_TABLE_PREFIX, osc_category_id());
        return $items;
    }
Title: Re: sitemap not working properly
Post by: telecomseva on August 31, 2012, 03:13:31 am
hi bandsinasia,

thanks for reply,

please also mention the after, before or replace in existing code so that we easily update it.

thanks
Title: Site map works
Post by: manish0172 on August 31, 2012, 02:38:21 pm
Hi friends , now your code sitemap will work , just open your oc-content\plugins\sitemap_generator\index.php

and replace with my code.. and then enjoy..


<?php
/*
Plugin Name: Sitemap Generator
Plugin URI: http://www.osclass.org/
Description: Sitemap Generator
Version: 1.2.2
Author: OSClass
Author URI: http://www.osclass.org/
Short Name: sitemap_generator
Plugin update URI: sitemap-generator
*/

if( !function_exists('osc_plugin_path') ) {
    function osc_plugin_path($file) {
        $file = preg_replace('|/+|','/', str_replace('\\','/',$file));
        $plugin_path = preg_replace('|/+|','/', str_replace('\\','/', PLUGINS_PATH));
        $file = $plugin_path . preg_replace('#^.*oc-content\/plugins\/#','',$file);
        return $file;
    }
}

function sitemap_generator() {
    $min = 1;

    $locales = osc_get_locales();

    $filename = osc_base_path() . 'sitemap.xml';
    @unlink($filename);
    $start_xml = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL;
    file_put_contents($filename, $start_xml);

    // INDEX
    sitemap_add_url(osc_base_url(), date('Y-m-d'), 'always');

    $categories = Category::newInstance()->toTree();
    $countries = Country::newInstance()->listAll();
    foreach($categories as $c) {
        $search = new Search();
        $search->addCategory($c['pk_i_id']);
        if($search->count()>=$min) {
      
      
      while ( osc_has_categories() ) {
       
       sitemap_add_url(osc_search_category_url(), date('Y-m-d'), 'hourly', osc_category_name());
       foreach(osc_get_category_items() as $items){
        $title = osc_sanitizeString($items['s_title']);
        $id = $items['fk_i_item_id'];
        $url = osc_search_category_url().'/'.$title.'_'.$id;
        sitemap_add_url($url, date('Y-m-d'), 'hourly');
       }
       if (osc_count_subcategories() > 0){
           
           while ( osc_has_subcategories() ) {
               
                sitemap_add_url(osc_search_category_url(), date('Y-m-d'), 'hourly', osc_category_name());
               
                foreach(osc_get_category_items() as $items){
                    $title = osc_sanitizeString($items['s_title']);
                    $id = $items['fk_i_item_id'];
                    $url = osc_search_category_url().'/'.$title.'_'.$id;
                    sitemap_add_url($url, date('Y-m-d'), 'hourly');
                   }
            }
           
        }
       
    }
   
   }
    /*foreach($categories as $c) {
           $search = new Search();
           $search->addCategory($c['pk_i_id']);
           if($search->count()>=$min) {
               sitemap_add_url(osc_search_url(array('sCategory' => $c['pk_i_id'])), date('Y-m-d'), 'hourly');
               foreach($c['categories'] as $sc){
                   $search = new Search();
                   $search->addCategory($sc['pk_i_id']);
                   if($search->count()>=$min) {
                       sitemap_add_url(osc_search_url(array('sCategory' => $sc['pk_i_id'])), date('Y-m-d'), 'hourly');
                       foreach($countries as $country) {
                           if(count($countries)>1) {
                               $search = new Search();
                               $search->addCategory($sc['pk_i_id']);
                               $search->addCountry($country['pk_c_code']);
                               if($search->count()>$min) {
                                   sitemap_add_url(osc_search_url(array('sCategory' => $sc['pk_i_id'], 'sCountry' => $country['s_name'])), date('Y-m-d'), 'hourly');
                               }
                           }
                           $regions = Region::newInstance()->getByCountry($country['pk_c_code']);
                           foreach($regions as $region) {
                               $search = new Search();
                               $search->addCategory($sc['pk_i_id']);
                               $search->addCountry($country['pk_c_code']);
                               $search->addRegion($region['pk_i_id']);
                               if($search->count()>$min) {
                                   sitemap_add_url(osc_search_url(array('sCategory' => osc_category_id(), 'sCountry' => $country['s_name'], 'sRegion' => $region['s_name'])), date('Y-m-d'), 'hourly');
                                   $cities = City::newInstance()->getByRegion($region['pk_i_id']);
                                   foreach($cities as $city) {
                                       $search = new Search();
                                       $search->addCategory($sc['pk_i_id']);
                                       $search->addCountry($country['pk_c_code']);
                                       $search->addRegion($region['pk_i_id']);
                                       $search->addCity($city['pk_i_id']);
                                       if($search->count()>$min) {
                                           sitemap_add_url(osc_search_url(array('sCategory' => osc_category_id(), 'sCountry' => $country['s_name'], 'sRegion' => $region['s_name'], 'sCity' => $city['s_name'])), date('Y-m-d'), 'hourly');
                                       }
                                   }
                               }
                           }
                       }
                   }
               }
           }
       }*/
           
         
          }
       
       

    foreach($countries as $country) {
        $regions = Region::newInstance()->getByCountry($country['pk_c_code']);
        foreach($regions as $region) {
            $cities = Search::newInstance()->listCities($region['pk_i_id']);
            $l = min(count($cities), 30);
            for($k=0;$k<$l;$k++) {
                if($cities[$k]['items']>$min) {
                    sitemap_add_url(osc_search_url(array('sCountry' => $country['s_name'], 'sRegion' => $region['s_name'], 'sCity' => $cities[$k]['city_name'])), date('Y-m-d'), 'hourly');
                }
            }
        }
    }

    $end_xml = '</urlset>';
    file_put_contents($filename, $end_xml, FILE_APPEND);
   
    // PING SEARCH ENGINES
    sitemap_ping_engines();
}

function sitemap_add_url($url = '', $date = '', $freq = 'daily') {
    if( preg_match('|\?(.*)|', $url, $match) ) {
        $sub_url = $match[1];
        $param = explode('&', $sub_url);
        foreach($param as &$p) {
            list($key, $value) = explode('=', $p);
            $p = $key . '=' . urlencode($value);
        }
        $sub_url = implode('&', $param);
        $url = preg_replace('|\?.*|', '?' . $sub_url, $url);
    }

    $filename = osc_base_path() . 'sitemap.xml';
    $xml  = '    <url>' . PHP_EOL;
    $xml .= '        <loc>' . htmlentities($url, ENT_QUOTES, "UTF-8") . '</loc>' . PHP_EOL;
    $xml .= '        <lastmod>' . $date . '</lastmod>' . PHP_EOL;
    $xml .= '        <changefreq>' . $freq . '</changefreq>' . PHP_EOL;
    $xml .= '    </url>' . PHP_EOL;
    file_put_contents($filename, $xml, FILE_APPEND);
}

function sitemap_ping_engines() {
    // GOOGLE
    osc_doRequest( 'http://www.google.com/webmasters/sitemaps/ping?sitemap='.urlencode(osc_base_url() . 'sitemap.xml'), array());
    // BING
    osc_doRequest( 'http://www.bing.com/webmaster/ping.aspx?siteMap='.urlencode(osc_base_url() . 'sitemap.xml'), array());
    // YAHOO!
    osc_doRequest( 'http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid='.osc_page_title().'&url='.urlencode(osc_base_url() . 'sitemap.xml'), array());
}

function sitemap_admin_menu() {
    echo '<h3><a href="#">' . __('Sitemap Generator', 'sitemap_generator') . '</a></h3>
    <ul>
        <li><a href="' . osc_admin_render_plugin_url(osc_plugin_folder(__FILE__) . '/sitemap.php') . '">&raquo; ' . __('Sitemap Help', 'sitemap_generator') . '</a></li>
        <li><a href="' . osc_admin_render_plugin_url(osc_plugin_folder(__FILE__) . '/generate.php') . '">&raquo; ' . __('Generate sitemap', 'sitemap_generator') . '</a></li>
    </ul>';
}

function sitemap_help() {
    sitemap_generator();
    osc_admin_render_plugin(osc_plugin_path(osc_plugin_folder(__FILE__)) . '/sitemap.php') ;
}

// This is needed in order to be able to activate the plugin
// osc_register_plugin(osc_plugin_path(__FILE__), 'sitemap_help');
// This is a hack to show a Configure link at plugins table (you could also use some other hook to show a custom option panel)
osc_add_hook(osc_plugin_path(__FILE__)."_configure", 'sitemap_help');
// This is a hack to show a Uninstall link at plugins table (you could also use some other hook to show a custom option panel)
osc_add_hook(osc_plugin_path(__FILE__)."_uninstall", '');
// Add the help to the menu
osc_add_hook('admin_menu', 'sitemap_admin_menu');

// Generate sitemap every day
// CHANGE THIS LINE TO  'cron_hourly' or 'cron_daily' to modify the frequent of running it
// REMOVE IT if you want to generate the sitemap manually
osc_add_hook('cron_weekly', 'sitemap_generator');

/* end of file */









Thanks and please visit my website
www.newmobileszone.com (http://www.newmobileszone.com)

 


Title: Re: sitemap not working properly
Post by: localsales on September 02, 2012, 02:38:09 pm
It generate a Fatal error: Call to undefined function osc_get_category_items() in E:\xampplite\htdocs\class\oc-content\plugins\sitemap_generator\index.php on line 46.
Title: Re: sitemap not working properly
Post by: bandsinasia on September 06, 2012, 06:08:30 am
Sorry, I forgot to add another thing. I forgot I also modified my osclass.

Go to /oc-includes/osclass/helpers/hCategories.php
and then add this function at the bottom of the file before "?>"

Code: [Select]
    function osc_get_category_items(){
        $conn = getConnection() ;
        $items = $conn->osc_dbFetchResults("SELECT a.s_title, a.fk_i_item_id
            FROM %st_item_description a
            JOIN %st_item b ON a.fk_i_item_id = b.pk_i_id
            AND b.fk_i_category_id = %d", DB_TABLE_PREFIX, DB_TABLE_PREFIX, osc_category_id());
        return $items;
    }

This is not OSClass standard way of doing this database query. If anybody can code this in a better way that follows the OSClass framework, please share it here :D

Basically, it will just get all the items based from a given category ID.
Title: Re: sitemap not working properly
Post by: telecomseva on September 07, 2012, 12:06:59 am
hi bandsinasia,

i m not a good php developer.
so i request you to please give the complete step to change the script.

thanks
Title: Re: sitemap not working properly
Post by: telecomseva on September 10, 2012, 07:25:15 pm
waiting for the replies from any one.

thanks
Title: Re: sitemap not working properly
Post by: bandsinasia on September 14, 2012, 07:07:29 pm
Step 1
Open your /oc-content/plugins/sitemap_generator/index.php
Replace it with the code provided by Manish0172
Code: [Select]
<?php
/*
Plugin Name: Sitemap Generator
Plugin URI: http://www.osclass.org/
Description: Sitemap Generator
Version: 1.2.2
Author: OSClass
Author URI: http://www.osclass.org/
Short Name: sitemap_generator
Plugin update URI: sitemap-generator
*/

if( !function_exists('osc_plugin_path') ) {
    function 
osc_plugin_path($file) {
        
$file preg_replace('|/+|','/'str_replace('\\','/',$file));
        
$plugin_path preg_replace('|/+|','/'str_replace('\\','/'PLUGINS_PATH));
        
$file $plugin_path preg_replace('#^.*oc-content\/plugins\/#','',$file);
        return 
$file;
    }
}

function 
sitemap_generator() {
    
$min 1;

    
$locales osc_get_locales();

    
$filename osc_base_path() . 'sitemap.xml';
    @
unlink($filename);
    
$start_xml '<?xml version="1.0" encoding="UTF-8"?>
' . PHP_EOL . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL;
    file_put_contents($filename, $start_xml);

    // INDEX
    sitemap_add_url(osc_base_url(), date('Y-m-d'), 'always');

    $categories = Category::newInstance()->toTree();
    $countries = Country::newInstance()->listAll();
    foreach($categories as $c) {
        $search = new Search();
        $search->addCategory($c['pk_i_id']);
        if($search->count()>=$min) {
     
     
      while ( osc_has_categories() ) {
       
       sitemap_add_url(osc_search_category_url(), date('Y-m-d'), 'hourly', osc_category_name());
       foreach(osc_get_category_items() as $items){
        $title = osc_sanitizeString($items['s_title']);
        $id = $items['fk_i_item_id'];
        $url = osc_search_category_url().'/'.$title.'_'.$id;
        sitemap_add_url($url, date('Y-m-d'), 'hourly');
       }
       if (osc_count_subcategories() > 0){
           
           while ( osc_has_subcategories() ) {
               
                sitemap_add_url(osc_search_category_url(), date('Y-m-d'), 'hourly', osc_category_name());
               
                foreach(osc_get_category_items() as $items){
                    $title = osc_sanitizeString($items['s_title']);
                    $id = $items['fk_i_item_id'];
                    $url = osc_search_category_url().'/'.$title.'_'.$id;
                    sitemap_add_url($url, date('Y-m-d'), 'hourly');
                   }
            }
           
        }
       
    }
   
   }
    /*foreach($categories as $c) {
           $search = new Search();
           $search->addCategory($c['pk_i_id']);
           if($search->count()>=$min) {
               sitemap_add_url(osc_search_url(array('sCategory' => $c['pk_i_id'])), date('Y-m-d'), 'hourly');
               foreach($c['categories'] as $sc){
                   $search = new Search();
                   $search->addCategory($sc['pk_i_id']);
                   if($search->count()>=$min) {
                       sitemap_add_url(osc_search_url(array('sCategory' => $sc['pk_i_id'])), date('Y-m-d'), 'hourly');
                       foreach($countries as $country) {
                           if(count($countries)>1) {
                               $search = new Search();
                               $search->addCategory($sc['pk_i_id']);
                               $search->addCountry($country['pk_c_code']);
                               if($search->count()>$min) {
                                   sitemap_add_url(osc_search_url(array('sCategory' => $sc['pk_i_id'], 'sCountry' => $country['s_name'])), date('Y-m-d'), 'hourly');
                               }
                           }
                           $regions = Region::newInstance()->getByCountry($country['pk_c_code']);
                           foreach($regions as $region) {
                               $search = new Search();
                               $search->addCategory($sc['pk_i_id']);
                               $search->addCountry($country['pk_c_code']);
                               $search->addRegion($region['pk_i_id']);
                               if($search->count()>$min) {
                                   sitemap_add_url(osc_search_url(array('sCategory' => osc_category_id(), 'sCountry' => $country['s_name'], 'sRegion' => $region['s_name'])), date('Y-m-d'), 'hourly');
                                   $cities = City::newInstance()->getByRegion($region['pk_i_id']);
                                   foreach($cities as $city) {
                                       $search = new Search();
                                       $search->addCategory($sc['pk_i_id']);
                                       $search->addCountry($country['pk_c_code']);
                                       $search->addRegion($region['pk_i_id']);
                                       $search->addCity($city['pk_i_id']);
                                       if($search->count()>$min) {
                                           sitemap_add_url(osc_search_url(array('sCategory' => osc_category_id(), 'sCountry' => $country['s_name'], 'sRegion' => $region['s_name'], 'sCity' => $city['s_name'])), date('Y-m-d'), 'hourly');
                                       }
                                   }
                               }
                           }
                       }
                   }
               }
           }
       }*/
           
         
          }
       
       

    foreach($countries as $country) {
        $regions = Region::newInstance()->getByCountry($country['pk_c_code']);
        foreach($regions as $region) {
            $cities = Search::newInstance()->listCities($region['pk_i_id']);
            $l = min(count($cities), 30);
            for($k=0;$k<$l;$k++) {
                if($cities[$k]['items']>$min) {
                    sitemap_add_url(osc_search_url(array('sCountry' => $country['s_name'], 'sRegion' => $region['s_name'], 'sCity' => $cities[$k]['city_name'])), date('Y-m-d'), 'hourly');
                }
            }
        }
    }

    $end_xml = '</urlset>';
    file_put_contents($filename, $end_xml, FILE_APPEND);
   
    // PING SEARCH ENGINES
    sitemap_ping_engines();
}

function sitemap_add_url($url = '', $date = '', $freq = 'daily') {
    if( preg_match('|\?(.*)|', $url, $match) ) {
        $sub_url = $match[1];
        $param = explode('&', $sub_url);
        foreach($param as &$p) {
            list($key, $value) = explode('=', $p);
            $p = $key . '=' . urlencode($value);
        }
        $sub_url = implode('&', $param);
        $url = preg_replace('|\?.*|', '?' . $sub_url, $url);
    }

    $filename = osc_base_path() . 'sitemap.xml';
    $xml  = '    <url>' . PHP_EOL;
    $xml .= '        <loc>' . htmlentities($url, ENT_QUOTES, "UTF-8") . '</loc>' . PHP_EOL;
    $xml .= '        <lastmod>' . $date . '</lastmod>' . PHP_EOL;
    $xml .= '        <changefreq>' . $freq . '</changefreq>' . PHP_EOL;
    $xml .= '    </url>' . PHP_EOL;
    file_put_contents($filename, $xml, FILE_APPEND);
}

function sitemap_ping_engines() {
    // GOOGLE
    osc_doRequest( 'http://www.google.com/webmasters/sitemaps/ping?sitemap='.urlencode(osc_base_url() . 'sitemap.xml'), array());
    // BING
    osc_doRequest( 'http://www.bing.com/webmaster/ping.aspx?siteMap='.urlencode(osc_base_url() . 'sitemap.xml'), array());
    // YAHOO!
    osc_doRequest( 'http://search.yahooapis.com/SiteExplorerService/V1/updateNotification?appid='.osc_page_title().'&url='.urlencode(osc_base_url() . 'sitemap.xml'), array());
}

function sitemap_admin_menu() {
    echo '<h3><a href="#">' . __('Sitemap Generator', 'sitemap_generator') . '</a></h3>
    <ul>
        <li><a href="' . osc_admin_render_plugin_url(osc_plugin_folder(__FILE__) . '/sitemap.php') . '">&raquo; ' . __('Sitemap Help', 'sitemap_generator') . '</a></li>
        <li><a href="' . osc_admin_render_plugin_url(osc_plugin_folder(__FILE__) . '/generate.php') . '">&raquo; ' . __('Generate sitemap', 'sitemap_generator') . '</a></li>
    </ul>';
}

function sitemap_help() {
    sitemap_generator();
    osc_admin_render_plugin(osc_plugin_path(osc_plugin_folder(__FILE__)) . '/sitemap.php') ;
}

// This is needed in order to be able to activate the plugin
// osc_register_plugin(osc_plugin_path(__FILE__), 'sitemap_help');
// This is a hack to show a Configure link at plugins table (you could also use some other hook to show a custom option panel)
osc_add_hook(osc_plugin_path(__FILE__)."_configure", 'sitemap_help');
// This is a hack to show a Uninstall link at plugins table (you could also use some other hook to show a custom option panel)
osc_add_hook(osc_plugin_path(__FILE__)."_uninstall", '');
// Add the help to the menu
osc_add_hook('admin_menu', 'sitemap_admin_menu');

// Generate sitemap every day
// CHANGE THIS LINE TO  'cron_hourly' or 'cron_daily' to modify the frequent of running it
// REMOVE IT if you want to generate the sitemap manually
osc_add_hook('cron_weekly', 'sitemap_generator');

/* end of file */


Step 2
Open your  /oc-includes/osclass/helpers/hCategories.php
Scroll down to the bottom of the file, until you see this "?>" at the last line.
Insert this code before that last line
Code: [Select]
  function osc_get_category_items(){
        $conn = getConnection() ;
        $items = $conn->osc_dbFetchResults("SELECT a.s_title, a.fk_i_item_id
            FROM %st_item_description a
            JOIN %st_item b ON a.fk_i_item_id = b.pk_i_id
            AND b.fk_i_category_id = %d", DB_TABLE_PREFIX, DB_TABLE_PREFIX, osc_category_id());
        return $items;
    }

Here is my updated file from OSClass 3. You can copy and use this if you're using the latest version as I am. If not, just follow step 2
Code: [Select]
<?php
    
/*
     *      OSCLass – software for creating and publishing online classified
     *                           advertising platforms
     *
     *                        Copyright (C) 2010 OSCLASS
     *
     *       This program is free software: you can redistribute it and/or
     *     modify it under the terms of the GNU Affero General Public License
     *     as published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
     *
     *      You should have received a copy of the GNU Affero General Public
     * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
     */


    /**
    * Helper Categories
    * @package OSClass
    * @subpackage Helpers
    * @author OSClass
    */

    /**
     * Gets current category
     *
     * @return array
     */
    
function osc_category() {
        if (
View::newInstance()->_exists('subcategories')) {
            
$category View::newInstance()->_current('subcategories') ;
        } elseif (
View::newInstance()->_exists('categories')) {
            
$category View::newInstance()->_current('categories') ;
        } elseif (
View::newInstance()->_exists('category')) {
            
$category View::newInstance()->_get('category') ;
        } else {
            
$category null;
        }
        return(
$category) ;
    }

    
/**
     * Low level function: Gets the list of categories as a tree
     *
     * <code>
     * <?php
     *  $c = osc_get_categories() ;
     * ?>

     * </code>
     *
     * @return <array>
     */
    function osc_get_categories() {
       if ( !View::newInstance()->_exists('categories') ) {
            View::newInstance()->_exportVariableToView('categories', Category::newInstance()->toTree() ) ;
        }
        return  View::newInstance()->_get('categories') ;
    }
   
    /* #dev.conquer: review that. If the result of toTree had the same format as items or comments, it would be the same as osc_field */
    function osc_field_toTree($item, $field) {
        if(isset($item[$field])) {
            return $item[$field] ;
        }
        return '' ;
    }

    /**
     * Low level function: Gets the value of the category attribute
     *
     * @return <array>
     */
    function osc_category_field($field, $locale = '') {
        return osc_field_toTree(osc_category(), $field) ;
    }

    /**
     * Gets the number of categories
     *
     * @return int
     */
    function osc_priv_count_categories() {
        return View::newInstance()->_count('categories') ;
    }

    /**
     * Gets the number of subcategories
     *
     * @return int
     */
    function osc_priv_count_subcategories() {
        return View::newInstance()->_count('subcategories') ;
    }

    /**
     * Gets the total of categories. If categories are not loaded, this function will load them.
     *
     * @return int
     */
    function osc_count_categories() {
        if ( !View::newInstance()->_exists('categories') ) {
            View::newInstance()->_exportVariableToView('categories', Category::newInstance()->toTree() ) ;
        }
        return osc_priv_count_categories() ;
    }

    /**
     * Let you know if there are more categories in the list. If categories are not loaded, this function will load them.
     *
     * @return boolean
     */
    function osc_has_categories() {
        if ( !View::newInstance()->_exists('categories') ) {
            View::newInstance()->_exportVariableToView('categories', Category::newInstance()->toTree() ) ;
        }
        return View::newInstance()->_next('categories') ;
    }

    /**
     * Gets the total of subcategories for the current category. If subcategories are not loaded, this function will load them and
     * it will prepare the the pointer to the first element
     *
     * @return int
     */
    function osc_count_subcategories() {
        $category = View::newInstance()->_current('categories') ;
        if ( $category == '' ) return -1 ;
        if ( !isset($category['categories']) ) return 0 ;
        if ( !is_array($category['categories']) ) return 0 ;
        if ( count($category['categories']) == 0 ) return 0;
        if ( !View::newInstance()->_exists('subcategories') ) {
            View::newInstance()->_exportVariableToView('subcategories', $category['categories']) ;
        }
        return osc_priv_count_subcategories() ;
    }

    /**
     * Let you know if there are more subcategories for the current category in the list. If subcategories are not loaded, this
     * function will load them and it will prepare the pointer to the first element
     *
     * @return boolean
     */
    function osc_has_subcategories() {
        $category = View::newInstance()->_current('categories') ;
        if ( $category == '' ) return -1 ;
        if ( !isset($category['categories']) ) return false ;

        if ( !View::newInstance()->_exists('subcategories') ) {
            View::newInstance()->_exportVariableToView('subcategories', $category['categories']) ;
        }
        $ret = View::newInstance()->_next('subcategories') ;
        //we have to delete for next iteration
        if (!$ret) View::newInstance()->_erase('subcategories') ;
        return $ret ;
    }

    /**
     * Gets the name of the current category
     *
     * @param string $locale
     * @return string
     */
    function osc_category_name($locale = "") {
        if ($locale == "") $locale = osc_current_user_locale() ;
        return osc_category_field("s_name", $locale) ;
    }

    /**
     * Gets the description of the current category
     *
     * @param string $locale
     * @return string
     */
    function osc_category_description($locale = "") {
        if ($locale == "") $locale = osc_current_user_locale() ;
        return osc_category_field("s_description", $locale) ;
    }

    /**
     * Gets the id of the current category
     *
     * @param string $locale
     * @return string
     */
    function osc_category_id($locale = "") {
        if ($locale == "") $locale = osc_current_user_locale() ;
        return osc_category_field("pk_i_id", $locale) ;
    }
   
    /**
     * Gets the slug of the current category
     *
     * @param string $locale
     * @return string
     */
    function osc_category_slug($locale = "") {
        if ($locale == "") $locale = osc_current_user_locale() ;
        return osc_category_field("s_slug", $locale) ;
    }

    /**
     * Gets the total items related with the current category
     *
     * @return int
     */
    function osc_category_total_items() {
        return osc_category_field("i_num_items", "") ;
        //$category = osc_category() ;
        //return CategoryStats::newInstance()->getNumItems($category) ;
    }

    /**
     * Reset the pointer of the array to the first category
     *
     * @return void
     */
    function osc_goto_first_category() {
        View::newInstance()->_reset('categories') ;
    }
   
    /**
     * Gets list of non-empty categories
     *
     * @return void
     */
    function osc_get_non_empty_categories() {
        $aCategories = Category::newInstance()->toTree(false);
        View::newInstance()->_exportVariableToView('categories', $aCategories );
        return  View::newInstance()->_get('categories') ;
    }
   
    /**
     * Prints category select
     *
     * @return void
     */
    function osc_categories_select($name = 'sCategory', $category = null, $default_str = null) {
        if($default_str == null) $default_str = __('Select a category');
        CategoryForm::category_select(Category::newInstance()->toTree(), $category, $default_str, $name) ;
    }

    /**
     * Get th category by id or slug
     *
     * @since 3.0
     * @param $by two possibilities: slug or id
     * @param $what the id or slug category we're looking for
     * @return array
     */
    function osc_get_category($by, $what) {
        if( !in_array($by, array('slug', 'id')) ) {
            return false;
        }

        switch ($by) {
            case 'slug':
                return Category::newInstance()->findBySlug($what);
            break;
            case 'id':
                return Category::newInstance()->findByPrimaryKey($what);
            break;
        }
    }
   
    function osc_get_category_items(){
            $conn = getConnection() ;
            $items = $conn->osc_dbFetchResults("SELECT a.s_title, a.fk_i_item_id FROM %st_item_description a JOIN %st_item b ON a.fk_i_item_id = b.pk_i_id AND b.fk_i_category_id = %d", DB_TABLE_PREFIX, DB_TABLE_PREFIX, osc_category_id());
            return $items;
    }

?>

Let me know if you have any questions
Title: Re: sitemap not working properly
Post by: okeypinoy on September 14, 2012, 08:11:53 pm
 ;D ;D ;D Thank you bandsinasia


it work

http://okeypinoy.com/sitemap.xml

 ;D ;D ;D
Title: SOLVED: sitemap not working properly
Post by: telecomseva on September 18, 2012, 02:37:01 am
hi bandsinasia,

thanks for the support.

It works fine.

but there is one small issue in step 1.

when i copy it and paste site goes down.

actually a small issue with the code.

i have clear that. now it is working fine.

here is the solution of code for step-1

find this
    $start_xml = <?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL;
 
and replace with

 $start_xml = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL;

have a look at
http://ads.muquqm.com/sitemap.xml (http://ads.muquqm.com/sitemap.xml)

once again thanks for the support
Title: Re: sitemap not working properly
Post by: telecomseva on September 18, 2012, 03:11:25 am
hi bandsinasia,

there is one issue with sitemap for location.

<url>
<loc>
http://ads.muquam.com/search/country,India/region,Tripura/city,Agartala/
</loc>
<lastmod>2012-09-18</lastmod>
<changefreq>hourly</changefreq>
</url>

this url goes to a blank page only.

but when we change above url in
http://ads.muquam.com/search/region,Tripura/city,Agartala/

it works fine.

can you help me out on this also. how to do it in code.

thanks
Title: Re: sitemap not working properly
Post by: telecomseva on September 18, 2012, 03:36:43 am
hi,

i have figure out this issue by changing the code.

Open your /oc-content/plugins/sitemap_generator/index.php

find
Code: [Select]
foreach($countries as $country) {
        $regions = Region::newInstance()->getByCountry($country['pk_c_code']);
        foreach($regions as $region) {
            $cities = Search::newInstance()->listCities($region['pk_i_id']);
            $l = min(count($cities), 30);
            for($k=0;$k<$l;$k++) {
                if($cities[$k]['items']>$min) {
                    sitemap_add_url(osc_search_url(array('sCountry' => $country['s_name'], 'sRegion' => $region['s_name'], 'sCity' => $cities[$k]['city_name'])), date('Y-m-d'), 'hourly');
                }
            }
        }
    }

replace with
Code: [Select]
foreach($countries as $country) {
        $regions = Region::newInstance()->getByCountry($country['pk_c_code']);
        foreach($regions as $region) {
            $cities = Search::newInstance()->listCities($region['pk_i_id']);
            $l = min(count($cities), 30);
            for($k=0;$k<$l;$k++) {
                if($cities[$k]['items']>$min) {
                    sitemap_add_url(osc_search_url(array('sRegion' => $region['s_name'], 'sCity' => $cities[$k]['city_name'])), date('Y-m-d'), 'hourly');
                }
            }
        }
    }

thanks every one. finally it is working fine.
Title: Re: sitemap not working properly
Post by: evilgenius79 on March 24, 2013, 12:41:46 pm
;D ;D ;D Thank you bandsinasia


it work

http://okeypinoy.com/sitemap.xml

 ;D ;D ;D


how did you add a style to your sitemap?
Title: Re: SOLVED : sitemap not working properly
Post by: evilgenius79 on March 25, 2013, 08:42:16 pm
^^^^^^^^^^^^^^^^^^^lol ban yet?
Title: Re: SOLVED : sitemap not working properly
Post by: vivekshan on April 26, 2018, 11:20:40 pm
there is still one problem in this sitemap generator

after following step 1 and step 2

when i have created sitemap
 

www.yoursite.com/classifieds/health-beauty-fitness/arogyam-pure-herbs-kit-for-psoriasis_11403

before the item id there is " i " like i11403

www.yoursite.com/classifieds/health-beauty-fitness/arogyam-pure-herbs-kit-for-psoriasis_i11403

i is missing
so please complete the things