/**
  * @param string $delimiter Delimiter string to explode with
  * @param string $string The string to explode
  * @param int $count Number of array entries
  * @return array Exploded values
  */
 public function revExplode($delimiter, $string, $count = 0)
 {
     /** @noinspection PhpDeprecationInspection PhpUndefinedClassInspection */
     return t3lib_div::revExplode($delimiter, $string, $count);
 }
	/**
	 * Decodes the file name and adjusts file parts accordingly
	 *
	 * @param array $pathParts Path parts of the URLs (can be modified)
	 * @return array GET varaibles from the file name or empty array
	 */
	protected function decodeSpURL_decodeFileName(array &$pathParts) {
		$getVars = array();
		$fileName = array_pop($pathParts);
		$fileParts = t3lib_div::revExplode('.', $fileName, 2);
		if (count($fileParts) == 2 && !$fileParts[1]) {
			$this->decodeSpURL_throw404('File "' . $fileName . '" was not found (2)!');
		}
		list($segment, $extension) = $fileParts;
		if ($extension) {
			$getVars = array();
			if (!$this->decodeSpURL_decodeFileName_lookupInIndex($fileName, $segment, $extension, $pathParts, $getVars)) {
				if (!$this->decodeSpURL_decodeFileName_checkHtmlSuffix($fileName, $segment, $extension, $pathParts)) {
					$this->decodeSpURL_throw404('File "' . $fileName . '" was not found (1)!');
				}
			}
		}
		elseif ($fileName != '') {
			$pathParts[] = $fileName;
		}
		return $getVars;
	}
 /**
  * Where-clause for free index-uid value.
  *
  * @param	integer		Free Index UID value to limit search to.
  * @return	string		WHERE SQL clause part.
  */
 function freeIndexUidWhere($freeIndexUid)
 {
     if ($freeIndexUid >= 0) {
         // First, look if the freeIndexUid is a meta configuration:
         list($indexCfgRec) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('indexcfgs', 'index_config', 'type=5 AND uid=' . intval($freeIndexUid) . $this->cObj->enableFields('index_config'));
         if (is_array($indexCfgRec)) {
             $refs = t3lib_div::trimExplode(',', $indexCfgRec['indexcfgs']);
             $list = array(-99);
             // Default value to protect against empty array.
             foreach ($refs as $ref) {
                 list($table, $uid) = t3lib_div::revExplode('_', $ref, 2);
                 switch ($table) {
                     case 'index_config':
                         list($idxRec) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'index_config', 'uid=' . intval($uid) . $this->cObj->enableFields('index_config'));
                         if ($idxRec) {
                             $list[] = $uid;
                         }
                         break;
                     case 'pages':
                         $indexCfgRecordsFromPid = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'index_config', 'pid=' . intval($uid) . $this->cObj->enableFields('index_config'));
                         foreach ($indexCfgRecordsFromPid as $idxRec) {
                             $list[] = $idxRec['uid'];
                         }
                         break;
                 }
             }
             $list = array_unique($list);
         } else {
             $list = array(intval($freeIndexUid));
         }
         return ' AND IP.freeIndexUid IN (' . implode(',', $list) . ')';
     }
 }
Example #4
0
 /**
  * Register a class which renders a "editor".
  * A editor is something that modifies a file. This can be a text editor or a module to crop an image.
  *
  * @param	string		$idName This is the ID of the editor. Chars allowed only: [a-zA-z]
  * @param	string		$class Function/Method reference, '[file-reference":"]["&"]class'. See t3lib_div::callUserFunction().
  * @param	string		$position can be used to set the position of a new item within the list of existing items. $position has this syntax: [cmd]:[item-key]. cmd can be "after", "before" or "top" (or "bottom"/blank which is default). If "after"/"before" then submodule will be inserted after/before the existing item with [item-key] if found. If not found, the bottom of list. If "top" the item is inserted in the top of the item list.
  * @return	void
  */
 function register_editor($idName, $classRef, $position = '')
 {
     tx_dam::_addItem($idName, $classRef, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dam']['editorClasses'], $position);
     // an editor is also and module function so we register it here
     if (strstr($classRef, ':')) {
         list($file, $class) = t3lib_div::revExplode(':', $classRef, 2);
         $requireFile = t3lib_div::getFileAbsFileName($file);
     } else {
         $class = $classRef;
     }
     // Check for persistent object token, "&"
     if (substr($class, 0, 1) == '&') {
         $class = substr($class, 1);
     }
     // register module function
     t3lib_extMgm::insertModuleFunction('txdamM1_edit', $class, $requireFile, 'LLL:EXT:dam/mod_edit/locallang.xml:tx_dam_edit.title');
 }
 /**
  * This is taken directly from class.tx_realurl.php
  * Decodes the file name and adjusts file parts accordingly
  *
  * @param array $pathParts Path parts of the URLs (can be modified)
  * @return array GET varaibles from the file name or empty array
  */
 protected function decodeSpURL_decodeFileName(array &$pathParts) {
   $getVars = array();
   $fileName = rawurldecode(array_pop($pathParts));
   list($segment, $extension) = t3lib_div::revExplode('.', $fileName, 2);
   if ($extension) {
     $getVars = array();
     if (!$this->decodeSpURL_decodeFileName_lookupInIndex($fileName, $segment, $extension, $pathParts, $getVars)) {
       if (!$this->decodeSpURL_decodeFileName_checkHtmlSuffix($fileName, $segment, $extension, $pathParts)) {
       }
     }
   }
   return $getVars;
 }
 /**
  * Creates and returns reference to a user defined object.
  * This function can return an object reference if you like. Just prefix the function call with "&": "$objRef = &t3lib_div::getUserObj('EXT:myext/class.tx_myext_myclass.php:&tx_myext_myclass');". This will work ONLY if you prefix the class name with "&" as well. See description of function arguments.
  * Usage: 5
  *
  * @param	string		Class reference, '[file-reference":"]["&"]class-name'. You can prefix the class name with "[file-reference]:" and t3lib_div::getFileAbsFileName() will then be used to resolve the filename and subsequently include it by "require_once()" which means you don't have to worry about including the class file either! Example: "EXT:realurl/class.tx_realurl.php:&tx_realurl". Finally; for the class name you can prefix it with "&" and you will reuse the previous instance of the object identified by the full reference string (meaning; if you ask for the same $classRef later in another place in the code you will get a reference to the first created one!).
  * @param	string		Required prefix of class name. By default "tx_" is allowed.
  * @param	boolean		If set, no debug() error message is shown if class/function is not present.
  * @return	object		The instance of the class asked for. Instance is created with t3lib_div::makeInstance
  * @see callUserFunction()
  */
 function &getUserObj($classRef, $checkPrefix = 'user_', $silent = 0)
 {
     global $TYPO3_CONF_VARS;
     // Check persistent object and if found, call directly and exit.
     if (is_object($GLOBALS['T3_VAR']['getUserObj'][$classRef])) {
         return $GLOBALS['T3_VAR']['getUserObj'][$classRef];
     } else {
         // Check file-reference prefix; if found, require_once() the file (should be library of code)
         if (strstr($classRef, ':')) {
             list($file, $class) = t3lib_div::revExplode(':', $classRef, 2);
             $requireFile = t3lib_div::getFileAbsFileName($file);
             if ($requireFile) {
                 require_once $requireFile;
             }
         } else {
             $class = $classRef;
         }
         // Check for persistent object token, "&"
         if (substr($class, 0, 1) == '&') {
             $class = substr($class, 1);
             $storePersistentObject = TRUE;
         } else {
             $storePersistentObject = FALSE;
         }
         // Check prefix is valid:
         if ($checkPrefix && !t3lib_div::isFirstPartOfStr(trim($class), $checkPrefix) && !t3lib_div::isFirstPartOfStr(trim($class), 'tx_')) {
             if (!$silent) {
                 debug("Class '" . $class . "' was not prepended with '" . $checkPrefix . "'", 1);
             }
             return FALSE;
         }
         // Check if class exists:
         if (class_exists($class)) {
             $classObj =& t3lib_div::makeInstance($class);
             // If persistent object should be created, set reference:
             if ($storePersistentObject) {
                 $GLOBALS['T3_VAR']['getUserObj'][$classRef] =& $classObj;
             }
             return $classObj;
         } else {
             if (!$silent) {
                 debug("<strong>ERROR:</strong> No class named: " . $class, 1);
             }
         }
     }
 }
 function splitGroup($group, $default = '')
 {
     $groups = explode(',', $group);
     foreach ($groups as $group) {
         $item = t3lib_div::revExplode('_', $group, 2);
         if (count($item) == 1) {
             $record_ids[$default][] = $item[0];
         } else {
             $record_ids[$item[0]][] = $item[1];
         }
     }
     return $record_ids;
 }
 /**
  * Check a config value if its enabled
  * Anything except '' and 0 is true
  * If the the option is not set the default value will be returned
  *
  * @param	string		$configPath Pointer to an "object" in the TypoScript array, fx. 'setup.selections.default'
  * @param	mixed 		$default Default value when option is not set, otherwise the value itself
  * @return boolean
  */
 function checkValueEnabled($configPath, $default = false)
 {
     $parts = t3lib_div::revExplode('.', $configPath, 2);
     $config = tx_dam_config::getValue($parts[0], true);
     return tx_dam_config::isEnabledOption($config, $parts[1], $default);
 }
    /**
     * Recursive rendering of flexforms
     *
     * @param	array		(part of) Data Structure for which to render. Keys on first level is flex-form fields
     * @param	array		(part of) Data array of flexform corresponding to the input DS. Keys on first level is flex-form field names
     * @param	string		Table name, eg. tt_content
     * @param	string		Field name, eg. tx_templavoila_flex
     * @param	array		The particular record from $table in which the field $field is found
     * @param	array		Array of standard information for rendering of a form field in TCEforms, see other rendering functions too
     * @param	string		Form field prefix, eg. "[data][sDEF][lDEF][...][...]"
     * @param	integer		Indicates nesting level for the function call
     * @param	string		Prefix for ID-values
     * @param	boolean		Defines whether the next flexform level is open or closed. Comes from _TOGGLE pseudo field in FlexForm xml.
     * @return	string		HTMl code for form.
     */
    function getSingleField_typeFlex_draw($dataStruct, $editData, $table, $field, $row, &$PA, $formPrefix = '', $level = 0, $idPrefix = 'ID', $toggleClosed = FALSE)
    {
        $output = '';
        $mayRestructureFlexforms = $GLOBALS['BE_USER']->checkLanguageAccess(0);
        // Data Structure array must be ... and array of course...
        if (is_array($dataStruct)) {
            foreach ($dataStruct as $key => $value) {
                // Traversing fields in structure:
                if (is_array($value)) {
                    // The value of each entry must be an array.
                    // ********************
                    // Making the row:
                    // ********************
                    // Title of field:
                    $theTitle = htmlspecialchars(t3lib_div::fixed_lgd_cs($this->sL($value['tx_templavoila']['title']), 30));
                    // If it's a "section" or "container":
                    if ($value['type'] == 'array') {
                        // Creating IDs for form fields:
                        // It's important that the IDs "cascade" - otherwise we can't dynamically expand the flex form because this relies on simple string substitution of the first parts of the id values.
                        $thisId = t3lib_div::shortMd5(uniqid('id', TRUE));
                        // This is a suffix used for forms on this level
                        $idTagPrefix = $idPrefix . '-' . $thisId;
                        // $idPrefix is the prefix for elements on lower levels in the hierarchy and we combine this with the thisId value to form a new ID on this level.
                        // If it's a "section" containing other elements:
                        if ($value['section']) {
                            // Load script.aculo.us if flexform sections can be moved by drag'n'drop:
                            $GLOBALS['SOBE']->doc->getPageRenderer()->loadScriptaculous();
                            // Render header of section:
                            $output .= '<div class="t3-form-field-label-flexsection"><strong>' . $theTitle . '</strong></div>';
                            // Render elements in data array for section:
                            $tRows = array();
                            $cc = 0;
                            if (is_array($editData[$key]['el'])) {
                                foreach ($editData[$key]['el'] as $k3 => $v3) {
                                    $cc = $k3;
                                    if (is_array($v3)) {
                                        $theType = key($v3);
                                        $theDat = $v3[$theType];
                                        $newSectionEl = $value['el'][$theType];
                                        if (is_array($newSectionEl)) {
                                            $tRows[] = $this->getSingleField_typeFlex_draw(array($theType => $newSectionEl), array($theType => $theDat), $table, $field, $row, $PA, $formPrefix . '[' . $key . '][el][' . $cc . ']', $level + 1, $idTagPrefix, $v3['_TOGGLE']);
                                        }
                                    }
                                }
                            }
                            // Now, we generate "templates" for new elements that could be added to this section by traversing all possible types of content inside the section:
                            // We have to handle the fact that requiredElements and such may be set during this rendering process and therefore we save and reset the state of some internal variables - little crude, but works...
                            // Preserving internal variables we don't want to change:
                            $TEMP_requiredElements = $this->requiredElements;
                            // Traversing possible types of new content in the section:
                            $newElementsLinks = array();
                            foreach ($value['el'] as $nnKey => $nCfg) {
                                $additionalJS_post_saved = $this->additionalJS_post;
                                $this->additionalJS_post = array();
                                $additionalJS_submit_saved = $this->additionalJS_submit;
                                $this->additionalJS_submit = array();
                                $newElementTemplate = $this->getSingleField_typeFlex_draw(array($nnKey => $nCfg), array(), $table, $field, $row, $PA, $formPrefix . '[' . $key . '][el][' . $idTagPrefix . '-form]', $level + 1, $idTagPrefix);
                                // Makes a "Add new" link:
                                $var = uniqid('idvar');
                                $replace = 'replace(/' . $idTagPrefix . '-/g,"' . $idTagPrefix . '-"+' . $var . '+"-")';
                                $onClickInsert = 'var ' . $var . ' = "' . 'idx"+(new Date()).getTime();';
                                // Do not replace $isTagPrefix in setActionStatus() because it needs section id!
                                $onClickInsert .= 'new Insertion.Bottom($("' . $idTagPrefix . '"), unescape("' . rawurlencode($newElementTemplate) . '").' . $replace . '); setActionStatus("' . $idTagPrefix . '");';
                                $onClickInsert .= 'eval(unescape("' . rawurlencode(implode(';', $this->additionalJS_post)) . '").' . $replace . ');';
                                $onClickInsert .= 'TBE_EDITOR.addActionChecks("submit", unescape("' . rawurlencode(implode(';', $this->additionalJS_submit)) . '").' . $replace . ');';
                                $onClickInsert .= 'return false;';
                                // Kasper's comment (kept for history): Maybe there is a better way to do this than store the HTML for the new element in rawurlencoded format - maybe it even breaks with certain charsets? But for now this works...
                                $this->additionalJS_post = $additionalJS_post_saved;
                                $this->additionalJS_submit = $additionalJS_submit_saved;
                                $new = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:cm.new', 1);
                                $newElementsLinks[] = '<a href="#" onclick="' . htmlspecialchars($onClickInsert) . '">' . t3lib_iconWorks::getSpriteIcon('actions-document-new') . htmlspecialchars(t3lib_div::fixed_lgd_cs($this->sL($nCfg['tx_templavoila']['title']), 30)) . '</a>';
                            }
                            // Reverting internal variables we don't want to change:
                            $this->requiredElements = $TEMP_requiredElements;
                            // Adding the sections:
                            $toggleAll = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.toggleall', 1);
                            $output .= '
							<div class="t3-form-field-toggle-flexsection">
								<a href="#" onclick="' . htmlspecialchars('flexFormToggleSubs("' . $idTagPrefix . '"); return false;') . '">' . t3lib_iconWorks::getSpriteIcon('actions-move-right', array('title' => $toggleAll)) . $toggleAll . '
								</a>
							</div>

							<div id="' . $idTagPrefix . '" class="t3-form-field-container-flexsection">' . implode('', $tRows) . '</div>';
                            $output .= $mayRestructureFlexforms ? '<div class="t3-form-field-add-flexsection"><strong>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.addnew', 1) . ':</strong> ' . implode(' | ', $newElementsLinks) . '</div>' : '';
                        } else {
                            // It is a container
                            $toggleIcon_open = t3lib_iconWorks::getSpriteIcon('actions-move-down');
                            $toggleIcon_close = t3lib_iconWorks::getSpriteIcon('actions-move-right');
                            // Create on-click actions.
                            //$onClickCopy = 'new Insertion.After($("'.$idTagPrefix.'"), getOuterHTML("'.$idTagPrefix.'").replace(/'.$idTagPrefix.'-/g,"'.$idTagPrefix.'-copy"+Math.floor(Math.random()*100000+1)+"-")); return false;';	// Copied elements doesn't work (well) in Safari while they do in Firefox and MSIE! UPDATE: It turned out that copying doesn't work for any browser, simply because the data from the copied form never gets submitted to the server for some reason! So I decided to simply disable copying for now. If it's requested by customers we can look to enable it again and fix the issue. There is one un-fixable problem though; Copying an element like this will violate integrity if files are attached inside that element because the file reference doesn't get an absolute path prefixed to it which would be required to have TCEmain generate a new copy of the file.
                            $onClickRemove = 'if (confirm("Are you sure?")){/*###REMOVE###*/;$("' . $idTagPrefix . '").hide();setActionStatus("' . $idPrefix . '");} return false;';
                            $onClickToggle = 'flexFormToggle("' . $idTagPrefix . '"); return false;';
                            $onMove = 'flexFormSortable("' . $idPrefix . '")';
                            // Notice: Creating "new" elements after others seemed to be too difficult to do and since moving new elements created in the bottom is now so easy with drag'n'drop I didn't see the need.
                            // Putting together header of a section. Sections can be removed, copied, opened/closed, moved up and down:
                            // I didn't know how to make something right-aligned without a table, so I put it in a table. can be made into <div>'s if someone like to.
                            // Notice: The fact that I make a "Sortable.create" right onmousedown is that if we initialize this when rendering the form in PHP new and copied elements will not be possible to move as a sortable. But this way a new sortable is initialized everytime someone tries to move and it will always work.
                            $ctrlHeader = '
								<table class="t3-form-field-header-flexsection" onmousedown="' . ($mayRestructureFlexforms ? htmlspecialchars($onMove) : '') . '">
								<tr>
									<td>
										<a href="#" onclick="' . htmlspecialchars($onClickToggle) . '" id="' . $idTagPrefix . '-toggle">
											' . ($toggleClosed ? $toggleIcon_close : $toggleIcon_open) . '
										</a>
										<strong>' . $theTitle . '</strong> <em><span id="' . $idTagPrefix . '-preview"></span></em>
									</td>
									<td align="right">' . ($mayRestructureFlexforms ? t3lib_iconWorks::getSpriteIcon('actions-move-move', array('title' => 'Drag to Move')) : '') . ($mayRestructureFlexforms ? '<a href="#" onclick="' . htmlspecialchars($onClickRemove) . '">' . t3lib_iconWorks::getSpriteIcon('actions-edit-delete', array('title' => 'Delete')) : '') . '</td>
									</tr>
								</table>';
                            $s = t3lib_div::revExplode('[]', $formPrefix, 2);
                            $actionFieldName = '_ACTION_FLEX_FORM' . $PA['itemFormElName'] . $s[0] . '][_ACTION][' . $s[1];
                            // Push the container to DynNestedStack as it may be toggled
                            $this->pushToDynNestedStack('flex', $idTagPrefix);
                            // Putting together the container:
                            $this->additionalJS_delete = array();
                            $output .= '
								<div id="' . $idTagPrefix . '" class="t3-form-field-container-flexsections">
									<input id="' . $idTagPrefix . '-action" type="hidden" name="' . htmlspecialchars($actionFieldName) . '" value=""/>

									' . $ctrlHeader . '
									<div class="t3-form-field-record-flexsection" id="' . $idTagPrefix . '-content"' . ($toggleClosed ? ' style="display:none;"' : '') . '>' . $this->getSingleField_typeFlex_draw($value['el'], $editData[$key]['el'], $table, $field, $row, $PA, $formPrefix . '[' . $key . '][el]', $level + 1, $idTagPrefix) . '
									</div>
									<input id="' . $idTagPrefix . '-toggleClosed" type="hidden" name="' . htmlspecialchars('data[' . $table . '][' . $row['uid'] . '][' . $field . ']' . $formPrefix . '[_TOGGLE]') . '" value="' . ($toggleClosed ? 1 : 0) . '" />
								</div>';
                            $output = str_replace('/*###REMOVE###*/', t3lib_div::slashJS(htmlspecialchars(implode('', $this->additionalJS_delete))), $output);
                            // NOTICE: We are saving the toggle-state directly in the flexForm XML and "unauthorized" according to the data structure. It means that flexform XML will report unclean and a cleaning operation will remove the recorded togglestates. This is not a fatal problem. Ideally we should save the toggle states in meta-data but it is much harder to do that. And this implementation was easy to make and with no really harmful impact.
                            // Pop the container from DynNestedStack
                            $this->popFromDynNestedStack('flex', $idTagPrefix);
                        }
                        // If it's a "single form element":
                    } elseif (is_array($value['TCEforms']['config'])) {
                        // Rendering a single form element:
                        if (is_array($PA['_valLang'])) {
                            $rotateLang = $PA['_valLang'];
                        } else {
                            $rotateLang = array($PA['_valLang']);
                        }
                        $conditionData = is_array($editData) ? $editData : array();
                        // add current $row to data processed by isDisplayCondition()
                        $conditionData['parentRec'] = $row;
                        $tRows = array();
                        foreach ($rotateLang as $vDEFkey) {
                            $vDEFkey = 'v' . $vDEFkey;
                            if (!$value['TCEforms']['displayCond'] || $this->isDisplayCondition($value['TCEforms']['displayCond'], $conditionData, $vDEFkey)) {
                                $fakePA = array();
                                $fakePA['fieldConf'] = array('label' => $this->sL(trim($value['TCEforms']['label'])), 'config' => $value['TCEforms']['config'], 'defaultExtras' => $value['TCEforms']['defaultExtras'], 'onChange' => $value['TCEforms']['onChange']);
                                if ($PA['_noEditDEF'] && $PA['_lang'] === 'lDEF') {
                                    $fakePA['fieldConf']['config'] = array('type' => 'none', 'rows' => 2);
                                }
                                if ($fakePA['fieldConf']['onChange'] == 'reload' || $GLOBALS['TCA'][$table]['ctrl']['type'] && !strcmp($key, $GLOBALS['TCA'][$table]['ctrl']['type']) || $GLOBALS['TCA'][$table]['ctrl']['requestUpdate'] && t3lib_div::inList($GLOBALS['TCA'][$table]['ctrl']['requestUpdate'], $key)) {
                                    if ($GLOBALS['BE_USER']->jsConfirmation(1)) {
                                        $alertMsgOnChange = 'if (confirm(TBE_EDITOR.labels.onChangeAlert) && TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm() };';
                                    } else {
                                        $alertMsgOnChange = 'if(TBE_EDITOR.checkSubmit(-1)){ TBE_EDITOR.submitForm();}';
                                    }
                                } else {
                                    $alertMsgOnChange = '';
                                }
                                $fakePA['fieldChangeFunc'] = $PA['fieldChangeFunc'];
                                if (strlen($alertMsgOnChange)) {
                                    $fakePA['fieldChangeFunc']['alert'] = $alertMsgOnChange;
                                }
                                $fakePA['onFocus'] = $PA['onFocus'];
                                $fakePA['label'] = $PA['label'];
                                $fakePA['itemFormElName'] = $PA['itemFormElName'] . $formPrefix . '[' . $key . '][' . $vDEFkey . ']';
                                $fakePA['itemFormElName_file'] = $PA['itemFormElName_file'] . $formPrefix . '[' . $key . '][' . $vDEFkey . ']';
                                $fakePA['itemFormElID'] = $fakePA['itemFormElName'];
                                if (isset($editData[$key][$vDEFkey])) {
                                    $fakePA['itemFormElValue'] = $editData[$key][$vDEFkey];
                                } else {
                                    $fakePA['itemFormElValue'] = $fakePA['fieldConf']['config']['default'];
                                }
                                $theFormEl = $this->getSingleField_SW($table, $field, $row, $fakePA);
                                $theTitle = htmlspecialchars($fakePA['fieldConf']['label']);
                                if (!in_array('DEF', $rotateLang)) {
                                    $defInfo = '<div class="typo3-TCEforms-originalLanguageValue">' . $this->getLanguageIcon($table, $row, 0) . $this->previewFieldValue($editData[$key]['vDEF'], $fakePA['fieldConf'], $field) . '&nbsp;</div>';
                                } else {
                                    $defInfo = '';
                                }
                                if (!$PA['_noEditDEF']) {
                                    $prLang = $this->getAdditionalPreviewLanguages();
                                    foreach ($prLang as $prL) {
                                        $defInfo .= '<div class="typo3-TCEforms-originalLanguageValue">' . $this->getLanguageIcon($table, $row, 'v' . $prL['ISOcode']) . $this->previewFieldValue($editData[$key]['v' . $prL['ISOcode']], $fakePA['fieldConf'], $field) . '&nbsp;</div>';
                                    }
                                }
                                $languageIcon = '';
                                if ($vDEFkey != 'vDEF') {
                                    $languageIcon = $this->getLanguageIcon($table, $row, $vDEFkey);
                                }
                                // Put row together
                                // possible linebreaks in the label through xml: \n => <br/>, usage of nl2br() not possible, so it's done through str_replace
                                $processedTitle = str_replace('\\n', '<br />', $theTitle);
                                $tRows[] = '<div class="t3-form-field-container t3-form-field-container-flex">' . '<div class="t3-form-field-label t3-form-field-label-flex">' . $languageIcon . t3lib_BEfunc::wrapInHelp($PA['_cshKey'], $key, $processedTitle) . '</div>
									<div class="t3-form-field t3-form-field-flex">' . $theFormEl . $defInfo . $this->renderVDEFDiff($editData[$key], $vDEFkey) . '</div>
								</div>';
                            }
                        }
                        if (count($tRows)) {
                            $output .= implode('', $tRows);
                        }
                    }
                }
            }
        }
        return $output;
    }
