예제 #1
0
 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 "]";
 }
예제 #2
0
 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();
 }
예제 #3
0
 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();
 }