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() { # 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'])); }
if ($req->doesExist('apikey')) { /* * To use the Spotweb API we need the actual permission */ $currentSession['security']->fatalPermCheck(SpotSecurity::spotsec_consume_api, ''); /* * but we also need a specific permission, because else things could * be automated which we simply do not want to be automated */ $currentSession['security']->fatalPermCheck(SpotSecurity::spotsec_consume_api, $page); } # if SpotTiming::start('renderpage'); switch ($page) { case 'render': $page = new SpotPage_render($db, $settings, $currentSession, $req->getDef('tplname', ''), array('search' => $req->getDef('search', $spotUserSystem->getIndexFilter($currentSession['user']['userid'])), 'data' => $req->getDef('data', array()), 'messageid' => $req->getDef('messageid', ''), 'pagenr' => $req->getDef('pagenr', 0), 'perpage' => $req->getDef('perpage', 10), 'sortby' => $req->getDef('sortby', ''), 'sortdir' => $req->getDef('sortdir', ''))); $page->render(); break; # render # render case 'getspot': if (strpos($_SERVER['HTTP_USER_AGENT'], "SABnzbd+") === 0) { $page = new SpotPage_getnzb($db, $settings, $currentSession, array('messageid' => $req->getDef('messageid', ''), 'action' => $req->getDef('action', 'display'), 'username' => $req->getDef('username', ''), 'apikey' => $req->getDef('apikey', ''))); } else { $page = new SpotPage_getspot($db, $settings, $currentSession, $req->getDef('messageid', '')); } # else $page->render(); break; # getspot # getspot
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 getIndexFilter() { $spotUser = new SpotUserSystem($this->_db, $this->_settings); return $spotUser->getIndexFilter($this->_currentSession['user']['userid']); }
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 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 $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'])); # 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); } catch (Exception $x) { // Article not found. ignore. } # catch } # foreach # XML output header('Content-Type: application/rss+xml; charset=UTF-8'); echo $doc->saveXML(); }
die("Security settings zijn gewijzigd, draai upgrade-db.php aub" . PHP_EOL); } # if # Nu is het pas veilig rechten te checken op het gebruik van de apikey if ($req->doesExist('apikey')) { # Om de API te mogen gebruiken moet je het algemene consume API recht hebben $currentSession['security']->fatalPermCheck(SpotSecurity::spotsec_consume_api, ''); # maar ook het pagina specifieke, anders zou je bv. "preferences" kunnen wijzigen # met een apikey $currentSession['security']->fatalPermCheck(SpotSecurity::spotsec_consume_api, $page); } # if SpotTiming::start('renderpage'); switch ($page) { case 'render': $page = new SpotPage_render($db, $settings, $currentSession, $req->getDef('tplname', ''), array('search' => $req->getDef('search', $spotUserSystem->getIndexFilter($currentSession['user']['userid'])), 'data' => $req->getDef('data', array()), 'messageid' => $req->getDef('messageid', ''), 'pagenr' => $req->getDef('pagenr', 0), 'sortby' => $req->getDef('sortby', ''), 'sortdir' => $req->getDef('sortdir', ''))); $page->render(); break; # render # render case 'getspot': if (strpos($_SERVER['HTTP_USER_AGENT'], "SABnzbd+") === 0) { $page = new SpotPage_getnzb($db, $settings, $currentSession, array('messageid' => $req->getDef('messageid', ''), 'action' => $req->getDef('action', 'display'), 'username' => $req->getDef('username', ''), 'apikey' => $req->getDef('apikey', ''))); } else { $page = new SpotPage_getspot($db, $settings, $currentSession, $req->getDef('messageid', '')); } # else $page->render(); break; # getspot # getspot