/[drupal]/contributions/modules/getid3/getid3.module
ViewVC logotype

Contents of /contributions/modules/getid3/getid3.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.12 - (show annotations) (download) (as text)
Wed Oct 15 18:55:19 2008 UTC (13 months, 1 week ago) by drewish
Branch: MAIN
Changes since 1.11: +11 -11 lines
File MIME type: text/x-php
Following the new D7 concatenation coding standard.
1 <?php
2 // $Id: getid3.module,v 1.11 2008/10/15 18:12:06 drewish Exp $
3
4 define('GETID3_RECOMMEND_VERSION', '1.7.8b3');
5
6 /**
7 * Implementation of hook_help
8 */
9 function getid3_help($section, $arg) {
10 switch ($section) {
11 case 'admin/settings/getid3':
12 $help = '<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.",
13 array('!download-link' => url('http://prdownloads.sourceforge.net/getid3'), '!info-link' => url('http://getid3.org/'), '%recommended-version' => GETID3_RECOMMEND_VERSION)) . '</p>';
14 return $help;
15 }
16 }
17
18 /**
19 * Loads the getID3 library once and returns whether it was successfully loaded.
20 *
21 * @return
22 * Boolean indicating if the library was loaded
23 */
24 function getid3_load($display_warning = TRUE) {
25 $getid3_path = getid3_get_path();
26
27 if (file_exists($getid3_path . '/getid3.php') && file_exists($getid3_path . '/write.php')) {
28 // A little workaround for getID3 on Windows.
29 if (!defined('GETID3_HELPERAPPSDIR')) {
30 define('GETID3_HELPERAPPSDIR', realpath($getid3_path . '/../helperapps') . '/');
31 }
32 include_once($getid3_path . '/getid3.php');
33
34 // Initialize getID3 tag-writing module. NOTE: Their wanky dependency setup
35 // requires that this file must be included AFTER an instance of the getID3
36 // class has been instantiated.
37 $getid3 = new getID3;
38 require_once($getid3_path . '/write.php');
39
40 return defined('GETID3_VERSION');
41 }
42 else {
43 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);
44 return FALSE;
45 }
46 }
47
48 /**
49 * Create and initialize an instance of getID3 class.
50 */
51 function getid3_instance() {
52 $id3 = NULL;
53 if (getid3_load()) {
54 $id3 = new getID3();
55 // MD5 is a big performance hit. Disable it by default.
56 $id3->option_md5_data = FALSE;
57 $id3->option_md5_data_source = FALSE;
58 $id3->encoding = 'UTF-8';
59 }
60 return $id3;
61 }
62
63 /**
64 * Analyze file and return its media information.
65 *
66 * @param $path
67 * A string specifying a file path.
68 * @return
69 * An array with the information returned by getID3.
70 */
71 function getid3_analyze($path) {
72 $info = array();
73 if($id3 = getid3_instance()) {
74 $info = $id3->analyze($path);
75 unset($id3);
76 }
77 return $info;
78 }
79
80 /**
81 * Implementation of hook_menu()
82 */
83 function getid3_menu() {
84 $items['admin/settings/getid3'] = array(
85 'title' => 'getID3()',
86 'description' => 'Configure settings associated with getID3().',
87 'page callback' => 'drupal_get_form',
88 'page arguments' => array('getid3_admin_settings_form', NULL),
89 'access arguments' => array('administer site configuration'),
90 );
91 return $items;
92 }
93
94 /**
95 * Administration settings for getID3().
96 */
97 function getid3_admin_settings_form() {
98 $form['getid3_path'] = array(
99 '#type' => 'textfield',
100 '#title' => t('Path'),
101 '#default_value' => getid3_get_path(),
102 '#description' => t('The location where getID3() is installed. Relative paths are from the Drupal root directory.'),
103 '#after_build' => array('_getid3_admin_settings_check_path'),
104 );
105 if ($version = getid3_get_version(FALSE)) {
106 $form['getid3_version'] = array(
107 '#type' => 'item',
108 '#title' => t('Version'),
109 '#markup' => '<pre>' . check_plain($version) . '</pre>',
110 '#description' => t("If you're seeing this it indicates that the getID3 library was found."),
111 );
112
113 // Check for existence of the 'demos' folder, contained in the getID3
114 // library. The contents of this folder create a potential securtiy hole,
115 // so we recommend that the user delete it.
116 $getid3_demos_path = getid3_get_path() . '/../demos';
117 if (file_exists($getid3_demos_path)) {
118 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');
119 }
120 }
121 $form['getid3_show_warnings'] = array(
122 '#type' => 'checkbox',
123 '#title' => t("Display Warnings"),
124 '#default_value' => variable_get('getid3_show_warnings', FALSE),
125 '#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."),
126 );
127 return system_settings_form($form);
128 }
129
130 /**
131 * Checks the that the directory in $form_element exists and contains a file
132 * named 'getid3.php'. If validation fails, the form element is flagged with an
133 * error from within the file_check_directory function. See:
134 * system_check_directory()
135 *
136 * @param $form_element
137 * The form element containing the name of the directory to check.
138 */
139 function _getid3_admin_settings_check_path($form_element) {
140 $path = $form_element['#value'];
141 if (!is_dir($path) || !(file_exists($path . '/getid3.php') && file_exists($path . '/write.php'))) {
142 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)));
143 }
144 return $form_element;
145 }
146
147 /**
148 * Returns the path where getID3() is installed.
149 */
150 function getid3_get_path() {
151 return variable_get('getid3_path', drupal_get_path('module', 'getid3') . '/getid3/getid3');
152 }
153
154 /**
155 * Returns the version number of getID3() that's installed.
156 */
157 function getid3_get_version() {
158 return getid3_load(FALSE) ? GETID3_VERSION : NULL;
159 }

  ViewVC Help
Powered by ViewVC 1.1.2