ui.php

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 1,237 行 · 第 1/3 页

PHP
1,237
字号
<?php
/**
 * The HTML_Progress_UI class provides a basic look and feel
 * implementation of a progress bar.
 *
 * PHP versions 4 and 5
 *
 * LICENSE: This source file is subject to version 3.0 of the PHP license
 * that is available through the world-wide-web at the following URI:
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
 * the PHP License and are unable to obtain it through the web, please
 * send a note to license@php.net so we can mail you a copy immediately.
 *
 * @category   HTML
 * @package    HTML_Progress
 * @subpackage Progress_UI
 * @author     Laurent Laville <pear@laurent-laville.org>
 * @copyright  1997-2005 The PHP Group
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
 * @version    CVS: $Id: UI.php,v 1.8 2005/07/25 13:09:30 farell Exp $
 * @link       http://pear.php.net/package/HTML_Progress
 */

require_once 'HTML/Common.php';

/**
 * The HTML_Progress_UI class provides a basic look and feel
 * implementation of a progress bar.
 *
 * PHP versions 4 and 5
 *
 * LICENSE: This source file is subject to version 3.0 of the PHP license
 * that is available through the world-wide-web at the following URI:
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
 * the PHP License and are unable to obtain it through the web, please
 * send a note to license@php.net so we can mail you a copy immediately.
 *
 * @category   HTML
 * @package    HTML_Progress
 * @subpackage Progress_UI
 * @author     Laurent Laville <pear@laurent-laville.org>
 * @copyright  1997-2005 The PHP Group
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
 * @version    Release: @package_version@
 * @link       http://pear.php.net/package/HTML_Progress2
 */

class HTML_Progress_UI extends HTML_Common
{
    /**
     * Whether the progress bar is horizontal, vertical, polygonal or circle.
     * The default is horizontal.
     *
     * @var        integer
     * @since      1.0
     * @access     private
     * @see        getOrientation(), setOrientation()
     */
    var $_orientation;

    /**
     * Whether the progress bar is filled in 'natural' or 'reverse' way.
     * The default fill way is 'natural'.
     *
     * <ul>
     * <li>since 0.5 : 'way'  =  bar fill way
     *   <ul>
     *     <li>with Progress Bar Horizontal,
     *              natural way is : left to right
     *        <br />reverse way is : right to left
     *     <li>with Progress Bar Vertical,
     *              natural way is : down to up
     *        <br />reverse way is : up to down
     *     <li>with Progress Circle or Polygonal,
     *              natural way is : clockwise
     *        <br />reverse way is : anticlockwise
     *   </ul>
     * </ul>
     *
     * @var        string
     * @since      1.0
     * @access     private
     * @see        getFillWay(), setFillWay()
     */
    var $_fillWay;

    /**
     * The cell count of the progress bar. The default is 10.
     *
     * @var        integer
     * @since      1.0
     * @access     private
     * @see        getCellCount(), setCellCount()
     */
    var $_cellCount;

    /**
     * The cell coordinates for a progress polygonal shape.
     *
     * @var        array
     * @since      1.2.0
     * @access     private
     * @see        getCellCoordinates(), setCellCoordinates()
     */
    var $_coordinates;

    /**
     * The width of grid in cell-size of the polygonal shape.
     *
     * @var        integer
     * @since      1.2.0
     * @access     private
     * @see        getCellCoordinates(), setCellCoordinates()
     */
    var $_xgrid;

    /**
     * The height of grid in cell-size of the polygonal shape.
     *
     * @var        integer
     * @since      1.2.0
     * @access     private
     * @see        getCellCoordinates(), setCellCoordinates()
     */
    var $_ygrid;

