Hello, I would like to add links output by the views module. I don't expect XML sitemap to automatically integrate with the way I've output links using Views, but it would be nice if XML permitted manual addition of these links. To see what I mean, you can visit:
http://www.checkmarkmedia.com/giancoli-physics-6th-edition-solutions/cha...
This page contains an attachment display containing many links that I'd like to add to my sitemap.

Comments

dave reid’s picture

Status: Active » Fixed

That's exactly why we have the new xmlsitemap_custom sub-module. :) Enable that module and then go to admin/settings/xmlsitemap/custom

shaundychko’s picture

Ahhhhh, sorry about the rookie mistake. I had tried the custom module, but mistakenly pasted the entire absolute URL, including the domain, and got the error message: "The custom link [big link with domain] is either invalid or it cannot be accessed by anonymous users.". I doubt many others will make the same mistake, since on second glance it's quite clear what to do, but perhaps, if you have spare time for very minor details, the error checking could look for this mistake since it's quite natural to copy and paste the entire URL.

Thank you very much for rewriting this module. Even with the "unstable" version I've been VERY happy with it, and I'm especially pleased about this custom URL feature.

avpaderno’s picture

Title: custom arbitrary links (used in views) » Custom arbitrary links (used in views)

Looking at what done from Drupal core code in http://example.com/admin/settings/site-information, the description for the field Default front page reports the URL is relative, even though that should be clean from the text rendered before the textfield (which is the same text rendered in the XML sitemap settings page).

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

vacilando’s picture

Version: 6.x-2.0-unstable6 » 6.x-2.0-beta1
Category: feature » support
Status: Closed (fixed) » Active

I need to add custom links to the sitemap, many thousands of them for each website. The way I understand it, /admin/settings/xmlsitemap/custom is not a solution for me, since that allows adding individual links only.
Since the links I need to add are actually produced by views, I briefly thought http://drupal.org/node/507674 was the answer. But that seems to be just a recipe preceding the above custom link adding system.

So I guess need to add them programmatically. I found http://drupal.org/node/264655 which points to http://drupalcontrib.org/api/function/hook_xmlsitemap_links/xmlsitemap
Seems like the answer, but I am not totally clear about the details.
I guess I need to implement hook_xmlsitemap_links() in my module and put in it an array of all the custom links. I am assuming that when xmlsitemap runs (by cron or on manual rebuild process) then this hook is used and the array is incorporated into the sitemap. Correct?
The last thing I am not sure about is what will happen in cases when my array of links will contain 100k links. Will xmlsitemap (cron, rebuild batch) manage such a large array - will it break it into pieces and gradually import or will it choke because of lack of memory? If this is not the way how to add very large sets of links, then how should I do it?
Thanks a lot for any comments!

vacilando’s picture

Issue tags: +views, +sitemap, +custom

Further to #5 -- I've done a test.
I took a views-produced link http://www.mysite.tld/path/abc123 and added the following code in my module called 'mymodule':

function mymodule_xmlsitemap_links() {
  $links = array();

  $links[] = array(
    'type' => 'mymodule',
    'id' => 'abc123',
    'loc' => 'path',
    'lastmod' => time(),
    'changefreq' => 4600,
    'priority' => 0.5,
  );

  return $links;
}

But after rebuilding the URL http://www.mysite.tld/path/abc123 is not in the sitemap. Looked for xmlsitemap errors in /admin/reports/dblog but there was just one message saying the rebuild had completed successfully.
What am I doing wrong?

