/** * Enter description here... * * @param string $view default name of view * @param tx_rnbase_configurations $configurations * @return string */ function render($view, &$configurations) { $this->_init($configurations); $templateCode = tx_rnbase_util_Files::getFileResource($this->getTemplate($view, '.html')); if (!strlen($templateCode)) { tx_rnbase::load('tx_rnbase_util_Misc'); tx_rnbase_util_Misc::mayday('TEMPLATE NOT FOUND: ' . $this->getTemplate($view, '.html')); } // Die ViewData bereitstellen $viewData =& $configurations->getViewData(); // Optional kann schon ein Subpart angegeben werden $subpart = $this->getMainSubpart($viewData); if (!empty($subpart)) { $templateCode = tx_rnbase_util_Templates::getSubpart($templateCode, $subpart); if (!strlen($templateCode)) { tx_rnbase::load('tx_rnbase_util_Misc'); tx_rnbase_util_Misc::mayday('SUBPART NOT FOUND: ' . $subpart); } } $controller = $this->getController(); if ($controller) { // disable substitution marker cache if ($configurations->getBool($controller->getConfId() . '_caching.disableSubstCache')) { tx_rnbase_util_Templates::disableSubstCache(); } } $out = $templateCode; $out = $this->createOutput($templateCode, $viewData, $configurations, $configurations->getFormatter()); $out = $this->renderPluginData($out, $configurations); if ($controller) { $params = array(); $params['confid'] = $controller->getConfId(); $params['item'] = $controller->getViewData()->offsetGet('item'); $params['items'] = $controller->getViewData()->offsetGet('items'); $markerArray = $subpartArray = $wrappedSubpartArray = array(); tx_rnbase_util_BaseMarker::callModules($out, $markerArray, $subpartArray, $wrappedSubpartArray, $params, $configurations->getFormatter()); $out = tx_rnbase_util_BaseMarker::substituteMarkerArrayCached($out, $markerArray, $subpartArray, $wrappedSubpartArray); } return $out; }
/** * @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; }
/** * 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 . ' '; }
/** * Suchanfrage an die Datenbank * Bei den Felder findet ein Mapping auf die eigentlichen DB-Felder statt. Dadurch werden * SQL-Injections erschwert und es sind JOINs möglich. * Field-Schema: TABLEALIAS.COLNAME * Beispiel: TEAM.NAME, TEAM.UID * * Options: Zusätzliche Bedingungen für Abfrage. * LIMIT, ORDERBY * * Sonderfall Freitextsuche über mehrere Felder: * Hierfür gibt es das Sonderfeld SEARCH_FIELD_JOINED. Dieses erwartet ein Array der Form * 'value' => 'Suchbegriff' * 'operator' => OP_LIKE * 'cols' => array(FIELD1, FIELD2,...) * * Sonderfall SQL Sub-Select: * Hierfür gibt es das Sonderfeld SEARCH_FIELD_CUSTOM. Dieses erwartet ein String mit dem * Sub-Select. Dieser wird direkt in die Query eingebunden. * * @param array $fields Felder nach denen gesucht wird * @param array $options * @return array oder int */ function search($fields, $options) { if (!is_array($fields)) { $fields = array(); } $this->_initSearch($options); $tableAliases = array(); if (isset($fields[SEARCH_FIELD_JOINED])) { $joinedFields = $fields[SEARCH_FIELD_JOINED]; unset($fields[SEARCH_FIELD_JOINED]); } if (isset($fields[SEARCH_FIELD_CUSTOM])) { $customFields = $fields[SEARCH_FIELD_CUSTOM]; unset($fields[SEARCH_FIELD_CUSTOM]); } // Die normalen Suchfelder abarbeiten foreach ($fields as $field => $data) { // Tabelle und Spalte ermitteln list($tableAlias, $col) = explode('.', $field); $tableAliases[$tableAlias][$col] = $data; } // Prüfen, ob in orderby noch andere Tabellen liegen $orderbyArr = $options['orderby']; if (is_array($orderbyArr)) { $aliases = array_keys($orderbyArr); foreach ($aliases as $alias) { if (strstr($alias, SEARCH_FIELD_CUSTOM)) { continue; } // CUSTOM ignorieren list($tableAlias, $col) = explode('.', $alias); if (!array_key_exists($tableAlias, $tableAliases)) { $tableAliases[$tableAlias] = array(); } } } if (is_array($joinedFields)) { reset($joinedFields); foreach ($joinedFields as $key => $joinedField) { // Für die JOINED-Fields müssen die Tabellen gesetzt werden, damit der SQL-JOIN passt foreach ($joinedField['cols'] as $field) { list($tableAlias, $col) = explode('.', $field); if (!isset($tableAliases[$tableAlias])) { $tableAliases[$tableAlias] = array(); } $joinedFields[$key]['fields'][] = ($this->useAlias() ? $tableAlias : $this->tableMapping[$tableAlias]) . '.' . strtolower($col); } } } // Deprecated: Diese Option nicht verwenden. Dafür gibt es den Hook! if (is_array($additionalTableAliases = $options['additionalTableAliases'])) { foreach ($additionalTableAliases as $additionalTableAlias) { if (!isset($tableAliases[$additionalTableAlias])) { $tableAliases[$additionalTableAlias] = array(); } } } tx_rnbase_util_Misc::callHook('rn_base', 'searchbase_handleTableMapping', array('tableAliases' => &$tableAliases, 'joinedFields' => &$joinedFields, 'customFields' => &$customFields, 'options' => &$options, 'tableMappings' => &$this->tableMapping), $this); $what = $this->getWhat($options, $tableAliases); $from = $this->getFrom($options, $tableAliases); $where = '1=1'; foreach ($tableAliases as $tableAlias => $colData) { foreach ($colData as $col => $data) { foreach ($data as $operator => $value) { if (is_array($value)) { // There is more then one value to test against column $joinedValues = $value[SEARCH_FIELD_JOINED]; if (!is_array($joinedValues)) { tx_rnbase_util_Misc::mayday('JOINED field required data array. Check up your search config.', 'rn_base'); } $joinedValues = array_values($joinedValues); for ($i = 0, $cnt = count($joinedValues); $i < $cnt; $i++) { $wherePart = Tx_Rnbase_Database_Connection::getInstance()->setSingleWhereField($this->useAlias() ? $tableAlias : $this->tableMapping[$tableAlias], $operator, $col, $joinedValues[$i]); if (trim($wherePart) !== '') { $where .= ' AND ' . $wherePart; } } } else { $wherePart = Tx_Rnbase_Database_Connection::getInstance()->setSingleWhereField($this->useAlias() ? $tableAlias : $this->tableMapping[$tableAlias], $operator, $col, $value); if (trim($wherePart) !== '') { $where .= ' AND ' . $wherePart; } } } } } // Jetzt die Freitextsuche über mehrere Felder if (is_array($joinedFields)) { foreach ($joinedFields as $joinedField) { // Ignore invalid queries if (!isset($joinedField['value']) || !isset($joinedField['operator']) || !isset($joinedField['fields']) || !$joinedField['fields']) { continue; } if ($joinedField['operator'] == OP_INSET_INT) { // Values splitten und einzelne Abfragen mit OR verbinden $addWhere = Tx_Rnbase_Database_Connection::getInstance()->searchWhere($joinedField['value'], implode(',', $joinedField['fields']), 'FIND_IN_SET_OR'); } else { $addWhere = Tx_Rnbase_Database_Connection::getInstance()->searchWhere($joinedField['value'], implode(',', $joinedField['fields']), $joinedField['operator']); } if ($addWhere) { $where .= ' AND ' . $addWhere; } } } if (isset($customFields)) { $where .= ' AND ' . $customFields; } if ($options['enableFieldsForAdditionalTableAliases']) { $where .= $this->setEnableFieldsForAdditionalTableAliases($tableAliases, $options); } $sqlOptions = array(); $sqlOptions['where'] = $where; if ($options['pidlist']) { $sqlOptions['pidlist'] = $options['pidlist']; } if ($options['recursive']) { $sqlOptions['recursive'] = $options['recursive']; } if ($options['limit']) { $sqlOptions['limit'] = $options['limit']; } if ($options['offset']) { $sqlOptions['offset'] = $options['offset']; } if ($options['enablefieldsoff']) { $sqlOptions['enablefieldsoff'] = $options['enablefieldsoff']; } if ($options['enablefieldsbe']) { $sqlOptions['enablefieldsbe'] = $options['enablefieldsbe']; } if ($options['enablefieldsfe']) { $sqlOptions['enablefieldsfe'] = $options['enablefieldsfe']; } if ($options['groupby']) { $sqlOptions['groupby'] = $options['groupby']; } if ($options['having']) { $sqlOptions['having'] = $options['having']; } if ($options['callback']) { $sqlOptions['callback'] = $options['callback']; } if ($options['ignorei18n']) { $sqlOptions['ignorei18n'] = $options['ignorei18n']; } if ($options['i18nolmode']) { $sqlOptions['i18nolmode'] = $options['i18nolmode']; } if ($options['i18n']) { $sqlOptions['i18n'] = $options['i18n']; } if ($options['ignoreworkspace']) { $sqlOptions['ignoreworkspace'] = $options['ignoreworkspace']; } if ($options['sqlonly']) { $sqlOptions['sqlonly'] = $options['sqlonly']; } if ($options['union']) { $sqlOptions['union'] = $options['union']; } if ($options['array_object']) { $sqlOptions['array_object'] = $options['array_object']; } if (!isset($options['count']) && is_array($options['orderby'])) { // Aus dem Array einen String bauen $orderby = array(); if (array_key_exists('RAND', $options['orderby']) && $options['orderby']['RAND']) { $orderby[] = 'RAND()'; } else { if (array_key_exists('RAND', $options['orderby'])) { unset($options['orderby']['RAND']); } foreach ($options['orderby'] as $field => $order) { // free Order-Clause if (strstr($field, SEARCH_FIELD_CUSTOM)) { $orderby[] = $order; continue; } list($tableAlias, $col) = explode('.', $field); $tableAlias = $this->useAlias() ? $tableAlias : $this->tableMapping[$tableAlias]; if ($tableAlias) { $orderby[] = $tableAlias . '.' . strtolower($col) . ' ' . (strtoupper($order) == 'DESC' ? 'DESC' : 'ASC'); } else { $orderby[] = $field . ' ' . (strtoupper($order) == 'DESC' ? 'DESC' : 'ASC'); } } } $sqlOptions['orderby'] = implode(',', $orderby); } if (!isset($options['count']) && (!(isset($options['what']) || isset($options['groupby']) || isset($options['sqlonly'])) || isset($options['forcewrapper']))) { // der Filter kann ebenfalls eine Klasse setzen. Diese hat Vorrang. $sqlOptions['wrapperclass'] = $options['wrapperclass'] ? $options['wrapperclass'] : $this->getGenericWrapperClass(); } // if we have to do a count and there still is a count in the custom what // or there is a having or a groupby // so we have to wrap the query into a subquery to count the results if (!$options['disableCountWrap'] && isset($options['count']) && (isset($options['what']) && strpos(strtoupper($options['what']), 'COUNT(') !== FALSE || $options['groupby'] || $options['having'])) { $sqlOptions['sqlonly'] = 1; $query = Tx_Rnbase_Database_Connection::getInstance()->doSelect($what, $from, $sqlOptions, $options['debug'] ? 1 : 0); $what = 'COUNT(*) AS cnt'; $from = '(' . $query . ') AS COUNTWRAP'; $sqlOptions = array('enablefieldsoff' => TRUE, 'sqlonly' => empty($options['sqlonly']) ? 0 : $options['sqlonly']); } $result = Tx_Rnbase_Database_Connection::getInstance()->doSelect($what, $from, $sqlOptions, $options['debug'] ? 1 : 0); if (isset($options['sqlonly'])) { return $result; } // else: return isset($options['count']) ? $result[0]['cnt'] : $result; }