function AnalyzeDirectory() { global $audio_path, $dbh; // Scan $audio_path try { // Build array containing filenames $files = array(); ScanDirectory($audio_path, $files); // Initialize getID3 engine $getid3 = new getID3(); $getid3->encoding = 'UTF-8'; $getid3->option_md5_data = true; $getid3->option_md5_data_source = true; // Scan all files foreach ($files as $filename => $name) { try { $getid3->Analyze($filename); if (!@$getid3->info['audio']) { xml_gen::p($name . ' skipped - not an audio file.'); continue; } // Extract data $filemtime = filemtime($filename); $filesize = filesize($filename); $filename_sls = addslashes(utf8_encode($filename)); $format_name = @$getid3->info['fileformat'] . (@$getid3->info['audio']['dataformat'] != @$getid3->info['fileformat'] ? '/' . @$getid3->info['audio']['dataformat'] : ''); $format_name_id = Lookup($format_name, 'format_name'); $encoder_version_id = Lookup(@$getid3->info['audio']['encoder'], 'encoder_version'); $encoder_options_id = Lookup(@$getid3->info['audio']['encoder_options'], 'encoder_options'); $bitrate_mode_id = Lookup(@$getid3->info['audio']['bitrate_mode'], 'bitrate_mode'); $channel_mode_id = Lookup(@$getid3->info['audio']['channelmode'], 'channel_mode'); $sample_rate = (int) @$getid3->info['audio']['sample_rate']; $bits_per_sample = (int) @$getid3->info['audio']['bits_per_sample']; $lossless = (int) @$getid3->info['audio']['lossless']; $playtime = (double) @$getid3->info['playtime_seconds']; $avg_bit_rate = (double) @$getid3->info['bitrate']; $rg_track_gain = (double) @$getid3->info['replay_gain']['track']['adjustment']; $rg_album_gain = (double) @$getid3->info['replay_gain']['album']['adjustment']; $md5data = addslashes(@$getid3->info['md5_data_source'] ? @$getid3->info['md5_data_source'] : @$getid3->info['md5_data']); // Insert file entry $dbh->query("insert into getid3_file (filename, filemtime, filesize, format_name_id, encoder_version_id, encoder_options_id, bitrate_mode_id, channel_mode_id, sample_rate, bits_per_sample, lossless, playtime, avg_bit_rate, md5data, replaygain_track_gain, replaygain_album_gain) values ('{$filename_sls}', {$filemtime}, {$filesize}, {$format_name_id}, {$encoder_version_id}, {$encoder_options_id}, {$bitrate_mode_id}, {$channel_mode_id}, {$sample_rate}, {$bits_per_sample}, {$lossless}, {$playtime}, {$avg_bit_rate}, '{$md5data}', {$rg_track_gain}, {$rg_album_gain})"); $file_id = $dbh->insert_id(); // Loop thru tags if (@$getid3->info['tags']) { foreach ($getid3->info['tags'] as $tag_name => $tag_data) { // Loop thru fields foreach ($tag_data as $field_name => $values) { // Loop thru values foreach ($values as $value) { $tag_id = Lookup($tag_name, 'tag'); $field_id = Lookup($field_name, 'field'); $value_id = Lookup($value, 'value'); // Insert comments entry $dbh->query("insert into getid3_comment (file_id, tag_id, field_id, value_id) values ({$file_id}, {$tag_id}, {$field_id}, {$value_id})"); } } } } echo xml_gen::p('#' . $file_id . ' - ' . utf8_encode($filename) . ' OK.'); flush(); } catch (Exception $e) { echo xml_gen::p_err($name . ' skipped - getID3() threw the exception: ' . $e->getmessage()); } } } catch (Exception $e) { echo xml_gen::p_err('An error occured: ' . $e->getmessage()); } }
function DoColumnDetails($column) { global $result; global $MaxGroupValueReached; global $result_schema; global $record; global $array_of_things_to_save; global $schema_to_use; global $work_type; global $group1; $RunAgain = 0; // when building groups this times the app to look for another entry $schema_array = $result_schema[$schema_to_use][$column]; /* // we test for the presence of GROUPS // and if so add them to the array so they are picked up if ($result[$work_type][$record]["groupA0_linktype"]) { array_push($schema_array,$result[$schema_to_use]["array_publishedat"]["linktype"]); } if ($result[$work_type][$record]["groupA0_link"]) { array_push($schema_array,$result[$schema_to_use]["array_publishedat"]["link"]); } */ foreach ($schema_array as $key => $value) { //echo $key . $value; $rowvalue = ""; $helpvalue = ""; // now we are in the subarray -- the elements within key="title" for example // // we store an array of keys like "title" that is later used when we send information to update_work.php. // //$array_of_things_to_save = array(); $override_value = ""; foreach ($value as $key_minor => $value_minor) { // LIMIT: Only allowed one GROUP So Far // $group1 is a variable (index starts at 0) that counts how many LINKS we've added. if ($key_minor == "isgroup") { if ($value_minor == "group1") { // Now we get complicated because we have more than one of these. $override_value_key = $value_minor . "_" . $group1 . "_" . $key; //echo $override_value_key; $override_value = $result[$work_type][$record][$override_value_key]; if (!$result[$work_type][$record][$override_value_key]) { // // A control did NOT exist // AND // there has been no valid entries at this Nth item (where n = $group1) if ($group1 > $MaxGroupValueReached) { // at the point when we hit a dead entry we just BAIL entirely. // The group has ended and columns are only suppose to have one group in them. // THere we are done ELSE infinite loop // 14/09/2014 // This ended up working BUT because previous data // did not have the NEW FIELD, it added it to the end of the entire set // and consequently I could not use it // 13/09/2014 // Just verified that we DO still need this. // We are effectively building a list "group1[0] ... group1[infinity]... we use // the "does it exist" test to prevent us from growing exponentially. // THE PROBLEM // The problem with this is when I went to add a new field ... each link requiring an ISBN // I cannot go back and fix the old entries, which means as soon as it tries to find // an ISBN and can't... it does not render the rest of the elements. // POSSIBLE SOLUTION // We test to see if an element of N was found and if so // we skip the Existence Test. // That is if a linktype exists for N=9 then we know there is a 9th ROW, even if // the NewField does not exist in it. // IMPLEMENTATION: Just keep track of the Highest N we encounter. If this elements is // on the Nth Row[if we have this info] then it gets a pass, even if it does not exist //echo "Reached Last In Series with max group = ".$group1. " and max group = ".$MaxGroupValueReached; return; } } else { // we track what record # we "found". // if we find a control in a set (i.e., set N=1) then // even if another label (a new field added after the original dataset created) is added // we still display it. $MaxGroupValueReached = $group1; } //echo "Max Group Reached = ".$group1; // now try to "iterate" through all of them and write them all now. //echo "-->".$override_value; $key = $override_value_key; // we set this so that the control is named this. If the control is named this then things should save! } else { if ($value_minor == "groupend") { // test to see if the next value exists? $group1++; //echo "here2"; // we have to just run again and look and hope error handling handles errors? $RunAgain = 1; // try to write an ID echo "<h3><hr></hr></h3>"; } } /* MY LOGIC -- somehow I want to run through the entire... COLUMN? again -- would that work? If I made a RULE that only one thing can be in a column? */ } if ($key_minor == "type") { $rowvalue = DrawInputObject($rowvalue, $value_minor, $key, $override_value); } else { if ($key_minor == "help") { $helpvalue = $value_minor; } } } // foreach 1 // I moved the push array to the end so that if the key is modified (as it is for groups) the change is reflecte if ($key != "group1end") { array_push($array_of_things_to_save, $key); echo '<div class="panel panel-default"><div class="panel panel-success"><div class="panel-heading">'; echo '<h3>'; $label = Lookup($key); echo '<span class="label label-primary">' . $label . '</span>'; echo '</h3>'; if ($helpvalue != "") { echo '<h4><span class="label label-warning">' . $helpvalue . '</span></h4>'; } echo ' </div></div> <div id="panelz" class="panel-body">'; echo $rowvalue; echo '</div></div>'; } } //foreach2 if ($RunAgain == 1) { DoColumnDetails($column); } }