/**
  * @param string $table
  * @param string $field
  * @param array $row
  * @param array $PA
  */
 function getSingleField_beforeRender($table, $field, &$row, &$PA)
 {
     global $TCA;
     if ($table == 'tx_caretaker_instance' && $field === 'testconfigurations') {
         switch ($PA['fieldConf']['config']['tag']) {
             case 'testconfigurations.test_service':
                 break;
             case 'testconfigurations.test_conf':
                 $test = $this->getFFValue($table, $row, $field, str_replace('test_conf', 'test_service', $PA['itemFormElName']));
                 // get related test configuration
                 $testrow = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,test_service,test_conf', 'tx_caretaker_test', 'uid=' . intval($test) . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('tx_caretaker_test'));
                 $row['test_service'] = $testrow[0]['test_service'];
                 if ($PA['itemFormElValue'] == NULL) {
                     $PA['itemFormElValue'] = $testrow[0]['test_conf'];
                 }
                 if (is_array($PA['itemFormElValue'])) {
                     $PA['itemFormElValue'] = \TYPO3\CMS\Core\Utility\GeneralUtility::array2xml($PA['itemFormElValue']);
                 }
                 if (!is_array($PA['fieldConf']['config']['ds'])) {
                     $PA['fieldConf']['config']['ds'] = $TCA['tx_caretaker_test']['columns']['test_conf']['config']['ds'];
                 }
                 break;
         }
     }
 }
 /**
  * Migrate tt_news_categorymounts to category_pems in either be_groups or be_users
  *
  * @param string $table either be_groups or be_users
  */
 public function migrateTtNewsCategoryMountsToSysCategoryPerms($table)
 {
     /** @var \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler */
     $dataHandler = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
     $dataHandler->admin = TRUE;
     /* assign imported categories to be_groups or be_users */
     $whereClause = 'tt_news_categorymounts != \'\'' . BackendUtility::deleteClause($table);
     $beGroupsOrUsersWithTtNewsCategorymounts = $this->databaseConnection->exec_SELECTgetRows('*', $table, $whereClause);
     $data = array();
     foreach ((array) $beGroupsOrUsersWithTtNewsCategorymounts as $beGroupOrUser) {
         $ttNewsCategoryPermissions = GeneralUtility::trimExplode(',', $beGroupOrUser['tt_news_categorymounts']);
         $sysCategoryPermissions = array();
         foreach ($ttNewsCategoryPermissions as $ttNewsCategoryPermissionUid) {
             $whereClause = 'import_source = \'TT_NEWS_CATEGORY_IMPORT\' AND import_id = ' . $ttNewsCategoryPermissionUid;
             $sysCategory = $this->databaseConnection->exec_SELECTgetSingleRow('uid', 'sys_category', $whereClause);
             if (!empty($sysCategory)) {
                 $sysCategoryPermissions[] = $sysCategory['uid'];
             }
         }
         if (count($sysCategoryPermissions)) {
             $data[$table][$beGroupOrUser['uid']] = array('category_perms' => implode(',', $sysCategoryPermissions) . ',' . $beGroupOrUser['category_perms']);
         }
     }
     $dataHandler->start($data, array());
     $dataHandler->process_datamap();
 }
Exemplo n.º 3
0
 /**
  * Checks whether a an BE user account named admin with default password exists.
  *
  * @return \TYPO3\CMS\Reports\Status An tx_reports_reports_status_Status object representing whether a default admin account exists
  */
 protected function getAdminAccountStatus()
 {
     $value = $GLOBALS['LANG']->getLL('status_ok');
     $message = '';
     $severity = \TYPO3\CMS\Reports\Status::OK;
     $whereClause = 'username = '******'TYPO3_DB']->fullQuoteStr('admin', 'be_users') . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('be_users');
     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid, username, password', 'be_users', $whereClause);
     if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
         $secure = TRUE;
         // Check against salted password
         if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('saltedpasswords')) {
             if (\TYPO3\CMS\Saltedpasswords\Utility\SaltedPasswordsUtility::isUsageEnabled('BE')) {
                 /** @var $saltingObject \TYPO3\CMS\Saltedpasswords\Salt\SaltInterface */
                 $saltingObject = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance($row['password']);
                 if (is_object($saltingObject)) {
                     if ($saltingObject->checkPassword('password', $row['password'])) {
                         $secure = FALSE;
                     }
                 }
             }
         }
         // Check against plain MD5
         if ($row['password'] === '5f4dcc3b5aa765d61d8327deb882cf99') {
             $secure = FALSE;
         }
         if (!$secure) {
             $value = $GLOBALS['LANG']->getLL('status_insecure');
             $severity = \TYPO3\CMS\Reports\Status::ERROR;
             $editUserAccountUrl = 'alt_doc.php?returnUrl=mod.php?M=tools_txreportsM1&edit[be_users][' . $row['uid'] . ']=edit';
             $message = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.backend_admin'), '<a href="' . $editUserAccountUrl . '">', '</a>');
         }
     }
     $GLOBALS['TYPO3_DB']->sql_free_result($res);
     return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->getLL('status_adminUserAccount'), $value, $message, $severity);
 }
