You are here

function _xmlsitemap_xml_links in XML sitemap 5

Extract links from site maps returned by hook_xmlsitemap_links().

Return value

An array of links.

Related topics

1 call to _xmlsitemap_xml_links()
xmlsitemap_xmlsitemap_links in ./xmlsitemap.module
Implementation of hook_xmlsitemap_links().

File

./xmlsitemap.module, line 666
Creates a site map compatible with the sitemaps.org schema.

Code

function _xmlsitemap_xml_links() {
  $links = array();
  $xml = module_invoke_all('xmlsitemap_links', 'xml');
  $xml = array_merge($xml, module_invoke_all('gsitemap', 'xml'));
  foreach ($xml as $entries) {
    $start = strpos($entries, '<url>');
    if ($start !== FALSE) {
      $length = strpos($entries, '</urlset>') - $start;
      $entries = substr($entries, $start, $length);
      $entries = explode('<url>', $entries);
      foreach ($entries as $value) {
        if (($start = strpos($value, '<loc>')) !== FALSE) {
          $length = $start + strlen('<loc>');
          $link['#loc'] = substr($value, $length, strpos($value, '</loc>') - $length);
          if (($start = strpos($value, '<lastmod>')) !== FALSE) {
            $length = $start + strlen('<lastmod>');
            $t = array_shift(explode('+', substr($value, $length, strpos($value, '</lastmod>') - $length)));
            $t = explode('T', $t);
            $t = array_merge(explode('-', $t[0]), explode(':', $t[1]));
            $link['#lastmod'] = gmmktime($t[3], $t[4], $t[5], $t[1], $t[2], $t[0]);
          }
          if (($start = strpos($value, '<changefreq>')) !== FALSE) {
            $length = $start + strlen('<changefreq>');
            $link['#changefreq'] = substr($value, $length, strpos($value, '</changefreq>') - $length);
          }
          if (($start = strpos($value, '<priority>')) !== FALSE) {
            $length = $start + strlen('<priority>');
            $link['#priority'] = substr($value, $length, strpos($value, '</priority>') - $length);
          }
          $links[] = $link;
        }
      }
    }
  }
  return $links;
}