xpath("//id[. ='".$id."']/.."); return @$xmlNode[0]->locale->title; } return null; } function getTitleFromDiscID($id,$sys) { switch ($sys) { case "ps3": return ps3GetTitleFromDiscID($id); default: return NULL; } } function getNameFromISO($iso,$sys) { $id = substr($iso,0,9); if ($sys === 'ps3') { $t = getTitleFromDiscID($id,$sys); if (strlen($t) >= 3) return $t; } $p1 = strpos($iso,'[') + 1; $p2 = strpos($iso,']',$p1); return substr($iso,$p1,($p2 - strlen($iso))); } function readParamSFO($data,$force_max = false) { $keytable_offset = unpack('I',substr($data,8,4))[1]; $data_offset = unpack('I',substr($data,12,4))[1]; $table_entries = unpack('I',substr($data,16,4))[1]; $keytable = array_filter(explode("\0",substr($data,$keytable_offset,($data_offset - $keytable_offset)))); $idxtable = substr($data,20,($keytable_offset-20)); $data = substr($data,$data_offset,-1); $pos = 0; $i = 1; while ($pos < strlen($idxtable)) { $key[$i]['start'] = unpack('I',substr($idxtable,$pos,2)."\0\0")[1]; $pos = $pos + 2; $key[$i]['fmt'] = unpack('I',substr($idxtable,$pos,2)."\0\0")[1]; $pos = $pos + 2; $key[$i]['len'] = unpack('I',substr($idxtable,$pos,4))[1]; $pos = $pos + 4; $key[$i]['max_len'] = unpack('I',substr($idxtable,$pos,4))[1]; $pos = $pos + 4; $key[$i]['offset'] = unpack('I',substr($idxtable,$pos,4))[1]; $pos = $pos + 4; $i++; } $i = 0; foreach ($key as $k) { if ($force_max) { $pm = substr($data,$k['offset'],$k['max_len']); } else { $pm = substr($data,$k['offset'],$k['len']); } $param[$keytable[$i]] = trim($pm); $i++; } return $param; } function scanISO($ftp,$content,$dir,$disk = "dev_hdd0") { // Assumes filename is XXXX#####-[Game Name].iso (or .bin) // Falls back to entire filename as title. global $crlf; switch (strtolower($dir)) { case "psx": // no break to allow it to hit ps1 processing $dir = "ps1"; case "ps1": $rdir = "PSXISO"; break; case "ps2": $rdir = "PS2ISO"; break; case "ps3": $rdir = "PS3ISO"; break; case "dvd": $rdir = "DVDISO"; break; case "bd": $rdir = "BDISO"; break; default: return false; break; } if ($ftp === "local") { $ftptmp = array(); $ftptmp_tmp = scandir($disk.'/'.$rdir); foreach ($ftptmp_tmp as $v) { if ($v !== "." && $v !== "..") $ftptmp[]['name'] = $v; } unset($ftptmp_tmp); } else { $ftptmp = ftp_mlsd($ftp,"/".$disk."/".$rdir); } foreach ($ftptmp as $d) { if (strtolower(substr($d['name'],(strlen($d['name']) - 3),3)) == "bin" || strtolower(substr($d['name'],(strlen($d['name']) - 3),3)) == "iso" || strtolower(substr($d['name'],(strlen($d['name']) - 5),5)) == "iso.0") { if ($dir == 'ps1' || $dir == 'ps2' || $dir == 'psp') { $valid = "No"; } else { $valid = "-N/A-"; } if (preg_match("/^[SNUBPM][A-Z]{3}[0-9]{5}/",$d['name'])) { $v = getNameFromISO($d['name'],$dir); $tid = substr($d['name'],0,9); if ($dir == 'ps1' || $dir == 'ps2' || $dir == 'ps3') { if ($dir == 'ps3') { $valid = "IRD"; } else { $valid = "redump.org"; } if (preg_match("/\[\^\]/",$d['name'])) { if ($dir == 'ps3') { $valid = "None"; } else { $valid = "None"; } } if (preg_match("/\[\!\]/",$d['name'])) { $valid = "Fail"; } } } else { $tid = "-N/A-"; if (strtolower(substr($d['name'],(strlen($d['name']) - 5),5)) == "iso.0") { $v = substr($d['name'],0,(strlen($d['name']) - 6)); } else { $v = substr($d['name'],0,(strlen($d['name']) - 4)); } } echo strtoupper($dir).": ".$v."".$crlf; $i = getNextKey(@$content[strtolower($dir)]); unset($ca); $ca['ID'] = $tid; $ca['Title'] = removeUnwantedWording($v); $ca['Region'] = getCountryFromTitleID(substr($d['name'],0,9)); $ca['Type'] = "ISO"; $ca['Verification'] = $valid; $content = setContent($content,$i,strtolower($dir),$ca); } } return $content; } function getCountryFromTitleID($titleid) { $cc = substr($titleid,2,1); switch ($cc) { case "U": return "US"; case "E"; return "EU"; case "J": case "P": return "JP"; default: return "WW"; } } function scanFolder($ftp,$content,$dir,$disk = "dev_hdd0",$filter = true) { global $crlf; $ftptmp = ftp_mlsd($ftp,"/".$disk."/".$dir); $res = []; foreach ($ftptmp as $d) { // is XXXX#####, starts with N or U, is a directory, isn't blacklisted (by id) if ((preg_match("/^[NU][A-Z]{3}[0-9]{5}$/",$d['name']) && $d['type'] == 'dir' && !isBlacklisted($d['name'])) || !$filter) { unset($ca); ob_start(); $result = ftp_get($ftp, "php://output", "/dev_hdd0/".$dir."/".$d['name']."/PARAM.SFO", FTP_BINARY); $ps3sfo = ob_get_contents(); ob_end_clean(); if (strlen(@$ps3sfo) > 0) { $pdecode = readParamSFO($ps3sfo); // Check again against SFO TITLE_ID if (isBlacklisted(@$pdecode['TITLE_ID'])) { continue; } if (@$pdecode['BOOTABLE']) { $v = preg_replace("/\n/"," ",$pdecode['TITLE']); switch (substr($pdecode['TITLE_ID'],0,2)) { case "UL": case "UC": $pdecode = readParamSFO($ps3sfo,1); $v = preg_replace("/\n/"," ",$pdecode['TITLE']); echo "PSP (Pkg): ".$v."".$crlf; $i = getNextKey(@$content['psp']); $ca['ID'] = $pdecode['TITLE_ID']; $ca['Title'] = $v; $ca['Region'] = getCountryFromTitleID(substr($pdecode['TITLE_ID'],0,9)); $ca['Type'] = "PKG"; $ca['Verification'] = "None"; $content = setContent($content,$i,'psp',$ca); break; case "SC": case "SL": $ser = substr($pdecode['TITLE_ID'],4,5); if ((intval($ser) >= 20000 && substr($pdecode['TITLE_ID'],1,1) == "L") || (intval($ser) >= 96000 && substr($pdecode['TITLE_ID'],1,1) == "C")) { echo "PS2: ".removeUnwantedWording($v)." [".$pdecode['TITLE_ID']."]".$crlf; $i = getNextKey(@$content['ps2']); $ca['ID'] = $pdecode['TITLE_ID']; $ca['Title'] = removeUnwantedWording($v); $ca['Region'] = getCountryFromTitleID(substr($pdecode['TITLE_ID'],0,9)); $ca['Type'] = "PSN"; $ca['Verification'] = "PSN"; $content = setContent($content,$i,'ps2',$ca); } else { echo "PS1: ".removeUnwantedWording($v)." [".$pdecode['TITLE_ID']."]".$crlf; $i = getNextKey(@$content['ps1']); $ca['ID'] = $pdecode['TITLE_ID']; $ca['Title'] = removeUnwantedWording($v); $ca['Region'] = getCountryFromTitleID(substr($pdecode['TITLE_ID'],0,9)); $ca['Type'] = "PSN"; $ca['Verification'] = "PSN"; $content = setContent($content,$i,'ps1',$ca); } break; default: // Fell back to generic PSN Package, so check overrides if (checkOverride($pdecode['TITLE_ID'],'ps1')) { echo "PS1: ".removeUnwantedWording($v)."".$crlf; $i = getNextKey(@$content['ps1']); $ca['ID'] = $pdecode['TITLE_ID']; $ca['Title'] = removeUnwantedWording($v); $ca['Region'] = getCountryFromTitleID(substr($pdecode['TITLE_ID'],0,9)); $ca['Type'] = "PSN"; $ca['Verification'] = "PSN"; $content = setContent($content,$i,'ps1',$ca); } elseif (checkOverride($pdecode['TITLE_ID'],'ps2')) { echo "PS2: ".removeUnwantedWording($v)."".$crlf; $i = getNextKey(@$content['ps2']); $ca['ID'] = $pdecode['TITLE_ID']; $ca['Title'] = removeUnwantedWording($v); $ca['Region'] = getCountryFromTitleID(substr($pdecode['TITLE_ID'],0,9)); $ca['Type'] = "PSN"; $ca['Verification'] = "PSN"; $content = setContent($content,$i,'ps2',$ca); } elseif (checkOverride($pdecode['TITLE_ID'],'ps3')) { echo "PS3: ".removeUnwantedWording($v)."".$crlf; $i = getNextKey(@$content['ps3']); $ca['ID'] = $pdecode['TITLE_ID']; $ca['Title'] = removeUnwantedWording($v); $ca['Region'] = getCountryFromTitleID(substr($pdecode['TITLE_ID'],0,9)); $ca['Type'] = "PSN"; $ca['Verification'] = "PSN"; $content = setContent($content,$i,'ps3',$ca); } elseif (checkOverride($pdecode['TITLE_ID'],'software')) { echo "Software: ".removeUnwantedWording($v)."".$crlf; $i = getNextKey(@$content['software']); $ca['ID'] = $pdecode['TITLE_ID']; $ca['Title'] = removeUnwantedWording($v); $ca['Region'] = "-N/A-"; $ca['Type'] = "PKG"; $ca['Verification'] = "-N/A-"; $content = setContent($content,$i,'software',$ca); } else { echo "PSN: ".removeUnwantedWording($v)." (".$pdecode['TITLE_ID'].")".$crlf; $i = getNextKey(@$content['psn']); $ca['ID'] = $pdecode['TITLE_ID']; $ca['Title'] = removeUnwantedWording($v); $ca['Region'] = getCountryFromTitleID(substr($pdecode['TITLE_ID'],0,9)); $ca['Type'] = "PSN"; $ca['Verification'] = "PSN"; $content = setContent($content,$i,'psn',$ca); } break; } } } } elseif ($dir == 'game' && preg_match("/^[A-Z0-9]{9}$/",$d['name']) && (!preg_match("/^B[A-Z0-9]{8}$/",$d['name']) || $d['name'] == "BLES80608")) { ob_start(); $result = ftp_get($ftp, "php://output", "/".$disk."/".$dir."/".$d['name']."/PARAM.SFO", FTP_BINARY); $ps3sfo = ob_get_contents(); ob_end_clean(); $pdecode = readParamSFO($ps3sfo,1); // Check again against SFO TITLE_ID if (isBlacklisted(@$pdecode['TITLE_ID'])) { continue; } $v = preg_replace("/\n/"," ",$pdecode['TITLE']); echo "Software: ".removeUnwantedWording($v)." [".$pdecode['TITLE_ID']."]".$crlf; $i = getNextKey(@$content['software']); $ca['ID'] = $pdecode['TITLE_ID']; $ca['Title'] = removeUnwantedWording($v); $ca['Region'] = "-N/A-"; $ca['Type'] = "PKG"; $ca['Verification'] = "-N/A-"; $content = setContent($content,$i,'software',$ca); } } return $content; } function setContent($c,$i,$t,$d) { global $override; $c[$t][$i] = $d; if (is_array(@$override[$t][$d['ID']])) { foreach ($override[$t][$d['ID']] as $k => $v) { $c[$t][$i][$k] = $v; } } return $c; } function sortByTitle($a, $b) { return strnatcasecmp($a['Title'], $b['Title']); } function processData($d,$s,$c=null) { global $crlf; $s .= " (".count($d)." total)"; global $ascii_table; usort($d, 'sortByTitle'); if (is_array($c)) { $width = 0; foreach ($c as $f) { $width = ($width + $f); } $width = $width + (count($c) * 3) - 1; $out = "+".str_repeat('-',$width)."+".$crlf; $out .= $ascii_table->make_table($d,$s,true,$c); } else { $out = $ascii_table->make_table($d,$s,true); } return $out."".$crlf; } function getNextKey($array) { if (is_array(@$array)) { return count($array); } else { return 0; } } function getTableTitle($k) { switch ($k) { case 'ps1': $title = "PLAYSTATION(R) 1 Games"; break; case 'ps2': $title = "PLAYSTATION(R) 2 Games"; break; case 'ps3': $title = "PLAYSTATION(R) 3 Games"; break; case 'psp': $title = "PLAYSTATION(R) Portable Games"; break; case 'psn': $title = "PLAYSTATION(R) Network Games"; break; case 'software': $title = "PLAYSTATION(R) 3 Software"; break; case 'dvd': $title = "DVD Video ISOs"; break; case 'bd': $title = "Blu-ray Video ISOs"; break; } return $title; } function getTableWidth($c) { global $ascii_table; $cw = array(); $cm = 0; foreach ($c as $k => $v) { $ascii_table->get_col_widths($c[$k]); $atcw = $ascii_table->col_widths; foreach ($atcw as $t) { if ($t > $cm) { $cm = $t; $cw = $atcw; } } } return $cw; } class ascii_table{ public $col_widths = array(); private $table_width = 0; private $crlf = "\n"; public $error = ''; function __construct($init = "\n") { $this->crlf = $init; } function make_table($array,$title='',$return=false,$col_widths = array()){ $table = ''; $this->table_width = 0; if (is_array($col_widths)) { $this->col_widths = $col_widths; } else { $this->col_widths = array(); $this->get_col_widths($array); } if($title!=''){ $this->get_table_width(); $table .= $this->make_title($title); } if(isset($array[0])){ $table .= $this->make_divider(); $table .= $this->make_headers(); $table .= $this->make_divider(); $table .= $this->make_rows($array); $table .= $this->make_divider(); } if(is_string($return)){ $save = @file_put_contents($return,$table); if($save){ return true; }else{ $this->error = 'Unable to save table to "'.$return.'".'; return false; } }else{ if($return){ return $table; }else{ echo $table; } } } static function len($col_value){ return extension_loaded('mbstring') ? mb_strlen($col_value) : strlen($col_value); } function break_table($table){ $load_file = @file_get_contents($table); if($load_file!==false){ $table = $load_file; } $table = explode("".$this->crlf,trim($table)); if(substr($table[0],0,1)!='+'){ unset($table[0]); $table = array_values($table); } $array = array(); $array_columns = array(); $columns = explode('|',$table[1]); foreach($columns as $n => $value){ if($n>0 && $n $column){ $array[$row][$column] = trim($row_items[$pos]); } } $array = array_values($array); return $array; } function scrape_table($table,$key,$value=null){ $table = $this->break_table($table); $array = array(); foreach($table as $row => $data){ if($value==null){ $grabbed_value = $data[$key]; $grabbed_key = $row; }else{ $grabbed_key = $data[$key]; $grabbed_value = $data[$value]; } $array[$grabbed_key] = $grabbed_value; } return $array; } function get_col_widths($array){ if(isset($array[0])){ foreach(array_keys($array[0]) as $col){ $this->col_widths[$col] = max(max(array_map(array($this,'len'), $this->arr_col($array, $col))), $this->len($col)); } } } function arr_col($array,$col){ if(is_callable('array_column')){ return array_column($array,$col); }else{ $return = array(); foreach($array as $n => $dat){ if(isset($dat[$col])){ $return[] = $dat[$col]; } } return $return; } } function get_table_width(){ $this->table_width = array_sum($this->col_widths); $this->table_width += count($this->col_widths)*2; $this->table_width += count($this->col_widths)+1; } function make_title($title){ $title = trim($title); $lpadding = floor(($this->table_width-$this->len($title))/2) - 1; $rpadding = $lpadding; while ($this->len($title) + $lpadding + $rpadding + 2 < $this->table_width) { $rpadding++; } return "|".str_repeat(' ',max($lpadding,0)).$title.str_repeat(' ',max($rpadding,0))."|".$this->crlf; } function make_divider(){ $divider = '+'; foreach($this->col_widths as $col => $length){ $divider .= str_repeat('-',$length+2).'+'; } return $divider."".$this->crlf; } function make_headers(){ $row = '|'; foreach($this->col_widths as $col => $length){ $row .= ' '.$col.' '; if($this->len($col)<$length){ $row .= str_repeat(' ',$length-$this->len($col)); } $row .= '|'; } return $row."".$this->crlf; } function make_rows($array){ $rows = ''; foreach($array as $n => $data){ $rows .= '|'; foreach($data as $col => $value){ $rows .= ' '.$value.' '; if($this->len($value)<$this->col_widths[$col]){ $rows .= str_repeat(' ', $this->col_widths[$col]-$this->len($value)); } $rows .= '|'; } $rows .= "".$this->crlf; } return $rows; } } function array_to_xml_custom( $data, &$xml_data , $i = 0) { if ($i == 0) { global $content_order; foreach ($content_order as $f) { if (@$data[$f]) { $ctmp = array(); foreach ($data[$f] as $v) { $ctmp[] = $v; } unset($data[$f]); $data[$f]['name'] = getTableTitle($f); $data[$f]['content'] = $ctmp; unset($ctmp); $subnode = $xml_data->addChild($f); array_to_xml_custom($data[$f],$subnode,1); } } return; } foreach( $data as $key => $value ) { if( is_numeric($key) ){ $key = 'item'; } if( is_array($value) ) { $subnode = $xml_data->addChild($key); array_to_xml_custom($value, $subnode, ($i + 1)); } else { $xml_data->addChild(strtolower($key),htmlspecialchars("$value")); } } } function exportToXML($data,$xsl = NULL) { if (strpos($xsl[1],"id=") <= 0) { $xsl[1] = preg_replace("/version\=/","id=\"stylesheet\" version=",$xsl[1]); } $xsl = implode("", $xsl); $xml_data = NULL; if ($xsl !== NULL) { $xml_data = new SimpleXMLElement(']>'.$xsl.''); } else { $xml_data = new SimpleXMLElement(''); } if ($xml_data !== NULL) { array_to_xml_custom($data,$xml_data); $dom = new DOMDocument("1.0"); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML($xml_data->asXML()); return $dom->saveXML(); } else { return NULL; } }