Exemplo n.º 4
0
 /**
  * Checks whether a an BE user account named admin with default password exists.
  *
  * @return \TYPO3\CMS\Reports\Status An object representing whether a default admin account exists
  */
 protected function getAdminAccountStatus()
 {
     $value = $GLOBALS['LANG']->getLL('status_ok');
     $message = '';
     $severity = \TYPO3\CMS\Reports\Status::OK;
     $whereClause = 'username = '******'TYPO3_DB']->fullQuoteStr('admin', 'be_users') . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('be_users');
     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid, username, password', 'be_users', $whereClause);
     if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
         $secure = TRUE;
         /** @var $saltingObject \TYPO3\CMS\Saltedpasswords\Salt\SaltInterface */
         $saltingObject = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance($row['password']);
         if (is_object($saltingObject)) {
             if ($saltingObject->checkPassword('password', $row['password'])) {
                 $secure = FALSE;
             }
         }
         // Check against plain MD5
         if ($row['password'] === '5f4dcc3b5aa765d61d8327deb882cf99') {
             $secure = FALSE;
         }
         if (!$secure) {
             $value = $GLOBALS['LANG']->getLL('status_insecure');
             $severity = \TYPO3\CMS\Reports\Status::ERROR;
             $editUserAccountUrl = 'alt_doc.php?returnUrl=' . rawurlencode(BackendUtility::getModuleUrl('system_ReportsTxreportsm1')) . '&edit[be_users][' . $row['uid'] . ']=edit';
             $message = sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:warning.backend_admin'), '<a href="' . htmlspecialchars($editUserAccountUrl) . '">', '</a>');
         }
     }
     $GLOBALS['TYPO3_DB']->sql_free_result($res);
     return GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Status', $GLOBALS['LANG']->getLL('status_adminUserAccount'), $value, $message, $severity);
 }
Exemplo n.º 5
0
 /**
  * Processes the item to be rendered before the actual example content gets rendered
  * Deactivates the original example content output
  *
  * @param PageLayoutView $parentObject : The parent object that triggered this hook
  * @param boolean $drawItem : A switch to tell the parent object, if the item still must be drawn
  * @param string $headerContent : The content of the item header
  * @param string $itemContent : The content of the item itself
  * @param array $row : The current data row for this item
  *
  * @return    void
  */
 public function preProcess(PageLayoutView &$parentObject, &$drawItem, &$headerContent, &$itemContent, array &$row)
 {
     if ($row['CType']) {
         $showHidden = $parentObject->tt_contentConfig['showHidden'] ? '' : BackendUtility::BEenableFields('tt_content');
         $deleteClause = BackendUtility::deleteClause('tt_content');
         if ($GLOBALS['BE_USER']->uc['hideContentPreview']) {
             $drawItem = FALSE;
         }
         switch ($row['CType']) {
             case 'gridelements_pi1':
                 $drawItem = FALSE;
                 $itemContent .= $this->renderCTypeGridelements($parentObject, $row, $showHidden, $deleteClause);
                 $refIndexObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\ReferenceIndex');
                 /* @var $refIndexObj \TYPO3\CMS\Core\Database\ReferenceIndex */
                 $refIndexObj->updateRefIndexTable('tt_content', $row['uid']);
                 break;
             case 'shortcut':
                 $drawItem = FALSE;
                 $itemContent .= $this->renderCTypeShortcut($parentObject, $row, $showHidden, $deleteClause);
                 break;
         }
     }
     $gridType = $row['tx_gridelements_backend_layout'] ? ' t3-gridtype-' . $row['tx_gridelements_backend_layout'] : '';
     $headerContent = '<div id="ce' . $row['uid'] . '" class="t3-ctype-' . $row['CType'] . $gridType . '">' . $headerContent . '</div>';
 }
Exemplo n.º 6
0
 /**
  * Checks whether a BE user account named admin with default password exists.
  *
  * @return \TYPO3\CMS\Reports\Status An object representing whether a default admin account exists
  */
 protected function getAdminAccountStatus()
 {
     $value = $this->getLanguageService()->getLL('status_ok');
     $message = '';
     $severity = ReportStatus::OK;
     $whereClause = 'username = '******'admin', 'be_users') . BackendUtility::deleteClause('be_users');
     $res = $this->getDatabaseConnection()->exec_SELECTquery('uid, username, password', 'be_users', $whereClause);
     $row = $this->getDatabaseConnection()->sql_fetch_assoc($res);
     if (!empty($row)) {
         $secure = true;
         /** @var \TYPO3\CMS\Saltedpasswords\Salt\SaltInterface $saltingObject */
         $saltingObject = SaltFactory::getSaltingInstance($row['password']);
         if (is_object($saltingObject)) {
             if ($saltingObject->checkPassword('password', $row['password'])) {
                 $secure = false;
             }
         }
         // Check against plain MD5
         if ($row['password'] === '5f4dcc3b5aa765d61d8327deb882cf99') {
             $secure = false;
         }
         if (!$secure) {
             $value = $this->getLanguageService()->getLL('status_insecure');
             $severity = ReportStatus::ERROR;
             $editUserAccountUrl = BackendUtility::getModuleUrl('record_edit', array('edit[be_users][' . $row['uid'] . ']' => 'edit', 'returnUrl' => BackendUtility::getModuleUrl('system_ReportsTxreportsm1')));
             $message = sprintf($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:warning.backend_admin'), '<a href="' . htmlspecialchars($editUserAccountUrl) . '">', '</a>');
         }
     }
     $this->getDatabaseConnection()->sql_free_result($res);
     return GeneralUtility::makeInstance(ReportStatus::class, $this->getLanguageService()->getLL('status_adminUserAccount'), $value, $message, $severity);
 }
