You are here

robotstxt.install in RobotsTxt 6

Same filename and directory in other branches
  1. 8 robotstxt.install
  2. 5 robotstxt.install
  3. 7 robotstxt.install

File

robotstxt.install
View source
<?php

/**
 * Implementation of hook_install().
 */
function robotstxt_install() {
  if (file_exists('./robots.txt')) {
    variable_set('robotstxt', file_get_contents('./robots.txt'));
  }
  elseif (file_exists(drupal_get_path('module', 'robotstxt') . '/robots.txt')) {
    variable_set('robotstxt', file_get_contents(drupal_get_path('module', 'robotstxt') . '/robots.txt'));
  }
}

/**
 * Implementation of hook_uninstall().
 */
function robotstxt_uninstall() {
  variable_del('robotstxt');
}

/**
 * Implementation of hook_requirements().
 */
function robotstxt_requirements($phase) {
  $requirements = array();
  $t = get_t();
  switch ($phase) {
    case 'runtime':

      // Module cannot work without Clean URLs.
      if (!variable_get('clean_url', 0)) {
        $requirements['robotstxt_cleanurl'] = array(
          'title' => $t('RobotsTxt'),
          'severity' => REQUIREMENT_ERROR,
          'value' => $t('<a href="!clean_url">Clean URLs</a> are mandatory for this module.', array(
            '!clean_url' => url('admin/settings/clean-urls'),
          )),
        );
      }

      // Webservers prefer the robots.txt file on disk and does not allow menu path overwrite.
      if (file_exists('./robots.txt')) {
        $requirements['robotstxt_file'] = array(
          'title' => $t('RobotsTxt'),
          'severity' => REQUIREMENT_WARNING,
          'value' => $t('RobotsTxt module works only if you remove the existing robots.txt file in your website root.'),
        );
      }
  }
  return $requirements;
}

/**
 * Automatically add the 'administer robots.txt' permission to granted users.
 */
function robotstxt_update_6100() {
  $ret = array();
  $res = db_query('SELECT rid, perm FROM {permission}');
  $perms = array();
  while ($p = db_fetch_object($res)) {
    $perm = $p->perm;
    $perm = preg_replace('/administer site configuration/', 'administer site configuration, administer robots.txt', $perm);
    $perms[$p->rid] = $perm;
  }
  foreach ($perms as $key => $value) {
    db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $value, $key);
  }
  return $ret;
}

Functions

Namesort descending Description
robotstxt_install Implementation of hook_install().
robotstxt_requirements Implementation of hook_requirements().
robotstxt_uninstall Implementation of hook_uninstall().
robotstxt_update_6100 Automatically add the 'administer robots.txt' permission to granted users.