functions.php
来自「在综合英文版XOOPS 2.09, 2.091, 2.092 的基础上正式发布X」· PHP 代码 · 共 1,693 行 · 第 1/4 页
PHP
1,693 行
$content = str_replace("\n<!--nextpage-->", '<!--nextpage-->', $content); $content = str_replace("<!--nextpage-->\n", '<!--nextpage-->', $content); $pages = explode('<!--nextpage-->', $content); $numpages = count($pages); } else { $pages[0] = stripslashes($post->post_content); $multipage = 0; } return true;}function is_new_day() { global $day, $previousday; if ($day != $previousday) { return(1); } else { return(0); }}// Filters: these are the core of WP's plugin architecturefunction apply_filters($tag, $string) { global $wp_filter;; if (isset($wp_filter['all'])) { foreach ($wp_filter['all'] as $priority => $functions) { if (isset($wp_filter[$tag][$priority])) $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], $wp_filter[$tag][$priority]); else $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], array()); $wp_filter[$tag][$priority] = array_unique($wp_filter[$tag][$priority]); } } if (isset($wp_filter[$tag])) { ksort($wp_filter[$tag]); foreach ($wp_filter[$tag] as $priority => $functions) { foreach($functions as $function) {// if ($tag == "the_content") echo $function."<br>\n"; $string = $function($string); } } } return $string;}function add_filter($tag, $function_to_add, $priority = 10) { global $wp_filter; // So the format is wp_filter['tag']['array of priorities']['array of functions'] if (!@in_array($function_to_add, $wp_filter[$tag]["$priority"])) { $wp_filter[$tag]["$priority"][] = $function_to_add; } return true;}function remove_filter($tag, $function_to_remove, $priority = 10) { global $wp_filter;; if (@in_array($function_to_remove, $wp_filter[$tag]["$priority"])) { $new_function_list = array(); foreach ($wp_filter[$tag]["$priority"] as $function) { if ($function_to_remove != $function) { $new_function_list[] = $function; } } if (!count($new_function_list)) { if (!empty($wp_filter[$tag]["$priority"])) { unset($wp_filter[$tag]["$priority"]); } } else { $wp_filter[$tag]["$priority"] = $new_function_list; } } //die(var_dump($wp_filter)); return true;}// The *_action functions are just aliases for the *_filter functions, they take special strings instead of generic contentfunction do_action($tag, $string) { return apply_filters($tag, $string);}function add_action($tag, $function_to_add, $priority = 10) { add_filter($tag, $function_to_add, $priority);}function remove_action($tag, $function_to_remove, $priority = 10) { remove_filter($tag, $function_to_remove, $priority);}function wp_head() { do_action('wp_head', '');}function mb_conv($str,$to,$from){ if (function_exists('xoopschina_mb_convert_encoding')) { $retstr = xoopschina_mb_convert_encoding($str,$to,$from); } else { $retstr = $str; } return $retstr;}/* rewrite_rules * Construct rewrite matches and queries from permalink structure. * matches - The name of the match array to use in the query strings. * If empty, $1, $2, $3, etc. are used. * Returns an associate array of matches and queries. */function rewrite_rules($matches = '', $permalink_structure = '') { function preg_index($number, $matches = '') { $match_prefix = '$'; $match_suffix = ''; if (! empty($matches)) { $match_prefix = '$' . $matches . '['; $match_suffix = ']'; } return "$match_prefix$number$match_suffix"; } $rewrite = array(); if (empty($permalink_structure)) { $permalink_structure = get_settings('permalink_structure'); if (empty($permalink_structure)) { return $rewrite; } } $rewritecode = array( '%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', '%postname%', '%post_id%' ); $rewritereplace = array( '([0-9]{4})?', '([0-9]{1,2})?', '([0-9]{1,2})?', '([0-9]{1,2})?', '([0-9]{1,2})?', '([0-9]{1,2})?', '([_0-9a-z-]+)?', '([0-9]+)?' ); $queryreplace = array ( 'year=', 'monthnum=', 'day=', 'hour=', 'minute=', 'second=', 'name=', 'p=' ); $match = str_replace('/', '/?', $permalink_structure); $match = preg_replace('|/[?]|', '', $match, 1); $match = str_replace($rewritecode, $rewritereplace, $match); $match = preg_replace('|[?]|', '', $match, 1); $feedmatch = trailingslashit(str_replace('?/?', '/', $match)); $trackbackmatch = $feedmatch; preg_match_all('/%.+?%/', $permalink_structure, $tokens); $query = 'index.php?'; $feedquery = 'wp-feed.php?'; $trackbackquery = 'wp-trackback.php?'; for ($i = 0; $i < count($tokens[0]); ++$i) { if (0 < $i) { $query .= '&'; $feedquery .= '&'; $trackbackquery .= '&'; } $query_token = str_replace($rewritecode, $queryreplace, $tokens[0][$i]) . preg_index($i+1, $matches); $query .= $query_token; $feedquery .= $query_token; $trackbackquery .= $query_token; } ++$i; // Add post paged stuff $match .= '([0-9]+)?/?$'; $query .= '&page=' . preg_index($i, $matches); // Add post feed stuff $feedregex = '(feed|rdf|rss|rss2|atom)/?$'; $feedmatch .= $feedregex; $feedquery .= '&feed=' . preg_index($i, $matches); // Add post trackback stuff $trackbackregex = 'trackback/?$'; $trackbackmatch .= $trackbackregex; // Site feed $sitefeedmatch = 'feed/?([_0-9a-z-]+)?/?$'; $sitefeedquery = 'wp-feed.php?feed=' . preg_index(1, $matches); // Site comment feed $sitecommentfeedmatch = 'comments/feed/?([_0-9a-z-]+)?/?$'; $sitecommentfeedquery = 'wp-feed.php?feed=' . preg_index(1, $matches) . '&withcomments=1'; // Code for nice categories and authors, currently not very flexible $front = substr($permalink_structure, 0, strpos($permalink_structure, '%')); if ( '' == get_settings('category_base') ) $catmatch = $front . 'category/'; else $catmatch = get_settings('category_base') . '/'; $catmatch = preg_replace('|^/+|', '', $catmatch); $catfeedmatch = $catmatch . '(.*)/' . $feedregex; $catfeedquery = 'wp-feed.php?category_name=' . preg_index(1, $matches) . '&feed=' . preg_index(2, $matches); $catmatch = $catmatch . '?(.*)'; $catquery = 'index.php?category_name=' . preg_index(1, $matches); $authormatch = $front . 'author/'; $authormatch = preg_replace('|^/+|', '', $authormatch); $authorfeedmatch = $authormatch . '(.*)/' . $feedregex; $authorfeedquery = 'wp-feed.php?author_name=' . rawurlencode(preg_index(1, $matches)) . '&feed=' . preg_index(2, $matches); $authormatch = $authormatch . '?(.*)'; $authorquery = 'index.php?author_name=' . rawurlencode(preg_index(1, $matches)); $rewrite = array( $catfeedmatch => $catfeedquery, $catmatch => $catquery, $authorfeedmatch => $authorfeedquery, $authormatch => $authorquery, $match => $query, $feedmatch => $feedquery, $trackbackmatch => $trackbackquery, $sitefeedmatch => $sitefeedquery, $sitecommentfeedmatch => $sitecommentfeedquery ); return $rewrite;}function get_posts($args) { global $wpdb, $tableposts; parse_str($args, $r); if (!isset($r['numberposts'])) $r['numberposts'] = 5; if (!isset($r['offset'])) $r['offset'] = 0; // The following not implemented yet if (!isset($r['category'])) $r['category'] = ''; if (!isset($r['orderby'])) $r['orderby'] = ''; if (!isset($r['order'])) $r['order'] = ''; $now = current_time('mysql'); $posts = $wpdb->get_results("SELECT DISTINCT * FROM $tableposts WHERE post_date <= '$now' AND (post_status = 'publish') GROUP BY $tableposts.ID ORDER BY post_date DESC LIMIT " . $r['offset'] . ',' . $r['numberposts']); return $posts;}function check_comment($author, $email, $url, $comment, $user_ip) { if (1 == get_settings('comment_moderation')) return false; // If moderation is set to manual if ( (count(explode('http:', $comment)) - 1) >= get_settings('comment_max_links') ) return false; // Check # of external links if ('' == trim( get_settings('moderation_keys') ) ) return true; // If moderation keys are empty $words = explode("\n", get_settings('moderation_keys') ); foreach ($words as $word) { $word = trim($word); $pattern = "#$word#i"; if ( preg_match($pattern, $author) ) return false; if ( preg_match($pattern, $email) ) return false; if ( preg_match($pattern, $url) ) return false; if ( preg_match($pattern, $comment) ) return false; if ( preg_match($pattern, $user_ip) ) return false; } return true;}// Check for hacks file if the option is enabledif (get_settings('hack_file')) { if (file_exists(XOOPS_ROOT_PATH.'/modules/wordpress/my-hacks.php')) require(XOOPS_ROOT_PATH.'/modules/wordpress/my-hacks.php');}function get_xoops_option($dirname,$conf_name) { global $xoopsDB; $query = "SELECT mid FROM ".$xoopsDB->prefix('modules')." WHERE dirname='".$dirname."' "; $result = $xoopsDB->query($query); $record= $xoopsDB->fetcharray($result); $mid = $record['mid']; $query = "SELECT conf_value,conf_valuetype FROM ".$xoopsDB->prefix('config')." WHERE conf_modid=".$mid." AND conf_name='".$conf_name."' "; $result = $xoopsDB->query($query); $record= $xoopsDB->fetcharray($result); $value = $record['conf_value']; $valuetype = $record['conf_valuetype']; switch ($valuetype) { case 'int': return intval($value); break; case 'array': return unserialize($value); case 'float': return (float)$value; break; case 'textarea': return $value; default: return $value; break; } return($value);}function block_style_get($echo = 'true') {global $xoopsConfig; if (file_exists(XOOPS_ROOT_PATH.'/modules/wordpress/themes/'.$xoopsConfig['theme_set'].'/wp-blocks.css.php')) { $themes = $xoopsConfig['theme_set']; } else { $themes = "default"; } $wp_block_style=""; include_once(XOOPS_ROOT_PATH."/modules/wordpress/themes/".$themes."/wp-blocks.css.php"); if ($echo) { if (trim($wp_block_style) != "") { echo <<< EOD<style type="text/css" media="screen"> <!-- $wp_block_style --></style>EOD; } } else { return trim($wp_block_style); }}function wp_refcheck($offset = "", $redirect = true) { global $siteurl; $ref = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $_ENV['HTTP_REFERER']; if ($ref == '') { if ($redirect) { if (defined('XOOPS_URL')) { //XOOPS Module mode redirect_header($siteurl, 1, "You cannot update Database contents.(Could not detect HTTP_REFERER)"); } else { header("Location: $siteurl"); } } return false; } if (strpos($ref, $siteurl.$offset) !== 0 ) { if ($redirect) { if (defined('XOOPS_URL')) { //XOOPS Module mode redirect_header($siteurl, 1, "You cannot update Database contents.(HTTP_REFERER is not valid site.)"); } else { header("Location: $siteurl"); } } return false; } return true;}function wp_get_rss_charset() { global $blog_charset; if (function_exists('xoopschina_mb_convert_encoding')) { if ($blog_charset != 'iso-8859-1') { $rss_charset = 'utf-8'; } else { $rss_charset = $blog_charset; } }else{ $rss_charset = $blog_charset; } return $rss_charset;}function wp_convert_rss_charset($srcstr) { global $blog_charset; $rss_charset = wp_get_rss_charset(); if ($blog_charset != $rss_charset) { return xoopschina_mb_convert_encoding($srcstr, $rss_charset, $blog_charset); } else { return $srcstr; }}function trailingslashit($string) { if ( '/' != substr($string, -1)) { $string .= '/'; } return $string;}function get_version() { $old_stat=error_reporting(0); include (dirname(dirname(__FILE__))."/xoops_version.php"); error_reporting($old_stat); return $modversion['version'];}?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?