Index: getid3.admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/getid3/getid3.admin.inc,v retrieving revision 1.1 diff -u -p -r1.1 getid3.admin.inc --- getid3.admin.inc 25 Jul 2010 03:31:55 -0000 1.1 +++ getid3.admin.inc 12 Jan 2011 17:51:48 -0000 @@ -14,7 +14,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()) { @@ -24,14 +24,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', @@ -43,18 +35,17 @@ function getid3_admin_settings_form() { } /** - * Checks the that the directory in $form_element exists and contains a file - * named 'getid3.php'. If validation fails, the form element is flagged with an - * error from within the file_check_directory function. See: - * system_check_directory() + * Checks the directory in $form_element exists and contains a file named + * 'getid3.php'. If validation fails, the form element is flagged + * with an error from within the file_check_directory function. * * @param $form_element * 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; -} \ No newline at end of file +} Index: getid3.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/getid3/getid3.install,v retrieving revision 1.9 diff -u -p -r1.9 getid3.install --- getid3.install 11 Dec 2010 19:47:37 -0000 1.9 +++ getid3.install 12 Jan 2011 17:51:48 -0000 @@ -2,6 +2,11 @@ // $Id: getid3.install,v 1.9 2010/12/11 19:47:37 drewish Exp $ /** + * @file + * Install, update and uninstall functions for the getid3 module. + */ + +/** * Implements hook_requirements(). */ function getid3_requirements($phase) { @@ -9,20 +14,23 @@ 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()); - $getid3_demos_path = getid3_get_path() . '/../demos'; + + // Check if demos directory exists. + $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; } } + // 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; } } @@ -48,7 +56,7 @@ function getid3_install() { // If there is one FALSE value in the status array, there was an error. if (array_search(FALSE, $status) !== FALSE) { - drupal_set_message(t('Setting the module weight of getID3 failed.'), 'error'); + drupal_set_message(st('Setting the module weight of getID3 failed.'), 'error'); } } Index: getid3.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/getid3/getid3.module,v retrieving revision 1.17 diff -u -p -r1.17 getid3.module --- getid3.module 11 Dec 2010 19:47:37 -0000 1.17 +++ getid3.module 12 Jan 2011 17:51:48 -0000 @@ -2,6 +2,7 @@ // $Id: getid3.module,v 1.17 2010/12/11 19:47:37 drewish Exp $ define('GETID3_RECOMMEND_VERSION', '1.8.2'); +define('GETID3_PATH', 'sites/all/libraries/getid3'); /** * Implements hook_help(). @@ -34,28 +35,28 @@ function getid3_menu() { * Loads the getID3 library once and returns whether it was successfully loaded. * * @return - * Boolean indicating if the library was loaded + * Boolean indicating if the library was loaded. */ -function getid3_load($display_warning = TRUE) { - $getid3_path = getid3_get_path(); +function getid3_load() { + $library_path = getid3_get_path(); - if (file_exists($getid3_path . '/getid3.php') && file_exists($getid3_path . '/write.php')) { + if (file_exists("$library_path/getid3/getid3.php") && file_exists("$library_path/getid3/write.php")) { // A little workaround for getID3 on Windows. if (!defined('GETID3_HELPERAPPSDIR')) { - define('GETID3_HELPERAPPSDIR', realpath($getid3_path . '/../helperapps') . '/'); + define('GETID3_HELPERAPPSDIR', realpath("$library_path/helperapps") . '/'); } - include_once($getid3_path . '/getid3.php'); + include_once("$library_path/getid3/getid3.php"); // Initialize getID3 tag-writing module. NOTE: Their wanky dependency setup // requires that this file must be included AFTER an instance of the getID3 // class has been instantiated. $getid3 = new getID3; - require_once($getid3_path . '/write.php'); + require_once("$library_path/getid3/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 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; } } @@ -96,12 +97,44 @@ function getid3_analyze($path) { * 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's installed. */ function getid3_get_version() { - return getid3_load(FALSE) ? GETID3_VERSION : NULL; + return getid3_load() ? GETID3_VERSION : NULL; }