Esempio n. 1
0
 /**
  * Find the Live-Uid for a given page,
  * the results are cached at run-time to avoid too many database-queries
  *
  * @throws InvalidArgumentException
  * @param  $uid
  * @return void
  */
 protected function getLivePageUid($uid)
 {
     if (!isset(self::$pageCache[$uid])) {
         $rec = t3lib_beFunc::getRecord('pages', $uid);
         if (is_array($rec)) {
             self::$pageCache[$uid] = $rec['t3ver_oid'] ? $rec['t3ver_oid'] : $uid;
         } else {
             throw new InvalidArgumentException('uid is supposed to point to an existing page - given value was:' . $uid, 1290628113);
         }
     }
     return self::$pageCache[$uid];
 }
 function main()
 {
     $content = '<html><body>';
     $conf = t3lib_div::_GP('P');
     $conf['md5ID'];
     if ($conf['table'] == 'tx_datasources_datasource') {
         $dsRecord = t3lib_beFunc::getRecord($conf['table'], intval($conf['uid']));
         if (is_array($dsRecord)) {
             $dsArr = t3lib_div::xml2array($dsRecord['configuration']);
             $dsConf = $dsArr['data']['sDEF']['lDEF'];
             $content .= '<p>Trying to connect with Host / DSN <strong>' . htmlspecialchars($dsConf['field_host']['vDEF']) . '</strong> with user <strong>' . htmlspecialchars($dsConf['field_username']['vDEF']) . '</strong> ... ';
             $dbConn =& ADONewConnection($dsConf['field_dbtype']['vDEF']);
             $dbConn->PConnect($dsConf['field_host']['vDEF'], $dsConf['field_username']['vDEF'], $dsConf['field_password']['vDEF'], $dsConf['field_dbname']['vDEF']);
             $dbConn->SetFetchMode(ADODB_FETCH_ASSOC);
             $content .= $dbConn->ErrorMsg();
             if ($dbConn->_connectionID) {
                 $content .= '</p>';
                 $query = 'SELECT * FROM ' . $dsConf['field_table']['vDEF'];
                 $recordSet =& $dbConn->SelectLimit($query, 150);
                 if (!$recordSet) {
                     $content .= '<p>Query failed (' . htmlspecialchars($query) . '):<br />';
                     $content .= $dbConn->ErrorMsg() . '</p>';
                 } else {
                     $content .= '<span style="color:green">successful!</span></p>';
                     $counter = 0;
                     $content .= '<p>Showing the first 150 entries from the result recordset:</p>';
                     $content .= '<table border="1">';
                     while (!$recordSet->EOF) {
                         $content .= '<tr>';
                         if ($counter == 0) {
                             foreach (array_keys($recordSet->fields) as $key) {
                                 $content .= '<th>' . htmlspecialchars($key) . '</th>';
                             }
                             $content .= '</tr><tr>';
                         }
                         foreach (array_values($recordSet->fields) as $value) {
                             $content .= '<td>' . htmlspecialchars($value) . '&nbsp;</td>';
                         }
                         $recordSet->MoveNext();
                         $counter++;
                         $content .= '</tr>';
                     }
                     $content .= '<table>';
                 }
             }
         } else {
             $content .= '<span style="color:red">failed!</span></p><p><strong>Error Message:</strong>' . $dbConn->ErrorMsg() . '</p>';
         }
     }
     $content .= '</body></html>';
     echo $content;
 }
 /**
  * Main function, adding items to the click menu array.
  *
  * @param	object		Reference to the parent object of the clickmenu class which calls this function
  * @param	array		The current array of menu items - you have to add or remove items to this array in this function. Thats the point...
  * @param	string		The database table OR filename
  * @param	integer		For database tables, the UID
  * @return	array		The modified menu array.
  */
 function main(&$backRef, $menuItems, $table, $uid)
 {
     global $BE_USER, $LANG, $TYPO3_DB;
     $localItems = array();
     if (!$backRef->cmLevel) {
         $LL = $LANG->includeLLFile(t3lib_extMgm::extPath('templavoila') . 'locallang.xml', 0);
         // Adding link for Mapping tool:
         if (@is_file($table)) {
             if ($BE_USER->isAdmin()) {
                 if (function_exists('finfo_open')) {
                     $finfoMode = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
                     $fi = finfo_open($finfoMode);
                     $mimeInformation = @finfo_file($fi, $table);
                     $enabled = FALSE;
                     if (t3lib_div::isFirstPartOfStr($mimeInformation, 'text/html') || t3lib_div::isFirstPartOfStr($mimeInformation, 'application/xml')) {
                         $enabled = TRUE;
                     }
                     finfo_close($fi);
                 } else {
                     $pi = @pathinfo($table);
                     $enabled = preg_match('/(html?|tmpl|xml)/', $pi['extension']);
                 }
                 if ($enabled) {
                     $url = t3lib_extMgm::extRelPath('templavoila') . 'cm1/index.php?file=' . rawurlencode($table);
                     $localItems[] = $backRef->linkItem($LANG->getLLL('cm1_title', $LL, 1), $backRef->excludeIcon('<img src="' . $backRef->backPath . t3lib_extMgm::extRelPath('templavoila') . 'cm1/cm_icon.gif" width="15" height="12" border="0" align="top" alt="" />'), $backRef->urlRefForCM($url, 'returnUrl'), 1);
                 }
             }
         } elseif (t3lib_div::inList('tx_templavoila_tmplobj,tx_templavoila_datastructure,tx_templavoila_content', $table)) {
             $url = t3lib_extMgm::extRelPath('templavoila') . 'cm1/index.php?table=' . rawurlencode($table) . '&uid=' . $uid . '&_reload_from=1';
             $localItems[] = $backRef->linkItem($LANG->getLLL('cm1_title', $LL, 1), $backRef->excludeIcon('<img src="' . $backRef->backPath . t3lib_extMgm::extRelPath('templavoila') . 'cm1/cm_icon.gif" width="15" height="12" border="0" align="top" alt="" />'), $backRef->urlRefForCM($url, 'returnUrl'), 1);
         }
         $isTVelement = ('tt_content' == $table && $backRef->rec['CType'] == 'templavoila_pi1' || 'pages' == $table) && $backRef->rec['tx_templavoila_flex'];
         // Adding link for "View: Sub elements":
         if ($table == 'tt_content' && $isTVelement) {
             $localItems = array();
             $url = t3lib_extMgm::extRelPath('templavoila') . 'mod1/index.php?id=' . intval($backRef->rec['pid']) . '&altRoot[table]=' . rawurlencode($table) . '&altRoot[uid]=' . $uid . '&altRoot[field_flex]=tx_templavoila_flex';
             $localItems[] = $backRef->linkItem($LANG->getLLL('cm1_viewsubelements', $LL, 1), $backRef->excludeIcon('<img src="' . $backRef->backPath . t3lib_extMgm::extRelPath('templavoila') . 'cm1/cm_icon.gif" width="15" height="12" border="0" align="top" alt="" />'), $backRef->urlRefForCM($url, 'returnUrl'), 1);
         }
         // Adding link for "View: Flexform XML" (admin only):
         if ($BE_USER->isAdmin() && $isTVelement) {
             $url = t3lib_extMgm::extRelPath('templavoila') . 'cm2/index.php?' . '&viewRec[table]=' . rawurlencode($table) . '&viewRec[uid]=' . $uid . '&viewRec[field_flex]=tx_templavoila_flex';
             $localItems[] = $backRef->linkItem($LANG->getLLL('cm1_viewflexformxml', $LL, 1), $backRef->excludeIcon('<img src="' . $backRef->backPath . t3lib_extMgm::extRelPath('templavoila') . 'cm2/cm_icon.gif" width="15" height="12" border="0" align="top" alt="" />'), $backRef->urlRefForCM($url, 'returnUrl'), 1);
         }
         // Adding link for "View: DS/TO" (admin only):
         if ($BE_USER->isAdmin() && $isTVelement) {
             if (tx_templavoila_div::canBeInterpretedAsInteger($backRef->rec['tx_templavoila_ds'])) {
                 $url = t3lib_extMgm::extRelPath('templavoila') . 'cm1/index.php?' . 'table=tx_templavoila_datastructure&uid=' . $backRef->rec['tx_templavoila_ds'];
                 $localItems[] = $backRef->linkItem($LANG->getLLL('cm_viewdsto', $LL, 1) . ' [' . $backRef->rec['tx_templavoila_ds'] . '/' . $backRef->rec['tx_templavoila_to'] . ']', $backRef->excludeIcon('<img src="' . $backRef->backPath . t3lib_extMgm::extRelPath('templavoila') . 'cm2/cm_icon.gif" width="15" height="12" border="0" align="top" alt="" />'), $backRef->urlRefForCM($url, 'returnUrl'), 1);
             }
         }
         #			if ($table=='tt_content') {
         #					// Adding link for "Pages using this element":
         #				$localItems[] = $backRef->linkItem(
         #					$LANG->getLLL('cm1_pagesusingthiselement',$LL),
         #					$backRef->excludeIcon('<img src="'.t3lib_extMgm::extRelPath('templavoila').'cm1/cm_icon_activate.gif" width="15" height="12" border=0 align=top>'),
         #					"top.loadTopMenu('".t3lib_div::linkThisScript()."&cmLevel=1&subname=tx_templavoila_cm1_pagesusingthiselement');return false;",
         #					0,
         #					1
         #				);
         #			}
     } else {
         if (t3lib_div::_GP('subname') == 'tx_templavoila_cm1_pagesusingthiselement') {
             $menuItems = array();
             $url = t3lib_extMgm::extRelPath('templavoila') . 'mod1/index.php?id=';
             // Generate a list of pages where this element is also being used:
             $res = $TYPO3_DB->exec_SELECTquery('*', 'tx_templavoila_elementreferences', 'uid=' . $backRef->rec['uid']);
             if ($res) {
                 while (false != ($referenceRecord = $TYPO3_DB->sql_fetch_assoc($res))) {
                     $pageRecord = t3lib_beFunc::getRecord('pages', $referenceRecord['pid']);
                     $icon = t3lib_iconWorks::getSpriteIconForRecord('pages', $pageRecord);
                     // To do: Display language flag icon and jump to correct language
                     #						if ($referenceRecord['lkey'] != 'lDEF') {
                     #							$icon .= ' lKey:'.$referenceRecord['lkey'];
                     #						} elseif ($referenceRecord['vkey'] != 'vDEF') {
                     #							$icon .= ' vKey:'.$referenceRecord['vkey'];
                     #						}
                     if (is_array($pageRecord)) {
                         $menuItems[] = $backRef->linkItem($icon, t3lib_beFunc::getRecordTitle('pages', $pageRecord, 1), $backRef->urlRefForCM($url . $pageRecord['uid'], 'returnUrl'), 1);
                     }
                 }
             }
         }
     }
     // Simply merges the two arrays together and returns ...
     if (count($localItems)) {
         $menuItems = array_merge($menuItems, $localItems);
     }
     return $menuItems;
 }
 /**
  * Returns true if the current backend user has write access to the note specified by $uid
  *
  * @param	integer		$uid: The note UID
  * @param	object		&$reference: Reference to the page module
  * @return	boolean		true if the current BE user may write / delete the specified note record
  * @access private
  */
 function internal_checkWriteAccess($uid, &$reference)
 {
     $noteRecord = t3lib_beFunc::getRecord('tx_rlmptvnotes_notes', $uid);
     if (is_array($noteRecord)) {
         $pageInfoArr = t3lib_BEfunc::readPageAccess($noteRecord['pid'], $reference->perms_clause);
         return $pageInfoArr['uid'] > 0;
     }
     return false;
 }
 /**
  * A function which can be used for load a batch of records from $table into internal memory of this object.
  * The function is also used to produce proper default data for new records
  * Ultimately the function will call renderRecord()
  *
  * @param	string		Table name, must be found in $TCA
  * @param	string		Comma list of id values. If $idList is "prev" then the value from $this->prevPageID is used. NOTICE: If $operation is "new", then negative ids are meant to point to a "previous" record and positive ids are PID values for new records. Otherwise (for existing records that is) it is straight forward table/id pairs.
  * @param	string		If "new", then a record with default data is returned. Further, the $id values are meant to be PID values (or if negative, pointing to a previous record). If NOT new, then the table/ids are just pointing to an existing record!
  * @return	void
  * @see renderRecord()
  */
 function fetchRecord($table, $idList, $operation)
 {
     global $TCA;
     if ((string) $idList == 'prev') {
         $idList = $this->prevPageID;
     }
     if ($TCA[$table]) {
         t3lib_div::loadTCA($table);
         // For each ID value (integer) we
         $ids = t3lib_div::trimExplode(',', $idList, 1);
         foreach ($ids as $id) {
             if (strcmp($id, '')) {
                 // If ID is not blank:
                 // For new records to be created, find default values:
                 if ($operation == 'new') {
                     // Default values:
                     $newRow = array();
                     // Used to store default values as found here:
                     // Default values as set in userTS:
                     $TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');
                     if (is_array($TCAdefaultOverride[$table . '.'])) {
                         foreach ($TCAdefaultOverride[$table . '.'] as $theF => $theV) {
                             if (isset($TCA[$table]['columns'][$theF])) {
                                 $newRow[$theF] = $theV;
                             }
                         }
                     }
                     if ($id < 0) {
                         $record = t3lib_beFunc::getRecord($table, abs($id), 'pid');
                         $pid = $record['pid'];
                         unset($record);
                     } else {
                         $pid = intval($id);
                     }
                     $pageTS = t3lib_beFunc::getPagesTSconfig($pid);
                     if (isset($pageTS['TCAdefaults.'])) {
                         $TCAPageTSOverride = $pageTS['TCAdefaults.'];
                         if (is_array($TCAPageTSOverride[$table . '.'])) {
                             foreach ($TCAPageTSOverride[$table . '.'] as $theF => $theV) {
                                 if (isset($TCA[$table]['columns'][$theF])) {
                                     $newRow[$theF] = $theV;
                                 }
                             }
                         }
                     }
                     // Default values as submitted:
                     if (is_array($this->defVals[$table])) {
                         foreach ($this->defVals[$table] as $theF => $theV) {
                             if (isset($TCA[$table]['columns'][$theF])) {
                                 $newRow[$theF] = $theV;
                             }
                         }
                     }
                     // Fetch default values if a previous record exists
                     if ($id < 0 && $TCA[$table]['ctrl']['useColumnsForDefaultValues']) {
                         // Fetches the previous record:
                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid=' . abs($id) . t3lib_BEfunc::deleteClause($table));
                         if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                             // Gets the list of fields to copy from the previous record.
                             $fArr = t3lib_div::trimExplode(',', $TCA[$table]['ctrl']['useColumnsForDefaultValues'], 1);
                             foreach ($fArr as $theF) {
                                 if (isset($TCA[$table]['columns'][$theF])) {
                                     $newRow[$theF] = $row[$theF];
                                 }
                             }
                         }
                         $GLOBALS['TYPO3_DB']->sql_free_result($res);
                     }
                     // Finally, call renderRecord:
                     $this->renderRecord($table, uniqid('NEW'), $id, $newRow);
                 } else {
                     $id = intval($id);
                     // Fetch database values
                     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid=' . intval($id) . t3lib_BEfunc::deleteClause($table));
                     if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                         t3lib_BEfunc::fixVersioningPid($table, $row);
                         $this->renderRecord($table, $id, $row['pid'], $row);
                         $contentTable = $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'];
                         $this->lockRecord($table, $id, $contentTable == $table ? $row['pid'] : 0);
                         // Locking the pid if the table edited is the content table.
                     }
                     $GLOBALS['TYPO3_DB']->sql_free_result($res);
                 }
             }
         }
     }
 }
 /**
  * Finds the currently selected template object by climbing up the root line.
  *
  * @param	array		$row: A page record
  * @return	mixed		The template object record or FALSE if none was found
  * @access	protected
  */
 function getContentTree_fetchPageTemplateObject($row)
 {
     $templateObjectUid = $row['tx_templavoila_ds'] ? intval($row['tx_templavoila_to']) : 0;
     if (!$templateObjectUid) {
         $rootLine = t3lib_beFunc::BEgetRootLine($row['uid'], '', TRUE);
         foreach ($rootLine as $rootLineRecord) {
             $pageRecord = t3lib_beFunc::getRecord('pages', $rootLineRecord['uid']);
             if ($row['uid'] != $pageRecord['uid'] && $pageRecord['tx_templavoila_next_ds'] && $pageRecord['tx_templavoila_next_to']) {
                 // If there is a next-level TO:
                 $templateObjectUid = $pageRecord['tx_templavoila_next_to'];
                 break;
             } elseif ($pageRecord['tx_templavoila_ds'] && $pageRecord['tx_templavoila_to']) {
                 // Otherwise try the NORMAL TO:
                 $templateObjectUid = $pageRecord['tx_templavoila_to'];
                 break;
             }
         }
     }
     return t3lib_beFunc::getRecordWSOL('tx_templavoila_tmplobj', $templateObjectUid);
 }
