/** * initialize category related vars and add subcategories to the category selection * * @return void */ function initCategoryVars() { $storagePid = FALSE; if ($this->confArr['useStoragePid']) { $sParr = $this->tsfe->getStorageSiterootPids(); $storagePid = $sParr['_STORAGE_PID']; } $lc = $this->conf['displayCatMenu.']; if ($this->theCode == 'CATMENU') { // init catPidList $catPl = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'pages', 's_misc'); $catPl = $catPl ? $catPl : $this->cObj->stdWrap($lc['catPidList'], $lc['catPidList.']); $catPl = implode(',', t3lib_div::intExplode(',', $catPl)); $recursive = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'recursive', 's_misc'); if (!strcmp($recursive, '') || $recursive === NULL) { $recursive = $this->cObj->stdWrap($lc['recursive'], $lc['recursive.']); } if ($catPl) { $storagePid = $this->pi_getPidList($catPl, $recursive); } } if ($storagePid) { $this->SPaddWhere = ' AND tt_news_cat.pid IN (' . $storagePid . ')'; } if ($this->conf['catExcludeList']) { $this->SPaddWhere .= ' AND tt_news_cat.uid NOT IN (' . $this->conf['catExcludeList'] . ')'; } $this->enableCatFields = $this->getEnableFields('tt_news_cat'); $addWhere = $this->SPaddWhere . $this->enableCatFields; $useSubCategories = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'useSubCategories', 'sDEF'); $this->config['useSubCategories'] = strcmp($useSubCategories, '') ? $useSubCategories : $this->conf['useSubCategories']; // global ordering for categories, Can be overwritten later by catOrderBy for a certain content element $catOrderBy = trim($this->conf['catOrderBy']); $this->config['catOrderBy'] = $catOrderBy ? $catOrderBy : 'sorting'; // categoryModes are: 0=display all categories, 1=display selected categories, -1=display deselected categories $categoryMode = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'categoryMode', 'sDEF'); $this->config['categoryMode'] = $categoryMode ? $categoryMode : intval($this->conf['categoryMode']); // catselection holds only the uids of the categories selected by GETvars if ($this->piVars['cat']) { // catselection holds only the uids of the categories selected by GETvars $this->config['catSelection'] = $this->hObj->checkRecords($this->piVars['cat']); $this->piVars_catSelection = $this->config['catSelection']; if ($this->config['useSubCategories'] && $this->config['catSelection']) { // get subcategories for selection from getVars $subcats = tx_ttnews_div::getSubCategories($this->config['catSelection'], $addWhere); $this->config['catSelection'] = implode(',', array_unique(explode(',', $this->config['catSelection'] . ($subcats ? ',' . $subcats : '')))); } } $catExclusive = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], 'categorySelection', 'sDEF'); $catExclusive = $catExclusive ? $catExclusive : trim($this->cObj->stdWrap($this->conf['categorySelection'], $this->conf['categorySelection.'])); $this->catExclusive = $this->config['categoryMode'] ? $catExclusive : 0; // ignore cat selection if categoryMode isn't set $this->catExclusive = $this->hObj->checkRecords($this->catExclusive); // store the actually selected categories because we need them for the comparison in categoryMode 2 and -2 $this->actuallySelectedCategories = $this->catExclusive; // get subcategories if ($this->config['useSubCategories'] && $this->catExclusive) { $subcats = tx_ttnews_div::getSubCategories($this->catExclusive, $addWhere); $this->catExclusive = implode(',', array_unique(explode(',', $this->catExclusive . ($subcats ? ',' . $subcats : '')))); } // get more category fields from FF or TS $fields = explode(',', 'catImageMode,catTextMode,catImageMaxWidth,catImageMaxHeight,maxCatImages,catTextLength,maxCatTexts'); foreach ($fields as $key) { $value = $this->pi_getFFvalue($this->cObj->data['pi_flexform'], $key, 's_category'); $this->config[$key] = is_numeric($value) ? $value : $this->conf[$key]; } }
/** * extends a given list of categories by their subcategories * * @param string $catlist: list of categories which will be extended by subcategories * @param integer $cc: counter to detect recursion in nested categories * @return string extended $catlist */ function getSubCategories($catlist, $addWhere = '', $cc = 0) { if (!$catlist) { t3lib_div::devLog('EMPTY $catlist (' . __CLASS__ . '::' . __FUNCTION__ . ')', 'tt_news', 3, array()); } $sCatArr = array(); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', 'tt_news_cat', 'tt_news_cat.parent_category IN (' . $catlist . ') AND deleted=0 ' . $addWhere); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $cc++; if ($cc > 10000) { $GLOBALS['TT']->setTSlogMessage('tt_news: one or more recursive categories where found'); return implode(',', $sCatArr); } $subcats = tx_ttnews_div::getSubCategories($row['uid'], $addWhere, $cc); $subcats = $subcats ? ',' . $subcats : ''; $sCatArr[] = $row['uid'] . $subcats; } $GLOBALS['TYPO3_DB']->sql_free_result($res); $catlist = implode(',', $sCatArr); return $catlist; }
/** * [Describe function...] * * @return [type] ... */ function initSubCategories() { if ($this->useSubCategories && $this->category) { $subcats = tx_ttnews_div::getSubCategories($this->category); $this->selectedCategories = t3lib_div::uniqueList($this->category . ($subcats ? ',' . $subcats : '')); } else { $this->selectedCategories = $this->category; } }
/** * [Describe function...] * * @return [type] ... */ function initSubCategories() { if ($this->useSubCategories && $this->category) { $subcats = tx_ttnews_div::getSubCategories($this->category); $this->selectedCategories = \TYPO3\CMS\Core\Utility\GeneralUtility::uniqueList($this->category . ($subcats ? ',' . $subcats : '')); } else { $this->selectedCategories = $this->category; } }
/** * This method is called by a hook in the TYPO3 Core Engine (TCEmain) when a record is saved. We use it to disable saving of the current record if it has categories assigned that are not allowed for the BE user. * * @param array $fieldArray: The field names and their values to be processed (passed by reference) * @param string $table: The table TCEmain is currently processing * @param string $id: The records id (if any) * @param object $pObj: Reference to the parent object (TCEmain) * @return void * @access public */ function processDatamap_preProcessFieldArray(&$fieldArray, $table, $id, &$pObj) { if ($table == 'tt_news_cat' && is_int($id)) { // prevent moving of categories into their rootline $newParent = intval($fieldArray['parent_category']); if ($newParent) { $subcategories = tx_ttnews_div::getSubCategories($id, $this->SPaddWhere . $this->enableCatFields); if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList($subcategories, $newParent)) { $sourceRec = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($table, $id, 'title'); $targetRec = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($table, $fieldArray['parent_category'], 'title'); /** * TODO: 19.05.2009 * localize */ $pObj->log($table, $id, 2, 0, 1, "processDatamap: Attempt to move category '%s' (%s) to inside of its own rootline (at category '%s' (%s)).", 1, array($sourceRec['title'], $id, $targetRec['title'], $newParent)); // unset fieldArray to prevent saving of the record $fieldArray = array(); } } } if ($table == 'tt_news') { // copy "type" field in localized records if (!is_int($id) && $fieldArray['l18n_parent']) { // record is a new localization $rec = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord($table, $fieldArray['l18n_parent'], 'type'); // get "type" from parent record $fieldArray['type'] = $rec['type']; // set type of current record } // check permissions of assigned categories if (is_int($id) && !$GLOBALS['BE_USER']->isAdmin()) { $categories = array(); $recID = $fieldArray['l18n_parent'] > 0 ? $fieldArray['l18n_parent'] : $id; // get categories from the tt_news record in db $cRes = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid_foreign, deleted', 'tt_news_cat_mm, tt_news_cat', 'uid_foreign=uid AND deleted=0 AND uid_local=' . $recID); while ($cRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($cRes)) { $categories[] = $cRow['uid_foreign']; } $GLOBALS['TYPO3_DB']->sql_free_result($cRes); $notAllowedItems = array(); if ($categories[0]) { // original record has no categories $treeIDs = tx_ttnews_div::getAllowedTreeIDs(); if (count($treeIDs)) { $allowedItems = $treeIDs; } else { $allowedItems = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $GLOBALS['BE_USER']->getTSConfigVal('tt_newsPerms.tt_news_cat.allowedItems')); } foreach ($categories as $k) { if (!in_array($k, $allowedItems)) { $notAllowedItems[] = $k; } } } if ($notAllowedItems[0]) { $pObj->log($table, $id, 2, 0, 1, "processDatamap: Attempt to modify a record from table '%s' without permission. Reason: the record has one or more categories assigned that are not defined in your BE usergroup (" . implode($notAllowedItems, ',') . ").", 1, array($table)); // unset fieldArray to prevent saving of the record $fieldArray = array(); } } } }
function buildCalendarArray() { // Define the list of pages to search (999 depth level). $this->search_list = $this->pi_getPidList($this->menuPid, $this->recursion); // Display only records that are active. $this->splitQuery = 'AND tx_newscalendar_state = 1'; // If showAllRecors is active, display all records. if ($this->conf['show.']['allRecords']) { $this->splitQuery = ''; } // gregory goidin - rvvn // Calculate the first and last date of the month. $currentTime = $this->time; $firstDate = $calendarStartMonth = strtotime($this->calendarYear . '-' . $this->calendarMonth . '-01'); $lastDate = $calendarEndMonth = mktime(23, 59, 59, intval($this->calendarMonth), date('t', $calendarStartMonth), intval($this->calendarYear)); switch ($this->displayType) { case 1: // CALENDAR if ($this->conf['calendar.']['hideIfInPast'] == 1 && $currentTime >= $calendarStartMonth && $currentTime <= $calendarEndMonth) { $firstDate = $currentTime; } else { if ($this->conf['calendar.']['hideIfInPast'] == 1 && $currentTime > $calendarEndMonth) { $firstDate = 1; $lastDate = 1; } } break; case 2: // LISTVIEW if ($this->conf['listView.']['hideIfInPast'] == 1 && $currentTime >= $calendarStartMonth && $currentTime <= $calendarEndMonth) { $firstDate = $currentTime; } else { if ($this->conf['listView.']['hideIfInPast'] == 1 && $currentTime > $calendarEndMonth) { $firstDate = 1; $lastDate = 1; } } break; case 3: // LISTINTERVAL if ($this->conf['listInterval.']['hideIfInPast'] == 1 && $currentTime >= $calendarStartMonth && $currentTime <= $calendarEndMonth) { $firstDate = $currentTime; } else { if ($this->conf['listInterval.']['hideIfInPast'] == 1 && $currentTime > $calendarEndMonth) { $firstDate = 1; $lastDate = 1; } } break; case 4: // NEXTEVENTS if ($this->conf['nextEvents.']['relativeToCalendar'] == 1 && $currentTime <= $calendarStartMonth) { $firstDate = $calendarStartMonth; } else { $firstDate = $currentTime; } break; } // Language query setup if ($this->sys_language_mode == 'strict' && $GLOBALS['TSFE']->sys_language_content) { // Just news in the same language $langClause = 'tt_news.sys_language_uid = ' . $GLOBALS['TSFE']->sys_language_content; } else { // sys_language_mode != 'strict': If a certain language is requested, select only news-records in the default language. The translated articles (if they exist) will be overlayed later in the list or single function. $langClause = 'tt_news.sys_language_uid IN (0,-1)'; } // gregory goidin - rvvn // New way of creating the sql query ( new display ). if ($this->displayType == 4) { $queryYearMonth = 'AND ( (tx_newssdf_calendardate=0 AND datetime >= ' . $firstDate . ' ) ' . 'OR ( tx_newssdf_calendardate_end=0 AND tx_newssdf_calendardate >= ' . $firstDate . ' ) ' . 'OR ( tx_newssdf_calendardate_end >= ' . $firstDate . ' ) )'; } else { $queryYearMonth = 'AND ( (tx_newssdf_calendardate=0 AND datetime >= ' . $firstDate . ' AND datetime <= ' . $lastDate . ' ) ' . 'OR ( tx_newssdf_calendardate_end=0 AND tx_newssdf_calendardate >= ' . $firstDate . ' AND tx_newssdf_calendardate <= ' . $lastDate . ' ) ' . 'OR ( tx_newssdf_calendardate <= ' . $lastDate . ' AND tx_newssdf_calendardate_end >= ' . $firstDate . ' ) )'; } $this->where = $langClause . ' ' . $queryYearMonth . ' ' . $this->splitQuery . ' ' . $this->cObj->enableFields('tt_news'); // gregory goidin - rvvn // add the limit parameter to configure the browsebox if needed in the sql query if ($this->displayType == 2 && intval($this->conf['pageBrowser.']['show']) == 1 && intval($this->conf['pageBrowser.']['limit']) >= 1 && intval($this->conf['pageBrowser.']['maxPages']) >= 1) { $limit = ""; $currentPage = 0; if (intval($this->piVars[$this->conf['pageBrowser.']['pointer']]) > 0) { $currentPage = intval($this->piVars[$this->conf['pageBrowser.']['pointer']]); } $limit = intval($this->conf['pageBrowser.']['limit']) * $currentPage . "," . intval($this->conf['pageBrowser.']['limit']); } else { if ($this->displayType == 4 && intval($this->conf['pageBrowser.']['show']) == 1 && intval($this->conf['pageBrowser.']['limit']) >= 1 && intval($this->conf['pageBrowser.']['maxPages']) >= 1) { $limit = ""; $currentPage = 0; if (intval($this->piVars[$this->conf['pageBrowser.']['pointer']]) > 0) { $currentPage = intval($this->piVars[$this->conf['pageBrowser.']['pointer']]); } $limitMax = intval($this->conf['pageBrowser.']['limit']); if (intval($this->conf['pageBrowser.']['limit']) * ($currentPage + 1) > intval($this->conf['nextEvents.']['maxItems'])) { $limitMax = intval($this->conf['nextEvents.']['maxItems']) - intval($this->conf['pageBrowser.']['limit']) * $currentPage; } $limit = intval($this->conf['pageBrowser.']['limit']) * $currentPage . "," . $limitMax; } else { if ($this->displayType == 4 && intval($this->conf['pageBrowser.']['show']) == 0) { $limit = "0," . intval($this->conf['nextEvents.']['maxItems']); } } } $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tt_news.uid, tt_news.pid, tt_news.sys_language_uid, tt_news.title, tt_news.datetime, tt_news.tx_newssdf_calendardate_end, tt_news.tx_newssdf_calendardate, tt_news.short, tt_news.image, tt_news.imagecaption, tt_news.imagealttext, tt_news.imagetitletext, tt_news.bodytext, tt_news.page, tt_news.type, tt_news.ext_url', 'tt_news', $this->where . ' AND tt_news.pid in (' . $this->search_list . ')', '', 'tx_newssdf_calendardate, tt_news.datetime ASC', $limit); $this->globalRes = $res; //****************************************************************// //gregory goidin - rvvn : start : We need the total count to initialize the pageBrowser /** * If the type of view is able to have a page browser we need to count the events again * so we have the total record count for the paginator. * We bypass the Calendar View by default. */ if ($this->displayType != 1) { $resCount = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'tt_news', $this->where . ' AND tt_news.pid in (' . $this->search_list . ')', '', 'tx_newssdf_calendardate, tt_news.datetime ASC', ""); $rowCount = $GLOBALS['TYPO3_DB']->sql_fetch_row($resCount); if ($this->displayType == 4 && $rowCount[0] > intval($this->conf['nextEvents.']['maxItems'])) { $rowCount[0] = intval($this->conf['nextEvents.']['maxItems']); } $this->globalResCount = $rowCount[0]; } else { // For calendar view we do not use limits or paginator browser $this->globalResCount = $GLOBALS['TYPO3_DB']->sql_num_rows($this->globalRes); } //gregory goidin - rvvn : stop ! //****************************************************************// // Prevent interval item rendering on normal and next events list views. // Only this will be prepared to render selected categories. if ($this->displayType == 1 || $this->displayType == 3) { // Fill array with result set. // CHANGED BY RICC FROM '1' to '0' $arrayCounter = 0; if ($this->categorySelection && $this->useSubCategories) { $this->categorySelection .= ',' . tx_ttnews_div::getSubCategories($this->categorySelection); } while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { /** * START: News category in list if applicable */ if ($this->categorySelection) { $exists = false; $categoryArray = explode(",", $this->categorySelection); foreach ($categoryArray as $selectedCatId) { $exists = array_key_exists($selectedCatId, tx_ttnews::getCategories($row['uid'])); if ($exists) { break; } } if (!$exists) { continue; } } /** * STOP: News category in list if applicable */ // News item default types $resultList[$arrayCounter]['type'] = $row['type']; $resultList[$arrayCounter]['page'] = $row['page']; $resultList[$arrayCounter]['ext_url'] = $row['ext_url']; $resultList[$arrayCounter]['image'] = $row['image']; $resultList[$arrayCounter]['short'] = $row['short']; $auxiliar_data = $resultList; // get the translated record if the content language is not the default language if ($GLOBALS['TSFE']->sys_language_content) { // $OLmode = ($this->sys_language_mode == 'strict'?'hideNonTranslated':''); $OLmode = $GLOBALS['TSFE']->tmpl->setup['config.']['sys_language_overlay']; $row = $GLOBALS['TSFE']->sys_page->getRecordOverlay('tt_news', $row, $GLOBALS['TSFE']->sys_language_content, $OLmode); } // Choose startdate, preference for tx_newscalendardate over datetime. $finalStartDate = $row['tx_newssdf_calendardate'] ? $row['tx_newssdf_calendardate'] : $row['datetime']; if ($this->calendarYear == date('Y', $finalStartDate) && $this->calendarMonth == date('n', $finalStartDate)) { $resultList[$arrayCounter]['uid'] = $row['uid']; $resultList[$arrayCounter]['title'] = $row['title']; $resultList[$arrayCounter]['monthday'] = date('j', $finalStartDate); $resultList[$arrayCounter]['enddate'] = $row['tx_newssdf_calendardate_end']; $resultList[$arrayCounter]['datetime'] = $finalStartDate; $arrayCounter++; } if ($row['tx_newssdf_calendardate_end'] > 0) { $startDate = date('Y-m-d', $finalStartDate); $endDate = date('Y-m-d', $row['tx_newssdf_calendardate_end']); $daysBetween = $this->GetDays($startDate, $endDate, $row['uid']); while ($date = each($daysBetween)) { if ($startDate != $date[1]) { $timeDate = strtotime($date[1] . date(' H:i', $finalStartDate)); if ($this->calendarYear == date('Y', $timeDate) && $this->calendarMonth == date('n', $timeDate)) { $resultList[$arrayCounter]['uid'] = $row['uid']; $resultList[$arrayCounter]['title'] = $row['title']; $resultList[$arrayCounter]['monthday'] = date('j', $timeDate); $resultList[$arrayCounter]['enddate'] = 0; $resultList[$arrayCounter]['datetime'] = $timeDate; $resultList[$arrayCounter]['type'] = $row['type']; $resultList[$arrayCounter]['page'] = $row['page']; $resultList[$arrayCounter]['ext_url'] = $row['ext_url']; $resultList[$arrayCounter]['image'] = $row['image']; $resultList[$arrayCounter]['short'] = $row['short']; /** * Remove items when in a interval and "hideIfInPast" is on * $this->conf['calendar.']['hideIfInPast'] * Thanks to Marvin Stobberingh for reporting. */ if ($this->conf['calendar.']['hideIfInPast']) { if ($resultList[$arrayCounter]['datetime'] < time()) { unset($resultList[$arrayCounter - 1]); } else { $arrayCounter++; } } else { $arrayCounter++; } } } } } } # sort alphabetically by name if (is_array($resultList)) { usort($resultList, array($this, 'compare_datetime')); } $this->resultListCount = count($resultList); $this->resultList = $resultList; } return; }