5 Jappix - An open social platform
6 This is the Jappix music search script
8 -------------------------------------------------
12 Last revision: 15/01/12
17 define('JAPPIX_BASE', '..');
19 // Get the needed files
20 require_once('./functions.php');
21 require_once('./read-main.php');
22 require_once('./read-hosts.php');
24 // Optimize the page rendering
28 // Not allowed for a special node
29 if(isStatic() || isUpload())
32 // If valid data was sent
33 if((isset($_GET['searchquery']) && !empty($_GET['searchquery'])) && (isset($_GET['location']) && !empty($_GET['location']))) {
35 header('Content-Type: text/xml; charset=utf-8');
38 $searchquery = $_GET['searchquery'];
39 $location = $_GET['location'];
42 if($location == 'jamendo')
43 exit(read_url('http://api.jamendo.com/get2/name+id+duration+url/track/xml/?searchquery='.urlencode($searchquery).'&order=searchweight_desc'));
47 $searchquery = strtolower($searchquery);
49 // Escape the regex special characters
50 $searchquery = escapeRegex($searchquery);
52 // Search in the directory
53 $repertory = '../store/music/';
54 $scan = scandir($repertory);
56 foreach($scan as $current) {
57 // This file match our query!
58 if(is_file($repertory.$current) && $current && preg_match('/(^|\s|\[)('.$searchquery.')(.+)?(\.(og(g|a)|mp3|wav))$/i', strtolower($current))) {
59 // Get the basic informations
60 $title = preg_replace('/^(.+)(\.)(og(g|a)|mp3|wav)$/i', '$1', $current);
61 $url = $location.'store/music/'.$current;
62 $ext = getFileExt($current);
68 else if($ext == 'wav')
69 $type = 'audio/x-wav';
73 // Get the advanced informations
74 $locked_title = $title;
78 $title_regex = '/^(([^-]+) - )?([^\[]+)( \[(.+))?$/i';
79 $artist_regex = '/^(.+) - (.+)$/i';
80 $source_regex = '/^(.+) \[(.+)\]$/i';
82 if(preg_match($title_regex, $locked_title))
83 $title = preg_replace($title_regex, '$3', $locked_title);
85 if(preg_match($artist_regex, $locked_title))
86 $artist = preg_replace($artist_regex, '$1', $locked_title);
88 if(preg_match($source_regex, $locked_title))
89 $source = preg_replace($source_regex, '$2', $locked_title);
92 $xml .= '<data><track><name>'.htmlspecialchars($title).'</name><artist>'.htmlspecialchars($artist).'</artist><source>'.htmlspecialchars($source).'</source><id>'.htmlspecialchars($id).'</id><url>'.htmlspecialchars($url).'</url><type>'.$type.'</type></track></data>';
99 // Return the path to the file