    /**
     * The progress bar's structure
     *
     * <ul>
     * <li>['cell']
     *     <ul>
     *     <li>since 1.0 : 'id'             =  cell identifier mask
     *     <li>since 1.0 : 'class'          =  css class selector
     *     <li>since 0.1 : 'width'          =  cell width
     *     <li>since 0.1 : 'height'         =  cell height
     *     <li>since 0.1 : 'active-color'   =  active color
     *     <li>since 0.1 : 'inactive-color' =  inactive color
     *     <li>since 0.1 : 'spacing'        =  cell spacing
     *     <li>since 0.6 : 'color'          =  foreground color
     *     <li>since 0.6 : 'font-size'      =  font size
     *     <li>since 0.6 : 'font-family'    =  font family
     *     <li>since 1.2 : 'background-color' = background color
     *     </ul>
     * <li>['border']
     *     <ul>
     *     <li>since 1.0 : 'class'  =  css class selector
     *     <li>since 0.1 : 'width'  =  border width
     *     <li>since 0.1 : 'style'  =  border style
     *     <li>since 0.1 : 'color'  =  border color
     *     </ul>
     * <li>['string']
     *     <ul>
     *     <li>sicne 1.0 : 'id'                =  string identifier
     *     <li>since 0.6 : 'width'             =  with of progress string
     *     <li>since 0.6 : 'height'            =  height of progress string
     *     <li>since 0.1 : 'font-family'       =  font family
     *     <li>since 0.1 : 'font-size'         =  font size
     *     <li>since 0.1 : 'color'             =  font color
     *     <li>since 0.6 : 'background-color'  =  background color
     *     <li>since 0.6 : 'align'             =  horizontal align  (left, center, right, justify)
     *     <li>since 0.6 : 'valign'            =  vertical align  (top, bottom, left, right)
     *     </ul>
     * <li>['progress']
     *     <ul>
     *     <li>since 1.0 : 'class'             =  css class selector
     *     <li>since 0.1 : 'background-color'  =  bar background color
     *     <li>since 1.0 : 'auto-size'         = compute best progress size
     *     <li>since 0.1 : 'width'             =  bar width
     *     <li>since 0.1 : 'height'            =  bar height
     *     </ul>
     * </ul>
     *
     * @var        array
     * @since      1.0
     * @access     private
     * @see        HTML_Progress::toArray()
     */
    var $_progress = array();

    /**
     * External Javascript file to override internal default code
     *
     * @var        string
     * @since      1.0
     * @access     private
     * @see        getScript(), setScript()
     */
    var $_script;


