} catch (Exception $x) { echo "Fatal error occured while updating blacklist:" . PHP_EOL; echo " " . $x->getMessage() . PHP_EOL; echo PHP_EOL . PHP_EOL; echo $x->getTraceAsString(); echo PHP_EOL . PHP_EOL; } } # if ## External whitelist $settings_external_whitelist = $settings->get('external_whitelist'); if ($settings_external_whitelist) { try { $spotsOverview = new SpotsOverview($db, $settings); # haal de whitelist op list($http_code, $whitelist) = $spotsOverview->getFromWeb($settings->get('whitelist_url'), false, 30 * 60); if ($http_code == 304) { echo "Whitelist not modified, no need to update" . PHP_EOL; } elseif (strpos($whitelist['content'], ">")) { echo "Error, whitelist does not have expected layout!" . PHP_EOL; } else { # update de whitelist $whitelistarray = explode(chr(10), $whitelist['content']); # Perform a very small snaity check on the whitelist if (count($whitelistarray) > 5 && strlen($whitelistarray[0]) < 10) { $updatewhitelist = $db->updateExternallist($whitelistarray, SpotDb::spotterlist_White); echo "Finished updating whitelist. Added " . $updatewhitelist['added'] . ", removed " . $updatewhitelist['removed'] . ", skipped " . $updatewhitelist['skipped'] . " of " . count($whitelistarray) . " lines." . PHP_EOL; } else { echo "Whitelist is probably corrupt, skipping" . PHP_EOL; } # else
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); return; } # if # fetch remote content $dom = new DomDocument(); $dom->prevservWhiteSpace = false; if (!@(list($http_code, $tvrage) = $spotsOverview->getFromWeb('http://services.tvrage.com/feeds/showinfo.php?sid=' . $this->_params['rid'], false, 24 * 60 * 60))) { $this->showApiError(300); return; } # if $dom->loadXML($tvrage['content']); $showTitle = $dom->getElementsByTagName('showname'); # TVRage geeft geen 404 indien niet gevonden, dus vangen we dat zelf netjes op if (!@$showTitle->item(0)->nodeValue) { $this->showApiError(300); return; } # if $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); return; } # 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); return; } # 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); return; } elseif (!preg_match('/^[0-9]{1,8}$/', $this->_params['imdbid'])) { $this->showApiError(201); return; } # if # fetch remote content if (!@(list($http_code, $imdb) = $spotsOverview->getFromWeb('http://uk.imdb.com/title/tt' . $this->_params['imdbid'] . '/', false, 24 * 60 * 60))) { $this->showApiError(300); return; } # 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); }