protected function send45() { /* @var $mail TYPO3\CMS\Core\Mail\MailMessage */ $mail = tx_rnbase::makeInstance(tx_rnbase_util_Typo3Classes::getMailMessageClass()); $mail->setFrom(array($this->from => $this->fromName)); $mail->setTo(tx_rnbase_util_Strings::trimExplode(',', $this->toAsString)); $mail->setSubject($this->subject); if ($this->replyTo) { $mail->addReplyTo($this->replyTo, $this->replyToName); } // Or set it after like this if ($this->htmlPart) { $mail->setBody($this->htmlPart, 'text/html'); } // Add alternative parts with addPart() if ($this->textPart) { $mail->addPart($this->textPart, 'text/plain'); } if (!empty($this->attachments)) { foreach ($this->attachments as $attachment) { if (!$mail->attach(Swift_Attachment::fromPath($attachment['src']))) { tx_rnbase_util_Logger::warn('Adding attachment failed!', 'rn_base', array('subject' => $mail->subject, 'to' => $this->toAsString, 'attachment' => $attachment)); } } } $mail->send(); }
/** * Returns the style for each data set. This is either an instance of tx_pbimagegraph_Fill_Array or * a simple php array with style data * @param $confArr * @return array */ public function getDataStyles($plotId, $confArr) { // Es wird der Style mit der ID 0 ausgelesen. Hier können mehrere Angaben gemacht werden $ret = array(); $type = $confArr['dataStyle.']['0']; $data = $confArr['dataStyle.']['0.']; switch ($type) { case 'color': case 'addColor': $strColors = tx_rnbase_util_Strings::trimExplode(',', $data['color']); foreach ($strColors as $color) { $ret[] = array('type' => 'color', 'color' => $color); } break; case 'gradient': $intDirection = tx_rnbase_plot_Builder::readConstant('IMAGE_GRAPH_GRAD_' . strtoupper($data['direction'])); $strColorsStart = tx_rnbase_util_Strings::trimExplode(',', $data['startColor']); $strColorsEnd = tx_rnbase_util_Strings::trimExplode(',', $data['endColor']); $maxStart = count($strColorsStart); $maxEnd = count($strColorsEnd); $max = $maxStart > $maxEnd ? $maxStart : $maxEnd; for ($i = 0; $i < $max; $i++) { $strStartColor = $i < $maxStart ? $strColorsStart[$i] : $strColorsStart[$maxStart - 1]; $strEndColor = $i < $maxEnd ? $strColorsEnd[$i] : $strColorsEnd[$maxEnd - 1]; $ret[] = array('type' => 'gradient', 'color' => array($intDirection, $strStartColor, $strEndColor)); } break; } return $ret; }
/** * comma separated list of mailaddresses. * @param string $emailAsString */ public function setTo($emailAsString) { $addresses = tx_rnbase_util_Strings::trimExplode(',', $emailAsString); $this->to = array(); foreach ($addresses as $mailAddress) { $this->to[$mailAddress] = ''; } }
/** * @param tx_rnbase_parameters $parameters * @param tx_rnbase_configurations $configurations * * @return string */ function execute(&$parameters, &$configurations) { $this->setConfigurations($configurations); $debugKey = $configurations->get($this->getConfId() . '_debugview'); $debug = $debugKey && ($debugKey === '1' || $_GET['debug'] && array_key_exists($debugKey, array_flip(tx_rnbase_util_Strings::trimExplode(',', $_GET['debug']))) || $_POST['debug'] && array_key_exists($debugKey, array_flip(tx_rnbase_util_Strings::trimExplode(',', $_POST['debug'])))); if ($debug) { $time = microtime(TRUE); $memStart = memory_get_usage(); } if ($configurations->getBool($this->getConfId() . 'toUserInt')) { if ($debug) { tx_rnbase_util_Debug::debug('Converting to USER_INT!', 'View statistics for: ' . $this->getConfId() . ' Key: ' . $debugKey); } $configurations->convertToUserInt(); } // Add JS or CSS files $this->addResources($configurations, $this->getConfId()); $cacheHandler = $this->getCacheHandler($configurations, $this->getConfId() . '_caching.'); $out = $cacheHandler ? $cacheHandler->getOutput() : ''; $cached = !empty($out); if (!$cached) { $viewData =& $configurations->getViewData(); tx_rnbase_util_Misc::pushTT(get_class($this), 'handleRequest'); $out = $this->handleRequest($parameters, $configurations, $viewData); tx_rnbase_util_Misc::pullTT(); if (!$out) { // View // It is possible to set another view via typoscript $viewClassName = $configurations->get($this->getConfId() . 'viewClassName'); $viewClassName = strlen($viewClassName) > 0 ? $viewClassName : $this->getViewClassName(); // TODO: error handling... $view = tx_rnbase::makeInstance($viewClassName); $view->setTemplatePath($configurations->getTemplatePath()); if (method_exists($view, 'setController')) { $view->setController($this); } // Das Template wird komplett angegeben $tmplName = $this->getTemplateName(); if (!$tmplName || !strlen($tmplName)) { tx_rnbase_util_Misc::mayday('No template name defined!'); } $view->setTemplateFile($configurations->get($tmplName . 'Template', TRUE)); tx_rnbase_util_Misc::pushTT(get_class($this), 'render'); $out = $view->render($tmplName, $configurations); tx_rnbase_util_Misc::pullTT(); } if ($cacheHandler) { $cacheHandler->setOutput($out); } } if ($debug) { $memEnd = memory_get_usage(); tx_rnbase_util_Debug::debug(array('Action' => get_class($this), 'Conf Id' => $this->getConfId(), 'Execution Time' => microtime(TRUE) - $time, 'Memory Start' => $memStart, 'Memory End' => $memEnd, 'Memory Consumed' => $memEnd - $memStart, 'Cached?' => $cached ? 'yes' : 'no', 'CacheHandler' => is_object($cacheHandler) ? get_class($cacheHandler) : '', 'SubstCacheEnabled?' => tx_rnbase_util_Templates::isSubstCacheEnabled() ? 'yes' : 'no'), 'View statistics for: ' . $this->getConfId() . ' Key: ' . $debugKey); } // reset the substCache after each view! tx_rnbase_util_Templates::resetSubstCache(); return $out; }
/** * * @group integration */ public function test_is_encoding() { $strUtf8 = pack("H*", self::$hexUtf8); $strIso88591 = pack("H*", self::$hexIso88591); if (false) { echo '<pre>' . var_export(array('iso88591' => array('string' => $strIso88591, 'utf8 level' => tx_rnbase_util_Strings::isUtf8String($strIso88591), 'utf8 encoding' => tx_mklib_util_Encoding::detectUtfEncoding($strIso88591), 'bytelength' => mb_strlen($strIso88591, '8bit'), 'bin2hex' => bin2hex($strIso88591), 'is utf8' => tx_mklib_util_Encoding::isEncoding($strIso88591, 'UTF-8'), 'is iso88591' => tx_mklib_util_Encoding::isEncoding($strIso88591, 'ISO-8859-1')), 'utf8' => array('string' => $strUtf8, 'utf8 level' => tx_rnbase_util_Strings::isUtf8String($strUtf8), 'utf8 encoding' => tx_mklib_util_Encoding::detectUtfEncoding($strUtf8), 'bytelength' => mb_strlen($strUtf8, '8bit'), 'bin2hex' => bin2hex($strUtf8), 'is utf8' => tx_mklib_util_Encoding::isEncoding($strUtf8, 'UTF-8'), 'is iso88591' => tx_mklib_util_Encoding::isEncoding($strUtf8, 'ISO-8859-1')), 'DEBUG: ' . __FILE__ . '&' . __METHOD__ . ' Line: ' . __LINE__), true) . '</pre>'; } // @TODO: remove me $this->assertTrue(tx_mklib_util_Encoding::isEncoding($strIso88591, 'ISO-8859-1'), '$strIso88591 ist NICHT ISO-8859-1'); $this->assertFalse(tx_mklib_util_Encoding::isEncoding($strIso88591, 'UTF-8'), '$strIso88591 IST UTF-8'); $this->assertTrue(tx_mklib_util_Encoding::isEncoding($strUtf8, 'UTF-8'), '$strUtf8 ist NICHT UTF-8'); $this->assertFalse(tx_mklib_util_Encoding::isEncoding($strUtf8, 'ISO-8859-1'), '$strUtf8 IST ISO-8859-1'); }
/** * Erzeugt anhand von einer URL hidden Felder, welche mit übergeben werden. * Dabei werden die Get-Parameter aus der Action URL entfernt. * Das ist wichtig, wenn das Formular mit GET abgeschickt wird * und die Action URL bereits GET Parameter enthält. * Die in der URL enthaltenen Parameter gehen verloren! * * @author Michael Wagner * @param string $url * @return string */ public static function getHiddenFieldsForUrlParams($url) { $sysHidden = ''; $params = array(); if (strpos($url, '?') !== FALSE) { $params = substr($url, strpos($url, '?') + 1); $utility = tx_rnbase_util_Typo3Classes::getGeneralUtilityClass(); $params = $utility::explodeUrl2Array($params); $url = substr($url, 0, strpos($url, '?')); } foreach ($params as $name => $value) { $name = tx_rnbase_util_Strings::removeXSS($name); $value = tx_rnbase_util_Strings::removeXSS($value); $sysHidden .= '<input type="hidden" name="' . $name . '" value="' . $value . '" />'; } return $sysHidden; }
public function init(tx_rnbase_configurations $conf, $confId) { $this->conf = $conf; $this->confId = $confId; $apiKey = $conf->get($confId . 'google.apikey'); $apiKey = $apiKey ? $apiKey : NULL; $width = $conf->get($confId . 'width'); $height = $conf->get($confId . 'height'); $this->map = tx_rnbase::makeInstance('tx_wecmap_map_google', $apiKey, $width, $height); // Der MapType $mapType = $conf->get($confId . 'maptype') ? constant($conf->get($confId . 'maptype')) : NULL; $types = array_flip(tx_rnbase_maps_TypeRegistry::getMapTypes()); if ($mapType && array_key_exists($mapType, $types)) { $this->setMapType(tx_rnbase_maps_TypeRegistry::getInstance()->getType($this, $mapType)); } // Controls $controls = $conf->get($confId . 'google.controls'); if ($controls) { $controls = tx_rnbase_util_Strings::trimExplode(',', $controls); foreach ($controls as $control) { $this->addControl(tx_rnbase::makeInstance('tx_rnbase_maps_google_Control', $control)); } } }
/** * Return label markers defined by Typoscript * * @param tx_rnbase_util_FormatUtil $formatter * @param string $confId * @param string $marker * @param array $defaultMarkerArr * @return array */ public function initTSLabelMarkers(&$formatter, $confId, $marker, $defaultMarkerArr = 0) { $arr1 = array(); if ($labels = $formatter->configurations->get($confId . 'labels')) { $labels = tx_rnbase_util_Strings::trimExplode(',', $labels); $labelArr = array(); foreach ($labels as $label) { // Für die Abfrage nach den Labels dürfen keine Punkte als Trenner verwendet werden // Daher Umwandlung in Underscores $labelId = str_replace('.', '_', $confId . 'label.' . $label); $labelArr['label_' . $label] = $formatter->configurations->getLL($labelId); } $arr1 = $formatter->getItemMarkerArrayWrapped($labelArr, $confId, 0, $marker . '_'); } $this->defaultMarkerArr = array_merge($arr1, $this->defaultMarkerArr); return $this->defaultMarkerArr; }
/** * This callback is called by the includeSubTemplates preg_replace * * @access private * * @param unknown $match * @return string */ public static function cbIncludeSubTemplates($match) { list($filePath, $subPart) = tx_rnbase_util_Strings::trimExplode('@', $match[1]); try { $fileContent = self::getSubpartFromFile($filePath, '###' . strtoupper($subPart) . '###'); } catch (Exception $e) { $fileContent = '<!-- ' . $e->getMessage() . ' -->'; } return $fileContent; }
/** * Get a exploded value * * @param string $pathKey * @param string $delim * @param boolean $deep * @return array */ public function getExploded($pathKey, $delim = ',', $deep = FALSE) { $value = $this->get($pathKey, $deep); if (is_array($value)) { return $value; } if (empty($value)) { return array(); } return tx_rnbase_util_Strings::trimExplode($delim, $value, TRUE); }
/** * Erstellt eine Select-Box aus dem übergebenen Array. * in den Options kann mit dem key reload angegeben werden, * ob das Formular bei Änderungen direkt abgeschickt werden soll. * mit dem key onchange kann ein eigene onchange Funktion * hinterlegt werden. * außerdem kann in den options mit multiple angegeben werden * ob es eine mehrfach Auswahl geben soll * * @param string $name * @param string $currentValues comma separated * @param array $selectOptions * @param array $options * @return string */ public function createSelectByArray($name, $currentValues, array $selectOptions, $options = array()) { $options = is_array($options) ? $options : array(); $onChangeStr = $options['reload'] ? ' this.form.submit(); ' : ''; if ($options['onchange']) { $onChangeStr .= $options['onchange']; } if ($onChangeStr) { $onChangeStr = ' onchange="' . $onChangeStr . '" '; } $multiple = $options['multiple'] ? ' multiple="multiple"' : ''; $name .= $options['multiple'] ? '[]' : ''; $size = $options['size'] ? ' size="' . $options['size'] . '"' : ''; $out = '<select name="' . $name . '" class="select"' . $onChangeStr . $multiple . $size . '>'; $currentValues = tx_rnbase_util_Strings::trimExplode(',', $currentValues); // Die Options ermitteln foreach ($selectOptions as $value => $label) { $selected = ''; if (in_array($value, $currentValues)) { $selected = 'selected="selected"'; } $out .= '<option value="' . $value . '" ' . $selected . '>' . $label . '</option>'; } $out .= '</select>'; return $out; }
/** * Returns a given CamelCasedString as an lowercase string with underscores. * Example: Converts BlogExample to blog_example, and minimalValue to minimal_value * Taken from t3lib_div for backward compatibility * * @deprecated use tx_rnbase_util_Strings::camelCaseToLowerCaseUnderscored instead * * @param string $string: String to be converted to lowercase underscore * @return string lowercase_and_underscored_string */ public static function camelCaseToLowerCaseUnderscored($string) { self::logDeprecatedFunction(); tx_rnbase::load('tx_rnbase_util_Strings'); return tx_rnbase_util_Strings::camelCaseToLowerCaseUnderscored($string); }
/** * Find the actions to handle the request * You can define more than one actions per request. So think of an action as a content element * to render. * So if your plugin supports a list and a detail view, you can render both of them * on the same page, including only one plugin. Make a view selection and add both views. * The controller will serve the request to both actions. * * Order: defaultAction < configurationDefaultAction < parametersAction < configurationsAction * * 1.) The defaultAction is the ultimative Fallback if nothing else is given. * 2.) The configurationDefaultAction can be set in TS and/or flexform to customize the initial view. * 3.) The parametersAction is given by form or link to controll the behaviour. * 4.) The configurationAction can force a fixed view of a context element. * * @param object the parameters object * @param object the configurations objet * @return array an array with the actions or NULL */ protected function _findAction($parameters, $configurations) { // What should be preferred? Config or Request? // An action from parameter is preferred $action = !intval($configurations->get('ignoreActionParam')) ? $this->_getParameterAction($parameters) : FALSE; if (!$action) { $action = $configurations->get('action'); } else { // Bei Actions aus dem Request kodierte Klassen korrigieren $action = str_replace('\\\\', '\\', $action); } // Falls es mehrere Actions sind den String splitten if ($action) { $action = tx_rnbase_util_Strings::trimExplode(',', $action); } if (is_array($action) && count($action) == 1) { $action = tx_rnbase_util_Strings::trimExplode('|', $action[0]); // Nochmal mit Pipe versuchen } // If there is still no action we use defined defaultAction $action = !$action ? $configurations->get('defaultAction') : $action; return $action; }
/** * validates a value with the tca definition of a specific table. * * @param string $value * @param string $field * @param string $tableName * @param array $options * only_record_fields: validates only fields included in the record * @return boolean */ public static function validateField($value, $field, $tableName, $options = NULL) { $options = tx_rnbase_model_data::getInstance($options); $columns = self::getTcaColumns($tableName, $options); // skip, if there is no config if (empty($columns[$field]['config'])) { return TRUE; } $config =& $columns[$field]['config']; // check minitems if (!empty($config['minitems']) && $config['minitems'] > 0 && empty($value)) { return FALSE; } // check eval list if (!empty($config['eval'])) { // check eval list tx_rnbase::load('tx_rnbase_util_Strings'); $evalList = tx_rnbase_util_Strings::trimExplode(',', $config['eval'], TRUE); foreach ($evalList as $func) { switch ($func) { // @TODO: implement the other evals case 'required': if (empty($value)) { return FALSE; } break; default: // fiel is not invalid! break; } } } return TRUE; }
/** * Umwandlung eines Zeitstrings yyyy-mm-dd H:i:s in einen Timestamp * * @param string $datetime Format: yyyy-mm-dd H:i:s * @return int */ static function datetime_mysql2tstamp($datetime, $timezone = 'CET') { list($datum, $zeit) = explode(' ', $datetime); list($jahr, $monat, $tag) = tx_rnbase_util_Strings::intExplode('-', $datum); list($std, $min, $sec) = $zeit ? tx_rnbase_util_Strings::intExplode(':', $zeit) : array(0, 0, 0); return self::getTimeStamp($jahr, $monat, $tag, $std, $min, $sec, $timezone); }
/** * Render an array of data entries with an html template. The html template should look like this: * ###DATAS### * ###DATA### * ###DATA_UID### * ###DATA### * ###DATAEMPTYLIST### * Shown if list is empty * ###DATAEMPTYLIST### * ###DATAS### * We have some conventions here: * The given parameter $marker should be named 'DATA' for this example. The the list subpart * is experted to be named '###'.$marker.'S###'. Please notice the trailing S! * If you want to render a pagebrowser add it to the $viewData with key 'pagebrowser'. * A filter will be detected and rendered too. It should be available in $viewData with key 'filter'. * * @param array|Traversable $dataArr entries * @param string $template * @param string $markerClassname item-marker class * @param string $confId ts-Config for data entries like team. * @param string $marker name of marker like TEAM * @param tx_rnbase_util_FormatUtil $formatter * @param array $markerParams array of settings for itemmarker * @return string */ function render(&$dataArr, $viewData, $template, $markerClassname, $confId, $marker, $formatter, $markerParams = NULL) { $viewData = is_object($viewData) ? $viewData : new ArrayObject(); $debugKey = $formatter->getConfigurations()->get($confId . '_debuglb'); $debug = $debugKey && ($debugKey === '1' || $_GET['debug'] && array_key_exists($debugKey, array_flip(tx_rnbase_util_Strings::trimExplode(',', $_GET['debug']))) || $_POST['debug'] && array_key_exists($debugKey, array_flip(tx_rnbase_util_Strings::trimExplode(',', $_POST['debug'])))); if ($debug) { $time = microtime(TRUE); $mem = memory_get_usage(); $wrapTime = tx_rnbase_util_FormatUtil::$time; $wrapMem = tx_rnbase_util_FormatUtil::$mem; } $outerMarker = $this->getOuterMarker($marker, $template); $htmlParser = tx_rnbase_util_Typo3Classes::getHtmlParserClass(); while ($templateList = $htmlParser::getSubpart($template, '###' . $outerMarker . 'S###')) { if ((is_array($dataArr) || $dataArr instanceof Traversable) && count($dataArr)) { /* @var $listMarker tx_rnbase_util_ListMarker */ $listMarker = tx_rnbase::makeInstance('tx_rnbase_util_ListMarker', $this->info->getListMarkerInfo()); $templateEntry = $htmlParser::getSubpart($templateList, '###' . $marker . '###'); $offset = 0; $pageBrowser = $viewData->offsetGet('pagebrowser'); if ($pageBrowser) { $state = $pageBrowser->getState(); $offset = $state['offset']; } $markerArray = $subpartArray = array(); $listMarker->addVisitors($this->visitors); $out = $listMarker->render($dataArr, $templateEntry, $markerClassname, $confId, $marker, $formatter, $markerParams, $offset); $subpartArray['###' . $marker . '###'] = $out; $subpartArray['###' . $marker . 'EMPTYLIST###'] = ''; // Das Menu für den PageBrowser einsetzen if ($pageBrowser) { $subpartArray['###PAGEBROWSER###'] = tx_rnbase_util_BaseMarker::fillPageBrowser($htmlParser::getSubpart($template, '###PAGEBROWSER###'), $pageBrowser, $formatter, $confId . 'pagebrowser.'); $listSize = $pageBrowser->getListSize(); } else { $listSize = count($dataArr); } $markerArray['###' . $marker . 'COUNT###'] = $formatter->wrap($listSize, $confId . 'count.'); // charbrowser $pagerData = $viewData->offsetGet('pagerData'); $charPointer = $viewData->offsetGet('charpointer'); $subpartArray['###CHARBROWSER###'] = tx_rnbase_util_BaseMarker::fillCharBrowser(tx_rnbase_util_Templates::getSubpart($template, '###CHARBROWSER###'), $markerArray, $pagerData, $charPointer, $formatter->getConfigurations(), $confId . 'charbrowser.'); $out = tx_rnbase_util_BaseMarker::substituteMarkerArrayCached($templateList, $markerArray, $subpartArray); } else { // Support für EMPTYLIST-Block if (tx_rnbase_util_BaseMarker::containsMarker($template, $marker . 'EMPTYLIST')) { $out = $htmlParser::getSubpart($template, '###' . $marker . 'EMPTYLIST###'); } else { $out = $this->info->getEmptyListMessage($confId, $viewData, $formatter->getConfigurations()); } } $template = tx_rnbase_util_Templates::substituteSubpart($template, '###' . $outerMarker . 'S###', $out, 0); } $markerArray = array(); $subpartArray = array(); // Muss ein Formular mit angezeigt werden // Zuerst auf einen Filter prüfen $filter = $viewData->offsetGet('filter'); if ($filter) { $template = $filter->getMarker()->parseTemplate($template, $formatter, $confId . 'filter.', $marker); } // Jetzt noch die alte Variante $markerArray['###SEARCHFORM###'] = ''; $seachform = $viewData->offsetGet('searchform'); if ($seachform) { $markerArray['###SEARCHFORM###'] = $seachform; } $out = tx_rnbase_util_BaseMarker::substituteMarkerArrayCached($template, $markerArray, $subpartArray); if ($debug) { tx_rnbase::load('class.tx_rnbase_util_Misc.php'); $wrapTime = tx_rnbase_util_FormatUtil::$time - $wrapTime; $wrapMem = tx_rnbase_util_FormatUtil::$mem - $wrapMem; tx_rnbase_util_Debug::debug(array('Rows' => count($dataArr), 'Execustion time' => microtime(TRUE) - $time, 'WrapTime' => $wrapTime, 'WrapMem' => $wrapMem, 'Memory start' => $mem, 'Memory consumed' => memory_get_usage() - $mem), 'ListBuilder Statistics for: ' . $confId . ' Key: ' . $debugKey); } return $out; }
/** * removes xss from the value * * @param string $field * @return string */ public function getCleaned($paramName, $qualifier = '') { $value = $this->get($paramName, $qualifier); // remove Cross-Site Scripting if (!empty($value) && strlen($value) > 3) { $value = tx_rnbase_util_Strings::removeXSS($value); } return $value; }
/** * Open a (persistent) connection to a MySQL server * mssql_pconnect() wrapper function * Method is taken from t3lib_db * * @param string Database host IP/domain * @param string Username to connect with. * @param string Password to connect with. * @return pointer Returns a positive MySQL persistent link identifier on success, or FALSE on error. */ private function connect($credArr) { $dbHost = $credArr['host'] ? $credArr['host'] : 'localhost'; $dbUsername = $credArr['username']; $dbPassword = $credArr['password']; // if the connection fails we need a different method to get the error message @ini_set('track_errors', 1); @ini_set('html_errors', 0); // check if MySQL extension is loaded if (!extension_loaded('mssql')) { $message = 'Database Error: It seems that MsSQL support for PHP is not installed!'; throw new RuntimeException($message, 1271492606); } // Check for client compression if ($credArr['no_pconnect']) { $link = @mssql_connect($dbHost, $dbUsername, $dbPassword); } else { $link = @mssql_pconnect($dbHost, $dbUsername, $dbPassword); } $error_msg = $php_errormsg; @ini_restore('track_errors'); @ini_restore('html_errors'); if (!$link) { $message = 'Database Error: Could not connect to MySQL server ' . $dbHost . ' with user ' . $dbUsername . ': ' . $error_msg; throw new RuntimeException($message, 1271492616); } $setDBinit = tx_rnbase_util_Strings::trimExplode(LF, str_replace("' . LF . '", LF, $credArr['setDBinit']), TRUE); foreach ($setDBinit as $v) { if (mssql_query($v, $link) === FALSE) { // TODO: handler errors } } return $link; }
/** * * @deprecated use tx_rnbase_util_Strings::debugString */ public static function debugString($str) { tx_rnbase::load('tx_rnbase_util_Strings'); return tx_rnbase_util_Strings::debugString($str); }
/** * Converts field names for setters and geters * * @param string $string * @return string */ protected function underscore($string) { tx_rnbase::load('tx_rnbase_util_Strings'); return tx_rnbase_util_Strings::camelCaseToLowerCaseUnderscored($string); }
/** * Find out all visible sub modules for the current user. * mod.mymod._cfg.funcmenu.deny = className of submodules * mod.mymod._cfg.funcmenu.allow = className of submodules * @param array $items * @return array */ protected function getFuncMenuItems($items) { $visibleItems = $items; if ($denyItems = $this->getConfigurations()->get('_cfg.funcmenu.deny')) { $denyItems = tx_rnbase_util_Strings::trimExplode(',', $denyItems); foreach ($denyItems as $item) { unset($visibleItems[$item]); } } if ($allowItems = $this->getConfigurations()->get('_cfg.funcmenu.allow')) { $visibleItems = array(); $allowItems = tx_rnbase_util_Strings::trimExplode(',', $allowItems); foreach ($allowItems as $item) { $visibleItems[$item] = $items[$item]; } } return $visibleItems; }
/** * Build a single where clause. This is a compare of a column to a value with a given operator. * Based on the operator the string is hopefully correctly build. It is up to the client to * connect these single clauses with boolean operator for a complete where clause. * * @param string $tableAlias database tablename or alias * @param string $operator operator constant * @param string $col name of column * @param string $value value to compare to */ function setSingleWhereField($tableAlias, $operator, $col, $value) { $where = ''; switch ($operator) { case OP_NOTIN_INT: case OP_IN_INT: $value = implode(',', tx_rnbase_util_Strings::intExplode(',', $value)); $where .= $tableAlias . '.' . strtolower($col) . ' ' . $operator . ' (' . $value . ')'; break; case OP_NOTIN: case OP_IN: $values = tx_rnbase_util_Strings::trimExplode(',', $value); for ($i = 0, $cnt = count($values); $i < $cnt; $i++) { $values[$i] = $GLOBALS['TYPO3_DB']->fullQuoteStr($values[$i], $tableAlias); } $value = implode(',', $values); $where .= $tableAlias . '.' . strtolower($col) . ' ' . ($operator == OP_IN ? 'IN' : 'NOT IN') . ' (' . $value . ')'; break; case OP_NOTIN_SQL: case OP_IN_SQL: $where .= $tableAlias . '.' . strtolower($col) . ' ' . ($operator == OP_IN_SQL ? 'IN' : 'NOT IN') . ' (' . $value . ')'; break; case OP_INSET_INT: // Values splitten und einzelne Abfragen mit OR verbinden $where = $this->searchWhere($value, $tableAlias . '.' . strtolower($col), 'FIND_IN_SET_OR'); break; case OP_EQ: $where .= $tableAlias . '.' . strtolower($col) . ' = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($value, $tableAlias); break; case OP_NOTEQ: $where .= $tableAlias . '.' . strtolower($col) . ' != ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($value, $tableAlias); break; case OP_LT: $where .= $tableAlias . '.' . strtolower($col) . ' < ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($value, $tableAlias); break; case OP_LTEQ: $where .= $tableAlias . '.' . strtolower($col) . ' <= ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($value, $tableAlias); break; case OP_GT: $where .= $tableAlias . '.' . strtolower($col) . ' > ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($value, $tableAlias); break; case OP_GTEQ: $where .= $tableAlias . '.' . strtolower($col) . ' >= ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($value, $tableAlias); break; case OP_EQ_INT: case OP_NOTEQ_INT: case OP_GT_INT: case OP_LT_INT: case OP_GTEQ_INT: case OP_LTEQ_INT: $where .= $tableAlias . '.' . strtolower($col) . ' ' . $operator . ' ' . intval($value); break; case OP_EQ_NOCASE: $where .= 'lower(' . $tableAlias . '.' . strtolower($col) . ') = lower(' . $GLOBALS['TYPO3_DB']->fullQuoteStr($value, $tableAlias) . ')'; break; case OP_LIKE: // Stringvergleich mit LIKE $where .= $this->searchWhere($value, $tableAlias . '.' . strtolower($col)); break; case OP_LIKE_CONST: $where .= $this->searchWhere($value, $tableAlias . '.' . strtolower($col), OP_LIKE_CONST); break; default: tx_rnbase_util_Misc::mayday('Unknown Operator for comparation defined: ' . $operator); } return $where . ' '; }
/** * Liefert die * @param string $var * @return string|false */ public static function detectUtfEncoding($var) { tx_rnbase::load('tx_rnbase_util_Strings'); $bytes = tx_rnbase_util_Strings::isUtf8String($var); $encoding = FALSE; switch ($bytes) { case 2: $encoding = 'UTF-8'; break; case 3: $encoding = 'UTF-16'; break; case 4: $encoding = 'UTF-32'; break; } return $encoding; }
/** * Open a (persistent) connection to a MySQL server * mysql_pconnect() wrapper function * Method is taken from t3lib_db * * @param string Database host IP/domain * @param string Username to connect with. * @param string Password to connect with. */ private function connect($credArr) { if (!extension_loaded('mysqli')) { throw new \RuntimeException('Database Error: PHP mysqli extension not loaded. This is a must have for TYPO3 CMS!', 1271492607); } $dbHost = $credArr['host'] ? $credArr['host'] : 'localhost'; $dbUsername = $credArr['username']; $dbPassword = $credArr['password']; $dbPort = isset($credArr['port']) ? (int) $credArr['port'] : 3306; $dbSocket = empty($credArr['socket']) ? NULL : $credArr['socket']; $dbCompress = !empty($credArr['dbClientCompress']) && $dbHost != 'localhost' && $dbHost != '127.0.0.1'; if (isset($credArr['no_pconnect']) && !$credArr['no_pconnect']) { $dbHost = 'p:' . $dbHost; } $this->db = mysqli_init(); $connected = $this->db->real_connect($dbHost, $dbUsername, $dbPassword, NULL, $dbPort, $dbSocket, $dbCompress ? MYSQLI_CLIENT_COMPRESS : 0); if (!$connected) { $message = 'Database Error: Could not connect to MySQL server ' . $dbHost . ' with user ' . $dbUsername . ': ' . $this->sql_error(); throw new RuntimeException($message, 1271492616); } $this->isConnected = TRUE; $connectionCharset = empty($credArr['connectionCharset']) ? 'utf8' : $credArr['connectionCharset']; $this->db->set_charset($connectionCharset); $setDBinit = tx_rnbase_util_Strings::trimExplode(LF, str_replace("' . LF . '", LF, $credArr['setDBinit']), TRUE); foreach ($setDBinit as $v) { if ($this->query($v) === FALSE) { // TODO: handler errors } } }
/** * Removes dam references. If no parameter is given, all references will be removed. * * @param string $uids commaseperated uids */ public static function deleteReferences($tableName, $fieldName, $itemId, $uids = '') { $where = 'tablenames=' . tx_rnbase_util_DB::fullQuoteStr($tableName, 'tx_dam_mm_ref'); $where .= ' AND ident=' . tx_rnbase_util_DB::fullQuoteStr($fieldName, 'tx_dam_mm_ref'); $where .= ' AND uid_foreign=' . (int) $itemId; if (strlen(trim($uids))) { $uids = implode(',', tx_rnbase_util_Strings::intExplode(',', $uids)); $where .= ' AND uid_local IN (' . $uids . ') '; } tx_rnbase_util_DB::doDelete('tx_dam_mm_ref', $where); // Jetzt die Bildanzahl aktualisieren self::updateImageCount($tableName, $fieldName, $itemId); }
/** * Felder über ein Configarray setzen * * @param array $fields * @param array $cfgFields */ static function setConfigFieldsByArray(&$fields, &$cfgFields) { if (is_array($cfgFields)) { foreach ($cfgFields as $field => $cfg) { // Tabellen-Alias $tableAlias = substr($field, strlen($field) - 1, 1) == '.' ? strtoupper(substr($field, 0, strlen($field) - 1)) : strtoupper($field); if ($tableAlias == SEARCH_FIELD_JOINED) { // Hier sieht die Konfig etwas anders aus foreach ($cfg as $jField) { $jField['operator'] = constant($jField['operator']); $jField['cols'] = tx_rnbase_util_Strings::trimExplode(',', $jField['cols']); $fields[SEARCH_FIELD_JOINED][] = $jField; } continue; } if ($tableAlias == SEARCH_FIELD_CUSTOM) { $fields[SEARCH_FIELD_CUSTOM] = $cfg; } // Spaltenname if (!is_array($cfg)) { continue; } while (list($col, $data) = each($cfg)) { $colName = strtoupper(substr($col, 0, strlen($col) - 1)); // Operator und Wert if (!is_array($data)) { continue; } foreach ($data as $op => $value) { $fields[$tableAlias . '.' . $colName][constant($op)] = $value; } } } } }
/** * Init this link by typoscript setup * * @param tx_rnbase_configurations $configurations * @param string $confId * * @return tx_rnbase_util_Link */ public function initByTS($configurations, $confId, $parameterArr) { $parameterArr = is_array($parameterArr) ? $parameterArr : array(); $pid = $configurations->getCObj()->stdWrap($configurations->get($confId . 'pid'), $configurations->get($confId . 'pid.')); $qualifier = $configurations->get($confId . 'qualifier'); if ($qualifier) { $this->designator($qualifier); } $target = $configurations->get($confId . 'target'); if ($target) { $this->target($target); } // feste URL für externen Link if ($fixed = $configurations->get($confId . 'fixedUrl', TRUE)) { $this->destination($fixed); } else { $this->destination($pid ? $pid : $GLOBALS['TSFE']->id); // absolute und ggf. schema url erzeugen if ($absUrl = $configurations->get($confId . 'absurl')) { $this->setAbsUrl(TRUE, $absUrl == 1 || strtolower($absUrl) == 'true' ? '' : $absUrl); } } if (array_key_exists('SECTION', $parameterArr)) { $this->anchor(htmlspecialchars($parameterArr['SECTION'])); unset($parameterArr['SECTION']); } else { $this->anchor((string) $configurations->get($confId . 'section', TRUE)); } $this->parameters($parameterArr); // eigene Parameter für typolink, die einfach weitergegeben werden $typolinkCfg = $configurations->get($confId . 'typolink.'); if (is_array($typolinkCfg)) { foreach ($typolinkCfg as $cfgName => $cfgValue) { $this->addTypolinkParam($cfgName, $cfgValue); } } // Zusätzliche Parameter für den Link $atagParams = $configurations->get($confId . 'atagparams.', TRUE); if (is_array($atagParams)) { // Die Parameter werden jetzt nochmal per TS validiert und können somit dynamisch gesetzt werden $attributes = array(); foreach ($atagParams as $aParam => $lvalue) { if (substr($aParam, strlen($aParam) - 1, 1) == '.') { $aParam = substr($aParam, 0, strlen($aParam) - 1); if (array_key_exists($aParam, $atagParams)) { continue; } } $attributes[$aParam] = $configurations->getCObj()->stdWrap($atagParams[$aParam], $atagParams[$aParam . '.']); } $this->attributes($attributes); } // KeepVars prüfen // Per Default sind die KeepVars nicht aktiviert. Mit useKeepVars == 1 können sie hinzugefügt werden if (!$configurations->get($confId . 'useKeepVars')) { $this->overruled(); } elseif ($keepVarConf = $configurations->get($confId . 'useKeepVars.')) { // Sonderoptionen für KeepVars gesetzt $newKeepVars = array(); // skip empty values? default false! $skipEmpty = !empty($keepVarConf['skipEmpty']); $keepVars = $configurations->getKeepVars(); $allow = $keepVarConf['allow']; $deny = $keepVarConf['deny']; if ($allow) { $allow = tx_rnbase_util_Strings::trimExplode(',', $allow); foreach ($allow as $allowed) { $value = $keepVars->offsetGet($allowed); if ($skipEmpty && empty($value)) { continue; } $newKeepVars[$allowed] = $keepVars->offsetGet($allowed); } } elseif ($deny) { $deny = array_flip(tx_rnbase_util_Strings::trimExplode(',', $deny)); $keepVarsArr = $keepVars->getArrayCopy(); foreach ($keepVarsArr as $key => $value) { if ($skipEmpty && empty($value)) { continue; } if (!array_key_exists($key, $deny)) { $newKeepVars[$key] = $value; } } } $add = $keepVarConf['add']; if ($add) { $add = tx_rnbase_util_Strings::trimExplode(',', $add); foreach ($add as $linkvar) { $linkvar = tx_rnbase_util_Strings::trimExplode('=', $linkvar); if (count($linkvar) < 2) { // tt_news::* or ttnews::id list($qualifier, $name) = tx_rnbase_util_Strings::trimExplode('::', $linkvar[0]); if ($value = tx_rnbase_parameters::getPostOrGetParameter($qualifier)) { if ($name == '*' && is_array($value)) { foreach ($value as $paramName => $paramValue) { if ($skipEmpty && empty($paramValue)) { continue; } if (strpos($paramName, 'NK_') === FALSE) { $newKeepVars[$qualifier . '::' . $paramName] = $paramValue; } } } else { $newKeepVars[$linkvar[0]] = $value[$name]; } } } else { $newKeepVars[$linkvar[0]] = $linkvar[1]; } } } $this->overruled($newKeepVars); } if ($configurations->get($confId . 'noCache')) { $this->noCache(); } // Bei der Linkerzeugung wir normalerweise immer ein cHash angelegt. Bei Plugins, die als USER_INT // ausgeführt werden, ist dies nicht notwendig und geht auf die Performance. Daher wird hier // automatisch der cHash für USER_INT deaktiviert. Per Typocript kann man es aber bei Bedarf manuell // wieder aktivieren if ($configurations->get($confId . 'noHash') || $configurations->get($confId . 'noHash') !== '0' && $configurations->isPluginUserInt()) { $this->noHash(); } return $this; }
/** * Wir lassen als Dateinamen nur Buchstaben, Zahlen, * Bindestrich, Unterstrich und Punkt zu. * Umlaute und Sonderzeichen werden versucht in lesbare Buchstaben zu parsen. * Nicht zulässige Zeichen werden in einen Unterstrich umgewandelt. * Der Dateiuname wird optional in Kleinbuchstaben umgewandelt. * * @param string $name * @param boolean $forceLowerCase * @return string */ public static function cleanupFileName($name, $forceLowerCase = TRUE) { $cleaned = $name; if (function_exists('iconv')) { tx_rnbase::load('tx_rnbase_util_Strings'); $charset = tx_rnbase_util_Strings::isUtf8String($cleaned) ? 'UTF-8' : 'ISO-8859-1'; $oldLocal = setlocale(LC_ALL, 0); setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu', 'de', 'ge'); $cleaned = iconv($charset, 'ASCII//TRANSLIT', $cleaned); setlocale(LC_ALL, $oldLocal); } $cleaned = preg_replace('/[^A-Za-z0-9-_.]/', '_', $cleaned); return $forceLowerCase ? strtolower($cleaned) : $cleaned; }
/** * Setzt eventuelle Sprachparameter, * damit nur valide Daten für die aktuelle Sprache ausgelesen werden. * * @param array &$fields * @param array &$options * @return void */ protected function handleLanguageOptions(&$fields, &$options) { if (!isset($options['i18n']) && !isset($options['ignorei18n']) && !isset($options['enablefieldsoff'])) { $tableName = $this->getEmptyModel()->getTableName(); $languageField = tx_rnbase_util_TCA::getLanguageFieldForTable($tableName); // Die Sprache prüfen wir nur, wenn ein Sprachfeld gesetzt ist. if (!empty($languageField)) { $tsfe = tx_rnbase_util_TYPO3::getTSFE(); $languages = array(); if (isset($options['additionali18n'])) { $languages = tx_rnbase_util_Strings::trimExplode(',', $options['additionali18n'], TRUE); } // for all languages $languages[] = '-1'; // Wenn eine bestimmte Sprache gesetzt ist, // laden wir diese ebenfalls. if (is_object($tsfe) && $tsfe->sys_language_content) { $languages[] = $tsfe->sys_language_content; } else { // default language $languages[] = '0'; } $options['i18n'] = implode(',', array_unique($languages, SORT_NUMERIC)); } } }
/** * @group unit */ public function testInList() { self::assertTrue(tx_rnbase_util_Strings::inList('1,2,3', '2')); self::assertFalse(tx_rnbase_util_Strings::inList('1,2,3', '4')); }