Пример #1
0
 function render()
 {
     # Validate permissions
     $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_statistics, '');
     # init
     $svcUserFilter = new Services_User_Filters($this->_daoFactory, $this->_settings);
     # set the page title
     $this->_pageTitle = _("Statistics");
     #- display stuff -#
     $svcSearchQp = new Services_Search_QueryParser($this->_daoFactory->getConnection());
     $parsedSearch = $svcSearchQp->filterToQuery('', array('field' => '', 'direction' => ''), $this->_currentSession, $svcUserFilter->getIndexFilter($this->_currentSession['user']['userid']));
     $this->template('statistics', array('quicklinks' => $this->_settings->get('quicklinks'), 'filters' => $svcUserFilter->getFilterList($this->_currentSession['user']['userid'], 'filter'), 'parsedsearch' => $parsedSearch, 'limit' => $this->_params['limit']));
 }
Пример #2
0
 /**
  * Search the spotweb database for a specific piece of information
  *
  * @param $outputtype
  */
 function search($outputtype)
 {
     # Check users' permissions
     $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_perform_search, '');
     $searchParams = array();
     /**
      * Now determine what type of information we are searching for using sabnzbd
      */
     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
         /*
          * Actually retrieve the information from TVRage, based on the
          * tvrage passed by the API
          */
         $svcMediaInfoTvrage = new Services_MediaInformation_Tvrage($this->_daoFactory, $this->_settings);
         $svcMediaInfoTvrage->setSearchid($this->_params['rid']);
         $tvRageInfo = $svcMediaInfoTvrage->retrieveInfo();
         if (!$tvRageInfo->isValid()) {
             $this->showApiError(300);
             return;
         }
         # if
         /*
          * Try to parse the season parameter. This can be either in the form of S1, S01, 1, 2012, etc.
          * we try to standardize all these types of season definitions into one format.
          */
         $episodeSearch = '';
         $seasonSearch = '';
         if (preg_match('/^[sS][0-9]{1,2}$/', $this->_params['season']) || preg_match('/^[0-9]{1,4}$/', $this->_params['season'])) {
             /*
              * Did we get passed a 4 digit season (most likely a year), or a
              * two digit season?
              */
             if (strlen($this->_params['season']) < 3) {
                 if (is_numeric($this->_params['season'])) {
                     $seasonSearch = 'S' . str_pad($this->_params['season'], 2, "0", STR_PAD_LEFT);
                 } else {
                     $seasonSearch = $this->_params['season'];
                 }
                 # else
             } else {
                 $seasonSearch = $this->_params['season'] . ' ';
             }
             # else
         } elseif ($this->_params['season'] != "") {
             $this->showApiError(201);
             return;
         }
         # if
         /*
          * And try to add an episode parameter, basically the same set of rules
          * as for the season
          */
         if (preg_match('/^[eE][0-9]{1,2}$/', $this->_params['ep']) || preg_match('/^[0-9]{1,2}$/', $this->_params['ep']) || preg_match('/^[0-9]{1,2}\\/[0-9]{1,2}$/', $this->_params['ep'])) {
             if (is_numeric($this->_params['ep'])) {
                 $episodeSearch .= 'E' . str_pad($this->_params['ep'], 2, "0", STR_PAD_LEFT);
             } else {
                 $episodeSearch .= $this->_params['ep'];
             }
             # else
         } elseif ($this->_params['ep'] != "") {
             $this->showApiError(201);
             return;
         } else {
             // Complete season search, add wildcard character to season
             $seasonSearch .= '*';
             // and search for the text 'Season ' ...
             $searchParams['value'][] = "Titel:=:OR:+\"" . $tvRageInfo->getTitle() . "\" +\"Season " . (int) $this->_params['season'] . "\"";
         }
         # else
         /*
          * The + operator is supported both by PostgreSQL and MySQL's FTS
          *
          * We search both for S04E17 and S04 E17 (with a space)
          */
         $searchParams['value'][] = "Titel:=:OR:+\"" . $tvRageInfo->getTitle() . "\" +" . $seasonSearch . $episodeSearch;
         if (!empty($episodeSearch)) {
             $searchParams['value'][] = "Titel:=:OR:+\"" . $tvRageInfo->getTitle() . "\" +" . $seasonSearch . ' +' . $episodeSearch;
         }
         # if
     } elseif ($this->_params['t'] == "music") {
         if (empty($this->_params['artist']) && empty($this->_params['cat'])) {
             $this->_params['cat'] = 3000;
         } else {
             $searchParams['value'][] = "Titel:=:DEF:\"" . $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
         /*
          * Actually retrieve the information from imdb, based on the
          * imdbid passed by the API
          */
         $svcMediaInfoImdb = new Services_MediaInformation_Imdb($this->_daoFactory, $this->_settings);
         $svcMediaInfoImdb->setSearchid($this->_params['imdbid']);
         $imdbInfo = $svcMediaInfoImdb->retrieveInfo();
         if (!$imdbInfo->isValid()) {
             $this->showApiError(300);
             return;
         }
         # if
         /* Extract the release date from the IMDB info page */
         if ($imdbInfo->getReleaseYear() != null) {
             $movieReleaseDate = '+(' . $imdbInfo->getReleaseYear() . ')';
         } else {
             $movieReleaseDate = '';
         }
         # else
         /*
          * Add movie title to the query
          */
         $searchParams['value'][] = "Titel:=:OR:+\"" . $imdbInfo->getTitle() . "\" " . $movieReleaseDate;
         // imdb sometimes returns the title translated, if so, pass the original title as well
         if ($imdbInfo->getAlternateTitle() != null) {
             $searchParams['value'][] = "Title:=:OR:+\"" . $imdbInfo->getAlternateTitle() . "\" " . $movieReleaseDate;
         }
         # if
     } elseif (!empty($this->_params['q'])) {
         $searchTerm = str_replace(" ", " +", $this->_params['q']);
         $searchParams['value'][] = "Titel:=:OR:+" . $searchTerm;
     }
     # elseif
     /*
      * When a user added a maximum age for queries, convert it to
      * a Spotweb query as well
      */
     if ($this->_params['maxage'] != "" && is_numeric($this->_params['maxage'])) {
         $searchParams['value'][] = "date:>:DEF:-" . $this->_params['maxage'] . "days";
     }
     # if
     /*
      * We combine the "newznabapi" categories, with a custom extension for
      * categories so we can filter deeper than the newznab API can per default
      */
     $tmpCat = array();
     foreach (explode(",", $this->_params['cat']) as $category) {
         $tmpCat[] = $this->nabcat2spotcat($category);
     }
     # foreach
     $searchParams['tree'] = implode(",", $tmpCat) . ',' . $this->_params['spotcat'];
     /*
      * Do not retrieve spots with a filesize of zero (these are very old spots,
      * which have no NZB linked to it) as they are useless for a API consumer
      */
     $searchParams['value'][] = "filesize:>:DEF:0";
     /*
      * Gather the preference of the results per page and use it in this
      * system as well when no value is explicitly provided
      */
     if (!empty($this->_params['limit']) && is_numeric($this->_params['limit']) && $this->_params['limit'] < 500) {
         $limit = $this->_params['limit'];
     } else {
         $limit = $this->_currentSession['user']['prefs']['perpage'];
     }
     # else
     if (!empty($this->_params['offset']) && is_numeric($this->_params['offset'])) {
         $pageNr = $this->_params['offset'];
     } else {
         $pageNr = 0;
     }
     # else
     /*
      * We get a bunch of query parameters, so now change this to the actual
      * search query the user requested including the required sorting
      */
     $svcUserFilter = new Services_User_Filters($this->_daoFactory, $this->_settings);
     $svcSearchQp = new Services_Search_QueryParser($this->_daoFactory->getConnection());
     $parsedSearch = $svcSearchQp->filterToQuery($searchParams, array('field' => 'stamp', 'direction' => 'DESC'), $this->_currentSession, $svcUserFilter->getIndexFilter($this->_currentSession['user']['userid']));
     /*
      * Actually fetch the spots, we always perform
      * this action even when the watchlist is editted
      */
     $svcProvSpotList = new Services_Providers_SpotList($this->_daoFactory->getSpotDao());
     $spotsTmp = $svcProvSpotList->fetchSpotList($this->_currentSession['user']['userid'], $pageNr, $limit, $parsedSearch);
     $this->showResults($spotsTmp, $pageNr * $limit, $outputtype);
 }
