Auto Sitemap ( Dinamic SEO sitemap.xml generation) v0.1

  • I tested it for user profiles, blogs and main url it is working great.

    For group profiles and tidypics, images, albums it is not working.

    I am using medias plugin for video same for that.

    How to add more options like for user profiles and blogs?

  • do you see checkboxes for those entities in the last section of the plugin settings page ?

    remain checked after save settings?

    Plugin is onli tested tested with blog, event_calendar andd users profiles 

  • and with some custom entities of my site 

  • entities remain unchecked after save.

    I try to add some manuall entities in start.php file those work but display mixed result.

  • maybe a javascript  error?

    checkboxes of the last section have a hidden input where selected entities are stored. Its filled by javascript. It is working for you?

    you can try to change "input/hidden" to "input/text" for debug

    let me know

  • Manually added entities worked for me. I am going to post start.php in next message.

    Here is a easy way to add search engine ping option.

    http://converg.com/why-you-should-ping-your-sitemap/

     

  • <?php
    /* ######################################################
     *  Ramón Iglesias
     *  monchomail@gmail.com
     *  12-08-2012
     * ###################################################### */

    elgg_register_event_handler('init', 'system', 'auto_sitemap_init');

    // Busco las entidades que deben aparecer en el sitemap y se las paso a la vista
    global $relevantEntities;
    $relevantEntities = Array('user' , 'group' , 'blog' ,'file' , 'event' ,'media' ,'image' ,'album');    


    /* =============================================================== */
    function auto_sitemap_init() {
        
        // Registro el controlador
        elgg_register_page_handler('auto_sitemap','auto_sitemap_page_handler');

    }

    /* =============================================================== */
    function auto_sitemap_page_handler($page) {

        $esquema = elgg_get_plugin_setting('esquema');
        if ( empty( $esquema )){
            $esquema = 'sitemap_org_0_9';
        }
        
        switch ($page[0]) {
            
            // ------------------------------------------------------------------------------------
            case 'index':        

                // custom URLs
                $sitemaps[] = 'custom' ;

                // relevant entities
                global $relevantEntities;
                
                foreach ($relevantEntities as $entity) {
                    if ( elgg_get_plugin_setting( $entity . '_url') ){
                        $sitemaps[] = $entity;
                    }
                }            
                
                // other entities
                $otherActiveEntities = array_filter(explode(',' , elgg_get_plugin_setting('other_urls_types')));
                
                if ( !empty($otherActiveEntities)){
                    $sitemaps[] = 'other' ;
                }

                // Pinto el sitemap (indice)
                echo elgg_view('auto_sitemap/' . $esquema . "/sitemapindex", array('sitemaps' => $sitemaps));
                
                return true;
                
            break;

            // ------------------------------------------------------------------------------------
            case 'custom':        
                
                $tipos = Array( 'always' , 'hourly' , 'daily' ,'weekly' , 'monthly', 'yearly', 'never');                    
                $urls = auto_sitemap_getCustomUrls( $tipos );

                // if no custom urls configured, sitemap doesnt exists
                if ( empty($urls) ){                
                    // sitemap doesnt exists
                    return false;
                                    
                }else{
                    echo elgg_view('auto_sitemap/' . $esquema . "/0_9_scheme", array('urls' => $urls));                
                    return true;
                                                    
                }
                
                
            break;
            
            // ------------------------------------------------------------------------------------        
            case 'user':        
            case 'group':        
            case 'blog':        
            case 'file':        
            case 'event':
            case 'media':
            case 'image':
            case 'album':
                    
                $urls = auto_sitemap_getEntityUrls( $page[0] );            

                // if this entity is not active in settigs sitemap doesnt exists
                if ( ! elgg_get_plugin_setting($page[0] . '_url') ){                
                    return false;
                                    
                }else{
                    echo elgg_view('auto_sitemap/' . $esquema . "/0_9_scheme", array('urls' => $urls));                
                    return true;
                                                    
                }            
                
            break;
            
            // ------------------------------------------------------------------------------------                
            case 'other':    
                
                $otherActiveEntities = array_filter(explode(',' , elgg_get_plugin_setting('other_urls_types')));
                
                $urls = auto_sitemap_getOtherEntityUrls( $otherActiveEntities );    

                // if no other entities selected in settings, sitemap doesnt exists
                if ( empty($urls) ){                
                    return false;
                                    
                }else{
                    echo elgg_view('auto_sitemap/' . $esquema . "/0_9_scheme", array('urls' => $urls));                
                    return true;
                                                    
                }
                
            break;            
            
            // ------------------------------------------------------------------------------------        
            default:
                return false;
            break;
        }
    }





    /* =============================================================== */
    function auto_sitemap_getCustomUrls( $tipos ){
        
        // get main url
        $mainurl = elgg_get_plugin_setting('main_url');
        $changefreq = elgg_get_plugin_setting('main_url_changefreq');
        $priority = elgg_get_plugin_setting('main_url_priority');

        if ( !empty($mainurl) ){
            $urls[] = Array(
                            'loc' => $mainurl,
                            'changefreq' => $changefreq,
                            'priority' => $priority
                        );
        }
        
        // get custmo urls
        foreach ($tipos as $tipo) {

            $urlList = Array();    
            $urlList = explode("\n", elgg_get_plugin_setting( $tipo . '_url'));                
            $priority = elgg_get_plugin_setting( $tipo . '_url_priority');
            
            foreach ($urlList as $url) {
                if ( ! empty($url) ){                                
                    $urls[] = Array(
                                    'loc' => $url,
                                    'changefreq' => $tipo,
                                    'priority' => $priority
                                );
                }
            }
        }
        

        return $urls;
    }

    /* =============================================================== */
    function auto_sitemap_getEntityUrls( $tipo ){
        
        switch ($tipo) {
            case 'user':
                $options['type'] = 'user';
                
            break;
            case 'media':
            case 'image':
            case 'album':
            case 'group':
            case 'blog':
            case 'file':
                $options['type'] = 'object';
                $options['subtypes'] = $tipo;            
            break;
            
            case 'event':
                $options['type'] = 'object';
                $options['subtypes'] = 'event_calendar';
            break;        
        }
        
        $changefreq = elgg_get_plugin_setting( $tipo . '_url_changefreq');
        $priority = elgg_get_plugin_setting( $tipo . '_url_priority');
        $options['limit'] = '5000';
                
        $entradas = elgg_get_entities($options);
                
        foreach ($entradas as $value) {
            
            $entityUrls[] = array('loc' => $value->getURL(),
                                    'lastmod' => $value->getTimeUpdated(),
                                    'changefreq' => $changefreq,
                                    'priority' => $priority
                                );
        }        
            
        // Ordeno por fecha
        usort($entityUrls, 'auto_sitemap_comparar');
        
        return $entityUrls;
        
    }


    /* =============================================================== */
    function auto_sitemap_getOtherEntityUrls( $entities ){
        
        foreach ($entities as $entity) {

            $options['type'] = 'object';
            $options['subtypes'] = $entity;            
            
            $changefreq = elgg_get_plugin_setting('other_url_changefreq');
            $priority = elgg_get_plugin_setting('other_url_priority');
            $options['limit'] = '5000';
                    
            $entradas = elgg_get_entities($options);
                    
            foreach ($entradas as $value) {
                
                $entityUrls[] = array('loc' => $value->getURL(),
                                        'lastmod' => $value->getTimeUpdated(),
                                        'changefreq' => $changefreq,
                                        'priority' => $priority
                                    );
            }        
        }
            
        // Ordeno por fecha
        usort($entityUrls, 'auto_sitemap_comparar');
        
        return $entityUrls;
        
    }


    /* =============================================================== */
    function xml_plugin_get_otherEntityTypes() {
        $valid_types = array();
        $entity_stats = get_entity_statistics();
        
        foreach($entity_stats['object'] as $subtype => $counter) {
            if ($subtype != 'plugin' &&
                $subtype != '__base__' &&
                $subtype != 'admin_notice' &&
                $subtype != 'messages' &&
                $subtype != 'widget' &&
                $subtype != 'blog' &&
                $subtype != 'file' &&
                $subtype != 'event_calendar'
                ) {
                    $valid_types[elgg_echo($subtype)] = $subtype;
            }
        }
        return $valid_types;
    }


    /* =============================================================== */
    function auto_sitemap_comparar($x,$y){
        if ( $x['lastmod'] == $y['lastmod'] )
            return 0;
        else if ( $x['lastmod'] > $y['lastmod'] )
            return -1;
        else
            return 1;
    }


    ?>

  • Now everything is working for me except group profiles.

    BTW you done a great job.....I am going to recomend this plugin for everyone..

    thanks

     

  • One more error found. it is given by google webmasters. For all urls .xml extension is missing....check below message.

    Errors
    Missing XML tag
    This required tag is missing. Please add it and resubmit.
    1
    Parent tag: urlset
    Tag: url
  • ok this is just for groups because it is not working.

  • I realized that groups are types instead of subtypes. So they shoud be processede like "users".

    I'll fix that tomorrow.  wait for a second release

  • Ok it also works for me now.. thanks

Stats

  • Category: Misc
  • License: GNU General Public License (GPL) version 2
  • Updated: 2014-11-17
  • Downloads: 3282
  • Recommendations: 22

Other Projects

View the_yke's plugins