Pages::GenHead()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package      fwolflib
4
 * @copyright    Copyright 2004-2007, Fwolf
5
 * @author       Fwolf <[email protected]>
6
 */
7
8
/**
9
 * Generate web pages
10
 *
11
 * @package    fwolflib
12
 * @copyright  Copyright 2004-2007, Fwolf
13
 * @author     Fwolf <[email protected]>
14
 * @since      2004-4-13 22:50:52
15
 * @access     public
16
 * @version    $Id$
17
 */
18
class Pages
0 ignored issues
show
Bug introduced by
There is one abstract method GenBody in this class; you could implement it, or declare this class as abstract.
Loading history...
19
{
20
	/**
21
	 * Debug mode
22
	 * @access	protected
23
	 * @var	boolean
24
	 */
25
	protected $mDebug = false;
26
27
	/**
28
	 * Parts of html heads, this is NOT html code
29
	 * Sample value: 'meta'=>array('..', '...'), 'title'='...'
30
	 * @access	protected
31
	 * @var	array
32
	 */
33
	protected $mHead = array();
34
35
	/**
36
	 * Parts of html code before <head>, this is NOT html code
37
	 * Sample value: 'xml'=>array('..', '...'), 'doctype'=>'...'
38
	 * @access	protected
39
	 * @var	array
40
	 */
41
	protected $mHeadahead = array();
42
43
	/**
44
	 * Result html content
45
	 * $mHtml = $mHtmlHeadahead + $mHtmlHead + $mHtmlBody
46
	 * And + some <marks> between these parts.
47
	 * @access	protected
48
	 * @var	string
49
	 */
50
	protected $mHtml = '';
51
52
	/**
53
	 * Html content part of body
54
	 * Code of '<body>' part.
55
	 * @access	protected
56
	 * @var	string
57
	 */
58
	protected $mHtmlBody = '';
59
60
	/**
61
	 * Html content part of head
62
	 * Code of '<head>' part.
63
	 * @access	protected
64
	 * @var	string
65
	 */
66
	protected $mHtmlHead = '';
67
68
	/**
69
	 * Html content part of html_head
70
	 * Code ahead of '<head>', xml, doctype & html marks.
71
	 * @access	protected
72
	 * @var	string
73
	 */
74
	protected $mHtmlHeadahead = '';
75
76
	
77
    /**
78
     * 构造函数
79
     */
80
    function __construct()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
81
	{
82
		//开始输出缓冲区
83
		ob_start();
84
85
		//开始SESSION
86
		//调试程序的时候因为程序经常改动,所以不使用CACHE
87
		if (true == $this->mDebug)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
88
			session_cache_limiter('private,must-revalidate');
89
		session_start();
90
    } // end of func __construct
91
92
	
93
	/**
94
	 * 显示网页正式内容
95
	 * @param	boolean	$return	Return contents instead of print out.
96
	 * @access	public
97
	 */
98
	public function Display($return=false)
99
	{
100
		if (empty($this->mHtml))
101
			$this->GenHtml();
102
		if (true == $return)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
103
			return $this->mHtml;
104
		else{
105
			echo $this->mHtml;
106
			//结束输出缓冲区,输出内容
107
			ob_end_flush();
108
		}
109
	} // end of func Display
110
111
112
	/**
113
	 * Generate body part of html code
114
	 * @access	protected
115
	 * @return	string
116
	 */
117
	abstract protected function GenBody();
118
119
120
	/**
121
	 * Generate head part of html code
122
	 * @access	proteced
123
	 * @return	string
124
	 */
125
	protected function GenHead()
126
	{
127
		$this->mHtmlHeadahead = '';
128
		// Xml format declaration
129
		if (array_key_exists('xml', $this->mHeadahead))
130
			$this->mHtmlHeadahead .= $this->GenHeadXml() . "\n";
131
		// Doctype
132
133
	} // end of func GenHead
134
135
136
	/**
137
	 * Generate xml declaration part of head_ahead
138
	 * $this->mHeadahead['xml'] = array('version'=>'1.0', 'encoding'='utf-8')
139
	 * @access	protected
140
	 * @return	string
141
	 */
142
	protected function GenHeadXml()
143
	{
144
		if (array_key_exists('xml', $this->mHeadahead)) {
145
			$ar = $this->mHeadahead['xml'];
146
			return "<?xml version=\"{$ar['version']}\" encoding=\"{$ar['encoding']}\"?>";
147
		}
148
		else
149
			return '';
150
	} // end of func GenHeadXml
151
152
153
	/**
154
	 * Generate html code from joining several parts
155
	 * @access	protected
156
	 * @return	string
157
	 */
158
	protected function GenHtml()
159
	{
160
		$this->mHtml = '';
161
		$this->mHtml .= $this->GenHead;
0 ignored issues
show
Bug introduced by
The property GenHead does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
162
		$this->mHtml .= $this->GenBody;
0 ignored issues
show
Bug introduced by
The property GenBody does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
163
		$this->mHtml .= "</body>\n</html>";
164
		return $this->mHtml;
165
	} // end of func GenHtml
166
167
168
	/**
169
	 * Set xml part of head_ahead
170
	 * @access	public
171
	 * @param	string	$version
172
	 * @param	string	$encoding
173
	 */
174
	public function SetHeadXml($version = '1.0', $encoding='utf-8') {
175
		$this->mHeadahead['xml']['version'] = $version;
176
		$this->mHeadahead['xml']['encoding'] = $encoding;
177
	} // end of func SetHeadXml
178
179
180
} // end of class Pages
181
182
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...