Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
W3CValidatorServiceUtil.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
43  {
52  public static function validate($content)
53  {
54  $xhtmlValidationErrors = array();
55  $params = array(
56  'fragment' => $content,
57  'output' => 'soap12',
58  );
59 
60  $url = 'http://validator.w3.org/check';
61  $ch = curl_init();
62  curl_setopt($ch, CURLOPT_URL, $url);
63  curl_setopt($ch, CURLOPT_POST, true);
64  curl_setopt($ch, CURLOPT_POSTFIELDS, $params); // multipart encoding
65  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
66  curl_setopt($ch, CURLOPT_REFERER, '');
67  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
68  curl_setopt($ch, CURLOPT_TIMEOUT, 60);
69  curl_setopt($ch, CURLOPT_USERAGENT, 'PHP CURL');
70 
71  $xml = curl_exec($ch);
72  if (curl_errno($ch))
73  {
74  throw new FailedServiceException(curl_error($ch));
75  }
76  else
77  {
78  curl_close($ch);
79  }
80  $doc = simplexml_load_string($xml);
81  $doc->registerXPathNamespace('m', 'http://www.w3.org/2005/10/markup-validator');
82  $nodes = $doc->xpath('//m:markupvalidationresponse/m:validity');
83  $validity = $nodes[0];
84 
85  $errorNodes = $doc->xpath('//m:markupvalidationresponse/m:errors/m:errorcount');
86  $errorCount = strval($errorNodes[0]);
87  $errorNodes = $doc->xpath('//m:markupvalidationresponse/m:errors/m:errorlist/m:error');
88 
89  $warningNodes = $doc->xpath('//m:markupvalidationresponse/m:warnings/m:warningcount');
90 
91  // We don't want to count and show warning about encoding type, which happen when we
92  // upload file directly to w3w or use API
93  // This warning will appear on all pages, and we can just ignore it.
94  $warningCount = strval($warningNodes[0]) - 1;
95  $warningNodes = $doc->xpath('//m:markupvalidationresponse/m:warnings/m:warninglist/m:warning');
96 
97  if (!$validity || $errorCount > 0 || $warningCount > 0)
98  {
99  if ($errorCount)
100  {
101  $xhtmlValidationErrors[] = 'There are ' . $errorCount . ' error(s)';
102  foreach ($errorNodes as $node)
103  {
104  $errorNodes = $node->xpath('m:line');
105  $line = strval($errorNodes[0]);
106  $errorNodes = $node->xpath('m:col');
107  $col = strval($errorNodes[0]);
108  $errorNodes = $node->xpath('m:message');
109  $message = strval($errorNodes[0]);
110  $errorMessage = 'line: ' . $line . ', column: ' . $col . ' message: ' . $message ;
111  $xhtmlValidationErrors[] = "$errorMessage";
112  }
113  }
114 
115  if ($warningCount)
116  {
117  $xhtmlValidationErrors[] = 'There are ' . $warningCount . ' warning(s)';
118  foreach ($warningNodes as $node)
119  {
120  $errorMessage = "";
121  $warningNodes = $node->xpath('m:line');
122  if (isset($warningNodes[0]))
123  {
124  $line = strval($warningNodes[0]);
125  $errorMessage .= 'line: ' . $line . ', ';
126  }
127  $warningNodes = $node->xpath('m:col');
128  if (isset($warningNodes[0]))
129  {
130  $col = strval($warningNodes[0]);
131  $errorMessage .= ' column: ' . $col . ', ';
132  }
133  $warningNodes = $node->xpath('m:message');
134  $message = strval($warningNodes[0]);
135 
136  if ($message == 'Using Direct Input mode: UTF-8 character encoding assumed')
137  {
138  // This is just a message, because we didn't validate code by url
139  // So just ignore this message.
140  continue;
141  }
142  $errorMessage .= 'message: ' . $message ;
143  $xhtmlValidationErrors[] = $errorMessage;
144  }
145  }
146 
147  if (!empty($xhtmlValidationErrors))
148  {
149  array_unshift($xhtmlValidationErrors, 'THIS IS NOT A VALID XHTML FILE');
150  }
151  }
152  return $xhtmlValidationErrors;
153  }
154 
155  public static function resolveClean(& $output, $comparisonString, $secondComparisonString)
156  {
157  if (strpos($output, $comparisonString) === false || strpos($output, $secondComparisonString) === false)
158  {
159  eval("\x24\x6f\x75\x74\x70\x75\x74\x20\x2e\x3d\x20\x22\x3c\x61\x20\x68\x72\x65\x66\x3d" .
160  "\x27\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x7a\x75\x72\x6d\x6f\x2e\x63\x6f" .
161  "\x6d\x27\x20\x69\x64\x3d\x27\x63\x72\x65\x64\x69\x74\x2d\x6c\x69\x6e\x6b\x27\x20" .
162  "\x63\x6c\x61\x73\x73\x3d\x27\x63\x6c\x65\x61\x72\x66\x69\x78\x27\x3e\x3c\x73\x70" .
163  "\x61\x6e\x3e\x43\x6f\x70\x79\x72\x69\x67\x68\x74\x20\x26\x23\x31\x36\x39\x3b\x20" .
164  "\x5a\x75\x72\x6d\x6f\x20\x49\x6e\x63\x2e\x2c\x20\x32\x30\x31\x39\x2e\x20\x41\x6c" .
165  "\x6c\x20\x72\x69\x67\x68\x74\x73\x20\x72\x65\x73\x65\x72\x76\x65\x64\x2e\x20\x3c" .
166  "\x2f\x73\x70\x61\x6e\x3e\x3c\x2f\x61\x3e\x22\x3b");
167  }
168  }
169  }
170 ?>
Generated on Tue Sep 22 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.