<commit_before><?php
/**
 * PHPFrame/Document/HTMLDocument.php
 * 
 * PHP version 5
 * 
 * @category  PHPFrame
 * @package   Document
 * @author    <NAME> <<EMAIL>>
 * @copyright 2009 The PHPFrame Group
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @version   SVN: $Id$
 * @link      http://code.google.com/p/phpframe/source/browse/PHPFrame
 */

/**
 * HTML Document Class
 * 
 * @category PHPFrame
 * @package  Document
 * @author   <NAME> <<EMAIL>>
 * @license  http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @link     http://code.google.com/p/phpframe/source/browse/PHPFrame
 * @see      PHPFrame_Document
 * @since    1.0
 */
class PHPFrame_HTMLDocument extends PHPFrame_XMLDocument
{
    /**
     * An array containing meta tags.
     * 
     * @var array
     */
    private $_meta_tags = array();
    /**
     * An array containing scripts.
     * 
     * @var array
     */
    private $_scripts = array();
    /**
     * An array containing style sheets.
     * 
     * @var array
     */
    private $_style_sheets = array();
    /**
     * If set to TRUE object will only include contents of the body tag. This 
     * is used for AJAX output.
     * 
     * @var bool
     */
    private $_body_only = false;
    
    /**
     * Constructor
     * 
     * @param string $mime    [Optional]
     * @param string $charset [Optional]
     * 
     * @return void
     * @uses   DOMImplementation, PHPFrame_URI, PHPFrame_Pathway
     * @since  1.0 
     */
    public function __construct($mime="text/html", $charset=null) 
    {
        // Call parent's constructor to set mime type
        parent::__construct($mime, $charset);
        
        // Acquire DOM object of HTML type
        $imp = new DOMImplementation;
        $this->dom = $imp->createDocument(
            null,
            "html",
            $this->getDocType()
        ); 
        
        // Get root node
        $html_node = $this->dom->getElementsByTagName("html")->item(0);
        
        // Add head
        $head_node = $this->addNode($html_node, "head");
        // Add body
        $this->addNode($html_node, "body", null, "\n{content}\n");
        
        // Add meta tags
        $this->addMetaTag("generator", "PHPFrame");
        $this->addMetaTag(
            null, 
            $this->getMimeType()."; charset=".$this->getCharset(),
            "Content-Type"
        );
        
        // Add base url
        $uri = new PHPFrame_URI();
        $this->addNode($head_node, "base", array("href"=>$uri->getBase()));
    }
    
