Ejemplo n.º 1
0
 /**
  * Check subpages for context from rootline
  * method is called from hook "hook_checkEnableFields"
  *
  * @param array $arData key: pObj value: TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController (required)
  *                      key: row  value: page record to evaluate
  *                      key: bypassGroupCheck  value: boolean
  *
  * @return boolean false if context from root does not match
  */
 public function checkEnableFields($arData)
 {
     $contexts = Tx_Contexts_Context_Container::get();
     $bFindExtendSubPage = 0;
     foreach (array_reverse($arData['pObj']->rootLine) as $page) {
         //check extendtosubpages
         if ($page['extendToSubpages'] == '0' && $bFindExtendSubPage == 0) {
             continue;
         } else {
             $bFindExtendSubPage = 1;
         }
         $arEnable = explode(',', $page['tx_contexts_enable']);
         foreach ($arEnable as $nContextId) {
             if (!isset($contexts[$nContextId]) && $nContextId) {
                 return false;
             }
         }
         $arDisable = explode(',', $page['tx_contexts_disable']);
         foreach ($arDisable as $nContextId) {
             if (isset($contexts[$nContextId]) && $nContextId) {
                 return false;
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Match context by alias
  *
  * @param string $strContext alias from context entry
  *
  * @return boolean TRUE if context matches, FALSE if not
  */
 public function matches($strContext)
 {
     if (isset($this->arMatches[$strContext])) {
         return $this->arMatches[$strContext];
     }
     $container = Tx_Contexts_Context_Container::get();
     $context = $container->find($strContext);
     $this->arMatches[$strContext] = $context !== null;
     return $this->arMatches[$strContext];
 }
Ejemplo n.º 3
0
/**
 * Context Typoscript Connector
 *
 * This function is for usage in Typo3 TypoScript to get match context directly.
 *
 * @param string $strContext context alias
 *
 * @return boolean True if it matches, false if not
 */
function user_contexts_matches($strContext)
{
    static $initialized = false;
    if (!$initialized) {
        //load and resolve all contexts
        Tx_Contexts_Context_Container::get()->initMatching();
        $initialized = true;
    }
    return Tx_Contexts_Api_ContextMatcher::getInstance()->matches($strContext);
}
Ejemplo n.º 4
0
    /**
     * Display a textarea with validation for the entered aliases and expressions
     *
     * @param array          $arFieldInfo Information about the current input field
     * @param t3lib_tceforms $tceforms    Form rendering library object
     * @return string HTML code
     */
    public function textCombinations($arFieldInfo, t3lib_tceforms $tceforms)
    {
        $text = $tceforms->getSingleField_typeText($arFieldInfo['table'], $arFieldInfo['field'], $arFieldInfo['row'], $arFieldInfo);
        $evaluator = new Tx_Contexts_Context_Type_Combination_LogicalExpressionEvaluator();
        $arTokens = $evaluator->tokenize($arFieldInfo['itemFormElValue']);
        $arNotFound = array();
        $arUnknownTokens = array();
        foreach ($arTokens as $token) {
            if (is_array($token) && $token[0] === Tx_Contexts_Context_Type_Combination_LogicalExpressionEvaluator::T_VAR) {
                $contexts = Tx_Contexts_Context_Container::get()->initAll();
                $bFound = false;
                foreach ($contexts as $context) {
                    if ($context->getAlias() == $token[1]) {
                        $bFound = true;
                    }
                }
                if (!$bFound) {
                    $arNotFound[] = $token[1];
                }
            } elseif (is_array($token) && $token[0] === Tx_Contexts_Context_Type_Combination_LogicalExpressionEvaluator::T_UNKNOWN) {
                $arUnknownTokens[] = $token[1];
            }
        }
        if (!$arNotFound && !$arUnknownTokens) {
            return $text;
        }
        $html = <<<HTM
{$text}<br />
<div class="typo3-message message-error">
    <div class="message-body">
HTM;
        if ($arNotFound) {
            $strNotFound = implode(', ', $arNotFound);
            $html .= <<<HTM
<div>
    {$GLOBALS['LANG']->sL('LLL:EXT:contexts/Resources/Private/Language' . '/flexform.xml:aliasesNotFound')}: {$strNotFound}
</div>
HTM;
        }
        if ($arUnknownTokens) {
            $strUnknownTokens = implode(', ', $arUnknownTokens);
            $html .= <<<HTM
<div>
    {$GLOBALS['LANG']->sL('LLL:EXT:contexts/Resources/Private/Language' . '/flexform.xml:unknownTokensFound')}: {$strUnknownTokens}
</div>
HTM;
        }
        $html .= <<<HTM
    </div>
</div>
HTM;
        return $html;
    }
Ejemplo n.º 5
0
 /**
  * Tries to get if the setting is enabled by evaluating the flat columns
  * within the record
  *
  * @param string $table   Table name
  * @param string $setting Setting name
  * @param array  $row     Record array
  *
  * @return null|boolean NULL when table has no flat settings or the record
  *                      doesn't contain the appropriate flat columns
  *                      boolean otherwise
  */
 protected static function isSettingEnabledFlat($table, $setting, array $row)
 {
     $flatColumns = Tx_Contexts_Api_Configuration::getFlatColumns($table, $setting);
     if (!$flatColumns) {
         return null;
     }
     $rowValid = true;
     $flatColumnContents = array();
     foreach ($flatColumns as $i => $flatColumn) {
         if (!array_key_exists($flatColumn, $row)) {
             t3lib_div::devLog('Missing flat field "' . $flatColumn . '"', 'tx_contexts', t3lib_div::SYSLOG_SEVERITY_WARNING, array('table' => $table, 'row' => $row));
             $rowValid = false;
         } elseif ($row[$flatColumn] !== '') {
             $flatColumnContents[$i] = array_flip(explode(',', $row[$flatColumn]));
         } else {
             $flatColumnContents[$i] = array();
         }
     }
     if (!$rowValid) {
         return null;
     }
     foreach (Tx_Contexts_Context_Container::get() as $context) {
         if (array_key_exists($context->getUid(), $flatColumnContents[0])) {
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Render a checkbox for the default settings of records in
  * this table
  *
  * @param array $params
  * @param t3lib_TCEforms $fobj
  * @return string
  */
 public function renderDefaultSettingsField($params, $fobj)
 {
     global $TCA;
     $table = $params['fieldConf']['config']['table'];
     t3lib_div::loadTCA($table);
     $content = '';
     $namePre = str_replace('[default_settings_', '[default_settings][', $params['itemFormElName']);
     /* @var $context Tx_Contexts_Context_Abstract */
     $uid = (int) $params['row']['uid'];
     $context = $uid ? Tx_Contexts_Context_Container::get()->initAll()->find($uid) : null;
     foreach ($params['fieldConf']['config']['settings'] as $setting => $config) {
         $id = $params['itemFormElID'] . '-' . $setting;
         $name = $namePre . '[' . $setting . ']';
         $content .= '<input type="hidden" name="' . $name . '" value="0"/>';
         $content .= '<input class="checkbox" type="checkbox" name="' . $name . '" ';
         if (!$context || !$context->hasSetting($table, $setting, 0) || $context->getSetting($table, $setting, 0)->getEnabled()) {
             $content .= 'checked="checked" ';
         }
         $content .= 'value="1" id="' . $id . '" /> ';
         $content .= '<label for="' . $id . '">';
         $content .= $fobj->sL($config['label']);
         $content .= '</label><br/>';
     }
     return $content;
 }
Ejemplo n.º 7
0
 /**
  * Creates a string that can be used to identify the current
  * context combination.
  * Used for cache hash modification.
  *
  * @return string Hash modificator
  */
 protected function getHashString()
 {
     $keys = array_keys(Tx_Contexts_Context_Container::get()->getArrayCopy());
     sort($keys, SORT_NUMERIC);
     return implode(',', $keys);
 }