You are here

xmlsitemap.install in XML sitemap 5

File

xmlsitemap.install
View source
<?php

/**
 * Implementation of hook_install().
 */
function xmlsitemap_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {xmlsitemap_additional} (\n        path varchar(128) NOT NULL default '',\n        pid int,\n        last_changed int(11),\n        previously_changed int(11),\n        priority float,\n        PRIMARY KEY (path)\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {xmlsitemap_additional} (\n        path varchar(128) NOT NULL default '',\n        pid integer,\n        last_changed integer,\n        previously_changed integer,\n        priority real,\n        PRIMARY KEY (path)\n      );");
      break;
  }
  db_query("DELETE FROM {url_alias} WHERE dst LIKE 'sitemap%.xml'");
}

/**
 * Implementation of hook_enable().
 */
function xmlsitemap_enable() {
  global $base_path;
  $xsl = file_get_contents(drupal_get_path('module', 'xmlsitemap') . '/gss/gss.xsl');
  $css_start = strpos($xsl, '<link href="') + strlen('<link href="');
  $css_length = strpos($xsl, '" type="text/css" rel="stylesheet"/>') - $css_start;
  $xsl = substr_replace($xsl, $base_path . drupal_get_path('module', 'xmlsitemap') . '/gss/gss.css', $css_start, $css_length);
  $js_start = strpos($xsl, '<script src="') + strlen('<script src="');
  $js_length = strpos($xsl, '"></script>') - $js_start;
  $xsl = substr_replace($xsl, $base_path . drupal_get_path('module', 'xmlsitemap') . '/gss/gss.js', $js_start, $js_length);
  if (file_check_directory($path = file_directory_path() . '/xmlsitemap', FILE_CREATE_DIRECTORY)) {
    file_save_data($xsl, "{$path}/gss.xsl", FILE_EXISTS_REPLACE);
  }
  _xmlsitemap_gsitemap_replace();
}

/**
 * Replace Google Sitemap if it is installed.
 */
function _xmlsitemap_gsitemap_replace() {
  if (db_result(db_query("\n    SELECT 1 FROM {system}\n    WHERE type = 'module' AND name = 'gsitemap' AND (status = 1 OR schema_version >= 0)\n  "))) {
    db_query("\n      INSERT INTO {xmlsitemap_additional} (path, pid, last_changed, previously_changed, priority)\n      SELECT path, pid, last_changed, previously_changed, priority FROM {gsitemap_additional}\n    ");
    $modules = array(
      'xmlsitemap_node',
      'xmlsitemap_engines',
    );
    if (variable_get('gsitemap_showterms', FALSE)) {
      $modules[] = 'xmlsitemap_term';
      variable_del('gsitemap_showterms');
    }
    if (variable_get('gsitemap_showusers', FALSE)) {
      $modules[] = 'xmlsitemap_user';
      variable_del('gsitemap_showusers');
    }
    drupal_install_modules($modules);
    $settings = db_query("SELECT * FROM {variable} WHERE name LIKE 'gsitemap\\_%'");
    while ($variable = db_fetch_object($settings)) {
      switch ($variable->name) {
        case 'gsitemap_frontpage':
          $name = 'xmlsitemap_front_page_priority';
          break;
        case 'gsitemap_priority':
          $name = 'xmlsitemap_additional_links_priority';
          break;
        case 'gsitemap_logacc':
          $name = 'xmlsitemap_log_access';
          break;
        default:
          $name = 'xmlsitemap' . strstr($variable->name, '_');
          break;
      }
      variable_set($name, (double) unserialize($variable->value));
    }
    module_disable(array(
      'gsitemap',
    ));
    drupal_uninstall_module('gsitemap');
  }
}

/**
 * Implementation of hook_disable().
 */
function xmlsitemap_disable() {
  $path = file_directory_path() . '/xmlsitemap';
  if ($dir = @opendir($path)) {
    while (($file = readdir($dir)) !== FALSE) {
      if ($file != '.' && $file != '..') {
        unlink("{$path}/{$file}");
      }
    }
    closedir($dir);
    rmdir($path);
  }
}

/**
 * Implementation of hook_uninstall().
 */
function xmlsitemap_uninstall() {
  db_query("DROP TABLE {xmlsitemap_additional}");
  $settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'xmlsitemap\\_%'");
  while ($variable = db_fetch_object($settings)) {
    variable_del($variable->name);
  }
}

Functions

Namesort descending Description
xmlsitemap_disable Implementation of hook_disable().
xmlsitemap_enable Implementation of hook_enable().
xmlsitemap_install Implementation of hook_install().
xmlsitemap_uninstall Implementation of hook_uninstall().
_xmlsitemap_gsitemap_replace Replace Google Sitemap if it is installed.