summaryrefslogtreecommitdiffstats
path: root/modules/php_musicbrainz/mbUtil.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules/php_musicbrainz/mbUtil.php')
-rw-r--r--modules/php_musicbrainz/mbUtil.php62
1 files changed, 62 insertions, 0 deletions
diff --git a/modules/php_musicbrainz/mbUtil.php b/modules/php_musicbrainz/mbUtil.php
new file mode 100644
index 00000000..87517556
--- /dev/null
+++ b/modules/php_musicbrainz/mbUtil.php
@@ -0,0 +1,62 @@
+<?php
+ class mbValueError extends Exception {}
+
+ function extractFragment( $type ) {
+ if ( ( $p = parse_url( $type ) ) == false ) {
+ return $type;
+ }
+ return $p['fragment'];
+ }
+
+ function extractUuid( $uid ) {
+ if ( empty($uid) )
+ return $uid;
+
+ $types = array( "artist/", "release/", "track/" );
+ for ( $i = 0; $i < 3; $i++ ) {
+ if ( ($pos = strpos( $uid, $types[$i] )) !== false ) {
+ $pos += strlen($types[$i]);
+ if ( $pos + 36 == strlen($uid) ) {
+ return substr( $uid, $pos, 36 );
+ }
+ }
+ }
+
+ if ( strlen($uid) == 36 )
+ return $uid;
+
+ throw new mbValueError( "$uid is not a valid MusicBrainz ID.", 1 );
+ }
+
+ require_once( 'mbUtil_countrynames.php' );
+ function getCountryName( $id ) {
+ if ( isset( $mbCountryNames[$id] ) )
+ return $mbCountryNames[$id];
+
+ return "";
+ }
+
+ require_once( 'mbUtil_languagenames.php' );
+ function getLanguageName( $id ) {
+ if ( isset( $mbLanguageNames[$id] ) )
+ return $mbLanguageNames[$id];
+
+ return "";
+ }
+
+ require_once( 'mbUtil_scriptnames.php' );
+ function getScriptName( $id ) {
+ if ( isset( $mbScriptNames[$id] ) )
+ return $mbScriptNames[$id];
+
+ return "";
+ }
+
+ require_once( 'mbUtil_releasetypenames.php' );
+ function getReleaseTypeName( $id ) {
+ if ( isset( $mbReleaseTypeNames[$id] ) )
+ return $mbReleaseTypeNames[$id];
+
+ return "";
+ }
+?>