You are here

parser_simplepie.install in FeedAPI 6

Same filename and directory in other branches
  1. 5 parser_simplepie/parser_simplepie.install

Install file for Parser SimplePie module.

File

parser_simplepie/parser_simplepie.install
View source
<?php

/**
 * @file
 * Install file for Parser SimplePie module.
 */

/**
 * Implementation of hook_requirements().
 */
function parser_simplepie_requirements($phase) {
  $requirements = array();

  // Ensure translations don't break at install time
  $t = get_t();
  switch ($phase) {
    case 'install':
    case 'runtime':
      if (module_exists('libraries') && file_exists(libraries_get_path('simplepie') . '/simplepie.inc')) {
        $path = libraries_get_path('simplepie') . '/simplepie.inc';
      }
      else {
        $path = dirname(__FILE__) . '/simplepie.inc';
      }
      if (!file_exists($path)) {
        $requirements['parser_simplepie'] = array(
          'title' => $t("FeedAPI SimplePie"),
          'description' => $t("Obtain the !simplepie package from http://simplepie.org/downloads and copy simplepie.inc to the parser_simplepie directory."),
          'severity' => $phase == 'install' ? REQUIREMENT_WARNING : REQUIREMENT_ERROR,
          'value' => $t('simplepie.inc file missing'),
        );
      }
      elseif ($phase == 'runtime') {
        require_once $path;
        $requirements['parser_simplepie'] = array(
          'title' => $t('SimplePie Parser'),
          'description' => t('The current installed version of SimplePie is !version', array(
            '!version' => '<strong>' . SIMPLEPIE_VERSION . '</strong>',
          )),
          'severity' => REQUIREMENT_OK,
          'value' => $t('Installed correctly'),
        );
      }
  }
  return $requirements;
}

/**
 * Implementation of hook_install().
 */
function parser_simplepie_install() {
  $path = drupal_get_path('module', 'parser_simplepie') . '/simplepie.inc';
  if (!file_exists($path)) {
    drupal_set_message('<strong>' . t("To use SimplePie parser, obtain the SimplePie package from http://simplepie.org/downloads and copy simplepie.inc to the parser_simplepie directory.") . '</strong>');
  }

  // Set the parser of defaultly shipped processors if it's not done previously
  $default_processors = array(
    'feed',
  );
  $set_simplepie = array(
    "parsers" => array(
      "parser_simplepie" => array(
        "enabled" => TRUE,
        "weight" => 0,
      ),
    ),
  );
  foreach ($default_processors as $processor) {
    $settings = variable_get('feedapi_settings_' . $processor, FALSE);
    if (!isset($settings['parsers'])) {
      $settings = is_array($settings) ? array_merge($settings, $set_simplepie) : $set_simplepie;
      variable_set('feedapi_settings_' . $processor, $settings);
    }
  }
}

/**
 * Implementation of hook_uninstall().
 */
function parser_simplepie_uninstall() {

  // Empty cache directory
  $cache_dir = variable_get('parser_simplepie_cache', FALSE);
  if (is_dir($cache_dir)) {
    $dp = opendir($cache_dir);
    while (($file = readdir($dp)) !== FALSE) {
      if (is_file($file)) {
        unlink($cache_dir . '/' . $file);
      }
    }
    closedir($dp);
    rmdir($cache_dir);
  }
  variable_del('parser_simplepie_cache');
}

Functions