Exemplo n.º 7
0
    /**
     * This method is called by the Scheduler task that triggers
     * the autopublication process
     * It searches for workspaces whose publication date is in the past
     * and publishes them
     *
     * @return void
     */
    public function autoPublishWorkspaces()
    {
        // Temporarily set admin rights
        // @todo once workspaces are cleaned up a better solution should be implemented
        $currentAdminStatus = $GLOBALS['BE_USER']->user['admin'];
        $GLOBALS['BE_USER']->user['admin'] = 1;
        // Select all workspaces that needs to be published / unpublished:
        $workspaces = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,swap_modes,publish_time,unpublish_time', 'sys_workspace', 'pid=0
				AND
				((publish_time!=0 AND publish_time<=' . (int) $GLOBALS['EXEC_TIME'] . ')
				OR (publish_time=0 AND unpublish_time!=0 AND unpublish_time<=' . (int) $GLOBALS['EXEC_TIME'] . '))' . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('sys_workspace'));
        $workspaceService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
        foreach ($workspaces as $rec) {
            // First, clear start/end time so it doesn't get select once again:
            $fieldArray = $rec['publish_time'] != 0 ? array('publish_time' => 0) : array('unpublish_time' => 0);
            $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_workspace', 'uid=' . (int) $rec['uid'], $fieldArray);
            // Get CMD array:
            $cmd = $workspaceService->getCmdArrayForPublishWS($rec['uid'], $rec['swap_modes'] == 1);
            // $rec['swap_modes']==1 means that auto-publishing will swap versions, not just publish and empty the workspace.
            // Execute CMD array:
            $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
            $tce->stripslashes_values = 0;
            $tce->start(array(), $cmd);
            $tce->process_cmdmap();
        }
        // Restore admin status
        $GLOBALS['BE_USER']->user['admin'] = $currentAdminStatus;
    }
Exemplo n.º 8
0
 /**
  * Runs conversion procedure.
  *
  * @return    string    Generated content
  */
 function runConversion()
 {
     $content = '';
     // Select all instances
     $res = $this->getDatabaseConnection()->exec_SELECTquery('uid,pid,pi_flexform', 'tt_content', 'list_type=\'irfaq_pi1\'' . BackendUtility::BEenableFields('tt_content') . BackendUtility::deleteClause('tt_content'));
     $results = $this->getDatabaseConnection()->sql_num_rows($res);
     $converted = 0;
     $data = array();
     $pidList = array();
     $replaceEmpty = intval(GeneralUtility::_GP('replaceEmpty'));
     /** @var \TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools $flexformtools */
     $flexformtools = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\FlexForm\\FlexFormTools');
     /* @var $flexformtools t3lib_flexformtools */
     $GLOBALS['TYPO3_CONF_VARS']['BE']['compactFlexFormXML'] = true;
     $GLOBALS['TYPO3_CONF_VARS']['BE']['niceFlexFormXMLtags'] = true;
     // Walk all rows
     while (false !== ($row = $this->getDatabaseConnection()->sql_fetch_assoc($res))) {
         $ffArray = GeneralUtility::xml2array($row['pi_flexform']);
         $modified = false;
         if (is_array($ffArray) && isset($ffArray['data']['sDEF'])) {
             foreach ($ffArray['data']['sDEF'] as $sLang => $sLdata) {
                 foreach ($this->fieldSet as $sheet => $fieldList) {
                     foreach ($fieldList as $field) {
                         if (isset($ffArray['data']['sDEF'][$sLang][$field]) && isset($ffArray['data']['sDEF'][$sLang][$field]['vDEF']) && strlen($ffArray['data']['sDEF'][$sLang][$field]['vDEF']) > 0 && (!isset($ffArray['data'][$sheet][$sLang][$field]) || !isset($ffArray['data'][$sheet][$sLang][$field]['vDEF']) || $replaceEmpty && strlen($ffArray['data'][$sheet][$sLang][$field]['vDEF']) == 0)) {
                             $ffArray['data'][$sheet][$sLang][$field]['vDEF'] = $ffArray['data']['sDEF'][$sLang][$field]['vDEF'];
                             if ($row['pid'] > 0) {
                                 $pidList[$row['pid']] = $row['pid'];
                             }
                             $modified = true;
                         }
                     }
                 }
             }
         }
         if ($modified) {
             // Assemble data back
             $data['tt_content'][$row['uid']] = array('pi_flexform' => $flexformtools->flexArray2Xml($ffArray));
             $converted++;
         }
     }
     $this->getDatabaseConnection()->sql_free_result($res);
     if ($converted > 0) {
         // Update data
         /** @var \TYPO3\CMS\Core\DataHandling\DataHandler $tce */
         $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
         /* @var $tce t3lib_TCEmain */
         $tce->start($data, null);
         $tce->process_datamap();
         if (count($tce->errorLog) > 0) {
             $content .= '<p>' . $this->lang->getLL('errors') . '</p><ul><li>' . implode('</li><li>', $tce->errorLog) . '</li></ul>';
         }
         // Clear cache
         foreach ($pidList as $pid) {
             $tce->clear_cacheCmd($pid);
         }
     }
     $content .= '<p>' . sprintf($this->lang->getLL('result'), $results, $converted) . '</p>';
     return $content;
 }
