TYPO3 CMS  TYPO3_6-2
DeprecatedRteProperties.php
Go to the documentation of this file.
1 <?php
3 
18 
25 
26  protected $title = 'Deprecated RTE properties in Page TSconfig';
27 
28  // Properties that may be replaced automatically in Page TSconfig (except inludes from external files)
29  protected $replacementRteProperties = array(
30  'disableRightClick' => 'contextMenu.disable',
31  'disableContextMenu' => 'contextMenu.disable',
32  'hidePStyleItems' => 'buttons.formatblock.removeItems',
33  'hideFontFaces' => 'buttons.fontstyle.removeItems',
34  'fontFace' => 'buttons.fontstyle.addItems',
35  'hideFontSizes' => 'buttons.fontsize.removeItems',
36  'classesCharacter' => 'buttons.textstyle.tags.span.allowedClasses',
37  'classesParagraph' => 'buttons.blockstyle.tags.div.allowedClasses',
38  'classesTable' => 'buttons.blockstyle.tags.table.allowedClasses',
39  'classesTD' => 'buttons.blockstyle.tags.td.allowedClasses',
40  'classesImage' => 'buttons.image.properties.class.allowedClasses',
41  'classesLinks' => 'buttons.link.properties.class.allowedClasses',
42  'blindImageOptions' => 'buttons.image.options.removeItems',
43  'blindLinkOptions' => 'buttons.link.options.removeItems',
44  'defaultLinkTarget' => 'buttons.link.properties.target.default'
45  );
46 
48  'disableTYPO3Browsers' => array(
49  'buttons.image.TYPO3Browser.disabled',
50  'buttons.link.TYPO3Browser.disabled'
51  ),
52  'showTagFreeClasses' => array(
53  'buttons.blockstyle.showTagFreeClasses',
54  'buttons.textstyle.showTagFreeClasses'
55  ),
56  'disablePCexamples' => array(
57  'buttons.blockstyle.disableStyleOnOptionLabel',
58  'buttons.textstyle.disableStyleOnOptionLabel'
59  )
60  );
61 
62  // Properties that may not be replaced automatically in Page TSconfig
63  protected $useInsteadRteProperties = array(
64  'fontSize' => 'buttons.fontsize.addItems',
65  'RTE.default.classesAnchor' => 'RTE.default.buttons.link.properties.class.allowedClasses',
66  'RTE.default.classesAnchor.default.[link-type]' => 'RTE.default.buttons.link.[link-type].properties.class.default',
67  'mainStyleOverride' => 'contentCSS',
68  'mainStyleOverride_add.[key]' => 'contentCSS',
69  'mainStyle_font' => 'contentCSS',
70  'mainStyle_size' => 'contentCSS',
71  'mainStyle_color' => 'contentCSS',
72  'mainStyle_bgcolor' => 'contentCSS',
73  'inlineStyle.[any-keystring]' => 'contentCSS',
74  'ignoreMainStyleOverride' => 'n.a.'
75  );
76 
83  public function checkForUpdate(&$description) {
84  $result = FALSE;
85  // TYPO3 version 4.6 and above
86  if ($this->versionNumber >= 4006000) {
87  $pages = $this->getPagesWithDeprecatedRteProperties($dbQueries, $customMessages);
88  $pagesCount = count($pages);
89  $deprecatedProperties = '';
90  $deprecatedRteProperties = array_merge($this->replacementRteProperties, $this->useInsteadRteProperties);
91  foreach ($deprecatedRteProperties as $deprecatedProperty => $replacementProperty) {
92  $deprecatedProperties .= '<tr><td>' . $deprecatedProperty . '</td><td>' . $replacementProperty . '</td></tr>' . LF;
93  }
94  foreach ($this->doubleReplacementRteProperties as $deprecatedProperty => $replacementProperties) {
95  $deprecatedProperties .= '<tr><td>' . $deprecatedProperty . '</td><td>' . implode(' and ', $replacementProperties) . '</td></tr>' . LF;
96  }
97  $description = '<p>The following Page TSconfig RTE properties are deprecated since TYPO3 4.6 and have been removed in TYPO3 6.0.</p>' . LF . '<table><thead><tr><th>Deprecated property</th><th>Use instead</th></tr></thead>' . LF . '<tbody>' . $deprecatedProperties . '</tboby></table>' . LF . '<p>You are currently using some of these properties on <strong>' . strval($pagesCount) . '&nbsp;pages</strong> (including deleted and hidden pages).</p>' . LF;
98  if ($pagesCount) {
99  $pagesUids = array();
100  foreach ($pages as $page) {
101  $pagesUids[] = $page['uid'];
102  }
103  $description .= '<p>Pages id\'s: ' . implode(', ', $pagesUids) . '</p>';
104  }
105  $replacementProperties = '';
106  foreach ($this->useInsteadRteProperties as $deprecatedProperty => $replacementProperty) {
107  $replacementProperties .= '<tr><td>' . $deprecatedProperty . '</td><td>' . $replacementProperty . '</td></tr>' . LF;
108  }
109  if ($pagesCount) {
110  $updateablePages = $this->findUpdateablePagesWithDeprecatedRteProperties($pages);
111  if (count($updateablePages)) {
112  $replacementProperties = '';
113  foreach ($this->replacementRteProperties as $deprecatedProperty => $replacementProperty) {
114  $replacementProperties .= '<tr><td>' . $deprecatedProperty . '</td><td>' . $replacementProperty . '</td></tr>' . LF;
115  }
116  $description .= '<p>This wizard will perform automatic replacement of the following properties on <strong>' . strval(count($updateablePages)) . '&nbsp;pages</strong> (including deleted and hidden):</p>' . LF . '<table><thead><tr><th>Deprecated property</th><th>Will be replaced by</th></tr></thead><tbody>' . $replacementProperties . '</tboby></table>' . LF . '<p>The Page TSconfig column of the remaining pages will need to be updated manually.</p>' . LF;
117  } else {
118  $replacementProperties = '';
119  foreach ($this->useInsteadRteProperties as $deprecatedProperty => $_) {
120  $replacementProperties .= '<tr><td>' . $deprecatedProperty . '</td></tr>' . LF;
121  }
122  foreach ($this->doubleReplacementRteProperties as $deprecatedProperty => $_) {
123  $replacementProperties .= '<tr><td>' . $deprecatedProperty . '</td></tr>' . LF;
124  }
125  $description .= '<p>This wizard cannot update the following properties, some of which are present on those pages:</p>' . LF . '<table><thead><tr><th>Deprecated property</th></tr></thead><tbody>' . $replacementProperties . '</tboby></table>' . LF . '<p>Therefore, the Page TSconfig column of those pages will need to be updated manually.</p>' . LF;
126  }
127  $result = TRUE;
128  } else {
129  // if we found no occurence of deprecated settings and wizard was already executed, then
130  // we do not show up anymore
131  if ($this->isWizardDone()) {
132  $result = FALSE;
133  }
134  }
135  $description .= '<p>Only page records are searched for deprecated properties. However, such properties can also be used in BE group and BE user records (prepended with page.). These are not searched nor updated by this wizard.</p>' . LF . '<p>Page TSconfig may also be included from external files. These are not updated by this wizard. If required, the update will need to be done manually.</p>' . LF . '<p>Note also that deprecated properties have been replaced in default configurations provided by htmlArea RTE';
136  }
137  return $result;
138  }
139 
147  public function performUpdate(array &$dbQueries, &$customMessages) {
148  $customMessages = '';
149  $pages = $this->getPagesWithDeprecatedRteProperties($dbQueries, $customMessages);
150  if (empty($customMessages)) {
151  $pagesCount = count($pages);
152  if ($pagesCount) {
153  $updateablePages = $this->findUpdateablePagesWithDeprecatedRteProperties($pages);
154  if (count($updateablePages)) {
155  $this->updatePages($updateablePages, $dbQueries, $customMessages);
156  // If the update was successful
157  if (empty($customMessages)) {
158  // If all pages were updated, we query again to check if any deprecated properties are still present.
159  if (count($updateablePages) === $pagesCount) {
160  $pagesAfter = $this->getPagesWithDeprecatedRteProperties($dbQueries, $customMessages);
161  if (empty($customMessages)) {
162  if (count($pagesAfter)) {
163  $customMessages = 'Some deprecated Page TSconfig properties were found. However, the wizard was unable to automatically replace all the deprecated properties found. Some properties will have to be replaced manually.';
164  }
165  }
166  } else {
167  $customMessages = 'Some deprecated Page TSconfig properties were found. However, the wizard was unable to automatically replace all the deprecated properties found. Some properties will have to be replaced manually.';
168  }
169  }
170  } else {
171  $customMessages = 'Some deprecated Page TSconfig properties were found. However, the wizard was unable to automatically replace any of the deprecated properties found. These properties will have to be replaced manually.';
172  }
173  }
174  }
175  $this->markWizardAsDone();
176  return empty($customMessages);
177  }
178 
186  protected function getPagesWithDeprecatedRteProperties(&$dbQueries, &$customMessages) {
187  $fields = 'uid, TSconfig';
188  $table = 'pages';
189  $where = '';
191  $db = $GLOBALS['TYPO3_DB'];
192  foreach (array_merge($this->replacementRteProperties, $this->useInsteadRteProperties, $this->doubleReplacementRteProperties) as $deprecatedRteProperty => $_) {
193  $where .= ($where ? ' OR ' : '') . '(TSConfig LIKE BINARY ' . $db->fullQuoteStr('%RTE.%' . $deprecatedRteProperty . '%', 'pages') . ' AND TSConfig NOT LIKE BINARY ' . $db->fullQuoteStr('%RTE.%' . $deprecatedRteProperty . 's%', 'pages') . ')' . LF;
194  }
195  $res = $db->exec_SELECTquery($fields, $table, $where);
196  $dbQueries[] = str_replace(chr(10), ' ', $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery);
197  if ($db->sql_error()) {
198  $customMessages = 'SQL-ERROR: ' . htmlspecialchars($db->sql_error());
199  }
200  $pages = array();
201  while ($row = $db->sql_fetch_assoc($res)) {
202  $pages[] = $row;
203  }
204  return $pages;
205  }
206 
214  foreach ($pages as $index => $page) {
215  $deprecatedProperties = explode(',', '/' . implode('/,/((RTE\\.(default\\.|config\\.[a-zA-Z0-9_\\-]*\\.[a-zA-Z0-9_\\-]*\\.))|\\s)', array_keys($this->replacementRteProperties)) . '/');
216  $replacementProperties = explode(',', '$1' . implode(',$1', array_values($this->replacementRteProperties)));
217  $updatedPageTSConfig = preg_replace($deprecatedProperties, $replacementProperties, $page['TSconfig']);
218  if ($updatedPageTSConfig == $page['TSconfig']) {
219  unset($pages[$index]);
220  } else {
221  $pages[$index]['TSconfig'] = $updatedPageTSConfig;
222  }
223  }
224  return $pages;
225  }
226 
234  protected function updatePages($pages, &$dbQueries, &$customMessages) {
235  foreach ($pages as $page) {
236  $table = 'pages';
237  $where = 'uid =' . $page['uid'];
238  $field_values = array(
239  'TSconfig' => $page['TSconfig']
240  );
241  $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, $where, $field_values);
242  $dbQueries[] = str_replace(chr(10), ' ', $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery);
243  if ($GLOBALS['TYPO3_DB']->sql_error()) {
244  $customMessages .= 'SQL-ERROR: ' . htmlspecialchars($GLOBALS['TYPO3_DB']->sql_error()) . LF . LF;
245  }
246  }
247  }
248 
249 }
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]