1 |
1 |
<?php |
2 |
2 |
defined('IN_PHPCMS') or exit('No permission resources.'); |
3 |
3 |
pc_base::load_app_func('util','content'); |
4 |
4 |
pc_base::load_sys_func('dir'); |
5 |
5 |
class html { |
6 |
6 |
private $siteid,$url,$html_root,$queue,$categorys; |
7 |
7 |
public function __construct() { |
8 |
8 |
$this->queue = pc_base::load_model('queue_model'); |
9 |
9 |
define('HTML',true); |
10 |
10 |
self::set_siteid(); |
11 |
11 |
$this->categorys = getcache('category_content_'.$this->siteid,'commons'); |
12 |
12 |
$this->url = pc_base::load_app_class('url', 'content'); |
13 |
13 |
$this->html_root = pc_base::load_config('system','html_root'); |
14 |
14 |
$this->sitelist = getcache('sitelist','commons'); |
15 |
15 |
} |
16 |
16 |
|
17 |
17 |
/** |
18 |
18 |
* 生成内容页 |
19 |
19 |
* @param $file 文件地址 |
20 |
20 |
* @param $data 数据 |
21 |
21 |
* @param $array_merge 是否合并 |
22 |
22 |
* @param $action 方法 |
23 |
23 |
* @param $upgrade 是否是升级数据 |
24 |
24 |
*/ |
25 |
25 |
public function show($file, $data = '', $array_merge = 1,$action = 'add',$upgrade = 0) { |
26 |
26 |
if($upgrade) $file = '/'.ltrim($file,WEB_PATH); |
27 |
27 |
$allow_visitor = 1; |
28 |
28 |
$id = $data['id']; |
29 |
29 |
if($array_merge) { |
30 |
30 |
$data = new_stripslashes($data); |
31 |
31 |
$data = array_merge($data['system'],$data['model']); |
32 |
32 |
} |
33 |
33 |
//通过rs获取原始值 |
34 |
34 |
$rs = $data; |
35 |
35 |
if(isset($data['paginationtype'])) { |
36 |
36 |
$paginationtype = $data['paginationtype']; |
37 |
37 |
$maxcharperpage = $data['maxcharperpage']; |
38 |
38 |
} else { |
39 |
39 |
$paginationtype = 0; |
40 |
40 |
} |
41 |
41 |
$catid = $data['catid']; |
42 |
42 |
$CATEGORYS = $this->categorys; |
43 |
43 |
$CAT = $CATEGORYS[$catid]; |
44 |
44 |
$CAT['setting'] = string2array($CAT['setting']); |
45 |
45 |
define('STYLE',$CAT['setting']['template_list']); |
46 |
46 |
|
47 |
47 |
//最顶级栏目ID |
48 |
48 |
$arrparentid = explode(',', $CAT['arrparentid']); |
49 |
49 |
$top_parentid = $arrparentid[1] ? $arrparentid[1] : $catid; |
50 |
50 |
|
51 |
51 |
//$file = '/'.$file; |
52 |
52 |
//添加到发布点队列 |
53 |
53 |
//当站点为非系统站点 |
54 |
54 |
|
55 |
55 |
if($this->siteid!=1) { |
56 |
56 |
$site_dir = $this->sitelist[$this->siteid]['dirname']; |
57 |
57 |
$file = $this->html_root.'/'.$site_dir.$file; |
58 |
58 |
} |
59 |
59 |
|
60 |
60 |
$this->queue->add_queue($action,$file,$this->siteid); |
61 |
61 |
|
62 |
62 |
$modelid = $CAT['modelid']; |
63 |
63 |
require_once CACHE_MODEL_PATH.'content_output.class.php'; |
64 |
64 |
$content_output = new content_output($modelid,$catid,$CATEGORYS); |
65 |
65 |
$output_data = $content_output->get($data); |
66 |
66 |
extract($output_data); |
67 |
67 |
if(module_exists('comment')) { |
68 |
68 |
$allow_comment = isset($allow_comment) ? $allow_comment : 1; |
69 |
69 |
} else { |
70 |
70 |
$allow_comment = 0; |
71 |
71 |
} |
72 |
72 |
$this->db = pc_base::load_model('content_model'); |
73 |
73 |
$this->db->set_model($modelid); |
74 |
74 |
//上一页 |
75 |
75 |
$previous_page = $this->db->get_one("`catid` = '$catid' AND `id`<'$id' AND `status`=99",'*','id DESC'); |
76 |
76 |
//下一页 |
77 |
77 |
$next_page = $this->db->get_one("`catid`= '$catid' AND `id`>'$id' AND `status`=99",'*','id ASC'); |
78 |
78 |
|
79 |
79 |
if(empty($previous_page)) { |
80 |
80 |
$previous_page = array('title'=>L('first_page','','content'), 'thumb'=>IMG_PATH.'nopic_small.gif', 'url'=>'javascript:alert(\''.L('first_page','','content').'\');'); |
81 |
81 |
} |
82 |
82 |
if(empty($next_page)) { |
83 |
83 |
$next_page = array('title'=>L('last_page','','content'), 'thumb'=>IMG_PATH.'nopic_small.gif', 'url'=>'javascript:alert(\''.L('last_page','','content').'\');'); |
84 |
84 |
} |
85 |
85 |
|
86 |
86 |
$title = strip_tags($title); |
87 |
87 |
//SEO |
88 |
88 |
$seo_keywords = ''; |
89 |
89 |
if(!empty($keywords)) $seo_keywords = implode(',',$keywords); |
90 |
90 |
$siteid = $this->siteid; |
91 |
91 |
$SEO = seo($siteid, $catid, $title, $description, $seo_keywords); |
92 |
92 |
|
93 |
93 |
$ishtml = 1; |
94 |
94 |
$template = $template ? $template : $CAT['setting']['show_template']; |
95 |
95 |
|
96 |
96 |
//分页处理 |
97 |
97 |
$pages = $titles = ''; |
98 |
98 |
if($paginationtype==1) { |
99 |
99 |
//自动分页 |
100 |
100 |
if($maxcharperpage < 10) $maxcharperpage = 500; |
101 |
101 |
$contentpage = pc_base::load_app_class('contentpage'); |
102 |
102 |
$content = $contentpage->get_data($content,$maxcharperpage); |
103 |
103 |
} |
104 |
104 |
|
105 |
105 |
if($paginationtype!=0) { |
106 |
106 |
//手动分页 |
107 |
107 |
$CONTENT_POS = strpos($content, '[page]'); |
108 |
108 |
if($CONTENT_POS !== false) { |
109 |
109 |
$this->url = pc_base::load_app_class('url', 'content'); |
110 |
110 |
$contents = array_filter(explode('[page]', $content)); |
111 |
111 |
$pagenumber = count($contents); |
112 |
112 |
if (strpos($content, '[/page]')!==false && ($CONTENT_POS<7)) { |
113 |
113 |
$pagenumber--; |
114 |
114 |
} |
115 |
115 |
for($i=1; $i<=$pagenumber; $i++) { |
116 |
116 |
$upgrade = $upgrade ? '/'.ltrim($file,WEB_PATH) : ''; |
117 |
117 |
$pageurls[$i] = $this->url->show($id, $i, $catid, $data['inputtime'],'','','edit',$upgrade); |
118 |
118 |
|
119 |
119 |
} |
120 |
120 |
$END_POS = strpos($content, '[/page]'); |
121 |
121 |
if($END_POS !== false) { |
122 |
122 |
if($CONTENT_POS>7) { |
123 |
123 |
$content = '[page]'.$title.'[/page]'.$content; |
124 |
124 |
} |
125 |
125 |
if(preg_match_all("|\[page\](.*)\[/page\]|U", $content, $m, PREG_PATTERN_ORDER)) { |
126 |
126 |
foreach($m[1] as $k=>$v) { |
127 |
127 |
$p = $k+1; |
128 |
128 |
$titles[$p]['title'] = strip_tags($v); |
129 |
129 |
$titles[$p]['url'] = $pageurls[$p][0]; |
130 |
130 |
} |
131 |
131 |
} |
132 |
132 |
} |
133 |
133 |
//生成分页 |
134 |
134 |
foreach ($pageurls as $page=>$urls) { |
135 |
135 |
$pages = content_pages($pagenumber,$page, $pageurls); |
136 |
136 |
//判断[page]出现的位置是否在第一位 |
137 |
137 |
if($CONTENT_POS<7) { |
138 |
138 |
$content = $contents[$page]; |
139 |
139 |
} else { |
140 |
140 |
if ($page==1 && !empty($titles)) { |
141 |
141 |
$content = $title.'[/page]'.$contents[$page-1]; |
142 |
142 |
} else { |
143 |
143 |
$content = $contents[$page-1]; |
144 |
144 |
} |
145 |
145 |
} |
146 |
146 |
if($titles) { |
147 |
147 |
list($title, $content) = explode('[/page]', $content); |
148 |
148 |
$content = trim($content); |
149 |
149 |
if(strpos($content,'</p>')===0) { |
150 |
150 |
$content = '<p>'.$content; |
151 |
151 |
} |
152 |
152 |
if(stripos($content,'<p>')===0) { |
153 |
153 |
$content = $content.'</p>'; |
154 |
154 |
} |
155 |
155 |
} |
156 |
156 |
$pagefile = $urls[1]; |
157 |
157 |
if($this->siteid!=1) { |
158 |
158 |
$pagefile = $this->html_root.'/'.$site_dir.$pagefile; |
159 |
159 |
} |
160 |
160 |
$this->queue->add_queue($action,$pagefile,$this->siteid); |
161 |
161 |
$pagefile = PHPCMS_PATH.$pagefile; |
162 |
162 |
ob_start(); |
163 |
163 |
include template('content', $template); |
164 |
164 |
$this->createhtml($pagefile); |
165 |
165 |
} |
166 |
166 |
return true; |
167 |
167 |
} |
168 |
168 |
} |
169 |
169 |
//分页处理结束 |
170 |
170 |
$file = PHPCMS_PATH.$file; |
171 |
171 |
ob_start(); |
172 |
172 |
include template('content', $template); |
173 |
173 |
return $this->createhtml($file); |
174 |
174 |
} |
175 |
175 |
|
176 |
176 |
/** |
177 |
177 |
* 生成栏目列表 |
178 |
178 |
* @param $catid 栏目id |
179 |
179 |
* @param $page 当前页数 |
180 |
180 |
*/ |
181 |
181 |
public function category($catid, $page = 0) { |
182 |
182 |
$CAT = $this->categorys[$catid]; |
183 |
183 |
@extract($CAT); |
184 |
184 |
if(!$ishtml) return false; |
185 |
185 |
if(!$catid) showmessage(L('category_not_exists','content'),'blank'); |
186 |
186 |
$CATEGORYS = $this->categorys; |
187 |
187 |
if(!isset($CATEGORYS[$catid])) showmessage(L('information_does_not_exist', 'content'),'blank'); |
188 |
188 |
$siteid = $CAT['siteid']; |
189 |
189 |
$copyjs = ''; |
190 |
190 |
$setting = string2array($setting); |
191 |
191 |
if(!$setting['meta_title']) $setting['meta_title'] = $catname; |
192 |
192 |
$SEO = seo($siteid, '',$setting['meta_title'],$setting['meta_description'],$setting['meta_keywords']); |
193 |
193 |
define('STYLE',$setting['template_list']); |
194 |
194 |
|
195 |
195 |
$page = intval($page); |
196 |
196 |
$parentdir = $CAT['parentdir']; |
197 |
197 |
$catdir = $CAT['catdir']; |
198 |
198 |
//检查是否生成到根目录 |
199 |
199 |
$create_to_html_root = $CAT['sethtml']; |
200 |
200 |
//$base_file = $parentdir.$catdir.'/'; |
201 |
201 |
//生成地址 |
202 |
202 |
if($CAT['create_to_html_root']) $parentdir = ''; |
203 |
203 |
|
204 |
204 |
//获取父级的配置,看是否生成静态,如果是动态则直接把父级目录调过来为生成静态目录所用 |
205 |
205 |
$parent_setting = string2array($CATEGORYS[$CAT['parentid']]['setting']); |
206 |
206 |
if($parent_setting['ishtml']==0 && $setting['ishtml']==1){ |
207 |
207 |
$parentdir = $CATEGORYS[$CAT['parentid']]['catdir'].'/'; |
208 |
208 |
} |
209 |
209 |
|
210 |
210 |
$base_file = $this->url->get_list_url($setting['category_ruleid'],$parentdir, $catdir, $catid, $page); |
211 |
211 |
$base_file = '/'.$base_file; |
212 |
212 |
|
213 |
213 |
//非系统站点时,生成到指定目录 |
214 |
214 |
if($this->siteid!=1) { |
215 |
215 |
$site_dir = $this->sitelist[$this->siteid]['dirname']; |
216 |
216 |
if($create_to_html_root) { |
217 |
217 |
$base_file = '/'.$site_dir.$base_file; |
218 |
218 |
} else { |
219 |
219 |
$base_file = '/'.$site_dir.$this->html_root.$base_file; |
220 |
220 |
} |
221 |
221 |
} |
222 |
222 |
//判断二级域名是否直接绑定到该栏目 |
223 |
223 |
$root_domain = preg_match('/^((http|https):\/\/)([a-z0-9\-\.]+)\/$/',$CAT['url']) ? 1 : 0; |
224 |
224 |
$count_number = substr_count($CAT['url'], '/'); |
225 |
225 |
$urlrules = getcache('urlrules','commons'); |
226 |
226 |
$urlrules = explode('|',$urlrules[$category_ruleid]); |
227 |
227 |
|
228 |
228 |
if($create_to_html_root) { |
229 |
229 |
if($this->siteid==1) { |
230 |
230 |
$file = PHPCMS_PATH.$base_file; |
231 |
231 |
} else { |
232 |
232 |
$file = PHPCMS_PATH.substr($this->html_root,1).$base_file; |
233 |
233 |
} |
234 |
234 |
//添加到发布点队列 |
235 |
235 |
$this->queue->add_queue('add',$base_file,$this->siteid); |
236 |
236 |
//评论跨站调用所需的JS文件 |
237 |
237 |
if(substr($base_file, -10)=='index.html' && $count_number==3) { |
238 |
238 |
$copyjs = 1; |
239 |
239 |
$this->queue->add_queue('add',$base_file,$this->siteid); |
240 |
240 |
} |
241 |
241 |
//URLRULES |
242 |
242 |
if($CAT['isdomain']) { |
243 |
243 |
$second_domain = 1; |
244 |
244 |
foreach ($urlrules as $_k=>$_v) { |
245 |
245 |
$urlrules[$_k] = $_v; |
246 |
246 |
} |
247 |
247 |
} else { |
248 |
248 |
foreach ($urlrules as $_k=>$_v) { |
249 |
249 |
$urlrules[$_k] = '/'.$_v; |
250 |
250 |
} |
251 |
251 |
} |
252 |
252 |
} else { |
253 |
253 |
$file = PHPCMS_PATH.substr($this->html_root,1).$base_file; |
254 |
254 |
//添加到发布点队列 |
255 |
255 |
$this->queue->add_queue('add',$this->html_root.$base_file,$this->siteid); |
256 |
256 |
//评论跨站调用所需的JS文件 |
257 |
257 |
if(substr($base_file, -10)=='index.html' && $count_number==3) { |
258 |
258 |
$copyjs = 1; |
259 |
259 |
$this->queue->add_queue('add',$this->html_root.$base_file,$this->siteid); |
260 |
260 |
} |
261 |
261 |
//URLRULES |
262 |
262 |
$htm_prefix = $root_domain ? '' : $this->html_root; |
263 |
263 |
$htm_prefix = rtrim(WEB_PATH,'/').$htm_prefix; |
264 |
264 |
if($CAT['isdomain']) { |
265 |
265 |
$second_domain = 1; |
266 |
266 |
} else { |
267 |
267 |
$second_domain = 0;//判断该栏目是否绑定了二级域名或者上级栏目绑定了二级域名,存在的话,重新构造列表页url规则 |
268 |
268 |
foreach ($urlrules as $_k=>$_v) { |
269 |
269 |
$urlrules[$_k] = $htm_prefix.'/'.$_v; |
270 |
270 |
} |
271 |
271 |
} |
272 |
272 |
} |
273 |
273 |
|
274 |
274 |
if($type==0) { |
275 |
275 |
$template = $setting['category_template'] ? $setting['category_template'] : 'category'; |
276 |
276 |
$template_list = $setting['list_template'] ? $setting['list_template'] : 'list'; |
277 |
277 |
$template = $child ? $template : $template_list; |
278 |
278 |
$arrparentid = explode(',', $arrparentid); |
279 |
279 |
$top_parentid = $arrparentid[1] ? $arrparentid[1] : $catid; |
280 |
280 |
$array_child = array(); |
281 |
281 |
$self_array = explode(',', $arrchildid); |
282 |
282 |
foreach ($self_array as $arr) { |
283 |
283 |
if($arr!=$catid) $array_child[] = $arr; |
284 |
284 |
} |
285 |
285 |
$arrchildid = implode(',', $array_child); |
286 |
286 |
//URL规则 |
287 |
287 |
$urlrules = implode('~', $urlrules); |
288 |
288 |
|
289 |
289 |
define('URLRULE', $urlrules); |
290 |
290 |
//绑定域名时,设置$catdir 为空 |
291 |
291 |
if($root_domain) $parentdir = $catdir = ''; |
292 |
292 |
if($second_domain) { |
293 |
293 |
$parentdir = ''; |
294 |
294 |
$parentdir = str_replace($catdir.'/', '', $CAT['url']); |
295 |
295 |
} |
296 |
296 |
|
297 |
297 |
$GLOBALS['URL_ARRAY'] = array('categorydir'=>$parentdir, 'catdir'=>$catdir, 'catid'=>$catid); |
298 |
298 |
} else { |
299 |
299 |
//单网页 |
300 |
300 |
$datas = $this->page($catid); |
301 |
301 |
if($datas) extract($datas); |
302 |
302 |
$template = $setting['page_template'] ? $setting['page_template'] : 'page'; |
303 |
303 |
$parentid = $CATEGORYS[$catid]['parentid']; |
304 |
304 |
$arrchild_arr = $CATEGORYS[$parentid]['arrchildid']; |
305 |
305 |
if($arrchild_arr=='') $arrchild_arr = $CATEGORYS[$catid]['arrchildid']; |
306 |
306 |
$arrchild_arr = explode(',',$arrchild_arr); |
307 |
307 |
array_shift($arrchild_arr); |
308 |
308 |
$keywords = $keywords ? $keywords : $setting['meta_keywords']; |
309 |
309 |
$SEO = seo($siteid, 0, $title,$setting['meta_description'],$keywords); |
310 |
310 |
} |
311 |
311 |
ob_start(); |
312 |
312 |
include template('content',$template); |
313 |
313 |
return $this->createhtml($file, $copyjs); |
314 |
314 |
} |
315 |
315 |
/** |
316 |
316 |
* 更新首页 |
317 |
317 |
*/ |
318 |
318 |
public function index() { |
319 |
319 |
if($this->siteid==1) { |
320 |
320 |
$file = PHPCMS_PATH.'index.html'; |
321 |
321 |
//添加到发布点队列 |
322 |
322 |
$this->queue->add_queue('edit','/index.html',$this->siteid); |
323 |
323 |
} else { |
324 |
324 |
$site_dir = $this->sitelist[$this->siteid]['dirname']; |
325 |
325 |
$file = $this->html_root.'/'.$site_dir.'/index.html'; |
326 |
326 |
//添加到发布点队列 |
327 |
327 |
$this->queue->add_queue('edit',$file,$this->siteid); |
328 |
328 |
$file = PHPCMS_PATH.$file; |
329 |
329 |
} |
330 |
330 |
define('SITEID', $this->siteid); |
331 |
331 |
//SEO |
332 |
332 |
$SEO = seo($this->siteid); |
333 |
333 |
$siteid = $this->siteid; |
334 |
334 |
$CATEGORYS = $this->categorys; |
335 |
335 |
$style = $this->sitelist[$siteid]['default_style']; |
336 |
336 |
ob_start(); |
337 |
337 |
include template('content','index',$style); |
338 |
338 |
return $this->createhtml($file, 1); |
339 |
339 |
} |
340 |
340 |
/** |
341 |
341 |
* 单网页 |
342 |
342 |
* @param $catid |
343 |
343 |
*/ |
344 |
344 |
public function page($catid) { |
345 |
345 |
$this->page_db = pc_base::load_model('page_model'); |
346 |
346 |
$data = $this->page_db->get_one(array('catid'=>$catid)); |
347 |
347 |
return $data; |
348 |
348 |
} |
349 |
349 |
/** |
350 |
350 |
* 写入文件 |
351 |
351 |
* @param $file 文件路径 |
352 |
352 |
* @param $copyjs 是否复制js,跨站调用评论时,需要该js |
353 |
353 |
*/ |
354 |
354 |
private function createhtml($file, $copyjs = '') { |
355 |
355 |
$data = ob_get_contents(); |
356 |
356 |
ob_clean(); |
357 |
357 |
$dir = dirname($file); |
358 |
358 |
if(!is_dir($dir)) { |
359 |
359 |
mkdir($dir, 0777,1); |
360 |
360 |
} |
361 |
361 |
if ($copyjs && !file_exists($dir.'/js.html')) { |
362 |
362 |
@copy(PC_PATH.'modules/content/templates/js.html', $dir.'/js.html'); |
363 |
363 |
} |
364 |
364 |
$strlen = file_put_contents($file, $data); |
365 |
365 |
@chmod($file,0777); |
366 |
366 |
if(!is_writable($file)) { |
367 |
367 |
$file = str_replace(PHPCMS_PATH,'',$file); |
368 |
368 |
showmessage(L('file').':'.$file.'<br>'.L('not_writable')); |
369 |
369 |
} |
370 |
370 |
return $strlen; |
371 |
371 |
} |
372 |
372 |
|
373 |
373 |
/** |
374 |
374 |
* 设置当前站点id |
375 |
375 |
*/ |
376 |
376 |
private function set_siteid() { |
377 |
377 |
if(defined('IN_ADMIN')) { |
378 |
378 |
$this->siteid = $GLOBALS['siteid'] = get_siteid(); |
379 |
379 |
} else { |
380 |
380 |
if (param::get_cookie('siteid')) { |
381 |
381 |
$this->siteid = $GLOBALS['siteid'] = param::get_cookie('siteid'); |
382 |
382 |
} else { |
383 |
383 |
$this->siteid = $GLOBALS['siteid'] = 1; |
384 |
384 |
} |
385 |
385 |
} |
386 |
386 |
} |
387 |
387 |
/** |
388 |
388 |
* 生成相关栏目列表、只生成前5页 |
389 |
389 |
* @param $catid |
390 |
390 |
*/ |
391 |
391 |
public function create_relation_html($catid) { |
|
392 |
/* |
|
393 |
* 修改者:Abel Lan |
|
394 |
* 修改日期:2018-3-1 |
|
395 |
* 修改目的:修复bug:在添加或编辑文章内容时,会将文章所属栏目直接生成5个列表静态页面文件(而未考虑文章不足5页) |
|
396 |
* 修改编号:create_relation_html-001 |
|
397 |
* create_relation_html-001修改前开始 |
392 |
398 |
for($page = 1; $page < 6; $page++) { |
393 |
399 |
$this->category($catid,$page); |
394 |
400 |
} |
|
401 |
* create_relation_html-001修改前结束 |
|
402 |
* create_relation_html-001修改后开始 |
|
403 |
*/ |
|
404 |
$page = 1; |
|
405 |
$pagesize = isset($pagesize) ? $pagesize : 20; |
|
406 |
do { |
|
407 |
$this->category($catid,$page); |
|
408 |
$page++; |
|
409 |
$total_number = isset($total_number) ? $total_number : PAGES; |
|
410 |
} while ($page <= $total_number && $page < $pagesize); |
|
411 |
//create_relation_html-001修改后结束 |
|
412 |
|
395 |
413 |
//检查当前栏目的父栏目,如果存在则生成 |
396 |
414 |
$arrparentid = $this->categorys[$catid]['arrparentid']; |
397 |
415 |
if($arrparentid) { |
398 |
416 |
$arrparentid = explode(',', $arrparentid); |
399 |
417 |
foreach ($arrparentid as $catid) { |
400 |
418 |
if($catid) $this->category($catid,1); |
401 |
419 |
} |
402 |
420 |
} |
403 |
421 |
} |
404 |
422 |
} |