Exemplo n.º 9
0
 /**
  * Get the enable fields clause based on the table configuration
  *
  * @param string $tableName: the name of the table
  * @return string enable fileds clause
  */
 public static function getEnableFields($tableName)
 {
     if (TYPO3_MODE === 'FE') {
         $enableFields = $GLOBALS['TSFE']->sys_page->enableFields($tableName);
     } else {
         $enableFields = \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($tableName);
     }
 }
 /**
  * Check if BE user exists
  *
  * @param $username
  * @return bool
  */
 protected function beUserExists($username)
 {
     $table = 'be_users';
     if (0 < $this->getDatabaseConnection()->exec_SELECTcountRows('*', $table, 'username=' . $this->getDatabaseConnection()->fullQuoteStr($username, $table) . BackendUtility::deleteClause($table))) {
         return true;
     }
     return false;
 }
Exemplo n.º 11
0
 /**
  * Enable fields for BE and FE
  *
  * @param string $table
  *
  * @return string
  */
 public function enableFields($table)
 {
     $where = '';
     if (TYPO3_MODE === 'FE') {
         $where .= GeneralUtility::getTsFe()->sys_page->enableFields($table);
     } else {
         $where .= BackendUtility::BEenableFields($table);
         $where .= BackendUtility::deleteClause($table);
     }
     return $where;
 }
Exemplo n.º 12
0
 /**
  * add cities to selectbox.
  *
  * @param array                              $parentArray
  * @param \TYPO3\CMS\Backend\Form\FormEngine $fObj
  */
 public function addCityItems(array $parentArray, \TYPO3\CMS\Backend\Form\FormEngine $fObj)
 {
     $this->init();
     $rows = $this->database->exec_SELECTgetRows('city', 'tx_clubdirectory_domain_model_address', '1=1 ' . BackendUtility::BEenableFields('tx_clubdirectory_domain_model_address') . BackendUtility::deleteClause('tx_clubdirectory_domain_model_address'), 'city', 'city', '');
     foreach ($rows as $row) {
         $item = array();
         $item[0] = $row['city'];
         $item[1] = $row['city'];
         $item[2] = null;
         $parentArray['items'][] = $item;
     }
 }
Exemplo n.º 13
0
 /**
  * Check if the note plugin expects output. If there are no sys_note records on the given
  * pages, the extbase bootstrap doesn't have to run the complete plugin.
  * This mechanism should increase the performance of the hooked backend modules heavily.
  *
  * @param array $arguments Arguments for the extbase plugin
  * @return bool
  */
 protected function expectOutput(array $arguments = array())
 {
     // no pids set
     if (!isset($arguments['pids']) || empty($arguments['pids']) || empty($GLOBALS['BE_USER']->user['uid'])) {
         return false;
     }
     $pidList = $this->databaseConnection->cleanIntList($arguments['pids']);
     if (empty($pidList)) {
         return false;
     }
     // check if there are records
     return $this->databaseConnection->exec_SELECTcountRows('*', 'sys_note', 'pid IN (' . $pidList . ')' . BackendUtility::deleteClause('sys_note')) > 0;
 }
 /**
  * Fetch available page overlay records of page
  *
  * @param array $result
  * @return array
  */
 public function addData(array $result)
 {
     if ($result['effectivePid'] === 0) {
         // No overlays for records on pid 0 and not for new pages below root
         return $result;
     }
     $database = $this->getDatabase();
     $dbRows = $database->exec_SELECTgetRows('*', 'pages_language_overlay', 'pid=' . (int) $result['effectivePid'] . BackendUtility::deleteClause('pages_language_overlay') . BackendUtility::versioningPlaceholderClause('pages_language_overlay'));
     if ($dbRows === null) {
         throw new \UnexpectedValueException('Database query error ' . $database->sql_error(), 1440777705);
     }
     $result['pageLanguageOverlayRows'] = $dbRows;
     return $result;
 }
Exemplo n.º 15
0
 /**
  * Adds records to the export object for a specific page id.
  *
  * @param int $pid Page id for which to select records to add
  * @param array $tables Array of table names to select from
  * @return void
  */
 protected function addRecordsForPid($pid, array $tables)
 {
     foreach ($GLOBALS['TCA'] as $table => $value) {
         if ($table != 'pages' && (in_array($table, $tables) || in_array('_ALL', $tables))) {
             if ($GLOBALS['BE_USER']->check('tables_select', $table) && !$GLOBALS['TCA'][$table]['ctrl']['is_static']) {
                 $orderBy = $GLOBALS['TCA'][$table]['ctrl']['sortby'] ? 'ORDER BY ' . $GLOBALS['TCA'][$table]['ctrl']['sortby'] : $GLOBALS['TCA'][$table]['ctrl']['default_sortby'];
                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'pid = ' . (int) $pid . BackendUtility::deleteClause($table), '', $GLOBALS['TYPO3_DB']->stripOrderBy($orderBy));
                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                     $this->export->export_addRecord($table, $row);
                 }
             }
         }
     }
 }