Пример #3
0
 function render()
 {
     # Make sure the proper permissions are met
     $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_spotdetail, '');
     $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_spots_index, '');
     $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_rssfeed, '');
     $nzbhandling = $this->_currentSession['user']['prefs']['nzbhandling'];
     # Don't allow the RSS feed to be cached
     $this->sendExpireHeaders(true);
     /*
      * Transform the query parameters to a list of filters, fields, 
      * sortings, etc.
      */
     $svcUserFilter = new Services_User_Filters($this->_daoFactory, $this->_settings);
     $svcSearchQp = new Services_Search_QueryParser($this->_daoFactory->getConnection());
     $parsedSearch = $svcSearchQp->filterToQuery($this->_params['search'], array('field' => $this->_params['sortby'], 'direction' => $this->_params['sortdir']), $this->_currentSession, $svcUserFilter->getIndexFilter($this->_currentSession['user']['userid']));
     /* 
      * Actually fetch the spots
      */
     $pageNr = $this->_params['page'];
     $svcProvSpotList = new Services_Providers_SpotList($this->_daoFactory->getSpotDao());
     $spotsTmp = $svcProvSpotList->fetchSpotList($this->_currentSession['user']['userid'], $pageNr, $this->_currentSession['user']['prefs']['perpage'], $parsedSearch);
     # Create an XML document for RSS
     $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);
     # Retrieve full spots so we can show images for spots etc.
     foreach ($spotsTmp['list'] as $spotHeaders) {
         try {
             $spot = $this->_tplHelper->getFullSpot($spotHeaders['messageid'], false);
             /*
              * We supress the error by using this ugly operator simply because the library
              * sometimes gives an notice and we cannot be bothered to fix it, but it does
              * give an incorrect and unusable RSS feed
              */
             $spot = @$this->_tplHelper->formatSpot($spot);
             $title = str_replace(array('<', '>', '&'), array('&#x3C;', '&#x3E;', '&amp;'), $spot['title']);
             $poster = empty($spot['spotterid']) ? $spot['poster'] : $spot['poster'] . " (" . $spot['spotterid'] . ")";
             $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&amp;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
     # Output XML
     $this->sendContentTypeHeader('rss');
     echo $doc->saveXML();
 }
Пример #4
0
 function render()
 {
     $result = new Dto_FormResult('notsubmitted');
     # Make sure the user has the appropriate rights
     $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_keep_own_filters, '');
     # Instantiate the SpotUser system
     $svcUserFilter = new Services_User_Filters($this->_daoFactory, $this->_settings);
     $spotFilter = $svcUserFilter->getFilter($this->_currentSession['user']['userid'], $this->_filterId);
     # set the page title
     $this->_pageTitle = "spot: filters";
     /*
      * bring the forms' action into the local scope for 
      * easier access
      */
     $formAction = $this->_editFilterForm['action'];
     # Are we submitting this form, or just rendering it?
     if (!empty($formAction)) {
         switch ($formAction) {
             case 'removefilter':
                 $result = $svcUserFilter->removeFilter($this->_currentSession['user']['userid'], $this->_filterId);
                 break;
                 # case 'removefilter'
             # case 'removefilter'
             case 'discardfilters':
                 $result = $svcUserFilter->resetFilterList($this->_currentSession['user']['userid']);
                 break;
                 # case 'discardfilters'
             # case 'discardfilters'
             case 'setfiltersasdefault':
                 $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_set_filters_as_default, '');
                 $result = $svcUserFilter->setFiltersAsDefault($this->_currentSession['user']['userid']);
                 break;
                 # case 'setfiltersasdefault'
             # case 'setfiltersasdefault'
             case 'exportfilters':
                 $result = $svcUserFilter->filtersToXml($svcUserFilter->getPlainFilterList($this->_currentSession['user']['userid'], 'filter'));
                 break;
                 # case 'exportfilters'
             # case 'exportfilters'
             case 'importfilters':
                 $uploadHandler = new Services_Providers_FileUpload('editfilterform', 'filterimport');
                 if ($uploadHandler->isUploaded()) {
                     if ($uploadHandler->success()) {
                         try {
                             $xml = file_get_contents($uploadHandler->getTempName());
                             $filterList = $svcUserFilter->xmlToFilters($xml);
                             $svcUserFilter->setFilterList($this->_currentSession['user']['userid'], $filterList->getData('filters'));
                         } catch (Exception $x) {
                             $result->addError(_('Uploaded Spotwebfilter in invalid'));
                         }
                         # catch
                     } else {
                         $result->addError(sprintf(_('Error while uploading filter (%s)', $uploadHandler->errorText())));
                     }
                     # else
                 } else {
                     $result->addError(_("Filter hasn't been uploaded"));
                 }
                 # else
                 break;
                 # case 'importfilters'
             # case 'importfilters'
             case 'addfilter':
                 # Create a new filter record, we will always add the filter to the root with no children
                 $filter = $this->_editFilterForm;
                 $filter['valuelist'] = explode('&', $filter['valuelist']);
                 $filter['torder'] = 999;
                 $filter['tparent'] = 0;
                 $filter['children'] = array();
                 $filter['filtertype'] = 'filter';
                 $filter['enablenotify'] = isset($filter['enablenotify']) ? true : false;
                 # and actually add the filter
                 $result = $svcUserFilter->addFilter($this->_currentSession['user']['userid'], $filter);
                 break;
                 # case 'addfilter'
             # case 'addfilter'
             case 'reorder':
                 /*
                  * The nestedSortable jquery widget will not pass an explicit sorting, we
                  * add it ourselves using the order of the elements we are given
                  */
                 $result = $svcUserFilter->reorderFilters($this->_currentSession['user']['userid'], $this->_orderList);
                 break;
                 # case 'reorder'
             # case 'reorder'
             case 'changefilter':
                 # Retrieve the filter we want to edit
                 $this->_editFilterForm['id'] = $this->_filterId;
                 $this->_editFilterForm['enablenotify'] = isset($this->_editFilterForm['enablenotify']) ? true : false;
                 $result = $svcUserFilter->changeFilter($this->_currentSession['user']['userid'], $this->_editFilterForm);
                 break;
                 # case 'changefilter'
         }
         # switch
     }
     # if
     #- display stuff -#
     $this->template('editfilter', array('filter' => $spotFilter, 'sorton' => $this->_sorton, 'sortorder' => $this->_sortorder, 'sortby' => $this->_sorton, 'sortdir' => $this->_sortorder, 'lastformaction' => $formAction, 'result' => $result, 'data' => $this->_data, 'http_referer' => $this->_editFilterForm['http_referer']));
 }
