Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cAjaxRequest
  • cAutoload
  • cBackend
  • cEffectiveSetting
  • cGuiScrollListAlltranslations
  • cHTMLValidator
  • cMailer
  • cModuleFileTranslation
  • cModuleHandler
  • cModuleSearch
  • cModuleSynchronizer
  • cModuleTemplateHandler
  • CodeMirror
  • cPasswordRequest
  • cPermission
  • cRegistry
  • cSystemPurge
  • cSystemtest
  • cTinymce4Configuration
  • cTinyMCE4Editor
  • cTinyMCEEditor
  • cWYSIWYGEditor
  • FrontendList
  • HtmlParser
  • TODOBackendList
  • TreeItem
  • UploadList
  • UploadSearchResultList

Functions

  • addArtspec
  • addSortImages
  • backToMainArea
  • buildArticleSelect
  • buildCategorySelect
  • buildCategorySelectRights
  • buildHeapTable
  • buildStackString
  • buildTree
  • buildUserOrGroupPermsFromRequest
  • callPluginStore
  • cApiCatGetLevelNode
  • cApiImageCheckCachedImageValidity
  • cApiImageCheckImageEditingPosibility
  • cApiImageGetCacheFileName
  • cApiImageGetTargetDimensions
  • cApiImageIsAnimGif
  • cApiImgScale
  • cApiImgScaleGetMD5CacheFile
  • cApiImgScaleHQ
  • cApiImgScaleImageMagick
  • cApiImgScaleLQ
  • cApiIsImageMagickAvailable
  • cApiStrCleanURLCharacters
  • cApiStrNormalizeLineEndings
  • cApiStrRecodeString
  • cApiStrReplaceDiacritics
  • cApiStrTrimAfterWord
  • cApiStrTrimHard
  • cApiStrTrimSentence
  • cDeprecated
  • cDie
  • cError
  • checkLangInClients
  • checkPathInformation
  • cInclude
  • compareUrlStrings
  • conChangeTemplateForCat
  • conCopyArticle
  • conCopyArtLang
  • conCopyContainerConf
  • conCopyContent
  • conCopyMetaTags
  • conCopyTemplateConfiguration
  • conCreateLocationString
  • conDeeperCategoriesArray
  • conDeleteart
  • conEditArt
  • conEditFirstTime
  • conFetchCategoryTree
  • conFlagOnOffline
  • conGenerateCode
  • conGenerateCodeForAllArts
  • conGenerateCodeForAllArtsInCategory
  • conGenerateCodeForAllartsUsingLayout
  • conGenerateCodeForAllartsUsingMod
  • conGenerateCodeForAllArtsUsingTemplate
  • conGenerateCodeForArtInAllCategories
  • conGenerateCodeForClient
  • conGenerateKeywords
  • conGetAvailableMetaTagTypes
  • conGetCategoryArticleId
  • conGetCategoryAssignments
  • conGetContainerConfiguration
  • conGetContentFromArticle
  • conGetHtmlTranslationTable
  • conGetMetaValue
  • conGetTemplateConfigurationIdForArticle
  • conGetTemplateConfigurationIdForCategory
  • conGetTopmostCat
  • conGetUsedModules
  • conHtmlentities
  • conHtmlEntityDecode
  • conHtmlSpecialChars
  • conIsLocked
  • conLock
  • conLockBulkEditing
  • conMakeArticleIndex
  • conMakeCatOnline
  • conMakeInlineScript
  • conMakeOnline
  • conMakeOnlineBulkEditing
  • conMakePublic
  • conMakeStart
  • conMoveArticles
  • conPhp54Check
  • conRemoveOldCategoryArticle
  • conSaveContentEntry
  • conSetCodeFlag
  • conSetCodeFlagBulkEditing
  • conSetMetaValue
  • conSyncArticle
  • copyRightsForElement
  • createBulkEditingFunction
  • createRandomName
  • createRightsForElement
  • cWarning
  • dbGetColumns
  • dbGetIndexes
  • dbGetPrimaryKeyName
  • dbTableExists
  • dbUpgradeTable
  • defineIfNotDefined
  • deleteArtspec
  • deleteRightsForElement
  • deleteSystemProperty
  • displayDatetime
  • emptyLogFile
  • endAndLogTiming
  • extractNumber
  • generateDisplayFilePath
  • generateJs
  • getAllClientsAndLanguages
  • getArtLang
  • getArtspec
  • getAvailableContentTypes
  • getCanonicalDay
  • getCanonicalMonth
  • getDirectorySize
  • getEffectiveSetting
  • getEffectiveSettingsByType
  • getEncodingByLanguage
  • getFileContents
  • getFileInformation
  • getFileType
  • getGroupOrUserName
  • getIDForArea
  • getJsHelpContext
  • getLanguageNamesByClient
  • getLanguagesByClient
  • getmicrotime
  • getNamedFrame
  • getParam
  • getParentAreaId
  • getSearchResults
  • getStrExpandCollapseButton
  • getSystemProperties
  • getSystemPropertiesByType
  • getSystemProperty
  • getTemplateSelect
  • getUplExpandCollapseButton
  • htmldecode
  • htmlentities_iso88592
  • humanReadableSize
  • includePlugins
  • insertEmptyStrRow
  • ipMatch
  • isAlphanumeric
  • isArchive
  • isArtInMultipleUse
  • isFunctionDisabled
  • isGroup
  • isIPv4
  • isRunningFromWeb
  • isStartArticle
  • isUtf8
  • isValidMail
  • langActivateDeactivateLanguage
  • langDeleteLanguage
  • langEditLanguage
  • langGetTextDirection
  • langNewLanguage
  • langRenameLanguage
  • layDeleteLayout
  • layEditLayout
  • machineReadableSize
  • mailLogBulkEditingFunctions
  • mailLogDecodeAddresses
  • markSubMenuItem
  • mask
  • modDeleteModule
  • modEditModule
  • phpInfoToHtml
  • plugin_include
  • prCreateURLNameLocationString
  • prDeleteCacheFileContent
  • prGetCacheFileContent
  • prResolvePathViaCategoryNames
  • prResolvePathViaURLNames
  • prWriteCacheFileContent
  • putFileContents
  • recursiveCopy
  • removeFileInformation
  • renderBackendBreadcrumb
  • renderLabel
  • renderSelectProperty
  • renderTextProperty
  • saveGroupRights
  • saveRights
  • scanDirectory
  • scanPlugins
  • sendEncodingHeader
  • set_magic_quotes_gpc
  • setArtspecDefault
  • setArtspecOnline
  • setSystemProperty
  • showTree
  • startTiming
  • statCreateLocationString
  • statDisplayTopChooser
  • statDisplayYearlyTopChooser
  • statGetAvailableMonths
  • statGetAvailableYears
  • statResetStatistic
  • statsArchive
  • statsDisplayInfo
  • statsOverviewAll
  • statsOverviewTop
  • statsOverviewTopYear
  • statsOverviewYear
  • strAssignTemplate
  • strBuildSqlValues
  • strCheckTreeForErrors
  • strCopyCategory
  • strCopyTree
  • strDeeperCategoriesArray
  • strDeleteCategory
  • strHasArticles
  • strHasStartArticle
  • strMakePublic
  • strMakeVisible
  • strMoveCatTargetallowed
  • strMoveDownCategory
  • strMoveSubtree
  • strMoveUpCategory
  • strNewCategory
  • strNewTree
  • strNextBackwards
  • strNextDeeper
  • strNextDeeperAll
  • strNextPost
  • strOrderedPostTreeList
  • strRemakeTreeTable
  • strRenameCategory
  • strRenameCategoryAlias
  • strSortPrePost
  • strSyncCategory
  • systemHavePerm
  • tplAutoFillModules
  • tplBrowseLayoutForContainers
  • tplcfgDuplicate
  • tplDeleteTemplate
  • tplDuplicateTemplate
  • tplEditTemplate
  • tplGetContainerDefault
  • tplGetContainerMode
  • tplGetContainerName
  • tplGetContainerNumbersInLayout
  • tplGetContainerTypes
  • tplGetInUsedData
  • tplIsTemplateInUse
  • tplPreparseLayout
  • tplProcessSendContainerConfiguration
  • updateClientCache
  • updateFileInformation
  • uplCreateFriendlyName
  • uplDirectoryListRecursive
  • uplGetDirectoriesToExclude
  • uplGetFileExtension
  • uplGetFileIcon
  • uplGetFileTypeDescription
  • uplGetThumbnail
  • uplHasFiles
  • uplHasSubdirs
  • uplmkdir
  • uplRecursiveDBDirectoryList
  • uplRecursiveDirectoryList
  • uplRenameDirectory
  • uplSearch
  • uplSyncDirectory
  • uplSyncDirectoryDBFS
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3:  * This file contains the html validator class.
  4:  *
  5:  * @package Core
  6:  * @subpackage Backend
  7:  * @author timo.hummel
  8:  * @copyright four for business AG <www.4fb.de>
  9:  * @license http://www.contenido.org/license/LIZENZ.txt
 10:  * @link http://www.4fb.de
 11:  * @link http://www.contenido.org
 12:  */
 13: 
 14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 15: 
 16: /**
 17:  * This class validates HTML.
 18:  *
 19:  * @package Core
 20:  * @subpackage Backend
 21:  */
 22: class cHTMLValidator {
 23: 
 24:     /**
 25:      *
 26:      * @var array
 27:      */
 28:     protected $_doubleTags = array(
 29:         "form",
 30:         "head",
 31:         "body",
 32:         "html",
 33:         "td",
 34:         "tr",
 35:         "table",
 36:         "a",
 37:         "tbody",
 38:         "title",
 39:         "container",
 40:         "span",
 41:         "div"
 42:     );
 43: 
 44:     /**
 45:      *
 46:      * @var array
 47:      */
 48:     public $missingNodes = array();
 49: 
 50:     /**
 51:      *
 52:      * @deprecated
 53:      *         not used anymore
 54:      * @var string
 55:      */
 56:     public $iNodeName;
 57: 
 58:     /**
 59:      *
 60:      * @var string
 61:      */
 62:     protected $_html;
 63: 
 64:     /**
 65:      *
 66:      * @var array
 67:      */
 68:     protected $_nestingLevel = array();
 69: 
 70:     /**
 71:      *
 72:      * @var array
 73:      */
 74:     protected $_nestingNodes = array();
 75: 
 76:     /**
 77:      *
 78:      * @var array
 79:      */
 80:     protected $_existingTags = array();
 81: 
 82:     /**
 83:      *
 84:      * @param string $html
 85:      */
 86:     public function validate($html) {
 87:         $nestingLevel = 0;
 88: 
 89:         // Clean up HTML first from any PHP scripts, and clean up line breaks
 90:         $this->_html = $this->_cleanHTML($html);
 91: 
 92:         $htmlParser = new HtmlParser($this->_html);     
 93: 
 94:         while ($htmlParser->parse()) {
 95:             $nodeName = $htmlParser->getNodeName();
 96:             $this->_existingTags[] = $nodeName;
 97:             // Check if we found a double tag
 98:             if (in_array($nodeName, $this->_doubleTags)) {
 99:                 if (!array_key_exists($nodeName, $this->_nestingLevel)) {
100:                     $this->_nestingLevel[$nodeName] = 0;
101:                 }
102: 
103:                 if (!array_key_exists($nodeName, $this->_nestingNodes)) {
104:                     $this->_nestingNodes[$nodeName][intval($this->_nestingLevel[$nodeName])] = array();
105:                 }
106: 
107:                 // Check if it's a start tag
108:                 if ($htmlParser->getNodeType() == HtmlParser::NODE_TYPE_ELEMENT) {
109:                     // Push the current element to the stack, remember ID and
110:                     // Name, if possible
111:                     $nestingLevel++;
112: 
113:                     $this->_nestingNodes[$nodeName][intval($this->_nestingLevel[$nodeName])]["name"] = $htmlParser->getNodeAttributes('name');
114:                     $this->_nestingNodes[$nodeName][intval($this->_nestingLevel[$nodeName])]["id"] = $htmlParser->getNodeAttributes('id');
115:                     $this->_nestingNodes[$nodeName][intval($this->_nestingLevel[$nodeName])]["level"] = $nestingLevel;
116:                     $this->_nestingNodes[$nodeName][intval($this->_nestingLevel[$nodeName])]["char"] = $htmlParser->getHtmlTextIndex();
117:                     $this->_nestingLevel[$nodeName]++;
118:                 }
119: 
120:                 if ($htmlParser->getNodeType() == HtmlParser::NODE_TYPE_ENDELEMENT) {
121:                     // Check if we've an element of this type on the stack
122:                     if ($this->_nestingLevel[$nodeName] > 0) {
123:                         unset($this->_nestingNodes[$nodeName][$this->_nestingLevel[$nodeName]]);
124:                         $this->_nestingLevel[$nodeName]--;
125: 
126:                         if ($this->_nestingNodes[$nodeName][intval($this->_nestingLevel[$nodeName])]["level"] != $nestingLevel) {
127:                             // Todo: Check for the wrong nesting level
128:                         }
129: 
130:                         $nestingLevel--;
131:                     }
132:                 }
133:             }
134:         }
135: 
136:         // missingNodes should be an empty array by default
137:         $this->missingNodes = array();
138: 
139:         // Collect all missing nodes
140:         foreach ($this->_nestingLevel as $key => $value) {
141:             // One or more missing tags found
142:             if ($value > 0) {
143:                 // Step trough all missing tags
144:                 for ($i = 0; $i < $value; $i++) {
145:                     $node = $this->_nestingNodes[$key][$i];
146: 
147:                     list($line, $char) = $this->_getLineAndCharPos($node["char"]);
148:                     $this->missingNodes[] = array(
149:                         "tag" => $key,
150:                         "id" => $node["id"],
151:                         "name" => $node["name"],
152:                         "line" => $line,
153:                         "char" => $char
154:                     );
155: 
156:                     $this->missingTags[$line][$char] = true;
157:                 }
158:             }
159:         }
160:     }
161: 
162:     /**
163:      *
164:      * @param string $tag
165:      * @return bool
166:      */
167:     public function tagExists($tag) {
168:         if (in_array($tag, $this->_existingTags)) {
169:             return true;
170:         } else {
171:             return false;
172:         }
173:     }
174: 
175:     /**
176:      *
177:      * @param string $html
178:      * @return mixed
179:      */
180:     protected function _cleanHTML($html) {
181:         // remove all php code from layout
182:         $resultingHTML = preg_replace('/<\?(php)?((.)|(\s))*?\?>/i', '', $html);
183: 
184:         // We respect only \n, but we need to take care of windows (\n\r) and
185:         // other systems (\r)
186:         $resultingHTML = str_replace("\r\n", "\n", $resultingHTML);
187:         $resultingHTML = str_replace("\r", "\n", $resultingHTML);
188: 
189:         return $resultingHTML;
190:     }
191: 
192:     /**
193:      *
194:      * @deprecated
195:      *         not used anymore
196:      * @return string
197:      */
198:     protected function _returnErrorMap() {
199:         $html = "<pre>";
200: 
201:         $chunks = explode("\n", $this->_html);
202: 
203:         foreach ($chunks as $key => $value) {
204:             $html .= ($key + 1) . " ";
205: 
206:             for ($i = 0; $i < strlen($value); $i++) {
207:                 $char = substr($value, $i, 1);
208: 
209:                 if (is_array($this->missingTags[$key + 1])) {
210:                     // echo ($key+1) . " ". $i."<br>";
211:                     if (array_key_exists($i + 2, $this->missingTags[$key + 1])) {
212:                         $html .= "<u><b>" . conHtmlSpecialChars($char) . "</b></u>";
213:                     } else {
214:                         $html .= conHtmlSpecialChars($char);
215:                     }
216:                 } else {
217:                     $html .= conHtmlSpecialChars($char);
218:                 }
219:             }
220: 
221:             $html .= "<br>";
222:         }
223: 
224:         return $html;
225:     }
226: 
227:     /**
228:      *
229:      * @param int $charpos
230:      * @return array
231:      */
232:     protected function _getLineAndCharPos($charpos) {
233:         $mangled = substr($this->_html, 0, $charpos);
234: 
235:         $line = substr_count($mangled, "\n") + 1;
236:         $char = $charpos - strrpos($mangled, "\n");
237: 
238:         return array($line, $char);
239:     }
240: }
241: 
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0