Exemplo n.º 16
0
    /**
     * Find all sys_notes by a given pidlist
     *
     * @param string $pidlist comma separated list of pids
     * @return array records
     */
    public function findAllByPidList($pidlist)
    {
        $records = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'sys_note', 'pid IN (' . $GLOBALS['TYPO3_DB']->cleanIntList($pidlist) . ')
					AND (personal=0 OR cruser='******'BE_USER']->user['uid']) . ')' . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('sys_note'), '', 'sorting');
        // exec_SELECTgetRows can return NULL if the query failed. This is
        // transformed here to an empty array instead.
        if ($records === NULL) {
            $records = array();
        }
        foreach ($records as $key => $record) {
            $records[$key]['tstamp'] = new \DateTime('@' . $record['tstamp']);
            $records[$key]['author'] = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('be_users', $record['cruser']);
        }
        return $records;
    }
Exemplo n.º 17
0
 /**
  * @param string|array $uids
  * @param mixed $valueColumn See Arr::column
  * @param mixed $keyColumn See Arr::column
  * @return array|NULL
  * @throws \Exception
  */
 public function findByUids($uids, $valueColumn = NULL, $keyColumn = NULL)
 {
     $select = '*';
     $uids = Arr::commaListToArray($uids, "CategoryService expected uids to be a comma list or an array");
     if (empty($uids)) {
         return array();
     }
     $where = "uid IN (" . implode(',', $uids) . ') ' . BackendUtility::deleteClause(self::$categoryTable);
     $rows = $this->getDatabase()->exec_SELECTgetRows($select, self::$categoryTable, $where, '', 'sorting ASC');
     if (!is_array($rows) || empty($rows)) {
         return array();
     }
     if ($valueColumn || $keyColumn) {
         return Arr::column($rows, $valueColumn, $keyColumn);
     }
     return $rows;
 }
 /**
  * Prepares the list of frontend users.
  *
  * @param array $params
  * @param object $pObj
  */
 public function users(array &$params, $pObj)
 {
     if (GeneralUtility::inList('be_groups,fe_groups', $params['table'])) {
         $databaseConnection = $this->getDatabaseConnection();
         $userTable = $params['table'] === 'be_groups' ? 'be_users' : 'fe_users';
         /** @var \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList $recordList */
         $recordList = GeneralUtility::makeInstance('TYPO3\\CMS\\Recordlist\\RecordList\\AbstractDatabaseRecordList');
         $recordList->start(0, $userTable, 0);
         $queryParts = $recordList->makeQueryArray($userTable, 0);
         $queryParts['WHERE'] = '1=1' . BackendUtility::deleteClause($userTable);
         $result = $databaseConnection->exec_SELECT_queryArray($queryParts);
         while (($row = $databaseConnection->sql_fetch_assoc($result)) !== FALSE) {
             $label = BackendUtility::getRecordTitle($userTable, $row);
             $params['items'][] = array($label, $row['uid']);
         }
         $databaseConnection->sql_free_result($result);
     }
 }
Exemplo n.º 19
0
 /**
  * Finds an existing file.
  *
  * @param string $fileName
  * @return \TYPO3\CMS\Core\Resource\AbstractFile|null
  */
 protected static function findExistingFile($fileName)
 {
     $file = null;
     $relativePath = substr(PathUtility::dirname($fileName), strlen(PATH_site));
     $resourceFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
     $targetFolder = $resourceFactory->retrieveFileOrFolderObject($relativePath);
     $storageConfiguration = $targetFolder->getStorage()->getConfiguration();
     if (isset($storageConfiguration['basePath'])) {
         $basePath = rtrim($storageConfiguration['basePath'], '/') . '/';
         $basePath = GeneralUtility::getFileAbsFileName($basePath);
         $identifier = substr($fileName, strlen($basePath) - 1);
         $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('uid', 'sys_file', 'storage=' . intval($targetFolder->getStorage()->getUid()) . ' AND identifier=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($identifier, 'sys_file') . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('sys_file'));
         if (!empty($row['uid'])) {
             /** @var \TYPO3\CMS\Core\Resource\FileRepository $fileRepository */
             $fileRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\FileRepository::class);
             $file = $fileRepository->findByUid($row['uid']);
         }
     }
     return $file;
 }
