Skip to content
Snippets Groups Projects
Commit ecb98b63 authored by Ion Eftodii's avatar Ion Eftodii Committed by Viktor Holovachek
Browse files

Resolve #3147653 "Automated drupal 9"

parent a9ff9022
No related branches found
No related tags found
1 merge request!1Resolve #3147653 "Automated drupal 9"
INSTALL
-------
1. Place the entire getid3 directory into your modules directory
(modules is the usual location).
2. Create a new folder for the getID3 library at:
cd YOUR-DRUPAL-ROOT
mkdir -p libraries/getid3
3. Go to http://www.getid3.org/ and download the latest stable version
(currently 1.9.9) into the new directory:
cd libraries/getid3
wget "http://downloads.sourceforge.net/project/getid3/getID3%28%29%201.x/1.9.9/getID3-1.9.9-20141218.zip"
4. Unzip the contents of the zip file into libraries/getid3/ so that
write.php is located in libraries/getid3/getid3/:
unzip getID3-1.9.9-20141218.zip
5. Delete the demos directory:
rm -r demos/
6. Go to Dashboard > Modules and enable the GetID3 module.
7. Go to Dashboard > Configuration > Media > getID3. If you see the version you
just downloaded, the module is installed correctly.
# getID3()
CONTENTS OF THIS FILE
---------------------
The getID3() Drupal module facilitates the installation and management of the
getID3() PHP library, used to extractuseful information from MP3s and other
multimedia file formats.
* About getID3()
* About getID3() Drupal Module
* Installation
getID3() is a PHP script that extracts useful information (such as ID3 tags,
bitrate, playtime, etc.) from MP3s & other multimedia file formats (Ogg, WMA,
WMV, ASF, WAV, AVI, AAC, VQF, FLAC, MusePack, Real,QuickTime, Monkey's Audio,
MIDI and more).
ABOUT getID3()
--------------
This API module is used by other modules to ensure that getID3() is correctly
installed. Developers who need the getID3() functionality can make this a
dependency by their module, and then call the getid3_load() function to properly
use the getID3() library without having to worry about whether it's installed
or not.
getID3() is a PHP script that extracts useful information
(such as ID3 tags, bitrate, playtime, etc.) from MP3s & other multimedia file
formats (Ogg, WMA, WMV, ASF, WAV, AVI, AAC, VQF, FLAC, MusePack, Real,
QuickTime, Monkey's Audio, MIDI and more).
## Installation
ABOUT getID3() Drupal Module
----------------------------
Install the Real name module as you would normally install a contributed
Drupal module. Visit https://www.drupal.org/node/1897420 for further
information.
The getID3() Drupal module facilitates the installation and management of the
getID3() PHP library, used to extract useful information from MP3s and other
multimedia file formats.
## Composer
This API module is used by other modules to ensure that getID3() is correctly
installed. Developers who need the getID3() functionality can make this a
dependency by their module, and then call the getid3_load() function to
properly use the getID3() library without having to worry about whether
it's installed or not.
If your site is [managed via Composer](https://www.drupal.org/node/2718229), use
Composer to download the module, which will also download the required library:
```sh
composer require "drupal/getid3"
```
^1.0 downloads the latest release, use 1.x-dev to get the -dev release instead.
Use ```composer update drupal/getid3 --with-dependencies``` to update to a new
release.
1. Run "composer require --prefer-dist composer/installers" to ensure that you
have the "composer/installers" package installed. This package facilitates
the installation of packages into directories other than "/vendor" (e.g.
"/libraries") using Composer.
2. Add the following to the "installer-paths" section of "composer.json":
"libraries/{$name}": ["type:drupal-library"],
3. Add the following to the "repositories" section of "composer.json":
{
"type": "package",
"package": {
"name": "james-heinrich/getid3",
"version": "1.9.21",
"type": "drupal-library",
"dist": {
"url": "https://github.com/JamesHeinrich/getID3/archive/refs/tags/v1.9.21.zip",
"type": "zip"
}
}
}
4. Run "composer require --prefer-dist james-heinrich/getid3:1.9.21"
- you should find that new directories have been created under "/libraries"
INSTALLATION
------------
## Configuration
Please read the INSTALL.txt file present in the module folder and follow the
instructions to install the module.
1. Go to Dashboard > Modules and enable the GetID3 module.
2. Go to Dashboard > Configuration > Media > getID3. If you see the version you
just downloaded, the module is installed correctly.
path: 'sites/all/libraries/getid3/getid3'
path: 'libraries/getid3/getid3'
<?php
/**
* @file
* Drush integration for getID3.
*/
/**
* Implements hook_drush_command().
*/
function getid3_drush_command() {
$items['getid3-download'] = [
'callback' => 'drush_getid3_download',
'description' => dt('Downloads the required getID3 library from SourceForge.net.'),
'arguments' => [
'path' => dt('Optional. A path to the download folder. If omitted Drush will use the default location (sites/all/libraries/getid3).'),
],
];
return $items;
}
/**
* Implements drush_MODULE_pre_COMMAND().
*
* This automatically downloads the library when the module is being installed.
*/
function drush_getid3_pre_pm_enable() {
$modules = func_get_args();
if (in_array('getid3', $modules)) {
drush_getid3_download();
}
}
/**
* Download the getID3 library from SourceForge.
*/
function drush_getid3_download() {
$args = func_get_args();
if (!empty($args[0])) {
$library_path = $args[0];
}
else {
$library_path = drush_get_context('DRUSH_DRUPAL_ROOT') . '/sites/all/libraries/getid3';
}
// @todo It would be great if we could use recommended_version.
$version = GETID3_RECOMMENDED_VERSION;
$filename = 'getID3-1.9.9-20141218.zip';
$md5 = 'fc9a902d9ee09b281c4b35926bf00f0b';
$url = "http://downloads.sourceforge.net/project/getid3/getID3%28%29%201.x/{$version}/{$filename}";
// Create the directory.
if (!drush_shell_exec('mkdir -p %s', $library_path)) {
return drush_set_error('GETID3_MKDIR', dt('Drush was unable to create the getID3 directory at @path.', ['@path' => $library_path]));
}
$zipfile_path = $library_path . '/' . $filename;
drush_register_file_for_deletion($zipfile_path);
// Download the file.
if (!drush_shell_exec('wget -O %s %s', $zipfile_path, $url)) {
return drush_set_error('GETID3_FETCH', dt('Drush was unable to download the getID3 library to @path.', ['@path' => $zipfile_path]));
}
// Check MD5 hash.
if (md5_file($zipfile_path) != $md5) {
return drush_set_error('GETID3_MD5', dt('The downloaded file @path was corrupted. Expected MD5 checksum: @md5.', ['@path' => $zipfile_path, '@md5' => $md5]));
}
// Unzip it the file -- using the "update" option to avoid being prompted
// about overwriting files.
if (!drush_shell_exec('unzip -u %s -d %s', $zipfile_path, $library_path)) {
return drush_set_error('GETID3_UNZIP', dt('Drush was unable to unzip the archive @path.', ['@path' => $zipfile_path]));
}
// Delete the demos. They're a security risk.
$demos_path = $library_path . '/demos';
if (!drush_shell_exec('rm -r %s', $demos_path)) {
return drush_set_error('GETID3_RM', dt("Drush was unable to remove getID3's demos directory. You should do so manually.", ['@path' => $demos_path]));
}
drush_log(dt('getID3 has been installed to @path.', ['@path' => $library_path]), 'success');
}
......@@ -5,7 +5,7 @@
* Install, update and uninstall functions for the getid3 module.
*/
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\Html;
use Drupal\Core\Url;
/**
......@@ -19,7 +19,7 @@ function getid3_requirements($phase) {
$requirements['getid3']['title'] = t('getID3()');
if (getid3_load(FALSE)) {
$requirements['getid3']['value'] = SafeMarkup::checkPlain(getid3_get_version());
$requirements['getid3']['value'] = Html::escape(getid3_get_version());
// Check if demos directory exists.
$getid3_demos_path = getid3_get_path() . '/../demos';
......@@ -31,7 +31,9 @@ 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 <a href="@getid3">getID3()</a> to %getid3dir, or <a href="@getid3settings">configure its installation path</a>.', ['@getid3' => 'http://www.getid3.org', '%getid3dir' => 'sites/all/libraries/getid3', '@getid3settings' => Url::fromRoute('getid3.config')]);
$requirements['getid3']['description'] = t('You must install <a href="http://www.getid3.org">getID3()</a> to <em>libraries/getid3</em>, or <a href="@getid3settings">configure its installation path</a>.', [
'@getid3settings' => Url::fromRoute('getid3.config')->toString(),
]);
$requirements['getid3']['severity'] = REQUIREMENT_ERROR;
}
}
......@@ -47,7 +49,8 @@ function getid3_install() {
$status = getid3_load();
if ($status == FALSE) {
$path = getid3_get_path();
drupal_set_message(t('The getID3 files <em>getid3.php</em> and <em>write.php</em> could not be found in the %path directory.', ['%path' => $path]), 'error');
\Drupal::messenger()
->addError(t('The getID3 files <em>getid3.php</em> and <em>write.php</em> could not be found in the %path directory.', ['%path' => $path]));
}
// Set module weight for the getID3 module.
module_set_weight('getid3', '-10');
......
......@@ -2,11 +2,12 @@
/**
* @file
* GetID3 module functions.
*/
use Drupal\Core\Url;
define('GETID3_RECOMMENDED_VERSION', '1.9.9');
define('GETID3_RECOMMENDED_VERSION', '1.9.21');
/**
* Implements hook_help().
......@@ -14,19 +15,27 @@ define('GETID3_RECOMMENDED_VERSION', '1.9.9');
function getid3_help($route_name) {
switch ($route_name) {
case 'help.page.getid3':
// Case 'admin/help#getid3':
return '<p>' . t("To use this module you'll need to <a href='!download-link'>download the library</a> from the <a href='!info-link'>getID3 website</a> and extract the contents into the module's getid3 directory. Currently, the recommended version of the getID3 library is %recommended-version.",
['!download-link' => Url::fromUri('http://prdownloads.sourceforge.net/getid3'), '!info-link' => Url::fromUri('http://getid3.org/'), '%recommended-version' => GETID3_RECOMMENDED_VERSION]) . '</p>';
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t("To use this module you'll need to <a href='@download-link'>download the library</a> from the <a href='@info-link'>getID3 website</a> and extract the contents into the module's getid3 directory. Currently, the recommended version of the getID3 library is %recommended-version.",
[
'@download-link' => Url::fromUri('http://prdownloads.sourceforge.net/getid3')->toString(),
'@info-link' => Url::fromUri('https://www.getid3.org/')->toString(),
'%recommended-version' => GETID3_RECOMMENDED_VERSION,
]) . '</p>';
return $output;
}
}
/**
* Load the getID3 library.
*
* @return
* @param bool $display_warning
* Whether or not the warning message should be displayed.
*
* @return bool
* Boolean indicating if the library was successfully loaded.
*/
function getid3_load($display_warning = TRUE) {
function getid3_load(bool $display_warning = TRUE): bool {
$getid3_path = getid3_get_path();
if (file_exists($getid3_path . '/getid3.php') && file_exists($getid3_path . '/write.php')) {
// A little workaround for getID3 on Windows.
......@@ -50,12 +59,15 @@ function getid3_load($display_warning = TRUE) {
/**
* Create and initialize an instance of getID3 class.
*/
function getid3_instance() {
$id3 = NULL;
function getid3_instance(): ?getID3 {
$id3_lib_available = getid3_load();
if ($id3_lib_available == FALSE) {
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>.", ['!admin-settings-audio-getid3' => Url::fromRoute('getid3.config')]), 'error', FALSE);
return $id3;
$params = [
'!admin-settings-audio-getid3' => Url::fromRoute('getid3.config'),
];
\Drupal::messenger()
->addError(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>.", $params));
return NULL;
}
$id3 = new getID3();
......@@ -69,13 +81,13 @@ function getid3_instance() {
/**
* Analyze file and return its media information.
*
* @param $filepath
* @param string $filepath
* A string specifying a file path.
*
* @return
* @return array
* An array with the information returned by getID3.
*/
function getid3_analyze($filepath) {
function getid3_analyze(string $filepath): array {
$info = [];
if ($id3 = getid3_instance()) {
$info = $id3->analyze($filepath);
......@@ -94,15 +106,13 @@ function getid3_get_path() {
$path = 'libraries/getid3/getid3';
$config->set('path', $path)->save();
}
return $path;
}
/**
* Returns the version number of getID3() that is installed.
*/
function getid3_get_version() {
function getid3_get_version(): ?string {
if (getid3_load() == FALSE) {
return NULL;
}
......
......@@ -2,12 +2,14 @@
namespace Drupal\getid3\Form;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\Html;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Form builder for the GetId3 settings form.
*
* @internal
*/
class GetId3ConfigForm extends ConfigFormBase {
......@@ -45,16 +47,17 @@ class GetId3ConfigForm extends ConfigFormBase {
$form['getid3_version'] = [
'#type' => 'item',
'#title' => $this->t('Version'),
'#markup' => '<pre>' . SafeMarkup::checkPlain($version) . '</pre>',
'#markup' => '<pre>' . Html::escape($version) . '</pre>',
'#description' => $this->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,
// library. The contents of this folder create a potential security hole,
// so we recommend that the user delete it.
$getid3_demos_path = $path . '/../demos';
if (file_exists($getid3_demos_path)) {
drupal_set_message($this->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.", ['%path' => realpath($getid3_demos_path)]), 'error');
$this->messenger()
->addError($this->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.", ['%path' => realpath($getid3_demos_path)]));
}
}
$show_warnings = $this->config('getid3.settings')->get('getid3_show_warnings');
......@@ -71,13 +74,6 @@ class GetId3ConfigForm extends ConfigFormBase {
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
......@@ -99,15 +95,17 @@ class GetId3ConfigForm extends ConfigFormBase {
*
* @param array $form_element
* The form element containing the name of the directory to check.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return array
* Returns form element.
*/
public static function afterBuild(array $form_element, FormStateInterface $form_state) {
$path = $form_state->getValue('getid3_path');
if (!is_dir($path) || !(file_exists($path . '/getid3.php') && file_exists($path . '/write.php'))) {
drupal_set_message(t('The getID3 files <em>getid3.php</em> and <em>write.php</em> could not be found in the %path directory.', ['%path' => $path]), 'error');
\Drupal::messenger()
->addError(t('The getID3 files <em>getid3.php</em> and <em>write.php</em> could not be found in the %path directory.', ['%path' => $path]));
}
return $form_element;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment