function parseFull($xmlStr) { # Gebruik een spot template zodat we altijd de velden hebben die we willen $tpl_spot = array('category' => '', 'website' => '', 'image' => '', 'sabnzbdurl' => '', 'messageid' => '', 'searchurl' => '', 'description' => '', 'sub' => '', 'filesize' => '', 'poster' => '', 'tag' => '', 'nzb' => '', 'title' => '', 'filename' => '', 'newsgroup' => '', 'subcatlist' => array(), 'subcata' => '', 'subcatb' => '', 'subcatc' => '', 'subcatd' => '', 'imageid' => '', 'subcatz' => ''); /* * Onderdruk errors bij corrupte messaegeid, bv: <*****@*****.**> */ $xml = @new SimpleXMLElement($xmlStr); $xml = $xml->Posting; $tpl_spot['category'] = (string) $xml->Category; $tpl_spot['website'] = (string) $xml->Website; $tpl_spot['description'] = (string) utf8_encode($xml->Description); $tpl_spot['filesize'] = (string) $xml->Size; $tpl_spot['poster'] = (string) utf8_encode($xml->Poster); $tpl_spot['tag'] = (string) utf8_encode($xml->Tag); $tpl_spot['title'] = (string) utf8_encode($xml->Title); # FTD spots bevatten de filename if (!empty($xml->Filename)) { $tpl_spot['filename'] = (string) $xml->Filename; } # if # FTD spots bevatten de newsgroup if (!empty($xml->Newsgroup)) { $tpl_spot['newsgroup'] = (string) $xml->newsgroup; } # if # Images behandelen we op een speciale manier, in oude spots # was er gewoon een URL, in de nieuwe een hoogte/lengte/messageid if (empty($xml->Image->Segment)) { $tpl_spot['image'] = (string) $xml->Image; } else { $tpl_spot['image'] = array('segment' => (string) $xml->Image->Segment, 'height' => (string) $xml->Image['Height'], 'width' => (string) $xml->Image['Width']); } # else # NZB segmenten plakken we gewoon aan elkaar foreach ($xml->xpath('/Spotnet/Posting/NZB/Segment') as $seg) { $tpl_spot['nzb'][] = (string) $seg; } # foreach # fix the category in the XML array but only for new spots if ((int) $xml->Key != 1) { $tpl_spot['category'] = (int) $tpl_spot['category'] - 1; } # if # # Bij FTD spots wordt er al een gesplitste array van subcategorieen aangeleverd # die uiteraard niet compatible is met de nieuwe style van subcategorieen # $subcatList = array(); # Category subelementen plakken we gewoon aan elkaar, category zelf kennen we toe if (!empty($xml->SubCat)) { foreach ($xml->xpath('/Spotnet/Posting/Category/SubCat') as $sub) { $subcatList[] = (string) $sub; } # foreach } else { foreach ($xml->xpath('/Spotnet/Posting/Category/Sub') as $sub) { $subcatList[] = (string) $sub; } # foreach } # if # match hoofdcat/subcat-type/subcatvalue foreach ($subcatList as $subcat) { if (preg_match('/(\\d+)([aAbBcCdDzZ])(\\d+)/', preg_quote($subcat), $tmpMatches)) { $subCatVal = strtolower($tmpMatches[2]) . (int) $tmpMatches[3]; $tpl_spot['subcatlist'][] = $subCatVal; $tpl_spot['subcat' . $subCatVal[0]] .= $subCatVal . '|'; } # if } # foreach # we zetten de Z3 category erbij op het moment dat een oude spot in de erotiek # category valt, dit maakt ons filter een stuk simpeler. if (empty($tpl_spot['subcatz'])) { $tpl_spot['subcatz'] = SpotCategories::createSubcatZ($tpl_spot['category'], $tpl_spot['subcata'] . $tpl_spot['subcatb'] . $tpl_spot['subcatd']); } # if # and return the parsed XML return $tpl_spot; }
function parseFull($xmlStr) { # Create a template array so we always have the full fields to prevent ugly notices $tpl_spot = array('category' => '', 'website' => '', 'image' => '', 'sabnzbdurl' => '', 'messageid' => '', 'searchurl' => '', 'description' => '', 'sub' => '', 'filesize' => '', 'poster' => '', 'tag' => '', 'nzb' => '', 'title' => '', 'filename' => '', 'newsgroup' => '', 'subcata' => '', 'subcatb' => '', 'subcatc' => '', 'subcatd' => '', 'subcatz' => '', 'created' => '', 'key' => '', 'prevMsgids' => array()); /* * Some legacy spotNet clients create incorrect/invalid multiple segments, * we use this crude way to workaround this. GH issue #1608 */ if (strpos($xmlStr, 'spot.net></Segment') !== false) { $xmlStr = str_replace(array('spot.net></Segment>', 'spot.ne</Segment>'), array('spot.net</Segment>', 'spot.net</Segment>'), $xmlStr); } // if /* * Fix up some forgotten entity encoding / cdata sections in the XML */ $xmlStr = $this->correctElmContents($xmlStr, array('Title', 'Description', 'Image', 'Tag', 'Website')); /* * Supress errors for corrupt messageids, eg: <*****@*****.**> */ $xml = @new SimpleXMLElement($xmlStr); $xml = $xml->Posting; $tpl_spot['created'] = (string) $xml->Created; $tpl_spot['key'] = (string) $xml->Key; $tpl_spot['category'] = (string) $xml->Category; $tpl_spot['website'] = (string) $xml->Website; $tpl_spot['description'] = (string) $xml->Description; $tpl_spot['filesize'] = (string) $xml->Size; $tpl_spot['poster'] = (string) utf8_encode($xml->Poster); $tpl_spot['tag'] = (string) utf8_encode($xml->Tag); $tpl_spot['title'] = (string) $xml->Title; // Decode HTML special characters, title otherwise search will be broken, description as body in newsgroup $tpl_spot['title'] = html_entity_decode($tpl_spot['title'], ENT_QUOTES, 'UTF-8'); $tpl_spot['description'] = html_entity_decode($tpl_spot['description'], ENT_QUOTES, 'UTF-8'); # FTD spots have the filename if (!empty($xml->Filename)) { $tpl_spot['filename'] = (string) $xml->Filename; } # if # FTD spots have the newsgroup if (!empty($xml->Newsgroup)) { $tpl_spot['newsgroup'] = (string) $xml->newsgroup; } # if /* * Images available can be in the XML in two different ways. * * Some older spots just have an URL we can use, newer spots * have an height/width/messageid(s) pair we use to retrieve the image * from */ if (empty($xml->Image->Segment)) { $tpl_spot['image'] = (string) $xml->Image; } else { $tpl_spot['image'] = array('height' => (string) $xml->Image['Height'], 'width' => (string) $xml->Image['Width']); foreach ($xml->xpath('/Spotnet/Posting/Image/Segment') as $seg) { # Make sure the messageid's are valid so we do not throw an NNTP error if (!$this->_util->validMessageId((string) $seg)) { $tpl_spot['image']['segment'] = array(); break; } else { $tpl_spot['image']['segment'][] = (string) $seg; } # if } # foreach } # else # Just stitch together the NZB segments foreach ($xml->xpath('/Spotnet/Posting/NZB/Segment') as $seg) { if (!$this->_util->validMessageId((string) $seg)) { $tpl_spot['nzb'] = array(); break; } else { $tpl_spot['nzb'][] = (string) $seg; } # else } # foreach // PREVSPOTS if (!empty($xml->PREVSPOTS->Spot)) { foreach ($xml->xpath('/Spotnet/Posting/PREVSPOTS/Spot') as $seg) { # Make sure the messageid's are valid so we do not throw an NNTP error if ($this->_util->validMessageId((string) $seg)) { $tpl_spot['prevMsgids'][] = (string) $seg; } # if } # foreach } # else # fix the category in the XML array but only for new spots if ((int) $xml->Key != 1) { $tpl_spot['category'] = (int) $tpl_spot['category'] - 1; } # if /* * For FTD spots an array of subcategories is created. This array is not * compatible with that of newer spots so we need two seperate codepaths */ $subcatList = array(); /* * We fix up the category list later in the system, so we just extract the * list of subcategories */ if (!empty($xml->SubCat)) { foreach ($xml->xpath('/Spotnet/Posting/Category/SubCat') as $sub) { $subcatList[] = (string) $sub; } # foreach } else { foreach ($xml->xpath('/Spotnet/Posting/Category/Sub') as $sub) { $subcatList[] = (string) $sub; } # foreach } # if /* * Mangle the several types of subcategory listing to make sure we only * have to use one type in the rest of Spotwb */ foreach ($subcatList as $subcat) { if (preg_match('/(\\d+)([aAbBcCdDzZ])(\\d+)/', preg_quote($subcat), $tmpMatches)) { $subCatVal = strtolower($tmpMatches[2]) . (int) $tmpMatches[3]; $tpl_spot['subcat' . $subCatVal[0]] .= $subCatVal . '|'; } # if } # foreach /* * subcatz is a subcategory introduced in later Spotnet formats, we prefer to * always have this subcategory so we just fake it if it's not listed. */ if (empty($tpl_spot['subcatz'])) { $tpl_spot['subcatz'] = SpotCategories::createSubcatZ($tpl_spot['category'], $tpl_spot['subcata'] . $tpl_spot['subcatb'] . $tpl_spot['subcatd']); } # if # map deprecated genre categories to their new genre category $tpl_spot['subcatd'] = SpotCategories::mapDeprecatedGenreSubCategories($tpl_spot['category'], $tpl_spot['subcatd'], $tpl_spot['subcatz']); $tpl_spot['subcatc'] = SpotCategories::mapLanguageSubCategories($tpl_spot['category'], $tpl_spot['subcatc'], $tpl_spot['subcatz']); # and return the parsed XML return $tpl_spot; }
function parseFull($xmlStr) { # Create a template array so we always have the full fields to prevent ugly notices $tpl_spot = array('category' => '', 'website' => '', 'image' => '', 'sabnzbdurl' => '', 'messageid' => '', 'searchurl' => '', 'description' => '', 'sub' => '', 'filesize' => '', 'poster' => '', 'tag' => '', 'nzb' => '', 'title' => '', 'filename' => '', 'newsgroup' => '', 'subcatlist' => array(), 'subcata' => '', 'subcatb' => '', 'subcatc' => '', 'subcatd' => '', 'subcatz' => ''); /* * Supress errors for corrupt messageids, eg: <*****@*****.**> */ $xml = @new SimpleXMLElement($xmlStr); $xml = $xml->Posting; $tpl_spot['category'] = (string) $xml->Category; $tpl_spot['website'] = (string) $xml->Website; $tpl_spot['description'] = (string) $xml->Description; $tpl_spot['filesize'] = (string) $xml->Size; $tpl_spot['poster'] = (string) utf8_encode($xml->Poster); $tpl_spot['tag'] = (string) utf8_encode($xml->Tag); $tpl_spot['title'] = (string) $xml->Title; # FTD spots have the filename if (!empty($xml->Filename)) { $tpl_spot['filename'] = (string) $xml->Filename; } # if # FTD spots have the newsgroup if (!empty($xml->Newsgroup)) { $tpl_spot['newsgroup'] = (string) $xml->newsgroup; } # if /* * Images available can be in the XML in two different ways. * * Some older spots just have an URL we can use, newer spots * have an height/width/messageid(s) pair we use to retrieve the image * from */ if (empty($xml->Image->Segment)) { $tpl_spot['image'] = (string) $xml->Image; } else { $tpl_spot['image'] = array('height' => (string) $xml->Image['Height'], 'width' => (string) $xml->Image['Width']); foreach ($xml->xpath('/Spotnet/Posting/Image/Segment') as $seg) { # Make sure the messageid's are valid so we do not throw an NNTP error if (!$this->validMessageId((string) $seg)) { $tpl_spot['image']['segment'] = array(); break; } else { $tpl_spot['image']['segment'][] = (string) $seg; } # if } # foreach } # else # Just stitch together the NZB segments foreach ($xml->xpath('/Spotnet/Posting/NZB/Segment') as $seg) { if (!$this->validMessageId((string) $seg)) { $tpl_spot['nzb'] = array(); break; } else { $tpl_spot['nzb'][] = (string) $seg; } # else } # foreach # fix the category in the XML array but only for new spots if ((int) $xml->Key != 1) { $tpl_spot['category'] = (int) $tpl_spot['category'] - 1; } # if /* * For FTD spots an array of subcategories is created. This array is not * compatible with that of newer spots so we need two seperate codepaths */ $subcatList = array(); /* * We fix up the category list later in the system, so we just extract the * list of subcategories */ if (!empty($xml->SubCat)) { foreach ($xml->xpath('/Spotnet/Posting/Category/SubCat') as $sub) { $subcatList[] = (string) $sub; } # foreach } else { foreach ($xml->xpath('/Spotnet/Posting/Category/Sub') as $sub) { $subcatList[] = (string) $sub; } # foreach } # if /* * Mangle the several types of subcategory listing to make sure we only * have to use one type in the rest of Spotwb */ foreach ($subcatList as $subcat) { if (preg_match('/(\\d+)([aAbBcCdDzZ])(\\d+)/', preg_quote($subcat), $tmpMatches)) { $subCatVal = strtolower($tmpMatches[2]) . (int) $tmpMatches[3]; $tpl_spot['subcatlist'][] = $subCatVal; $tpl_spot['subcat' . $subCatVal[0]] .= $subCatVal . '|'; } # if } # foreach /* * subcatz is a subcategory introduced in later Spotnet formats, we prefer to * always have this subcategory so we just fake it if it's not listed. */ if (empty($tpl_spot['subcatz'])) { $tpl_spot['subcatz'] = SpotCategories::createSubcatZ($tpl_spot['category'], $tpl_spot['subcata'] . $tpl_spot['subcatb'] . $tpl_spot['subcatd']); } # if # and return the parsed XML return $tpl_spot; }