File: DBHTMLHandler.php

package info (click to toggle)
php-doc 20241205~git.dfcbb86%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 70,956 kB
  • sloc: xml: 968,269; php: 23,883; javascript: 671; sh: 177; makefile: 37
file content (115 lines) | stat: -rw-r--r-- 4,386 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
namespace phpdotnet\phd;

class PI_DBHTMLHandler extends PIHandler {
    private $attrs = array(
        "background-color"              => "",
        "bgcolor"                       => "",
        "cellpadding"                   => "",
        "cellspacing"                   => "",
        "class"                         => "",
        "dir"                           => "",
        "filename"                      => "",
        "funcsynopsis-style"            => "",
        "img.src.path"                  => "",
        "label-width"                   => "",
        "linenumbering.everyNth"        => "",
        "linenumbering.separator"       => "",
        "linenumbering.width"           => "",
        "list-presentation"             => "",
        "list-width"                    => "",
        "row-height"                    => "",
        "start"                         => "",
        "stop-chunking"                 => "",
        "table-summary"                 => "",
        "table-width"                   => "",
        "term-presentation"             => "",
        "term-separator"                => "",
        "term-width"                    => "",
        "toc"                           => "",

        //Attributes for <?dbtimestamp
        "format"                        => "",
        "padding"                       => "",
    );

    public function __construct($format) {
        parent::__construct($format);
    }

    public function parse($target, $data) {
        $pattern = "/(?<attr>[\w]+[\w\-\.]*)[\s]*=[\s]*\"(?<value>[^\"]*)\"/";
        preg_match_all($pattern, $data, $matches);
        for ($i = 0; $i < count($matches["attr"]); $i++) {
            $attr = trim($matches["attr"][$i]);
            $value = trim($matches["value"][$i]);
            $this->setAttribute($attr, $value);
        }
        //Hack for stop-chunking
        if ($data == "stop-chunking") {
            $this->setAttribute("stop-chunking", true);
        }
        //Parse <?dbtimestamp
        if ($target == 'dbtimestamp') {
            $this->parseDBTimestamp();
            $this->setAttribute("padding", "");
            $this->setAttribute("format", "");
        }
    }

    public function setAttribute($attr, $value) {
        if (isset($this->attrs[$attr])) {
            $this->attrs[$attr] = $value;
        }
    }

    public function getAttribute($attr) {
        return isset($this->attrs[$attr]) ? $this->attrs[$attr] : false;
    }

    /**
     * Function to parse dbtimestamp processing instructions
     * Reference: http://www.sagehill.net/docbookxsl/Datetime.html
     */
    public function parseDBTimestamp() {
        // Array to parse formats from dbtimestamp to date()
        $parseArray = array(
            "a"         => "D",         // Day abbreviation
            "A"         => "l",         // Day name
            "b"         => "M",         // Month abbreviation
            "c"         => "c",         // ISO date and time
            "B"         => "F",         // Month name
            "d"         => "d",         // Day in month
            "H"         => "H",         // Hour in day
            "j"         => "z",         // Day in year
            "m"         => "m",         // Month in year
            "M"         => "i",         // Minute in hour
            "S"         => "s",         // Second in minute
            "U"         => "W",         // Week in year
            "w"         => "w",         // Day in week
            "x"         => "Y-m-dP",    // ISO date
            "X"         => "H:i:sP",    // ISO time
            "Y"         => "Y",         // Year
        );
        if ($this->getAttribute("padding") == "0") {
            $parseArray["d"] = "j";
            $parseArray["H"] = "G";
            $parseArray["m"] = "n";
        }
        $format = $this->getAttribute("format");
        if (!$format) {
            return $this->format->appendData(date('c', getenv('SOURCE_DATE_EPOCH') ?: time()));
        }
        $dateFormat = "";
        $len = strlen($format);
        for ($i = 0; $i < $len; $i++) {
            $dateFormat .= isset($parseArray[$format[$i]])
                           ? $parseArray[$format[$i]]
                           : $format[$i];
        }
        return $this->format->appendData(date($dateFormat, getenv('SOURCE_DATE_EPOCH') ?: time()));
    }

}