⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 browser.php

📁 PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。
💻 PHP
📖 第 1 页 / 共 3 页
字号:
    }

    /**
     *    Accessor for raw page information.
     *    @return string      Original text content of web page.
     *    @access public
     */
    function getContent() {
        return $this->_page->getRaw();
    }

    /**
     *    Accessor for plain text version of the page.
     *    @return string      Normalised text representation.
     *    @access public
     */
    function getContentAsText() {
        return $this->_page->getText();
    }

    /**
     *    Accessor for parsed title.
     *    @return string     Title or false if no title is present.
     *    @access public
     */
    function getTitle() {
        return $this->_page->getTitle();
    }

    /**
     *    Accessor for a list of all links in current page.
     *    @return array   List of urls with scheme of
     *                    http or https and hostname.
     *    @access public
     */
    function getUrls() {
        return $this->_page->getUrls();
    }

    /**
     *    Sets all form fields with that name.
     *    @param string $label   Name or label of field in forms.
     *    @param string $value   New value of field.
     *    @return boolean        True if field exists, otherwise false.
     *    @access public
     */
    function setField($label, $value, $position=false) {
        return $this->_page->setField(new SimpleByLabelOrName($label), $value, $position);
    }

    /**
     *    Sets all form fields with that name. Will use label if
     *    one is available (not yet implemented).
     *    @param string $name    Name of field in forms.
     *    @param string $value   New value of field.
     *    @return boolean        True if field exists, otherwise false.
     *    @access public
     */
    function setFieldByName($name, $value, $position=false) {
        return $this->_page->setField(new SimpleByName($name), $value, $position);
    }

    /**
     *    Sets all form fields with that id attribute.
     *    @param string/integer $id   Id of field in forms.
     *    @param string $value        New value of field.
     *    @return boolean             True if field exists, otherwise false.
     *    @access public
     */
    function setFieldById($id, $value) {
        return $this->_page->setField(new SimpleById($id), $value);
    }

    /**
     *    Accessor for a form element value within the page.
     *    Finds the first match.
     *    @param string $label       Field label.
     *    @return string/boolean     A value if the field is
     *                               present, false if unchecked
     *                               and null if missing.
     *    @access public
     */
    function getField($label) {
        return $this->_page->getField(new SimpleByLabelOrName($label));
    }

    /**
     *    Accessor for a form element value within the page.
     *    Finds the first match.
     *    @param string $name        Field name.
     *    @return string/boolean     A string if the field is
     *                               present, false if unchecked
     *                               and null if missing.
     *    @access public
     */
    function getFieldByName($name) {
        return $this->_page->getField(new SimpleByName($name));
    }

    /**
     *    Accessor for a form element value within the page.
     *    @param string/integer $id  Id of field in forms.
     *    @return string/boolean     A string if the field is
     *                               present, false if unchecked
     *                               and null if missing.
     *    @access public
     */
    function getFieldById($id) {
        return $this->_page->getField(new SimpleById($id));
    }

    /**
     *    Clicks the submit button by label. The owning
     *    form will be submitted by this.
     *    @param string $label    Button label. An unlabeled
     *                            button can be triggered by 'Submit'.
     *    @param hash $additional Additional form data.
     *    @return string/boolean  Page on success.
     *    @access public
     */
    function clickSubmit($label = 'Submit', $additional = false) {
        if (! ($form = &$this->_page->getFormBySubmit(new SimpleByLabel($label)))) {
            return false;
        }
        $success = $this->_load(
                $form->getAction(),
                $form->submitButton(new SimpleByLabel($label), $additional));
        return ($success ? $this->getContent() : $success);
    }

    /**
     *    Clicks the submit button by name attribute. The owning
     *    form will be submitted by this.
     *    @param string $name     Button name.
     *    @param hash $additional Additional form data.
     *    @return string/boolean  Page on success.
     *    @access public
     */
    function clickSubmitByName($name, $additional = false) {
        if (! ($form = &$this->_page->getFormBySubmit(new SimpleByName($name)))) {
            return false;
        }
        $success = $this->_load(
                $form->getAction(),
                $form->submitButton(new SimpleByName($name), $additional));
        return ($success ? $this->getContent() : $success);
    }

    /**
     *    Clicks the submit button by ID attribute of the button
     *    itself. The owning form will be submitted by this.
     *    @param string $id       Button ID.
     *    @param hash $additional Additional form data.
     *    @return string/boolean  Page on success.
     *    @access public
     */
    function clickSubmitById($id, $additional = false) {
        if (! ($form = &$this->_page->getFormBySubmit(new SimpleById($id)))) {
            return false;
        }
        $success = $this->_load(
                $form->getAction(),
                $form->submitButton(new SimpleById($id), $additional));
        return ($success ? $this->getContent() : $success);
    }
    
    /**
     *    Tests to see if a submit button exists with this
     *    label.
     *    @param string $label    Button label.
     *    @return boolean         True if present.
     *    @access public
     */
    function isSubmit($label) {
        return (boolean)$this->_page->getFormBySubmit(new SimpleByLabel($label));
    }

    /**
     *    Clicks the submit image by some kind of label. Usually
     *    the alt tag or the nearest equivalent. The owning
     *    form will be submitted by this. Clicking outside of
     *    the boundary of the coordinates will result in
     *    a failure.
     *    @param string $label    ID attribute of button.
     *    @param integer $x       X-coordinate of imaginary click.
     *    @param integer $y       Y-coordinate of imaginary click.
     *    @param hash $additional Additional form data.
     *    @return string/boolean  Page on success.
     *    @access public
     */
    function clickImage($label, $x = 1, $y = 1, $additional = false) {
        if (! ($form = &$this->_page->getFormByImage(new SimpleByLabel($label)))) {
            return false;
        }
        $success = $this->_load(
                $form->getAction(),
                $form->submitImage(new SimpleByLabel($label), $x, $y, $additional));
        return ($success ? $this->getContent() : $success);
    }

    /**
     *    Clicks the submit image by the name. Usually
     *    the alt tag or the nearest equivalent. The owning
     *    form will be submitted by this. Clicking outside of
     *    the boundary of the coordinates will result in
     *    a failure.
     *    @param string $name     Name attribute of button.
     *    @param integer $x       X-coordinate of imaginary click.
     *    @param integer $y       Y-coordinate of imaginary click.
     *    @param hash $additional Additional form data.
     *    @return string/boolean  Page on success.
     *    @access public
     */
    function clickImageByName($name, $x = 1, $y = 1, $additional = false) {
        if (! ($form = &$this->_page->getFormByImage(new SimpleByName($name)))) {
            return false;
        }
        $success = $this->_load(
                $form->getAction(),
                $form->submitImage(new SimpleByName($name), $x, $y, $additional));
        return ($success ? $this->getContent() : $success);
    }

    /**
     *    Clicks the submit image by ID attribute. The owning
     *    form will be submitted by this. Clicking outside of
     *    the boundary of the coordinates will result in
     *    a failure.
     *    @param integer/string $id    ID attribute of button.
     *    @param integer $x            X-coordinate of imaginary click.
     *    @param integer $y            Y-coordinate of imaginary click.
     *    @param hash $additional      Additional form data.
     *    @return string/boolean       Page on success.
     *    @access public
     */
    function clickImageById($id, $x = 1, $y = 1, $additional = false) {
        if (! ($form = &$this->_page->getFormByImage(new SimpleById($id)))) {
            return false;
        }
        $success = $this->_load(
                $form->getAction(),
                $form->submitImage(new SimpleById($id), $x, $y, $additional));
        return ($success ? $this->getContent() : $success);
    }
    
    /**
     *    Tests to see if an image exists with this
     *    title or alt text.
     *    @param string $label    Image text.
     *    @return boolean         True if present.
     *    @access public
     */
    function isImage($label) {
        return (boolean)$this->_page->getFormByImage(new SimpleByLabel($label));
    }

    /**
     *    Submits a form by the ID.
     *    @param string $id       The form ID. No submit button value
     *                            will be sent.
     *    @return string/boolean  Page on success.
     *    @access public
     */
    function submitFormById($id) {
        if (! ($form = &$this->_page->getFormById($id))) {
            return false;
        }
        $success = $this->_load(
                $form->getAction(),
                $form->submit());
        return ($success ? $this->getContent() : $success);
    }

    /**
     *    Finds a URL by label. Will find the first link
     *    found with this link text by default, or a later
     *    one if an index is given. The match ignores case and
     *    white space issues.
     *    @param string $label     Text between the anchor tags.
     *    @param integer $index    Link position counting from zero.
     *    @return string/boolean   URL on success.
     *    @access public
     */
    function getLink($label, $index = 0) {
        $urls = $this->_page->getUrlsByLabel($label);
        if (count($urls) == 0) {
            return false;
        }
        if (count($urls) < $index + 1) {
            return false;
        }
        return $urls[$index];
    }

    /**
     *    Follows a link by label. Will click the first link
     *    found with this link text by default, or a later
     *    one if an index is given. The match ignores case and
     *    white space issues.
     *    @param string $label     Text between the anchor tags.
     *    @param integer $index    Link position counting from zero.
     *    @return string/boolean   Page on success.
     *    @access public
     */
    function clickLink($label, $index = 0) {
        $url = $this->getLink($label, $index);
        if ($url === false) {
            return false;
        }
        $this->_load($url, new SimpleGetEncoding());
        return $this->getContent();
    }
    
    /**
     *    Finds a link by id attribute.
     *    @param string $id        ID attribute value.
     *    @return string/boolean   URL on success.
     *    @access public
     */
    function getLinkById($id) {
        return $this->_page->getUrlById($id);
    }

    /**
     *    Follows a link by id attribute.
     *    @param string $id        ID attribute value.
     *    @return string/boolean   Page on success.
     *    @access public
     */
    function clickLinkById($id) {
        if (! ($url = $this->getLinkById($id))) {
            return false;
        }
        $this->_load($url, new SimpleGetEncoding());
        return $this->getContent();
    }

    /**
     *    Clicks a visible text item. Will first try buttons,
     *    then links and then images.
     *    @param string $label        Visible text or alt text.
     *    @return string/boolean      Raw page or false.
     *    @access public
     */
    function click($label) {
        $raw = $this->clickSubmit($label);
        if (! $raw) {
            $raw = $this->clickLink($label);
        }
        if (! $raw) {
            $raw = $this->clickImage($label);
        }
        return $raw;
    }

    /**
     *    Tests to see if a click target exists.
     *    @param string $label    Visible text or alt text.
     *    @return boolean         True if target present.
     *    @access public
     */
    function isClickable($label) {
        return $this->isSubmit($label) || ($this->getLink($label) !== false) || $this->isImage($label);
    }
}
?>

⌨️ 快捷键说明

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