Esempio n. 7
0
 /**
  * Remove all records which are not permitted for the user
  *
  * @param array $recs
  * @param string $table
  * @return array
  */
 protected function filterPermittedElements($recs, $table)
 {
     $checkField = $table == 'pages' ? 'uid' : 'wspid';
     $permittedElements = array();
     if (is_array($recs)) {
         foreach ($recs as $rec) {
             $page = t3lib_beFunc::getRecord('pages', $rec[$checkField], 'uid,pid,perms_userid,perms_user,perms_groupid,perms_group,perms_everybody');
             if ($GLOBALS['BE_USER']->doesUserHaveAccess($page, 1)) {
                 $permittedElements[] = $rec;
             }
         }
     }
     return $permittedElements;
 }
	/**
	 * This method is called by a hook in the TYPO3 Core Engine (TCEmain).
	 *
	 * @param	string		$status: The TCEmain operation status, fx. 'update'
	 * @param	string		$table: The table TCEmain is currently processing
	 * @param	string		$id: The records id (if any)
	 * @param	array		$fieldArray: The field names and their values to be processed
	 * @param	object		$reference: Reference to the parent object (TCEmain)
	 * @return	void
	 * @access	public
	 * @todo	"delete" should search for all references to the element.
	 */
	function processCmdmap_preProcess (&$command, $table, $id, $value, &$reference) {

		if ($this->debug) t3lib_div::devLog('processCmdmap_preProcess', 'templavoila', 0, array ($command, $table, $id, $value));
		if ($GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['tx_templavoila_api']['apiIsRunningTCEmain']) return;
		if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tx_templavoila_tcemain']['doNotInsertElementRefsToPage'])) {
			$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tx_templavoila_tcemain']['doNotInsertElementRefsToPage']++;
		}
		else {
			$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tx_templavoila_tcemain']['doNotInsertElementRefsToPage'] = 1;
		}

		if ($table != 'tt_content') return;

		$templaVoilaAPI = t3lib_div::makeInstance('tx_templavoila_api');

		switch ($command) {
			case 'delete' :
				$record = t3lib_beFunc::getRecord('tt_content', $id);
					// Check for FCE access
				$params = array(
					'table' => $table,
					'row' => $record,
				);
				$ref = null;
				if (!t3lib_div::callUserFunction('EXT:templavoila/class.tx_templavoila_access.php:&tx_templavoila_access->recordEditAccessInternals', $params, $ref)) {
					$reference->newlog(sprintf($GLOBALS['LANG']->getLL($status != 'new' ? 'access_noModifyAccess' : 'access_noCrateAccess'), $table, $id), 1);
					$command = '';	// Do not delete! A hack but there is no other way to prevent deletion...
				}
				else {
					if (intval($record['t3ver_oid']) > 0 && $record['pid'] == -1) {
							// we unlink a offline version in a workspace
						if (abs($record['t3ver_wsid']) !== 0) {
							$record = t3lib_BEfunc::getRecord('tt_content', intval($record['t3ver_oid']));
						}
					}
						// avoid that deleting offline version in the live workspace unlinks the online version - see #11359 
					if ($record['uid'] && $record['pid']) {
						$sourceFlexformPointersArr = $templaVoilaAPI->flexform_getPointersByRecord($record['uid'], $record['pid']);
						$sourceFlexformPointer = $sourceFlexformPointersArr[0];
						$templaVoilaAPI->unlinkElement($sourceFlexformPointer);
					}
				}
				break;
			case 'copy':
				unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tx_templavoila_tcemain']['doNotInsertElementRefsToPage']);
				break;
		}
		if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tx_templavoila_tcemain']['doNotInsertElementRefsToPage'])) {
			$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tx_templavoila_tcemain']['doNotInsertElementRefsToPage']--;
		}
	}