Пример #5
0
         $page->render();
         break;
         # twitteroauth
     # twitteroauth
     case 'statistics':
         $page = new SpotPage_statistics($daoFactory, $settings, $currentSession, array('limit' => $req->getDef('limit', '')));
         $page->render();
         break;
         # statistics
     # statistics
     default:
         SpotTiming::start('renderpage->case-default');
         if (@$_SERVER['HTTP_X_PURPOSE'] == 'preview') {
             $page = new SpotPage_getimage($daoFactory, $settings, $currentSession, array('messageid' => $req->getDef('messageid', ''), 'image' => array('type' => 'speeddial')));
         } else {
             $svcUserFilters = new Services_User_Filters($daoFactory, $settings);
             $page = new SpotPage_index($daoFactory, $settings, $currentSession, array('search' => $req->getDef('search', $svcUserFilters->getIndexFilter($currentSession['user']['userid'])), 'pagenr' => $req->getDef('pagenr', 0), 'sortby' => $req->getDef('sortby', ''), 'sortdir' => $req->getDef('sortdir', ''), 'messageid' => $req->getDef('messageid', ''), 'action' => $req->getDef('action', ''), 'data' => $req->getDef('data', array())));
         }
         # if
         SpotTiming::stop('renderpage->case-default');
         $page->render();
         break;
         # default
 }
 # switch
 SpotTiming::stop('renderpage');
 # timing
 SpotTiming::stop('total');
 # enable or disable timer
 if ($settings->get('enable_timing') && !in_array($req->getDef('page', ''), array('catsjson', 'statics', 'getnzb', 'getnzbmobile', 'markallasread'))) {
     SpotTiming::display();
Пример #6
0
 function getIndexFilter()
 {
     $svcUserFilter = new Services_User_Filters($this->_daoFactory, $this->_settings);
     return $svcUserFilter->getIndexFilter($this->_currentSession['user']['userid']);
 }
Пример #7
0
 function render()
 {
     SpotTiming::start(__CLASS__ . '::' . __FUNCTION__);
     # Give an page title
     $this->_pageTitle = _("overview");
     /* 
      * Make sure the user has the appropriate permissions
      */
     $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_spots_index, '');
     /*
      * When the user wants to perform a search, it needs specific search rights
      * as well
      */
     if (!empty($this->_params['search'])) {
         $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_perform_search, '');
     }
     # if
     /*
      * We get a bunch of query parameters, so now change this to the actual
      * search query the user requested including the required sorting
      */
     $svcUserFilter = new Services_User_Filters($this->_daoFactory, $this->_settings);
     $svcSearchQp = new Services_Search_QueryParser($this->_daoFactory->getConnection());
     $parsedSearch = $svcSearchQp->filterToQuery($this->_params['search'], array('field' => $this->_params['sortby'], 'direction' => $this->_params['sortdir']), $this->_currentSession, $svcUserFilter->getIndexFilter($this->_currentSession['user']['userid']));
     /*
      * If any specific action was chosen, we perform that as well
      */
     if (isset($parsedSearch['filterValueList'][0]['fieldname']) && $parsedSearch['filterValueList'][0]['fieldname'] == "Watch") {
         # Make sure the appropriate permissions are set
         $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_keep_own_watchlist, '');
         $svcSpotStateListDao = new Services_Actions_SpotStateList($this->_daoFactory->getSpotStateListDao());
         switch ($this->_action) {
             case 'remove':
                 $svcSpotStateListDao->removeFromWatchList($this->_params['messageid'], $this->_currentSession['user']['userid']);
                 $spotsNotifications = new SpotNotifications($this->_daoFactory, $this->_settings, $this->_currentSession);
                 $spotsNotifications->sendWatchlistHandled($this->_action, $this->_params['messageid']);
                 break;
             case 'add':
                 $svcSpotStateListDao->addToWatchList($this->_params['messageid'], $this->_currentSession['user']['userid']);
                 $spotsNotifications = new SpotNotifications($this->_daoFactory, $this->_settings, $this->_currentSession);
                 $spotsNotifications->sendWatchlistHandled($this->_action, $this->_params['messageid']);
                 break;
             default:
         }
         # switch
     }
     # if
     /*
      * Get the offset from the URL, if none given, we default to zero
      */
     $pageNr = $this->_params['pagenr'];
     /* 
      * Actually fetch the spots, we always perform
      * this action even when the watchlist is editted
      */
     $svcProvSpotList = new Services_Providers_SpotList($this->_daoFactory->getSpotDao());
     $spotsTmp = $svcProvSpotList->fetchSpotList($this->_currentSession['user']['userid'], $pageNr, $this->_currentSession['user']['prefs']['perpage'], $parsedSearch);
     /*
      * If we are on the first page, we want to pass '-1' as the previous page,
      * so the templates can deduce we are on the first page.
      *
      * If there are no more spots, make sure we don't show
      * the nextpage link
      */
     if ($spotsTmp['hasmore']) {
         $nextPage = $pageNr + 1;
     } else {
         $nextPage = -1;
     }
     # else
     $prevPage = max($pageNr - 1, -1);
     #- display stuff -#
     $this->template('spots', array('spots' => $spotsTmp['list'], 'quicklinks' => $this->_settings->get('quicklinks'), 'filters' => $svcUserFilter->getFilterList($this->_currentSession['user']['userid'], 'filter'), 'nextPage' => $nextPage, 'prevPage' => $prevPage, 'parsedsearch' => $parsedSearch, 'data' => $this->_params['data']));
     SpotTiming::stop(__CLASS__ . '::' . __FUNCTION__);
 }
