コード例 #1
0
ファイル: CSS.php プロジェクト: altesien/FinalProject
 /**
  * Validate a CSS data source
  *
  * Execute the W3C CSS validator service on each data source (filename
  * or string) given by parameter $styles.
  *
  * @param array $styles    Data sources to check validity
  * @param array &$messages Error and Warning messages
  *                         issue from W3C CSS validator service
  *
  * @return     boolean|PEAR_Error
  * @since      version 1.5.0 (2008-01-15)
  * @access     public
  * @throws     HTML_CSS_ERROR_INVALID_INPUT,
  *             HTML_CSS_ERROR_INVALID_DEPS, HTML_CSS_ERROR_INVALID_SOURCE
  */
 function validate($styles, &$messages)
 {
     $php = phpversion();
     if (version_compare($php, '5.0.0', '<')) {
         return $this->raiseError(HTML_CSS_ERROR_INVALID_DEPS, 'exception', array('funcname' => __FUNCTION__, 'dependency' => 'PHP 5', 'currentdep' => "PHP {$php}"));
     }
     @(include_once 'Services/W3C/CSSValidator.php');
     if (class_exists('Services_W3C_CSSValidator', false) === false) {
         return $this->raiseError(HTML_CSS_ERROR_INVALID_DEPS, 'exception', array('funcname' => __FUNCTION__, 'dependency' => 'PEAR::Services_W3C_CSSValidator', 'currentdep' => 'nothing'));
     }
     if (!is_array($styles)) {
         return $this->raiseError(HTML_CSS_ERROR_INVALID_INPUT, 'exception', array('var' => '$styles', 'was' => gettype($styles), 'expected' => 'array', 'paramnum' => 1));
     } elseif (!is_array($messages)) {
         return $this->raiseError(HTML_CSS_ERROR_INVALID_INPUT, 'exception', array('var' => '$messages', 'was' => gettype($messages), 'expected' => 'array', 'paramnum' => 2));
     }
     // prepare to call the W3C CSS validator service
     $v = new Services_W3C_CSSValidator();
     $validity = true;
     $messages = array('errors' => array(), 'warnings' => array());
     foreach ($styles as $i => $source) {
         if (!is_string($source)) {
             return $this->raiseError(HTML_CSS_ERROR_INVALID_INPUT, 'exception', array('var' => '$styles[' . $i . ']', 'was' => gettype($styles[$i]), 'expected' => 'string', 'paramnum' => 1));
         }
         if (strcasecmp(substr($source, -4, 4), '.css') == 0) {
             // validate a file as CSS content
             $r = $v->validateFile($source);
         } else {
             // validate a string as CSS content
             $r = $v->validateFragment($source);
         }
         if ($r === false) {
             $validity = false;
         }
         if ($r->isValid() === false) {
             $validity = false;
             foreach ($r->errors as $error) {
                 $properties = get_object_vars($error);
                 $messages['errors'][] = $properties;
             }
             foreach ($r->warnings as $warning) {
                 $properties = get_object_vars($warning);
                 $messages['warnings'][] = $properties;
             }
             $this->raiseError(HTML_CSS_ERROR_INVALID_SOURCE, count($r->errors) == 0 ? 'warning' : 'error', array('sourcenum' => $i, 'errcount' => count($r->errors), 'warncount' => count($r->warnings)));
         }
     }
     return $validity;
 }
コード例 #2
0
<?php

/**
 * Example file to demonstrate validating a URI.
 *
 * PHP version 5
 *
 * @category Web_Services
 * @package  Services_W3C_CSSValidator
 * @author   Laurent Laville <*****@*****.**>
 * @license  http://www.opensource.org/licenses/bsd-license.php BSD
 * @version  CVS: $Id$
 * @link     http://pear.php.net/package/Services_W3C_CSSValidator
 * @since    File available since Release 0.1.0
 */
error_reporting(E_ALL);
ini_set('display_errors', true);
require_once 'Services/W3C/CSSValidator.php';
$v = new Services_W3C_CSSValidator();
$r = $v->validateUri('http://pear.php.net');
echo '<pre>';
var_dump($r);
echo '</pre>';
コード例 #3
0
<?php

/**
 * Example file demonstrating how to validate a CSS fragment.
 *
 * PHP version 5
 *
 * @category Web_Services
 * @package  Services_W3C_CSSValidator
 * @author   Laurent Laville <*****@*****.**>
 * @license  http://www.opensource.org/licenses/bsd-license.php BSD
 * @version  CVS: $Id$
 * @link     http://pear.php.net/package/Services_W3C_CSSValidator
 * @since    File available since Release 0.1.0
 */
error_reporting(E_ALL);
ini_set('display_errors', true);
require_once 'Services/W3C/CSSValidator.php';
$v = new Services_W3C_CSSValidator();
$r = $v->validateFragment('ul.man-side_top,
ul.man-side_up,
ul.man-side_download {
    margin-top: 0.5e;
    margin-bottom: 0.5em;
    margin-left: 0.7em;
    padding-left: 0.7em;
}');
echo '<pre>';
var_dump($r);
echo '</pre>';
コード例 #4
0
<?php

/**
 * Example file demonstrating how to validate a CSS fragment.
 *
 * PHP version 5
 *
 * @category Web_Services
 * @package  Services_W3C_CSSValidator
 * @author   Laurent Laville <*****@*****.**>
 * @license  http://www.opensource.org/licenses/bsd-license.php BSD
 * @version  CVS: $Id$
 * @link     http://pear.php.net/package/Services_W3C_CSSValidator
 * @since    File available since Release 0.1.0
 */
error_reporting(E_ALL);
ini_set('display_errors', true);
require_once 'Services/W3C/CSSValidator.php';
$v = new Services_W3C_CSSValidator();
$r = $v->validateFragment('@import url("foo.css") screen, print;
@media screen { color: green; background-color: yellow; }
@namespace foo url("http://www.example.com/");
html { height: 100%; }
@charset "UTF-8";
@page thin:first { size: 3in 8in }
@fontdef url("http://www.example.com/sample.pfr");
@font-face { font-family: dreamy; font-weight: bold; }');
echo '<pre>';
var_dump($r);
echo '</pre>';
コード例 #5
0
<?php

/**
 * Example usage of Services_W3C_CSSValidator of validating a local file.
 *
 * PHP version 5
 *
 * @category Web_Services
 * @package  Services_W3C_CSSValidator
 * @author   Laurent Laville <*****@*****.**>
 * @license  http://www.opensource.org/licenses/bsd-license.php BSD
 * @version  CVS: $Id$
 * @link     http://pear.php.net/package/Services_W3C_CSSValidator
 * @since    File available since Release 0.1.0
 */
error_reporting(E_ALL);
ini_set('display_errors', true);
require_once 'Services/W3C/CSSValidator.php';
$v = new Services_W3C_CSSValidator();
$r = $v->validateFile('pear_manual.css');
echo '<pre>';
var_dump($r);
echo '</pre>';