From 9af4b1227b3335666a2aacc6b2c4a95cf9108239 Mon Sep 17 00:00:00 2001 From: Edison Wong Date: Sun, 29 May 2011 22:52:57 +0800 Subject: [PATCH] Issue #173616: Switch to Libraries API. --- getid3.admin.inc | 16 ++++------------ getid3.install | 15 ++++++++++----- getid3.module | 51 ++++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 56 insertions(+), 26 deletions(-) diff --git a/getid3.admin.inc b/getid3.admin.inc index 1387033..8971662 100644 --- a/getid3.admin.inc +++ b/getid3.admin.inc @@ -12,7 +12,7 @@ function getid3_admin_settings_form() { '#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.'), + '#description' => t('The location where getID3 library is installed. Relative paths are from the Drupal root directory.'), '#after_build' => array('_getid3_admin_settings_check_path'), ); if ($version = getid3_get_version()) { @@ -22,14 +22,6 @@ function getid3_admin_settings_form() { '#markup' => '
' . check_plain($version) . '
', '#description' => t("If you're seeing this it indicates that the getID3 library was found."), ); - - // Check for existence of the 'demos' folder, contained in the getID3 - // library. The contents of this folder create a potential securtiy hole, - // so we recommend that the user delete it. - $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 beneath Drupal's directory.", array('%path' => realpath($getid3_demos_path))), 'error'); - } } $form['getid3_show_warnings'] = array( '#type' => 'checkbox', @@ -51,9 +43,9 @@ function getid3_admin_settings_form() { * The form element containing the name of the directory to check. */ 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 getid3.php and write.php could not be found in the %path directory.', array('%path' => $path))); + $library_path = $form_element['#value']; + if (!is_dir($library_path) || !(file_exists("$library_path/getid3/getid3.php") && file_exists("$library_path/getid3/write.php"))) { + form_set_error($form_element['#parents'][0], t('The getID3 files getid3.php and write.php could not be found in the %library_path directory.', array('%library_path' => $library_path))); } return $form_element; } diff --git a/getid3.install b/getid3.install index 2dfe735..e0d42e3 100644 --- a/getid3.install +++ b/getid3.install @@ -5,6 +5,11 @@ */ /** + * @file + * Install, update and uninstall functions for the getid3 module. + */ + +/** * Implements hook_requirements(). */ function getid3_requirements($phase) { @@ -12,14 +17,14 @@ function getid3_requirements($phase) { $requirements = array(); if ($phase == 'runtime') { - // Test getID3 version - $requirements['getid3']['title'] = $t('getID3()'); + $library_path = getid3_get_path(); + $requirements['getid3']['title'] = $t('getID3 library'); - if (getid3_load(FALSE)) { + if (getid3_load()) { $requirements['getid3']['value'] = check_plain(getid3_get_version()); // Check if demos directory exists. - $getid3_demos_path = getid3_get_path() . '/../demos'; + $getid3_demos_path = "$library_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 beneath Drupal's directory.", array('%path' => realpath($getid3_demos_path))); $requirements['getid3']['severity'] = REQUIREMENT_ERROR; @@ -28,7 +33,7 @@ function getid3_requirements($phase) { // getID3 library not found or wrong version. else { $requirements['getid3']['value'] = $t('Not found or wrong version'); - $requirements['getid3']['description'] = $t('You must install getID3() to %getid3dir, or configure its installation path.', array('@getid3' => 'http://www.getid3.org', '%getid3dir' => 'sites/all/libraries/getid3', '@getid3settings' => url('admin/config/media/getid3'))); + $requirements['getid3']['description'] = $t('The getID3 files getid3.php and write.php could not be found in the %library_path directory.', array('%library_path' => $library_path)); $requirements['getid3']['severity'] = REQUIREMENT_ERROR; } } diff --git a/getid3.module b/getid3.module index 5fde7d6..67cadbc 100644 --- a/getid3.module +++ b/getid3.module @@ -1,6 +1,7 @@ settings.", array('!admin-settings-audio-getid3' => url('admin/config/media/getid3'))), 'error', FALSE); + drupal_set_message(t('The getID3 files getid3.php and write.php could not be found in the %library_path directory.', array('%library_path' => $library_path)), 'error', FALSE); return FALSE; } } @@ -95,12 +96,44 @@ function getid3_analyze($filepath) { * Returns the path where getID3() is installed. */ function getid3_get_path() { - return variable_get('getid3_path', 'sites/all/libraries/getid3/getid3'); + static $library_path = NULL; + + // HACK: If libraries api module is not installed but available, load it. + if (!function_exists('libraries_get_path') && file_exists(dirname(__FILE__) . '/../libraries/libraries.module')) { + require_once(dirname(__FILE__) . '/../libraries/libraries.module'); + } + + // Try to locate the library path in any possible setup. + if ($library_path == NULL) { + $variable_get_path = variable_get('getid3_path', GETID3_PATH); + if (!$library_path && file_exists("$variable_get_path/getid3/getid3.php") && file_exists("$variable_get_path/getid3/write.php")) { + $library_path = $variable_get_path; + } + + $drupal_get_path = drupal_get_path('module', 'getid3'); + if (!$library_path && file_exists("$drupal_get_path/getid3/getid3.php") && file_exists("$drupal_get_path/getid3/write.php")) { + $library_path = $drupal_get_path; + } + + if (function_exists('libraries_get_path')) { + $libraries_get_path = libraries_get_path('getid3'); + if (!$library_path && file_exists("$libraries_get_path/getid3/getid3.php") && file_exists("$libraries_get_path/getid3/write.php")) { + $library_path = $libraries_get_path; + } + } + } + + // Save the configuration if able to figure out target library path. + if ($library_path !== NULL) { + variable_set('getid3_path', $library_path); + } + + return variable_get('getid3_path', GETID3_PATH); } /** * Returns the version number of getID3() that is installed. */ function getid3_get_version() { - return getid3_load(FALSE) ? GETID3_VERSION : NULL; + return getid3_load() ? GETID3_VERSION : NULL; } -- 1.7.2.5