function render() { $spotnntp_hdr = new SpotNntp($this->_settings['nntp_hdr']); # Haal de volledige spotinhoud op $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $fullSpot = $spotsOverview->getFullSpot($this->_messageid, $spotnntp_hdr); # sluit de connectie voor de header, en open een nieuwe connectie voor de nzb $spotnntp_hdr->quit(); $spotnntp_img = new SpotNntp($this->_settings['nntp_nzb']); # # is het een array met een segment nummer naar de image, of is het # een string met de URL naar de image? # if (is_array($fullSpot['image'])) { Header("Content-Type: image/jpeg"); echo $spotnntp_img->getImage($fullSpot['image']['segment']); } else { $x = file_get_contents($fullSpot['image']); foreach ($http_response_header as $hdr) { if (substr($hdr, 0, strlen('Content-Type: ')) == 'Content-Type: ') { header($hdr); } # if } # foreach echo $x; } # else }
function getFilteredSpotCount($filterStr) { parse_str(html_entity_decode($filterStr), $query_params); $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $sqlFilter = $spotsOverview->filterToQuery($query_params['search']); return $this->getSpotCount($sqlFilter); }
function render() { $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $filter = $spotsOverview->filterToQuery($this->_params['search']); # Haal de offset uit de URL en zet deze als startid voor de volgende zoektocht # Als de offset niet in de url staat, zet de waarde als 0, het is de eerste keer # dat de index pagina wordt aangeroepen $pageNr = $this->_params['page']; $nextPage = $pageNr + 1; if ($nextPage == 1) { $prevPage = -1; } else { $prevPage = max($pageNr - 1, 0); } # else # laad de spots $spotsTmp = $spotsOverview->loadSpots($pageNr, $this->_prefs['perpage'], $filter, array('field' => $this->_params['sortby'], 'direction' => $this->_params['sortdir'])); # als er geen volgende pagina is, ook niet tonen if (!$spotsTmp['hasmore']) { $nextPage = -1; } # if # query wanneer de laatste keer de spots geupdate werden $lastUpdateTime = $this->_db->getLastUpdate($this->_settings['nntp_hdr']['host']); # zet de page title $this->_pageTitle = "overzicht"; #- display stuff -# $this->template('header'); $this->template('filters', array('search' => $this->_params['search'], 'lastupdate' => $lastUpdateTime, 'filters' => $this->_settings['filters'], 'activefilter' => $this->_params['search'])); $this->template('spots', array('spots' => $spotsTmp['list'], 'nextPage' => $nextPage, 'prevPage' => $prevPage, 'lastupdate' => $lastUpdateTime, 'activefilter' => $this->_params['search'])); $this->template('footer'); }
function render() { # zet de page title $this->_pageTitle = "watchlist"; # we moeten een messageid opgeven if (empty($this->_messageid) && ($this->_action != 'list')) { throw new Exception("Must give messageid"); } # if # afhankelijk van wat re gekozen is, voer het uit switch($this->_action) { case 'add' : $this->_db->addToWatchList($this->_messageid, ''); break; case 'remove' : $this->_db->removeFromWatchlist($this->_messageid); break; default : ; } # switch # Haal de volledige watchlist op $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $watchList = $spotsOverview->loadWatchList(array('field' => $this->_params['sortby'], 'direction' => $this->_params['sortdir'])); # query wanneer de laatste keer de spots geupdate werden $lastUpdateTime = $this->_db->getLastUpdate($this->_settings['nntp_hdr']['host']); #- display stuff -# $this->template('header'); $this->template('filters', array('search' => array(), 'lastupdate' => $lastUpdateTime, 'filters' => $this->_settings['filters'], 'activefilter' => array())); $this->template('watchlist', array('watchlist' => $watchList, 'action' => $this->_action)); $this->template('footer'); } # render
function render() { SpotTiming::start(__FUNCTION__); # Controleer de users' rechten $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_spots_index, ''); # als een zoekopdracht is meegegevne, moeten er ook rechten zijn om te mogen zoeken if (!empty($this->_params['search'])) { $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_perform_search, ''); } # if $spotsOverview = new SpotsOverview($this->_db, $this->_settings); # Zet the query parameters om naar een lijst met filters, velden, # en sorteringen etc $spotUserSystem = new SpotUserSystem($this->_db, $this->_settings); $parsedSearch = $spotsOverview->filterToQuery($this->_params['search'], array('field' => $this->_params['sortby'], 'direction' => $this->_params['sortdir']), $this->_currentSession, $spotUserSystem->getIndexFilter($this->_currentSession['user']['userid'])); # Haal de offset uit de URL en zet deze als startid voor de volgende zoektocht # Als de offset niet in de url staat, zet de waarde als 0, het is de eerste keer # dat de index pagina wordt aangeroepen $pageNr = $this->_params['pagenr']; $nextPage = $pageNr + 1; if ($nextPage == 1) { $prevPage = -1; } else { $prevPage = max($pageNr - 1, 0); } # else # afhankelijk van wat er gekozen is, voer het uit if (isset($parsedSearch['filterValueList'][0]['fieldname']) && $parsedSearch['filterValueList'][0]['fieldname'] == "Watch") { # Controleer de users' rechten $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_keep_own_watchlist, ''); switch ($this->_action) { case 'remove': $this->_db->removeFromSpotStateList(SpotDb::spotstate_Watch, $this->_params['messageid'], $this->_currentSession['user']['userid']); $spotsNotifications = new SpotNotifications($this->_db, $this->_settings, $this->_currentSession); $spotsNotifications->sendWatchlistHandled($this->_action, $this->_params['messageid']); break; case 'add': $this->_db->addToSpotStateList(SpotDb::spotstate_Watch, $this->_params['messageid'], $this->_currentSession['user']['userid'], ''); $spotsNotifications = new SpotNotifications($this->_db, $this->_settings, $this->_currentSession); $spotsNotifications->sendWatchlistHandled($this->_action, $this->_params['messageid']); break; default: } # switch } # if # laad de spots $spotsTmp = $spotsOverview->loadSpots($this->_currentSession['user']['userid'], $pageNr, $this->_currentSession['user']['prefs']['perpage'], $parsedSearch); # als er geen volgende pagina is, ook niet tonen if (!$spotsTmp['hasmore']) { $nextPage = -1; } # if # zet de page title $this->_pageTitle = "overzicht"; #- display stuff -# $this->template('spots', array('spots' => $spotsTmp['list'], 'quicklinks' => $this->_settings->get('quicklinks'), 'filters' => $this->_db->getFilterList($this->_currentSession['user']['userid'], 'filter'), 'nextPage' => $nextPage, 'prevPage' => $prevPage, 'parsedsearch' => $parsedSearch, 'data' => $this->_params['data'])); SpotTiming::stop(__FUNCTION__); }
function render() { $spotnntp = new SpotNntp($this->_settings['nntp_hdr']); # Haal de volledige spotinhoud op $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $fullSpot = $spotsOverview->getFullSpot($this->_messageid, $spotnntp); $comments = $spotsOverview->getSpotComments($this->_messageid, $spotnntp); # zet de page title $this->_pageTitle = "spot: " . $fullSpot['title']; #- display stuff -# $this->template('spotinfo', array('spot' => $fullSpot, 'comments' => $comments)); }
function render() { # Controleer de users' rechten $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_statistics, ''); # init $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $spotUserSystem = new SpotUserSystem($this->_db, $this->_settings); # zet de page title $this->_pageTitle = _("Statistieken"); #- display stuff -# $parsedSearch = $spotsOverview->filterToQuery('', array('field' => '', 'direction' => ''), $this->_currentSession, $spotUserSystem->getIndexFilter($this->_currentSession['user']['userid'])); $this->template('statistics', array('quicklinks' => $this->_settings->get('quicklinks'), 'filters' => $spotUserSystem->getFilterList($this->_currentSession['user']['userid'], 'filter'), 'parsedsearch' => $parsedSearch, 'limit' => $this->_params['limit'])); }
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[] = array('postcomment_invalidhashcash', array()); } # if # Body mag niet leeg zijn of heel kort $comment['body'] = trim($comment['body']); if (strlen($comment['body']) < 2) { $errorList[] = array('postcomment_bodytooshort', array()); } # if # Rating mag niet uit de range vallen if (($comment['rating'] > 10) || ($comment['rating'] < 0)) { $errorList[] = array('postcomment_ratinginvalid', array()); } # 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[] = array('postcomment_replayattack', array()); } # 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[] = array('postcomment_replayattack', array()); } # if # 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'), $fullSpot['title'], $comment); $this->_db->addPostedComment($user['userid'], $comment); } # if return $errorList; } # postComment
function render() { $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $filter = $spotsOverview->filterToQuery($this->_params['search']); $pageNr = $this->_params['page']; # laad de spots $spotsTmp = $spotsOverview->loadSpots($pageNr, $this->_prefs['perpage'], $filter, array('field' => $this->_params['sortby'], 'direction' => $this->_params['sortdir'])); $fullSpots = array(); $spotnntp = new SpotNntp($this->_settings['nntp_hdr'], $this->_settings['use_openssl']); foreach ($spotsTmp['list'] as $spot) { try { $fullSpots[] = $spotsOverview->getFullSpot($spot['messageid'], $spotnntp); } catch (Exception $x) { // Article not found. ignore. } } $this->template('atom', array('spots' => $fullSpots)); }
function handleNzbAction($messageids, $userSession, $action, $hdr_spotnntp, $nzb_spotnntp) { if (!is_array($messageids)) { $messageids = array($messageids); } # if # Controleer de security $userSession['security']->fatalPermCheck(SpotSecurity::spotsec_retrieve_nzb, ''); if ($action != 'display') { $userSession['security']->fatalPermCheck(SpotSecurity::spotsec_download_integration, $action); } # if # Haal de volledige spot op en gebruik de informatie daarin om de NZB file op te halen $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $nzbList = array(); foreach($messageids as $thisMsgId) { $fullSpot = $spotsOverview->getFullSpot($thisMsgId, $userSession['user']['userid'], $hdr_spotnntp); if (!empty($fullSpot['nzb'])) { $nzbList[] = array('spot' => $fullSpot, 'nzb' => $spotsOverview->getNzb($fullSpot['nzb'], $nzb_spotnntp)); } # if } # foreach # send nzblist to NzbHandler plugin $nzbHandlerFactory = new NzbHandler_Factory(); $nzbHandler = $nzbHandlerFactory->build($this->_settings, $action, $userSession['user']['prefs']['nzbhandling']); $nzbHandler->processNzb($fullSpot, $nzbList); # en voeg hem toe aan de lijst met downloads if ($userSession['user']['prefs']['keep_downloadlist']) { if ($userSession['security']->allowed(SpotSecurity::spotsec_keep_own_downloadlist, '')) { foreach($messageids as $thisMsgId) { $this->_db->addToSpotStateList(SpotDb::spotstate_Down, $thisMsgId, $userSession['user']['userid']); } # foreach } # if } # if # en verstuur een notificatie $spotsNotifications = new SpotNotifications($this->_db, $this->_settings, $userSession); $spotsNotifications->sendNzbHandled($action, $fullSpot); } # handleNzbAction
function handleNzbAction($messageid, $action, $hdr_spotnntp, $nzb_spotnntp) { # Haal de volledige spot op en gebruik de informatie daarin om de NZB file op te halen $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $fullSpot = $spotsOverview->getFullSpot($messageid, $hdr_spotnntp); $nzb = $spotsOverview->getNzb($fullSpot['nzb'], $nzb_spotnntp); # handel dit alles af naar gelang de actie die gekozen is switch ($action) { case 'disable': break; # gewoon nzb file output geven # gewoon nzb file output geven case 'display': Header("Content-Type: application/x-nzb"); Header("Content-Disposition: attachment; filename=\"" . urlencode($fullSpot['title']) . ".nzb\""); echo $nzb; break; # display # Voor deze acties moeten we de NZB file op het FS wegschrijven, dus dan doen we dat # display # Voor deze acties moeten we de NZB file op het FS wegschrijven, dus dan doen we dat case 'save': $this->saveNzbFile($fullSpot, $nzb); break; case 'runcommand': $this->saveNzbFile($fullSpot, $nzb); $this->runCommand($fullSpot); break; # runcommand # runcommand case 'push-sabnzbd': $this->runHttp($fullSpot, $nzb, $action); break; # push-sabnzbd # push-sabnzbd default: throw new Exception("Invalid action: " . $action); } # switch # en voeg hem toe aan de lijst met downloads if ($this->_settings['keep_downloadlist']) { $this->_db->addDownload($fullSpot['messageid']); } # if }
function handleNzbAction($messageids, $action, $hdr_spotnntp, $nzb_spotnntp) { if (!is_array($messageids)) { $messageids = array($messageids); } # if # Haal de volledige spot op en gebruik de informatie daarin om de NZB file op te halen $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $nzbList = array(); foreach($messageids as $thisMsgId) { $fullSpot = $spotsOverview->getFullSpot($thisMsgId, $hdr_spotnntp); $nzbList[] = $spotsOverview->getNzb($fullSpot['nzb'], $nzb_spotnntp); } # foreach # nu we alle nzb files hebben, trekken we de 'file' secties eruit, # en plakken die in onze overkoepelende nzb $nzbXml = simplexml_load_string('<?xml version="1.0" encoding="iso-8859-1" ?> <!DOCTYPE nzb PUBLIC "-//newzBin//DTD NZB 1.0//EN" "http://www.newzbin.com/DTD/nzb/nzb-1.0.dtd"> <nzb xmlns="http://www.newzbin.com/DTD/2003/nzb"></nzb>'); $domNzbXml = dom_import_simplexml($nzbXml); foreach($nzbList as $nzb) { $oneNzbFile = simplexml_load_string($nzb); # add each file section to the larger XML object foreach($oneNzbFile->file as $file) { # Import the file into the larger NZB object $domFile = $domNzbXml->ownerDocument->importNode(dom_import_simplexml($file), TRUE); $domNzbXml->appendChild($domFile); } # foreach } # foreach $nzb = $nzbXml->asXml(); # handel dit alles af naar gelang de actie die gekozen is switch ($action) { case 'disable' : break; # gewoon nzb file output geven case 'display' : { Header("Content-Type: application/x-nzb"); Header("Content-Disposition: attachment; filename=\"" . urlencode($fullSpot['title']) . ".nzb\""); echo $nzb; break; } # display # Voor deze acties moeten we de NZB file op het FS wegschrijven, dus dan doen we dat case 'save' : $this->saveNzbFile($fullSpot, $nzb); break; case 'runcommand' : { $this->saveNzbFile($fullSpot, $nzb); $this->runCommand($fullSpot); break; } # runcommand case 'push-sabnzbd' : { $this->runHttp($fullSpot, $nzb, $action); break; } # push-sabnzbd default : throw new Exception("Invalid action: " . $action); } # switch # en voeg hem toe aan de lijst met downloads if ($this->_settings['keep_downloadlist']) { foreach($messageids as $thisMsgId) { $this->_db->addDownload($thisMsgId); } # foreach } # if } # handleNzbAction
public function filtersToXml($filterList) { $spotsOverview = new SpotsOverview($this->_db, $this->_settings); # Opbouwen XML $doc = new DOMDocument('1.0', 'utf-8'); $doc->formatOutput = true; $mainElm = $doc->createElement('spotwebfilter'); $mainElm->appendChild($doc->createElement('version', '1.0')); $mainElm->appendChild($doc->createElement('generator', 'SpotWeb v' . SPOTWEB_VERSION)); $doc->appendChild($mainElm); $filterListElm = $doc->createElement('filters'); foreach ($filterList as $filter) { $filterElm = $doc->createElement('filter'); $filterElm->appendChild($doc->createElement('id', $filter['id'])); $filterElm->appendChild($doc->createElement('title', $filter['title'])); $filterElm->appendChild($doc->createElement('icon', $filter['icon'])); $filterElm->appendChild($doc->createElement('parent', $filter['tparent'])); $filterElm->appendChild($doc->createElement('order', $filter['torder'])); /* * Voeg nu de boom toe - we krijgen dat als tree aangeleverd maar * we willen die boom graag een beetje klein houden. We comprimeren * dus de boom * * Maar eerst moeten we de tree parseren naar een aparte lijst * categorieen en strongnots */ $dynaList = explode(',', $filter['tree']); list($categoryList, $strongNotList) = $spotsOverview->prepareCategorySelection($dynaList); $treeList = explode(',', $spotsOverview->compressCategorySelection($categoryList, $strongNotList)); $tree = $doc->createElement('tree'); foreach ($treeList as $treeItem) { if (!empty($treeItem)) { # Bepaal wat voor type tree element dit is $treeType = 'include'; if ($treeItem[0] == '~') { $treeType = 'strongnot'; $treeItem = substr($treeItem, 1); } elseif ($treeItem[1] == '!') { $treeType = 'exclude'; $treeItem = substr($treeItem, 1); } # else # Creer nu een tree item $treeElm = $doc->createElement('item', $treeItem); $treeElm->setAttribute('type', $treeType); if (!empty($treeItem)) { $tree->appendChild($treeElm); } # if } # if } # treeItems $filterElm->appendChild($tree); /* * Prepareer de filtervalue list zodat hij bruikbaar is * in de XML hieronder */ $tmpFilterValues = explode('&', $filter['valuelist']); $filterValueList = array(); foreach ($tmpFilterValues as $filterValue) { $tmpFilter = explode(':', urldecode($filterValue)); # maak de daadwerkelijke filter if (count($tmpFilter) >= 3) { $filterValueList[] = array('fieldname' => $tmpFilter[0], 'operator' => $tmpFilter[1], 'value' => join(":", array_slice($tmpFilter, 2))); } # if } # foreach /* * Voeg nu de filter items (text searches e.d. toe) */ if (!empty($filterValueList)) { $valuesElm = $doc->createElement('values'); foreach ($filterValueList as $filterValue) { # Creer nu een tree item $itemElm = $doc->createElement('item'); $itemElm->appendChild($doc->createElement('fieldname', $filterValue['fieldname'])); $itemElm->appendChild($doc->createElement('operator', $filterValue['operator'])); $itemElm->appendChild($doc->createElement('value', $filterValue['value'])); $valuesElm->appendChild($itemElm); } # foreach $filterElm->appendChild($valuesElm); } # if /* * Voeg nu de sort items */ if (!empty($filter['sorton'])) { $sortElm = $doc->createElement('sort'); # Creer nu een tree item $itemElm = $doc->createElement('item'); $itemElm->appendChild($doc->createElement('fieldname', $filter['sorton'])); $itemElm->appendChild($doc->createElement('direction', $filter['sortorder'])); $sortElm->appendChild($itemElm); $filterElm->appendChild($sortElm); } # if $filterListElm->appendChild($filterElm); } # foreach $mainElm->appendChild($filterListElm); return $doc->saveXML(); }
function render() { # Controleer de users' rechten $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_spotdetail, ''); $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_spots_index, ''); $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_rssfeed, ''); $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $nzbhandling = $this->_currentSession['user']['prefs']['nzbhandling']; # we willen niet dat de RSS feed gecached wordt $this->sendExpireHeaders(true); # Zet the query parameters om naar een lijst met filters, velden, # en sorteringen etc $parsedSearch = $spotsOverview->filterToQuery($this->_params['search'], array('field' => $this->_params['sortby'], 'direction' => $this->_params['sortdir']), $this->_currentSession); $this->_params['search'] = $parsedSearch['search']; # laad de spots $pageNr = $this->_params['page']; $spotsTmp = $spotsOverview->loadSpots($this->_currentSession['user']['userid'], $pageNr, $this->_currentSession['user']['prefs']['perpage'], $parsedSearch); # Opbouwen XML $doc = new DOMDocument('1.0', 'utf-8'); $doc->formatOutput = true; $rss = $doc->createElement('rss'); $rss->setAttribute('version', '2.0'); $rss->setAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom'); $doc->appendChild($rss); $atomSelfLink = $doc->createElementNS('http://www.w3.org/2005/Atom', 'atom10:link'); $atomSelfLink->setAttribute('href', html_entity_decode($this->_tplHelper->makeSelfUrl("full"))); $atomSelfLink->setAttribute('rel', 'self'); $atomSelfLink->setAttribute('type', 'application/rss+xml'); $channel = $doc->createElement('channel'); $channel->appendChild($doc->createElement('generator', 'Spotweb v' . SPOTWEB_VERSION)); $channel->appendChild($doc->createElement('language', 'nl')); $channel->appendChild($doc->createElement('title', 'Spotweb')); $channel->appendChild($doc->createElement('description', 'Spotweb RSS Feed')); $channel->appendChild($doc->createElement('link', $this->_tplHelper->makeBaseUrl("full"))); $channel->appendChild($atomSelfLink); $channel->appendChild($doc->createElement('webMaster', $this->_currentSession['user']['mail'] . ' (' . $this->_currentSession['user']['firstname'] . ' ' . $this->_currentSession['user']['lastname'] . ')')); $channel->appendChild($doc->createElement('pubDate', date('r'))); $rss->appendChild($channel); # Fullspots ophalen en aan XML toevoegen foreach($spotsTmp['list'] as $spotHeaders) { try { $spot = $this->_tplHelper->getFullSpot($spotHeaders['messageid'], false); # Normaal is fouten oplossen een beter idee, maar in dit geval is het een bug in de library (?) # Dit voorkomt Notice: Uninitialized string offset: 0 in lib/ubb/TagHandler.inc.php on line 142 # wat een onbruikbare RSS oplevert $spot = @$this->_tplHelper->formatSpot($spot); $title = preg_replace(array('/</', '/>/'), array('<', '>'), $spot['title']); $poster = (empty($spot['userid'])) ? $spot['poster'] : $spot['poster'] . " (" . $spot['userid'] . ")"; $guid = $doc->createElement('guid', $spot['messageid']); $guid->setAttribute('isPermaLink', 'false'); $description = $doc->createElement('description'); $descriptionCdata = $doc->createCDATASection($spot['description'] . '<br /><font color="#ca0000">Door: ' . $poster . '</font>'); $description->appendChild($descriptionCdata); $item = $doc->createElement('item'); $item->appendChild($doc->createElement('title', $title)); $item->appendChild($guid); $item->appendChild($doc->createElement('link', $this->_tplHelper->makeBaseUrl("full") . '?page=getspot&messageid=' . urlencode($spot['messageid']) . $this->_tplHelper->makeApiRequestString())); $item->appendChild($description); $item->appendChild($doc->createElement('author', $spot['messageid'] . ' (' . $poster . ')')); $item->appendChild($doc->createElement('pubDate', date('r', $spot['stamp']))); $item->appendChild($doc->createElement('category', SpotCategories::HeadCat2Desc($spot['category']) . ': ' . SpotCategories::Cat2ShortDesc($spot['category'], $spot['subcata']))); $enclosure = $doc->createElement('enclosure'); $enclosure->setAttribute('url', html_entity_decode($this->_tplHelper->makeNzbUrl($spot))); $enclosure->setAttribute('length', $spot['filesize']); switch ($nzbhandling['prepare_action']) { case 'zip' : $enclosure->setAttribute('type', 'application/zip'); break; default : $enclosure->setAttribute('type', 'application/x-nzb'); } # switch $item->appendChild($enclosure); $channel->appendChild($item); } # try catch(Exception $x) { // Article not found. ignore. } # catch } # foreach # XML output header('Content-Type: application/rss+xml; charset=UTF-8'); echo $doc->saveXML(); } # render()
echo "Whitelist is probably corrupt, skipping" . PHP_EOL; } # else } } catch (Exception $x) { echo "Fatal error occured while updating whitelist:" . PHP_EOL; echo " " . $x->getMessage() . PHP_EOL; echo PHP_EOL . PHP_EOL; echo $x->getTraceAsString(); echo PHP_EOL . PHP_EOL; } } # if ## Statistics if ($settings->get('prepare_statistics') && $newSpotCount > 0) { $spotsOverview = new SpotsOverview($db, $settings); $spotImage = new SpotImage($db); $spotsOverview->setActiveRetriever(true); echo "Starting to create statistics " . PHP_EOL; foreach ($spotImage->getValidStatisticsLimits() as $limitValue => $limitName) { # Reset timelimit set_time_limit(60); foreach ($settings->get('system_languages') as $language => $name) { foreach ($spotImage->getValidStatisticsGraphs() as $graphValue => $graphName) { $spotsOverview->getStatisticsImage($graphValue, $limitValue, $settings_nntp_hdr, $language); } # foreach graph } # foreach language echo "Finished creating statistics " . $limitName . PHP_EOL; }
function getFullSpot($msgId, $markAsRead) { # Controleer de users' rechten $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_spotdetail, ''); $spotnntp = new SpotNntp($this->_settings->get('nntp_hdr')); $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $fullSpot = $spotsOverview->getFullSpot($msgId, $this->_currentSession['user']['userid'], $spotnntp); # seen list if ($markAsRead) { if ($this->_spotSec->allowed(SpotSecurity::spotsec_keep_own_seenlist, '')) { if ($this->_currentSession['user']['prefs']['keep_seenlist']) { if ($fullSpot['seenstamp'] == NULL) { $this->_db->addToSpotStateList(SpotDb::spotstate_Seen, $msgId, $this->_currentSession['user']['userid']); } # if } # if } # if allowed } # if return $fullSpot; } # getFullSpot
function render() { $settings_nntp_hdr = $this->_settings->get('nntp_hdr'); $settings_nntp_nzb = $this->_settings->get('nntp_nzb'); # Check users' permissions $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_spotimage, ''); # Haal de image op if (isset($this->_image['type']) && $this->_image['type'] == 'speeddial') { /* * Because the speeddial image shows stuff like last update and amount of new spots, * we want to make sure this is not a totally closed system */ $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_spots_index, ''); # init $spotImage = new SpotImage($this->_db); $totalSpots = $this->_db->getSpotCount(''); $newSpots = $this->_tplHelper->getNewCountForFilter(''); $lastUpdate = $this->_tplHelper->formatDate($this->_db->getLastUpdate($settings_nntp_hdr['host']), 'lastupdate'); $data = $spotImage->createSpeedDial($totalSpots, $newSpots, $lastUpdate); } elseif (isset($this->_image['type']) && $this->_image['type'] == 'statistics') { $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_statistics, ''); # init $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $graph = isset($this->_image['graph']) ? $this->_image['graph'] : false; $limit = isset($this->_image['limit']) ? $this->_image['limit'] : false; $data = $spotsOverview->getStatisticsImage($graph, $limit, $settings_nntp_hdr, $this->_currentSession['user']['prefs']['user_language']); } elseif (isset($this->_image['type']) && $this->_image['type'] == 'avatar') { # Check users' permissions $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_spotimage, 'avatar'); # init $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $imgDefaults = array('md5' => false, 'size' => 80, 'default' => 'identicon', 'rating' => 'g'); $imgSettings = array_merge($imgDefaults, $this->_image); if ($imgSettings['size'] < 1 || $imgSettings['size'] > 512) { $imgSettings['size'] = $imgDefaults['size']; } # if if (!in_array($imgSettings['default'], array('identicon', 'mm', 'monsterid', 'retro', 'wavatar'))) { $imgSettings['default'] = $imgDefaults['default']; } # if if (!in_array($imgSettings['rating'], array('g', 'pg', 'r', 'x'))) { $imgSettings['rating'] = $imgDefaults['rating']; } # if $data = $spotsOverview->getAvatarImage($imgSettings['md5'], $imgSettings['size'], $imgSettings['default'], $imgSettings['rating']); } else { # init $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $hdr_spotnntp = new SpotNntp($settings_nntp_hdr); /* Als de HDR en de NZB host hetzelfde zijn, zet geen tweede verbinding op */ if ($settings_nntp_hdr['host'] == $settings_nntp_nzb['host']) { $nzb_spotnntp = $hdr_spotnntp; } else { $nzb_spotnntp = new SpotNntp($this->_settings->get('nntp_nzb')); } # else # Haal de volledige spotinhoud op $fullSpot = $this->_tplHelper->getFullSpot($this->_messageid, false); $data = $spotsOverview->getImage($fullSpot, $nzb_spotnntp); } # else # Images mogen gecached worden op de client, behalve als is opgegeven dat het niet mag if (isset($data['expire'])) { $this->sendExpireHeaders(true); } else { $this->sendExpireHeaders(false); } # else header("Content-Type: " . image_type_to_mime_type($data['metadata']['imagetype'])); header("Content-Length: " . strlen($data['content'])); echo $data['content']; }
function search($outputtype) { $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $search = array(); if (($this->_params['t'] == "t" || $this->_params['t'] == "tvsearch") && $this->_params['rid'] != "") { # validate input if (!preg_match('/^[0-9]{1,6}$/', $this->_params['rid'])) { $this->showApiError(201); } # if # fetch remote content $dom = new DomDocument(); $dom->prevservWhiteSpace = false; if (!@$dom->load('http://services.tvrage.com/feeds/showinfo.php?sid=' . $this->_params['rid'] . '/')) { $this->showApiError(300); } # if $showTitle = $dom->getElementsByTagName('showname'); $tvSearch = $showTitle->item(0)->nodeValue; $epSearch = ''; if (preg_match('/^[sS][0-9]{1,2}$/', $this->_params['season']) || preg_match('/^[0-9]{1,2}$/', $this->_params['season'])) { $epSearch = (is_numeric($this->_params['season'])) ? ' AND S' . str_pad($this->_params['season'], 2, "0", STR_PAD_LEFT) : ' AND ' . $this->_params['season']; } elseif ($this->_params['season'] != "") { $this->showApiError(201); } # if if (preg_match('/^[eE][0-9]{1,2}$/', $this->_params['ep']) || preg_match('/^[0-9]{1,2}$/', $this->_params['ep'])) { $episode = (is_numeric($this->_params['ep'])) ? 'E' . str_pad($this->_params['ep'], 2, "0", STR_PAD_LEFT) : $this->_params['ep']; $epSearch .= (!empty($epSearch)) ? $episode : ' AND ' . $episode; } elseif ($this->_params['ep'] != "") { $this->showApiError(201); } # if $search['value'][] = "Titel:" . trim($tvSearch) . $epSearch; } elseif ($this->_params['t'] == "m" || $this->_params['t'] == "movie") { # validate input if ($this->_params['imdbid'] == "") { $this->showApiError(200); } elseif (!preg_match('/^[0-9]{1,8}$/', $this->_params['imdbid'])) { $this->showApiError(201); } # if # fetch remote content if (!@$imdb_content = file_get_contents('http://uk.imdb.com/title/tt' . $this->_params['imdbid'] . '/')) { $this->showApiError(300); } # if preg_match('/<title>(.*?) \(.*?<\/title>/ms', $imdb_content, $movieTitle); $search['value'][] = "Titel:\"" . trim($movieTitle[1]) . "\""; } elseif (!empty($this->_params['q'])) { $search['value'][] = "Titel:" . $this->_params['q']; } # elseif if ($this->_params['maxage'] != "" && is_numeric($this->_params['maxage'])) $search['value'][] = "date:>:-" . $this->_params['maxage'] . "days"; $search['tree'] = $this->nabcat2spotcat($this->_params['cat']); # Spots met een filesize 0 niet opvragen $search['value'][] = "filesize:>:0"; $limit = $this->_currentSession['user']['prefs']['perpage']; if ($this->_params['limit'] != "" && is_numeric($this->_params['limit']) && $this->_params['limit'] < 500) $limit = $this->_params['limit']; $pageNr = ($this->_params['offset'] != "" && is_numeric($this->_params['offset'])) ? $this->_params['offset'] : 0; $offset = $pageNr*$limit; $parsedSearch = $spotsOverview->filterToQuery($search, array('field' => 'stamp', 'direction' => 'DESC'), $this->_currentSession); $spots = $spotsOverview->loadSpots($this->_currentSession['user']['userid'], $pageNr, $limit, $parsedSearch); $this->showResults($spots, $offset, $outputtype); } # search
function categoriesToJson() { /* First parse the search string so we know which items to select and which not */ $spotUserSystem = new SpotUserSystem($this->_db, $this->_settings); $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $parsedSearch = $spotsOverview->filterToQuery($this->_params['search'], array(), $this->_currentSession, $spotUserSystem->getIndexFilter($this->_currentSession['user']['userid'])); if ($this->_params['disallowstrongnot']) { $parsedSearch['strongNotList'] = ''; } # if $compressedCatList = ',' . $spotsOverview->compressCategorySelection($parsedSearch['categoryList'], $parsedSearch['strongNotList']); //error_log($this->_params['search']['tree']); //var_dump($parsedSearch); //var_dump($compressedCatList); //die(); echo "["; $hcatList = array(); foreach (SpotCategories::$_head_categories as $hcat_key => $hcat_val) { # The uer can opt to only show a specific category, if so, skip all others if ($hcat_key != $this->_params['category'] && $this->_params['category'] != '*') { continue; } # if # If the user choose to show only one category, we dont want the category item itself if ($this->_params['category'] == '*') { $hcatTmp = '{"title": "' . $hcat_val . '", "isFolder": true, "key": "cat' . $hcat_key . '", "children": ['; } # if $typeCatDesc = array(); if (isset(SpotCategories::$_categories[$hcat_key]['z'])) { foreach (SpotCategories::$_categories[$hcat_key]['z'] as $type_key => $type_value) { if ($type_key !== 'z' && ($this->_params['subcatz'] == $type_key || $this->_params['subcatz'] == '*')) { # Now determine wether we need to enable the checkbox $isSelected = strpos($compressedCatList, ',cat' . $hcat_key . '_z' . $type_key . ',') !== false ? "true" : "false"; # Is this strongnot? $isStrongNot = strpos($compressedCatList, ',~cat' . $hcat_key . '_z' . $type_key . ',') !== false ? true : false; if ($isStrongNot) { $isStrongNot = '"strongnot": true, "addClass": "strongnotnode", '; $isSelected = 'true'; } else { $isStrongNot = ''; } # if # If the user choose to show only one categortype, we dont want the categorytype item itself if ($this->_params['subcatz'] == '*') { $typeCatTmp = '{"title": "' . $type_value . '", "isFolder": true, ' . $isStrongNot . ' "select": ' . $isSelected . ', "hideCheckbox": false, "key": "cat' . $hcat_key . '_z' . $type_key . '", "unselectable": false, "children": ['; } # if } # if $subcatDesc = array(); foreach (SpotCategories::$_subcat_descriptions[$hcat_key] as $sclist_key => $sclist_desc) { if ($sclist_key !== 'z' && ($this->_params['subcatz'] == $type_key || $this->_params['subcatz'] == '*')) { # We inherit the strongnode from our parent $isStrongNot = strpos($compressedCatList, ',~cat' . $hcat_key . '_z' . $type_key . ',') !== false ? true : false; if ($isStrongNot) { $isStrongNot = '"strongnot": true, "addClass": "strongnotnode", '; $isSelected = 'true'; } else { $isStrongNot = ''; } # if $subcatTmp = '{"title": "' . $sclist_desc . '", "isFolder": true, ' . $isStrongNot . ' "hideCheckbox": true, "key": "cat' . $hcat_key . '_z' . $type_key . '_' . $sclist_key . '", "unselectable": false, "children": ['; # echo ".." . $sclist_desc . " <br>"; $catList = array(); foreach (SpotCategories::$_categories[$hcat_key][$sclist_key] as $key => $valTmp) { if (in_array('z' . $type_key, $valTmp[1])) { $val = $valTmp[0]; if (strlen($val) != 0 && strlen($key) != 0) { # Now determine wether we need to enable the checkbox $isSelected = strpos($compressedCatList, ',cat' . $hcat_key . '_z' . $type_key . '_' . $sclist_key . $key . ',') !== false ? true : false; $parentSelected = strpos($compressedCatList, ',cat' . $hcat_key . '_z' . $type_key . ',') !== false ? true : false; $isSelected = $isSelected || $parentSelected ? 'true' : 'false'; /* * Is this strongnot? */ $isStrongNot = strpos($compressedCatList, ',~cat' . $hcat_key . '_z' . $type_key . ',') !== false ? true : false; if (!$isStrongNot) { $isStrongNot = strpos($compressedCatList, ',~cat' . $hcat_key . '_z' . $type_key . '_' . $sclist_key . $key . ',') !== false ? true : false; } # if if ($isStrongNot) { $isStrongNot = '"strongnot": true, "addClass": "strongnotnode", '; $isSelected = 'true'; } else { $isStrongNot = ''; } # if $catList[] = '{"title": "' . $val . '", "icon": false, "select": ' . $isSelected . ', ' . $isStrongNot . '"key":"' . 'cat' . $hcat_key . '_z' . $type_key . '_' . $sclist_key . $key . '"}'; } # if } # if } # foreach $subcatTmp .= join(",", $catList); $subcatDesc[] = $subcatTmp . "]}"; } # if } # foreach if ($type_key !== 'z') { # If the user choose to show only one categortype, we dont want the categorytype item itself if ($this->_params['subcatz'] == '*') { $typeCatDesc[] = $typeCatTmp . join(",", $subcatDesc) . "]}"; } else { if (!empty($subcatDesc)) { $typeCatDesc[] = join(",", array_filter($subcatDesc)); } # if } # else } else { $typeCatDesc[] = join(",", $subcatDesc); } # else } # foreach } # foreach # If the user choose to show only one category, we dont want the category item itself if ($this->_params['category'] == '*') { $hcatList[] = $hcatTmp . join(",", $typeCatDesc) . "]}"; } else { $hcatList[] = join(",", $typeCatDesc); } # if } # foreach echo join(",", $hcatList); echo "]"; }
function handleNzbAction($messageids, $action, $hdr_spotnntp, $nzb_spotnntp) { if (!is_array($messageids)) { $messageids = array($messageids); } # if # Haal de volledige spot op en gebruik de informatie daarin om de NZB file op te halen $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $nzbList = array(); foreach ($messageids as $thisMsgId) { $fullSpot = $spotsOverview->getFullSpot($thisMsgId, $hdr_spotnntp); if (!empty($fullSpot['nzb'])) { $nzbList[] = array('spot' => $fullSpot, 'nzb' => $spotsOverview->getNzb($fullSpot['nzb'], $nzb_spotnntp)); } # if } # foreach # nu we alle nzb files hebben, trekken we de 'file' secties eruit, # en plakken die in onze overkoepelende nzb switch ($this->_settings['nzbhandling']['prepare_action']) { case 'zip': $nzb = $this->zipNzbList($nzbList); $mimeType = 'application/x-zip-compressed'; $fileName = 'SpotWeb_' . microtime(true) . '.zip'; break; # zip # zip default: $nzb = $this->mergeNzbList($nzbList); $mimeType = 'application/x-nzb'; $fileName = urlencode($fullSpot['title']) . '.nzb'; break; # merge } # switch # handel dit alles af naar gelang de actie die gekozen is switch ($action) { case 'disable': break; # gewoon nzb file output geven # gewoon nzb file output geven case 'display': Header("Content-Type: " . $mimeType); Header("Content-Disposition: attachment; filename=\"" . $fileName . "\""); echo $nzb; break; # display # Voor deze acties moeten we de NZB file op het FS wegschrijven, dus dan doen we dat # display # Voor deze acties moeten we de NZB file op het FS wegschrijven, dus dan doen we dat case 'save': $this->saveNzbFile($fullSpot, $nzb); break; case 'runcommand': $this->saveNzbFile($fullSpot, $nzb); $this->runCommand($fullSpot); break; # runcommand # runcommand case 'push-sabnzbd': $fileParams = array('content' => $nzb, 'name' => $fileName, 'mimetype' => $mimeType); $this->runHttp($fullSpot, $fileParams, $action); break; # push-sabnzbd # push-sabnzbd default: throw new Exception("Invalid action: " . $action); } # switch # en voeg hem toe aan de lijst met downloads if ($this->_settings['keep_downloadlist']) { foreach ($messageids as $thisMsgId) { $this->_db->addDownload($thisMsgId); } # foreach } # if }
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[] = array('postreport_alreadyreported', array()); } # 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[] = array('postcomment_invalidhashcash', array()); } # if # Body mag niet leeg zijn of heel kort $report['body'] = trim($report['body']); if (strlen($report['body']) < 2) { $errorList[] = array('postcomment_bodytooshort', array()); } # 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[] = array('postcomment_replayattack', array()); } # 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[] = array('postcomment_replayattack', array()); } # 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'), $this->_settings->get('report_group'), $report); $this->_db->addPostedReport($user['userid'], $dbReport); } # if return $errorList; }
public function filtersToXml($filterList) { $spotsOverview = new SpotsOverview($this->_db, $this->_settings); # create the XML document $doc = new DOMDocument('1.0', 'utf-8'); $doc->formatOutput = true; $mainElm = $doc->createElement('spotwebfilter'); $mainElm->appendChild($doc->createElement('version', '1.0')); $mainElm->appendChild($doc->createElement('generator', 'SpotWeb v' . SPOTWEB_VERSION)); $doc->appendChild($mainElm); $filterListElm = $doc->createElement('filters'); foreach ($filterList as $filter) { $filterElm = $doc->createElement('filter'); $filterElm->appendChild($doc->createElement('id', $filter['id'])); $filterElm->appendChild($doc->createElement('title', $filter['title'])); $filterElm->appendChild($doc->createElement('icon', $filter['icon'])); $filterElm->appendChild($doc->createElement('parent', $filter['tparent'])); $filterElm->appendChild($doc->createElement('order', $filter['torder'])); $filterElm->appendChild($doc->createElement('enablenotify', $filter['enablenotify'])); /* * Now add the tree. We get the list of filters as a tree, but we * want to keep the XML as clean as possible so we try to compress it. * * First we have to extract the tree to a list of selections, strongnots * and excludes */ $dynaList = explode(',', $filter['tree']); list($categoryList, $strongNotList) = $spotsOverview->prepareCategorySelection($dynaList); $treeList = explode(',', $spotsOverview->compressCategorySelection($categoryList, $strongNotList)); $tree = $doc->createElement('tree'); foreach ($treeList as $treeItem) { if (!empty($treeItem)) { # determine what type of element this is $treeType = 'include'; if ($treeItem[0] == '~') { $treeType = 'strongnot'; $treeItem = substr($treeItem, 1); } elseif ($treeItem[1] == '!') { $treeType = 'exclude'; $treeItem = substr($treeItem, 1); } # else # and create the XML item $treeElm = $doc->createElement('item', $treeItem); $treeElm->setAttribute('type', $treeType); if (!empty($treeItem)) { $tree->appendChild($treeElm); } # if } # if } # treeItems $filterElm->appendChild($tree); /* * Prepareer the filtervalue list to make it usable for the XML */ $tmpFilterValues = explode('&', $filter['valuelist']); $filterValueList = array(); foreach ($tmpFilterValues as $filterValue) { $tmpFilter = explode(':', urldecode($filterValue)); # and create the actual filter if (count($tmpFilter) >= 3) { $filterValueList[] = array('fieldname' => $tmpFilter[0], 'operator' => $tmpFilter[1], 'value' => join(":", array_slice($tmpFilter, 2))); } # if } # foreach /* * Now add the filter items (text searches etc) */ if (!empty($filterValueList)) { $valuesElm = $doc->createElement('values'); foreach ($filterValueList as $filterValue) { # Create the value XML item $itemElm = $doc->createElement('item'); $itemElm->appendChild($doc->createElement('fieldname', $filterValue['fieldname'])); $itemElm->appendChild($doc->createElement('operator', $filterValue['operator'])); $itemElm->appendChild($doc->createElement('value', $filterValue['value'])); $valuesElm->appendChild($itemElm); } # foreach $filterElm->appendChild($valuesElm); } # if /* * Add the sorting items */ if (!empty($filter['sorton'])) { $sortElm = $doc->createElement('sort'); $itemElm = $doc->createElement('item'); $itemElm->appendChild($doc->createElement('fieldname', $filter['sorton'])); $itemElm->appendChild($doc->createElement('direction', $filter['sortorder'])); $sortElm->appendChild($itemElm); $filterElm->appendChild($sortElm); } # if $filterListElm->appendChild($filterElm); } # foreach $mainElm->appendChild($filterListElm); return $doc->saveXML(); }
function search($outputtype) { # Controleer de users' rechten $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_perform_search, ''); $spotsOverview = new SpotsOverview($this->_db, $this->_settings); $search = array(); if (($this->_params['t'] == "t" || $this->_params['t'] == "tvsearch") && $this->_params['rid'] != "") { # validate input if (!preg_match('/^[0-9]{1,6}$/', $this->_params['rid'])) { $this->showApiError(201); } # if # fetch remote content $dom = new DomDocument(); $dom->prevservWhiteSpace = false; if (!@$dom->load('http://services.tvrage.com/feeds/showinfo.php?sid=' . $this->_params['rid'] . '/')) { $this->showApiError(300); } # if $showTitle = $dom->getElementsByTagName('showname'); $tvSearch = $showTitle->item(0)->nodeValue; $epSearch = ''; if (preg_match('/^[sS][0-9]{1,2}$/', $this->_params['season']) || preg_match('/^[0-9]{1,2}$/', $this->_params['season'])) { $epSearch = is_numeric($this->_params['season']) ? 'S' . str_pad($this->_params['season'], 2, "0", STR_PAD_LEFT) : $this->_params['season']; } elseif ($this->_params['season'] != "") { $this->showApiError(201); } # if if (preg_match('/^[eE][0-9]{1,2}$/', $this->_params['ep']) || preg_match('/^[0-9]{1,2}$/', $this->_params['ep'])) { $epSearch .= is_numeric($this->_params['ep']) ? 'E' . str_pad($this->_params['ep'], 2, "0", STR_PAD_LEFT) : $this->_params['ep']; } elseif ($this->_params['ep'] != "") { $this->showApiError(201); } # if $search['value'][] = "Titel:=:" . trim($tvSearch) . " " . $epSearch; } elseif ($this->_params['t'] == "music") { if (empty($this->_params['artist']) && empty($this->_params['cat'])) { $this->_params['cat'] = 3000; } else { $search['value'][] = "Titel:=:\"" . $this->_params['artist'] . "\""; } # if } elseif ($this->_params['t'] == "m" || $this->_params['t'] == "movie") { # validate input if ($this->_params['imdbid'] == "") { $this->showApiError(200); } elseif (!preg_match('/^[0-9]{1,8}$/', $this->_params['imdbid'])) { $this->showApiError(201); } # if # fetch remote content if (!@($imdb_content = file_get_contents('http://uk.imdb.com/title/tt' . $this->_params['imdbid'] . '/'))) { $this->showApiError(300); } # if preg_match('/<h1 class="header" itemprop="name">([^\\<]*)<span>/ms', $imdb_content, $movieTitle); $search['value'][] = "Titel:=:\"" . trim($movieTitle[1]) . "\""; } elseif (!empty($this->_params['q'])) { $searchTerm = str_replace(" ", " +", $this->_params['q']); $search['value'][] = "Titel:=:+" . $searchTerm; } # elseif if ($this->_params['maxage'] != "" && is_numeric($this->_params['maxage'])) { $search['value'][] = "date:>:-" . $this->_params['maxage'] . "days"; } $tmpCat = array(); foreach (explode(",", $this->_params['cat']) as $category) { $tmpCat[] = $this->nabcat2spotcat($category); } # foreach $search['tree'] = implode(",", $tmpCat); # Spots met een filesize 0 niet opvragen $search['value'][] = "filesize:>:0"; $limit = $this->_currentSession['user']['prefs']['perpage']; if ($this->_params['limit'] != "" && is_numeric($this->_params['limit']) && $this->_params['limit'] < 500) { $limit = $this->_params['limit']; } $pageNr = $this->_params['offset'] != "" && is_numeric($this->_params['offset']) ? $this->_params['offset'] : 0; $offset = $pageNr * $limit; $spotUserSystem = new SpotUserSystem($this->_db, $this->_settings); $parsedSearch = $spotsOverview->filterToQuery($search, array('field' => 'stamp', 'direction' => 'DESC'), $this->_currentSession, $spotUserSystem->getIndexFilter($this->_currentSession['user']['userid'])); $spots = $spotsOverview->loadSpots($this->_currentSession['user']['userid'], $pageNr, $limit, $parsedSearch); $this->showResults($spots, $offset, $outputtype); }
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']) { $this->debug('foreach-loop, spot is either false or not verified'); continue; } # if /* * Special moderator commands always have keyid 2 */ if ($spot['keyid'] == 2) { $this->debug('foreach-loop, spot is a moderation spot'); $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]] = 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') { $this->debug('foreach-loop, spot is expired: ' . $spot['stamp']); continue; } elseif ($spot['stamp'] < $this->_settings->get('retrieve_newer_than')) { $this->debug('foreach-loop, spot is too old: ' . $spot['stamp']); $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 && !$fullspot_isInDb) { /* * 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) { } 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) { } 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' # 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); }