Also, how to submit 100k links like this - the same way? (See #5.)

vacilando’s picture

One month later... did a number of tests in beta1 and in dev in the meantime but the above code (#6) never includes my views links in the sitemap. Could somebody please advise what's the correct method for adding such links programmatically?

shaundychko’s picture

I think this comment: http://drupal.org/node/499670#comment-1761566

combined with this module (currently in dev): http://drupal.org/project/views_build_menu

could provide a clean solution for this issue, but in the meantime, for the bold (and careless?) hackers, here's a solution that sort of works for my specific scenario. I want to include nodes that are returned by a view. The content type must be excluded from the xmlsitemap by default, so the following is to avoid clicking on the sitemap include option on each node edit page.

Using http://drupal.org/project/views_bonus I exported a list of node id's in csv format. Using phpmyadmin, import this into a new table (called get_these in this example) which has a column of type integer (called nid). With the xmlsitemap table selected, choose the SQL tab, and paste the following code:

UPDATE xmlsitemap,get_these SET xmlsitemap.status='1',xmlsitemap.status_override='1'
WHERE xmlsitemap.id=get_these.nid

This works only if the content type was previously included by default, with a subsequent cron run in order to put them into the xmlsitemap table, and then disabled, followed by cron, which, instead of deleting them from the table, sets the status and status_override values to 0. Furthermore, after running the SQL above successfully, the sitemap needs to be rebuilt at /admin/settings/xmlsitemap/rebuild since a mere cron run will not pick up the new entries.

I can't wait for a better way of doing this! =)

shaundychko’s picture

As another approach, I've tried creating a module that uses the xmlsitemap_custom module, and views. It works until it encounters a form validation error (such as when a node already exists in the sitemap). Would someone care to help solving this issue? I think the module should work if drupal_execute() could keep processing beyond when it encounters the validation error. The dpm() in here shows that the code loops through all nodes returned by the view, but drupal_execute() doesn't process after an error.

xml_views.info:

; $Id$
name = xml_views
description = Add links from a View to the XML Sitemap
core = 6.x

xml_views.module:

<?php

/**
 * Implementation of hook_menu()
 * 
 * Hook menu registers page callbacks with Drupal's central menu system
 */
 
function xml_views_menu() {
  $items = array();
  
  $items['admin/settings/xml_views'] = array(
    'title' => 'xml_views settings',
    'description' => 'Configuration options for the xml_views module',
    'page callback' => 'xml_views_admin_settings',
    'access callback' => 'user_access',
    'access arguments' => array('administer site configuration')
  );
  
  return $items;
}

/**
 * Page callback for admin settings
 */
function xml_views_admin_settings() {
  return drupal_get_form('xml_views_settings_form');
}

/**
 * Function that creates the admin/settings/xml_views form
 */
function xml_views_settings_form() {
  $form = array();
  
  $form['view_name'] = array(
    '#type' => 'textfield',
    '#title' => t('view_name'),
    '#description' => t('Enter the name of the view that loads all the nodes 
       which should be included in the xml sitemap. The default display 
       will be used.'),
    '#required' => TRUE
  );
  
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Save settings'
  );
  return $form;
}

/**
 * submit function for admin/settings/xml_views form
 */
function xml_views_settings_form_submit(&$form, &$form_state) {
  // Load xmlsitemap_custom.admin.inc
  module_load_include('inc', 'xmlsitemap_custom', 'xmlsitemap_custom.admin');

  $view_name = $form_state['values']['view_name'];
  $view_result = array();
  $view_result = views_get_view_result($view_name);
  foreach($view_result as $item){
    $form_state = array();
    $form_state['values']['loc'] = drupal_get_path_alias('node/' . $item->nid);
    dpm($form_state['values']['loc']);
    drupal_execute('xmlsitemap_custom_edit_link_form', $form_state);
  }
}
vacilando’s picture

Finally got #6 to work.

Very briefly, my 2 cents worth:

1) Instead of making an array of arrays, each array simply needs to be saved using xmlsitemap_link_save($singlelinkarray)
2) Also, you need to call hook_xmlsitemap_links() in your hook_cron()

Cron then adds links to the xmlsitemap table.
By running a rebuild the actual sitemap files are then created on from that table.

It works for me -- at least before someone suggests a better approach.

Enjoy!

samuelet’s picture

#10 works also for me, thanks Vacilando.
About this workaround, i'm pretty sure that the sitemap "Maximum number of sitemap links to process at once:" setting is not automatically applied in this approach, so that you have to take care yourself of such implementation in case you have an high amount of links to add.

rag_gupta’s picture

Issue summary: View changes

We can as well generate custom links(like from Views arguments: /category/jobs/%) using a php module/script and generate a simple txt file which we can submit to Google/Bing. Any special advantage in adding such bulk links using XML Sitemap module?

avpaderno’s picture

Version: 6.x-2.0-beta1 » 6.x-2.x-dev
Status: Active » Closed (outdated)
Issue tags: -views, -sitemap, -custom

I am closing this issue, which is for a not supported Drupal version.