View source
<?php
function getid3_requirements($phase) {
$t = get_t();
$requirements = array();
if ($phase == 'runtime') {
$requirements['getid3']['title'] = $t('getID3()');
if (getid3_load(FALSE)) {
$requirements['getid3']['value'] = check_plain(getid3_get_version());
$getid3_demos_path = getid3_get_path() . '/../demos';
if (file_exists($getid3_demos_path)) {
$requirements['getid3']['description'] = $t("Your getID3 library is insecure! The demos distributed with getID3 contains code which creates a huge security hole. Remove the demos directory (%path) from beneth Drupal's directory.", array(
'%path' => realpath($getid3_demos_path),
));
$requirements['getid3']['severity'] = REQUIREMENT_ERROR;
}
}
else {
$requirements['getid3']['value'] = $t('Not found or wrong version');
$requirements['getid3']['description'] = $t('You must install <a href="@getid3">getID3()</a> to %getid3dir, or <a href="@getid3settings">configure its installation path</a>.', array(
'@getid3' => 'http://www.getid3.org',
'%getid3dir' => 'sites/all/libraries/getid3',
'@getid3settings' => url('admin/settings/getid3'),
));
$requirements['getid3']['severity'] = REQUIREMENT_ERROR;
}
}
return $requirements;
}
function getid3_load($display_warning = TRUE) {
$getid3_path = getid3_get_path();
if (file_exists($getid3_path . '/getid3.php') && file_exists($getid3_path . '/write.php')) {
if (!defined('GETID3_HELPERAPPSDIR')) {
define('GETID3_HELPERAPPSDIR', realpath($getid3_path . '/../helperapps') . '/');
}
include_once $getid3_path . '/getid3.php';
$getid3 = new getID3();
require_once $getid3_path . '/write.php';
return defined('GETID3_VERSION');
}
else {
drupal_set_message(t("The getID3() module cannot find the getID3 library used to read and write ID3 tags. The site administrator will need to verify that it is installed and then update the <a href='!admin-settings-audio-getid3'>settings</a>.", array(
'!admin-settings-audio-getid3' => url('admin/settings/getid3'),
)), 'error', FALSE);
return FALSE;
}
}
function &getid3_instance() {
$id3 = NULL;
if (getid3_load()) {
$id3 = new getID3();
$id3->option_md5_data = FALSE;
$id3->option_md5_data_source = FALSE;
$id3->encoding = 'UTF-8';
}
return $id3;
}
function &getid3_analyze($path) {
$info = array();
if ($id3 =& getid3_instance()) {
$info = $id3
->analyze($path);
unset($id3);
}
return $info;
}
function getid3_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/getid3',
'title' => t('getID3()'),
'description' => t('Configure settings associated with getID3().'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'getid3_admin_settings',
),
'access' => user_access('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
}
return $items;
}
function getid3_admin_settings() {
$form['getid3_path'] = array(
'#type' => 'textfield',
'#title' => t('Path'),
'#default_value' => getid3_get_path(),
'#description' => t('The location where getID3() is installed. Relative paths are from the Drupal root directory.'),
'#after_build' => array(
'_getid3_admin_settings_check_path',
),
);
if ($version = getid3_get_version()) {
$form['getid3_version'] = array(
'#type' => 'item',
'#title' => t('Version'),
'#value' => '<pre>' . check_plain($version) . '</pre>',
'#description' => t("If you're seeing this it indicates that the getID3 library was found."),
);
$getid3_demos_path = getid3_get_path() . '/../demos';
if (file_exists($getid3_demos_path)) {
drupal_set_message(t("Your getID3 library is insecure! The demos distributed with getID3 contains code which creates a huge security hole. Remove the demos directory (%path) from beneth Drupal's directory.", array(
'%path' => realpath($getid3_demos_path),
)), 'error');
}
}
$form['getid3_show_warnings'] = array(
'#type' => 'checkbox',
'#title' => t("Display Warnings"),
'#default_value' => variable_get('getid3_show_warnings', FALSE),
'#description' => t("Check this to display the warning messages from the getID3 library when reading and writing ID3 tags. Generally it's a good idea to leave this unchecked, getID3 reports warnings for several trivial problems and the warnings can be confusing to users. This setting can be useful when debugging problems with the ID3 tags."),
);
return system_settings_form($form);
}
function _getid3_admin_settings_check_path($form_element) {
$path = $form_element['#value'];
if (!is_dir($path) || !(file_exists($path . '/getid3.php') && file_exists($path . '/write.php'))) {
form_set_error($form_element['#parents'][0], t('The getID3 files <em>getid3.php</em> and <em>write.php</em> could not be found in the %path directory.', array(
'%path' => $path,
)));
}
return $form_element;
}
function getid3_get_path() {
return variable_get('getid3_path', 'sites/all/libraries/getid3/getid3');
}
function getid3_get_version() {
return getid3_load(FALSE) ? GETID3_VERSION : NULL;
}