    /**
     * The progress bar's UI model class constructor
     *
     * Constructor Summary
     *
     * o Creates a natural horizontal progress bar that displays ten cells/units.
     *   <code>
     *   $html = new HTML_Progress_UI();
     *   </code>
     *
     * o Creates a natural horizontal progress bar with the specified cell count,
     *   which cannot be less than 1 (minimum), but has no maximum limit.
     *   <code>
     *   $html = new HTML_Progress_UI($cell);
     *   </code>
     *
     * @param      int       $cell          (optional) Cell count
     *
     * @since      1.0
     * @access     public
     * @throws     HTML_PROGRESS_ERROR_INVALID_INPUT
     */
    function HTML_Progress_UI()
    {
        // if you've not yet created an instance of html_progress
        if (!$GLOBALS['_HTML_PROGRESS_CALLBACK_ERRORHANDLER']) {
            // init default error handling system,
            HTML_Progress::_initErrorHandler();
        }

        $args = func_get_args();

        switch (count($args)) {
         case 1:
            /*   int cell  */
            if (!is_int($args[0])) {
                return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
                    array('var' => '$cell',
                          'was' => $args[0],
                          'expected' => 'integer',
                          'paramnum' => 1));

            } elseif ($args[0] < 1) {
                return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
                    array('var' => '$cell',
                          'was' => $args[0],
                          'expected' => 'greater or equal 1',
                          'paramnum' => 1));
            }
            $this->_cellCount = $args[0];
            break;
         default:
            $this->_cellCount = 10;
            break;
        }
        $this->_orientation = HTML_PROGRESS_BAR_HORIZONTAL;
        $this->_fillWay = 'natural';
        $this->_script = null;              // uses internal javascript code

        $this->_progress = array(
            'cell' =>
                array(
                    'id' => "progressCell%01s",
                    'class' => "cell",
                    'active-color' => "#006600",
                    'inactive-color' => "#CCCCCC",
                    'font-family' => "Courier, Verdana",
                    'font-size' => 8,
                    'color' => "#000000",
                    'background-color' => "#FFFFFF",
                    'width' => 15,
                    'height' => 20,
                    'spacing' => 2
                ),
            'border' =>
                array(
                    'class' => "progressBarBorder",
                    'width' => 0,
                    'style' => "solid",
                    'color' => "#000000"
                ),
            'string' =>
                array(
                    'id' => "installationProgress",
                    'width' => 50,
                    'font-family' => "Verdana, Arial, Helvetica, sans-serif",
                    'font-size' => 12,
                    'color' => "#000000",
                    'background-color' => "#FFFFFF",
                    'align' => "right",
                    'valign' => "right"
                ),
            'progress' =>
                array(
                    'class' => "progressBar",
                    'background-color' => "#FFFFFF",
                    'auto-size' => true
                )
        );
        $this->_updateProgressSize();   // updates the new size of progress bar
    }

    /**
     * Returns HTML_PROGRESS_BAR_HORIZONTAL or HTML_PROGRESS_BAR_VERTICAL,
     * depending on the orientation of the progress bar.
     * The default orientation is HTML_PROGRESS_BAR_HORIZONTAL.
     *
     * @return     integer
     * @since      1.0
     * @access     public
     * @see        setOrientation()
     * @tutorial   ui.getorientation.pkg
     */
    function getOrientation()
    {
        return $this->_orientation;
    }

    /**
     * Sets the progress bar's orientation, which must be HTML_PROGRESS_BAR_HORIZONTAL
     * or HTML_PROGRESS_BAR_VERTICAL.
     * The default orientation is HTML_PROGRESS_BAR_HORIZONTAL.
     *
     * @param      integer   $orient        Orientation (horizontal or vertical)
     *
     * @return     void
     * @since      1.0
     * @access     public
     * @throws     HTML_PROGRESS_ERROR_INVALID_INPUT
     * @see        getOrientation()
     * @tutorial   ui.setorientation.pkg
     */
    function setOrientation($orient)
    {
        if (!is_int($orient)) {
            return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
                array('var' => '$orient',
                      'was' => gettype($orient),
                      'expected' => 'integer',
                      'paramnum' => 1));

        } elseif (($orient != HTML_PROGRESS_BAR_HORIZONTAL) &&
                  ($orient != HTML_PROGRESS_BAR_VERTICAL) &&
                  ($orient != HTML_PROGRESS_POLYGONAL) &&
                  ($orient != HTML_PROGRESS_CIRCLE)) {
            return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
                array('var' => '$orient',
                      'was' => $orient,
                      'expected' => HTML_PROGRESS_BAR_HORIZONTAL.' | '.
                                    HTML_PROGRESS_BAR_VERTICAL.' | '.
                                    HTML_PROGRESS_POLYGONAL.' | '.
                                    HTML_PROGRESS_CIRCLE,
                      'paramnum' => 1));
        }

        $previous = $this->_orientation;    // gets previous orientation
        $this->_orientation = $orient;      // sets the new orientation

        if ($previous != $orient) {
            // if orientation has changed, we need to swap cell width and height
            $w = $this->_progress['cell']['width'];
            $h = $this->_progress['cell']['height'];

            $this->_progress['cell']['width']  = $h;
            $this->_progress['cell']['height'] = $w;

            $this->_updateProgressSize();   // updates the new size of progress bar
        }
    }

    /**
     * Returns 'natural' or 'reverse', depending of the fill way of progress bar.
     * For horizontal progress bar, natural way is from left to right, and reverse
     * way is from right to left.
     * For vertical progress bar, natural way is from down to up, and reverse
     * way is from up to down.
     * The default fill way is 'natural'.
     *
     * @return     string
     * @since      1.0
     * @access     public
     * @see        setFillWay()
     * @tutorial   ui.getfillway.pkg
     */
    function getFillWay()
    {
        return $this->_fillWay;
    }

    /**
     * Sets the progress bar's fill way, which must be 'natural' or 'reverse'.
     * The default fill way is 'natural'.
     *
     * @param      string    $way           fill direction (natural or reverse)
     *
     * @return     void
     * @since      1.0
     * @access     public
     * @throws     HTML_PROGRESS_ERROR_INVALID_INPUT
     * @see        getFillWay()
     * @tutorial   ui.setfillway.pkg
     */
    function setFillWay($way)
    {
        if (!is_string($way)) {
            return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
                array('var' => '$way',
                      'was' => gettype($way),
                      'expected' => 'string',
                      'paramnum' => 1));

        } elseif ((strtolower($way) != 'natural') && (strtolower($way) != 'reverse')) {
            return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
                array('var' => '$way',
                      'was' => $way,
                      'expected' => 'natural | reverse',
                      'paramnum' => 1));
        }
        $this->_fillWay = strtolower($way);
    }

    /**

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?