Main Page | Directories | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages | Examples

t3lib_modSettings Class Reference

List of all members.

Public Member Functions

 init ($prefix='', $storeList='')
 Initializes the object.
 setSessionType ($type='ses')
 Set session type to 'ses' which will store the settings data not permanently.
 setStoreList ($storeList)
 Set MOD_SETTINGS keys which should be stored.
 addToStoreList ($storeList)
 Add MOD_SETTINGS keys to the current list.
 addToStoreListFromPrefix ($prefix='')
 Add names of keys of the MOD_SETTING array by a prefix.
 initStorage ()
 Get the stored settings from MOD_SETTINGS and set them in $this->storedSettings.
 cleanupStorageArray ($storedSettings)
 Remove corrupted data entries from the stored settings array.
 compileEntry ($data)
 Creates an entry for the stored settings array Collects data from MOD_SETTINGS selected by the storeList.
 getStoredData ($storeIndex, $writeArray=array())
 Copies the stored data from entry $index to $writeArray which can be used to set MOD_SETTINGS.
 processStoreControl ($mconfName='')
 Processing of the storage command LOAD, SAVE, REMOVE.
 writeStoredSetting ($writeArray=array(), $mconfName='')
 Write the current storage array and update MOD_SETTINGS.
 getStoreControl ($showElements='load, remove, save', $useOwnForm=TRUE)
 Returns the storage control box.
 processEntry ($storageArr)
 Processing entry for the stored settings array Can be overwritten by extended class.

Public Attributes

 $type = 'perm'
 If type is set 'ses' then the module data will be stored into the session and will be lost with logout.
 $prefix = ''
 prefix of MOD_SETTING array keys that should be stored
 $storeList = array()
 Names of keys of the MOD_SETTING array which should be stored.
 $storedSettings = array()
 The stored settings array.
 $msg = ''
 Message from the last storage command.
 $formName = 'storeControl'
 Name of the form.
 $writeDevLog = 0

Member Function Documentation

t3lib_modSettings::addToStoreList storeList  ) 
 

Add MOD_SETTINGS keys to the current list.

Parameters:
mixed array or string (,) - add names of keys of the MOD_SETTING array which should be stored
Returns:
void

Definition at line 231 of file class.t3lib_modsettings.php.

References $storeList.

00231                                        {
00232       $storeList = is_array($storeList) ? $storeList : t3lib_div::trimExplode(',',$storeList,1);
00233       $this->storeList = array_merge($this->storeList, $storeList);
00234 
00235       if ($this->writeDevLog) t3lib_div::devLog('Store list:'.implode(',',$this->storeList), 't3lib_modSettings', 0);
00236    }

t3lib_modSettings::addToStoreListFromPrefix prefix = ''  ) 
 

Add names of keys of the MOD_SETTING array by a prefix.

Parameters:
string prefix of MOD_SETTING array keys that should be stored
Returns:
void

Definition at line 245 of file class.t3lib_modsettings.php.

References $prefix.

00245                                                  {
00246       global $SOBE;
00247 
00248       $prefix = $prefix ? $prefix : $this->prefix;
00249 
00250       reset($SOBE->MOD_SETTINGS);
00251       while(list($key)=each($SOBE->MOD_SETTINGS))  {
00252          if (ereg('^'.$prefix,$key)) {
00253             $this->storeList[$key]=$key;
00254          }
00255       }
00256 
00257       unset($this->storeList[$this->prefix.'_storedSettings']);
00258 
00259       if ($this->writeDevLog) t3lib_div::devLog('Store list:'.implode(',',$this->storeList), 't3lib_modSettings', 0);
00260    }

t3lib_modSettings::cleanupStorageArray storedSettings  ) 
 

Remove corrupted data entries from the stored settings array.

Parameters:
array $storedSettings
Returns:
array $storedSettings

Definition at line 294 of file class.t3lib_modsettings.php.

References $storedSettings.

Referenced by initStorage(), and writeStoredSetting().

00294                                                    {
00295 
00296       $storedSettings = is_array($storedSettings) ? $storedSettings : array();
00297 
00298          // clean up the array
00299       foreach($storedSettings as $id => $sdArr) {
00300          if (!is_array($sdArr)) unset($storedSettings[$id]);
00301          if (!is_array($sdArr['data'])) unset($storedSettings[$id]);
00302          if (!trim($sdArr['title']))   $storedSettings[$id]['title'] = '[no title]';
00303       }
00304 
00305       return $storedSettings;
00306    }

t3lib_modSettings::compileEntry data  ) 
 

Creates an entry for the stored settings array Collects data from MOD_SETTINGS selected by the storeList.

