/**
  * Updates an already existing category record and stores it into the database.
  *
  * @author  Martin Helmich <*****@*****.**>
  * @version 2008-05-16
  * @return  void
  */
 function save_editCategory()
 {
     $res = $this->databaseHandle->exec_SELECTquery('*', 'tx_mmforum_forums', 'uid=' . intval($this->param['cid']));
     $ctg = $this->databaseHandle->sql_fetch_assoc($res);
     $updateArray = array('tstamp' => $GLOBALS['EXEC_TIME'], 'forum_name' => trim($this->param['ctg']['title']), 'grouprights_read' => $this->param['ctg']['authRead'], 'grouprights_write' => $this->param['ctg']['authWrite'], 'grouprights_mod' => $this->param['ctg']['authMod'], 'hidden' => $this->param['ctg']['hidden']);
     if (strlen($updateArray['forum_name']) == 0) {
         return array('title' => '<div class="mm_forum-fatalerror">' . $this->getLL('error.noTitle') . '</div>');
     }
     if ($this->param['ctg']['order'] == 'first') {
         $updateArray['sorting'] = 0;
         if ($ctg['sorting'] != 0) {
             $this->globalIncSorting(0, 1, $this->param['ctg']['parentID']);
         }
     } elseif ($this->param['ctg']['order'] == 'last') {
         $updateArray['sorting'] = $this->getMaxSorting() + 1;
     } else {
         if ($this->param['ctg']['order'] != $ctg['sorting']) {
             $this->globalIncSorting($this->param['ctg']['order'], 2, $this->param['ctg']['parentID']);
         }
         $updateArray['sorting'] = $this->param['ctg']['order'];
     }
     $this->databaseHandle->exec_UPDATEquery('tx_mmforum_forums', 'uid=' . intval($this->param['cid']), $updateArray);
     if ($updateArray['grouprights_read'] != $ctg['grouprights_read']) {
         $res = $this->databaseHandle->exec_SELECTquery('uid', 'tx_mmforum_forums', 'parentID=' . $ctg['uid']);
         while (list($fid) = $this->databaseHandle->sql_fetch_row($res)) {
             $this->delete_forumIndex($fid);
         }
     }
 }
 /**
  * Get column names
  *
  * @since 1.0.0
  *
  * @param $table
  *
  * @return array
  */
 protected function getColumnNames($table)
 {
     $table = preg_replace('/[^a-z0-9_]/', '', $table);
     if (isset($this->tableColumnCache[$table])) {
         return $this->tableColumnCache[$table];
     } else {
         $result = $this->databaseConnection->exec_SELECTgetSingleRow('*', $table, '1 = 1');
         if ($result) {
             $columnNames = array_keys($result);
             $this->tableColumnCache[$table] = $columnNames;
         } else {
             $columnNames = array();
             $result = $this->databaseConnection->sql_query('SELECT DATABASE();');
             $row = $this->databaseConnection->sql_fetch_row($result);
             $databaseName = $row[0];
             $this->databaseConnection->sql_free_result($result);
             $result = $this->databaseConnection->sql_query("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '" . $databaseName . "' AND TABLE_NAME = '" . $table . "';");
             while ($row = $this->databaseConnection->sql_fetch_row($result)) {
                 $columnNames[] = $row[0];
             }
             $this->databaseConnection->sql_free_result($result);
             $this->tableColumnCache[$table] = $columnNames;
         }
         return $columnNames;
     }
 }
 /**
  *
  * Retrievs a topic's forum UID.
  *
  * @author  Martin Helmich <*****@*****.**>
  * @version 2007-07-21
  * @param   int $topic_uid The topic's UID
  * @return  int            The forum's UID
  */
 function getForumUIDByTopic($topic_uid)
 {
     $topic_uid = intval($topic_uid);
     $res = $this->databaseHandle->exec_SELECTquery('forum_id', 'tx_mmforum_topics', 'uid=' . $topic_uid . ' AND deleted=0');
     if ($this->databaseHandle->sql_num_rows($res) > 0) {
         list($forum_uid) = $this->databaseHandle->sql_fetch_row($res);
         return $forum_uid;
     } else {
         return false;
     }
 }
 /**
  * @test
  *
  * @return void
  */
 public function sqlFetchRowReturnsNumericArray()
 {
     $this->prepareTableForFetchTests();
     $res = $this->subject->admin_query("SELECT * FROM {$this->testTable} ORDER BY id");
     $expectedResult = [['1', null, null, 'Mr. Smith', '0', 'Oakland Road', 'Los Angeles', 'USA'], ['2', null, null, 'Ms. Smith', '0', 'Oakland Road', 'Los Angeles', 'USA'], ['3', null, null, 'Alice im Wunderland', '0', 'Große Straße', 'Königreich der Herzen', 'Wunderland'], ['4', null, null, 'Agent Smith', '1', 'Unbekannt', 'Unbekannt', 'Matrix']];
     $i = 0;
     while ($row = $this->subject->sql_fetch_row($res)) {
         $this->assertSame($expectedResult[$i], $row);
         $i++;
     }
 }
