📄 cms_site.class.inc
字号:
<?php/*Copyright Intermesh 2003Author: Merijn Schering <mschering@intermesh.nl>Version: 1.0 Release date: 08 July 2003This program is free software; you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by theFree Software Foundation; either version 2 of the License, or (at youroption) any later version.*/class cms_site extends cms { var $site; var $language; var $template; var $publish_url; var $publish_path; var $publish_static = false; var $template_file_replacements = array (); var $folder_id; var $file_id; var $task; var $tags = array ('home', 'folders', 'rootfolders', 'files', 'path', 'icon', 'login', 'back', 'active_doc', 'document', 'folderlist', 'hot_items', 'languages', 'items', 'menu'); function cms_site() { global $GO_CONFIG, $GO_LANGUAGE; $this->db(); $this->folder_id = isset ($_REQUEST['folder_id']) ? $_REQUEST['folder_id'] : 0; $this->file_id = isset ($_REQUEST['file_id']) ? $_REQUEST['file_id'] : 0; $this->task = isset ($_REQUEST['task']) ? $_REQUEST['task'] : ''; $language_id = isset ($_REQUEST['language_id']) ? $_REQUEST['language_id'] : 0; $site_id = isset ($_REQUEST['site_id']) ? $_REQUEST['site_id'] : 0; //If a site_id was passed then get it if ($site_id > 0) { $this->site = $this->get_site($site_id); }else { /* if no site_id was passed then we are not in Group-Office but somebody is requesting the site through a domain. Try to get the site by domain. Get the domain name without this page eg. http://www.test.com/test/index.php?file_id=0&folder_id=9 becomes: www.test.com/test */ $domain = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; if (strpos($domain, basename($_SERVER['PHP_SELF'])) !== false) { //chop off filename $pos = strrpos($domain, '/'); if ($pos !== false) { $domain = substr($domain, 0, $pos); } } if (!$this->site = $this->get_site_by_domain($domain, true)) { exit(); } } $this->language = isset ($_SESSION['language']) ? $_SESSION['language'] : false; if ($language_id > 0) { $this->language = $_SESSION['language'] = $this->get_language($language_id); }elseif (!$this->language || $this->language['site_id'] != $this->site['id']) { $this->get_languages($this->site['id']); if ($this->next_record()) { $this->language = $_SESSION['language'] = $this->Record; } else { return false; } } //$publish_path = $this->site['publish_path']; //$root_publish_path = $GO_CONFIG->get_setting('cms_publish_path'); //$this->publish_path = $root_publish_path.$publish_path; //$this->publish_url = $GO_CONFIG->get_setting('cms_publish_url').$publish_path; $this->template = $this->get_template($this->language['template_id']); $GO_LANGUAGE->set_language($this->language['language_code']); //echo $this->language['id']; } function publish() { global $GO_CONFIG; require_once ($GO_CONFIG->class_path.'filesystem.class.inc'); $fs = new filesystem(true); if (!file_exists($this->publish_path)) { return false; } $fs->delete($this->publish_path); mkdir($this->publish_path); if ($this->site['publish_style'] == '2') { $this->publish_static = true; mkdir($this->publish_path.'_site_data'); mkdir($this->publish_path.'_search'); $file = '<?php $site_id='.$this->site["id"].'; require_once("'.$GO_CONFIG->root_path.'Group-Office.php"); if ($cms_module = $GO_MODULES->get_module("cms")) { $published = true; require_once($GO_CONFIG->root_path.$cms_module["path"]."view.inc"); }else { die("Failed to get Content Management Module"); } ?>'; if (!$fp = fopen($this->publish_path.'_search/index.php', 'w+')) { return false; } elseif (!fwrite($fp, $file)) { fclose($fp); return false; } else { fclose($fp); } $this->create_stylesheet($this->publish_path.'_site_data'.$GO_CONFIG->slash.'style.css'); $this->create_template_files(); return $this->create_files($this->language['root_folder_id'], $this->publish_path); } else { $file = '<?php $site_id='.$this->site["id"].'; require_once("'.$GO_CONFIG->root_path.'Group-Office.php"); if ($cms_module = $GO_MODULES->get_module("cms")) { $published = true; require_once($GO_CONFIG->root_path.$cms_module["path"]."view.inc"); }else { die("Failed to get Content Management Module"); } ?>'; if (!$fp = fopen($this->publish_path.'index.php', 'w+')) { return false; } elseif (!fwrite($fp, $file)) { fclose($fp); return false; } else { return fclose($fp); } } } function create_stylesheet($path) { global $GO_CONFIG; $file = ''; if ($template = $this->get_template($this->language['template_id'])) { $file = $template['style']; } if (!$fp = fopen($path, 'w+')) { return false; } elseif (!fwrite($fp, $file)) { fclose($fp); return false; } else { fclose($fp); } return true; } function create_template_files() { global $GO_CONFIG, $GO_MODULES; $cms_module = $GO_MODULES->get_module('cms'); $this->get_template_files($this->language['template_id']); while ($this->next_record()) { if (!$fp = fopen($this->publish_path.'_site_data'.$GO_CONFIG->slash.$this->f('name'), 'w+')) { return false; } elseif (!fwrite($fp, $this->f('content'))) { fclose($fp); return false; } else { fclose($fp); } $tpl_file['dynamic'] = $cms_module['url'].'template_file.php?template_file_id='.$this->f('id'); $tpl_file['static'] = $this->publish_url.'_site_data/'.$this->f('name'); $this->template_file_replacements[] = $tpl_file; } } function create_files($folder_id, $path) { global $GO_CONFIG, $GO_MODULES; $cms_module = $GO_MODULES->get_module("cms"); $cms_site = new cms_site($this->site['id']); $cms_site->get_folders($folder_id); while ($cms_site->next_record()) { $new_path = $path.urlencode($cms_site->f('name')).$GO_CONFIG->slash; if (!file_exists($new_path)) { mkdir($new_path); } if (!is_writable($new_path) || !$this->create_files($cms_site->f('id'), $new_path)) { return false; } } $index_created = false; $cms_site->get_files($folder_id, 'priority', 'ASC'); while ($cms_site->next_record()) { if ($folder_id == $this->language['root_folder_id'] && !$index_created) { $name = 'index.html'; $index_created = true; } else { $name = $cms_site->f('name'); } $full_path = $path.urlencode($name); $file = $this->generate_page($cms_site->f('id')); if (!$fp = fopen($full_path, 'w+')) { return false; } elseif (!fwrite($fp, $file)) { fclose($fp); return false; } else { fclose($fp); } $tpl_file['dynamic'] = $cms_module['full_url'].'view.php?site_id='.$this->site['id'].'&file_id='.$cms_site->f('id'); $tpl_file['static'] = str_replace($this->publish_path, $this->publish_url, $full_path); $this->template_file_replacements[] = $tpl_file; } return true; } function generate_header($title = '', $keywords = '', $description = '') { global $GO_CONFIG, $GO_MODULES, $charset; $cms_module = isset ($cms_module) ? $cms_module : $GO_MODULES->get_module('cms'); $header = '<?xml version="1.0" encoding="'.$charset.'"?>'."\r\n". '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\r\n". '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'.$this->language['language_code'].'" lang="'.$this->language['language_code'].'">'."\r\n". '<head>'."\r\n". '<meta http-equiv="Content-Type" content="text/html; charset='.$charset.'" />'."\r\n". '<meta name="robots" content="all,index,follow" />'."\r\n". '<meta name="revisit-after" content="7 days" />'."\r\n". '<meta name="keywords" content="'.$keywords.'" />'."\r\n". '<meta name="description" content="'.$description.'" />'."\r\n". '<meta name="Generator" content="Group-Office '.$GO_CONFIG->version.'" />'."\r\n". '<title>'.$title.'</title>'."\r\n"; if ($this->publish_static) { $header .= '<link href="'.$this->publish_url.'_site_data/style.css" rel="stylesheet" type="text/css" />'."\r\n"; } else { $header .= '<link href="'.$cms_module['url'].'stylesheet.php?template_id='.$this->language['template_id'].'" rel="stylesheet" type="text/css" />'."\r\n"; $header .= '<link href="'.$cms_module['url'].'stylesheet.php?print=true&template_id='.$this->language['template_id'].'" rel="stylesheet" type="text/css" media="print" />'."\r\n"; } $header .= '<script type="text/javascript" src="'.$GO_CONFIG->host.'javascript/common.js"></script>'."\r\n". '</head>'."\r\n". '<body>'."\r\n". "\r\n<!-- End of generated header --> \r\n\r\n"; return $header; } function generate_footer() { return "\r\n\r\n<!-- Start of generated Footer --> \r\n\r\n". '</body>'."\r\n". '</html>'."\r\n"; } function generate_frontpage() { $frontpage_template_item = $this->get_template_item($this->template['frontpage_template_item_id']); $page = $this->generate_header($this->language['name'], $this->language['keywords'], $this->language['description']); $page .= $this->parse_template($frontpage_template_item['content']); $page .= $this->generate_footer(); return $page; } function find_page($folder_id) { $this->get_files($folder_id); while ($this->next_record()) { if (eregi('htm', $this->f('extension'))) { return $this->f('id'); } } $this->get_folders($folder_id); while ($this->next_record()) { return $this->find_page($this->f('id')); } } function generate_page() { global $GO_CONFIG, $GO_MODULES, $GO_LANGUAGE, $cms_empty, $cms_there_are_results_for_multiple, $cms_there_are_results_for_single; $cms_module = $GO_MODULES->get_module('cms'); //set the folder id we are in if ($this->folder_id == 0) { if ($this->template['activate_frontpage'] == '1' && $this->task == '') { return $this->generate_frontpage(); } else { $this->folder_id = $this->language['root_folder_id']; } } $folder = $this->get_folder($this->folder_id); /* * if someone enter's a disabled folder redirect it to the root folder' if ($folder['disabled'] == '1') { $this->folder_id = $this->language['root_folder_id']; $folder = $this->get_folder($this->folder_id); $this->file_id = 0; }*/ if ($this->task == '' && ($folder['multipage'] == '1')) { $this->task = 'multipage_display'; } require_once ($GO_LANGUAGE->get_language_file('cms')); if ($this->file_id == 0 && $this->task != 'search_results') { $this->file_id = $this->find_page($this->folder_id); } if ($this->file_id > 0) { $file = $this->get_file($this->file_id); if($file['folder_id'] != $this->folder_id) { $this->folder_id = $file['folder_id']; $folder = $this->get_folder($this->folder_id); } if (!eregi('htm', $file['extension'])) { return $file['content']; } if ($file['description'] == '') { $file['description'] = $this->language['description']; } if ($file['keywords'] == '') { $file['keywords'] = $this->language['keywords']; } if ($file['title'] == '') { $file['title'] = strip_extension($file['name']); } } else { $file['title'] = $this->language['title']; $meta_title = $this->language['title']; $file['keywords'] = $this->language['keywords']; $file['description'] = $this->language['description']; } $main_template_item = $this->get_template_item($this->template['main_template_item_id']); $max_length = 300; $print_title = 'false'; $title_class = ''; $class = ''; $read_more_class = ''; $read_more_text = ''; $template = ''; $item_template = ''; $hide_hot_items = 'false'; if ($main_template_item) { $main_template_content = $this->parse_template($main_template_item['content']); $content_tag = $this->get_tag('content', $main_template_content); $attributes = $this->get_attributes($content_tag); //max_length for multipage display $max_length = isset ($attributes['max_length']) ? $attributes['max_length'] : $max_length; $class = isset ($attributes['class']) ? $attributes['class'] : $class; $print_title = isset ($attributes['print_title']) ? $attributes['print_title'] : $print_title; $title_class = isset ($attributes['title_class']) ? $attributes['title_class'] : $title_class; $read_more_class = isset ($attributes['read_more_class']) ? $attributes['read_more_class'] : $read_more_class; $read_more_text = isset ($attributes['read_more_text']) ? $attributes['read_more_text'] : $read_more_text; $template = isset ($attributes['template']) ? $attributes['template'] : $template; $item_template = isset ($attributes['item_template']) ? $attributes['item_template'] : $item_template; $hide_hot_items = isset ($attributes['hide_hot_items ']) ? $attributes['hide_hot_items'] : $hide_hot_items; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -