/**
  * Create a zip file from an extension
  *
  * @param array $extension
  * @return string
  */
 public function createZipFileFromExtension($extension)
 {
     $extensionPath = $this->getAbsoluteExtensionPath($extension);
     $version = $this->getExtensionVersion($extension);
     $fileName = $this->getAbsolutePath('typo3temp/' . $extension . '_' . $version . '.zip');
     $zip = new \ZipArchive();
     $zip->open($fileName, \ZipArchive::CREATE);
     $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($extensionPath));
     foreach ($iterator as $key => $value) {
         $archiveName = str_replace($extensionPath, '', $key);
         if (\TYPO3\CMS\Core\Utility\StringUtility::isLastPartOfString($key, '.')) {
             continue;
         } else {
             $zip->addFile($key, $archiveName);
         }
     }
     $zip->close();
     return $fileName;
 }
示例#2
0
 /**
  * @test
  * @dataProvider isLastPartOfStringReturnsInvalidArgumentDataProvider
  * @expectedException \InvalidArgumentException
  */
 public function isLastPartOfStringReturnsThrowsExceptionWithInvalidArguments($string, $part)
 {
     $this->assertFalse(\TYPO3\CMS\Core\Utility\StringUtility::isLastPartOfString($string, $part));
 }
 /**
  * Helper function for parseFunc()
  *
  * @param string $theValue The value to process.
  * @param array $conf TypoScript configuration for parseFunc
  * @return string The processed value
  * @access private
  * @see parseFunc()
  * @todo Define visibility
  */
 public function _parseFunc($theValue, $conf)
 {
     if (!empty($conf['if.']) && !$this->checkIf($conf['if.'])) {
         return $theValue;
     }
     // Indicates that the data is from within a tag.
     $inside = 0;
     // Pointer to the total string position
     $pointer = 0;
     // Loaded with the current typo-tag if any.
     $currentTag = '';
     $stripNL = 0;
     $contentAccum = array();
     $contentAccumP = 0;
     $allowTags = strtolower(str_replace(' ', '', $conf['allowTags']));
     $denyTags = strtolower(str_replace(' ', '', $conf['denyTags']));
     $totalLen = strlen($theValue);
     do {
         if (!$inside) {
             if (!is_array($currentTag)) {
                 // These operations should only be performed on code outside the typotags...
                 // data: this checks that we enter tags ONLY if the first char in the tag is alphanumeric OR '/'
                 $len_p = 0;
                 $c = 100;
                 do {
                     $len = strcspn(substr($theValue, $pointer + $len_p), '<');
                     $len_p += $len + 1;
                     $endChar = ord(strtolower(substr($theValue, $pointer + $len_p, 1)));
                     $c--;
                 } while ($c > 0 && $endChar && ($endChar < 97 || $endChar > 122) && $endChar != 47);
                 $len = $len_p - 1;
             } else {
                 // If we're inside a currentTag, just take it to the end of that tag!
                 $tempContent = strtolower(substr($theValue, $pointer));
                 $len = strpos($tempContent, '</' . $currentTag[0]);
                 if (is_string($len) && !$len) {
                     $len = strlen($tempContent);
                 }
             }
             // $data is the content until the next <tag-start or end is detected.
             // In case of a currentTag set, this would mean all data between the start- and end-tags
             $data = substr($theValue, $pointer, $len);
             if ($data != '') {
                 if ($stripNL) {
                     // If the previous tag was set to strip NewLines in the beginning of the next data-chunk.
                     $data = preg_replace('/^[ ]*' . CR . '?' . LF . '/', '', $data);
                 }
                 // These operations should only be performed on code outside the tags...
                 if (!is_array($currentTag)) {
                     // Constants
                     $tmpConstants = $GLOBALS['TSFE']->tmpl->setup['constants.'];
                     if ($conf['constants'] && is_array($tmpConstants)) {
                         foreach ($tmpConstants as $key => $val) {
                             if (is_string($val)) {
                                 $data = str_replace('###' . $key . '###', $val, $data);
                             }
                         }
                     }
                     // Short
                     if (is_array($conf['short.'])) {
                         $shortWords = $conf['short.'];
                         krsort($shortWords);
                         foreach ($shortWords as $key => $val) {
                             if (is_string($val)) {
                                 $data = str_replace($key, $val, $data);
                             }
                         }
                     }
                     // stdWrap
                     if (is_array($conf['plainTextStdWrap.'])) {
                         $data = $this->stdWrap($data, $conf['plainTextStdWrap.']);
                     }
                     // userFunc
                     if ($conf['userFunc']) {
                         $data = $this->callUserFunction($conf['userFunc'], $conf['userFunc.'], $data);
                     }
                     // Makelinks: (Before search-words as we need the links to be generated when searchwords go on...!)
                     if ($conf['makelinks']) {
                         $data = $this->http_makelinks($data, $conf['makelinks.']['http.']);
                         $data = $this->mailto_makelinks($data, $conf['makelinks.']['mailto.']);
                     }
                     // Search Words:
                     if ($GLOBALS['TSFE']->no_cache && $conf['sword'] && is_array($GLOBALS['TSFE']->sWordList) && $GLOBALS['TSFE']->sWordRegEx) {
                         $newstring = '';
                         do {
                             $pregSplitMode = 'i';
                             if (isset($GLOBALS['TSFE']->config['config']['sword_noMixedCase']) && !empty($GLOBALS['TSFE']->config['config']['sword_noMixedCase'])) {
                                 $pregSplitMode = '';
                             }
                             $pieces = preg_split('/' . $GLOBALS['TSFE']->sWordRegEx . '/' . $pregSplitMode, $data, 2);
                             $newstring .= $pieces[0];
                             $match_len = strlen($data) - (strlen($pieces[0]) + strlen($pieces[1]));
                             if (strstr($pieces[0], '<') || strstr($pieces[0], '>')) {
                                 // Returns TRUE, if a '<' is closer to the string-end than '>'.
                                 // This is the case if we're INSIDE a tag (that could have been
                                 // made by makelinks...) and we must secure, that the inside of a tag is
                                 // not marked up.
                                 $inTag = strrpos($pieces[0], '<') > strrpos($pieces[0], '>');
                             }
                             // The searchword:
                             $match = substr($data, strlen($pieces[0]), $match_len);
                             if (trim($match) && strlen($match) > 1 && !$inTag) {
                                 $match = $this->wrap($match, $conf['sword']);
                             }
                             // Concatenate the Search Word again.
                             $newstring .= $match;
                             $data = $pieces[1];
                         } while ($pieces[1]);
                         $data = $newstring;
                     }
                 }
                 $contentAccum[$contentAccumP] .= $data;
             }
             $inside = 1;
         } else {
             // tags
             $len = strcspn(substr($theValue, $pointer), '>') + 1;
             $data = substr($theValue, $pointer, $len);
             if (StringUtility::isLastPartOfString($data, '/>') && !GeneralUtility::isFirstPartOfStr($data, '<link ')) {
                 $tagContent = substr($data, 1, -2);
             } else {
                 $tagContent = substr($data, 1, -1);
             }
             $tag = explode(' ', trim($tagContent), 2);
             $tag[0] = strtolower($tag[0]);
             if ($tag[0][0] === '/') {
                 $tag[0] = substr($tag[0], 1);
                 $tag['out'] = 1;
             }
             if ($conf['tags.'][$tag[0]]) {
                 $treated = 0;
                 $stripNL = 0;
                 // in-tag
                 if (!$currentTag && !$tag['out']) {
                     // $currentTag (array!) is the tag we are currently processing
                     $currentTag = $tag;
                     $contentAccumP++;
                     $treated = 1;
                     // in-out-tag: img and other empty tags
                     if (preg_match('/^(area|base|br|col|hr|img|input|meta|param)$/i', $tag[0])) {
                         $tag['out'] = 1;
                     }
                 }
                 // out-tag
                 if ($currentTag[0] == $tag[0] && $tag['out']) {
                     $theName = $conf['tags.'][$tag[0]];
                     $theConf = $conf['tags.'][$tag[0] . '.'];
                     // This flag indicates, that NL- (13-10-chars) should be stripped first and last.
                     $stripNL = $theConf['stripNL'] ? 1 : 0;
                     // This flag indicates, that this TypoTag section should NOT be included in the nonTypoTag content.
                     $breakOut = $theConf['breakoutTypoTagContent'] ? 1 : 0;
                     $this->parameters = array();
                     if ($currentTag[1]) {
                         $params = GeneralUtility::get_tag_attributes($currentTag[1]);
                         if (is_array($params)) {
                             foreach ($params as $option => $val) {
                                 $this->parameters[strtolower($option)] = $val;
                             }
                         }
                     }
                     $this->parameters['allParams'] = trim($currentTag[1]);
                     // Removes NL in the beginning and end of the tag-content AND at the end of the currentTagBuffer.
                     // $stripNL depends on the configuration of the current tag
                     if ($stripNL) {
                         $contentAccum[$contentAccumP - 1] = preg_replace('/' . CR . '?' . LF . '[ ]*$/', '', $contentAccum[$contentAccumP - 1]);
                         $contentAccum[$contentAccumP] = preg_replace('/^[ ]*' . CR . '?' . LF . '/', '', $contentAccum[$contentAccumP]);
                         $contentAccum[$contentAccumP] = preg_replace('/' . CR . '?' . LF . '[ ]*$/', '', $contentAccum[$contentAccumP]);
                     }
                     $this->data[$this->currentValKey] = $contentAccum[$contentAccumP];
                     $newInput = $this->cObjGetSingle($theName, $theConf, '/parseFunc/.tags.' . $tag[0]);
                     // fetch the content object
                     $contentAccum[$contentAccumP] = $newInput;
                     $contentAccumP++;
                     // If the TypoTag section
                     if (!$breakOut) {
                         $contentAccum[$contentAccumP - 2] .= $contentAccum[$contentAccumP - 1] . $contentAccum[$contentAccumP];
                         unset($contentAccum[$contentAccumP]);
                         unset($contentAccum[$contentAccumP - 1]);
                         $contentAccumP -= 2;
                     }
                     unset($currentTag);
                     $treated = 1;
                 }
                 // other tags...
                 if (!$treated) {
                     $contentAccum[$contentAccumP] .= $data;
                 }
             } else {
                 // If a tag was not a typo tag, then it is just added to the content
                 $stripNL = 0;
                 if (GeneralUtility::inList($allowTags, $tag[0]) || $denyTags != '*' && !GeneralUtility::inList($denyTags, $tag[0])) {
                     $contentAccum[$contentAccumP] .= $data;
                 } else {
                     $contentAccum[$contentAccumP] .= HTMLSpecialChars($data);
                 }
             }
             $inside = 0;
         }
         $pointer += $len;
     } while ($pointer < $totalLen);
     // Parsing nonTypoTag content (all even keys):
     reset($contentAccum);
     $contentAccumCount = count($contentAccum);
     for ($a = 0; $a < $contentAccumCount; $a++) {
         if ($a % 2 != 1) {
             // stdWrap
             if (is_array($conf['nonTypoTagStdWrap.'])) {
                 $contentAccum[$a] = $this->stdWrap($contentAccum[$a], $conf['nonTypoTagStdWrap.']);
             }
             // userFunc
             if ($conf['nonTypoTagUserFunc']) {
                 $contentAccum[$a] = $this->callUserFunction($conf['nonTypoTagUserFunc'], $conf['nonTypoTagUserFunc.'], $contentAccum[$a]);
             }
         }
     }
     return implode('', $contentAccum);
 }
 /**
  * Returns the parsed and processed configuration
  *
  * @param array $rawConfiguration Raw configuration from TypoScriptFrontendController::$config['config']
  * @return array
  */
 protected function getConfiguration(array $rawConfiguration)
 {
     $configuration = isset($rawConfiguration['cors.']) ? $rawConfiguration['cors.'] : [];
     foreach ($configuration as $option => $value) {
         // Perform stdWrap processing on all options
         if (StringUtility::isLastPartOfString($option, '.') && isset($value['stdWrap.'])) {
             unset($configuration[$option]);
             $option = substr($option, 0, -1);
             $value = $this->frontendController->cObj->stdWrap($configuration[$option], $value['stdWrap.']);
         }
         switch ($option) {
             case 'allowCredentials':
                 $value = in_array($value, ['1', 'true'], TRUE);
                 break;
             case 'allowHeaders':
             case 'allowMethods':
             case 'allowOrigin':
             case 'exposeHeaders':
                 $value = GeneralUtility::trimExplode(',', $value);
                 break;
             case 'maxAge':
                 $value = (int) $value;
                 break;
         }
         if ($option == 'allowOrigin.' && isset($value['pattern'])) {
             $option = 'allowOriginPattern';
             $value = $value['pattern'];
         }
         $configuration[$option] = $value;
     }
     return $configuration;
 }
 /**
  * Applies stdWrap on Fluid path definitions
  *
  * @param array $paths
  *
  * @return array
  */
 protected function applyStandardWrapToFluidPaths(array $paths)
 {
     $finalPaths = array();
     foreach ($paths as $key => $path) {
         if (StringUtility::isLastPartOfString($key, '.')) {
             if (isset($paths[substr($key, 0, -1)])) {
                 continue;
             }
             $path = $this->cObj->stdWrap('', $path);
         } elseif (isset($paths[$key . '.'])) {
             $path = $this->cObj->stdWrap($path, $paths[$key . '.']);
         }
         $finalPaths[$key] = GeneralUtility::getFileAbsFileName($path);
     }
     return $finalPaths;
 }
 /**
  * @test
  * @dataProvider isLastPartOfStringReturnsFalseForNotMatchingFirstPartDataProvider
  */
 public function isLastPartOfStringReturnsFalseForNotMatchingFirstPart($string, $part)
 {
     $this->assertFalse(\TYPO3\CMS\Core\Utility\StringUtility::isLastPartOfString($string, $part));
 }