functions.php
来自「在综合英文版XOOPS 2.09, 2.091, 2.092 的基础上正式发布X」· PHP 代码 · 共 1,693 行 · 第 1/4 页
PHP
1,693 行
<?phpif (!function_exists('_')) { function _($string) { return $string; }}if (!function_exists('floatval')) { function floatval($string) { return ((float) $string); }}/* functions... */function &wp_getWysiwygForm($wp_form, $caption, $name, $value = "", $width = '100%', $height = '400px'){ include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php"; $editor = false; switch(strtolower($wp_form)){ case "spaw": if (is_readable(XOOPS_ROOT_PATH . "/class/spaw/formspaw.php")) { include_once(XOOPS_ROOT_PATH . "/class/spaw/formspaw.php"); $editor = new XoopsFormSpaw($caption, $name, $value, $width, $height); } break; case "fck": if ( is_readable(XOOPS_ROOT_PATH . "/class/fckeditor/formfckeditor.php")) { include_once(XOOPS_ROOT_PATH . "/class/fckeditor/formfckeditor.php"); $editor = new XoopsFormFckeditor($caption, $name, $value, $width, $height); } break; case "htmlarea": if ( is_readable(XOOPS_ROOT_PATH . "/class/htmlarea/formhtmlarea.php")) { include_once(XOOPS_ROOT_PATH . "/class/htmlarea/formhtmlarea.php"); $editor = new XoopsFormHtmlarea($caption, $name, $value, $width, $height); } break; case "koivi": if ( is_readable(XOOPS_ROOT_PATH . "/class/wysiwyg/formwysiwygtextarea.php")) { include_once(XOOPS_ROOT_PATH . "/class/wysiwyg/formwysiwygtextarea.php"); $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, $width, $height, ''); } break; } return $editor;}function get_lastpostdate() { global $cache_lastpostdate, $use_cache, $time_difference, $pagenow, $wpdb; if ((!isset($cache_lastpostdate)) OR (!$use_cache)) { $now = date("Y-m-d H:i:s",(time() + ($time_difference * 3600))); $lastpostdate = $wpdb->get_var("SELECT post_date FROM {$wpdb->posts} WHERE post_date <= '$now' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1"); $cache_lastpostdate = $lastpostdate; } else { $lastpostdate = $cache_lastpostdate; } return $lastpostdate;}function user_pass_ok($user_login,$user_pass) { global $cache_userdata,$use_cache; if ((empty($cache_userdata[$user_login])) OR (!$use_cache)) { $userdata = get_userdatabylogin($user_login); } else { $userdata = $cache_userdata[$user_login]; } return (md5(trim($user_pass)) == $userdata->user_pass);}function get_currentuserinfo() { // a bit like get_userdata(), on steroids global $user_login, $userdata, $user_level, $user_ID, $user_nickname, $user_email, $user_url, $user_pass_md5, $cookiehash, $xoopsUser; // *** retrieving user's data from cookies and db - no spoofing/* $user_login = $_COOKIE['wordpressuser_'.$cookiehash]; $userdata = get_userdatabylogin($user_login); $user_level = $userdata->user_level; $user_ID = $userdata->ID; $user_nickname = $userdata->user_nickname; $user_email = $userdata->user_email; $user_url = $userdata->user_url; $user_pass_md5 = md5($userdata->user_pass);*/ if ($xoopsUser) { $user_login = $xoopsUser->uname(); $userdata = get_userdatabylogin($user_login); $user_level = $userdata->user_level; $user_ID = $userdata->ID; $user_nickname = $userdata->user_nickname; $user_email = $userdata->user_email; $user_url = $userdata->user_url;// $user_pass_md5 = md5($userdata->user_pass); $user_pass_md5 = $xoopsUser->pass(); }}function get_userdata($userid) { global $wpdb, $cache_userdata, $use_cache, $xoopsDB ; $userid = intval($userid); if ((empty($cache_userdata[$userid])) || (!$use_cache)) { $user = $wpdb->get_row("SELECT * FROM {$wpdb->users} WHERE ID = $userid"); $xuser = $wpdb->get_row("SELECT * FROM ".$xoopsDB->prefix('users')." WHERE uid=$userid"); $user->user_nickname = stripslashes($user->user_nickname); $user->user_firstname = stripslashes($user->user_firstname); $user->user_lastname = stripslashes($user->user_lastname); $user->user_firstname = stripslashes($user->user_firstname); $user->user_lastname = stripslashes($user->user_lastname); $user->user_description = stripslashes($user->user_description); $user->user_pass = $xuser->pass; $cache_userdata[$userid] = $user; } else { $user = $cache_userdata[$userid]; } return $user;}function get_userdata2($userid) { // for team-listing// global $post;// $user_data['ID'] = $userid; global $post, $xoopsUser; $user_data['ID'] = $xoopsUser->uid(); $user_data['user_login'] = $post->user_login; $user_data['user_firstname'] = $post->user_firstname; $user_data['user_lastname'] = $post->user_lastname; $user_data['user_nickname'] = $post->user_nickname; $user_data['user_level'] = $post->user_level; $user_data['user_email'] = $post->user_email; $user_data['user_url'] = $post->user_url; return $user_data;}function get_userdatabylogin($user_login) { global $cache_userdata, $use_cache, $wpdb, $xoopsDB ; if ((empty($cache_userdata["$user_login"])) OR (!$use_cache)) { $user = $wpdb->get_row("SELECT * FROM {$wpdb->users} WHERE user_login = '$user_login'"); $xuser = $wpdb->get_row("SELECT * FROM ".$xoopsDB->prefix('users')." WHERE uname='".trim($user_login)."'"); $user->user_pass = $xuser->pass; $cache_userdata["$user_login"] = $user; } else { $user = $cache_userdata["$user_login"]; } return $user;}function get_userid($user_login) { global $cache_userdata, $use_cache, $wpdb ; if ((empty($cache_userdata["$user_login"])) OR (!$use_cache)) { $user_id = $wpdb->get_var("SELECT ID FROM {$wpdb->users} WHERE user_login = '$user_login'"); $cache_userdata["$user_login"] = $user_id; } else { $user_id = $cache_userdata["$user_login"]; } return $user_id;}function get_usernumposts($userid) { global $wpdb ; $userid = intval($userid); return $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_author = $userid");}// examine a url (supposedly from this blog) and try to// determine the post ID it represents.function url_to_postid($url = '') { global $wpdb, $siteurl ; // Take a link like 'http://example.com/blog/something' // and extract just the '/something': $uri = preg_replace("#$siteurl#i", '', $url); // on failure, preg_replace just returns the subject string // so if $uri and $siteurl are the same, they didn't match: if ($uri == $siteurl) return 0; // First, check to see if there is a 'p=N' to match against: preg_match('#[?&]p=(\d+)#', $uri, $values); $p = intval($values[1]); if ($p) return $p; // Match $uri against our permalink structure $permalink_structure = get_settings('permalink_structure'); // Matt's tokenizer code $rewritecode = array( '%year%', '%monthnum%', '%day%', '%postname%', '%post_id%' ); $rewritereplace = array( '([0-9]{4})?', '([0-9]{1,2})?', '([0-9]{1,2})?', '([0-9a-z-]+)?', '([0-9]+)?' ); // Turn the structure into a regular expression $matchre = str_replace('/', '/?', $permalink_structure); $matchre = str_replace($rewritecode, $rewritereplace, $matchre); // Extract the key values from the uri: preg_match("#$matchre#",$uri,$values); // Extract the token names from the structure: preg_match_all("#%(.+?)%#", $permalink_structure, $tokens); for($i = 0; $i < count($tokens[1]); $i++) { $name = $tokens[1][$i]; $value = $values[$i+1]; // Create a variable named $year, $monthnum, $day, $postname, or $post_id: $$name = $value; } // If using %post_id%, we're done: if (intval($post_id)) return intval($post_id); // Otherwise, build a WHERE clause, making the values safe along the way: if ($year) $where .= " AND YEAR(post_date) = " . intval($year); if ($monthnum) $where .= " AND MONTH(post_date) = " . intval($monthnum); if ($day) $where .= " AND DAYOFMONTH(post_date) = " . intval($day); if ($postname) $where .= " AND post_name = '" . $wpdb->escape($postname) . "' "; // Run the query to get the post ID: $id = intval($wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE 1 = 1 " . $where)); return $id;}/* Options functions */function get_settings($setting) { global $wpdb, $cache_settings, $use_cache, $REQUEST_URI; if (!isset($use_cache)) $use_cache=1; if (strstr($REQUEST_URI, 'install.php')) return false; if ((empty($cache_settings)) OR (!$use_cache)) { $settings = get_alloptions(); $cache_settings = $settings; } else { $settings = $cache_settings; } if (!isset($settings->$setting)) { return false; } else { return $settings->$setting; }}function get_alloptions() { global $wpdb ; $options = $wpdb->get_results("SELECT option_name, option_value FROM {$wpdb->options}"); if ($options) { foreach ($options as $option) { $all_options->{$option->option_name} = $option->option_value; } } return $all_options;}function update_option($option_name, $newvalue) { global $wpdb, $cache_settings; // No validation at the moment $newvalue = stripslashes($newvalue); $newvalue = trim($newvalue); // I can't think of any situation we wouldn't want to trim $newvalue = $wpdb->escape($newvalue); $wpdb->query("UPDATE {$wpdb->options} SET option_value = '$newvalue' WHERE option_name = '$option_name'"); $cache_settings = get_alloptions(); // Re cache settings}function add_option($name, $value='') { // Adds an option if it doesn't already exist global $wpdb; if(!get_settings($name)) { $name = $wpdb->escape($name); $options = $wpdb->get_results("SELECT option_id FROM {$wpdb->options} WHERE option_name = '$name'"); if (count($options) == 0) { $value = $wpdb->escape($value); $wpdb->query("INSERT INTO {$wpdb->options} (option_name, option_value) VALUES ('$name', '$value')"); if($wpdb->insert_id) { global $cache_settings; $cache_settings->{$name} = $value; } } } return;}function get_postdata($postid) { global $post, $wpdb ; $postid = intval($postid); $post = $wpdb->get_row("SELECT * FROM {$wpdb->posts} WHERE ID = $postid"); $postdata = array ( 'ID' => $post->ID, 'Author_ID' => $post->post_author, 'Date' => $post->post_date, 'Content' => $post->post_content, 'Excerpt' => $post->post_excerpt, 'Title' => $post->post_title, 'Category' => $post->post_category, 'Lat' => $post->post_lat, 'Lon' => $post->post_lon, 'post_status' => $post->post_status, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_password' => $post->post_password, 'to_ping' => $post->to_ping, 'pinged' => $post->pinged ); return $postdata;}function get_postdata2($postid=0) { // less flexible, but saves DB queries global $post; $postdata = array ( 'ID' => $post->ID, 'Author_ID' => $post->post_author, 'Date' => $post->post_date, 'Content' => $post->post_content, 'Excerpt' => $post->post_excerpt, 'Title' => $post->post_title, 'Category' => $post->post_category, 'Lat' => $post->post_lat, 'Lon' => $post->post_lon, 'post_status' => $post->post_status, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_password' => $post->post_password ); return $postdata;}function get_commentdata($comment_ID,$no_cache=0,$include_unapproved=false) { // less flexible, but saves DB queries global $postc,$id,$commentdata, $wpdb ; $comment_ID = intval($comment_ID); if ($no_cache) { $query = "SELECT * FROM {$wpdb->comments} WHERE comment_ID = $comment_ID"; if (false == $include_unapproved) { $query .= " AND comment_approved = '1'"; } $myrow = $wpdb->get_row($query, ARRAY_A); } else { $myrow['comment_ID']=$postc->comment_ID; $myrow['comment_post_ID']=$postc->comment_post_ID; $myrow['comment_author']=$postc->comment_author; $myrow['comment_author_email']=$postc->comment_author_email; $myrow['comment_author_url']=$postc->comment_author_url; $myrow['comment_author_IP']=$postc->comment_author_IP; $myrow['comment_date']=$postc->comment_date; $myrow['comment_content']=$postc->comment_content; $myrow['comment_karma']=$postc->comment_karma; if (strstr($myrow['comment_content'], '<trackback />')) { $myrow['comment_type'] = 'trackback'; } elseif (strstr($myrow['comment_content'], '<pingback />')) { $myrow['comment_type'] = 'pingback'; } else { $myrow['comment_type'] = 'comment'; } } return $myrow;}function get_catname($cat_ID) { global $cache_catnames,$use_cache, $wpdb ; if ((!$cache_catnames) || (!$use_cache)) { $results = $wpdb->get_results("SELECT * FROM {$wpdb->categories}") or die('Oops, couldn\'t query the db for categories.'); foreach ($results as $post) { $cache_catnames[$post->cat_ID] = $post->cat_name; } } $cat_name = $cache_catnames[$cat_ID]; return $cat_name;}function profile($user_login) { global $user_data; echo "<a href='profile.php?user=".$user_data->user_login."' onclick=\"javascript:window.open('profile.php?user=".$user_data->user_login."','Profile','toolbar=0,status=1,location=0,directories=0,menuBar=1,scrollbars=1,resizable=0,width=480,height=320,left=100,top=100'); return false;\">$user_login</a>";}/*function dropdown_categories($default = 0) { global $post, $mode, $wpdb ; $categories = $wpdb->get_results("SELECT * FROM {$wpdb->categories} ORDER BY cat_name"); if ($post->ID) { $postcategories = $wpdb->get_col(" SELECT category_id FROM {$wpdb->categories}, {$wpdb->post2cat} WHERE {$wpdb->post2cat}.category_id = cat_ID AND {$wpdb->post2cat}.post_id = $post->ID "); } else { $postcategories[] = $default; } $i =0; foreach($categories as $category) { ++$i; $category->cat_name = stripslashes($category->cat_name); echo "\n<label for='category-$i' class='selectit'><input value='$category->cat_ID' type='checkbox' name='post_category[]' id='category-$i'"; if ($postcategories && in_array($category->cat_ID, $postcategories)) echo ' checked="checked"'; echo " /> $category->cat_name</label> "; }}*/function touch_time($edit = 1) { global $month, $postdata, $time_difference; // echo $postdata['Date']; if ('draft' == $postdata['post_status']) { $checked = 'checked="checked" '; $edit = false;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?