functions.php
来自「在综合英文版XOOPS 2.09, 2.091, 2.092 的基础上正式发布X」· PHP 代码 · 共 1,693 行 · 第 1/4 页
PHP
1,693 行
} $port = isset($bits['port']) ? $bits['port'] : 80; // Try to connect to the server at $host $fp = fsockopen($host, $port, $errno, $errstr, 30); if (!$fp) { debug_fwrite($log, 'Couldn\'t open a connection to '.$host."\n\n"); continue; } // Send the GET request $request = "GET $path HTTP/1.1\r\nHost: $host\r\nUser-Agent: WordPress/$wp_version PHP/" . phpversion() . "\r\n\r\n"; ob_end_flush(); fputs($fp, $request); // Start receiving headers and content $contents = ''; $headers = ''; $gettingHeaders = true; $found_pingback_server = 0; while (!feof($fp)) { $line = fgets($fp, 4096); if (trim($line) == '') { $gettingHeaders = false; } if (!$gettingHeaders) { $contents .= trim($line)."\n"; $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote); $pingback_link_offset_squote = strpos($contents, $pingback_str_squote); } else { $headers .= trim($line)."\n"; $x_pingback_header_offset = strpos(strtolower($headers), $x_pingback_str); } if ($x_pingback_header_offset) { preg_match('#x-pingback: (.+)#is', $headers, $matches); $pingback_server_url = trim($matches[1]); debug_fwrite($log, "Pingback server found from X-Pingback header @ $pingback_server_url\n"); $found_pingback_server = 1; break; } if ($pingback_link_offset_dquote || $pingback_link_offset_squote) { $quote = ($pingback_link_offset_dquote) ? '"' : '\''; $pingback_link_offset = ($quote=='"') ? $pingback_link_offset_dquote : $pingback_link_offset_squote; $pingback_href_pos = @strpos($contents, 'href=', $pingback_link_offset); $pingback_href_start = $pingback_href_pos+6; $pingback_href_end = @strpos($contents, $quote, $pingback_href_start); $pingback_server_url_len = $pingback_href_end-$pingback_href_start; $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len); debug_fwrite($log, "Pingback server found from Pingback <link /> tag @ $pingback_server_url\n"); $found_pingback_server = 1; break; } } if (!$found_pingback_server) { debug_fwrite($log, "Pingback server not found\n\n*************************\n\n"); @fclose($fp); } else { debug_fwrite($log,"\n\nPingback server data\n"); // Assuming there's a "http://" bit, let's get rid of it $host_clear = substr($pingback_server_url, 7); // the trailing slash marks the end of the server name $host_end = strpos($host_clear, '/'); // Another clear cut $host_len = $host_end-$host_start; $host = substr($host_clear, 0, $host_len); debug_fwrite($log, 'host: '.$host."\n"); // If we got the server name right, the rest of the string is the server path $path = substr($host_clear,$host_end); debug_fwrite($log, 'path: '.$path."\n\n"); // Now, the RPC call $method = 'pingback.ping'; debug_fwrite($log, 'Page Linked To: '.$pagelinkedto."\n"); debug_fwrite($log, 'Page Linked From: '); $pagelinkedfrom = get_permalink($post_ID); debug_fwrite($log, $pagelinkedfrom."\n"); $client = new xmlrpc_client($path, $host, 80); $message = new xmlrpcmsg($method, array(new xmlrpcval($pagelinkedfrom), new xmlrpcval($pagelinkedto))); $result = $client->send($message); if ($result){ if (!$result->value()){ debug_fwrite($log, $result->faultCode().' -- '.$result->faultString()); } else { $value = xmlrpc_decode1($result->value()); if (is_array($value)) { $value_arr = ''; foreach($value as $blah) { $value_arr .= $blah.' |||| '; } debug_fwrite($log, $value_arr); } else { debug_fwrite($log, $value); } } } @fclose($fp); } } debug_fwrite($log, "\nEND: ".time()."\n****************************\n\r"); debug_fclose($log);}/** ** sanitise HTML attributes, remove frame/applet/*script/mouseovers,etc. tags ** so that this kind of thing cannot be done: ** This is how we can do <b onmouseover="alert('badbadbad')">bad stuff</b>! **/function sanitise_html_attributes($text) { $text = preg_replace('#(([\s"\'])on[a-z]{1,}|style|class|id)="(.*?)"#i', '$1', $text); $text = preg_replace('#(([\s"\'])on[a-z]{1,}|style|class|id)=\'(.*?)\'#i', '$1', $text); $text = preg_replace('#(([\s"\'])on[a-z]{1,}|style|class|id)[ \t]*=[ \t]*([^ \t\>]*?)#i', '$1', $text); $text = preg_replace('#([a-z]{1,})="(( |\t)*?)(javascript|vbscript|about):(.*?)"#i', '$1=""', $text); $text = preg_replace('#([a-z]{1,})=\'(( |\t)*?)(javascript|vbscript|about):(.*?)\'#i', '$1=""', $text); $text = preg_replace('#\<(\/{0,1})([a-z]{0,2})(frame|applet)(.*?)\>#i', '', $text); return $text;}function doGeoUrlHeader($posts) { if (count($posts) == 1) { // there's only one result see if it has a geo code $row = $posts[0]; $lat = $row->post_lat; $lon = $row->post_lon; $title = $row->post_title; if(($lon != null) && ($lat != null) ) { echo "<meta name=\"ICBM\" content=\"".$lat.", ".$lon."\" />\n"; echo "<meta name=\"DC.title\" content=\"".convert_chars(strip_tags(get_bloginfo("name")),"unicode")." - ".$title."\" />\n"; echo "<meta name=\"geo.position\" content=\"".$lat.";".$lon."\" />\n"; return; } } else { if(get_settings('use_default_geourl')) { // send the default here echo "<meta name=\"ICBM\" content=\"".get_settings('default_geourl_lat').", ".get_settings('default_geourl_lon')."\" />\n"; echo "<meta name=\"DC.title\" content=\"".convert_chars(strip_tags(get_bloginfo("name")),"unicode")."\" />\n"; echo "<meta name=\"geo.position\" content=\"".get_settings('default_geourl_lat').";".get_settings('default_geourl_lon')."\" />\n"; } }}function getRemoteFile($host,$path) { $fp = fsockopen($host, 80, $errno, $errstr); if ($fp) { fputs($fp,"GET $path HTTP/1.0\r\nHost: $host\r\n\r\n"); while ($line = fgets($fp, 4096)) { $lines[] = $line; } fclose($fp); return $lines; } else { return false; }}function pingGeoURL($blog_ID) { $ourUrl = get_settings('blodotgsping_url')."/index.php?p=".$blog_ID; $host="geourl.org"; $path="/ping/?p=".$ourUrl; getRemoteFile($host,$path);}/* wp_set_comment_status: part of otaku42's comment moderation hack changes the status of a comment according to $comment_status. allowed values: hold : set comment_approve field to 0 approve: set comment_approve field to 1 delete : remove comment out of database returns true if change could be applied returns false on database error or invalid value for $comment_status */function wp_set_comment_status($comment_id, $comment_status) { global $wpdb; switch($comment_status) { case 'hold': $query = "UPDATE {$wpdb->comments} SET comment_approved='0' WHERE comment_ID='$comment_id' LIMIT 1"; break; case 'approve': $query = "UPDATE {$wpdb->comments} SET comment_approved='1' WHERE comment_ID='$comment_id' LIMIT 1"; break; case 'delete': $query = "DELETE FROM {$wpdb->comments} WHERE comment_ID='$comment_id' LIMIT 1"; break; default: return false; } if ($wpdb->query($query)) { return true; } else { return false; }}/* wp_get_comment_status part of otaku42's comment moderation hack gets the current status of a comment returned values: "approved" : comment has been approved "unapproved": comment has not been approved "deleted ": comment not found in database a (boolean) false signals an error */function wp_get_comment_status($comment_id) { global $wpdb; $result = $wpdb->get_var("SELECT comment_approved FROM {$wpdb->comments} WHERE comment_ID='$comment_id' LIMIT 1"); if ($result == NULL) { return "deleted"; } else if ($result == "1") { return "approved"; } else if ($result == "0") { return "unapproved"; } else { return false; }}function wp_notify_postauthor($comment_id, $comment_type='comment') { global $blog_charset; global $wpdb; global $siteurl ; $comment = $wpdb->get_row("SELECT * FROM {$wpdb->comments} WHERE comment_ID='$comment_id' LIMIT 1"); $post = $wpdb->get_row("SELECT * FROM {$wpdb->posts} WHERE ID='$comment->comment_post_ID' LIMIT 1"); $user = $wpdb->get_row("SELECT * FROM {$wpdb->users} WHERE ID='$post->post_author' LIMIT 1"); if ('' == $user->user_email) return false; // If there's no email to send the comment to $comment_author_domain = gethostbyaddr($comment->comment_author_IP); $blogname = stripslashes(get_settings('blogname')); if ('comment' == $comment_type) { $notify_message = _LANG_F_NEW_COMMENT." #$comment->comment_post_ID ".stripslashes($post->post_title)."\r\n\r\n"; $notify_message .= "Author : $comment->comment_author (IP: $comment->comment_author_IP , $comment_author_domain)\r\n"; $notify_message .= "E-mail : $comment->comment_author_email\r\n"; $notify_message .= "URI : $comment->comment_author_url\r\n"; $notify_message .= "Whois : http://ws.arin.net/cgi-bin/whois.pl?queryinput=$comment->comment_author_IP\r\n"; /* if (function_exists('xoopschina_mb_convert_encoding')) { $notify_message .= "Comment:\r\n".stripslashes(xoopschina_mb_convert_encoding($comment->comment_content,$blog_charset,"utf-8"))."\r\n\r\n"; } else { $notify_message .= "Comment:\r\n".stripslashes($comment->comment_content)."\r\n\r\n"; } */ $notify_message .= "Comment:\r\n".stripslashes($comment->comment_content)."\r\n\r\n"; $notify_message .= _LANG_F_ALL_COMMENTS." \r\n"; $subject = '[' . $blogname . '] Comment: "' .stripslashes($post->post_title).'"'; } elseif ('trackback' == $comment_type) { $notify_message = _LANG_F_NEW_TRACKBACK." #$comment_post_ID ".stripslashes($post->post_title)."\r\n\r\n"; /* if (function_exists('xoopschina_mb_convert_encoding')) { $notify_message .= "Website: ".xoopschina_mb_convert_encoding($comment->comment_author,$blog_charset,"utf-8")." (IP: $comment->comment_author_IP , $comment_author_domain)\r\n"; } else { $notify_message .= "Website: ".$comment->comment_author." (IP: $comment->comment_author_IP , $comment_author_domain)\r\n"; } */ $notify_message .= "Website: ".$comment->comment_author." (IP: $comment->comment_author_IP , $comment_author_domain)\r\n"; $notify_message .= "URI : $comment->comment_author_url\r\n"; /* if (function_exists('xoopschina_mb_convert_encoding')) { $notify_message .= "Comment:\r\n".stripslashes(xoopschina_mb_convert_encoding($comment->comment_content,$blog_charset,"auto"))."\r\n\r\n"; } else { $notify_message .= "Comment:\r\n".stripslashes($comment->comment_content)."\r\n\r\n"; } */ $notify_message .= "Comment:\r\n".stripslashes($comment->comment_content)."\r\n\r\n"; $notify_message .= _LANG_F_ALL_TRACKBACKS." \r\n"; $subject = '[' . $blogname . '] Trackback: "' .stripslashes($post->post_title).'"'; } elseif ('pingback' == $comment_type) { $notify_message = _LANG_F_NEW_PINGBACK." #$comment_post_ID ".stripslashes($post->post_title)."\r\n\r\n"; $notify_message .= "Website: $comment->comment_author\r\n"; $notify_message .= "URI : $comment->comment_author_url\r\n"; /* if (function_exists('xoopschina_mb_convert_encoding')) { $notify_message .= "Excerpt: \n[...] ".xoopschina_mb_convert_encoding($original_context,$blog_charset,"auto")." [...]\r\n\r\n"; } else { $notify_message .= "Excerpt: \n[...] ".$original_context." [...]\r\n\r\n"; } */ $notify_message .= "Excerpt: \n[...] ".$original_context." [...]\r\n\r\n"; $notify_message .= _LANG_F_ALL_PINGBACKS." \r\n"; $subject = '[' . $blogname . '] Pingback: "' .stripslashes($post->post_title).'"'; } $notify_message .= get_permalink($comment->comment_post_ID) . '#comments'; if ('' == $comment->comment_author_email || '' == $comment->comment_author) { /* if (function_exists('xoopschina_mb_convert_encoding')) { $from = "From: \"". xoopschina_mb_convert_encoding($blogname,$blog_charset,"auto") ."\" <wordpress@" . $_SERVER['SERVER_NAME'] . '>'; } else { $from = "From: \"". $blogname ."\" <wordpress@" . $_SERVER['SERVER_NAME'] . '>'; } */ $from = "From: \"". $blogname ."\" <" . get_settings('admin_email') . '>'; } else { /* if (function_exists('xoopschina_mb_convert_encoding')) { $from = 'From: "' . stripslashes(xoopschina_mb_convert_encoding($comment->comment_author,$blog_charset,"auto")) . "\" <$comment->comment_author_email>"; } else { $from = 'From: "' . stripslashes($comment->comment_author) . "\" <$comment->comment_author_email>"; } */ $from = 'From: "' . stripslashes($comment->comment_author) . "\" <$comment->comment_author_email>"; } /* if (function_exists('mb_send_mail')) { mb_send_mail($user->user_email, $subject, $notify_message, $from); } else { @mail($user->user_email, $subject, $notify_message, $from); } */ @mail($user->user_email, $subject, $notify_message, $from); return true;}/* wp_notify_moderator notifies the moderator of the blog (usually the admin) about a new comment that waits for approval always returns true */function wp_notify_moderator($comment_id) { global $wpdb; global $siteurl ; $comment = $wpdb->get_row("SELECT * FROM {$wpdb->comments} WHERE comment_ID='$comment_id' LIMIT 1"); $post = $wpdb->get_row("SELECT * FROM {$wpdb->posts} WHERE ID='$comment->comment_post_ID' LIMIT 1"); $user = $wpdb->get_row("SELECT * FROM {$wpdb->users} WHERE ID='$post->post_author' LIMIT 1"); $comment_author_domain = gethostbyaddr($comment->comment_author_IP); $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM {$wpdb->comments} WHERE comment_approved = '0'"); $notify_message = _LANG_F_COMMENT_POST." #$comment->comment_post_ID ".stripslashes($post->post_title)._LANG_F_WAITING_APPROVAL."\r\n\r\n"; $notify_message .= "Author : $comment->comment_author (IP: $comment->comment_author_IP , $comment_author_domain)\r\n"; $notify_message .= "E-mail : $comment->comment_author_email\r\n"; $notify_message .= "URL : $comment->comment_author_url\r\n"; $notify_message .= "Whois : http://ws.arin.net/cgi-bin/whois.pl?queryinput=$comment->comment_author_IP\r\n"; $notify_message .= "Comment:\r\n".stripslashes($comment->comment_content)."\r\n\r\n"; $notify_message .= _LANG_F_APPROVAL_VISIT." $siteurl/wp-admin/post.php?action=mailapprovecomment&p=".$comment->comment_post_ID."&comment=$comment_id\r\n"; $notify_message .= _LANG_F_DELETE_VISIT." $siteurl/wp-admin/post.php?action=confirmdeletecomment&p=".$comment->comment_post_ID."&comment=$comment_id\r\n"; $notify_message .= $comments_waiting._LANG_F_PLEASE_VISIT."\r\n"; $notify_message .= "$siteurl/wp-admin/moderation.php\r\n"; $subject = '[' . stripslashes(get_settings('blogname')) . '] 审核: "' .stripslashes($post->post_title).'"'; $from = "From: ".get_settings('admin_email'); /* if (function_exists('mb_send_mail')) { mb_send_mail(get_settings('admin_email'), $subject, $notify_message, $from); } else { @mail(get_settings('admin_email'), $subject, $notify_message, $from); } */ @mail(get_settings('admin_email'), $subject, $notify_message, $from); return true;}// implementation of in_array that also should work on PHP3if (!function_exists('in_array')) { function in_array($needle, $haystack) { $needle = strtolower($needle); for ($i = 0; $i < count($haystack); $i++) { if (strtolower($haystack[$i]) == $needle) { return true; } } return false; }}function start_wp() { global $post, $id, $postdata, $authordata, $day, $preview, $page, $pages, $multipage, $more, $numpages; global $preview_userid,$preview_date,$preview_content,$preview_title,$preview_category,$preview_notify,$preview_make_clickable,$preview_autobr; global $pagenow; if (!$preview) { $id = $post->ID; } else { $id = 0; $postdata = array ( 'ID' => 0, 'Author_ID' => $_GET['preview_userid'], 'Date' => $_GET['preview_date'], 'Content' => $_GET['preview_content'], 'Excerpt' => $_GET['preview_excerpt'], 'Title' => $_GET['preview_title'], 'Category' => $_GET['preview_category'], 'Notify' => 1 ); } $authordata = get_userdata($post->post_author); $day = mysql2date('d.m.y', $post->post_date); $currentmonth = mysql2date('m', $post->post_date); $numpages = 1; if (!$page) $page = 1; if (isset($p)) $more = 1; $content = $post->post_content; if (preg_match('/<!--nextpage-->/', $post->post_content)) { if ($page > 1) $more = 1; $multipage = 1; $content = stripslashes($post->post_content); $content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?