    /**
     * Convert object to string
     * 
     * @return string
     * @since  1.0
     */
    public function __toString()
    {
        // If "body only" mode we simply return the body
        if ($this->_body_only) {
           return $this->getBody();
        }
        
        // Add title tag in head node 
        $head_node = $this->dom->getElementsByTagName("head")->item(0);
        $this->addNode($head_node, "title", null, $this->getTitle());
        
        // Add meta tags
        foreach ($this->_meta_tags as $meta_tag) {
            $meta_node = $this->addNode($head_node, "meta");
            
            // Add name attribute if any
            if (!is_null($meta_tag["name"])) {
                $this->addNodeAttr($meta_node, "name", $meta_tag["name"]);
            }
            // Add http_equiv attribute if any
            if (!is_null($meta_tag["http_equiv"])) {
                $this->addNodeAttr($meta_node, "http-equiv", $meta_tag["http_equiv"]);
            }
            
            // Add content attribute
            $this->addNodeAttr($meta_node, "content", $meta_tag["content"]);
        }
        
        // Add scripts
        foreach ($this->_scripts as $script_attr) {
            // Create script tag node
            $this->addNode($head_node, "script", $script_attr);
        }
        
        // Add styles
        foreach ($this->_style_sheets as $style_sheet_attr) {
            $this->addNode($head_node, "link", $style_sheet_attr);
        }
        
        // Render DOM Document as HTML string
        $this->dom->formatOutput = true;
        $html = $this->dom->saveHTML();
        
        // Add body and return
        return str_replace("{content}", $this->getBody(), $html);<commit_msg>Minor tweak to HTMLDocument for prettier output.<commit_after><?php
/**
 * PHPFrame/Document/HTMLDocument.php
 * 
 * PHP version 5
 * 
 * @category  PHPFrame
 * @package   Document
 * @author    <NAME> <<EMAIL>>
 * @copyright 2009 The PHPFrame Group
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @version   SVN: $Id$
 * @link      http://code.google.com/p/phpframe/source/browse/PHPFrame
 */

/**
 * HTML Document Class
 * 
 * @category PHPFrame
 * @package  Document
 * @author   <NAME> <<EMAIL>>
 * @license  http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @link     http://code.google.com/p/phpframe/source/browse/PHPFrame
 * @see      PHPFrame_Document
 * @since    1.0
 */
class PHPFrame_HTMLDocument extends PHPFrame_XMLDocument
{
    /**
     * An array containing meta tags.
     * 
     * @var array
     */
    private $_meta_tags = array();
    /**
     * An array containing scripts.
     * 
     * @var array
     */
    private $_scripts = array();
    /**
     * An array containing style sheets.
     * 
     * @var array
     */
    private $_style_sheets = array();
    /**
     * If set to TRUE object will only include contents of the body tag. This 
     * is used for AJAX output.
     * 
     * @var bool
     */
    private $_body_only = false;
    
    /**
     * Constructor
     * 
     * @param string $mime    [Optional]
     * @param string $charset [Optional]
     * 
     * @return void
     * @uses   DOMImplementation, PHPFrame_URI, PHPFrame_Pathway
     * @since  1.0 
     */
    public function __construct($mime="text/html", $charset=null) 
    {
        // Call parent's constructor to set mime type
        parent::__construct($mime, $charset);
        
        // Acquire DOM object of HTML type
        $imp = new DOMImplementation;
        $this->dom = $imp->createDocument(
            null,
            "html",
            $this->getDocType()
        ); 
        
        // Get root node
        $html_node = $this->dom->getElementsByTagName("html")->item(0);
        
        // Add head
        $head_node = $this->addNode($html_node, "head");
        // Add body
        $this->addNode($html_node, "body", null, "\n{content}\n");
        
        // Add meta tags
        $this->addMetaTag("generator", "PHPFrame");
        $this->addMetaTag(
            null, 
            $this->getMimeType()."; charset=".$this->getCharset(),
            "Content-Type"
        );
        
        // Add base url
        $uri = new PHPFrame_URI();
        $this->addNode($head_node, "base", array("href"=>$uri->getBase()));
    }
    
    /**
     * Convert object to string
     * 
     * @return string
     * @since  1.0
     */
    public function __toString()
    {
        // If "body only" mode we simply return the body
        if ($this->_body_only) {
           return $this->getBody();
        }
        
        // Add title tag in head node 
        $head_node = $this->dom->getElementsByTagName("head")->item(0);
        $this->addNode($head_node, "title", null, $this->getTitle());
        
        // Add meta tags
        foreach ($this->_meta_tags as $meta_tag) {
            $meta_node = $this->addNode($head_node, "meta");
            
            // Add name attribute if any
            if (!is_null($meta_tag["name"])) {
                $this->addNodeAttr($meta_node, "name", $meta_tag["name"]);
            }
            // Add http_equiv attribute if any
            if (!is_null($meta_tag["http_equiv"])) {
                $this->addNodeAttr($meta_node, "http-equiv", $meta_tag["http_equiv"]);
            }
            
            // Add content attribute
            $this->addNodeAttr($meta_node, "content", $meta_tag["content"]);
        }
        
        // Add scripts
        foreach ($this->_scripts as $script_attr) {
            // Create script tag node
            $this->addNode($head_node, "script", $script_attr);
        }
        
        // Add styles
        foreach ($this->_style_sheets as $style_sheet_attr) {
            $this->addNode($head_node, "link", $style_sheet_attr);
        }
        
        // Render DOM Document as HTML string
        $this->dom->formatOutput = true;
        $html = $this->dom->saveHTML();
        
        // Make line breaks after script tags for pretty output
        $html = preg_replace("/<\/script>/", "</script>\n", $html);
        
        // Add body and return
        return str_replace("{content}", $this->getBody(), $html);
{'fraction_non_alphanumeric': 0.14106618477524283, 'fraction_numerical': 0.0029365258640162636, 'mean_word_length': 1.820063694267516, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4654463', 'n_tokens_mistral': 2668, 'n_tokens_neox': 2598, 'n_words': 610}