+
+ /**
+ * Initializes the configuration variables
+ *
+ * @return void
+ */
+ public function initConfiguration() {
+ $this->thisConfig = $this->getRTEConfig();
+ $this->buttonConfig = $this->getButtonConfig();
+ $this->imgPath = $this->getImgPath();
+ $this->RTEImageStorageDir = $this->getRTEImageStorageDir();
+ $this->defaultClass = $this->getDefaultClass();
+ $this->setMaximumImageDimensions();
+ }
+
+ /**
+ * Get the RTE configuration from Page TSConfig
+ *
+ * @return array RTE configuration array
+ */
+ protected function getRTEConfig() {
+ global $BE_USER;
+
+ $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
+ $RTEsetup = $BE_USER->getTSConfig('RTE',t3lib_BEfunc::getPagesTSconfig($RTEtsConfigParts[5]));
+ return t3lib_BEfunc::RTEsetup($RTEsetup['properties'],$RTEtsConfigParts[0],$RTEtsConfigParts[2],$RTEtsConfigParts[4]);
+ }
+
+ /**
+ * Get the path of the image to be inserted or modified
+ *
+ * @return string path to the image
+ */
+ protected function getImgPath() {
+ $RTEtsConfigParts = explode(':', $this->RTEtsConfigParams);
+ return $RTEtsConfigParts[6];
+ }
+
+ /**
+ * Get the configuration of the image button
+ *
+ * @return array the configuration array of the image button
+ */
+ protected function getButtonConfig() {
+ return ((is_array($this->thisConfig['buttons.']) && is_array($this->thisConfig['buttons.']['image.'])) ? $this->thisConfig['buttons.']['image.'] : array());
+ }
+
+ /**
+ * Get the allowed items or tabs
+ *
+ * @param string $items: initial list of possible items
+ * @return array the allowed items
+ */
+ public function getAllowedItems($items) {
+ $allowedItems = explode(',', $items);
+ $clientInfo = t3lib_div::clientInfo();
+ if ($clientInfo['BROWSER'] !== 'opera') {
+ $allowedItems[] = 'dragdrop';
+ }
+ // Call hook for extra options
+ foreach ($this->hookObjects as $hookObject) {
+ $allowedItems = $hookObject->addAllowedItems($allowedItems);
+ }
+ // Remove options according to RTE configuration
+ if (is_array($this->buttonConfig['options.']) && $this->buttonConfig['options.']['removeItems']) {
+ $allowedItems = array_diff($allowedItems, t3lib_div::trimExplode(',', $this->buttonConfig['options.']['removeItems'], 1));
+ } else {
+ $allowedItems = array_diff($allowedItems, t3lib_div::trimExplode(',', $this->buttonConfig['blindImageOptions'], 1));
+ }
+ return $allowedItems;
+ }
+
+ /**
+ * Get the default image class
+ *
+ * @return string the default class, if any
+ */
+ protected function getDefaultClass() {
+ $defaultClass = '';
+ if (is_array($this->buttonConfig['properties.'])) {
+ if (is_array($this->buttonConfig['properties.']['class.']) && trim($this->buttonConfig['properties.']['class.']['default'])) {
+ $defaultClass = trim($this->buttonConfig['properties.']['class.']['default']);
+ }
+ }
+ return $defaultClass;
+ }
+
+ /**
+ * Set variables for maximum image dimensions
+ *
+ * @return void
+ */
+ protected function setMaximumImageDimensions() {
+ if ($TYPO3_CONF_VARS['EXTCONF'][$this->extKey]['plainImageMaxWidth']) $this->plainMaxWidth = $TYPO3_CONF_VARS['EXTCONF'][$this->extKey]['plainImageMaxWidth'];
+ if ($TYPO3_CONF_VARS['EXTCONF'][$this->extKey]['plainImageMaxHeight']) $this->plainMaxHeight = $TYPO3_CONF_VARS['EXTCONF'][$this->extKey]['plainImageMaxHeight'];
+ if (is_array($this->buttonConfig['options.']) && is_array($this->buttonConfig['options.']['plain.'])) {
+ if ($this->buttonConfig['options.']['plain.']['maxWidth']) $this->plainMaxWidth = $this->buttonConfig['options.']['plain.']['maxWidth'];
+ if ($this->buttonConfig['options.']['plain.']['maxHeight']) $this->plainMaxHeight = $this->buttonConfig['options.']['plain.']['maxHeight'];
+ }
+ if (!$this->plainMaxWidth) $this->plainMaxWidth = 640;
+ if (!$this->plainMaxHeight) $this->plainMaxHeight = 680;
+ if (is_array($this->buttonConfig['options.']) && is_array($this->buttonConfig['options.']['magic.'])) {
+ if ($this->buttonConfig['options.']['magic.']['maxWidth']) $this->magicMaxWidth = $this->buttonConfig['options.']['magic.']['maxWidth'];
+ if ($this->buttonConfig['options.']['magic.']['maxHeight']) $this->magicMaxHeight = $this->buttonConfig['options.']['magic.']['maxHeight'];
+ }
+ // These defaults allow images to be based on their width - to a certain degree - by setting a high height. Then we're almost certain the image will be based on the width
+ if (!$this->magicMaxWidth) $this->magicMaxWidth = 300;
+ if (!$this->magicMaxHeight) $this->magicMaxHeight = 1000;
+ }
+
+ /**
+ * Get the help message to be displayed on a given tab
+ *
+ * @param string $act: the identifier of the tab
+ * @return string the text of the message
+ */
+ public function getHelpMessage($act) {
+ global $LANG;
+ switch ($act) {
+ case 'plain':
+ return sprintf($LANG->getLL('plainImage_msg'), $this->plainMaxWidth, $this->plainMaxHeight);
+ break;
+ case 'magic':
+ return sprintf($LANG->getLL('magicImage_msg'));
+ break;
+ default:
+ return '';
+ }
+ }