TYPO3 CMS  TYPO3_6-2
InternalLinktype.php
Go to the documentation of this file.
1 <?php
3 
24 
28  const DELETED = 'deleted';
29 
33  const HIDDEN = 'hidden';
34 
38  const MOVED = 'moved';
39 
43  const NOTEXISTING = 'notExisting';
44 
50  protected $errorParams = array();
51 
57  protected $responsePage = TRUE;
58 
64  protected $responseContent = TRUE;
65 
74  public function checkLink($url, $softRefEntry, $reference) {
75  $anchor = '';
76  $this->responseContent = TRUE;
77  // Might already contain values - empty it
78  unset($this->errorParams);
79  // Only check pages records. Content elements will also be checked
80  // as we extract the anchor in the next step.
81  if (strpos($softRefEntry['substr']['recordRef'], 'pages:') !== 0) {
82  return TRUE;
83  }
84  // Defines the linked page and anchor (if any).
85  if (strpos($url, '#c') !== FALSE) {
86  $parts = explode('#c', $url);
87  $page = $parts[0];
88  $anchor = $parts[1];
89  } else {
90  $page = $url;
91  }
92  // Check if the linked page is OK
93  $this->responsePage = $this->checkPage($page);
94  // Check if the linked content element is OK
95  if ($anchor) {
96  // Check if the content element is OK
97  $this->responseContent = $this->checkContent($page, $anchor);
98  }
99  if (is_array($this->errorParams['page']) && !$this->responsePage
100  || is_array($this->errorParams['content']) && !$this->responseContent
101  ) {
102  $this->setErrorParams($this->errorParams);
103  }
104  if ($this->responsePage === TRUE && $this->responseContent === TRUE) {
105  $response = TRUE;
106  } else {
107  $response = FALSE;
108  }
109  return $response;
110  }
111 
118  protected function checkPage($page) {
119  $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('uid, title, deleted, hidden, starttime, endtime', 'pages', 'uid = ' . (int)$page);
120  $this->responsePage = TRUE;
121  if ($row) {
122  if ($row['deleted'] == '1') {
123  $this->errorParams['errorType']['page'] = self::DELETED;
124  $this->errorParams['page']['title'] = $row['title'];
125  $this->errorParams['page']['uid'] = $row['uid'];
126  $this->responsePage = FALSE;
127  } elseif ($row['hidden'] == '1' || $GLOBALS['EXEC_TIME'] < (int)$row['starttime'] || $row['endtime'] && (int)$row['endtime'] < $GLOBALS['EXEC_TIME']) {
128  $this->errorParams['errorType']['page'] = self::HIDDEN;
129  $this->errorParams['page']['title'] = $row['title'];
130  $this->errorParams['page']['uid'] = $row['uid'];
131  $this->responsePage = FALSE;
132  }
133  } else {
134  $this->errorParams['errorType']['page'] = self::NOTEXISTING;
135  $this->errorParams['page']['uid'] = (int)$page;
136  $this->responsePage = FALSE;
137  }
138  return $this->responsePage;
139  }
140 
148  protected function checkContent($page, $anchor) {
149  // Get page ID on which the content element in fact is located
150  $res = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('uid, pid, header, deleted, hidden, starttime, endtime', 'tt_content', 'uid = ' . (int)$anchor);
151  $this->responseContent = TRUE;
152  // this content element exists
153  if ($res) {
154  // page ID on which this CE is in fact located.
155  $correctPageID = $res['pid'];
156  // Check if the element is on the linked page
157  // (The element might have been moved to another page)
158  if (!($correctPageID === $page)) {
159  $this->errorParams['errorType']['content'] = self::MOVED;
160  $this->errorParams['content']['uid'] = (int)$anchor;
161  $this->errorParams['content']['wrongPage'] = (int)$page;
162  $this->errorParams['content']['rightPage'] = (int)$correctPageID;
163  $this->responseContent = FALSE;
164  } else {
165  // The element is located on the page to which the link is pointing
166  if ($res['deleted'] == '1') {
167  $this->errorParams['errorType']['content'] = self::DELETED;
168  $this->errorParams['content']['title'] = $res['header'];
169  $this->errorParams['content']['uid'] = $res['uid'];
170  $this->responseContent = FALSE;
171  } elseif ($res['hidden'] == '1' || $GLOBALS['EXEC_TIME'] < (int)$res['starttime'] || $res['endtime'] && (int)$res['endtime'] < $GLOBALS['EXEC_TIME']) {
172  $this->errorParams['errorType']['content'] = self::HIDDEN;
173  $this->errorParams['content']['title'] = $res['header'];
174  $this->errorParams['content']['uid'] = $res['uid'];
175  $this->responseContent = FALSE;
176  }
177  }
178  } else {
179  // The content element does not exist
180  $this->errorParams['errorType']['content'] = self::NOTEXISTING;
181  $this->errorParams['content']['uid'] = (int)$anchor;
182  $this->responseContent = FALSE;
183  }
184  return $this->responseContent;
185  }
186 
193  public function getErrorMessage($errorParams) {
194  $errorType = $errorParams['errorType'];
195  if (is_array($errorParams['page'])) {
196  switch ($errorType['page']) {
197  case self::DELETED:
198  $errorPage = str_replace(
199  array(
200  '###title###',
201  '###uid###'
202  ),
203  array(
204  $errorParams['page']['title'],
205  $errorParams['page']['uid']
206  ),
207  $GLOBALS['LANG']->getLL('list.report.pagedeleted')
208  );
209  break;
210  case self::HIDDEN:
211  $errorPage = str_replace(
212  array(
213  '###title###',
214  '###uid###'
215  ),
216  array(
217  $errorParams['page']['title'],
218  $errorParams['page']['uid']
219  ),
220  $GLOBALS['LANG']->getLL('list.report.pagenotvisible')
221  );
222  break;
223  default:
224  $errorPage = str_replace(
225  '###uid###',
226  $errorParams['page']['uid'],
227  $GLOBALS['LANG']->getLL('list.report.pagenotexisting')
228  );
229  }
230  }
231  if (is_array($errorParams['content'])) {
232  switch ($errorType['content']) {
233  case self::DELETED:
234  $errorContent = str_replace(
235  array(
236  '###title###',
237  '###uid###'
238  ),
239  array(
240  $errorParams['content']['title'],
241  $errorParams['content']['uid']
242  ),
243  $GLOBALS['LANG']->getLL('list.report.contentdeleted')
244  );
245  break;
246  case self::HIDDEN:
247  $errorContent = str_replace(
248  array(
249  '###title###',
250  '###uid###'
251  ),
252  array(
253  $errorParams['content']['title'],
254  $errorParams['content']['uid']
255  ),
256  $GLOBALS['LANG']->getLL('list.report.contentnotvisible')
257  );
258  break;
259  case self::MOVED:
260  $errorContent = str_replace(
261  array(
262  '###title###',
263  '###uid###',
264  '###wrongpage###',
265  '###rightpage###'
266  ),
267  array(
268  $errorParams['content']['title'],
269  $errorParams['content']['uid'],
270  $errorParams['content']['wrongPage'],
271  $errorParams['content']['rightPage']
272  ),
273  $GLOBALS['LANG']->getLL('list.report.contentmoved')
274  );
275  break;
276  default:
277  $errorContent = str_replace('###uid###', $errorParams['content']['uid'], $GLOBALS['LANG']->getLL('list.report.contentnotexisting'));
278  }
279  }
280  if (isset($errorPage) && isset($errorContent)) {
281  $response = $errorPage . LF . $errorContent;
282  } elseif (isset($errorPage)) {
283  $response = $errorPage;
284  } elseif (isset($errorContent)) {
285  $response = $errorContent;
286  } else {
287  // This should not happen
288  $response = $GLOBALS['LANG']->getLL('list.report.noinformation');
289  }
290  return $response;
291  }
292 
299  public function getBrokenUrl($row) {
300  $domain = rtrim(\TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL'), '/');
301  $rootLine = \TYPO3\CMS\Backend\Utility\BackendUtility::BEgetRootLine($row['record_pid']);
302  // checks alternate domains
303  if (count($rootLine) > 0) {
304  $protocol = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SSL') ? 'https://' : 'http://';
306  if (!empty($domainRecord)) {
307  $domain = $protocol . $domainRecord;
308  }
309  }
310  return $domain . '/index.php?id=' . $row['url'];
311  }
312 }
static BEgetRootLine($uid, $clause='', $workspaceOL=FALSE)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]