'; echo '' . $title . ''; echo ''; $selfname = substr($_SERVER['PHP_SELF'], strrpos($_SERVER['PHP_SELF'], '/') + 1, -4); echo '
' . $title . '
来源: ' . str_replace('.php', '', $selfname) . '
' . $msg . '
'; echo ''; die(); } function markdown_convert($markdown) { // #,!,`,@cr,[] //行首: 标题# 对齐@ _HTML 无 独立div 图片!http://.jpg|ALT //行中: `强调` \uhttp://xxx|链接字\u if(substr($markdown,0, 4) != '[MD]') return $markdown; $mds = explode("\n", trim(substr($markdown,4))); $html = ''; foreach ($mds as $mi) { if (empty($mi)) { $html .= '
'; continue; } if ($mi[0] == '#') { //#一级标题 ##二级标题 ###三级标题 if (substr($mi,0, 3) == '###') $html .= '

' . markdown_convertcode(substr($mi,3)) . '

'; else if (substr($mi,0, 2) == '##') $html .= '

' . markdown_convertcode(substr($mi,2)) . '

'; else if ($mi[1] == 'c') $html .= '

' . markdown_convertcode(substr($mi,2)) . '

'; else if ($mi[1] == 'r') $html .= '

' . markdown_convertcode(substr($mi,2)) . '

'; else $html .= '

' . markdown_convertcode(substr($mi,1)) . '

'; } else if ($mi[0] == '@') {//c居中,r靠右 if ($mi[1] == 'c') $html .= '
' . markdown_convertcode(substr($mi,2)) . '
'; else if ($mi[1] == 'r') $html .= '
' . markdown_convertcode(substr($mi,2)) . '
'; else $html .= substr($mi,1); } else if ($mi[0] == '!') { //!图片地址 !图片地址|ALT文字 $mis = explode('|',$mi); $url = $mis[0]; $url = substr($url, 1); $alt = ''; if(isset($mis[1])) $alt = ' alt="' . str_replace('"',"",$mis[1]). '"'; $html .= '
'; } else if ($mi[0] == '_') { //HTML $html .= substr($mi, 1); } else { $html .= '
' . markdown_convertcode($mi) . '
'; } } return $html; } function markdown_convertcode($md) { $bcode = false; $md = str_replace(' ',' ',$md); $md = str_replace(' ',' ',$md); while (true) { $ind = strpos($md,'`'); if ($ind === false) break; $el = ''; if ($bcode) { $bcode = false; $el = ''; } else $bcode = true; $md = substr($md,0, $ind) . $el . substr($md,$ind + 1); } if ($bcode) $md .= ''; while (true) { $ind = strpos($md,'\\u'); if ($ind === false) break; $ind2 = strpos($md,'\\u', $ind+1); if ($ind2 === false) break; $mis = explode('|',substr($md,$ind + 2, $ind2-$ind-2)); $url = $mis[0]; $text = $url; if(isset($mis[1])) $text = $mis[1]; if($text[0] == '!'){ $html = ''; }else{ $html = '' . $text . ''; } $md = substr($md,0,$ind) . $html . substr($md,$ind2+2); } return $md; } function convertseowords($db, $content, $keystr = '') { $csql = new sql('a_web_word'); $seowords = $db->get($csql); $seo = array(); $max = rand(2, 5); shuffle($seowords); foreach ($seowords as $row) { if ($row['rank'] > rand(0, 100)) $seo[$row['name']] = $row['url']; } $repcnt = 0; foreach ($seo as $key => $val) { $keyind = 0; for($i=0;$i<5;$i++){ $ind = strpos($content, $key,$keyind); if ($ind === false) break; $tmp = substr($content, 0, $ind); $inda = strrpos($tmp, '', $inda); if ($indb === false){ //包含 $keyind = $ind + 1; continue; } } $inda = strrpos($tmp, ' alt="'); if ($inda !== false) { $indb = strpos($tmp, '"', $inda+6); if ($indb === false){ //包含 $keyind = $ind + 1; continue; } } break; } if ($ind === false) continue; $content = substr_replace($content, '' . $key . '', $ind, strlen($key)); $repcnt++; if ($repcnt >= $max) break; } if (!empty($keystr)) { $keystr = str_replace(',', ',', $keystr); $keystr = str_replace(';', ',', $keystr); $keystr = str_replace(';', ',', $keystr); $keys = explode(',', $keystr); foreach ($keys as $key) { if (empty($key)) continue; $keyind = 0; for($i=0;$i<5;$i++){ $ind = strpos($content, $key,$keyind); if ($ind === false) break; $tmp = substr($content, 0, $ind); $inda = strrpos($tmp, ''); if ($inda !== false) { $indb = strpos($tmp, '', $inda); if ($indb === false){ //包含 $keyind = $ind + 1; continue; } } $inda = strrpos($tmp, ' alt="'); if ($inda !== false) { $indb = strpos($tmp, '"', $inda+6); if ($indb === false){ //包含 $keyind = $ind + 1; continue; } } break; } if ($ind === false) continue; $content = substr_replace($content, '' . $key . '', $ind, strlen($key)); } } return $content; } function getwebtitle($db, $id) { $csql = new sql('a_web_seo'); $csql->where('url', $_SERVER['REQUEST_URI']); $webtitrow = $db->getone($csql); if (is_array($webtitrow)) { if ($webtitrow['pagecount'] < 1) $webtitrow['pagecount'] = 20; return $webtitrow; } $csql = new sql('a_web_seo'); $csql->where('id', $id); $webtitrow = $db->getone($csql); if (is_array($webtitrow)) { if ($webtitrow['pagecount'] < 1) $webtitrow['pagecount'] = 20; return $webtitrow; } $webtitrow = array(); $webtitrow['name'] = '众产平台'; $webtitrow['keys'] = '众产平台,众产事业'; $webtitrow['desc'] = '众产事业网站'; $webtitrow['pagecount'] = 30; return $webtitrow; } function titrep($str, $dat, $content = '') { foreach ($dat as $key => $val) { $str = str_replace('{' . $key . '}', $val, $str); } $str = str_replace('农业农业', '农业', $str); if (empty($content)) return $str; $ind = strpos($str, '{content'); if ($ind === false) return $str; $ind2 = strpos($str, '}', $ind); if ($ind2 === false) return $str; if ($ind2 - $ind == 8) { return str_replace('{content}', leftchinese($content), $str); } else { $len = substr($str, $ind + 8, $ind2 - $ind - 8); return str_replace(substr($str, $ind, $ind2 - $ind + 1), leftchinese($content, $len), $str); } } function leftchinese($content, $len = 0) { $content = htmlspecialchars_decode($content); $content = str_replace(" ", "", $content); $content = str_replace("\n", "", $content); $content = str_replace("\r", "", $content); $content = str_replace("\t", "", $content); $content = strip_tags($content); $content = trim($content); if ($len <= 0) return $content; if (mb_strlen($content, 'utf-8') > $len) return mb_substr($content, 0, $len, "utf-8"); return $content; } function showpage($count, $pageno, $pagecount, $pageurl) { if ($count <= 0) { // 1...3,4,5,6,7,8 $isend = (-$count < $pagecount); //if($pageno < 20) $isend = false; $epage = $pageno + 2; $spage = $pageno - 6; if ($isend) $epage = $pageno; if ($spage < 1) $spage = 1; echo '上页'; echo '下页'; if ($spage > 1) echo '1'; if ($spage > 2) echo '...'; for ($i = $spage; $i <= $epage; $i++) echo '' . $i . ''; } else { //1...3,4,5,6,7...n $epage = $pageno + 4; $spage = $pageno - 4; $pagemax = ceil($count / $pagecount); if ($spage < 1) $spage = 1; if ($epage > $pagemax) $epage = $pagemax; echo '上页'; echo '= $pagemax ? ' class="disabled"' : " href=\"" . $pageurl . ($pageno + 1) . "/\"") . '>下页'; if ($spage > 1) echo '1'; if ($spage > 2) echo '...'; for ($i = $spage; $i <= $epage; $i++) echo '' . $i . ''; if ($epage < $pagemax - 1) echo '...'; if ($epage < $pagemax) echo '' . $pagemax . ''; } } function fillsource($str) { $source = explode('|', $str); if (!isset($source[1])) return $source[0]; else return '' . '转自' . $source[0] . ''; } function showh1($webtit, $artrow) { $h1 = titrep($webtit['h1'], $artrow); $htip = titrep($webtit['htip'], $artrow); if (empty($h1)) echo ''; else if ($h1[0] == '<') echo $h1; else echo '

' . $h1 . '

'; if (empty($htip)) echo ''; else if ($htip[0] == '<') echo $htip; else echo '
' . $htip . '
'; } function markdown_fromhtml($content, $baseurl) { $html = html::str_get_html($content); if ($html === false || $html === null) return ''; $md = ''; _html2md_child($baseurl, $html->childNodes(), $md); return $md; } function _html2md_child($baseurl, $childs, &$md) { if ($childs === null) return; foreach ($childs as $child) { if ($child->tag == 'table') { $md .= '_' . str_replace("\n", "", $child->outertext) . "\n"; } else if ($child->tag == 'img') { if (empty(@$child->attr['src'])) continue; $md .= '!' . urljoin($child->attr['src'], $baseurl) . '|' . @$child->attr['alt'] . "\n"; } else if ($child->tag == 'ul') { //clog('find ul'); } else { $divps = $child->find('div,p'); if (count($divps) > 0) { $txt = trim($child->plaintext); _html2md_child($baseurl, $child->childNodes(), $md); } else { $divimgs = $child->find('img'); foreach ($divimgs as $divimg) { if (empty(@$divimg->attr['src'])) continue; $md .= '!' . urljoin($divimg->attr['src'], $baseurl) . '|' . @$divimg->attr['alt'] . "\n"; } $txtpre = ''; $txt = $child->plaintext; $txt = str_replace(' ', '', $txt); $txt = trim($txt); $style = @$child->attr['style'] . ',' . @$child->attr['align']; if (strpos($style, 'right') !== false) $txtpre = '@r'; else if (strpos($style, 'center') !== false) $txtpre = '@c'; if (!empty($txt)) { $txts = explode("\n", $txt); foreach ($txts as $tx) { $tx = trim($tx); while (true) { if (substr($tx, 0, 3) != ' ') break; $tx = substr($tx, 3); } if (empty($tx)) continue; $md .= $txtpre . $tx . "\n"; } } } } } } //相对网址转绝对网址 function urljoin($srcurl, $baseurl) { $srcinfo = parse_url($srcurl); if (isset($srcinfo['scheme'])) { return $srcurl; } $baseinfo = parse_url($baseurl); $url = $baseinfo['scheme'] . '://' . $baseinfo['host']; if (substr($srcinfo['path'], 0, 1) == '/') { $path = $srcinfo['path']; } else { $path = dirname($baseinfo['path']) . '/' . $srcinfo['path']; } $rst = array(); $path_array = explode('/', $path); if (!$path_array[0]) { $rst[] = ''; } foreach ($path_array as $key => $dir) { if ($dir == '..') { if (end($rst) == '..') { $rst[] = '..'; } elseif (!array_pop($rst)) { $rst[] = '..'; } } elseif ($dir && $dir != '.') { $rst[] = $dir; } } if (!end($path_array)) { $rst[] = ''; } $url .= implode('/', $rst); return str_replace('\\', '/', $url); }