|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2005 - 2010 Jochen Rieger (j.rieger@connecta.ag) 00006 * (c) 2010 - 2011 Michael Miousse (michael.miousse@infoglobe.ca) 00007 * All rights reserved 00008 * 00009 * This script is part of the TYPO3 project. The TYPO3 project is 00010 * free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * The GNU General Public License can be found at 00016 * http://www.gnu.org/copyleft/gpl.html. 00017 * 00018 * This script is distributed in the hope that it will be useful, 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00021 * GNU General Public License for more details. 00022 * 00023 * This copyright notice MUST APPEAR in all copies of the script! 00024 ***************************************************************/ 00025 /** 00026 * This class provides Check Internal Links plugin implementation. 00027 * 00028 * @author Dimitri König <dk@cabag.ch> 00029 * @author Michael Miousse <michael.miousse@infoglobe.ca> 00030 * @package TYPO3 00031 * @subpackage linkvalidator 00032 */ 00033 class tx_linkvalidator_linktype_Internal extends tx_linkvalidator_linktype_Abstract { 00034 00035 const DELETED = 'deleted'; 00036 const HIDDEN = 'hidden'; 00037 const MOVED = 'moved'; 00038 const NOTEXISTING = 'notExisting'; 00039 00040 /** 00041 * All parameters needed for rendering the error message. 00042 * 00043 * @var array 00044 */ 00045 protected $errorParams = array(); 00046 00047 /** 00048 * Result of the check, if the current page uid is valid or not. 00049 * 00050 * @var boolean 00051 */ 00052 protected $responsePage = TRUE; 00053 00054 /** 00055 * Result of the check, if the current content uid is valid or not. 00056 * 00057 * @var boolean 00058 */ 00059 protected $responseContent = TRUE; 00060 00061 /** 00062 * Checks a given URL + /path/filename.ext for validity 00063 * 00064 * @param string $url: url to check as page-id or page-id#anchor (if anchor is present) 00065 * @param array $softRefEntry: the softref entry which builds the context of that url 00066 * @param object $reference: parent instance of tx_linkvalidator_Processor 00067 * @return string TRUE on success or FALSE on error 00068 */ 00069 public function checkLink($url, $softRefEntry, $reference) { 00070 $page = ''; 00071 $anchor = ''; 00072 $response = TRUE; 00073 $this->responseContent = TRUE; 00074 00075 // Might already contain values - empty it. 00076 unset($this->errorParams); 00077 00078 // defines the linked page and anchor (if any). 00079 if (strpos($url, '#c') !== FALSE) { 00080 $parts = explode('#c', $url); 00081 $page = $parts[0]; 00082 $anchor = $parts[1]; 00083 } else { 00084 $page = $url; 00085 } 00086 00087 // Check if the linked page is OK. 00088 $this->responsePage = $this->checkPage($page, $softRefEntry, $reference); 00089 00090 // Check if the linked content element is OK. 00091 if ($anchor) { 00092 00093 // Check if the content element is OK. 00094 $this->responseContent = $this->checkContent($page, $anchor, $softRefEntry, $reference); 00095 00096 } 00097 00098 if ((is_array($this->errorParams['page']) && !$this->responsePage) 00099 || (is_array($this->errorParams['content']) && !$this->responseContent)) { 00100 $this->setErrorParams($this->errorParams); 00101 } 00102 00103 if (($this->responsePage === TRUE) && ($this->responseContent === TRUE)) { 00104 $response = TRUE; 00105 } else { 00106 $response = FALSE; 00107 } 00108 00109 return $response; 00110 } 00111 00112 /** 00113 * Checks a given page uid for validity 00114 * 00115 * @param string $page: page uid to check 00116 * @param array $softRefEntry: the softref entry which builds the context of that url 00117 * @param object $reference: parent instance of tx_linkvalidator_Processor 00118 * @return string TRUE on success or FALSE on error 00119 */ 00120 protected function checkPage($page, $softRefEntry, $reference) { 00121 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( 00122 'uid, title, deleted, hidden, starttime, endtime', 00123 'pages', 00124 'uid = ' . intval($page) 00125 ); 00126 $this->responsePage = TRUE; 00127 00128 if ($rows[0]) { 00129 if ($rows[0]['deleted'] == '1') { 00130 $this->errorParams['errorType']['page'] = DELETED; 00131 $this->errorParams['page']['title'] = $rows[0]['title']; 00132 $this->errorParams['page']['uid'] = $rows[0]['uid']; 00133 $this->responsePage = FALSE; 00134 } elseif ($rows[0]['hidden'] == '1' 00135 || $GLOBALS['EXEC_TIME'] < intval($rows[0]['starttime']) 00136 || ($rows[0]['endtime'] && intval($rows[0]['endtime']) < $GLOBALS['EXEC_TIME'])) { 00137 $this->errorParams['errorType']['page'] = HIDDEN; 00138 $this->errorParams['page']['title'] = $rows[0]['title']; 00139 $this->errorParams['page']['uid'] = $rows[0]['uid']; 00140 $this->responsePage = FALSE; 00141 } 00142 } else { 00143 $this->errorParams['errorType']['page'] = NOTEXISTING; 00144 $this->errorParams['page']['uid'] = intval($page); 00145 $this->responsePage = FALSE; 00146 } 00147 00148 return $this->responsePage; 00149 } 00150 00151 /** 00152 * Checks a given content uid for validity 00153 * 00154 * @param string $page: uid of the page to which the link is pointing 00155 * @param string $anchor: uid of the content element to check 00156 * @param array $softRefEntry: the softref entry which builds the context of that url 00157 * @param object $reference: parent instance of tx_linkvalidator_Processor 00158 * @return string TRUE on success or FALSE on error 00159 */ 00160 protected function checkContent($page, $anchor, $softRefEntry, $reference) { 00161 // Get page ID on which the content element in fact is located 00162 $res = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( 00163 'uid, pid, header, deleted, hidden, starttime, endtime', 00164 'tt_content', 00165 'uid = ' . intval($anchor) 00166 ); 00167 $this->responseContent = TRUE; 00168 00169 // this content element exists 00170 if ($res[0]) { 00171 // page ID on which this CE is in fact located. 00172 $correctPageID = $res[0]['pid']; 00173 00174 // check if the element is on the linked page 00175 // (the element might have been moved to another page) 00176 if (!($correctPageID === $page)) { 00177 $this->errorParams['errorType']['content'] = MOVED; 00178 $this->errorParams['content']['uid'] = intval($anchor); 00179 $this->errorParams['content']['wrongPage'] = intval($page); 00180 $this->errorParams['content']['rightPage'] = intval($correctPageID); 00181 $this->responseContent = FALSE; 00182 00183 } else { 00184 // the element is located on the page to which the link is pointing 00185 if ($res[0]['deleted'] == '1') { 00186 $this->errorParams['errorType']['content'] = DELETED; 00187 $this->errorParams['content']['title'] = $res[0]['header']; 00188 $this->errorParams['content']['uid'] = $res[0]['uid']; 00189 $this->responseContent = FALSE; 00190 } elseif ($res[0]['hidden'] == '1' 00191 || $GLOBALS['EXEC_TIME'] < intval($res[0]['starttime']) 00192 || ($res[0]['endtime'] && intval($res[0]['endtime']) < $GLOBALS['EXEC_TIME'])) { 00193 $this->errorParams['errorType']['content'] = HIDDEN; 00194 $this->errorParams['content']['title'] = $res[0]['header']; 00195 $this->errorParams['content']['uid'] = $res[0]['uid']; 00196 $this->responseContent = FALSE; 00197 } 00198 } 00199 00200 } else { 00201 // content element does not exist 00202 $this->errorParams['errorType']['content'] = NOTEXISTING; 00203 $this->errorParams['content']['uid'] = intval($anchor); 00204 $this->responseContent = FALSE; 00205 } 00206 00207 return $this->responseContent; 00208 } 00209 00210 /** 00211 * Generate the localized error message from the error params saved from the parsing. 00212 * 00213 * @param array all parameters needed for the rendering of the error message 00214 * @return string validation error message 00215 */ 00216 public function getErrorMessage($errorParams) { 00217 $errorType = $errorParams['errorType']; 00218 00219 if (is_array($errorParams['page'])) { 00220 switch ($errorType['page']) { 00221 case DELETED: 00222 $errorPage = $GLOBALS['LANG']->getLL('list.report.pagedeleted'); 00223 $errorPage = str_replace('###title###', $errorParams['page']['title'], $errorPage); 00224 $errorPage = str_replace('###uid###', $errorParams['page']['uid'], $errorPage); 00225 break; 00226 00227 case HIDDEN: 00228 $errorPage = $GLOBALS['LANG']->getLL('list.report.pagenotvisible'); 00229 $errorPage = str_replace('###title###', $errorParams['page']['title'], $errorPage); 00230 $errorPage = str_replace('###uid###', $errorParams['page']['uid'], $errorPage); 00231 break; 00232 00233 default: 00234 $errorPage = $GLOBALS['LANG']->getLL('list.report.pagenotexisting'); 00235 $errorPage = str_replace('###uid###', $errorParams['page']['uid'], $errorPage); 00236 } 00237 } 00238 00239 if (is_array($errorParams['content'])) { 00240 switch ($errorType['content']) { 00241 case DELETED: 00242 $errorContent = $GLOBALS['LANG']->getLL('list.report.contentdeleted'); 00243 $errorContent = str_replace('###title###', $errorParams['content']['title'], $errorContent); 00244 $errorContent = str_replace('###uid###', $errorParams['content']['uid'], $errorContent); 00245 break; 00246 00247 case HIDDEN: 00248 $errorContent = $GLOBALS['LANG']->getLL('list.report.contentnotvisible'); 00249 $errorContent = str_replace('###title###', $errorParams['content']['title'], $errorContent); 00250 $errorContent = str_replace('###uid###', $errorParams['content']['uid'], $errorContent); 00251 break; 00252 00253 case MOVED: 00254 $errorContent = $GLOBALS['LANG']->getLL('list.report.contentmoved'); 00255 $errorContent = str_replace('###title###', $errorParams['content']['title'], $errorContent); 00256 $errorContent = str_replace('###uid###', $errorParams['content']['uid'], $errorContent); 00257 $errorContent = str_replace('###wrongpage###', $errorParams['content']['wrongPage'], $errorContent); 00258 $errorContent = str_replace('###rightpage###', $errorParams['content']['rightPage'], $errorContent); 00259 break; 00260 00261 default: 00262 $errorContent = $GLOBALS['LANG']->getLL('list.report.contentnotexisting'); 00263 $errorContent = str_replace('###uid###', $errorParams['content']['uid'], $errorContent); 00264 } 00265 } 00266 00267 if ($errorPage && $errorContent) { 00268 $response = $errorPage . '<br />' . $errorContent; 00269 } elseif ($errorPage) { 00270 $response = $errorPage; 00271 } elseif ($errorContent) { 00272 $response = $errorContent; 00273 } 00274 00275 return $response; 00276 } 00277 00278 /** 00279 * Url parsing 00280 * 00281 * @param array $row: broken link record 00282 * @return string parsed broken url 00283 */ 00284 public function getBrokenUrl($row) { 00285 $domain = rtrim(t3lib_div::getIndpEnv('TYPO3_SITE_URL'), '/'); 00286 $rootLine = t3lib_BEfunc::BEgetRootLine($row['record_pid']); 00287 // checks alternate domains 00288 if (count($rootLine) > 0) { 00289 $protocol = t3lib_div::getIndpEnv('TYPO3_SSL') ? 'https://' : 'http://'; 00290 $domainRecord = t3lib_BEfunc::firstDomainRecord($rootLine); 00291 if(!empty($domainRecord)) { 00292 $domain = $protocol . $domainRecord; 00293 } 00294 } 00295 return $domain . '/index.php?id=' . $row['url']; 00296 } 00297 } 00298 00299 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/linkvalidator/classes/linktypes/class.tx_linkvalidator_linktypes_internal.php'])) { 00300 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/linkvalidator/classes/linktypes/class.tx_linkvalidator_linktypes_internal.php']); 00301 } 00302 00303 ?>
1.8.0