You are here

parser_simplepie.install in FeedAPI 5

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

File

parser_simplepie/parser_simplepie.install
View source
<?php

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

  // Set the parser of defaultly shipped processors if it's not done previously
  $default_processors = array(
    'feed',
    'feedapi_aggregator',
  );
  $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');
}
function parser_simplepie_update_1() {
  $path_to_files = file_create_path(file_directory_path() . '/simplepie_cache');
  if (!file_exists($path_to_files)) {
    mkdir($path_to_files);
  }
  if (!is_writeable($path_to_files)) {
    return FALSE;
  }
  variable_set('parser_simplepie_cache', $path_to_files);
  return array();
}

Functions