Пример #8
0
 function categoriesToJson()
 {
     /*
      * Don't allow the tree to be cached, it contains the current state of the
      * tree
      */
     $this->sendExpireHeaders(true);
     /* First parse the search string so we know which items to select and which not */
     $svcUserFilter = new Services_User_Filters($this->_daoFactory, $this->_settings);
     $svcSearchQp = new Services_Search_QueryParser($this->_daoFactory->getConnection());
     $parsedSearch = $svcSearchQp->filterToQuery($this->_params['search'], array(), $this->_currentSession, $svcUserFilter->getIndexFilter($this->_currentSession['user']['userid']));
     if ($this->_params['disallowstrongnot']) {
         $parsedSearch['strongNotList'] = '';
     }
     # if
     $compressedCatList = ',' . $svcSearchQp->compressCategorySelection($parsedSearch['categoryList'], $parsedSearch['strongNotList']);
     //error_log($this->_params['search']['tree']);
     //var_dump($parsedSearch);
     //var_dump($compressedCatList);
     //die();
     echo "[";
     $hcatList = array();
     $typeCatTmp = '';
     $hcatTmp = '';
     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 whether 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", ';
                         } 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) {
                             //error_log($hcat_key . ' => ' . $sclist_key . ' ==:: ' . $key);
                             if (in_array('z' . $type_key, $valTmp[2])) {
                                 $val = $valTmp[0];
                                 if (strlen($val) != 0 && strlen($key) != 0) {
                                     # Now determine whether 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 "]";
 }