Esempio n. 5
0
    /**
     * Gets the RSS feed's description
     *
     * @author  Martin Helmich <*****@*****.**>
     * @version 2008-07-17
     * @return  string The RSS feed's description.
     */
    function getFeedDescription()
    {
        if ($this->piVars['tid']) {
            $res = $this->databaseHandle->exec_SELECTquery('topic_title', 'tx_mmforum_topics t
				 LEFT JOIN tx_mmforum_forums f ON f.uid = t.forum_id
				 LEFT JOIN tx_mmforum_forums c ON c.uid = f.parentID', 'uid=' . intval($this->piVars['tid']) . $this->pObj->getMayRead_forum_query('f') . $this->pObj->getMayRead_forum_query('c'));
        } elseif ($this->piVars['fid']) {
            $res = $this->databaseHandle->exec_SELECTquery('f.forum_name', 'tx_mmforum_forums f
				 LEFT JOIN tx_mmforum_forums c ON c.uid = f.parentID', 'f.uid=' . intval($this->piVars['fid']) . $this->pObj->getMayRead_forum_query('f') . $this->pObj->getMayRead_forum_query('c'));
        } else {
            return '';
        }
        list($result) = $this->databaseHandle->sql_fetch_row($res);
        return $result;
    }
 /**
  * Determines the groups a user is in.
  *
  * @author  Martin Helmich <*****@*****.**>
  * @version 2007-06-06
  * @param   int   $user_id The UID of the user whose groups are to be
  *                         determined.
  * @return  array          An array containing all groups the user is a
  *                         member of.
  */
 function getUserGroupList($user_id)
 {
     if ($user_id == $GLOBALS['TSFE']->fe_user->user['uid']) {
         $groups = $GLOBALS['TSFE']->fe_user->user['usergroup'];
     } else {
         $res = $this->databaseHandle->exec_SELECTquery('usergroup', 'fe_users', 'uid=' . intval($user_id));
         if ($this->databaseHandle->sql_num_rows($res) == 0) {
             return 0;
         } else {
             list($groups) = $this->databaseHandle->sql_fetch_row($res);
         }
     }
     $aGroup = GeneralUtility::intExplode(',', $groups);
     $aGroup = tx_mmforum_tools::processArray_numeric($aGroup);
     return $aGroup;
 }
 /**
  * Search for users and returns usernames as result
  *
  * @param string $sword search string
  * @return array Array of usernames
  */
 public function search($sword)
 {
     $result = array();
     if (!$this->is_init) {
         $this->init();
     }
     if (!$this->validateName($this->field)) {
         return $result;
     }
     /** @see https://buzz.typo3.org/teams/security/article/correct-usage-of-typo3-database-api/ */
     $sword = '"' . $this->databaseHandle->escapeStrForLike($this->databaseHandle->quoteStr($sword, 'fe_users'), 'fe_users') . '%"';
     $res = $this->databaseHandle->exec_SELECTquery($this->field, 'fe_users', 'disable=0 AND deleted=0 AND ' . $this->field . ' LIKE ' . $sword . ' AND pid=' . $this->pid . ' AND FIND_IN_SET(' . $this->group_id . ', usergroup)', '', $this->field . ' ASC', '8');
     while (list($item) = $this->databaseHandle->sql_fetch_row($res)) {
         array_push($result, $item);
     }
     return $result;
 }
 /**
  * Inserts a new word into the search index table and returns it's UID.
  * If the word already exists in the search index, just the UID is returned.
  * @param string $word The word to be inserted
  * @return int         The word's UID
  */
 function wordAdd($word)
 {
     // Attempt to load word from database
     $res = $this->databaseHandle->exec_SELECTquery('uid', 'tx_mmforum_wordlist', "word=" . $this->databaseHandle->fullQuoteStr($word, 'tx_mmforum_wordlist') . " " . $this->getPidQuery($this->conf));
     if (!$res) {
         echo $this->databaseHandle->sql_error() . '<hr>';
     }
     // If words already exists, just return the UID
     if ($this->databaseHandle->sql_num_rows($res) > 0) {
         list($uid) = $this->databaseHandle->sql_fetch_row($res);
     } else {
         // Compost insert query
         $insertArray = array('pid' => $this->getFirstPid($this->conf), 'word' => $word, 'metaphone' => metaphone($word));
         // Execute insert query
         $this->databaseHandle->exec_INSERTquery('tx_mmforum_wordlist', $insertArray);
         $uid = $this->databaseHandle->sql_insert_id();
     }
     return $uid;
 }
Esempio n. 9
0
 /**
  *
  * Converts a commaseperated list of record UIDs to a TCEforms-readableformat.
  * This function converts a regular list of commaseperated record UIDs
  * (like e.g. "1,2,3") to a format that can be interpreted as form input
  * field default value by the t3lib_TCEforms class (like e.g.
  * "1|Username,2|Username_two,3|Username_three").
  *
  * @param   string $list The commaseperated list
  * @param   string $table The table the records' titles are to be
  *                            loaded from
  * @param   string $fieldname The fieldname used to identify the records,
  *                            like for example the username in the
  *                            fe_users table.
  *
  * @return string
  * @author  Martin Helmich <*****@*****.**>
  * @version 2007-04-23
  */
 function convertToTCEList($list, $table, $fieldname)
 {
     $items = GeneralUtility::trimExplode(',', $list);
     if (count($items) == 0) {
         return '';
     }
     $resultItems = array();
     foreach ($items as $item) {
         if ($item == '') {
             continue;
         }
         $res = $this->databaseHandle->exec_SELECTquery($fieldname, $table, 'uid="' . $item . '"');
         list($title) = $this->databaseHandle->sql_fetch_row($res);
         $resultItems[] = "{$item}|{$title}";
     }
     if (count($resultItems) == 0) {
         return '';
     }
     return implode(',', $resultItems);
 }
    /**
     * Displays additional statistics.
     *
     * @return  string The statistic table
     * @author  Martin Helmich <*****@*****.**>
     * @version 2007-05-31
     */
    function additionalStats()
    {
        $startTime = $this->getStartTime();
        $span = $GLOBALS['EXEC_TIME'] - $startTime;
        $days = round($span / 86400);
        $res = $this->databaseHandle->exec_SELECTquery('COUNT(*)', 'tx_mmforum_posts', 'deleted=0');
        list($post_count) = $this->databaseHandle->sql_fetch_row($res);
        $post_average = round($post_count / $days, 4);
        $res = $this->databaseHandle->exec_SELECTquery('COUNT(*)', 'tx_mmforum_topics', 'deleted=0');
        list($topic_count) = $this->databaseHandle->sql_fetch_row($res);
        $topic_average = round($topic_count / $days, 4);
        $res = $this->databaseHandle->exec_SELECTquery('COUNT(*)', 'fe_users', 'deleted=0 AND crdate >= ' . $startTime);
        list($user_count) = $this->databaseHandle->sql_fetch_row($res);
        $user_average = round($user_count / $days, 4);
        $res = $this->databaseHandle->exec_SELECTquery('COUNT(*)', 'tx_mmforum_pminbox', 'deleted=0 AND sendtime > ' . $startTime);
        list($pm_count) = $this->databaseHandle->sql_fetch_row($res);
        $pm_count /= 2;
        $pm_average = round($pm_count / $days, 4);
        $content = '
	<table cellspacing="0" cellpadding="2">
		<tr>
			<td>' . $this->getLL('menu.table.posts') . ' (' . $this->getLL('additional.totavg') . ')</td>
			<td>' . $post_count . ' / ' . $post_average . '</td>
		</tr>
		<tr>
			<td>' . $this->getLL('menu.table.topics') . ' (' . $this->getLL('additional.totavg') . ')</td>
			<td>' . $topic_count . ' / ' . $topic_average . '</td>
		</tr>
		<tr>
			<td>' . $this->getLL('menu.table.users') . ' (' . $this->getLL('additional.totavg') . ')</td>
			<td>' . $user_count . ' / ' . $user_average . '</td>
		</tr>
		<tr>
			<td>' . $this->getLL('menu.table.pms') . ' (' . $this->getLL('additional.totavg') . ')</td>
			<td>' . $pm_count . ' / ' . $pm_average . '</td>
		</tr>
	</table>
';
        return $content;
    }
    /**
     * Sends an e-mail to users who have subscribed to certain forumcategory
     * @param $topicId int The UID of the new topic that was created
     * @param $forumId int The UID of the forum about which the users are to be alerted.
     * @param \tx_mmforum_base $forumObj
     * @return void
     * @author Cyrill Helg
     */
    static function notifyForumSubscribers($topicId, $forumId, \tx_mmforum_base $forumObj)
    {
        $res = $this->databaseHandle->exec_SELECTquery('topic_title', 'tx_mmforum_topics', 'uid = ' . intval($topicId) . $forumObj->getStoragePIDQuery());
        list($topicName) = $this->databaseHandle->sql_fetch_row($res);
        $res = $this->databaseHandle->exec_SELECTquery('forum_name, parentID', 'tx_mmforum_forums', 'uid = ' . intval($forumId) . $forumObj->getStoragePIDQuery());
        list($forumName, $categoryId) = $this->databaseHandle->sql_fetch_row($res);
        // prepare the template (the variables that don't change all the time need only to be set once)
        $linkParams[$forumObj->prefixId] = array('action' => 'open_topic', 'id' => $topicId);
        $link = $forumObj->pi_getPageLink($GLOBALS['TSFE']->id, '', $linkParams);
        $link = $forumObj->tools->escapeBrackets($link);
        if (strlen($forumObj->conf['notifyingMail.']['topicLinkPrefix_override']) > 0) {
            $link = $forumObj->conf['notifyingMail.']['topicLinkPrefix_override'] . $link;
        }
        $template = $forumObj->pi_getLL('ntfMailForum.text');
        $marker = array('###LINK###' => $link, '###USERNAME###' => $toUsername, '###FORUMNAME###' => $forumName, '###TEAM###' => $forumObj->conf['teamName']);
        $subjectMarker = array('###TOPICNAME###' => $topicName, '###FORUMNAME###' => $forumName, '###BOARDNAME###' => $forumObj->conf['boardName']);
        // loop through each user who subscribed
        $res = $this->databaseHandle->exec_SELECTquery('DISTINCT tx_mmforum_forummail.user_id, fe_users.email, fe_users.' . $forumObj->getUserNameField(), 'tx_mmforum_forummail, fe_users', 'tx_mmforum_forummail.user_id = fe_users.uid AND
			 (tx_mmforum_forummail.forum_id = ' . intval($forumId) . ($categoryId > 0 ? ' OR tx_mmforum_forummail.forum_id = ' . $categoryId : '') . ') AND
			 fe_users.deleted = 0 AND
			 fe_users.disable = 0 AND
			 fe_users.email != "" AND
			 tx_mmforum_forummail.user_id != ' . intval($GLOBALS['TSFE']->fe_user->user['uid']) . $forumObj->getStoragePIDQuery('tx_mmforum_forummail'));
        while (list($toUserId, $toEmail, $toUsername) = $this->databaseHandle->sql_fetch_row($res)) {
            $marker['###USERNAME###'] = $forumObj->escape($toUsername);
            $mailtext = $forumObj->cObj->substituteMarkerArrayCached($template, $marker);
            // Compose mail and send
            $subject = $forumObj->cObj->substituteMarkerArray($forumObj->pi_getLL('ntfMailForum.subject'), $subjectMarker);
            $mail = GeneralUtility::makeInstance('t3lib_mail_Message');
            $mail->setFrom(array($forumObj->conf['notifyingMail.']['sender_address'] => $forumObj->conf['notifyingMail.']['sender']));
            $mail->setTo(array($toEmail => $toUsername));
            $mail->setSubject($subject);
            $mail->setBody($mailtext, 'text/plain');
            $mail->send();
        }
    }
Esempio n. 12
0
 /**
  * generates the News archive menu
  *
  * @return	string		html code of the archive menu
  */
 function displayArchiveMenu()
 {
     if ($this->debugTimes) {
         $this->hObj->getParsetime(__METHOD__ . ' start');
     }
     $this->arcExclusive = 1;
     $selectConf = $this->getSelectConf('', 1);
     $selectConf['where'] .= $this->enableFields;
     // Finding maximum and minimum values:
     $row = $this->getArchiveMenuRange($selectConf);
     if ($row['minval'] || $row['maxval']) {
         // if ($row['minval']) {
         $dateArr = array();
         $arcMode = $this->config['archiveMode'];
         $c = 0;
         $theDate = 0;
         while ($theDate < $row['maxval']) {
             switch ($arcMode) {
                 case 'month':
                     $theDate = mktime(0, 0, 0, date('m', $row['minval']) + $c, 1, date('Y', $row['minval']));
                     break;
                 case 'quarter':
                     $theDate = mktime(0, 0, 0, floor(date('m', $row['minval']) / 3) + 1 + 3 * $c, 1, date('Y', $row['minval']));
                     break;
                 case 'year':
                     $theDate = mktime(0, 0, 0, 1, 1, date('Y', $row['minval']) + $c);
                     break;
             }
             $dateArr[] = $theDate;
             $c++;
             if ($c > 1000) {
                 break;
             }
         }
         if ($this->debugTimes) {
             $this->hObj->getParsetime(__METHOD__ . ' $dateArr');
         }
         //			$selectConf['where'] .= $this->enableFields;
         if ($selectConf['pidInList']) {
             $selectConf['where'] .= ' AND tt_news.pid IN (' . $selectConf['pidInList'] . ')';
         }
         $tmpWhere = $selectConf['where'];
         $cachedPeriodAccum = FALSE;
         $storeKey = FALSE;
         if ($this->cache_amenuPeriods) {
             $storeKey = md5(serialize(array($this->catExclusive, $this->config['catSelection'], $this->tsfe->sys_language_content, $selectConf['pidInList'], $arcMode)));
             //				$cachedPeriodAccum = $this->tsfe->sys_page->getHash($storeKey);
             $cachedPeriodAccum = $this->cache->get($storeKey);
         }
         if ($cachedPeriodAccum != '') {
             if ($this->writeCachingInfoToDevlog > 1) {
                 \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('CACHE HIT (' . __CLASS__ . '::' . __FUNCTION__ . ')', 'tt_news', -1, array());
             }
             $periodAccum = unserialize($cachedPeriodAccum);
         } else {
             $periodAccum = array();
             foreach ($dateArr as $k => $v) {
                 $periodInfo = array();
                 $periodInfo['start'] = $v;
                 $periodInfo['active'] = $this->piVars['pS'] == $v ? 1 : 0;
                 $periodInfo['stop'] = $dateArr[$k + 1] - 1;
                 $periodInfo['HRstart'] = date('d-m-Y', $periodInfo['start']);
                 $periodInfo['HRstop'] = date('d-m-Y', $periodInfo['stop']);
                 $periodInfo['quarter'] = floor(date('m', $v) / 3) + 1;
                 $select_fields = 'COUNT(DISTINCT tt_news.uid)';
                 $from_table = 'tt_news';
                 $join = $selectConf['leftjoin'] ? ' LEFT JOIN ' . $selectConf['leftjoin'] : '';
                 $where_clause = $tmpWhere . ' AND tt_news.datetime>=' . $periodInfo['start'] . ' AND tt_news.datetime<' . $periodInfo['stop'];
                 $res = $this->db->exec_SELECTquery($select_fields, $from_table . $join, $where_clause);
                 $row = $this->db->sql_fetch_row($res);
                 $this->db->sql_free_result($res);
                 $periodInfo['count'] = $row[0];
                 if (!$this->conf['archiveMenuNoEmpty'] || $periodInfo['count']) {
                     $periodAccum[] = $periodInfo;
                 }
             }
             if ($this->cache_amenuPeriods && count($periodAccum)) {
                 if ($this->writeCachingInfoToDevlog) {
                     \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('CACHE MISS (' . __CLASS__ . '::' . __FUNCTION__ . ')', 'tt_news', 2, array());
                 }
                 //					$this->tsfe->sys_page->storeHash($storeKey, serialize($periodAccum), 'news_amenuPeriodsCache');
                 $this->cache->set($storeKey, serialize($periodAccum), __FUNCTION__);
             }
         }
         if ($this->debugTimes) {
             $this->hObj->getParsetime(__METHOD__ . ' periodAccum');
         }
         // get template subpart
         $t['total'] = $this->getNewsSubpart($this->templateCode, $this->spMarker('###TEMPLATE_ARCHIVE###'));
         $t['item'] = $this->getLayouts($t['total'], $this->alternatingLayouts, 'MENUITEM');
         $renderMarkers = $this->getMarkers($t['total']);
         $this->renderMarkers = array_unique($renderMarkers);
         $tCount = count($t['item']);
         $cc = 0;
         $veryLocal_cObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
         // reverse amenu order if 'reverseAMenu' is given
         if ($this->conf['reverseAMenu']) {
             arsort($periodAccum);
         }
         $archiveLink = $this->conf['archiveTypoLink.']['parameter'];
         $archiveLink = $archiveLink ? $archiveLink : $this->tsfe->id;
         $this->conf['parent.']['addParams'] = $this->conf['archiveTypoLink.']['addParams'];
         $amenuLinkCat = null;
         if (!$this->conf['disableCategoriesInAmenuLinks']) {
             if ($this->piVars_catSelection && $this->config['amenuWithCatSelector']) {
                 // use the catSelection from piVars only if 'amenuWithCatSelector' is given.
                 $amenuLinkCat = $this->piVars_catSelection;
             } else {
                 $amenuLinkCat = $this->actuallySelectedCategories;
             }
         }
         $itemsOutArr = array();
         $oldyear = 0;
         $itemsOut = '';
         foreach ($periodAccum as $pArr) {
             $wrappedSubpartArray = array();
             $markerArray = array();
             $year = date('Y', $pArr['start']);
             if ($this->conf['useHRDates']) {
                 $month = date('m', $pArr['start']);
                 if ($arcMode == 'year') {
                     $archLinkArr = $this->pi_linkTP_keepPIvars('|', array('cat' => $amenuLinkCat, 'year' => $year), $this->allowCaching, 1, $archiveLink);
                 } else {
                     $archLinkArr = $this->pi_linkTP_keepPIvars('|', array('cat' => $amenuLinkCat, 'year' => $year, 'month' => $month), $this->allowCaching, 1, $archiveLink);
                 }
                 $wrappedSubpartArray['###LINK_ITEM###'] = explode('|', $archLinkArr);
             } else {
                 $wrappedSubpartArray['###LINK_ITEM###'] = explode('|', $this->pi_linkTP_keepPIvars('|', array('cat' => $amenuLinkCat, 'pS' => $pArr['start'], 'pL' => $pArr['stop'] - $pArr['start'], 'arc' => 1), $this->allowCaching, 1, $archiveLink));
             }
             $yearTitle = '';
             if ($this->conf['showYearHeadersInAmenu'] && $arcMode != 'year') {
                 if ($year != $oldyear) {
                     if ($pArr['start'] < 20000) {
                         $yearTitle = 'no date';
                     } else {
                         $yearTitle = $year;
                     }
                     $oldyear = $year;
                 }
             }
             $veryLocal_cObj->start($pArr, 'tt_news');
             $markerArray['###ARCHIVE_YEAR###'] = '';
             if ($yearTitle) {
                 $markerArray['###ARCHIVE_YEAR###'] = $veryLocal_cObj->stdWrap($yearTitle, $this->conf['archiveYear_stdWrap.']);
             }
             $markerArray['###ARCHIVE_TITLE###'] = $veryLocal_cObj->cObjGetSingle($this->conf['archiveTitleCObject'], $this->conf['archiveTitleCObject.'], 'archiveTitleCObject');
             $markerArray['###ARCHIVE_COUNT###'] = $pArr['count'];
             $markerArray['###ARCHIVE_ITEMS###'] = $pArr['count'] == 1 ? $this->pi_getLL('archiveItem') : $this->pi_getLL('archiveItems');
             $markerArray['###ARCHIVE_ACTIVE###'] = $this->piVars['pS'] == $pArr['start'] ? $this->conf['archiveActiveMarkerContent'] : '';
             $layoutNum = $tCount == 0 ? 0 : $cc % $tCount;
             $amenuitem = $this->cObj->substituteMarkerArrayCached($t['item'][$layoutNum], $markerArray, array(), $wrappedSubpartArray);
             if ($this->conf['newsAmenuUserFunc']) {
                 // fill the generated data to an array to pass it to a userfuction as a single variable
                 $itemsOutArr[] = array('html' => $amenuitem, 'data' => $pArr);
             } else {
                 $itemsOut .= $amenuitem;
             }
             $cc++;
         }
         // Pass to user defined function
         if ($this->conf['newsAmenuUserFunc']) {
             $tmpItemsArr = FALSE;
             $itemsOutArr = $this->userProcess('newsAmenuUserFunc', $itemsOutArr);
             foreach ($itemsOutArr as $itemHtml) {
                 $tmpItemsArr[] = $itemHtml['html'];
             }
             if (is_array($tmpItemsArr)) {
                 $itemsOut = implode('', $tmpItemsArr);
             }
         }
         // Reset:
         $subpartArray = array();
         $wrappedSubpartArray = array();
         $markerArray = array();
         $markerArray['###ARCHIVE_HEADER###'] = $this->local_cObj->stdWrap($this->pi_getLL('archiveHeader'), $this->conf['archiveHeader_stdWrap.']);
         // Set content
         $subpartArray['###CONTENT###'] = $itemsOut;
         $content = $this->cObj->substituteMarkerArrayCached($t['total'], $markerArray, $subpartArray, $wrappedSubpartArray);
     } else {
         // if nothing is found in the archive display the TEMPLATE_ARCHIVE_NOITEMS message
         $markerArray['###ARCHIVE_HEADER###'] = $this->local_cObj->stdWrap($this->pi_getLL('archiveHeader'), $this->conf['archiveHeader_stdWrap.']);
         $markerArray['###ARCHIVE_EMPTY_MSG###'] = $this->local_cObj->stdWrap($this->pi_getLL('archiveEmptyMsg'), $this->conf['archiveEmptyMsg_stdWrap.']);
         $noItemsMsg = $this->getNewsSubpart($this->templateCode, $this->spMarker('###TEMPLATE_ARCHIVE_NOITEMS###'));
         $content = $this->cObj->substituteMarkerArrayCached($noItemsMsg, $markerArray);
     }
     if ($this->debugTimes) {
         $this->hObj->getParsetime(__METHOD__);
     }
     return $content;
 }
Esempio n. 13
0
 /**
  * Creates a new version of a record
  * (Requires support in the table)
  *
  * @param string $table Table name
  * @param int $id Record uid to versionize
  * @param string $label Version label
  * @param bool $delete If TRUE, the version is created to delete the record.
  * @return int|NULL Returns the id of the new version (if any)
  * @see copyRecord()
  */
 public function versionizeRecord($table, $id, $label, $delete = false)
 {
     $id = (int) $id;
     // Stop any actions if the record is marked to be deleted:
     // (this can occur if IRRE elements are versionized and child elements are removed)
     if ($this->isElementToBeDeleted($table, $id)) {
         return null;
     }
     if (!$GLOBALS['TCA'][$table] || !$GLOBALS['TCA'][$table]['ctrl']['versioningWS'] || $id <= 0) {
         if ($this->enableLogging) {
             $this->newlog('Versioning is not supported for this table "' . $table . '" / ' . $id, 1);
         }
         return null;
     }
     if (!$this->doesRecordExist($table, $id, 'show')) {
         if ($this->enableLogging) {
             $this->newlog('You didn\'t have correct permissions to make a new version (copy) of this record "' . $table . '" / ' . $id, 1);
         }
         return null;
     }
     // Select main record:
     $row = $this->recordInfo($table, $id, 'pid,t3ver_id,t3ver_state');
     if (!is_array($row)) {
         if ($this->enableLogging) {
             $this->newlog('Record "' . $table . ':' . $id . '" you wanted to versionize did not exist!', 1);
         }
         return null;
     }
     // Record must be online record
     if ($row['pid'] < 0) {
         if ($this->enableLogging) {
             $this->newlog('Record "' . $table . ':' . $id . '" you wanted to versionize was already a version in archive (pid=-1)!', 1);
         }
         return null;
     }
     // Record must not be placeholder for moving.
     if (VersionState::cast($row['t3ver_state'])->equals(VersionState::MOVE_PLACEHOLDER)) {
         if ($this->enableLogging) {
             $this->newlog('Record cannot be versioned because it is a placeholder for a moving operation', 1);
         }
         return null;
     }
     if ($delete && $this->cannotDeleteRecord($table, $id)) {
         if ($this->enableLogging) {
             $this->newlog('Record cannot be deleted: ' . $this->cannotDeleteRecord($table, $id), 1);
         }
         return null;
     }
     // Look for next version number:
     $res = $this->databaseConnection->exec_SELECTquery('t3ver_id', $table, '((pid=-1 && t3ver_oid=' . $id . ') OR uid=' . $id . ')' . $this->deleteClause($table), '', 't3ver_id DESC', '1');
     list($highestVerNumber) = $this->databaseConnection->sql_fetch_row($res);
     $this->databaseConnection->sql_free_result($res);
     // Look for version number of the current:
     $subVer = $row['t3ver_id'] . '.' . ($highestVerNumber + 1);
     // Set up the values to override when making a raw-copy:
     $overrideArray = array('t3ver_id' => $highestVerNumber + 1, 't3ver_oid' => $id, 't3ver_label' => $label ?: $subVer . ' / ' . date('d-m-Y H:m:s'), 't3ver_wsid' => $this->BE_USER->workspace, 't3ver_state' => (string) ($delete ? new VersionState(VersionState::DELETE_PLACEHOLDER) : new VersionState(VersionState::DEFAULT_STATE)), 't3ver_count' => 0, 't3ver_stage' => 0, 't3ver_tstamp' => 0);
     if ($GLOBALS['TCA'][$table]['ctrl']['editlock']) {
         $overrideArray[$GLOBALS['TCA'][$table]['ctrl']['editlock']] = 0;
     }
     // Checking if the record already has a version in the current workspace of the backend user
     if ($this->BE_USER->workspace !== 0) {
         // Look for version already in workspace:
         $versionRecord = BackendUtility::getWorkspaceVersionOfRecord($this->BE_USER->workspace, $table, $id, 'uid');
     }
     // Create new version of the record and return the new uid
     if (empty($versionRecord['uid'])) {
         // Create raw-copy and return result:
         // The information of the label to be used for the workspace record
         // as well as the information whether the record shall be removed
         // must be forwarded (creating remove placeholders on a workspace are
         // done by copying the record and override several fields).
         $workspaceOptions = array('delete' => $delete, 'label' => $label);
         return $this->copyRecord_raw($table, $id, -1, $overrideArray, $workspaceOptions);
         // Reuse the existing record and return its uid
         // (prior to TYPO3 CMS 6.2, an error was thrown here, which
         // did not make much sense since the information is available)
     } else {
         return $versionRecord['uid'];
     }
     return null;
 }
 /**
  * Determines if there is a value set for this field for a specific user.
  *
  * @param  int  $userId The UID of the user that is to be checked.
  * @return bool         TRUE, if there is a value stored for this user, otherwise
  *                      false.
  *
  * @author  Martin Helmich <*****@*****.**>
  * @version 2009-02-16
  */
 function isSetForUser($userId)
 {
     $res = $this->databaseHandle->exec_SELECTquery('COUNT(*)', 'tx_mmforum_userfields_contents', 'user_id=' . intval($userId) . ' AND field_id=' . intval($this->getUID()) . ' AND deleted=0');
     list($count) = $this->databaseHandle->sql_fetch_row($res);
     return $count > 0;
 }
Esempio n. 15
0
 /**
  * Returns the board UID of a topic
  * @param  int $topicId The topic UID
  * @return int          The board UID
  **/
 function get_forum_id($topicId)
 {
     $res = $this->databaseHandle->exec_SELECTquery('forum_id', 'tx_mmforum_topics', 'uid = ' . intval($topicId) . $this->getStoragePIDQuery());
     list($forumId) = $this->databaseHandle->sql_fetch_row($res);
     return $forumId;
 }
Esempio n. 16
0
 /**
  * Get query result code
  *
  * @param string $mQ
  * @param bool|\mysqli_result|object $res MySQLi result object / DBAL object
  * @param string $table
  * @return string
  */
 public function getQueryResultCode($mQ, $res, $table)
 {
     $out = '';
     $cPR = array();
     switch ($mQ) {
         case 'count':
             $row = $this->databaseConnection->sql_fetch_row($res);
             $cPR['header'] = 'Count';
             $cPR['content'] = '<BR><strong>' . $row[0] . '</strong> records selected.';
             break;
         case 'all':
             $rowArr = array();
             $lrow = null;
             while ($row = $this->databaseConnection->sql_fetch_assoc($res)) {
                 $rowArr[] = $this->resultRowDisplay($row, $GLOBALS['TCA'][$table], $table);
                 $lrow = $row;
             }
             if (is_array($this->hookArray['beforeResultTable'])) {
                 foreach ($this->hookArray['beforeResultTable'] as $_funcRef) {
                     $out .= GeneralUtility::callUserFunction($_funcRef, $GLOBALS['SOBE']->MOD_SETTINGS, $this);
                 }
             }
             if (!empty($rowArr)) {
                 $out .= '<table class="table table-striped table-hover">' . $this->resultRowTitles($lrow, $GLOBALS['TCA'][$table], $table) . implode(LF, $rowArr) . '</table>';
             }
             if (!$out) {
                 $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, 'No rows selected!', '', FlashMessage::INFO);
                 $out = $flashMessage->getMessageAsMarkup();
             }
             $cPR['header'] = 'Result';
             $cPR['content'] = $out;
             break;
         case 'csv':
             $rowArr = array();
             $first = 1;
             while ($row = $this->databaseConnection->sql_fetch_assoc($res)) {
                 if ($first) {
                     $rowArr[] = $this->csvValues(array_keys($row), ',', '');
                     $first = 0;
                 }
                 $rowArr[] = $this->csvValues($row, ',', '"', $GLOBALS['TCA'][$table], $table);
             }
             if (!empty($rowArr)) {
                 $out .= '<textarea name="whatever" rows="20" class="text-monospace" style="width:100%">' . htmlspecialchars(implode(LF, $rowArr)) . '</textarea>';
                 if (!$this->noDownloadB) {
                     $out .= '<br><input class="btn btn-default" type="submit" name="download_file" ' . 'value="Click to download file" onClick="window.location.href=\'' . $this->downloadScript . '\';">';
                 }
                 // Downloads file:
                 if (GeneralUtility::_GP('download_file')) {
                     $filename = 'TYPO3_' . $table . '_export_' . date('dmy-Hi') . '.csv';
                     $mimeType = 'application/octet-stream';
                     header('Content-Type: ' . $mimeType);
                     header('Content-Disposition: attachment; filename=' . $filename);
                     echo implode(CRLF, $rowArr);
                     die;
                 }
             }
             if (!$out) {
                 $out = '<em>No rows selected!</em>';
             }
             $cPR['header'] = 'Result';
             $cPR['content'] = $out;
             break;
         case 'explain':
         default:
             while ($row = $this->databaseConnection->sql_fetch_assoc($res)) {
                 $out .= '<br />' . DebugUtility::viewArray($row);
             }
             $cPR['header'] = 'Explain SQL query';
             $cPR['content'] = $out;
     }
     return $cPR;
 }
Esempio n. 17
0
 /**
  * Deletes a poll.
  * This function deletes a poll completely from database. This includes
  * the reference to the poll in the tx_mmforum_topics table, the answering
  * possibilities to this poll and the votes that were already made.
  *
  * @version 2007-05-25
  * @param  int  $uid   The UID of the poll that is to be deleted
  * @param  int  $topic The UID of the topic whose poll is to be deleted
  * @return void
  */
 function deletePoll($uid, $topic = 0)
 {
     if ($topic == 0) {
         $poll_id = intval($uid);
         $res = $this->databaseHandle->exec_SELECTquery('uid', 'tx_mmforum_topics', 'poll_id=' . $poll_id);
         if ($this->databaseHandle->sql_num_rows($res) == 0) {
             $topic_id = 0;
         } else {
             list($topic_id) = $this->databaseHandle->sql_fetch_row($res);
         }
     } elseif ($uid == 0) {
         $topic_id = intval($topic);
         $res = $this->databaseHandle->exec_SELECTquery('poll_id', 'tx_mmforum_topics', 'uid=' . $topic);
         if ($this->databaseHandle->sql_num_rows($res) == 0) {
             $poll_id = 0;
         } else {
             list($poll_id) = $this->databaseHandle->sql_fetch_row($res);
         }
     } else {
         $poll_id = intval($uid);
         $topic_id = intval($topic);
     }
     if ($poll_id > 0) {
         $this->databaseHandle->exec_UPDATEquery('tx_mmforum_polls', 'uid=' . $poll_id, array('deleted' => 1, 'tstamp' => $GLOBALS['EXEC_TIME']));
         $this->databaseHandle->exec_UPDATEquery('tx_mmforum_polls_answers', 'poll_id=' . $poll_id, array('deleted' => 1, 'tstamp' => $GLOBALS['EXEC_TIME']));
         $this->databaseHandle->exec_UPDATEquery('tx_mmforum_polls_votes', 'poll_id=' . $poll_id, array('deleted' => 1, 'tstamp' => $GLOBALS['EXEC_TIME']));
     }
     if ($topic_id > 0) {
         $this->databaseHandle->exec_UPDATEquery('tx_mmforum_topics', 'uid=' . $topic_id, array('poll_id' => 0));
     }
 }
 /**
  *
  * Gets the sorting value for a newly created forum.
  *
  * @param  Integer $parentUid The parent UID of the new forum
  * @return Integer            The new sorting value.
  */
 function getSortingForNewForum($parentUid = 0)
 {
     $res = $this->databaseHandle->exec_SELECTquery('MAX(sorting)+1', 'tx_mmforum_forums', 'deleted=0 AND parentID=' . intval($parentUid) . ' ' . $this->p->getStoragePIDQuery());
     list($newSorting) = $this->databaseHandle->sql_fetch_row($res);
     return $newSorting;
 }
 /**
  * Loads a cache variable from database.
  *
  * @author  Martin Helmich <*****@*****.**>
  * @version 2008-06-22
  * @param   string $key The key of the cache variable.
  * @return  mixed       The cache variable. Since the cache value is
  *                      stored in serialized form, this value can be of
  *                      any type. If the value was not found in the
  *                      cache table, this function will return NULL.
  */
 function getCacheValue($key)
 {
     $res = $this->databaseHandle->exec_SELECTquery('cache_value', 'tx_mmforum_cache', 'cache_key=' . $this->databaseHandle->fullQuoteStr($key, 'tx_mmforum_cache'));
     if ($this->databaseHandle->sql_num_rows($res)) {
         list($value) = $this->databaseHandle->sql_fetch_row($res);
         return unserialize($value);
     }
     return null;
 }