public function postSpot($user, $spot, $imageFilename, $nzbFilename) { $errorList = array(); $hdr_newsgroup = $this->_settings->get('hdr_group'); $bin_newsgroup = $this->_settings->get('nzb_group'); /* $hdr_newsgroup = 'alt.test'; $bin_newsgroup = 'alt.test'; */ # If the hashcash doesn't match, we will never post it if (substr(sha1('<' . $spot['newmessageid'] . '>'), 0, 4) != '0000') { $errorList[] = array('postspot_invalidhashcash', array()); } # if # Read the contents of image so we can check it $imageContents = file_get_contents($imageFilename); # the image should be below 1MB if (strlen($imageContents) > 1024 * 1024) { $errorList[] = array('postspot_imagetoolarge', array()); } # if /* * Get some image information, if it fails, this is an * error as well */ $tmpGdImageSize = getimagesize($imageFilename); if ($tmpGdImageSize === false) { $errorList[] = array('postspot_imageinvalid', array()); } else { $imageInfo = array('width' => $tmpGdImageSize[0], 'height' => $tmpGdImageSize[1]); } # if # Body cannot be empty, very short or too long $spot['body'] = trim($spot['body']); if (strlen($spot['body']) < 30) { $errorList[] = array('postspot_bodytooshort', array()); } # if if (strlen($spot['body']) > 9000) { $errorList[] = array('postspot_bodytoolong', array()); } # if # Title cannot be empty or very short $spot['title'] = trim($spot['title']); if (strlen($spot['title']) < 5) { $errorList[] = array('postspot_titletooshort', array()); } # if # Subcategory should be valid if ($spot['category'] < 0 || $spot['category'] > count(SpotCategories::$_head_categories)) { $errorList[] = array('postspot_invalidcategory', array($spot['category'])); } # if /* * Load the NZB file as an XML file so we can make sure * it's a valid XML and NZB file and we can determine the * filesize */ $nzbFileContents = file_get_contents($nzbFilename); $nzbXml = simplexml_load_string($nzbFileContents); # Do some basic sanity checking for some required NZB elements if (empty($nzbXml->file)) { $errorList[] = array('postspot_invalidnzb', array()); } # if # and determine the total filesize $spot['filesize'] = 0; foreach ($nzbXml->file as $file) { foreach ($file->segments->segment as $seg) { $spot['filesize'] += (int) $seg['bytes']; } # foreach } # foreach /* * Make sure we didn't use this messageid recently or at all, this * prevents people from not recalculating the hashcash in order to spam * the system */ if (!$this->_db->isNewSpotMessageIdUnique($spot['newmessageid'])) { $errorList[] = array('postspot_replayattack', array()); } # if # We require the keyid 7 because it is selfsigned $spot['key'] = 7; # Poster's username $spot['poster'] = $user['username']; # Fix up some overly long spot properties and other minor issues $spot['tag'] = substr(trim($spot['tag'], " |;\r\n\t"), 0, 99); $spot['http'] = substr(trim($spot['website']), 0, 449); # Create one list of all subcategories $spot['subcatlist'] = explode(',', $spot['subcatlist']); /* * Loop through all subcategories and check if they are valid in * our list of subcategories */ $subCatSplitted = array('a' => array(), 'b' => array(), 'c' => array(), 'd' => array(), 'z' => array()); foreach ($spot['subcatlist'] as $subCat) { $subcats = explode('_', $subCat); $subCatLetter = substr($subcats[2], 0, 1); $subCatSplitted[$subCatLetter][] = $subCat; if (!isset(SpotCategories::$_categories[$spot['category']][$subCatLetter][substr($subcats[2], 1)])) { $errorList[] = array('postspot_invalidsubcat', array($subCat . ' !! ' . $subCatLetter . ' !! ' . substr($subcats[2], 1))); } # if } # foreach /* * Make sure all subcategories are in the format we expect, for * example we strip the 'cat' part and strip the z-subcat */ $subcatCount = count($spot['subcatlist']); for ($i = 0; $i < $subcatCount; $i++) { $subcats = explode('_', $spot['subcatlist'][$i]); # If not in our format if (count($subcats) != 3) { $errorList[] = array('postspot_invalidsubcat', array($spot['subcatlist'][$i])); } else { $spot['subcatlist'][$i] = substr($subcats[2], 0, 1) . str_pad(substr($subcats[2], 1), 2, '0', STR_PAD_LEFT); # Explicitly add the 'z'-category $zcatStr = substr($subcats[1], 0, 1) . str_pad(substr($subcats[1], 1), 2, '0', STR_PAD_LEFT); if (array_search($zcatStr, $spot['subcatlist']) === false) { $spot['subcatlist'][] = $zcatStr; } # if } # else } # for # Make sure the spot isn't being posted in many categories if (count($subCatSplitted['a']) > 1) { $errorList[] = array('postspot_canonlybeoneformat', count($spot['subcatlist'])); } # if # Make sure the spot has at least a format if (count($subCatSplitted['a']) < 1) { $errorList[] = array('postspot_musthaveformat', count($spot['subcatlist'])); } # if # Make sure the spot isn't being posted for too many categories if (count($spot['subcatlist']) > 10) { $errorList[] = array('postspot_toomanycategories', count($spot['subcatlist'])); } # if # Make sure the spot isn't being posted for too many categories if (count($spot['subcatlist']) < 2) { $errorList[] = array('postspot_toofewcategories', count($spot['subcatlist'])); } # if # en post daadwerkelijk de spot if (empty($errorList)) { /* * Retrieve the image information and post the image to * the appropriate newsgroup so we have the messageid list of * images */ $imgSegmentList = $this->_nntp_post->postBinaryMessage($user, $bin_newsgroup, $imageContents, ''); $imageInfo['segments'] = $imgSegmentList; # Post the NZB file to the appropriate newsgroups $nzbSegmentList = $this->_nntp_post->postBinaryMessage($user, $bin_newsgroup, gzdeflate($nzbFileContents), ''); # Convert the current Spotnet info, to an XML structure $spotParser = new SpotParser(); $spotXml = $spotParser->convertSpotToXml($spot, $imageInfo, $nzbSegmentList); $spot['spotxml'] = $spotXml; # And actually post to the newsgroups $this->_nntp_post->postFullSpot($user, $this->_settings->get('privatekey'), $hdr_newsgroup, $spot); $this->_db->addPostedSpot($user['userid'], $spot, $spotXml); } # if return $errorList; }