functions.ini.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 693 行 · 第 1/2 页
PHP
693 行
if(!isset($post_cache_views[$post_id])){
$sql = "SELECT post_views FROM " . $GLOBALS["xoopsDB"]->prefix("wp_views") . " WHERE post_id=$post_id";
if (!$result = $GLOBALS["xoopsDB"]->query($sql)) {
$post_cache_views[$post_id] = 0;
}else{
$row = $GLOBALS["xoopsDB"]->fetchArray($result);
$post_cache_views[$post_id] = $row["post_views"];
}
}
return sprintf(__('Views: %d'), intval($post_cache_views[$post_id]));
}
function onaction_set_the_views(&$content) {
if ( empty($_GET["feed"]) && empty($GLOBALS["feed"]) && empty($GLOBALS["doing_trackback"]) && empty($GLOBALS["doing_rss"]) && empty($_POST) && is_single() ){
set_the_views();
}
return $content;
}
// Set post views given a post ID or post object.
function set_the_views($post_id = 0) {
static $views;
$post_id = intval($post_id);
if ( empty($post_id) && isset($GLOBALS['post']) ){
$post_id = $GLOBALS['post']->ID;
}
if($post_id==0 || !empty($views[$post_id])) return null;
$sql = "SELECT post_views FROM " . $GLOBALS["xoopsDB"]->prefix("wp_views") . " WHERE post_id=$post_id";
$exist = false;
if ($result = $GLOBALS["xoopsDB"]->query($sql)) {
while($row = $GLOBALS["xoopsDB"]->fetchArray($result)){
$exist = true;
break;
}
}
if($exist){
$sql = "UPDATE " . $GLOBALS["xoopsDB"]->prefix("wp_views") . " SET post_views=post_views+1 WHERE post_id=$post_id";
}else{
$sql = "INSERT INTO " . $GLOBALS["xoopsDB"]->prefix("wp_views") . " (post_id, post_views) VALUES ($post_id, 1)";
}
if ($result = $GLOBALS["xoopsDB"]->queryF($sql)) {
$views[$post_id] = 1;
}
return true;
}
function onaction_edit_post($post_id=0)
{
if(function_exists("flickr_clear_cache")){ // tricky!
flickr_clear_cache($post_id);
}
return true;
}
function onaction_gettext($text_translated, $text = "")
{
if(empty($text_translated)) return $text;
$blog_charset = wp_blog_charset();
return XoopsLocal::convert_encoding($text_translated, $blog_charset, WP_MO_CHARSET);
}
// Insert user information into wp-users when he publishes his first article
// adapted from wp-includes/registration-functions.php
function onaction_wp_register_user($post_id=null)
{
global $wpdb, $table_prefix;
$post = get_post($post_id);
$user = get_userdata($post->post_author, true);
if(!$wpdb->get_results("SELECT user_login FROM $wpdb->users WHERE ID = $user->ID LIMIT 1")){
$result = $wpdb->query("INSERT INTO $wpdb->users
( ID, user_login, display_name, user_nicename )
VALUES
( $user->ID, '".addslashes($user->user_login)."', '".addslashes($user->display_name)."', '".addslashes($user->user_nicename)."' )"
);
wp_cache_delete($user->ID, 'users');
wp_cache_delete($user->user_login, 'userlogins');
do_action('user_register', $user->ID);
}
return $user->ID;
}
function the_author_link_xoops($idmode='') {
global $id, $authordata;
if(!isset($authordata)){
global $wp_query;
$author = empty($wp_query->query_vars['author'])?(empty($wp_query->query_vars['author_name'])?0:$wp_query->query_vars['author_name']):$wp_query->query_vars['author'];
$authordata = get_userdata($author);
}
echo '<a href="' . XOOPS_URL. '/userinfo.php?uid=' . $authordata->ID . '" title="' . wp_specialchars(the_author($idmode, false)) . '">' . the_author($idmode, false) . '</a>';
}
// handler IO between XOOPS and WordPress
function wp_xoops_filter()
{
add_action("gettext", "onaction_gettext");
add_action("publish_post", "onaction_wp_register_user");
add_action("edit_post", "onaction_edit_post");
add_action("the_content", "onaction_set_the_views");
if(!empty($GLOBALS["xoopsModuleConfig"]["do_tag"])) {
require_once dirname(__FILE__)."/functions.tag.php";
add_action("publish_post", "onaction_set_tags");
add_action("edit_post", "onaction_set_tags");
add_action("the_content", "onaction_get_tags");
}
add_filter("the_content", "wp_filter_xoopsdecode", 1);
add_filter("get_the_excerpt", "wp_filter_xoopsdecode", 1);
add_filter("comment_text", "wp_filter_xoopsdecode", 1);
add_filter('pre_option_siteurl', "onaction_pre_option_siteurl");
add_filter('pre_option_home', "onaction_pre_option_home");
add_filter('option_home', "onaction_home");
add_filter('option_siteurl', "onaction_siteurl");
add_filter('option_blog_charset', "onaction_blog_charset");
add_filter('template_directory', "set_template_directory");
$action_list = array("option_blogdescription", "option_blogname", "the_title_rss", "the_content", "get_the_excerpt", "comment_author_rss", "get_comment_text", "the_category_rss");
foreach($action_list as $action){
add_filter($action, "onaction_rss_encoding");
}
}
function wp_filter_xoopsdecode(&$text)
{
$patterns[] = "/\[quote]/sU";
$replacements[] = '<div class="xoopsQuote"><blockquote>';
$patterns[] = "/\[\/quote]/sU";
$replacements[] = '</blockquote></div>';
$text = preg_replace($patterns, $replacements, $text);
$myts =& MyTextSanitizer::getInstance();
$text = $myts->displayTarea($text, $html = 1, $smiley = 1, $xcode = 1, $image = 1, $br = 1);
return $text;
}
function onaction_rss_encoding($var="")
{
static $action;
$action = isset($action)?$action:( !empty($_GET["feed"]) || !empty($GLOBALS["feed"]) || !empty($GLOBALS["doing_trackback"]) || !empty($GLOBALS["doing_rss"]) );
return ($action)?encoding_wp2rss($var):$var;
}
function wp_upload_dir()
{
if($path = trim(get_settings('upload_path'))){
$dir = XOOPS_UPLOAD_PATH."/".$path;
$url = XOOPS_UPLOAD_URL."/".$path;
}
elseif ( defined('UPLOADS') ){
$dir = XOOPS_UPLOAD_PATH."/".UPLOADS;
$url = XOOPS_UPLOAD_URL."/".UPLOADS;
}
else{
$dir = XOOPS_UPLOAD_PATH."/".WP_BLOG_DIRNAME;
$url = XOOPS_UPLOAD_URL."/".WP_BLOG_DIRNAME;
}
// Give the new dirs the same perms as XOOPS_UPLOAD_PATH.
$stat = stat(XOOPS_UPLOAD_PATH);
$dir_perms = $stat['mode'] & 0000777; // Get the permission bits.
if ( get_settings('uploads_use_yearmonth_folders')) {
// Generate the yearly and monthly dirs
$time = current_time( 'mysql' );
$y = substr( $time, 0, 4 );
$m = substr( $time, 5, 2 );
$dir = $dir . "/$y/$m";
$url = $url . "/$y/$m";
}
// Make sure we have an uploads dir
if ( ! wp_mkdir_p( $dir ) ) {
$message = sprintf(__('Unable to create directory %s. Is its parent directory writable by the server?'), $dir);
return array('error' => $message);
}
$uploads = array('path' => $dir, 'url' => $url, 'error' => false);
return apply_filters('upload_dir', $uploads);
}
function onaction_pre_option_siteurl($var="")
{
return onaction_siteurl($var);
}
function onaction_pre_option_home($var="")
{
return onaction_siteurl($var);
}
function onaction_home($var="")
{
return onaction_siteurl($var);
}
function onaction_siteurl($var="")
{
return XOOPS_URL."/modules/".WP_BLOG_DIRNAME;
}
function onaction_blog_charset($charset="")
{
if(!empty($GLOBALS['blog_charset_skip_filter'])){
$GLOBALS['blog_charset_skip_filter']=false;
}elseif ( !empty($_GET["feed"]) || !empty($GLOBALS["feed"]) || !empty($GLOBALS["doing_trackback"]) || !empty($GLOBALS["doing_rss"]) ){
$charset = wp_rss_charset();
}else{
$charset = wp_blog_charset();
}
return $charset;
}
// Set the template style
// Convert _POST from XOOPS
function set_template_directory($template_dir="", $template="")
{
// Ideally the following treatment should be done by setting "accept-charset" attribute in "form" tag, however its compatibility with browsers is unexpectable
if(!empty($_POST["post_from_xoops"])){
unset($_POST["post_from_xoops"]);
foreach($_POST as $key=>$val){
if(is_array($_POST[$key])){
foreach(array_keys($_POST[$key]) as $_key){
$_POST[$key][$_key] = encoding_xoops2wp($_POST[$key][$_key]);
}
}else{
$_POST[$key] = encoding_xoops2wp($val);
}
}
}
switch($GLOBALS['xoopsModuleConfig']["style"]){
// fixed as XOOPS
case 1:
$style = 1;
break;
// fixed as WP
case 2:
$style = 0;
break;
// selectable
default:
$style = isset($_GET["style"])?$_GET["style"]:(isset($_COOKIE["wp_style"])?$_COOKIE["wp_style"]:"");
$style = ($style=="w")?0:1;
if(isset($_GET["style"])){
setcookie("wp_style", $_GET["style"]);
}
break;
}
if( empty($style) ){
return $template_dir;
}else{
/*
if(!empty($GLOBALS["xoopsModuleConfig"]['theme_set']) && $GLOBALS["xoopsOption"]["pagetype"] != "admin" && is_object($GLOBALS['xoopsModule']) && $GLOBALS['xoopsModule']->getVar("dirname") == "wordpress"){
//$GLOBALS["xoopsConfig"]['theme_set'] = $GLOBALS["xoopsModuleConfig"]['theme_set'];
}
*/
return ABSPATH . "templates/wordpress";
}
}
function wp_the_excerpt()
{
if(empty($GLOBALS['post']->post_excerpt)) return;
ob_start();
the_excerpt();
$excerpt = ob_get_contents();
ob_end_clean();
echo "[".__("Excerpt")."]: ".$excerpt;
}
function wp_the_content($echo = true)
{
ob_start();
if(empty($GLOBALS['xoopsModuleConfig']['show_excerpt'])) {
the_content(__('(more...)'));
}else{
the_excerpt();
echo '<a href="'. get_permalink() . "\">".__('(more...)').'</a>';
}
$content = ob_get_contents();
ob_end_clean();
if(empty($echo)) return $content;
echo $content;
}
function wp_get_moduleid()
{
static $mid;
if(!empty($mid)){
return $mid;
}
if(is_object($GLOBALS["xoopsModule"]) && $GLOBALS["xoopsModule"]->getVar("dirname") == WP_BLOG_DIRNAME){
$mid = $GLOBALS["xoopsModule"]->getVar("mid");
}else{
$module_handler = &xoops_gethandler('module');
$module = $module_handler->getByDirname(WP_BLOG_DIRNAME);
$mid = $module->getVar("mid");
unset($module);
}
return $mid;
}
function wp_get_user_profile($format = "s", $uid = null)
{
global $xoopsUser;
if($uid === null) $user =& $xoopsUser;
elseif($uid >0){
$member_handler =& xoops_gethandler('member');
$user =& $member_handler->getUser($uid);
}else{
return null;
}
return is_object($user)? encoding_xoops2wp($user->getVar("bio", $format)) : null;
}
/**
* Enable multi-user mode
*
* Available features:
* Each author has a separate page;
* All contents including posts/comments are author oriented.
*
* Limitations (TODO):
* Category structure is controlled by admin only
* An author does not have the possibility to have his/her own templates
* Link management is module-wide, not per author
*
*/
function wp_xoops_ismu()
{
return !empty($GLOBALS["xoopsModuleConfig"]["enable_mu"]);
/*
(defined("WP_XOOPS_MU") && constant("WP_XOOPS_MU"))
*/
}
?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?