Example #10
0
 function explodeElement($elementList)
 {
     $elements = t3lib_div::trimExplode(',', $elementList);
     foreach ($elements as $k => $element) {
         $elements[$k] = t3lib_div::revExplode('_', $element, 2);
     }
     return $elements;
 }
 /**
  * @test
  */
 public function checkRevExplodeCorrectlyExplodesString()
 {
     $testString = 'my:words:here';
     $expectedArray = array('my:words', 'here');
     $actualArray = t3lib_div::revExplode(':', $testString, 2);
     $this->assertEquals($expectedArray, $actualArray);
 }
 /**
  * Tries to get the division comment above the function
  *
  * @param	string		$string: Content to test
  * @return	mixed		Returns array with comment text lines if found.
  * @access private
  */
 function getSectionDivisionComment($string)
 {
     $comment = t3lib_div::revExplode('**/', $string, 2);
     if (trim($comment[1]) && preg_match('#\\*\\/$#', trim($comment[1]))) {
         $outLines = array();
         $cDat = $this->parseFunctionComment($comment[1], array());
         $textLines = t3lib_div::trimExplode(chr(10), $cDat['text'], 1);
         foreach ($textLines as $v) {
             if (substr($v, 0, 1) != '*') {
                 $outLines[] = $v;
             }
         }
         return $outLines;
     }
 }
 function buildCodeBehind($aCB)
 {
     $sCBRef = $aCB["path"];
     $sName = $aCB["name"];
     if ($sCBRef[0] === "E" && $sCBRef[1] === "X" && t3lib_div::isFirstPartOfStr($sCBRef, "EXT:")) {
         $sCBRef = substr($sCBRef, 4);
         $sPrefix = "EXT:";
     } else {
         $sPrefix = "";
     }
     $aParts = explode(":", $sCBRef);
     $sFileRef = $sPrefix . $aParts[0];
     $sFilePath = $this->toServerPath($sFileRef);
     // determining type of the CB
     $sFileExt = strtolower(array_pop(t3lib_div::revExplode(".", $sFileRef, 2)));
     switch ($sFileExt) {
         case "php":
             if (is_file($sFilePath) && is_readable($sFilePath)) {
                 if (count($aParts) < 2) {
                     if (!in_array($sFilePath, get_included_files())) {
                         // class has not been defined. Let's try to determine automatically the class name
                         $aClassesBefore = get_declared_classes();
                         ob_start();
                         require_once $sFilePath;
                         ob_end_clean();
                         // output buffering for easing use of php class files that execute something outside the class definition ( like BE module's index.php !!)
                         $aClassesAfter = get_declared_classes();
                         $aNewClasses = array_diff($aClassesAfter, $aClassesBefore);
                         if (count($aNewClasses) !== 1) {
                             $this->mayday("<b>CodeBehind: Cannot automatically determine the classname to use in '" . $sFilePath . "'</b><br />Please add ':myClassName' after the file-path to explicitely.");
                         } else {
                             $sClass = array_shift($aNewClasses);
                         }
                     } else {
                         $this->mayday("<b>CodeBehind: Cannot automatically determine the classname to use in '" . $sFilePath . "'</b><br />Please add ':myClassName' after the file-path.");
                     }
                 } else {
                     $sClass = $aParts[1];
                     ob_start();
                     require_once $sFilePath;
                     ob_end_clean();
                     // output buffering for easing use of php class files that execute something outside the class definition ( like BE module's index.php !!)
                 }
                 if (class_exists($sClass)) {
                     $oCB = new $sClass();
                     $oCB->oForm =& $this;
                     $oCB->aConf = $aCB;
                     return array("type" => "php", "name" => $sName, "filepath" => $sFilePath, "class" => $sClass, "object" => &$oCB, "config" => isset($aCB["config"]) ? $aCB["config"] : FALSE);
                 } else {
                     $this->mayday("CodeBehind [" . $sCBRef . "]: class <b>" . $sClass . "</b> does not exist.");
                 }
             } else {
                 $this->mayday("CodeBehind [" . $sCBRef . "]: file <b>" . $sFileRef . "</b> does not exist.");
             }
             break;
         case "js":
             if (count($aParts) < 2) {
                 $this->mayday("CodeBehind [" . $sCBRef . "]: you have to provide a class name for javascript codebehind <b>" . $sCBRef . "</b>. Please add ':myClassName' after the file-path.");
             } else {
                 $sClass = $aParts[1];
             }
             if (is_file($sFilePath) && is_readable($sFilePath)) {
                 if (intval(filesize($sFilePath)) === 0) {
                     //$this->mayday("CodeBehind [" . $sCBRef . "]: seems to be empty</b>.");
                     $this->smartMayday_CBJavascript($sFilePath, $sClass, FALSE);
                 }
                 return array("type" => "js", "name" => $sName, "filepath" => $sFilePath, "class" => $sClass, "config" => isset($aCB["config"]) ? $aCB["config"] : FALSE);
             }
             break;
         default:
             $this->mayday("CodeBehind [" . $sCBRef . "]: allowed file extensions are <b>'.php', '.js' and '.ts'</b>.");
     }
 }
