Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Overwrite the private constructor with a public one #1554

  • Loading branch information...
commit 752e4db0016e6f86e8a77b4a1de42ae94046d876 1 parent be500da
spotweb authored
View
708 lib/SpotPosting.php
@@ -1,354 +1,354 @@
-<?php
-
-class SpotPosting {
- private $_db;
- private $_settings;
- private $_nntp_post;
-
- function __construct(SpotDb $db, SpotSettings $settings) {
- $this->_db = $db;
- $this->_settings = $settings;
-
- $this->_nntp_post = new SpotNntp($settings->get('nntp_post'));
- } # ctor
-
- /*
- * Post een comment op een spot naar de newsserver, als dit lukt komt er
- * een 'true' terug, anders een foutmelding
- */
- public function postComment($user, $comment) {
- $errorList = array();
-
- # haal de spot op waar dit een reply op is
- $spotsOverview = new SpotsOverview($this->_db, $this->_settings);
- $fullSpot = $spotsOverview->getFullSpot($comment['inreplyto'], $user['userid'], $this->_nntp_post);
-
- # als de hashcash al niet klopt, doen we verder geen moeite
- if (substr(sha1('<' . $comment['newmessageid'] . '>'), 0, 4) != '0000') {
- $errorList[] = _('Hash was not calculated properly');
- } # if
-
- # Body mag niet leeg zijn of heel kort
- $comment['body'] = trim($comment['body']);
- if (strlen($comment['body']) < 2) {
- $errorList[] = _('Please enter a comment');
- } # if
- if (strlen($comment['body']) > 9000) {
- $errorList[] = _('Comment is too long');
- } # if
-
- # Rating mag niet uit de range vallen
- if (($comment['rating'] > 10) || ($comment['rating'] < 0)) {
- $errorList[] = _('Invalid rating');
- } # if
-
- # controleer dat de messageid waarop we replyen overeenkomt
- # met het newMessageid om replay-attacks te voorkomen.
- $replyToPart = substr($comment['inreplyto'], 0, strpos($comment['inreplyto'], '@'));
-
- if (substr($comment['newmessageid'], 0, strlen($replyToPart)) != $replyToPart) {
- $errorList[] = _('Replay attack!?');
- } # if
-
- # controleer dat het random getal niet recentelijk ook al gebruikt
- # is voor deze messageid (hiermee voorkomen we dat de hashcash niet
- # steeds herberekend wordt voor het volspammen van 1 spot).
- if (!$this->_db->isCommentMessageIdUnique($comment['newmessageid'])) {
- $errorList[] = _('Replay attack!?');
- } # if
-
- # Make sure a newmessageid contains a certain length
- if (strlen($comment['newmessageid']) < 10) {
- $errorList[] = _('MessageID too short!?');
- } # if
-
- # Add the title as a comment property
- $comment['title'] = 'Re: ' . $fullSpot['title'];
-
- # Body komt vanuit het form als UTF-8, maar moet verzonden worden als ISO-8859-1
- # De database wil echter alleen UTF-8, dus moeten we dat even opsplitsen
- $dbComment = $comment;
- $comment['body'] = utf8_decode($comment['body']);
-
- # en post daadwerkelijk de comment
- if (empty($errorList)) {
- $this->_nntp_post->postComment($user,
- $this->_settings->get('privatekey'), # Server private key
- $this->_settings->get('comment_group'),
- $comment);
- $this->_db->addPostedComment($user['userid'], $dbComment);
- } # if
-
- return $errorList;
- } # postComment
-
- /*
- * Post a spot to the usenet server.
- */
- 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[] = _('Hash was not calculated properly');
- } # 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[] = _('Uploaded image is too large (maximum 1MB)');
- } # if
-
- /*
- * Get some image information, if it fails, this is an
- * error as well
- */
- $tmpGdImageSize = getimagesize($imageFilename);
- if ($tmpGdImageSize === false) {
- $errorList[] = _('Uploaded image was not recognized as an image');
- } 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[] = _('Please enter an description');
- } # if
- if (strlen($spot['body']) > 9000) {
- $errorList[] = _('Entered description is too long');
- } # if
-
- # Title cannot be empty or very short
- $spot['title'] = trim($spot['title']);
- if (strlen($spot['title']) < 5) {
- $errorList[] = _('Enter a title');
- } # if
-
- # Subcategory should be valid
- if (($spot['category'] < 0) || ($spot['category'] > count(SpotCategories::$_head_categories))) {
- $errorList[] = sprintf(_('Incorrect headcategory (%s)'), $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[] = _('Incorrect NZB file');
- } # 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[] = _('Replay attack!?');
- } # if
-
- # Make sure a newmessageid contains a certain length
- if (strlen($spot['newmessageid']) < 10) {
- $errorList[] = _('MessageID too short!?');
- } # 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);
-
- /**
- * If the post's character do not fit into ISO-8859-1, we HTML
- * encode the UTF-8 characters so we can properly post the spots
- */
- if (mb_detect_encoding($spot['title'], 'UTF-8, ISO-8859-1', true) == 'UTF-8') {
- $spot['title'] = mb_convert_encoding($spot['title'], 'HTML-ENTITIES', 'UTF-8');
- } # if
-
- /*
- * 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);
- # If not in our format
- if (count($subcats) != 3) {
- $errorList[] = sprintf(_('Incorrect subcategories (%s)'), $subCat);
- } else {
- $subCatLetter = substr($subcats[2], 0, 1);
-
- $subCatSplitted[$subCatLetter][] = $subCat;
-
- if (!isset(SpotCategories::$_categories[$spot['category']][$subCatLetter][substr($subcats[2], 1)])) {
- $errorList[] = sprintf(_('Incorrect subcategories (%s)'), $subCat . ' !! ' . $subCatLetter . ' !! ' . substr($subcats[2], 1));
- } # if
- } # else
- } # 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[] = sprintf(_('Incorrect subcateories (%s)'), $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 - we derive it from the full categorynames we already have
- $zcatStr = substr($subcats[1], 0, 1) . str_pad(substr($subcats[1], 1), 2, '0', STR_PAD_LEFT);
- if ((is_numeric(substr($subcats[1], 1))) && (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[] = _('You can only specify one format for a spot');
- } # if
-
- # Make sure the spot has at least a format
- if (count($subCatSplitted['a']) < 1) {
- $errorList[] = _('You need to specify a format for a spot');
- } # if
-
- # Make sure the spot isn't being posted for too many categories
- if (count($spot['subcatlist']) > 10) {
- $errorList[] = _('Too many categories');
- } # if
-
- # Make sure the spot isn't being posted for too many categories
- if (count($spot['subcatlist']) < 2) {
- $errorList[] = _('At least one category need to be selected');
- } # 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'), # Server private key
- $hdr_newsgroup,
- $spot);
- $this->_db->addPostedSpot($user['userid'], $spot, $spotXml);
- } # if
-
- return $errorList;
- } # postSpot
-
- /*
- * Post een spam report van een spot naar de newsserver, als dit lukt komt er
- * een 'true' terug, anders een foutmelding
- */
- public function reportSpotAsSpam($user, $report) {
- $errorList = array();
-
- # Controleer eerst of de user al een report heeft aangemaakt, dan kunnen we gelijk stoppen.
- if ($this->_db->isReportPlaced($report['inreplyto'], $user['userid'])) {
- $errorList[] = _('This spot has already been marked as spam');
- } # if
-
- # haal de spot op waar dit een reply op is
- $spotsOverview = new SpotsOverview($this->_db, $this->_settings);
- $fullSpot = $spotsOverview->getFullSpot($report['inreplyto'], $user['userid'], $this->_nntp_post);
-
- # als de hashcash al niet klopt, doen we verder geen moeite
- if (substr(sha1('<' . $report['newmessageid'] . '>'), 0, 4) != '0000') {
- $errorList[] = _('Hash was not calculated properly');
- } # if
-
- # Body mag niet leeg zijn of heel kort
- $report['body'] = trim($report['body']);
- if (strlen($report['body']) < 2) {
- $errorList[] = _('Please provide a comment');
- } # if
-
- # controleer dat de messageid waarop we replyen overeenkomt
- # met het newMessageid om replay-attacks te voorkomen.
- $replyToPart = substr($report['inreplyto'], 0, strpos($report['inreplyto'], '@'));
-
- if (substr($report['newmessageid'], 0, strlen($replyToPart)) != $replyToPart) {
- $errorList[] = _('Replay attack!?');
- } # if
-
- # controleer dat het random getal niet recentelijk ook al gebruikt
- # is voor deze messageid (hiermee voorkomen we dat de hashcash niet
- # steeds herberekend wordt voor het volspammen van 1 spot).
- if (!$this->_db->isReportMessageIdUnique($report['newmessageid'])) {
- $errorList[] = _('Replay attack!?');
- } # if
-
- # Make sure a newmessageid contains a certain length
- if (strlen($report['newmessageid']) < 10) {
- $errorList[] = _('MessageID too short!?');
- } # if
-
- # Body komt vanuit het form als UTF-8, maar moet verzonden worden als ISO-8859-1
- # De database wil echter alleen UTF-8, dus moeten we dat even opsplitsen
- $dbReport = $report;
- $report['body'] = utf8_decode($report['body']);
- $report['title'] = 'REPORT <' . $report['inreplyto'] . '> ' . $fullSpot['title'];
-
- # en post daadwerkelijk de report
- if (empty($errorList)) {
- $this->_nntp_post->reportSpotAsSpam($user,
- $this->_settings->get('privatekey'), # Server private key
- $this->_settings->get('report_group'),
- $report);
- $this->_db->addPostedReport($user['userid'], $dbReport);
- } # if
-
- return $errorList;
- } # reportSpotAsSpam
-
-} # SpotPosting
+<?php
+
+class SpotPosting {
+ private $_db;
+ private $_settings;
+ private $_nntp_post;
+
+ function __construct(SpotDb $db, SpotSettings $settings) {
+ $this->_db = $db;
+ $this->_settings = $settings;
+
+ $this->_nntp_post = new SpotNntp($settings->get('nntp_post'));
+ } # ctor
+
+ /*
+ * Post een comment op een spot naar de newsserver, als dit lukt komt er
+ * een 'true' terug, anders een foutmelding
+ */
+ public function postComment($user, $comment) {
+ $errorList = array();
+
+ # haal de spot op waar dit een reply op is
+ $spotsOverview = new SpotsOverview($this->_db, $this->_settings);
+ $fullSpot = $spotsOverview->getFullSpot($comment['inreplyto'], $user['userid'], $this->_nntp_post);
+
+ # als de hashcash al niet klopt, doen we verder geen moeite
+ if (substr(sha1('<' . $comment['newmessageid'] . '>'), 0, 4) != '0000') {
+ $errorList[] = _('Hash was not calculated properly');
+ } # if
+
+ # Body mag niet leeg zijn of heel kort
+ $comment['body'] = trim($comment['body']);
+ if (strlen($comment['body']) < 2) {
+ $errorList[] = _('Please enter a comment');
+ } # if
+ if (strlen($comment['body']) > 9000) {
+ $errorList[] = _('Comment is too long');
+ } # if
+
+ # Rating mag niet uit de range vallen
+ if (($comment['rating'] > 10) || ($comment['rating'] < 0)) {
+ $errorList[] = _('Invalid rating');
+ } # if
+
+ # controleer dat de messageid waarop we replyen overeenkomt
+ # met het newMessageid om replay-attacks te voorkomen.
+ $replyToPart = substr($comment['inreplyto'], 0, strpos($comment['inreplyto'], '@'));
+
+ if (substr($comment['newmessageid'], 0, strlen($replyToPart)) != $replyToPart) {
+ $errorList[] = _('Replay attack!?');
+ } # if
+
+ # controleer dat het random getal niet recentelijk ook al gebruikt
+ # is voor deze messageid (hiermee voorkomen we dat de hashcash niet
+ # steeds herberekend wordt voor het volspammen van 1 spot).
+ if (!$this->_db->isCommentMessageIdUnique($comment['newmessageid'])) {
+ $errorList[] = _('Replay attack!?');
+ } # if
+
+ # Make sure a newmessageid contains a certain length
+ if (strlen($comment['newmessageid']) < 10) {
+ $errorList[] = _('MessageID too short!?');
+ } # if
+
+ # Add the title as a comment property
+ $comment['title'] = 'Re: ' . $fullSpot['title'];
+
+ # Body komt vanuit het form als UTF-8, maar moet verzonden worden als ISO-8859-1
+ # De database wil echter alleen UTF-8, dus moeten we dat even opsplitsen
+ $dbComment = $comment;
+ $comment['body'] = utf8_decode($comment['body']);
+
+ # en post daadwerkelijk de comment
+ if (empty($errorList)) {
+ $this->_nntp_post->postComment($user,
+ $this->_settings->get('privatekey'), # Server private key
+ $this->_settings->get('comment_group'),
+ $comment);
+ $this->_db->addPostedComment($user['userid'], $dbComment);
+ } # if
+
+ return $errorList;
+ } # postComment
+
+ /*
+ * Post a spot to the usenet server.
+ */
+ 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[] = _('Hash was not calculated properly');
+ } # 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[] = _('Uploaded image is too large (maximum 1MB)');
+ } # if
+
+ /*
+ * Get some image information, if it fails, this is an
+ * error as well
+ */
+ $tmpGdImageSize = getimagesize($imageFilename);
+ if ($tmpGdImageSize === false) {
+ $errorList[] = _('Uploaded image was not recognized as an image');
+ } 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[] = _('Please enter an description');
+ } # if
+ if (strlen($spot['body']) > 9000) {
+ $errorList[] = _('Entered description is too long');
+ } # if
+
+ # Title cannot be empty or very short
+ $spot['title'] = trim($spot['title']);
+ if (strlen($spot['title']) < 5) {
+ $errorList[] = _('Enter a title');
+ } # if
+
+ # Subcategory should be valid
+ if (($spot['category'] < 0) || ($spot['category'] > count(SpotCategories::$_head_categories))) {
+ $errorList[] = sprintf(_('Incorrect headcategory (%s)'), $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[] = _('Incorrect NZB file');
+ } # 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[] = _('Replay attack!?');
+ } # if
+
+ # Make sure a newmessageid contains a certain length
+ if (strlen($spot['newmessageid']) < 10) {
+ $errorList[] = _('MessageID too short!?');
+ } # 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);
+
+ /**
+ * If the post's character do not fit into ISO-8859-1, we HTML
+ * encode the UTF-8 characters so we can properly post the spots
+ */
+ if (mb_detect_encoding($spot['title'], 'UTF-8, ISO-8859-1', true) == 'UTF-8') {
+ $spot['title'] = mb_convert_encoding($spot['title'], 'HTML-ENTITIES', 'UTF-8');
+ } # if
+
+ /*
+ * 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);
+ # If not in our format
+ if (count($subcats) != 3) {
+ $errorList[] = sprintf(_('Incorrect subcategories (%s)'), $subCat);
+ } else {
+ $subCatLetter = substr($subcats[2], 0, 1);
+
+ $subCatSplitted[$subCatLetter][] = $subCat;
+
+ if (!isset(SpotCategories::$_categories[$spot['category']][$subCatLetter][substr($subcats[2], 1)])) {
+ $errorList[] = sprintf(_('Incorrect subcategories (%s)'), $subCat . ' !! ' . $subCatLetter . ' !! ' . substr($subcats[2], 1));
+ } # if
+ } # else
+ } # 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[] = sprintf(_('Incorrect subcateories (%s)'), $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 - we derive it from the full categorynames we already have
+ $zcatStr = substr($subcats[1], 0, 1) . str_pad(substr($subcats[1], 1), 2, '0', STR_PAD_LEFT);
+ if ((is_numeric(substr($subcats[1], 1))) && (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[] = _('You can only specify one format for a spot');
+ } # if
+
+ # Make sure the spot has at least a format
+ if (count($subCatSplitted['a']) < 1) {
+ $errorList[] = _('You need to specify a format for a spot');
+ } # if
+
+ # Make sure the spot isn't being posted for too many categories
+ if (count($spot['subcatlist']) > 10) {
+ $errorList[] = _('Too many categories');
+ } # if
+
+ # Make sure the spot isn't being posted for too many categories
+ if (count($spot['subcatlist']) < 2) {
+ $errorList[] = _('At least one category need to be selected');
+ } # 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'), # Server private key
+ $hdr_newsgroup,
+ $spot);
+ $this->_db->addPostedSpot($user['userid'], $spot, $spotXml);
+ } # if
+
+ return $errorList;
+ } # postSpot
+
+ /*
+ * Post een spam report van een spot naar de newsserver, als dit lukt komt er
+ * een 'true' terug, anders een foutmelding
+ */
+ public function reportSpotAsSpam($user, $report) {
+ $errorList = array();
+
+ # Controleer eerst of de user al een report heeft aangemaakt, dan kunnen we gelijk stoppen.
+ if ($this->_db->isReportPlaced($report['inreplyto'], $user['userid'])) {
+ $errorList[] = _('This spot has already been marked as spam');
+ } # if
+
+ # haal de spot op waar dit een reply op is
+ $spotsOverview = new SpotsOverview($this->_db, $this->_settings);
+ $fullSpot = $spotsOverview->getFullSpot($report['inreplyto'], $user['userid'], $this->_nntp_post);
+
+ # als de hashcash al niet klopt, doen we verder geen moeite
+ if (substr(sha1('<' . $report['newmessageid'] . '>'), 0, 4) != '0000') {
+ $errorList[] = _('Hash was not calculated properly');
+ } # if
+
+ # Body mag niet leeg zijn of heel kort
+ $report['body'] = trim($report['body']);
+ if (strlen($report['body']) < 2) {
+ $errorList[] = _('Please provide a comment');
+ } # if
+
+ # controleer dat de messageid waarop we replyen overeenkomt
+ # met het newMessageid om replay-attacks te voorkomen.
+ $replyToPart = substr($report['inreplyto'], 0, strpos($report['inreplyto'], '@'));
+
+ if (substr($report['newmessageid'], 0, strlen($replyToPart)) != $replyToPart) {
+ $errorList[] = _('Replay attack!?');
+ } # if
+
+ # controleer dat het random getal niet recentelijk ook al gebruikt
+ # is voor deze messageid (hiermee voorkomen we dat de hashcash niet
+ # steeds herberekend wordt voor het volspammen van 1 spot).
+ if (!$this->_db->isReportMessageIdUnique($report['newmessageid'])) {
+ $errorList[] = _('Replay attack!?');
+ } # if
+
+ # Make sure a newmessageid contains a certain length
+ if (strlen($report['newmessageid']) < 10) {
+ $errorList[] = _('MessageID too short!?');
+ } # if
+
+ # Body komt vanuit het form als UTF-8, maar moet verzonden worden als ISO-8859-1
+ # De database wil echter alleen UTF-8, dus moeten we dat even opsplitsen
+ $dbReport = $report;
+ $report['body'] = utf8_decode($report['body']);
+ $report['title'] = 'REPORT <' . $report['inreplyto'] . '> ' . $fullSpot['title'];
+
+ # en post daadwerkelijk de report
+ if (empty($errorList)) {
+ $this->_nntp_post->reportSpotAsSpam($user,
+ $this->_settings->get('privatekey'), # Server private key
+ $this->_settings->get('report_group'),
+ $report);
+ $this->_db->addPostedReport($user['userid'], $dbReport);
+ } # if
+
+ return $errorList;
+ } # reportSpotAsSpam
+
+} # SpotPosting
View
482 lib/retriever/SpotRetriever_Abs.php
@@ -1,241 +1,241 @@
-<?php
-abstract class SpotRetriever_Abs {
- protected $_server;
- protected $_spotnntp;
- protected $_db;
- protected $_settings;
- protected $_debug;
- protected $_retro;
-
- private $_msgdata;
-
- /*
- * Returns the status in either xml or text format
- */
- abstract function displayStatus($cat, $txt);
-
- /*
- * Actual processing of the headers
- */
- abstract function process($hdrList, $curMsg, $increment, $timer);
-
- /*
- * Remove any extraneous reports from the database because we assume
- * the highest messgeid in the database is the latest on the server.
- */
- abstract function updateLastRetrieved($highestMessageId);
-
- /*
- * returns the name of the group we are expected to retrieve messages from
- */
- abstract function getGroupName();
-
- /*
- * Highest articleid for the implementation in the database
- */
- abstract function getMaxArticleId();
-
- /*
- * Returns the highest messageid in the database
- */
- abstract function getMaxMessageId();
-
- /*
- * default ctor
- */
- function __construct($server, SpotDb $db, SpotSettings $settings, $debug, $retro) {
- $this->_server = $server;
- $this->_db = $db;
- $this->_settings = $settings;
- $this->_debug = $debug;
- $this->_retro = $retro;
- } # ctor
-
- function debug($s) {
- if ($this->_debug) {
- echo 'DEBUG: ' . microtime(true) . ':' . $s . PHP_EOL;
- } # if
- } # debug
-
- function connect($group) {
- # if an retriever instance is already running, stop this one
- if ($this->_db->isRetrieverRunning($this->_server['host'])) {
- throw new RetrieverRunningException();
- } # if
-
- /*
- * and notify the system we are running
- */
- $this->_db->setRetrieverRunning($this->_server['host'], true);
-
- # and fireup the nntp connection
- $this->displayStatus("lastretrieve", $this->_db->getLastUpdate($this->_server['host']));
- $this->displayStatus("start", $this->_server['host']);
- $this->_spotnntp = new SpotNntp($this->_server);
- $this->_msgdata = $this->_spotnntp->selectGroup($group);
-
- return $this->_msgdata;
- } # connect
-
-
- /*
- * Given a list of messageids, check if we can find the corresponding
- * articlenumber on the NNTP server.
- */
- function searchMessageid($messageIdList) {
- $this->debug('searchMessageId=' . serialize($messageIdList));
-
- if (empty($messageIdList) || $this->_retro) {
- return 0;
- } # if
-
- $this->displayStatus('searchmsgid', '');
-
- $found = false;
- $decrement = 5000;
- $curMsg = $this->_msgdata['last'];
-
- # start searching
- while (($curMsg >= $this->_msgdata['first']) && (!$found)) {
- # Reset timelimit
- set_time_limit(120);
-
- $curMsg = max(($curMsg - $decrement), $this->_msgdata['first'] - 1);
-
- # get the list of headers (XHDR)
- $hdrList = $this->_spotnntp->getMessageIdList($curMsg - 1, ($curMsg + $decrement));
- $this->debug('getMessageIdList returned=' . serialize($hdrList));
-
- /*
- * Reverse the list with messageids because we assume we are at a recent
- * run and the last retrieved messageid should be on the top of the list
- * somewhere
- */
- $hdrList = array_reverse($hdrList, true);
-
- echo 'Searching from ' . ($curMsg -1) . ' to ' . ($curMsg + $decrement) . PHP_EOL;
-
- foreach($hdrList as $msgNum => $msgId) {
- if (isset($messageIdList[$msgId])) {
- $curMsg = $msgNum;
- $found = true;
- break;
- } # if
- } # for
- } # while
-
- $this->debug('getMessageIdList loop finished, found = ' . $found);
- $this->debug('getMessageIdList loop finished, curMsg = ' . $curMsg);
-
- return $curMsg;
- } # searchMessageId
-
- /*
- * Process all headers in $increment pieces and call the corresponding
- * actual implementation
- */
- function loopTillEnd($curMsg, $increment = 1000) {
- $processed = 0;
- $headersProcessed = 0;
- $highestMessageId = '';
-
- # make sure we handle articlenumber wrap arounds
- if ($curMsg < $this->_msgdata['first']) {
- $curMsg = $this->_msgdata['first'];
- } # if
-
- $this->displayStatus("groupmessagecount", ($this->_msgdata['last'] - $this->_msgdata['first']));
- $this->displayStatus("firstmsg", $this->_msgdata['first']);
- $this->displayStatus("lastmsg", $this->_msgdata['last']);
- $this->displayStatus("curmsg", $curMsg);
- $this->displayStatus("", "");
-
- while ($curMsg < $this->_msgdata['last']) {
- $timer = microtime(true);
-
- # get the list of headers (XOVER)
- $hdrList = $this->_spotnntp->getOverview($curMsg, ($curMsg + $increment));
-
- $saveCurMsg = $curMsg;
- # If no spots were found, just manually increase the
- # messagenumber with the increment to make sure we advance
- if ((count($hdrList) < 1) || ($hdrList[count($hdrList)-1]['Number'] < $curMsg)) {
- $curMsg += $increment;
- } else {
- $curMsg = ($hdrList[count($hdrList)-1]['Number'] + 1);
- } # else
-
- # run the processing method
- $processOutput = $this->process($hdrList, $saveCurMsg, $curMsg, $timer);
- $processed += $processOutput['count'];
- $headersProcessed += $processOutput['headercount'];
- $highestMessageId = $processOutput['lastmsgid'];
-
- # reset the start time to prevent a another retriever from starting
- # during the intial retrieve which can take many hours
- $this->_db->setRetrieverRunning($this->_server['host'], true);
- } # while
-
- # we are done updating, make sure that if the newsserver deleted
- # earlier retrieved messages, we remove them from our database
- if ($highestMessageId != '') {
- $this->debug('loopTillEnd() finished, highestMessageId = ' . $highestMessageId);
- $this->updateLastRetrieved($highestMessageId);
- } # if
-
- $this->displayStatus("totalprocessed", $processed);
- return $headersProcessed;
- } # loopTillEnd()
-
- function quit() {
- # notify the system we are not running anymore
- $this->_db->setRetrieverRunning($this->_server['host'], false);
-
- # and disconnect
- $this->_spotnntp->quit();
- $this->displayStatus("done", "");
- } # quit()
-
- function perform() {
- /*
- * try to connect to the usenet server and select the group
- */
- $msgdata = $this->connect($this->getGroupName());
-
- /*
- * Ask the implementation class for the highest articleid
- * found on the system
- */
- $curMsg = $this->getMaxArticleId();
-
- /*
- * If this usenet server is new for us, we just assume
- * we have to start from zero. Else we do a lookup from
- * the messageid to find the correct articlenumber.
- *
- * We cannot just use the articlenumber because the NNTP
- * spec allows a server to renumber of course.
- */
- if (($curMsg != 0) && (!$this->_retro)) {
- $curMsg = $this->searchMessageId($this->getMaxMessageId());
-
- if ($this->_server['buggy']) {
- $curMsg = max(1, $curMsg - 15000);
- } # if
- } # if
-
- /*
- * and actually start looping till we retrieved all headers or articles
- */
- $newProcessedCount = $this->loopTillEnd($curMsg, $this->_settings->get('retrieve_increment'));
-
- /*
- * and cleanup
- */
- $this->quit();
- $this->_db->setLastUpdate($this->_server['host']);
-
- return $newProcessedCount;
- } # perform
-
-} # class SpotRetriever
+<?php
+abstract class SpotRetriever_Abs {
+ protected $_server;
+ protected $_spotnntp;
+ protected $_db;
+ protected $_settings;
+ protected $_debug;
+ protected $_retro;
+
+ private $_msgdata;
+
+ /*
+ * Returns the status in either xml or text format
+ */
+ abstract function displayStatus($cat, $txt);
+
+ /*
+ * Actual processing of the headers
+ */
+ abstract function process($hdrList, $curMsg, $increment, $timer);
+
+ /*
+ * Remove any extraneous reports from the database because we assume
+ * the highest messgeid in the database is the latest on the server.
+ */
+ abstract function updateLastRetrieved($highestMessageId);
+
+ /*
+ * returns the name of the group we are expected to retrieve messages from
+ */
+ abstract function getGroupName();
+
+ /*
+ * Highest articleid for the implementation in the database
+ */
+ abstract function getMaxArticleId();
+
+ /*
+ * Returns the highest messageid in the database
+ */
+ abstract function getMaxMessageId();
+
+ /*
+ * default ctor
+ */
+ function __construct($server, SpotDb $db, SpotSettings $settings, $debug, $retro) {
+ $this->_server = $server;
+ $this->_db = $db;
+ $this->_settings = $settings;
+ $this->_debug = $debug;
+ $this->_retro = $retro;
+ } # ctor
+
+ function debug($s) {
+ if ($this->_debug) {
+ echo 'DEBUG: ' . microtime(true) . ':' . $s . PHP_EOL;
+ } # if
+ } # debug
+
+ function connect($group) {
+ # if an retriever instance is already running, stop this one
+ if ($this->_db->isRetrieverRunning($this->_server['host'])) {
+ throw new RetrieverRunningException();
+ } # if
+
+ /*
+ * and notify the system we are running
+ */
+ $this->_db->setRetrieverRunning($this->_server['host'], true);
+
+ # and fireup the nntp connection
+ $this->displayStatus("lastretrieve", $this->_db->getLastUpdate($this->_server['host']));
+ $this->displayStatus("start", $this->_server['host']);
+ $this->_spotnntp = new SpotNntp($this->_server);
+ $this->_msgdata = $this->_spotnntp->selectGroup($group);
+
+ return $this->_msgdata;
+ } # connect
+
+
+ /*
+ * Given a list of messageids, check if we can find the corresponding
+ * articlenumber on the NNTP server.
+ */
+ function searchMessageid($messageIdList) {
+ $this->debug('searchMessageId=' . serialize($messageIdList));
+
+ if (empty($messageIdList) || $this->_retro) {
+ return 0;
+ } # if
+
+ $this->displayStatus('searchmsgid', '');
+
+ $found = false;
+ $decrement = 5000;
+ $curMsg = $this->_msgdata['last'];
+
+ # start searching
+ while (($curMsg >= $this->_msgdata['first']) && (!$found)) {
+ # Reset timelimit
+ set_time_limit(120);
+
+ $curMsg = max(($curMsg - $decrement), $this->_msgdata['first'] - 1);
+
+ # get the list of headers (XHDR)
+ $hdrList = $this->_spotnntp->getMessageIdList($curMsg - 1, ($curMsg + $decrement));
+ $this->debug('getMessageIdList returned=' . serialize($hdrList));
+
+ /*
+ * Reverse the list with messageids because we assume we are at a recent
+ * run and the last retrieved messageid should be on the top of the list
+ * somewhere
+ */
+ $hdrList = array_reverse($hdrList, true);
+
+ echo 'Searching from ' . ($curMsg -1) . ' to ' . ($curMsg + $decrement) . PHP_EOL;
+
+ foreach($hdrList as $msgNum => $msgId) {
+ if (isset($messageIdList[$msgId])) {
+ $curMsg = $msgNum;
+ $found = true;
+ break;
+ } # if
+ } # for
+ } # while
+
+ $this->debug('getMessageIdList loop finished, found = ' . $found);
+ $this->debug('getMessageIdList loop finished, curMsg = ' . $curMsg);
+
+ return $curMsg;
+ } # searchMessageId
+
+ /*
+ * Process all headers in $increment pieces and call the corresponding
+ * actual implementation
+ */
+ function loopTillEnd($curMsg, $increment = 1000) {
+ $processed = 0;
+ $headersProcessed = 0;
+ $highestMessageId = '';
+
+ # make sure we handle articlenumber wrap arounds
+ if ($curMsg < $this->_msgdata['first']) {
+ $curMsg = $this->_msgdata['first'];
+ } # if
+
+ $this->displayStatus("groupmessagecount", ($this->_msgdata['last'] - $this->_msgdata['first']));
+ $this->displayStatus("firstmsg", $this->_msgdata['first']);
+ $this->displayStatus("lastmsg", $this->_msgdata['last']);
+ $this->displayStatus("curmsg", $curMsg);
+ $this->displayStatus("", "");
+
+ while ($curMsg < $this->_msgdata['last']) {
+ $timer = microtime(true);
+
+ # get the list of headers (XOVER)
+ $hdrList = $this->_spotnntp->getOverview($curMsg, ($curMsg + $increment));
+
+ $saveCurMsg = $curMsg;
+ # If no spots were found, just manually increase the
+ # messagenumber with the increment to make sure we advance
+ if ((count($hdrList) < 1) || ($hdrList[count($hdrList)-1]['Number'] < $curMsg)) {
+ $curMsg += $increment;
+ } else {
+ $curMsg = ($hdrList[count($hdrList)-1]['Number'] + 1);
+ } # else
+
+ # run the processing method
+ $processOutput = $this->process($hdrList, $saveCurMsg, $curMsg, $timer);
+ $processed += $processOutput['count'];
+ $headersProcessed += $processOutput['headercount'];
+ $highestMessageId = $processOutput['lastmsgid'];
+
+ # reset the start time to prevent a another retriever from starting
+ # during the intial retrieve which can take many hours
+ $this->_db->setRetrieverRunning($this->_server['host'], true);
+ } # while
+
+ # we are done updating, make sure that if the newsserver deleted
+ # earlier retrieved messages, we remove them from our database
+ if ($highestMessageId != '') {
+ $this->debug('loopTillEnd() finished, highestMessageId = ' . $highestMessageId);
+ $this->updateLastRetrieved($highestMessageId);
+ } # if
+
+ $this->displayStatus("totalprocessed", $processed);
+ return $headersProcessed;
+ } # loopTillEnd()
+
+ function quit() {
+ # notify the system we are not running anymore
+ $this->_db->setRetrieverRunning($this->_server['host'], false);
+
+ # and disconnect
+ $this->_spotnntp->quit();
+ $this->displayStatus("done", "");
+ } # quit()
+
+ function perform() {
+ /*
+ * try to connect to the usenet server and select the group
+ */
+ $msgdata = $this->connect($this->getGroupName());
+
+ /*
+ * Ask the implementation class for the highest articleid
+ * found on the system
+ */
+ $curMsg = $this->getMaxArticleId();
+
+ /*
+ * If this usenet server is new for us, we just assume
+ * we have to start from zero. Else we do a lookup from
+ * the messageid to find the correct articlenumber.
+ *
+ * We cannot just use the articlenumber because the NNTP
+ * spec allows a server to renumber of course.
+ */
+ if (($curMsg != 0) && (!$this->_retro)) {
+ $curMsg = $this->searchMessageId($this->getMaxMessageId());
+
+ if ($this->_server['buggy']) {
+ $curMsg = max(1, $curMsg - 15000);
+ } # if
+ } # if
+
+ /*
+ * and actually start looping till we retrieved all headers or articles
+ */
+ $newProcessedCount = $this->loopTillEnd($curMsg, $this->_settings->get('retrieve_increment'));
+
+ /*
+ * and cleanup
+ */
+ $this->quit();
+ $this->_db->setLastUpdate($this->_server['host']);
+
+ return $newProcessedCount;
+ } # perform
+
+} # class SpotRetriever
View
958 lib/retriever/SpotRetriever_Spots.php
@@ -1,479 +1,479 @@
-<?php
-class SpotRetriever_Spots extends SpotRetriever_Abs {
- private $_rsakeys;
- private $_outputType;
- private $_retrieveFull;
- private $_prefetch_image;
- private $_prefetch_nzb;
-
- /**
- * Server is the server array we are expecting to connect to
- * db - database object
- */
- function __construct($server, SpotDb $db, SpotSettings $settings, $outputType, $debug, $retro) {
- parent::__construct($server, $db, $settings, $debug, $retro);
-
- $this->_rsakeys = $this->_settings->get('rsa_keys');
- $this->_outputType = $outputType;
- $this->_retrieveFull = $this->_settings->get('retrieve_full');
- $this->_prefetch_image = $this->_settings->get('prefetch_image');
- $this->_prefetch_nzb = $this->_settings->get('prefetch_nzb');
- } # ctor
-
-
- /*
- * Returns the status in either xml or text format
- */
- function displayStatus($cat, $txt) {
- if ($this->_outputType != 'xml') {
- switch($cat) {
- case 'start' : echo "Retrieving new Spots from server " . $txt . "..." . PHP_EOL; break;
- case 'lastretrieve' : echo strftime("Last retrieve at %c", $txt) . PHP_EOL; break;
- case 'done' : echo "Finished retrieving spots." . PHP_EOL . PHP_EOL; break;
- case 'groupmessagecount': echo "Appr. Message count: " . $txt . "" . PHP_EOL; break;
- case 'firstmsg' : echo "First message number: " . $txt . "" . PHP_EOL; break;
- case 'lastmsg' : echo "Last message number: " . $txt . "" . PHP_EOL; break;
- case 'curmsg' : echo "Current message: " . $txt . "" . PHP_EOL; break;
- case 'progress' : echo "Retrieving " . $txt; break;
- case 'hdrparsed' : echo " (parsed " . $txt . " headers, "; break;
- case 'fullretrieved' : echo $txt . " full, "; break;
- case 'verified' : echo "verified " . $txt . ", "; break;
- case 'modcount' : echo "moderated " . $txt . ", "; break;
- case 'skipcount' : echo "skipped " . $txt . " of "; break;
- case 'loopcount' : echo $txt . " total messages)"; break;
- case 'timer' : echo " in " . $txt . " seconds" . PHP_EOL; break;
- case 'totalprocessed' : echo "Processed a total of " . $txt . " spots" . PHP_EOL; break;
- case 'searchmsgid' : echo "Looking for articlenumber for messageid" . PHP_EOL; break;
- case '' : echo PHP_EOL; break;
-
- default : echo $cat . $txt;
- } # switch
- } else {
-
- switch($cat) {
- case 'start' : echo "<spots>"; break;
- case 'done' : echo "</spots>"; break;
- case 'totalprocessed' : echo "<totalprocessed>" . $txt . "</totalprocessed>"; break;
- case 'skipcount' : echo "<totalskipped> " . $txt . "</totalskipped>"; break;
- case 'totalremoved' : echo "<totalremoved>" . $txt . "</totalremoved>"; break;
- default : break;
- } # switch
- } # else xmloutput
- } # displayStatus
-
- /*
- * Remove any extraneous reports from the database because we assume
- * the highest messgeid in the database is the latest on the server.
- */
- function updateLastRetrieved($highestMessageId) {
- $this->debug('Highest messageid found: ' . $highestMessageId);
-
- /*
- * Remove any extraneous spots from the database because we assume
- * the highest messgeid in the database is the latest on the server.
- *
- * If the server is marked as buggy, the last 'x' amount of spot are
- * always checked so we do not have to do this
- */
- if (!$this->_server['buggy']) {
- $this->_db->removeExtraSpots($highestMessageId);
- } # if
- } # updateLastRetrieved
-
- /*
- * Actually process the retrieved headers from XOVER
- */
- function process($hdrList, $curMsg, $endMsg, $timer) {
- $this->displayStatus("progress", ($curMsg) . " till " . ($endMsg));
-
- $spotParser = new SpotParser();
- $signedCount = 0;
- $hdrsRetrieved = 0;
- $fullsRetrieved = 0;
- $msgCounter = 0;
- $modCount = 0;
- $skipCount = 0;
- $lastProcessedId = '';
- $fullSpotDbList = array();
- $spotDbList = array();
- $moderationList = array();
- $processingStartTime = time();
-
- /*
- * Determine the cutoff date (unixtimestamp) from whereon we do not want to
- * load the spots
- */
- if ($this->_settings->get('retention') > 0) {
- $retentionStamp = time() - ($this->_settings->get('retention') * 24 * 60 * 60);
- } else {
- $retentionStamp = 0;
- } # else
- $this->debug('retentionStamp=' . $retentionStamp);
- $this->debug('hdrList=' . serialize($hdrList));
-
- /**
- * We ask the database to match our messageid's we just retrieved with
- * the list of id's we have just retrieved from the server
- */
- $dbIdList = $this->_db->matchSpotMessageIds($hdrList);
-
- $this->debug('dbIdList=' . serialize($dbIdList));
-
- # if we need to fetch images or nzb files, we need an spotsoverview instance
- if ($this->_retrieveFull && ($this->_prefetch_image) || ($this->_prefetch_nzb)) {
- $spotsOverview = new SpotsOverview($this->_db, $this->_settings);
- $spotsOverview->setActiveRetriever(true);
-
- /*
- * Only create a new NZB instance if the server differs from the
- * header host, else re-use the connection
- */
- $settings_nntp_nzb = $this->_settings->get('nntp_nzb');
- if ($this->_server['host'] == $settings_nntp_nzb['host']) {
- $nntp_nzb = $this->_spotnntp;
- } else {
- $nntp_nzb = new SpotNntp($settings_nntp_nzb);
- $nntp_nzb->selectGroup($this->_settings->get('nzb_group'));
- } # else
- } # if
-
-
- foreach($hdrList as $msgheader) {
- $msgCounter++;
- $this->debug('foreach-loop, start. msgId= ' . $msgCounter);
-
- /*
- * Keep te usenet server alive when processing is slow.
- */
- if (($processingStartTime - time()) > 30) {
- $this->_spotnntp->sendNoop();
- if ((isset($nntp_nzb)) && ($nntp_nzb != $this->_spotnntp)) {
- $nntp_nzb->sendNoop();
- } # if
-
- $processingStartTime = time();
- } # if
-
- /*
- * We keep track whether we actually fetched this header and fullspot
- * to add it to the database, because only then we can update the
- * titel from the spots title or rely on our database to fetch
- * the fullspot
- */
- $didFetchHeader = false;
- $didFetchFullSpot = false;
-
- # Reset timelimit
- set_time_limit(120);
-
- # messageid to check
- $msgId = substr($msgheader['Message-ID'], 1, -1);
-
- /*
- * We prepare some variables to we don't have to perform an array
- * lookup for each check and the code is easier to read.
- */
- $header_isInDb = isset($dbIdList['spot'][$msgId]);
- $fullspot_isInDb = isset($dbIdList['fullspot'][$msgId]);
-
- /*
- * If the spotheader is not yet added to the database, parse the header
- * information.
- *
- * If the header is present, but we don't have the fullspot yet or we are
- * running in 'retro' mode, parse the header as well because some fields
- * are only in the header and not in the full.
- *
- * We need some of those fields (for example KeyID)
- */
- if (!$header_isInDb || ((!$fullspot_isInDb || $this->_retro) && $this->_retrieveFull)) {
- $hdrsRetrieved++;
- $this->debug('foreach-loop, parsingXover, start. msgId= ' . $msgCounter);
- $spot = $spotParser->parseXover($msgheader['Subject'],
- $msgheader['From'],
- $msgheader['Date'],
- $msgheader['Message-ID'],
- $this->_rsakeys);
- $this->debug('foreach-loop, parsingXover, done. msgId= ' . $msgCounter);
-
- /*
- * When a parse error occured, we ignore the spot, also unverified
- * spots are ignored
- */
- if (($spot === false) || (!$spot['verified'])){
- continue;
- } # if
-
- /*
- * Special moderator commands always have keyid 2
- */
- if ($spot['keyid'] == 2) {
- $commandAr = explode(' ', strtolower($spot['title']));
- $validCommands = array('delete', 'dispose', 'remove');
-
- # is this one of the defined valid commands?
- if (in_array($commandAr[0], $validCommands) !== false) {
- $moderationList[] = $commandAr[1];
- $modCount++;
- } # if
-
- } else {
- /*
- * Don't add spots older than specified for the retention stamp
- */
- if (($retentionStamp > 0) && ($spot['stamp'] < $retentionStamp) && ($this->_settings->get('retentiontype') == 'everything')) {
- continue;
- } elseif ($spot['stamp'] < $this->_settings->get('retrieve_newer_than')) {
- $skipCount++;
- } else {
- /*
- * Do we have the header in the database? If not, lets add it
- */
- if (!$header_isInDb) {
- $spotDbList[] = $spot;
-
- /*
- * Some buggy NNTP servers give us the same messageid
- * in one XOVER statement, hence we update the list of
- * messageid's we already have retrieved and are ready
- * to be added to the database
- */
- $dbIdList['spot'][$msgId] = 1;
- $header_isInDb = true;
- $lastProcessedId = $msgId;
- $didFetchHeader = true;
-
- if ($spot['wassigned']) {
- $signedCount++;
- } # if
- } # if
- } # if
-
- } # else
- } else {
- $lastProcessedId = $msgId;
- } # else
-
-
- /*
- * We don't want to retrieve the fullspot if we don't have the header
- * in the database. Because we try to add headers in the above code we just have
- * to check if the header is in the database.
- *
- * We cannot collapse this code with the header fetching code because we want to
- * be able to add the fullspot to a system after all the headers are retrieved
- */
- if ($header_isInDb && # header must be in the db
- !$fullspot_isInDb) # but the fullspot should not
- {
- /*
- * Don't add older fullspots than specified for the retention stamp
- */
- if (($retentionStamp > 0) && (strtotime($msgheader['Date']) < $retentionStamp)) {
- continue;
- } # if
-
- if ($this->_retrieveFull) {
- $fullSpot = array();
- try {
- $fullsRetrieved++;
- $this->debug('foreach-loop, getFullSpot, start. msgId= ' . $msgId);
- $fullSpot = $this->_spotnntp->getFullSpot($msgId);
- $this->debug('foreach-loop, getFullSpot, done. msgId= ' . $msgId);
-
- # add this spot to the database
- $fullSpotDbList[] = $fullSpot;
- $fullspot_isInDb = true;
- $didFetchFullSpot = true;
-
- /*
- * Some buggy NNTP servers give us the same messageid
- * in once XOVER statement, hence we update the list of
- * messageid's we already have retrieved and are ready
- * to be added to the database
- */
- $dbIdList['fullspot'][$msgId] = 1;
-
- /*
- * Overwrite the spots' title because the fullspot contains the title in
- * UTF-8 format.
- * We also overwrite the spotterid from the spotsfull because the spotterid
- * is only in the header in more recent spots.
- */
- if ($didFetchHeader) {
- $spotDbList[count($spotDbList) - 1]['title'] = $fullSpot['title'];
- $spotDbList[count($spotDbList) - 1]['spotterid'] = $fullSpot['spotterid'];
- } # if
- }
- catch(ParseSpotXmlException $x) {
- ; # swallow error
- }
- catch(Exception $x) {
- /**
- * Sometimes we get an 'No such article' error for a header we just retrieved,
- * if we want to retrieve the full article. This is messed up, but let's just
- * swallow the error
- */
- if ($x->getCode() == 430) {
- ;
- }
- # if the XML is unparseable, don't bother complaining about it
- elseif ($x->getMessage() == 'String could not be parsed as XML') {
- ;
- } else {
- throw $x;
- } # else
- } # catch
-
- } # if retrievefull
- } # if fullspot is not in db yet
-
- if ($this->_retrieveFull && $header_isInDb && ($this->_prefetch_image || $this->_prefetch_nzb)) {
- try {
- /*
- * If we are running in 'retro' mode, it is possible both the header and spot are in the
- * database already, however -- we need the information from the fullspot so we retrieve it
- * again
- */
- if (!$didFetchFullSpot) {
- $fullSpot = $this->_db->getFullSpot($msgId, SPOTWEB_ANONYMOUS_USERID);
- $fullSpot = array_merge($spotParser->parseFull($fullSpot['fullxml']), $fullSpot);
- } # if
-
- /*
- * Prefetch (cache) the spots' image
- */
- if ($this->_prefetch_image) {
- /*
- * If the spot is older than 30 days, and the image is on the web, we do not
- * prefetch the image.
- */
- if (is_array($fullSpot['image']) || ($fullSpot['stamp'] > (int) time()-30*24*60*60)) {
- $this->debug('foreach-loop, getImage(), start. msgId= ' . $msgId);
- $spotsOverview->getImage($fullSpot, $nntp_nzb);
- $this->debug('foreach-loop, getImage(), done. msgId= ' . $msgId);
- } # if
- } # if
-
- /*
- * Prefetch (cache) the spots' NZB file
- */
- if ($this->_prefetch_nzb) {
- /*
- * Only do so if we can expect an NZB file
- */
- if (!empty($fullSpot['nzb']) && $fullSpot['stamp'] > 1290578400) {
- $this->debug('foreach-loop, getNzb(), start. msgId= ' . $msgId);
- $spotsOverview->getNzb($fullSpot, $nntp_nzb);
- $this->debug('foreach-loop, getNzb(), done. msgId= ' . $msgId);
- } # if
- } # if
- }
- catch(ParseSpotXmlException $x) {
- ; # swallow error
- }
- catch(Exception $x) {
- /**
- * Sometimes we get an 'No such article' error for a header we just retrieved,
- * if we want to retrieve the full article. This is messed up, but let's just
- * swallow the error
- */
- if ($x->getCode() == 430) {
- ;
- }
- # if the XML is unparseable, don't bother complaining about it
- elseif ($x->getMessage() == 'String could not be parsed as XML') {
- ;
- } else {
- throw $x;
- } # else
- } # catch
- } # if prefetch image and/or nzb
-
- $this->debug('foreach-loop, done. msgId= ' . $msgCounter);
- } # foreach
-
- if (count($hdrList) > 0) {
- $this->displayStatus("hdrparsed", $hdrsRetrieved);
- $this->displayStatus("fullretrieved", $fullsRetrieved);
- $this->displayStatus("verified", $signedCount);
- $this->displayStatus("modcount", $modCount);
- $this->displayStatus("skipcount", $skipCount);
- $this->displayStatus("loopcount", count($hdrList));
- } else {
- $this->displayStatus("hdrparsed", 0);
- $this->displayStatus("fullretrieved", 0);
- $this->displayStatus("verified", 0);
- $this->displayStatus("modcount", 0);
- $this->displayStatus("skipcount", 0);
- $this->displayStatus("loopcount", 0);
- } # else
-
- /*
- * Add the spots to the database and update the last article
- * number found
- */
- $this->_db->addSpots($spotDbList, $fullSpotDbList);
- $this->debug('added Spots, spotDbList=' . serialize($spotDbList));
- $this->debug('added Spots, fullSpotDbList=' . serialize($fullSpotDbList));
-
- /*
- * Actually act on the moderation settings. We cannot process this inline
- * because a spot can be added and moderated within the same iteration
- */
- switch($this->_settings->get('spot_moderation')) {
- case 'disable' : break;
- case 'markspot' : {
- $this->_db->markCommentsModerated($moderationList);
- $this->_db->markSpotsModerated($moderationList);
-
- break;
- } # case 'markspot'
- default : {
- $this->_db->removeSpots($moderationList);
- $this->_db->removeComments($moderationList);
-
- break;
- } # default
- } # switch
-
- # update the maximum article id
- if ($this->_retro) {
- $this->_db->setMaxArticleid('spots_retro', $endMsg);
- } else {
- $this->_db->setMaxArticleid($this->_server['host'], $endMsg);
- } # if
- $this->debug('loop finished, setMaxArticleId=' . serialize($endMsg));
-
- $this->displayStatus("timer", round(microtime(true) - $timer, 2));
-
- return array('count' => count($hdrList), 'headercount' => $hdrsRetrieved, 'lastmsgid' => $lastProcessedId);
- } # process()
-
- /*
- * returns the name of the group we are expected to retrieve messages from
- */
- function getGroupName() {
- return $this->_settings->get('hdr_group');
- } # getGroupName
-
- /*
- * Highest articleid for the implementation in the database
- */
- function getMaxArticleId() {
- if ($this->_retro) {
- return $this->_db->getMaxArticleid('spots_retro');
- } else {
- return $this->_db->getMaxArticleid($this->_server['host']);
- } # if
- } # getMaxArticleId
-
- /*
- * Returns the highest messageid in the database
- */
- function getMaxMessageId() {
- return $this->_db->getMaxMessageId('headers');
- } # getMaxMessageId
-
-
-} # class SpotRetriever_Spots
+<?php
+class SpotRetriever_Spots extends SpotRetriever_Abs {
+ private $_rsakeys;
+ private $_outputType;
+ private $_retrieveFull;
+ private $_prefetch_image;
+ private $_prefetch_nzb;
+
+ /**
+ * Server is the server array we are expecting to connect to
+ * db - database object
+ */
+ function __construct($server, SpotDb $db, SpotSettings $settings, $outputType, $debug, $retro) {
+ parent::__construct($server, $db, $settings, $debug, $retro);
+
+ $this->_rsakeys = $this->_settings->get('rsa_keys');
+ $this->_outputType = $outputType;
+ $this->_retrieveFull = $this->_settings->get('retrieve_full');
+ $this->_prefetch_image = $this->_settings->get('prefetch_image');
+ $this->_prefetch_nzb = $this->_settings->get('prefetch_nzb');
+ } # ctor
+
+
+ /*
+ * Returns the status in either xml or text format
+ */
+ function displayStatus($cat, $txt) {
+ if ($this->_outputType != 'xml') {
+ switch($cat) {
+ case 'start' : echo "Retrieving new Spots from server " . $txt . "..." . PHP_EOL; break;
+ case 'lastretrieve' : echo strftime("Last retrieve at %c", $txt) . PHP_EOL; break;
+ case 'done' : echo "Finished retrieving spots." . PHP_EOL . PHP_EOL; break;
+ case 'groupmessagecount': echo "Appr. Message count: " . $txt . "" . PHP_EOL; break;
+ case 'firstmsg' : echo "First message number: " . $txt . "" . PHP_EOL; break;
+ case 'lastmsg' : echo "Last message number: " . $txt . "" . PHP_EOL; break;
+ case 'curmsg' : echo "Current message: " . $txt . "" . PHP_EOL; break;
+ case 'progress' : echo "Retrieving " . $txt; break;
+ case 'hdrparsed' : echo " (parsed " . $txt . " headers, "; break;
+ case 'fullretrieved' : echo $txt . " full, "; break;
+ case 'verified' : echo "verified " . $txt . ", "; break;
+ case 'modcount' : echo "moderated " . $txt . ", "; break;
+ case 'skipcount' : echo "skipped " . $txt . " of "; break;
+ case 'loopcount' : echo $txt . " total messages)"; break;
+ case 'timer' : echo " in " . $txt . " seconds" . PHP_EOL; break;
+ case 'totalprocessed' : echo "Processed a total of " . $txt . " spots" . PHP_EOL; break;
+ case 'searchmsgid' : echo "Looking for articlenumber for messageid" . PHP_EOL; break;
+ case '' : echo PHP_EOL; break;
+
+ default : echo $cat . $txt;
+ } # switch
+ } else {
+
+ switch($cat) {
+ case 'start' : echo "<spots>"; break;
+ case 'done' : echo "</spots>"; break;
+ case 'totalprocessed' : echo "<totalprocessed>" . $txt . "</totalprocessed>"; break;
+ case 'skipcount' : echo "<totalskipped> " . $txt . "</totalskipped>"; break;
+ case 'totalremoved' : echo "<totalremoved>" . $txt . "</totalremoved>"; break;
+ default : break;
+ } # switch
+ } # else xmloutput
+ } # displayStatus
+
+ /*
+ * Remove any extraneous reports from the database because we assume
+ * the highest messgeid in the database is the latest on the server.
+ */
+ function updateLastRetrieved($highestMessageId) {
+ $this->debug('Highest messageid found: ' . $highestMessageId);
+
+ /*
+ * Remove any extraneous spots from the database because we assume
+ * the highest messgeid in the database is the latest on the server.
+ *
+ * If the server is marked as buggy, the last 'x' amount of spot are
+ * always checked so we do not have to do this
+ */
+ if (!$this->_server['buggy']) {
+ $this->_db->removeExtraSpots($highestMessageId);
+ } # if
+ } # updateLastRetrieved
+
+ /*
+ * Actually process the retrieved headers from XOVER
+ */
+ function process($hdrList, $curMsg, $endMsg, $timer) {
+ $this->displayStatus("progress", ($curMsg) . " till " . ($endMsg));
+
+ $spotParser = new SpotParser();
+ $signedCount = 0;
+ $hdrsRetrieved = 0;
+ $fullsRetrieved = 0;
+ $msgCounter = 0;
+ $modCount = 0;
+ $skipCount = 0;
+ $lastProcessedId = '';
+ $fullSpotDbList = array();
+ $spotDbList = array();
+ $moderationList = array();
+ $processingStartTime = time();
+
+ /*
+ * Determine the cutoff date (unixtimestamp) from whereon we do not want to
+ * load the spots
+ */
+ if ($this->_settings->get('retention') > 0) {
+ $retentionStamp = time() - ($this->_settings->get('retention') * 24 * 60 * 60);
+ } else {
+ $retentionStamp = 0;
+ } # else
+ $this->debug('retentionStamp=' . $retentionStamp);
+ $this->debug('hdrList=' . serialize($hdrList));
+
+ /**
+ * We ask the database to match our messageid's we just retrieved with
+ * the list of id's we have just retrieved from the server
+ */
+ $dbIdList = $this->_db->matchSpotMessageIds($hdrList);
+
+ $this->debug('dbIdList=' . serialize($dbIdList));
+
+ # if we need to fetch images or nzb files, we need an spotsoverview instance
+ if ($this->_retrieveFull && ($this->_prefetch_image) || ($this->_prefetch_nzb)) {
+ $spotsOverview = new SpotsOverview($this->_db, $this->_settings);
+ $spotsOverview->setActiveRetriever(true);
+
+ /*
+ * Only create a new NZB instance if the server differs from the
+ * header host, else re-use the connection
+ */
+ $settings_nntp_nzb = $this->_settings->get('nntp_nzb');
+ if ($this->_server['host'] == $settings_nntp_nzb['host']) {
+ $nntp_nzb = $this->_spotnntp;
+ } else {
+ $nntp_nzb = new SpotNntp($settings_nntp_nzb);
+ $nntp_nzb->selectGroup($this->_settings->get('nzb_group'));
+ } # else
+ } # if
+
+
+ foreach($hdrList as $msgheader) {
+ $msgCounter++;
+ $this->debug('foreach-loop, start. msgId= ' . $msgCounter);
+
+ /*
+ * Keep te usenet server alive when processing is slow.
+ */
+ if (($processingStartTime - time()) > 30) {
+ $this->_spotnntp->sendNoop();
+ if ((isset($nntp_nzb)) && ($nntp_nzb != $this->_spotnntp)) {
+ $nntp_nzb->sendNoop();
+ } # if
+
+ $processingStartTime = time();
+ } # if
+
+ /*
+ * We keep track whether we actually fetched this header and fullspot
+ * to add it to the database, because only then we can update the
+ * titel from the spots title or rely on our database to fetch
+ * the fullspot
+ */
+ $didFetchHeader = false;
+ $didFetchFullSpot = false;
+
+ # Reset timelimit
+ set_time_limit(120);
+
+ # messageid to check
+ $msgId = substr($msgheader['Message-ID'], 1, -1);
+
+ /*
+ * We prepare some variables to we don't have to perform an array
+ * lookup for each check and the code is easier to read.
+ */
+ $header_isInDb = isset($dbIdList['spot'][$msgId]);
+ $fullspot_isInDb = isset($dbIdList['fullspot'][$msgId]);
+
+ /*
+ * If the spotheader is not yet added to the database, parse the header
+ * information.
+ *
+ * If the header is present, but we don't have the fullspot yet or we are
+ * running in 'retro' mode, parse the header as well because some fields
+ * are only in the header and not in the full.
+ *
+ * We need some of those fields (for example KeyID)
+ */
+ if (!$header_isInDb || ((!$fullspot_isInDb || $this->_retro) && $this->_retrieveFull)) {
+ $hdrsRetrieved++;
+ $this->debug('foreach-loop, parsingXover, start. msgId= ' . $msgCounter);
+ $spot = $spotParser->parseXover($msgheader['Subject'],
+ $msgheader['From'],
+ $msgheader['Date'],
+ $msgheader['Message-ID'],
+ $this->_rsakeys);
+ $this->debug('foreach-loop, parsingXover, done. msgId= ' . $msgCounter);
+
+ /*
+ * When a parse error occured, we ignore the spot, also unverified
+ * spots are ignored
+ */
+ if (($spot === false) || (!$spot['verified'])){
+ continue;
+ } # if
+
+ /*
+ * Special moderator commands always have keyid 2
+ */
+ if ($spot['keyid'] == 2) {
+ $commandAr = explode(' ', strtolower($spot['title']));
+ $validCommands = array('delete', 'dispose', 'remove');
+
+ # is this one of the defined valid commands?
+ if (in_array($commandAr[0], $validCommands) !== false) {
+ $moderationList[] = $commandAr[1];
+ $modCount++;
+ } # if
+
+ } else {
+ /*
+ * Don't add spots older than specified for the retention stamp
+ */
+ if (($retentionStamp > 0) && ($spot['stamp'] < $retentionStamp) && ($this->_settings->get('retentiontype') == 'everything')) {
+ continue;
+ } elseif ($spot['stamp'] < $this->_settings->get('retrieve_newer_than')) {
+ $skipCount++;
+ } else {
+ /*
+ * Do we have the header in the database? If not, lets add it
+ */
+ if (!$header_isInDb) {
+ $spotDbList[] = $spot;
+
+ /*
+ * Some buggy NNTP servers give us the same messageid
+ * in one XOVER statement, hence we update the list of
+ * messageid's we already have retrieved and are ready
+ * to be added to the database
+ */
+ $dbIdList['spot'][$msgId] = 1;
+ $header_isInDb = true;
+ $lastProcessedId = $msgId;
+ $didFetchHeader = true;
+
+ if ($spot['wassigned']) {
+ $signedCount++;
+ } # if
+ } # if
+ } # if
+
+ } # else
+ } else {
+ $lastProcessedId = $msgId;
+ } # else
+
+
+ /*
+ * We don't want to retrieve the fullspot if we don't have the header
+ * in the database. Because we try to add headers in the above code we just have
+ * to check if the header is in the database.
+ *
+ * We cannot collapse this code with the header fetching code because we want to
+ * be able to add the fullspot to a system after all the headers are retrieved
+ */
+ if ($header_isInDb && # header must be in the db
+ !$fullspot_isInDb) # but the fullspot should not
+ {
+ /*
+ * Don't add older fullspots than specified for the retention stamp
+ */
+ if (($retentionStamp > 0) && (strtotime($msgheader['Date']) < $retentionStamp)) {
+ continue;
+ } # if
+
+ if ($this->_retrieveFull) {
+ $fullSpot = array();
+ try {
+ $fullsRetrieved++;
+ $this->debug('foreach-loop, getFullSpot, start. msgId= ' . $msgId);
+ $fullSpot = $this->_spotnntp->getFullSpot($msgId);
+ $this->debug('foreach-loop, getFullSpot, done. msgId= ' . $msgId);
+
+ # add this spot to the database
+ $fullSpotDbList[] = $fullSpot;
+ $fullspot_isInDb = true;
+ $didFetchFullSpot = true;
+
+ /*
+ * Some buggy NNTP servers give us the same messageid
+ * in once XOVER statement, hence we update the list of
+ * messageid's we already have retrieved and are ready
+ * to be added to the database
+ */
+ $dbIdList['fullspot'][$msgId] = 1;
+
+ /*
+ * Overwrite the spots' title because the fullspot contains the title in
+ * UTF-8 format.
+ * We also overwrite the spotterid from the spotsfull because the spotterid
+ * is only in the header in more recent spots.
+ */
+ if ($didFetchHeader) {
+ $spotDbList[count($spotDbList) - 1]['title'] = $fullSpot['title'];
+ $spotDbList[count($spotDbList) - 1]['spotterid'] = $fullSpot['spotterid'];
+ } # if
+ }
+ catch(ParseSpotXmlException $x) {
+ ; # swallow error
+ }
+ catch(Exception $x) {
+ /**
+ * Sometimes we get an 'No such article' error for a header we just retrieved,
+ * if we want to retrieve the full article. This is messed up, but let's just
+ * swallow the error
+ */
+ if ($x->getCode() == 430) {
+ ;
+ }
+ # if the XML is unparseable, don't bother complaining about it
+ elseif ($x->getMessage() == 'String could not be parsed as XML') {
+ ;
+ } else {
+ throw $x;
+ } # else
+ } # catch
+
+ } # if retrievefull
+ } # if fullspot is not in db yet
+
+ if ($this->_retrieveFull && $header_isInDb && ($this->_prefetch_image || $this->_prefetch_nzb)) {
+ try {
+ /*
+ * If we are running in 'retro' mode, it is possible both the header and spot are in the
+ * database already, however -- we need the information from the fullspot so we retrieve it
+ * again
+ */
+ if (!$didFetchFullSpot) {
+ $fullSpot = $this->_db->getFullSpot($msgId, SPOTWEB_ANONYMOUS_USERID);
+ $fullSpot = array_merge($spotParser->parseFull($fullSpot['fullxml']), $fullSpot);
+ } # if
+
+ /*
+ * Prefetch (cache) the spots' image
+ */
+ if ($this->_prefetch_image) {
+ /*
+ * If the spot is older than 30 days, and the image is on the web, we do not
+ * prefetch the image.
+ */
+ if (is_array($fullSpot['image']) || ($fullSpot['stamp'] > (int) time()-30*24*60*60)) {
+ $this->debug('foreach-loop, getImage(), start. msgId= ' . $msgId);
+ $spotsOverview->getImage($fullSpot, $nntp_nzb);
+ $this->debug('foreach-loop, getImage(), done. msgId= ' . $msgId);
+ } # if
+ } # if
+
+ /*
+ * Prefetch (cache) the spots' NZB file
+ */
+ if ($this->_prefetch_nzb) {
+ /*
+ * Only do so if we can expect an NZB file
+ */
+ if (!empty($fullSpot['nzb']) && $fullSpot['stamp'] > 1290578400) {
+ $this->debug('foreach-loop, getNzb(), start. msgId= ' . $msgId);
+ $spotsOverview->getNzb($fullSpot, $nntp_nzb);
+ $this->debug('foreach-loop, getNzb(), done. msgId= ' . $msgId);
+ } # if
+ } # if
+ }
+ catch(ParseSpotXmlException $x) {
+ ; # swallow error
+ }
+ catch(Exception $x) {
+ /**
+ * Sometimes we get an 'No such article' error for a header we just retrieved,
+ * if we want to retrieve the full article. This is messed up, but let's just
+ * swallow the error
+ */
+ if ($x->getCode() == 430) {
+ ;
+ }
+ # if the XML is unparseable, don't bother complaining about it
+ elseif ($x->getMessage() == 'String could not be parsed as XML') {
+ ;
+ } else {
+ throw $x;
+ } # else
+ } # catch
+ } # if prefetch image and/or nzb
+
+ $this->debug('foreach-loop, done. msgId= ' . $msgCounter);
+ } # foreach
+
+ if (count($hdrList) > 0) {
+ $this->displayStatus("hdrparsed", $hdrsRetrieved);
+ $this->displayStatus("fullretrieved", $fullsRetrieved);
+ $this->displayStatus("verified", $signedCount);
+ $this->displayStatus("modcount", $modCount);
+ $this->displayStatus("skipcount", $skipCount);
+ $this->displayStatus("loopcount", count($hdrList));
+ } else {
+ $this->displayStatus("hdrparsed", 0);
+ $this->displayStatus("fullretrieved", 0);
+ $this->displayStatus("verified", 0);
+ $this->displayStatus("modcount", 0);
+ $this->displayStatus("skipcount", 0);
+ $this->displayStatus("loopcount", 0);
+ } # else
+
+ /*
+ * Add the spots to the database and update the last article
+ * number found
+ */
+ $this->_db->addSpots($spotDbList, $fullSpotDbList);
+ $this->debug('added Spots, spotDbList=' . serialize($spotDbList));
+ $this->debug('added Spots, fullSpotDbList=' . serialize($fullSpotDbList));
+
+ /*
+ * Actually act on the moderation settings. We cannot process this inline
+ * because a spot can be added and moderated within the same iteration
+ */
+ switch($this->_settings->get('spot_moderation')) {
+ case 'disable' : break;
+ case 'markspot' : {
+ $this->_db->markCommentsModerated($moderationList);
+ $this->_db->markSpotsModerated($moderationList);
+
+ break;
+ } # case 'markspot'
+ default : {
+ $this->_db->removeSpots($moderationList);
+ $this->_db->removeComments($moderationList);
+