You are here

phantomjs_capture.install in PhantomJS Capture 7

Same filename and directory in other branches
  1. 8 phantomjs_capture.install

File

phantomjs_capture.install
View source
<?php

/**
 * Implements hook_install().
 */
function phantomjs_capture_install() {
  $directory = file_default_scheme() . '://phantomjs';
  $test_directory = file_default_scheme() . '://phantomjs/test';
  file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS, TRUE);
  file_prepare_directory($test_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS, TRUE);
}

/**
 * Implements hook_requirements().
 * @param $phase
 * @return array
 */
function phantomjs_capture_requirements($phase) {
  $requirements = [];
  $enabled = _is_exec_enabled();
  $url = "http://php.net/manual/en/function.exec.php";
  if ($enabled) {
    $message = t('The !url command is available.', [
      '!url' => l('exec()', $url),
    ]);
  }
  else {
    $message = t('The !url command is not available or the user has no permission to use it, you will be unable to use the phantomjs binary.', [
      '!url' => l('exec()', $url),
    ]);
  }
  $requirements['phantomjs_capture'] = [
    'title' => t('PhantomJS Capture'),
    'value' => $message,
    'severity' => $enabled ? REQUIREMENT_OK : REQUIREMENT_ERROR,
  ];
  return $requirements;
}

/**
 * Return if exec is enabled and can be executed by the user.
 *
 * Taken from a combination of answers online.
 * @see http://stackoverflow.com/questions/3938120/check-if-exec-is-disabled
 *
 * @return bool
 */
function _is_exec_enabled() {
  $safe_mode = ini_get('safe_mode');
  if ($safe_mode && drupal_strtolower($safe_mode) != 'off') {
    return FALSE;
  }
  $disabled = explode(',', ini_get('disable_functions'));
  return !in_array('exec', $disabled);
}

Functions

Namesort descending Description
phantomjs_capture_install Implements hook_install().
phantomjs_capture_requirements Implements hook_requirements().
_is_exec_enabled Return if exec is enabled and can be executed by the user.