progress.php

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

PHP
1,872
字号
     *   <code>
     *   $bar = new HTML_Progress($model);
     *   </code>
     *
     *
     * @param      object    $model         (optional) Model that hold the progress bar's data
     * @param      int       $orient        (optional) Orientation of progress bar
     * @param      int       $min           (optional) Minimum value of progress bar
     * @param      int       $max           (optional) Maximum value of progress bar
     * @param      array     $errorPrefs    (optional) Always last argument of class constructor.
     *                                       hash of params to configure PEAR_ErrorStack and loggers
     *
     * @since      1.0
     * @access     public
     * @throws     HTML_PROGRESS_ERROR_INVALID_INPUT
     * @see        setIndeterminate(),
     *             setBorderPainted(), setStringPainted(), setString(),
     *             setDM(), setUI(), setIdent()
     */
    function HTML_Progress()
    {
        $args = func_get_args();
        $num_args = func_num_args();

        if ($num_args > 0) {
            $errorPrefs = func_get_arg($num_args - 1);
            if (!is_array($errorPrefs)) {
                $errorPrefs = array();
            } else {
                $num_args--;
            }
            HTML_Progress::_initErrorHandler($errorPrefs);
        } else {
            HTML_Progress::_initErrorhandler();
        }

        $this->_listeners = array();          // none listeners by default

        $this->_DM = new HTML_Progress_DM();  // new instance of a progress DataModel
        $this->_UI = new HTML_Progress_UI();  // new instance of a progress UserInterface

        switch ($num_args) {
         case 1:
            if (is_object($args[0]) && (is_a($args[0], 'html_progress_dm'))) {
                /*   object html_progress_dm extends   */
                $this->_DM = &$args[0];

            } elseif (is_int($args[0])) {
                /*   int orient   */
                $this->_UI->setOrientation($args[0]);

            } else {
                return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
                    array('var' => '$model | $orient',
                          'was' => (gettype($args[0]) == 'object') ?
                                    get_class($args[0]).' object' : gettype($args[0]),
                          'expected' => 'html_progress_dm object | integer',
                          'paramnum' => 1));
            }
            break;
         case 2:
            /*   int min, int max   */
            if (!is_int($args[0])) {
                return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
                    array('var' => '$min',
                          'was' => $args[0],
                          'expected' => 'integer',
                          'paramnum' => 1));

            } elseif (!is_int($args[1])) {
                return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
                    array('var' => '$max',
                          'was' => $args[1],
                          'expected' => 'integer',
                          'paramnum' => 2));
            } else {
                $this->_DM->setMinimum($args[0]);
                $this->_DM->setMaximum($args[1]);
            }
            break;
         case 3:
            /*   int orient, int min, int max   */
            if (!is_int($args[0])) {
                return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
                    array('var' => '$orient',
                          'was' => $args[0],
                          'expected' => 'integer',
                          'paramnum' => 1));

            } elseif (!is_int($args[1])) {
                return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
                    array('var' => '$min',
                          'was' => $args[1],
                          'expected' => 'integer',
                          'paramnum' => 2));

            } elseif (!is_int($args[2])) {
                return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
                    array('var' => '$max',
                          'was' => $args[2],
                          'expected' => 'integer',
                          'paramnum' => 3));
            } else {
                $this->_UI->setOrientation($args[0]);
                $this->_DM->setMinimum($args[1]);
                $this->_DM->setMaximum($args[2]);
            }
            break;
         default:
        }
        $this->setString(null);
        $this->setStringPainted(false);
        $this->setBorderPainted(false);
        $this->setIndeterminate(false);
        $this->setIdent();
        $this->setAnimSpeed(0);

        // to fix a potential php config problem with PHP 4.2.0 : turn 'implicit_flush' ON
        ob_implicit_flush(1);
    }

    /**
     * Returns the current API version
     *
     * @return     float
     * @since      0.1
     * @access     public
     */
    function apiVersion()
    {
        return 1.2;
    }

    /**
     * Returns mode of the progress bar (determinate or not).
     *
     * @return     boolean
     * @since      1.0
     * @access     public
     * @see        setIndeterminate()
     * @tutorial   progress.isindeterminate.pkg
     */
    function isIndeterminate()
    {
        return $this->_indeterminate;
    }

    /**
     * Sets the $_indeterminate property of the progress bar, which determines
     * whether the progress bar is in determinate or indeterminate mode.
     * An indeterminate progress bar continuously displays animation indicating
     * that an operation of unknown length is occuring.
     * By default, this property is false.
     *
     * @param      boolean   $continuous    whether countinuously displays animation
     *
     * @return     void
     * @since      1.0
     * @access     public
     * @throws     HTML_PROGRESS_ERROR_INVALID_INPUT
     * @see        isIndeterminate()
     * @tutorial   progress.setindeterminate.pkg
     */
    function setIndeterminate($continuous)
    {
        if (!is_bool($continuous)) {
            return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
                array('var' => '$continuous',
                      'was' => gettype($continuous),
                      'expected' => 'boolean',
                      'paramnum' => 1));
        }
        $this->_indeterminate = $continuous;
    }

    /**
     * Determines whether the progress bar border is painted or not.
     * The default is false.
     *
     * @return     boolean
     * @since      1.0
     * @access     public
     * @see        setBorderPainted()
     * @tutorial   progress.isborderpainted.pkg
     */
    function isBorderPainted()
    {
        return $this->_paintBorder;
    }

    /**
     * Sets the value of $_paintBorder property, which determines whether the
     * progress bar should paint its border. The default is false.
     *
     * @param      boolean   $paint         whether the progress bar should paint its border
     *
     * @return     void
     * @since      1.0
     * @access     public
     * @throws     HTML_PROGRESS_ERROR_INVALID_INPUT
     * @see        isBorderPainted()
     * @tutorial   progress.setborderpainted.pkg
     */
    function setBorderPainted($paint)
    {
        if (!is_bool($paint)) {
            return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
                array('var' => '$paint',
                      'was' => gettype($paint),
                      'expected' => 'boolean',
                      'paramnum' => 1));
        }

        $this->_paintBorder = $paint;
    }

    /**
     * Determines whether the progress bar string is painted or not.
     * The default is false.
     * The progress bar displays the value returned by getPercentComplete() method
     * formatted as a percent such as 33%.
     *
     * @return     boolean
     * @since      1.0
     * @access     public
     * @see        setStringPainted(), setString()
     * @tutorial   progress.isstringpainted.pkg
     */
    function isStringPainted()
    {
        return $this->_paintString;
    }

    /**
     * Sets the value of $_paintString property, which determines whether the
     * progress bar should render a progress string. The default is false.
     *
     * @param      boolean   $paint         whether the progress bar should render a string
     *
     * @return     void
     * @since      1.0
     * @access     public
     * @throws     HTML_PROGRESS_ERROR_INVALID_INPUT
     * @see        isStringPainted(), setString()
     * @tutorial   progress.setstringpainted.pkg
     */
    function setStringPainted($paint)
    {
        if (!is_bool($paint)) {
            return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
                array('var' => '$paint',
                      'was' => gettype($paint),
                      'expected' => 'boolean',
                      'paramnum' => 1));
        }
        $this->_paintString = $paint;
    }

    /**
     * Returns the current value of the progress string.
     * By default, the progress bar displays the value returned by
     * getPercentComplete() method formatted as a percent such as 33%.
     *
     * @return     string
     * @since      1.0
     * @access     public
     * @see        setString(), isStringPainted()
     * @tutorial   progress.getstring.pkg
     */
    function getString()
    {
        if ($this->isStringPainted() && !is_null($this->_progressString)) {
            return $this->_progressString;
        } else {
            return sprintf("%s", $this->getPercentComplete(false)).' %';
        }
    }

    /**
     * Sets the current value of the progress string. By default, this string
     * is null. If you have provided a custom progress string and want to revert
     * to the built-in-behavior, set the string back to null.
     * The progress string is painted only if the isStringPainted() method
     * returns true.
     *
     * @param      string    $str           progress string
     *
     * @return     void
     * @since      1.0
     * @access     public
     * @see        getString(), isStringPainted(), setStringPainted()
     * @tutorial   progress.setstring.pkg
     */
    function setString($str)
    {
        $this->_progressString = $str;
    }

    /**
     * Returns the data model used by this progress bar.
     *
     * @return     object
     * @since      1.0
     * @access     public
     * @see        setDM()
     */
    function &getDM()
    {
        return $this->_DM;
    }

    /**
     * Sets the data model used by this progress bar.
     *
     * @param      string    $model         class name of a html_progress_dm extends object
     *
     * @return     void
     * @since      1.0
     * @access     public
     * @throws     HTML_PROGRESS_ERROR_INVALID_INPUT
     * @see        getDM()
     */
    function setDM($model)
    {
        if (!class_exists($model)) {
            return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
                array('var' => '$model',
                      'was' => 'class does not exists',
                      'expected' => $model.' class defined',
                      'paramnum' => 1));
        }

        $_dm = new $model();

        if (!is_a($_dm, 'html_progress_dm')) {
            return HTML_Progress::raiseError(HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
                array('var' => '$model',
                      'was' => $model,
                      'expected' => 'HTML_Progress_DM extends',
                      'paramnum' => 1));
        }
        $this->_DM =& $_dm;
    }

    /**
     * Returns the progress bar's minimum value stored in the progress bar's data model.
     * The default value is 0.
     *
     * @return     integer
     * @since      1.0
     * @access     public
     * @see        setMinimum(),
     *             HTML_Progress_DM::getMinimum()
     * @tutorial   dm.getminimum.pkg
     */
    function getMinimum()
    {
        return $this->_DM->getMinimum();
    }

    /**
     * Sets the progress bar's minimum value stored in the progress bar's data model.
     * If the minimum value is different from previous minimum, all change listeners
     * are notified.
     *
     * @param      integer   $min           progress bar's minimal value
     *
     * @return     void
     * @since      1.0
     * @access     public
     * @see        getMinimum(),
     *             HTML_Progress_DM::setMinimum()
     * @tutorial   dm.setminimum.pkg
     */
    function setMinimum($min)

⌨️ 快捷键说明

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