injectors.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. // iniettori metadati - cesco@ventuordici.org - arav2010
  3. //punto di iniezione
  4. function store_md_array($data, $obj_rel_path){
  5. $obj_abs_path = $GLOBALS["conf"]["data_basedir"].$obj_rel_path;
  6. if(is_file($obj_abs_path)){
  7. // incapsulamenti matchati a seconda delle estensioni...
  8. if(preg_match("/\.oga$|\.ogv$|\.ogg$/i",$obj_abs_path)){
  9. store_ogg_md($data,$obj_abs_path);
  10. }
  11. elseif(preg_match("/\.webm$|\.mkv$/i",$obj_abs_path)){
  12. // quando webm di merda supportera' i metadati
  13. }
  14. else{
  15. report(2,"$obj_abs_path file has illegal extension.");
  16. }
  17. }
  18. elseif(is_dir($obj_abs_path)){
  19. // metadati dir
  20. store_dir_md($data,$obj_abs_path);
  21. }
  22. else{
  23. report(2,"what is $obj_abs_path ?");
  24. // oppss
  25. }
  26. }
  27. // scrivi metadata sugli ogg
  28. function store_ogg_md($data,$obj_abs_path) {
  29. if(file_exists($obj_abs_path) AND is_file($obj_abs_path)){
  30. $wristri = "";
  31. foreach ($data as $key => $value) {
  32. if ($value == "") continue;
  33. $wristri .= " -t ".escapeshellarg($key."=".$value);
  34. }
  35. $writcom = escapeshellcmd($GLOBALS["conf"]["executables"]["vorbiscomment"])." -wR ".escapeshellarg($obj_abs_path)." $wristri";
  36. report(1, "AAAA ".$writcom);
  37. shell_exec($writcom);
  38. }
  39. }
  40. // scrivi metadata delle directory
  41. function store_dir_md($data,$obj_abs_path){
  42. if(file_exists($obj_abs_path) AND is_dir($obj_abs_path)){
  43. $dirmdfile = $obj_abs_path."/".$GLOBALS["conf"]["dirmetadatafile"];
  44. $fp = fopen($dirmdfile, 'w');
  45. foreach ($data as $key => $value) {
  46. $value = stripslashes($value);
  47. if (trim($key) == "" or trim($value) == "") continue;
  48. $argo = trim($key)."=".trim($value);
  49. fwrite($fp, $argo);
  50. }
  51. fclose($fp);
  52. } else {
  53. report(2,"$obj_abs_path is not a folder!");
  54. }
  55. }
  56. ?>