📄 cms.class.inc
字号:
//echo $replacement['old'].'- >'.$replacement['new'].'<br>'; $content = str_replace($replacement['old'], $replacement['new'], $content); } return $content; } function set_template_items($template_id, $main_template_item_id, $frontpage_template_item_id) { $sql = "UPDATE cms_templates SET main_template_item_id='$main_template_item_id', ". "frontpage_template_item_id='$frontpage_template_item_id' WHERE id='$template_id'"; $this->query($sql); } function get_template_files($template_id) { $this->query("SELECT * FROM cms_template_files WHERE template_id='$template_id'"); return $this->num_rows(); } function add_template_file($template_id, $name, $content) { $template_file_id = $this->nextid('cms_template_files'); if ($template_file_id > 0) { $size = strlen($content); $extension = get_extension($name); $mtime = get_gmt_time(); return $this->query("INSERT INTO cms_template_files (id, template_id, name, extension, size, mtime, content) VALUES ('$template_file_id','$template_id','$name','$extension','$size','$mtime','$content')"); } return false; } function get_template_file($template_file_id) { $this->query("SELECT * FROM cms_template_files WHERE id='$template_file_id'"); if ($this->next_record()) { return $this->Record; } return false; } function template_file_exists($template_id, $name) { $this->query("SELECT id FROM cms_template_files WHERE template_id='$template_id' AND name='$name'"); if ($this->next_record()) { return $this->f('id'); } return false; } function delete_template_file($template_file_id) { return $this->query("DELETE FROM cms_template_files WHERE id='$template_file_id'"); } function search_files($folder_id, $search_word) { $search_word = addslashes(strtoupper($search_word)); $cms = new cms(); $files = array(); $sql = "SELECT * FROM cms_files WHERE (extension='html' OR extension='htm') AND folder_id='$folder_id' AND (UPPER(content) REGEXP '[[:<:]]".$search_word."[[:>:]]'"; $search_word2 = htmlspecialchars($search_word); if($search_word2 != $search_word) { $sql .= " OR UPPER(content) REGEXP '[[:<:]]".$search_word2."[[:>:]]')"; }else { $sql .= ")"; } /* $sql = "SELECT * FROM cms_files WHERE (extension='html' OR extension='htm') AND folder_id='$folder_id' AND (UPPER(content) LIKE '%".$search_word."%'"; $search_word2 = htmlspecialchars($search_word); if($search_word2 != $search_word) { $sql .= " OR (UPPER(content) LIKE '%".$search_word2."%')"; }else { $sql .= ")"; }*/ $this->query($sql); while ($this->next_record()) { $files[] = $this->Record; } $this->get_folders($folder_id); while($this->next_record()) { $files = array_merge($files, $cms->search_files($this->f('id'), $search_word_id)); } return $files; } function get_body($html) { $to_removed_array = array ( "'<html[^>]*>'si", "'</html>'si", "'<body[^>]*>'si", "'</body>'si", "'<head[^>]*>.*?</head>'si", "'<style[^>]*>.*?</style>'si", "'<object[^>]*>.*?</object>'si", ); $html = preg_replace($to_removed_array, '', $html); //$html = preg_replace("/class\s*=\s*[\"']?.*?[\"']?\s/is", '', $html); //$html = preg_replace("/style\s*=\s*[\"'].*?[\"']\s/is", '', $html); //werkt min of meer$html = preg_replace("/class.*?\s/is", '', $html); //$html = preg_replace("/style.*?\s/is", '', $html); return $html; } function remove_styles($html) { $to_removed_array = array ( "'class=[\w]*\b'si", "'class=\"[^\"]*\"'si", "'class=\'[^\']*\''si", "'style=\"[^\"]*\"'si", "'style=\'[^\']*\''si", ); //$html = preg_replace("/class\s*=\s*.*?\s/is", '', $html); //$html = preg_replace("/class\s*=\s*.*?\s/is", '', $html); $html = preg_replace($to_removed_array, '', $html); return $html; } function extract_styles($style) { $styles = array(); $style_name = ''; $in_style = true; $style = str_replace("\r", '', $style); $style = str_replace("\n", '', $style); $style = str_replace(' ', '', $style); for ($i=0; $i<strlen($style); $i++) { $char = $style[$i]; if ($char == '{' || $char == ',') { $in_style = false; if (trim($style_name) != '') { $styles[] = $style_name; } $style_name = ''; }elseif($char == '.') { if ($style_name != '') { $style_name = ''; $in_style = false; }else { $in_style = true; } }elseif($char == ':') { $style_name = ''; $in_style = false; }elseif($char == '}') { $in_style = true; $style_name = ''; }else { if ($in_style) { $style_name .= $char; } } } return $styles; } function clean_up_html($html) { // remove escape slashes $html = stripslashes($html); // strip tags, still leaving attributes, second variable is allowable tags $html = strip_tags($html, '<p><b><br><img><i><u><a><h1><h2><h3><h4><h4><h5><h6><table><tr><td>'); /* // removes the attributes for allowed tags, use separate replace for heading tags since a // heading tag is two characters $html = ereg_replace("<([p|b|i|u])[^>]*>", "<\\1>", $html); $html = ereg_replace("<([h1|h2|h3|h4|h5|h6][1-6])[^>]*>", "<\\1>", $html); */ // remove all class and style attributes from the remaining tags $to_removed_array = array ( "'class=[\w]*\b'si", "'class=\"[^\"]*\"'si", "'class=\'[^\']*\''si", "'style=\"[^\"]*\"'si", "'style=\'[^\']*\''si", ); //$html = preg_replace("/class\s*=\s*.*?\s/is", '', $html); //$html = preg_replace("/class\s*=\s*.*?\s/is", '', $html); $html = preg_replace($to_removed_array, '', $html); return $html; } function strip_for_multipage($html) { $html = str_replace('</h1>', '<br />', $html); $html = str_replace('</h2>', '<br />', $html); $html = str_replace('</h3>', '<br />', $html); $html = str_replace('</h4>', '<br />', $html); $html = str_replace('</h5>', '<br />', $html); $html = str_replace('</h6>', '<br />', $html); return strip_tags($html, '<br>'); } function get_title_from_html($html, $title='') { global $GO_CONFIG; $important_tags = array( '//h1', '//h2', '//h3', '//h4', '//h5', '//h6', '//strong', '//b', "//*[@style='font-weight: bold;']", '//i', "//*[@style='font-style: italic;']" ); require_once($GO_CONFIG->class_path.'xml/xpath.class.inc'); $xpath = new xpath(); $html = '<html>'.strip_tags($html, '<h1><h2><h3><h4><h5><h6><strong><span><ul><ol><li><b><i>').'</html>'; if($xpath->importFromString($html)) { foreach($important_tags as $important_tag) { $nodes = $xpath->match($important_tag); foreach($nodes as $node) { if(strlen($title) == 0) { $title = strip_tags($xpath->getData($node)); }else { $important_words = $this->get_keywords_from_string($xpath->getData($node)); foreach($important_words as $word) { if(strlen($title.' '.$word) > 90) { return $title; }elseif(!stristr($title, $word)) { if(!isset($first)) { $title .= ' - '; $first = true; }else { $title .= ' '; } $title .= $word; } } } } } } return $title; } function get_keywords_from_string($string) { $words = explode(' ', $string); $important_words = array(); foreach($words as $word) { $word = $this->strip_unwanted_chars($word); if(strlen($word) > 0) { if( (strlen($word) > 5 || strtoupper($word) == $word) && !in_array(strtolower($word), $important_words)) { $important_words[] = strtolower($word); } } } return $important_words; } function get_description_from_html($html, $description='') { global $GO_CONFIG; $important_tags = array( '//h1', '//h2', '//h3', '//h4', '//h5', '//h6', '//strong', '//b', "//*[@style='font-weight: bold;']", '//i', "//*[@style='font-style: italic;']" ); require_once($GO_CONFIG->class_path.'xml/xpath.class.inc'); $xpath = new xpath(); $html = '<html>'.strip_tags($html, '<h1><h2><h3><h4><h5><h6><strong><span><ul><ol><li><b><i>').'</html>'; $html = str_replace('\r','', $html); $html = str_replace('\n',' ', $html); $html = str_replace('>','> ', $html); if($xpath->importFromString($html)) { foreach($important_tags as $important_tag) { $nodes = $xpath->match($important_tag); foreach($nodes as $node) { $important_words = $this->get_keywords_from_string($xpath->getData($node)); foreach($important_words as $word) { if(strlen($description.' '.$word) > 250) { return $description; }elseif(!stristr($description, $word)) { if(strlen($description) > 0) { $description .= ' '; } $description .= $word; } } } } } return $description; } function get_keywords_from_html($html, $keywords='') { $keywordsArr = $this->get_keywords_from_html_in_array($html); foreach($keywordsArr as $keyword) { if(!stristr($keywords, $keyword)) { if($keywords != '') { $keywords .= ', '; } $keywords .= $keyword; } } return $keywords; } function strip_unwanted_chars($word) { //cannot yet handle MBCS in html_entity_decode BUG //global $charset; //$word = html_entity_decode($word, ENT_QUOTES, 'UTF-8'); //Workaround: $word = str_replace(' ',' ', $word); $word = str_replace('&','&', $word); $word = trim($word); $word = str_replace('(','', $word); $word = str_replace(')','', $word); $word = str_replace('.','', $word); $word = str_replace('!','', $word); $word = str_replace('?','', $word); $word = str_replace(':','', $word); $word = str_replace(',','', $word); return $word; } function get_keywords_from_html_in_array($html) { global $GO_CONFIG; $important_tags = array( '//h1', '//h2', '//h3', '//h4', '//h5', '//h6', '//strong', '//b', "//*[@style='font-weight: bold;']", '//i', "//*[@style='font-style: italic;']" ); require_once($GO_CONFIG->class_path.'xml/xpath.class.inc'); $xpath = new xpath(); $html = str_replace('\r','', $html); $html = str_replace('\n',' ', $html); $html = str_replace('>','> ', $html); $html = '<html>'.strip_tags($html, '<h1><h2><h3><h4><h5><h6><strong><span><ul><ol><li><b><i>').'</html>'; $important_words = array(); if($xpath->importFromString($html)) { $strings = array(); foreach($important_tags as $important_tag) { $nodes = $xpath->match($important_tag); foreach($nodes as $node) { $strings[] = strip_tags($xpath->getData($node)); } } $string = implode(' ', $strings); $important_words = array_merge($important_words, $this->get_keywords_from_string($string)); //Words that occur more then once $text = strip_tags($html); $words = explode(' ', $text); foreach($words as $word) { $word = $this->strip_unwanted_chars($word); if(strlen($word) > 0) { if( (strlen($word) > 6 || strtoupper($word) == $word) && count(array_keys($words, $word)) > 1 && !in_array(strtolower($word), $important_words)) { $important_words[] = strtolower($word); } } } } return $important_words; } function delete_user($user_id) { $cms = new cms(); $sql = "SELECT id FROM cms_sites WHERE user_id='$user_id'"; $this->query($sql); while($this->next_record()) { $cms->delete_site($this->f('id')); } $sql = "SELECT id FROM cms_templates WHERE user_id='$user_id'"; $this->query($sql); while($this->next_record()) { $cms->delete_template($this->f('id')); } $this->query("DELETE FROM cms_settings WHERE user_id='$user_id'"); }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -