📄 cms.class.inc
字号:
if($in_value && $escape_char == '"') { if(file_exists($GO_CONFIG->local_path.'cms/templates/'.$template_id.'/'.basename($url))) { $replacement['old'] = $url; $replacement['new'] = $GO_CONFIG->local_url.'cms/templates/'.$template_id.'/'.basename($url); $replacements[] = $replacement; } $url = ''; $end=true; break; }elseif(!$in_value) { $escape_char = '"'; $in_value = true; } break; case "'": if($in_value && $escape_char == "'") { if(file_exists($GO_CONFIG->local_path.'cms/templates/'.$template_id.'/'.basename($url))) { $replacement['old'] = $url; $replacement['new'] = $GO_CONFIG->local_url.'cms/templates/'.$template_id.'/'.basename($url); $replacements[] = $replacement; } $url = ''; $end=true; break; }elseif(!$in_value) { $escape_char = "'"; $in_value = true; } break; default: if($in_value) { $url .= $char; } break; } if($end) { $end=false; break; } } } } while($replacement = array_shift($replacements)) { //echo $replacement['old'].'- >'.$replacement['new'].'<br>'; $content = str_replace($replacement['old'], $replacement['new'], $content); } return $content; } 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 search_files($folder_id, $search_word) { //$search_word = strtoupper($search_word); //$search_word = '%'.$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'"; $allkeywords=array(); $keywords= explode(' ', $search_word); foreach($keywords as $keyword) { $keyword2 = htmlspecialchars($keyword); $sql_str='content LIKE \'%'.$keyword.'%\''; if($keyword2 != $keyword) { $sql_str='('.$sql_str.' OR content LIKE \'%'.$keyword2.'%\')'; } $allkeywords[]=$sql_str; } if(count($allkeywords)) { $sql .= ' AND '.implode(' AND ',$allkeywords); } $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)); } 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("\r", '', $html); $html = str_replace("\n",' ', $html); $html = str_replace('<p> </p>','', $html); $to_removed_array = array ( "'<h1[^>]*>.*?</h1>'si", "'<h2[^>]*>.*?</h2>'si", "'<h3[^>]*>.*?</h3>'si", "'<h4[^>]*>.*?</h4>'si", "'<h5[^>]*>.*?</h5>'si", "'<h6[^>]*>.*?</h6>'si"); $html = preg_replace($to_removed_array, '', $html); return strip_tags($html); } 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 = str_replace('>', '> ', $html); $html = str_replace('\r','', $html); $html = str_replace('\n',' ', $html); $html = preg_replace('/&[^;]*;/', '', $html); $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 = trim(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 htmlspecialchars($title); }elseif(!stristr($title, $word)) { if(!isset($first)) { $title .= ' - '; $first = true; }else { $title .= ' '; } $title .= trim($word); } } } } } } return htmlspecialchars($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 = str_replace('>', '> ', $html); $html = str_replace('\r','', $html); $html = str_replace('\n',' ', $html); $html = preg_replace('/&[^;]*;/', '', $html); $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) { $important_words = $this->get_keywords_from_string($xpath->getData($node)); foreach($important_words as $word) { if(strlen($description.' '.$word) > 250) { return htmlspecialchars($description); }elseif(!stristr($description, $word)) { if(strlen($description) > 0) { $description .= ' '; } $description .= trim($word); } } } } } return htmlspecialchars($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 .= trim($keyword); } } return htmlspecialchars($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 = preg_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 __on_user_delete($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 + -