Parameters:
array Should work with data from _GP('storeControl'). This is ['title']: Title for the entry. ['desc']: A description text. Currently not used by this class
Returns:
array $storageArr: entry for the stored settings array

Definition at line 316 of file class.t3lib_modsettings.php.

References $SOBE, and processEntry().

Referenced by processStoreControl().

00316                                  {
00317       global $SOBE;
00318 
00319       $storageData = array();
00320       foreach($this->storeList as $MS_key)   {
00321          $storageData[$MS_key] = $SOBE->MOD_SETTINGS[$MS_key];
00322       }
00323       $storageArr = array (
00324                   'title' => $data['title'],
00325                   'desc' => (string)$data['desc'],
00326                   'data' => $storageData,
00327                   'user' => NULL,
00328                   'tstamp' => time(),
00329                );
00330       $storageArr = $this->processEntry($storageArr);
00331 
00332       return $storageArr;
00333    }

t3lib_modSettings::getStoreControl showElements = 'load,
remove  ,
save'  ,
useOwnForm = TRUE
 

Returns the storage control box.

Parameters:
string List of elemetns which should be shown: load,remove,save
boolean If set the box is wrapped with own form tag
Returns:
string HTML code

Definition at line 474 of file class.t3lib_modsettings.php.

References initStorage(), and table().

00474                                                                                  {
00475       global $TYPO3_CONF_VARS;
00476 
00477       $showElements = t3lib_div::trimExplode(',', $showElements, 1);
00478 
00479       $this->initStorage();
00480 
00481          // Preset selector
00482       $opt=array();
00483       $opt[] = '<option value="0">   </option>';
00484       foreach($this->storedSettings as $id => $v)  {
00485          $opt[] = '<option value="'.$id.'">'.htmlspecialchars($v['title']).'</option>';
00486       }
00487       $storedEntries = count($opt)>1;
00488 
00489 
00490 
00491       $codeTD = array();
00492 
00493 
00494          // LOAD, REMOVE, but also show selector so you can overwrite an entry with SAVE
00495       if($storedEntries AND (count($showElements))) {
00496 
00497             // selector box
00498          $onChange = 'document.forms[\''.$this->formName.'\'][\'storeControl[title]\'].value= this.options[this.selectedIndex].value!=0 ? this.options[this.selectedIndex].text : \'\';';
00499          $code = '
00500                <select name="storeControl[STORE]" onChange="'.htmlspecialchars($onChange).'">
00501                '.implode('
00502                   ', $opt).'
00503                </select>';
00504 
00505             // load button
00506          if(in_array('load', $showElements)) {
00507                $code.= '
00508                <input type="submit" name="storeControl[LOAD]" value="Load" /> ';
00509          }
00510 
00511             // remove button
00512          if(in_array('remove', $showElements)) {
00513                $code.= '
00514                <input type="submit" name="storeControl[REMOVE]" value="Remove" /> ';
00515          }
00516          $codeTD[] = '<td width="1%">Preset:</td>';
00517          $codeTD[] = '<td nowrap="nowrap">'.$code.'&nbsp;&nbsp;</td>';
00518       }
00519 
00520 
00521          // SAVE
00522       if(in_array('save', $showElements)) {
00523          $onClick = (!$storedEntries) ? '' : 'if (document.forms[\''.$this->formName.'\'][\'storeControl[STORE]\'].options[document.forms[\''.$this->formName.'\'][\'storeControl[STORE]\'].selectedIndex].value<0) return confirm(\'Are you sure you want to overwrite the existing entry?\');';
00524          $code = '<input name="storeControl[title]" value="" type="text" max="80" width="25"> ';
00525          $code.= '<input type="submit" name="storeControl[SAVE]" value="Save" onClick="'.htmlspecialchars($onClick).'" />';
00526          $codeTD[] = '<td nowrap="nowrap">'.$code.'</td>';
00527       }
00528 
00529 
00530       $codeTD = implode ('
00531          ', $codeTD);
00532 
00533       if (trim($code)) {
00534          $code = '
00535          <!--
00536             Store control
00537          -->
00538          <table border="0" cellpadding="3" cellspacing="0" width="100%">
00539             <tr class="bgColor4">
00540             '.$codeTD.'
00541             </tr>
00542          </table>
00543          ';
00544       }
00545 
00546       if ($this->msg)   {
00547          $code.= '
00548          <div><strong>'.htmlspecialchars($this->msg).'</strong></div>';
00549       }
00550 #TODO need to add parameters
00551       if ($useOwnForm AND trim($code)) {
00552          $code = '
00553       <form action="'.t3lib_div::getIndpEnv('SCRIPT_NAME').'" method="POST" name="'.$this->formName.'" enctype="'.$TYPO3_CONF_VARS['SYS']['form_enctype'].'">'.$code.'</form>';
00554       }
00555 
00556       return $code;
00557    }

t3lib_modSettings::getStoredData storeIndex,
writeArray = array()
 

Copies the stored data from entry $index to $writeArray which can be used to set MOD_SETTINGS.

Parameters:
mixed The entry key
array Preset data array. Will be overwritten by copied values.
Returns:
array Data array

Definition at line 343 of file class.t3lib_modsettings.php.

Referenced by processStoreControl().

00343                                                             {
00344       if ($this->storedSettings[$storeIndex])   {
00345          foreach($this->storeList as $k)  {
00346             $writeArray[$k] = $this->storedSettings[$storeIndex]['data'][$k];
00347          }
00348       }
00349       return $writeArray;
00350    }

t3lib_modSettings::init prefix = '',
storeList = ''
 

Initializes the object.

Parameters:
string Prefix of MOD_SETTING array keys that should be stored
array additional names of keys of the MOD_SETTING array which should be stored (array or comma list)
Returns:
void

Definition at line 181 of file class.t3lib_modsettings.php.

References $TYPO3_CONF_VARS, and setStoreList().

00181                                              {
00182       $this->prefix = $prefix;
00183       $this->setStoreList($storeList);
00184       $this->type = 'perm';
00185 
00186          // enable dev logging if set
00187       if ($TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_modSettings.php']['writeDevLog']) $this->writeDevLog = TRUE;
00188       if (TYPO3_DLOG) $this->writeDevLog = TRUE;
00189    }

t3lib_modSettings::initStorage  ) 
 

Get the stored settings from MOD_SETTINGS and set them in $this->storedSettings.

Returns:
void

Definition at line 279 of file class.t3lib_modsettings.php.

References $storedSettings, and cleanupStorageArray().

Referenced by getStoreControl(), and processStoreControl().

00279                            {
00280       global $SOBE;
00281 
00282       $storedSettings = unserialize($SOBE->MOD_SETTINGS[$this->prefix.'_storedSettings']);
00283       $this->storedSettings = $this->cleanupStorageArray($storedSettings);
00284    }

t3lib_modSettings::processEntry storageArr  ) 
 

Processing entry for the stored settings array Can be overwritten by extended class.

Parameters:
array $storageData: entry for the stored settings array
Returns:
array $storageData: entry for the stored settings array

Definition at line 576 of file class.t3lib_modsettings.php.

Referenced by compileEntry().

00576                                       {
00577       return $storageArr;
00578    }

t3lib_modSettings::processStoreControl mconfName = ''  ) 
 

Processing of the storage command LOAD, SAVE, REMOVE.

Parameters:
string Name of the module to store the settings for. Default: $GLOBALS['SOBE']->MCONF['name'] (current module)
Returns:
string Storage message. Also set in $this->msg

Definition at line 360 of file class.t3lib_modsettings.php.

References $msg, compileEntry(), getStoredData(), initStorage(), and writeStoredSetting().

00360                                                 {
00361 
00362       $this->initStorage();
00363 
00364       #debug($this->storedSettings, '$this->storedSettings', __LINE__, __FILE__);
00365 
00366       $storeControl = t3lib_div::_GP('storeControl');
00367       $storeIndex = $storeControl['STORE'];
00368 
00369       if ($this->writeDevLog) t3lib_div::devLog('Store command: '.t3lib_div::arrayToLogString($storeControl), 't3lib_modSettings', 0);
00370 
00371       $msg = '';
00372       $saveSettings = FALSE;
00373       $writeArray = array();
00374 
00375       if (is_array($storeControl)) {
00376 
00377          //
00378          // processing LOAD
00379          //
00380 
00381          if ($storeControl['LOAD'] AND $storeIndex)   {
00382                $writeArray = $this->getStoredData($storeIndex, $writeArray);
00383                $saveSettings = TRUE;
00384                $msg = "'".$this->storedSettings[$storeIndex]['title']."' preset loaded!";
00385 
00386          //
00387          // processing SAVE
00388          //
00389 
00390          } elseif ($storeControl['SAVE']) {
00391             if (trim($storeControl['title'])) {
00392 
00393                   // get the data to store
00394                $newEntry = $this->compileEntry($storeControl);
00395 
00396                   // create an index for the storage array
00397                if (!$storeIndex) {
00398                   $storeIndex = t3lib_div::shortMD5($newEntry['title']);
00399                }
00400 
00401                   // add data to the storage array
00402                $this->storedSettings[$storeIndex] = $newEntry;
00403 
00404                $saveSettings = TRUE;
00405                $msg = "'".$newEntry['title']."' preset saved!";
00406 
00407             } else {
00408                $msg = 'Please enter a name for the preset!';
00409             }
00410 
00411          //
00412          // processing REMOVE
00413          //
00414 
00415          } elseif ($storeControl['REMOVE'] AND $storeIndex) {
00416                // Removing entry
00417             $msg = "'".$this->storedSettings[$storeIndex]['title']."' preset entry removed!";
00418             unset($this->storedSettings[$storeIndex]);
00419 
00420             $saveSettings = TRUE;
00421          }
00422 
00423 
00424          $this->msg = $msg;
00425 
00426          if ($saveSettings)   {
00427             $this->writeStoredSetting($writeArray, $mconfName);
00428          }
00429 
00430       }
00431       return $this->msg;
00432    }

t3lib_modSettings::setSessionType type = 'ses'  ) 
 

Set session type to 'ses' which will store the settings data not permanently.

Parameters:
string Default is 'ses'
Returns:
void

Definition at line 197 of file class.t3lib_modsettings.php.

00197                                           {
00198       $this->type = $type;
00199    }

t3lib_modSettings::setStoreList storeList  ) 
 

Set MOD_SETTINGS keys which should be stored.

Parameters:
mixed array or string (,) - set additional names of keys of the MOD_SETTING array which should be stored
Returns:
void

Definition at line 218 of file class.t3lib_modsettings.php.

References $storeList.

Referenced by init().

00218                                        {
00219       $this->storeList = is_array($storeList) ? $storeList : t3lib_div::trimExplode(',',$storeList,1);
00220 
00221       if ($this->writeDevLog) t3lib_div::devLog('Store list:'.implode(',',$this->storeList), 't3lib_modSettings', 0);
00222    }

t3lib_modSettings::writeStoredSetting writeArray = array(),
mconfName = ''
 

Write the current storage array and update MOD_SETTINGS.

Parameters:
array Array of settings which should be overwrite current MOD_SETTINGS
string Name of the module to store the settings for. Default: $GLOBALS['SOBE']->MCONF['name'] (current module)
Returns:
void

Definition at line 442 of file class.t3lib_modsettings.php.

References $SOBE, cleanupStorageArray(), and t3lib_BEfunc::getModuleData().

Referenced by processStoreControl().

00442                                                                    {
00443       global $SOBE;
00444 
00445          // for debugging: just removes all module data from user settings
00446       # $GLOBALS['BE_USER']->pushModuleData($SOBE->MCONF['name'],array());
00447 
00448       unset($this->storedSettings[0]); // making sure, index 0 is not set!
00449       $this->storedSettings = $this->cleanupStorageArray($this->storedSettings);
00450       $writeArray[$this->prefix.'_storedSettings'] = serialize($this->storedSettings);
00451 
00452       $SOBE->MOD_SETTINGS = t3lib_BEfunc::getModuleData($SOBE->MOD_MENU, $writeArray, ($mconfName?$mconfName:$SOBE->MCONF['name']), $this->type);
00453 
00454       if ($this->writeDevLog) t3lib_div::devLog('Settings stored:'.$this->msg, 't3lib_modSettings', 0);
00455    }


Member Data Documentation

t3lib_modSettings::$formName = 'storeControl'
 

Name of the form.

Needed for JS

Definition at line 157 of file class.t3lib_modsettings.php.

t3lib_modSettings::$msg = ''
 

Message from the last storage command.

Definition at line 151 of file class.t3lib_modsettings.php.

Referenced by processStoreControl().

t3lib_modSettings::$prefix = ''
 

prefix of MOD_SETTING array keys that should be stored

Definition at line 136 of file class.t3lib_modsettings.php.

Referenced by addToStoreListFromPrefix().

t3lib_modSettings::$storedSettings = array()
 

The stored settings array.

Definition at line 146 of file class.t3lib_modsettings.php.

Referenced by cleanupStorageArray(), and initStorage().

t3lib_modSettings::$storeList = array()
 

Names of keys of the MOD_SETTING array which should be stored.

Definition at line 141 of file class.t3lib_modsettings.php.

Referenced by addToStoreList(), and setStoreList().

t3lib_modSettings::$type = 'perm'
 

If type is set 'ses' then the module data will be stored into the session and will be lost with logout.

Type 'perm' will store the data permanently.

Definition at line 131 of file class.t3lib_modsettings.php.

t3lib_modSettings::$writeDevLog = 0
 

Definition at line 161 of file class.t3lib_modsettings.php.


The documentation for this class was generated from the following file:
Generated on Sun Oct 3 01:07:00 2004 for TYPO3core 3.7.0 dev by  doxygen 1.3.8-20040913