Exemple #1
0
 /**
  * Hook that allows to dynamically extend the table definitions for e.g. custom
  * caches. The hook implementation may return table create strings that will be
  * respected by the extension manager during installation of an extension.
  *
  * @param string $extKey Extension key
  * @param array $extInfo Extension information array
  * @param string $fileContent Content of the current extension sql file
  * @param t3lib_install $instObj Instance of the installer
  * @param t3lib_install_Sql $instSqlObj Instance of the installer sql object
  * @param tx_em_Install $parent The calling parent object
  * @return string Either empty string or table create strings
  */
 public function appendTableDefinitions($extKey, array $extInfo, $fileContent, t3lib_install $instObj, t3lib_install_Sql $instSqlObj, tx_em_Install $parent)
 {
     global $TCA;
     $extensionFlatSettings = Tx_Contexts_Api_Configuration::getExtensionFlatSettings();
     if (!array_key_exists($extKey, $extensionFlatSettings)) {
         return '';
     }
     $sql = '';
     foreach ($extensionFlatSettings[$extKey] as $table => $settings) {
         $sql .= "\nCREATE TABLE {$table} (\n";
         foreach ($settings as $setting) {
             $flatColumns = Tx_Contexts_Api_Configuration::getFlatColumns($table, $setting);
             $sql .= $flatColumns[0] . " tinytext NOT NULL,\n";
             $sql .= $flatColumns[1] . " tinytext NOT NULL\n";
         }
         $sql .= ');';
     }
     return $sql;
 }
Exemple #2
0
 /**
  * Find the right class for the context type and instantiate it
  *
  * @param array $arRow Database context row
  *
  * @return Tx_Contexts_Context_Abstract|null
  * @throws Tx_Contexts_Exception
  */
 public static function createFromDb($arRow)
 {
     $classMap = Tx_Contexts_Api_Configuration::getContextTypes();
     $type = $arRow['type'];
     if (!$type || !array_key_exists($type, $classMap)) {
         t3lib_div::devLog('No class found for context type "' . $type . '"', 'tx_contexts', 2);
         $type = 'default';
     }
     if (!isset($classMap[$type]['class'])) {
         return null;
     }
     $class = $classMap[$type]['class'];
     if (!$class) {
         return null;
     }
     $instance = t3lib_div::makeInstance($class, $arRow);
     if ($instance instanceof t3lib_Singleton) {
         throw new Tx_Contexts_Exception($class . ' may not be singleton');
     }
     if (!$instance instanceof Tx_Contexts_Context_Abstract) {
         throw new Tx_Contexts_Exception($class . ' must extend Tx_Contexts_Context_Abstract');
     }
     return $instance;
 }
 /**
  * Get all settings of one record.
  *
  * @param string $table Database table
  * @param int    $uid   Record UID
  *
  * @return array Array of settings
  *               Key is the context column name (e.g. "tx_contexts_nav")
  *               Value is a Tx_Contexts_Context_Setting object
  */
 public final function getSettings($table, $uid)
 {
     $settingsKey = $table . '.' . $uid;
     if (array_key_exists($settingsKey, $this->settings)) {
         return $this->settings[$settingsKey];
     }
     $uids = array($uid);
     if ($uid && !array_key_exists($table . '.0', $this->settings)) {
         $uids[] = 0;
     }
     $where = 'context_uid = ' . $this->uid;
     $where .= " AND foreign_table = '{$table}'";
     $where .= " AND foreign_uid IN ('" . implode("','", $uids) . "')";
     $rows = (array) Tx_Contexts_Api_Configuration::getDb()->exec_SELECTgetRows('*', 'tx_contexts_settings', $where);
     foreach ($uids as $uid) {
         $this->settings[$table . '.' . $uid] = array();
     }
     foreach ($rows as $row) {
         $this->settings[$table . '.' . $row['foreign_uid']][$row['name']] = new Tx_Contexts_Context_Setting($this, $row);
     }
     return $this->settings[$settingsKey];
 }
<?php

/**
 * Geolocation contexts: Context registration
 *
 * PHP version 5
 *
 * @category   TYPO3-Extensions
 * @package    Contexts
 * @subpackage Geolocation
 * @author     Christian Weiske <*****@*****.**>
 * @license    http://opensource.org/licenses/gpl-license GPLv2 or later
 * @link       http://github.com/netresearch/contexts_geolocation
 */
defined('TYPO3_MODE') or die('Access denied.');
// Register context
Tx_Contexts_Api_Configuration::registerContextType('geolocation_country', 'LLL:EXT:contexts_geolocation/Resources/Private/Language/locallang_db.xml:title_country', 'Tx_Contexts_Geolocation_Context_Type_Country', 'FILE:EXT:contexts_geolocation/Configuration/flexform/Country.xml');
Tx_Contexts_Api_Configuration::registerContextType('geolocation_continent', 'LLL:EXT:contexts_geolocation/Resources/Private/Language/locallang_db.xml:title_continent', 'Tx_Contexts_Geolocation_Context_Type_Continent', 'FILE:EXT:contexts_geolocation/Configuration/flexform/Continent.xml');
Tx_Contexts_Api_Configuration::registerContextType('geolocation_distance', 'LLL:EXT:contexts_geolocation/Resources/Private/Language/locallang_db.xml:title_distance', 'Tx_Contexts_Geolocation_Context_Type_Distance', 'FILE:EXT:contexts_geolocation/Configuration/flexform/Distance.xml');
Exemple #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;
 }
 /**
  * Add setting columns to the TCA.
  *
  * @param string $table    Table to add settings to
  * @param array  $settings Array of settings to register.
  *                         Key is the setting name, value its title
  *
  * @return void
  */
 protected static function addToTcaColumns($table, array $settings)
 {
     global $TCA;
     t3lib_div::loadTCA($table);
     if (!isset($TCA[$table])) {
         return;
     }
     t3lib_div::loadTCA('tx_contexts_contexts');
     if (!array_key_exists(self::RECORD_SETTINGS_COLUMN, $TCA[$table]['columns'])) {
         $recordSettingsConf = array("exclude" => 1, "label" => 'LLL:' . self::LANG_FILE . ':tabname', "config" => array("type" => "user", "size" => "30", "userFunc" => 'Tx_Contexts_Service_Tca->renderRecordSettingsField', 'settings' => $settings));
         $arColumns = array(self::RECORD_SETTINGS_COLUMN => $recordSettingsConf);
         $arFlatColumns = Tx_Contexts_Api_Configuration::getFlatColumns($table);
         if (count($arFlatColumns)) {
             //add passthrough fields to keep settings when copying records
             foreach ($arFlatColumns as $arSetting) {
                 foreach ($arSetting as $columnName) {
                     $arColumns[$columnName] = array('config' => array('type' => 'passthrough'));
                 }
             }
         }
         t3lib_extMgm::addTCAcolumns($table, $arColumns, 1);
         switch ($table) {
             case 'pages':
                 t3lib_extMgm::addToAllTCAtypes($table, self::RECORD_SETTINGS_COLUMN, '1,4,5', 'after:fe_group');
                 t3lib_extMgm::addToAllTCAtypes($table, self::RECORD_SETTINGS_COLUMN, '254', 'after:hidden');
                 break;
             case 'tt_content':
                 t3lib_extMgm::addToAllTCAtypes($table, self::RECORD_SETTINGS_COLUMN, '', 'after:fe_group');
                 break;
         }
     } else {
         $TCA[$table]['columns'][self::RECORD_SETTINGS_COLUMN]['config']['settings'] = array_merge($TCA[$table]['columns'][self::RECORD_SETTINGS_COLUMN]['config']['settings'], $settings);
     }
     $defaultSettingsColumn = 'default_settings_' . $table;
     if (!array_key_exists($defaultSettingsColumn, $TCA['tx_contexts_contexts']['columns'])) {
         $defaultSettingsConf = array("exclude" => 1, 'label' => $TCA[$table]['ctrl']['title'], 'config' => array('type' => 'user', 'size' => 30, 'userFunc' => 'Tx_Contexts_Service_Tca->renderDefaultSettingsField', 'table' => $table, 'settings' => $settings));
         t3lib_extMgm::addTCAcolumns('tx_contexts_contexts', array($defaultSettingsColumn => $defaultSettingsConf), 1);
         t3lib_extMgm::addToAllTCAtypes('tx_contexts_contexts', $defaultSettingsColumn);
     } else {
         $TCA['tx_contexts_contexts']['columns'][$defaultSettingsColumn]['config']['settings'] = array_merge($TCA['tx_contexts_contexts']['columns'][$defaultSettingsColumn]['config']['settings'], $settings);
     }
 }
<?php

/**
 * Contexts WURFL context registration configuration.
 *
 * PHP version 5
 *
 * @category   Contexts
 * @package    WURFL
 * @subpackage Configuration
 * @author     Rico Sonntag <*****@*****.**>
 */
defined('TYPO3_MODE') or die('Access denied.');
// Register context
Tx_Contexts_Api_Configuration::registerContextType('wurfl', 'LLL:EXT:contexts_wurfl/Resources/Private/Language/locallang_mod.xml:context.title', 'Tx_ContextsWurfl_Context_Type_Wurfl', 'FILE:EXT:contexts_wurfl/Configuration/flexform/Wurfl.xml');
<?php

Tx_Contexts_Api_Configuration::enableContextsForTable($_EXTKEY, 'pages', array('tx_contexts_nav' => array('label' => 'LLL:' . Tx_Contexts_Api_Configuration::LANG_FILE . ':tx_contexts_menu_visibility', 'flatten' => true)));
Tx_Contexts_Api_Configuration::enableContextsForTable($_EXTKEY, 'tt_content');
Tx_Contexts_Api_Configuration::registerContextType('domain', 'Domain', 'Tx_Contexts_Context_Type_Domain', 'FILE:EXT:contexts/Configuration/flexform/ContextType/Domain.xml');
Tx_Contexts_Api_Configuration::registerContextType('getparam', 'GET parameter', 'Tx_Contexts_Context_Type_GetParam', 'FILE:EXT:contexts/Configuration/flexform/ContextType/GetParam.xml');
Tx_Contexts_Api_Configuration::registerContextType('ip', 'IP', 'Tx_Contexts_Context_Type_Ip', 'FILE:EXT:contexts/Configuration/flexform/ContextType/Ip.xml');
Tx_Contexts_Api_Configuration::registerContextType('httpheader', 'HTTP header', 'Tx_Contexts_Context_Type_HttpHeader', 'FILE:EXT:contexts/Configuration/flexform/ContextType/HttpHeader.xml');
Tx_Contexts_Api_Configuration::registerContextType('combination', 'Logical context combination', 'Tx_Contexts_Context_Type_Combination', 'FILE:EXT:contexts/Configuration/flexform/ContextType/Combination.xml');
Tx_Contexts_Api_Configuration::registerContextType('session', 'Session variable', 'Tx_Contexts_Context_Type_Session', 'FILE:EXT:contexts/Configuration/flexform/ContextType/Session.xml');
Exemple #9
0
 /**
  * Save the default settings to the settings table - default
  * settings will have a foreign_uid of 0
  *
  * @param int $contextId
  * @param array $settings
  * @return void
  */
 protected function saveDefaultSettings($contextId, $settings)
 {
     $existingSettings = (array) Tx_Contexts_Api_Configuration::getDb()->exec_SELECTgetRows('*', 'tx_contexts_settings', "context_uid = '{$contextId}' AND foreign_uid = 0");
     foreach ($settings as $table => $fields) {
         $fieldSettings = array();
         foreach ($existingSettings as $setting) {
             if ($setting['foreign_table'] == $table) {
                 $fieldSettings[$setting['name']] = $setting['uid'];
             }
         }
         foreach ($fields as $field => $enabled) {
             if (array_key_exists($field, $fieldSettings)) {
                 Tx_Contexts_Api_Configuration::getDb()->exec_UPDATEquery('tx_contexts_settings', 'uid=' . $fieldSettings[$field], array('enabled' => (int) $enabled));
             } else {
                 Tx_Contexts_Api_Configuration::getDb()->exec_INSERTquery('tx_contexts_settings', array('context_uid' => $contextId, 'foreign_table' => $table, 'name' => $field, 'foreign_uid' => 0, 'enabled' => (int) $enabled));
             }
         }
     }
 }
Exemple #10
0
 /**
  * Generates a SQL WHERE statement that filters out records
  * that may not be accessed with the current context settings
  *
  * @param string $table Database table name
  * @return string SQL filter string beginning with " AND "
  */
 protected function getFilterSql($table)
 {
     global $TCA;
     $sql = '';
     foreach (Tx_Contexts_Api_Configuration::getEnableSettings($table) as $setting) {
         $flatColumns = Tx_Contexts_Api_Configuration::getFlatColumns($table, $setting);
         if (!$flatColumns) {
             t3lib_div::devLog('Missing flat columns for setting "' . $setting . '"', 'tx_contexts', 2, array('table' => $table));
             continue;
         }
         $enableChecks = array($flatColumns[1] . " = ''");
         $disableChecks = array();
         foreach (Tx_Contexts_Context_Container::get() as $context) {
             /* @var $context Tx_Contexts_Context_Abstract */
             $enableChecks[] = $GLOBALS['TYPO3_DB']->listQuery($flatColumns[1], $context->getUid(), $table);
             $disableChecks[] = 'NOT ' . $GLOBALS['TYPO3_DB']->listQuery($flatColumns[0], $context->getUid(), $table);
         }
         $sql = ' AND (' . implode(' OR ', $enableChecks) . ')';
         if (count($disableChecks)) {
             $sql .= ' AND (' . $flatColumns[0] . " = ''" . ' OR (' . implode(' AND ', $disableChecks) . ')' . ')';
         }
     }
     return $sql;
 }