Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
115 lars 1
<?php
2
    //$Id: resource.vportale.php 99 2022-06-02 08:25:37Z tiefland $
3
 
4
    /**
5
     * MySQL Resource
6
     *
7
     * Resource Implementation based on the Custom API to use
8
     * MySQLi as the storage resource for Smarty's templates and configs.
9
     *
10
     * @package Resource-examples
11
     * @author  Rodney Rehm
12
     * @author  Lars Tiefland
13
     */
14
    class Smarty_Resource_Mysqli_vportale extends Smarty_Resource_Custom
15
    {
16
        private $conn;
17
        // prepared fetch() statement
18
        protected $fetch;
19
        // prepared fetchTimestamp() statement
20
        protected $mtime;
21
 
22
        public function __construct()
23
        {
24
            $sql = 'SELECT
25
                    letzte_aenderung_am,
26
                    inhalt
27
                FROM
28
                    vportale_template
29
                WHERE
30
                    id = ?
31
            ';
32
            if ( isset( $GLOBALS["remoteDB"] ) && $GLOBALS["remoteDB"] )
33
            {
34
                $this->conn = $GLOBALS["remoteDB"];
35
            }
36
            elseif ( isset( $GLOBALS["orderDB"] ) && $GLOBALS["orderDB"] )
37
            {
38
                $this->conn = $GLOBALS["orderDB"];
39
            }
40
            else
41
            {
42
                $this->conn = $GLOBALS["shopDB"];
43
            }
44
            $this->fetch = $this->conn->prepare( $sql );
45
            $sql = 'SELECT
46
                    letzte_aenderung_am
47
                FROM
48
                    vportale_template
49
                WHERE
50
                    id = ?
51
            ';
52
            $this->mtime = $this->conn->prepare( $sql );
53
        }
54
 
55
        /**
56
         * Fetch a template and its modification time from database
57
         *
58
         * @param string  $name   template name
59
         * @param string  $source template source
60
         * @param integer $mtime  template modification timestamp (epoch)
61
         *
62
         * @return void
63
         */
64
        protected function fetch( $name, &$source, &$mtime )
65
        {
66
            $this->fetch->bind_param( "s", $name );
67
            $this->fetch->execute();
68
            trigger_error( $this->conn->error );
69
            $res = $this->fetch->get_result();
70
            $row = $res->fetch_assoc();
71
            if ( $row )
72
            {
73
                $source = stripslashes( $row['inhalt'] );
74
                $mtime = strtotime( $row['letzte_aenderung_am'] );
75
            }
76
            else
77
            {
78
                $source = null;
79
                $mtime = null;
80
            }
81
        }
82
 
83
        /**
84
         * Fetch a template's modification time from database
85
         *
86
         * @note implementing this method is optional. Only implement it if modification times can be accessed faster than loading the compiled template source.
87
         *
88
         * @param string $name template name
89
         *
90
         * @return integer timestamp (epoch) the template was modified
91
         */
92
        protected function fetchTimestamp( $name )
93
        {
94
            $this->mtime->bind_param( "s", $name );
95
            $this->mtime->execute();
96
            trigger_error( $this->conn->error );
97
            $res = $this->mtime->get_result();
98
            $row = $res->fetch_assoc();
99
            $mtime = $row["letzte_aenderung_am"];
100
            return strtotime( $mtime );
101
        }
102
    }
103
 
104
 
105
    // register the resource name "mysqli"
106
    $GLOBALS["ui"]->registerResource( 'mysqli', new Smarty_Resource_Mysqli_vportale() );