Exemplo n.º 20
0
 /**
  * Fetch all modules displayed given a pid.
  *
  * @param int $pid
  * @return array
  */
 public function getModulesForPid($pid = NULL)
 {
     if (!isset($this->storage[$pid])) {
         $modules = array();
         foreach ($GLOBALS['TCA'] as $dataType => $configuration) {
             if (Tca::table($dataType)->isNotHidden()) {
                 $clause = 'pid = ' . $pid;
                 $clause .= BackendUtility::deleteClause($dataType);
                 $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('uid', $dataType, $clause);
                 if (!empty($record)) {
                     $moduleName = 'Vidi' . GeneralUtility::underscoredToUpperCamelCase($dataType) . 'M1';
                     $title = Tca::table($dataType)->getTitle();
                     $modules[$moduleName] = $title;
                 }
             }
         }
         $this->storage[$pid] = $modules;
     }
     return $this->storage[$pid];
 }
 /**
  * A plugin that renders a list of links to search results in other languages
  * The results are invisible by default and populated and shown by JavaScript
  */
 public function indexAction()
 {
     $currentLanguage = (int) $GLOBALS['TSFE']->sys_language_uid;
     // Get all system languages
     $systemLanguages = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_language', '1=1' . BackendUtility::deleteClause('sys_language') . ' AND uid NOT IN(' . $this->settings['excludedLanguages'] . ')');
     // We add the default language
     $systemLanguages[] = array('uid' => 0);
     $includedLanguages = array();
     $i = 0;
     foreach ($systemLanguages as $key => $systemLanguage) {
         if ((int) $systemLanguage['uid'] === $currentLanguage) {
             // We ignore the current language
             continue;
         }
         $includedLanguages[$i] = $this->getDataForLanguage($systemLanguage);
         $i++;
     }
     $this->view->assign('includedLanguages', $includedLanguages);
     $this->view->assign('currentPageId', (int) $GLOBALS['TSFE']->id);
 }
Exemplo n.º 22
0
 /**
  * Returns a localized record according to a Content object and a language identifier.
  * Notice! This method does not overlay anything but simply returns the raw localized record.
  *
  * @param Content $object
  * @param int $language
  * @return Content
  */
 public function getLocalizedContent(Content $object, $language)
 {
     // We want to cache data per Content object. Retrieve the Object hash.
     $objectHash = spl_object_hash($object);
     // Initialize the storage
     if (empty($this->localizedRecordStorage[$objectHash])) {
         $this->localizedRecordStorage[$objectHash] = array();
     }
     if (empty($this->localizedRecordStorage[$objectHash][$language])) {
         $clause = sprintf('%s = %s AND %s = %s', Tca::table($object)->getLanguageParentField(), $object->getUid(), Tca::table($object)->getLanguageField(), $language);
         $clause .= BackendUtility::deleteClause($object->getDataType());
         $localizedRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', $object->getDataType(), $clause);
         if ($localizedRecord) {
             $localizedContent = GeneralUtility::makeInstance('Fab\\Vidi\\Domain\\Model\\Content', $object->getDataType(), $localizedRecord);
             $this->localizedRecordStorage[$objectHash][$language] = $localizedContent;
         } else {
             $this->localizedRecordStorage[$objectHash][$language] = array();
             // We want an array at least, even if empty.
         }
     }
     return $this->localizedRecordStorage[$objectHash][$language];
 }
 /**
  * Try to retrieve all reference objects
  *
  * @param integer $uid
  * @param string $table
  * @param string $field
  * @return array<\TYPO3\CMS\Core\Resource\FileReference>
  */
 public static function getReferenceObjects($uid, $table, $field)
 {
     $fileReferenceObjects = array();
     /** @var \TYPO3\CMS\Core\Database\DatabaseConnection $database */
     $database =& $GLOBALS['TYPO3_DB'];
     $references = $database->exec_SELECTgetRows('uid', 'sys_file_reference', 'tablenames = ' . $database->fullQuoteStr($table, 'sys_file_reference') . ' AND fieldname=' . $database->fullQuoteStr($field, 'sys_file_reference') . ' AND uid_foreign=' . intval($uid) . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('sys_file_reference') . \TYPO3\CMS\Backend\Utility\BackendUtility::versioningPlaceholderClause('sys_file_reference'));
     if (!empty($references)) {
         foreach ($references as $reference) {
             $referenceUid = (int) $reference['uid'];
             if ($referenceUid > 0) {
                 try {
                     $referenceObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->getFileReferenceObject($referenceUid);
                     if ($referenceObject instanceof \TYPO3\CMS\Core\Resource\FileReference) {
                         $fileReferenceObjects[] = $referenceObject;
                     }
                 } catch (\Exception $e) {
                 }
             }
         }
     }
     return $fileReferenceObjects;
 }
 /**
  * @param int    $id
  * @param int    $depth
  * @param int    $begin
  * @param int    $perms_clause
  * @param string $table
  * @param string $field
  * @param string $fields
  *
  * @return string Comma seperated list of uids
  */
 public function getTreeListOfAnyTable($id, $depth = 99, $begin = 0, $perms_clause = 1, $table = 'sys_category', $field = 'parent', $fields = 'uid')
 {
     $depth = intval($depth);
     $begin = intval($begin);
     $id = intval($id);
     if ($begin == 0) {
         $theList = $id;
     } else {
         $theList = '';
     }
     if ($id && $depth > 0) {
         $res = $this->getDatabaseConnection()->exec_SELECTquery($fields, $table, $field . '=' . $id . ' ' . BackendUtility::deleteClause($table) . ' AND ' . $perms_clause);
         while ($row = $this->getDatabaseConnection()->sql_fetch_assoc($res)) {
             if ($begin <= 0) {
                 $theList .= ',' . $row['uid'];
             }
             if ($depth > 1) {
                 $theList .= $this->getTreeListOfAnyTable($row['uid'], $depth - 1, $begin - 1, $perms_clause, $table, $field, $fields);
             }
         }
     }
     return $theList;
 }
