/**
 *  Copyright (c) 2013-2014 Angelo ZERR.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  Contributors:
 *  Angelo Zerr <angelo.zerr@gmail.com> - initial API and implementation
 */
package org.eclipse.wst.html.webresources.internal.core.validation;

import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.wst.html.webresources.core.providers.IWebResourcesContext;
import org.eclipse.wst.html.webresources.core.providers.WebResourceKind;
import org.eclipse.wst.html.webresources.core.validation.IWebResourcesIgnoreValidator;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;


@SuppressWarnings( "restriction" )
public class PHPScriptIgnoreValidator implements IWebResourcesIgnoreValidator {

	private final IContentType htmlContentType;
	private final IContentType phpContentType;

	public PHPScriptIgnoreValidator() {
		htmlContentType = Platform.getContentTypeManager().getContentType("org.eclipse.wst.html.core.htmlsource");
		phpContentType = Platform.getContentTypeManager().getContentType("org.eclipse.php.core.phpsource");
	}

	@Override
	public boolean shouldIgnore(Object resource, WebResourceKind resourceKind, IWebResourcesContext context) {
		if (context != null) {
			IContentType fileContentType = null;

			try {
				fileContentType = context.getHtmlFile().getContentDescription().getContentType();
			}
			catch( Exception e ) { }

			if (fileContentType != null && 
					(fileContentType.isKindOf(phpContentType) || fileContentType.isKindOf(htmlContentType))) {
				final IDOMNode node = context.getHtmlNode();

				if (node instanceof IDOMAttr) {
					final IDOMAttr attr = (IDOMAttr) node;
					final String attrName = attr.getName();

					if (attrName != null &&
						(attrName.equalsIgnoreCase("href") || attrName.equalsIgnoreCase("src"))) {
						final String val = attr.getValue();

						if (val != null && (val.contains("<?php") || val.contains("?>"))) {
							return true;
						}
					}
				}
			}
		}

		return false;
	}

}

@@ -551,16 +551,87 @@
 ntType;%0A
+import org.eclipse.wst.html.core.internal.provisional.HTML40Namespace;%0A
 import o
@@ -1005,17 +1005,16 @@
 MNode;%0A%0A
-%0A
 @Suppres
@@ -1023,17 +1023,16 @@
 arnings(
- 
 %22restric
@@ -1036,17 +1036,16 @@
 riction%22
- 
 )%0Apublic
@@ -1119,16 +1119,118 @@
 ator %7B%0A%0A
+%09private static final String START_SCRIPT = %22%3C?php%22;%0A%09private static final String END_SCRIPT = %22?%3E%22;%0A%0A
 %09private
@@ -1851,19 +1851,16 @@
 %09%09%09%7D
-%0A%09%09%09
+ 
 catch
-(
  
+(
 Exce
@@ -1870,13 +1870,15 @@
 on e
- 
 ) %7B
- 
+%0A%09%09%09
 %7D%0A%0A%09
@@ -1910,18 +1910,17 @@
 null
- && 
 %0A%09%09%09%09%09
+&& 
 (fil
@@ -2214,61 +2214,242 @@
 l &&
-%0A%09%09%09%09%09%09(attrName.equalsIgnoreCase(%22href%22) %7C%7C attrName
+ (HTML40Namespace.ATTR_NAME_HREF.equalsIgnoreCase(attrName)%0A%09%09%09%09%09%09%09%7C%7C HTML40Namespace.ATTR_NAME_SRC.equalsIgnoreCase(attrName)%0A%09%09%09%09%09%09%09%7C%7C HTML40Namespace.ATTR_NAME_CLASS.equalsIgnoreCase(attrName)%0A%09%09%09%09%09%09%09%7C%7C HTML40Namespace.ATTR_NAME_ID
 .equ
@@ -2466,13 +2466,16 @@
 ase(
-%22src%22
+attrName
 ))) 
@@ -2558,23 +2558,28 @@
 ontains(
-%22%3C?php%22
+START_SCRIPT
 ) %7C%7C val
@@ -2588,20 +2588,26 @@
 ontains(
-%22?%3E%22
+END_SCRIPT
 ))) %7B%0A%09%09

Fix #43: Avoid validating class values with PHP code inside