You are here

jplayer.install in jPlayer 8.2

Same filename and directory in other branches
  1. 6 jplayer.install
  2. 7.2 jplayer.install

Installation file for jPlayer module.

File

jplayer.install
View source
<?php

/**
 * @file
 * Installation file for jPlayer module.
 */

/**
 * Implements hook_schema().
 */
function jplayer_schema() {
}

/**
 * Implements hook_requirements().
 */
function jplayer_requirements($phase) {
  $requirements = array();
  if ($phase == 'runtime') {
    $requirements['jplayer']['title'] = t('jPlayer');
    if ($jplayer_version = jplayer_get_version()) {
      $requirements['jplayer']['value'] = $jplayer_version;
      $requirements['jplayer']['severity'] = REQUIREMENT_OK;
    }
    else {
      $requirements['jplayer']['value'] = t('Not found');
      $requirements['jplayer']['description'] = t('Missing the jPlayer library. Please !download and extract it into the %directory directory.', array(
        '!download' => \Drupal::l('download jPlayer library', \Drupal\Core\Url::fromUri('http://www.jplayer.org/download/')),
        '%directory' => \Drupal::config('jplayer.settings')
          ->get('jplayer_directory'),
      ));
      $requirements['jplayer']['severity'] = REQUIREMENT_ERROR;
    }
  }
  return $requirements;
}

/**
 * Implements hook_uninstall().
 */
function jplayer_uninstall() {
  \Drupal::config('jplayer.settings')
    ->clear('jplayer_access_time')
    ->save();
}

/**
 * Add a table to track when direct file downloads are denied.
 */
function jplayer_update_7001() {
  $schema = array();
  $schema['jplayer_denied'] = array(
    'description' => 'Contains user statistics for when a user is blocked from downloading a file.',
    'fields' => array(
      'uid' => array(
        'description' => 'The user ID of the user.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'fid' => array(
        'description' => 'The file ID that was denied access.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'hostname' => array(
        'description' => 'The hostname of the user that was denied access.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
      ),
      'timestamp' => array(
        'description' => 'The last time this user was denied access.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'uid',
      'fid',
      'timestamp',
    ),
    'indexes' => array(
      'uid' => array(
        'uid',
      ),
      'fid' => array(
        'fid',
      ),
      'hostname' => array(
        'hostname',
      ),
      'timestamp' => array(
        'timestamp',
      ),
    ),
  );

  // If the site is being upgraded from a 6.x release, this table might exist.
  if (!db_table_exists('jplayer_denied')) {
    db_create_table('jplayer_denied', $schema['jplayer_denied']);
  }
}

/**
 * Transition to the jplayer_protect module if jplayer content protection is
 * enabled. */
function jplayer_update_7002() {
  if (\Drupal::config('jplayer.settings')
    ->get('jplayer_protected')) {
    \Drupal::config('jplayer.settings')
      ->set('jplayer_protect', TRUE)
      ->save();
    if (!\Drupal::moduleHandler()
      ->moduleExists('jplayer_protect')) {
      module_enable(array(
        'jplayer_protect',
      ));
      db_drop_table('jplayer_protect_denied');
      db_rename_table('jplayer_denied', 'jplayer_protect_denied');
    }
    else {
      return t('It appears that the jplayer_protect module has been manually enabled. Please move any data from the {jplayer_protect} table to the {jplayer_protect_denied} table and drop the {jplayer_protect} table.');
    }
  }
  else {
    db_drop_table('jplayer_denied');
  }
  \Drupal::config('jplayer.settings')
    ->clear('jplayer_protected')
    ->save();
}

Functions

Namesort descending Description
jplayer_requirements Implements hook_requirements().
jplayer_schema Implements hook_schema().
jplayer_uninstall Implements hook_uninstall().
jplayer_update_7001 Add a table to track when direct file downloads are denied.
jplayer_update_7002 Transition to the jplayer_protect module if jplayer content protection is enabled.