Exemplo n.º 25
0
 public function run($time, $notificationEmail, $testRunner)
 {
     $this->isTestRunner = $testRunner;
     $timestamp = $this->convertToTimeStamp($time);
     $this->sendNotificationEmail = !empty($notificationEmail);
     // update alle user
     // welche NICHT Administratoren sind
     // und einen lastlogin kleiner/gleich $timestamp haben
     // und lastlogin NICHT 0 ist -> die haben sich noch nicht eingeloggt
     // und nicht mit '_cli' beginnen
     $normalUser = '******' . ' AND lastLogin <=' . (int) $timestamp . ' AND lastLogin!=0' . ' AND username NOT LIKE "_cli_%"' . BackendUtility::deleteClause('be_users') . BackendUtility::BEenableFields('be_users');
     $this->disableUser($normalUser);
     // update alle user
     // welche NICHT Administratoren sind
     // und einen lastlogin GLEICH 0 haben -> die haben sich noch nicht eingeloggt
     // UND ein Erstellungsdatum kleiner/gleich $timestamp haben
     // und nicht mit '_cli' beginnen
     $userNeverLoggedIn = '  admin=0
                             AND lastLogin = 0' . ' AND donotdisable=0' . ' AND crdate <=' . (int) $timestamp . ' AND username NOT LIKE "_cli_%"' . BackendUtility::deleteClause('be_users') . BackendUtility::BEenableFields('be_users');
     $this->disableUser($userNeverLoggedIn);
     return $this->manageMailTransport($notificationEmail);
 }
 /**
  * Fetch a record from database. Deleted records will NOT be fetched.
  * Method is similar to BackendUtility::getRecord, but is more picky
  * about input and result.
  *
  * @param string $tableName The table name to fetch record from
  * @param int $uid Uid of record to fetch
  * @return array Fetched record row
  * @throws DatabaseRecordException|\InvalidArgumentException|\UnexpectedValueException|\RuntimeException
  */
 protected function getRecordFromDatabase($tableName, $uid)
 {
     if ($uid <= 0) {
         throw new \InvalidArgumentException('$uid must be positive integer, ' . $uid . ' given', 1437656456);
     }
     $database = $this->getDatabase();
     $tableName = $database->quoteStr($tableName, $tableName);
     $where = 'uid=' . (int) $uid . BackendUtility::deleteClause($tableName);
     $row = $database->exec_SELECTgetSingleRow('*', $tableName, $where);
     if ($row === null) {
         // Indicates a program / usage error
         throw new \RuntimeException('Database error fetching record from tablename ' . $tableName . ' with uid ' . $uid, 1437655862);
     }
     if ($row === false) {
         // Indicates a runtime error (eg. record was killed by other editor meanwhile) can be caught elsewhere
         // and transformed to a message to the user or something
         throw new DatabaseRecordException('Record with uid ' . $uid . ' from table ' . $tableName . ' not found', 1437656081);
     }
     if (!is_array($row)) {
         // Database connection behaves weird ...
         throw new \UnexpectedValueException('Database exec_SELECTgetSingleRow() did not return error type or result', 1437656323);
     }
     return $row;
 }
 /**
  * Generate a different preview link     *
  *
  * @param string                   $status       status
  * @param string                   $table        table name
  * @param integer                  $recordUid    id of the record
  * @param array                    $fields       fieldArray
  * @param DataHandling\DataHandler $parentObject parent Object
  *
  * @return void
  */
 public function processDatamap_afterDatabaseOperations($status, $table, $recordUid, array $fields, DataHandling\DataHandler $parentObject)
 {
     if (in_array($status, array('new', 'update')) && !in_array($table, array('tt_content', 'pages', 'sys_file_reference'))) {
         $record = BackendUtility::getRecord($table, $recordUid);
         if ((int) $record['sys_language_uid'] > 0) {
             // Ref Parent depend of context
             $uidForeign = $table === 'pages_language_overlay' ? (int) $record['pid'] : (int) $record['l10n_parent'];
             $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('fieldname', 'sys_file_reference', "tablenames='{$table}' AND uid_foreign=" . $uidForeign . BackendUtility::deleteClause('sys_file_reference'), 'fieldname', 'fieldname');
             $fieldnames = array();
             foreach ($rows as $row) {
                 $fieldnames[] = $row['fieldname'];
             }
             foreach ($fieldnames as $fieldname) {
                 $references = BackendUtility::getRecordsByField('sys_file_reference', 'tablenames', $table, 'AND uid_foreign=' . $recordUid . " AND fieldname='{$fieldname}'", '', 'sorting ASC');
                 $l10nParents = BackendUtility::getRecordsByField('sys_file_reference', 'uid_foreign', $uidForeign, " AND fieldname='{$fieldname}'", '', 'sorting ASC');
                 if ($references) {
                     for ($i = 0; count($references) > $i; $i++) {
                         $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_file_reference', 'uid=' . $references[$i]['uid'], array('sys_language_uid' => $record['sys_language_uid'], 'l10n_parent' => isset($l10nParents[$i]) && isset($l10nParents[$i]['uid']) ? $l10nParents[$i]['uid'] : 0));
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 28
0
 /**
  * Get the count of news records by month/year and
  * returns the result compiled as array
  *
  * @param DemandInterface $demand
  * @return array
  */
 public function countByDate(DemandInterface $demand)
 {
     $data = [];
     $sql = $this->findDemandedRaw($demand);
     // Get the month/year into the result
     $field = $demand->getDateField();
     $field = empty($field) ? 'datetime' : $field;
     $sql = 'SELECT FROM_UNIXTIME(' . $field . ', "%m") AS "_Month",' . ' FROM_UNIXTIME(' . $field . ', "%Y") AS "_Year" ,' . ' count(FROM_UNIXTIME(' . $field . ', "%m")) as count_month,' . ' count(FROM_UNIXTIME(' . $field . ', "%y")) as count_year' . ' FROM tx_news_domain_model_news ' . substr($sql, strpos($sql, 'WHERE '));
     if (TYPO3_MODE === 'FE') {
         $sql .= $GLOBALS['TSFE']->sys_page->enableFields('tx_news_domain_model_news');
     } else {
         $sql .= \TYPO3\CMS\Backend\Utility\BackendUtility::BEenableFields('tx_news_domain_model_news') . \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('tx_news_domain_model_news');
     }
     // strip unwanted order by
     $sql = $GLOBALS['TYPO3_DB']->stripOrderBy($sql);
     // group by custom month/year fields
     $orderDirection = strtolower($demand->getOrder());
     if ($orderDirection !== 'desc' && $orderDirection != 'asc') {
         $orderDirection = 'asc';
     }
     $sql .= ' GROUP BY _Month, _Year ORDER BY _Year ' . $orderDirection . ', _Month ' . $orderDirection;
     $res = $GLOBALS['TYPO3_DB']->sql_query($sql);
     while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
         $data['single'][$row['_Year']][$row['_Month']] = $row['count_month'];
     }
     $GLOBALS['TYPO3_DB']->sql_free_result($res);
     // Add totals
     if (is_array($data['single'])) {
         foreach ($data['single'] as $year => $months) {
             $countOfYear = 0;
             foreach ($months as $month) {
                 $countOfYear += $month;
             }
             $data['total'][$year] = $countOfYear;
         }
     }
     return $data;
 }
Exemplo n.º 29
0
 /**
  * Fetched fresh storage records from database because the new imported
  * ones are not in cached data of the StorageRepository
  *
  * @return bool|array
  */
 protected function fetchStorageRecords()
 {
     $whereClause = BackendUtility::BEenableFields('sys_file_storage');
     $whereClause .= BackendUtility::deleteClause('sys_file_storage');
     $rows = $this->getDatabaseConnection()->exec_SELECTgetRows('*', 'sys_file_storage', '1=1' . $whereClause, '', '', '', 'uid');
     return $rows;
 }
Exemplo n.º 30
0
    /**
     * Creates a menu of the tables that can be listed by this function
     * Only tables which has records on the page will be included.
     * Notice: The function also fills in the internal variable $this->activeTables with icon/titles.
     *
     * @param int $id Page id from which we are listing records (the function will look up if there are records on the page)
     * @return string HTML output.
     */
    public function getTableMenu($id)
    {
        // Initialize:
        $this->activeTables = array();
        $theTables = array('tt_content');
        // External tables:
        if (is_array($this->externalTables)) {
            $theTables = array_unique(array_merge($theTables, array_keys($this->externalTables)));
        }
        $out = '';
        // Traverse tables to check:
        foreach ($theTables as $tName) {
            // Check access and whether the proper extensions are loaded:
            if ($this->getBackendUser()->check('tables_select', $tName) && (isset($this->externalTables[$tName]) || GeneralUtility::inList('fe_users,tt_content', $tName) || \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($tName))) {
                // Make query to count records from page:
                $c = $this->getDatabase()->exec_SELECTcountRows('uid', $tName, 'pid=' . (int) $id . BackendUtility::deleteClause($tName) . BackendUtility::versioningPlaceholderClause($tName));
                // If records were found (or if "tt_content" is the table...):
                if ($c || GeneralUtility::inList('tt_content', $tName)) {
                    // Add row to menu:
                    $out .= '
					<td><a href="#' . $tName . '" title="' . $this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'], true) . '"></a>' . $this->iconFactory->getIconForRecord($tName, array(), Icon::SIZE_SMALL)->render() . '</td>';
                    // ... and to the internal array, activeTables we also add table icon and title (for use elsewhere)
                    $title = $this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'], true) . ': ' . $c . ' ' . $this->getLanguageService()->getLL('records', true);
                    $this->activeTables[$tName] = '<span title="' . $title . '">' . $this->iconFactory->getIconForRecord($tName, array(), Icon::SIZE_SMALL)->render() . '</span>' . '&nbsp;' . $this->getLanguageService()->sL($GLOBALS['TCA'][$tName]['ctrl']['title'], true);
                }
            }
        }
        // Wrap cells in table tags:
        $out = '
            <!--
                Menu of tables on the page (table menu)
            -->
            <table border="0" cellpadding="0" cellspacing="0" id="typo3-page-tblMenu">
				<tr>' . $out . '
                </tr>
			</table>';
        // Return the content:
        return $out;
    }