Ejemplo n.º 1
0
 /**
  * Will expand the parameters configuration to individual values. This follows a certain syntax of the value of each parameter.
  * Syntax of values:
  * - Basically: If the value is wrapped in [...] it will be expanded according to the following syntax, otherwise the value is taken literally
  * - Configuration is splitted by "|" and the parts are processed individually and finally added together
  * - For each configuration part:
  * 		- "[int]-[int]" = Integer range, will be expanded to all values in between, values included, starting from low to high (max. 1000). Example "1-34" or "-40--30"
  * 		- "_TABLE:[TCA table name];[_PID:[optional page id, default is current page]];[_ENABLELANG:1]" = Look up of table records from PID, filtering out deleted records. Example "_TABLE:tt_content; _PID:123"
  *  	  _ENABLELANG:1 picks only original records without their language overlays
  * 		- Default: Literal value
  *
  * @param	array		Array with key (GET var name) and values (value of GET var which is configuration for expansion)
  * @param	integer		Current page ID
  * @return	array		Array with key (GET var name) with the value being an array of all possible values for that key.
  */
 function expandParameters($paramArray, $pid)
 {
     global $TCA;
     // Traverse parameter names:
     foreach ($paramArray as $p => $v) {
         $v = trim($v);
         // If value is encapsulated in square brackets it means there are some ranges of values to find, otherwise the value is literal
         if (substr($v, 0, 1) === '[' && substr($v, -1) === ']') {
             // So, find the value inside brackets and reset the paramArray value as an array.
             $v = substr($v, 1, -1);
             $paramArray[$p] = array();
             // Explode parts and traverse them:
             $parts = explode('|', $v);
             foreach ($parts as $pV) {
                 // Look for integer range: (fx. 1-34 or -40--30 // reads minus 40 to minus 30)
                 if (preg_match('/^(-?[0-9]+)\\s*-\\s*(-?[0-9]+)$/', trim($pV), $reg)) {
                     // Integer range:
                     // Swap if first is larger than last:
                     if ($reg[1] > $reg[2]) {
                         $temp = $reg[2];
                         $reg[2] = $reg[1];
                         $reg[1] = $temp;
                     }
                     // Traverse range, add values:
                     $runAwayBrake = 1000;
                     // Limit to size of range!
                     for ($a = $reg[1]; $a <= $reg[2]; $a++) {
                         $paramArray[$p][] = $a;
                         $runAwayBrake--;
                         if ($runAwayBrake <= 0) {
                             break;
                         }
                     }
                 } elseif (substr(trim($pV), 0, 7) == '_TABLE:') {
                     // Parse parameters:
                     $subparts = t3lib_div::trimExplode(';', $pV);
                     $subpartParams = array();
                     foreach ($subparts as $spV) {
                         list($pKey, $pVal) = t3lib_div::trimExplode(':', $spV);
                         $subpartParams[$pKey] = $pVal;
                     }
                     // Table exists:
                     if (isset($TCA[$subpartParams['_TABLE']])) {
                         t3lib_div::loadTCA($subpartParams['_TABLE']);
                         $lookUpPid = isset($subpartParams['_PID']) ? intval($subpartParams['_PID']) : $pid;
                         $pidField = isset($subpartParams['_PIDFIELD']) ? trim($subpartParams['_PIDFIELD']) : 'pid';
                         $where = isset($subpartParams['_WHERE']) ? $subpartParams['_WHERE'] : '';
                         $addTable = isset($subpartParams['_ADDTABLE']) ? $subpartParams['_ADDTABLE'] : '';
                         $fieldName = $subpartParams['_FIELD'] ? $subpartParams['_FIELD'] : 'uid';
                         if ($fieldName === 'uid' || $TCA[$subpartParams['_TABLE']]['columns'][$fieldName]) {
                             $andWhereLanguage = '';
                             $transOrigPointerField = $TCA[$subpartParams['_TABLE']]['ctrl']['transOrigPointerField'];
                             if ($subpartParams['_ENABLELANG'] && $transOrigPointerField) {
                                 $andWhereLanguage = ' AND ' . $this->db->quoteStr($transOrigPointerField, $subpartParams['_TABLE']) . ' <= 0 ';
                             }
                             $where = $this->db->quoteStr($pidField, $subpartParams['_TABLE']) . '=' . intval($lookUpPid) . ' ' . $andWhereLanguage . $where;
                             $rows = $this->db->exec_SELECTgetRows($fieldName, $subpartParams['_TABLE'] . $addTable, $where . t3lib_BEfunc::deleteClause($subpartParams['_TABLE']), '', '', '', $fieldName);
                             if (is_array($rows)) {
                                 $paramArray[$p] = array_merge($paramArray[$p], array_keys($rows));
                             }
                         }
                     }
                 } else {
                     // Just add value:
                     $paramArray[$p][] = $pV;
                 }
                 // Hook for processing own expandParameters place holder
                 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['crawler/class.tx_crawler_lib.php']['expandParameters'])) {
                     $_params = array('pObj' => &$this, 'paramArray' => &$paramArray, 'currentKey' => $p, 'currentValue' => $pV, 'pid' => $pid);
                     foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['crawler/class.tx_crawler_lib.php']['expandParameters'] as $key => $_funcRef) {
                         t3lib_div::callUserFunction($_funcRef, $_params, $this);
                     }
                 }
             }
             // Make unique set of values and sort array by key:
             $paramArray[$p] = array_unique($paramArray[$p]);
             ksort($paramArray);
         } else {
             // Set the literal value as only value in array:
             $paramArray[$p] = array($v);
         }
     }
     return $paramArray;
 }