Example #14
0
 /**
  * Main function
  * Makes a header-location redirect to an edit form IF POSSIBLE from the passed data - otherwise the window will just close.
  *
  * @return	void
  */
 function main()
 {
     global $TCA;
     if ($this->doClose) {
         $this->closeWindow();
     } else {
         // Initialize:
         $table = $this->P['table'];
         $field = $this->P['field'];
         t3lib_div::loadTCA($table);
         $config = $TCA[$table]['columns'][$field]['config'];
         $fTable = $this->P['currentValue'] < 0 ? $config['neg_foreign_table'] : $config['foreign_table'];
         // Detecting the various allowed field type setups and acting accordingly.
         if (is_array($config) && $config['type'] == 'select' && !$config['MM'] && $config['maxitems'] <= 1 && t3lib_div::testInt($this->P['currentValue']) && $this->P['currentValue'] && $fTable) {
             // SINGLE value:
             $redirectUrl = 'alt_doc.php?returnUrl=' . rawurlencode('wizard_edit.php?doClose=1') . '&edit[' . $fTable . '][' . $this->P['currentValue'] . ']=edit';
             t3lib_utility_Http::redirect($redirectUrl);
         } elseif (is_array($config) && $this->P['currentSelectedValues'] && ($config['type'] == 'select' && $config['foreign_table'] || $config['type'] == 'group' && $config['internal_type'] == 'db')) {
             // MULTIPLE VALUES:
             // Init settings:
             $allowedTables = $config['type'] == 'group' ? $config['allowed'] : $config['foreign_table'] . ',' . $config['neg_foreign_table'];
             $prependName = 1;
             $params = '';
             // Selecting selected values into an array:
             $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
             $dbAnalysis->start($this->P['currentSelectedValues'], $allowedTables);
             $value = $dbAnalysis->getValueArray($prependName);
             // Traverse that array and make parameters for alt_doc.php:
             foreach ($value as $rec) {
                 $recTableUidParts = t3lib_div::revExplode('_', $rec, 2);
                 $params .= '&edit[' . $recTableUidParts[0] . '][' . $recTableUidParts[1] . ']=edit';
             }
             // Redirect to alt_doc.php:
             t3lib_utility_Http::redirect('alt_doc.php?returnUrl=' . rawurlencode('wizard_edit.php?doClose=1') . $params);
         } else {
             $this->closeWindow();
         }
     }
 }
 /**
  * Return be_users that should be notified on stage change from input list.
  * previously called notifyStageChange_getEmails() in tcemain
  *
  * @param	string		$listOfUsers List of backend users, on the form "be_users_10,be_users_2" or "10,2" in case noTablePrefix is set.
  * @param	boolean		$noTablePrefix If set, the input list are integers and not strings.
  * @return	array		Array of emails
  */
 protected function getEmailsForStageChangeNotification($listOfUsers, $noTablePrefix = FALSE)
 {
     $users = t3lib_div::trimExplode(',', $listOfUsers, 1);
     $emails = array();
     foreach ($users as $userIdent) {
         if ($noTablePrefix) {
             $id = intval($userIdent);
         } else {
             list($table, $id) = t3lib_div::revExplode('_', $userIdent, 2);
         }
         if ($table === 'be_users' || $noTablePrefix) {
             if ($userRecord = t3lib_BEfunc::getRecord('be_users', $id, 'uid,email,lang,realName')) {
                 if (strlen(trim($userRecord['email']))) {
                     $emails[$id] = $userRecord;
                 }
             }
         }
     }
     return $emails;
 }
 /**
  * Lets you split the content by LF and proces each line independently. Used to format content made with the RTE.
  *
  * @param	string		The input value
  * @param	array		TypoScript options
  * @return	string		The processed input value being returned; Splitted lines imploded by LF again.
  * @access private
  */
 function encaps_lineSplit($theValue, $conf)
 {
     $lParts = explode(LF, $theValue);
     $encapTags = t3lib_div::trimExplode(',', strtolower($conf['encapsTagList']), 1);
     $nonWrappedTag = $conf['nonWrappedTag'];
     $defaultAlign = isset($conf['defaultAlign.']) ? trim($this->stdWrap($conf['defaultAlign'], $conf['defaultAlign.'])) : trim($conf['defaultAlign']);
     if (!strcmp('', $theValue)) {
         return '';
     }
     foreach ($lParts as $k => $l) {
         $sameBeginEnd = 0;
         $emptyTag = 0;
         $l = trim($l);
         $attrib = array();
         $nWrapped = 0;
         if (substr($l, 0, 1) == '<' && substr($l, -1) == '>') {
             $fwParts = explode('>', substr($l, 1), 2);
             list($tagName, $tagParams) = explode(' ', $fwParts[0], 2);
             if (!$fwParts[1]) {
                 if (substr($tagName, -1) == '/') {
                     $tagName = substr($tagName, 0, -1);
                 }
                 if (substr($fwParts[0], -1) == '/') {
                     $sameBeginEnd = 1;
                     $emptyTag = 1;
                     $attrib = t3lib_div::get_tag_attributes('<' . substr($fwParts[0], 0, -1) . '>');
                 }
             } else {
                 $backParts = t3lib_div::revExplode('<', substr($fwParts[1], 0, -1), 2);
                 $attrib = t3lib_div::get_tag_attributes('<' . $fwParts[0] . '>');
                 $str_content = $backParts[0];
                 $sameBeginEnd = substr(strtolower($backParts[1]), 1, strlen($tagName)) == strtolower($tagName);
             }
         }
         if ($sameBeginEnd && in_array(strtolower($tagName), $encapTags)) {
             $uTagName = strtoupper($tagName);
             $uTagName = strtoupper($conf['remapTag.'][$uTagName] ? $conf['remapTag.'][$uTagName] : $uTagName);
         } else {
             $uTagName = strtoupper($nonWrappedTag);
             // The line will be wrapped: $uTagName should not be an empty tag
             $emptyTag = 0;
             $str_content = $lParts[$k];
             $nWrapped = 1;
             $attrib = array();
         }
         // Wrapping all inner-content:
         if (is_array($conf['innerStdWrap_all.'])) {
             $str_content = $this->stdWrap($str_content, $conf['innerStdWrap_all.']);
         }
         if ($uTagName) {
             // Setting common attributes
             if (is_array($conf['addAttributes.'][$uTagName . '.'])) {
                 foreach ($conf['addAttributes.'][$uTagName . '.'] as $kk => $vv) {
                     if (!is_array($vv)) {
                         if ((string) $conf['addAttributes.'][$uTagName . '.'][$kk . '.']['setOnly'] == 'blank') {
                             if (!strcmp($attrib[$kk], '')) {
                                 $attrib[$kk] = $vv;
                             }
                         } elseif ((string) $conf['addAttributes.'][$uTagName . '.'][$kk . '.']['setOnly'] == 'exists') {
                             if (!isset($attrib[$kk])) {
                                 $attrib[$kk] = $vv;
                             }
                         } else {
                             $attrib[$kk] = $vv;
                         }
                     }
                 }
             }
             // Wrapping all inner-content:
             if (is_array($conf['encapsLinesStdWrap.'][$uTagName . '.'])) {
                 $str_content = $this->stdWrap($str_content, $conf['encapsLinesStdWrap.'][$uTagName . '.']);
             }
             // Default align
             if (!$attrib['align'] && $defaultAlign) {
                 $attrib['align'] = $defaultAlign;
             }
             $params = t3lib_div::implodeAttributes($attrib, 1);
             if ($conf['removeWrapping'] && !($emptyTag && $conf['removeWrapping.']['keepSingleTag'])) {
                 $str_content = $str_content;
             } else {
                 if ($emptyTag) {
                     $str_content = '<' . strtolower($uTagName) . (trim($params) ? ' ' . trim($params) : '') . ' />';
                 } else {
                     $str_content = '<' . strtolower($uTagName) . (trim($params) ? ' ' . trim($params) : '') . '>' . $str_content . '</' . strtolower($uTagName) . '>';
                 }
             }
         }
         if ($nWrapped && $conf['wrapNonWrappedLines']) {
             $str_content = $this->wrap($str_content, $conf['wrapNonWrappedLines']);
         }
         $lParts[$k] = $str_content;
     }
     return implode(LF, $lParts);
 }
 /**
  * Renders the HTML header for a foreign record, such as the title, toggle-function, drag'n'drop, etc.
  * Later on the command-icons are inserted here.
  *
  * @param	string		$parentUid: The uid of the parent (embedding) record (uid or NEW...)
  * @param	string		$foreign_table: The foreign_table we create a header for
  * @param	array		$rec: The current record of that foreign_table
  * @param	array		$config: content of $PA['fieldConf']['config']
  * @param	boolean		$isVirtualRecord:
  * @return	string		The HTML code of the header
  */
 function renderForeignRecordHeader($parentUid, $foreign_table, $rec, $config, $isVirtualRecord = false)
 {
     // Init:
     $objectId = $this->inlineNames['object'] . self::Structure_Separator . $foreign_table . self::Structure_Separator . $rec['uid'];
     $expandSingle = $config['appearance']['expandSingle'] ? 1 : 0;
     // we need the returnUrl of the main script when loading the fields via AJAX-call (to correct wizard code, so include it as 3rd parameter)
     $onClick = "return inline.expandCollapseRecord('" . htmlspecialchars($objectId) . "', {$expandSingle}, '" . rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI')) . "')";
     // Pre-Processing:
     $isOnSymmetricSide = t3lib_loadDBGroup::isOnSymmetricSide($parentUid, $config, $rec);
     $hasForeignLabel = !$isOnSymmetricSide && $config['foreign_label'] ? true : false;
     $hasSymmetricLabel = $isOnSymmetricSide && $config['symmetric_label'] ? true : false;
     // Get the record title/label for a record:
     // render using a self-defined user function
     if ($GLOBALS['TCA'][$foreign_table]['ctrl']['label_userFunc']) {
         $params = array('table' => $foreign_table, 'row' => $rec, 'title' => '', 'isOnSymmetricSide' => $isOnSymmetricSide, 'parent' => array('uid' => $parentUid, 'config' => $config));
         $null = null;
         // callUserFunction requires a third parameter, but we don't want to give $this as reference!
         t3lib_div::callUserFunction($GLOBALS['TCA'][$foreign_table]['ctrl']['label_userFunc'], $params, $null);
         $recTitle = $params['title'];
         // render the special alternative title
     } elseif ($hasForeignLabel || $hasSymmetricLabel) {
         $titleCol = $hasForeignLabel ? $config['foreign_label'] : $config['symmetric_label'];
         $foreignConfig = $this->getPossibleRecordsSelectorConfig($config, $titleCol);
         // Render title for everything else than group/db:
         if ($foreignConfig['type'] != 'groupdb') {
             $recTitle = t3lib_BEfunc::getProcessedValueExtra($foreign_table, $titleCol, $rec[$titleCol], 0, 0, false);
             // Render title for group/db:
         } else {
             // $recTitle could be something like: "tx_table_123|...",
             $valueParts = t3lib_div::trimExplode('|', $rec[$titleCol]);
             $itemParts = t3lib_div::revExplode('_', $valueParts[0], 2);
             $recTemp = t3lib_befunc::getRecordWSOL($itemParts[0], $itemParts[1]);
             $recTitle = t3lib_BEfunc::getRecordTitle($itemParts[0], $recTemp, false);
         }
         $recTitle = t3lib_BEfunc::getRecordTitlePrep($recTitle);
         if (!strcmp(trim($recTitle), '')) {
             $recTitle = t3lib_BEfunc::getNoRecordTitle(true);
         }
         // render the standard
     } else {
         $recTitle = t3lib_BEfunc::getRecordTitle($foreign_table, $rec, true);
     }
     $altText = t3lib_BEfunc::getRecordIconAltText($rec, $foreign_table);
     $iconImg = t3lib_iconWorks::getSpriteIconForRecord($foreign_table, $rec, array('title' => htmlspecialchars($altText), 'id' => $objectId . '_icon"'));
     $label = '<span id="' . $objectId . '_label">' . $recTitle . '</span>';
     if (!$isVirtualRecord) {
         $iconImg = $this->wrapWithAnchor($iconImg, '#', array('onclick' => $onClick));
         $label = $this->wrapWithAnchor($label, '#', array('onclick' => $onClick, 'style' => 'display: block;'));
     }
     $ctrl = $this->renderForeignRecordHeaderControl($parentUid, $foreign_table, $rec, $config, $isVirtualRecord);
     // @TODO: Check the table wrapping and the CSS definitions
     $header = '<table cellspacing="0" cellpadding="0" border="0" width="100%" style="margin-right: ' . $this->inlineStyles['margin-right'] . 'px;"' . ($this->fObj->borderStyle[2] ? ' background="' . htmlspecialchars($this->backPath . $this->fObj->borderStyle[2]) . '"' : '') . ($this->fObj->borderStyle[3] ? ' class="' . htmlspecialchars($this->fObj->borderStyle[3]) . '"' : '') . '>' . '<tr class="class-main12"><td width="18" id="' . $objectId . '_iconcontainer">' . $iconImg . '</td><td align="left"><strong>' . $label . '</strong></td><td align="right">' . $ctrl . '</td></tr></table>';
     return $header;
 }