| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | if (!function_exists('_')) { |
|---|
| 4 | function _($string) { |
|---|
| 5 | return $string; |
|---|
| 6 | } |
|---|
| 7 | } |
|---|
| 8 | |
|---|
| 9 | if (!function_exists('floatval')) { |
|---|
| 10 | function floatval($string) { |
|---|
| 11 | return ((float) $string); |
|---|
| 12 | } |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | function popuplinks($text) { |
|---|
| 16 | // Comment text in popup windows should be filtered through this. |
|---|
| 17 | // Right now it's a moderately dumb function, ideally it would detect whether |
|---|
| 18 | // a target or rel attribute was already there and adjust its actions accordingly. |
|---|
| 19 | $text = preg_replace('/<a (.+?)>/i', "<a $1 target='_blank' rel='external'>", $text); |
|---|
| 20 | return $text; |
|---|
| 21 | } |
|---|
| 22 | |
|---|
| 23 | function mysql2date($dateformatstring, $mysqlstring, $use_b2configmonthsdays = 1) { |
|---|
| 24 | global $month, $weekday; |
|---|
| 25 | $m = $mysqlstring; |
|---|
| 26 | if (empty($m)) { |
|---|
| 27 | return false; |
|---|
| 28 | } |
|---|
| 29 | $i = mktime(substr($m,11,2),substr($m,14,2),substr($m,17,2),substr($m,5,2),substr($m,8,2),substr($m,0,4)); |
|---|
| 30 | if (!empty($month) && !empty($weekday) && $use_b2configmonthsdays) { |
|---|
| 31 | $datemonth = $month[date('m', $i)]; |
|---|
| 32 | $dateweekday = $weekday[date('w', $i)]; |
|---|
| 33 | $dateformatstring = ' '.$dateformatstring; |
|---|
| 34 | $dateformatstring = preg_replace("/([^\\\])D/", "\\1".backslashit(substr($dateweekday, 0, 3)), $dateformatstring); |
|---|
| 35 | $dateformatstring = preg_replace("/([^\\\])F/", "\\1".backslashit($datemonth), $dateformatstring); |
|---|
| 36 | $dateformatstring = preg_replace("/([^\\\])l/", "\\1".backslashit($dateweekday), $dateformatstring); |
|---|
| 37 | $dateformatstring = preg_replace("/([^\\\])M/", "\\1".backslashit(substr($datemonth, 0, 3)), $dateformatstring); |
|---|
| 38 | $dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring)-1); |
|---|
| 39 | } |
|---|
| 40 | $j = @date($dateformatstring, $i); |
|---|
| 41 | if (!$j) { |
|---|
| 42 | // for debug purposes |
|---|
| 43 | // echo $i." ".$mysqlstring; |
|---|
| 44 | } |
|---|
| 45 | return $j; |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | function current_time($type, $gmt = 0) { |
|---|
| 49 | switch ($type) { |
|---|
| 50 | case 'mysql': |
|---|
| 51 | if ($gmt) $d = gmdate('Y-m-d H:i:s'); |
|---|
| 52 | else $d = gmdate('Y-m-d H:i:s', (time() + (get_settings('gmt_offset') * 3600))); |
|---|
| 53 | return $d; |
|---|
| 54 | break; |
|---|
| 55 | case 'timestamp': |
|---|
| 56 | if ($gmt) $d = time(); |
|---|
| 57 | else $d = time() + (get_settings('gmt_offset') * 3600); |
|---|
| 58 | return $d; |
|---|
| 59 | break; |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | function date_i18n($dateformatstring, $unixtimestamp) { |
|---|
| 64 | global $month, $weekday; |
|---|
| 65 | $i = $unixtimestamp; |
|---|
| 66 | if ((!empty($month)) && (!empty($weekday))) { |
|---|
| 67 | $datemonth = $month[date('m', $i)]; |
|---|
| 68 | $dateweekday = $weekday[date('w', $i)]; |
|---|
| 69 | $dateformatstring = ' '.$dateformatstring; |
|---|
| 70 | $dateformatstring = preg_replace("/([^\\\])D/", "\\1".backslashit(substr($dateweekday, 0, 3)), $dateformatstring); |
|---|
| 71 | $dateformatstring = preg_replace("/([^\\\])F/", "\\1".backslashit($datemonth), $dateformatstring); |
|---|
| 72 | $dateformatstring = preg_replace("/([^\\\])l/", "\\1".backslashit($dateweekday), $dateformatstring); |
|---|
| 73 | $dateformatstring = preg_replace("/([^\\\])M/", "\\1".backslashit(substr($datemonth, 0, 3)), $dateformatstring); |
|---|
| 74 | $dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring)-1); |
|---|
| 75 | } |
|---|
| 76 | $j = @date($dateformatstring, $i); |
|---|
| 77 | return $j; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | function get_weekstartend($mysqlstring, $start_of_week) { |
|---|
| 81 | $my = substr($mysqlstring,0,4); |
|---|
| 82 | $mm = substr($mysqlstring,8,2); |
|---|
| 83 | $md = substr($mysqlstring,5,2); |
|---|
| 84 | $day = mktime(0,0,0, $md, $mm, $my); |
|---|
| 85 | $weekday = date('w',$day); |
|---|
| 86 | $i = 86400; |
|---|
| 87 | while ($weekday > get_settings('start_of_week')) { |
|---|
| 88 | $weekday = date('w',$day); |
|---|
| 89 | $day = $day - 86400; |
|---|
| 90 | $i = 0; |
|---|
| 91 | } |
|---|
| 92 | $week['start'] = $day + 86400 - $i; |
|---|
| 93 | $week['end'] = $day + 691199; |
|---|
| 94 | return $week; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | function get_lastpostdate($timezone = 'server') { |
|---|
| 98 | global $tableposts, $cache_lastpostdate, $pagenow, $wpdb; |
|---|
| 99 | $add_seconds_blog = get_settings('gmt_offset') * 3600; |
|---|
| 100 | $add_seconds_server = date('Z'); |
|---|
| 101 | $now = current_time('mysql', 1); |
|---|
| 102 | if ( !isset($cache_lastpostdate[$timezone]) ) { |
|---|
| 103 | switch(strtolower($timezone)) { |
|---|
| 104 | case 'gmt': |
|---|
| 105 | $lastpostdate = $wpdb->get_var("SELECT post_date_gmt FROM $tableposts WHERE post_date_gmt <= '$now' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1"); |
|---|
| 106 | break; |
|---|
| 107 | case 'blog': |
|---|
| 108 | $lastpostdate = $wpdb->get_var("SELECT post_date FROM $tableposts WHERE post_date_gmt <= '$now' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1"); |
|---|
| 109 | break; |
|---|
| 110 | case 'server': |
|---|
| 111 | $lastpostdate = $wpdb->get_var("SELECT DATE_ADD(post_date_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $tableposts WHERE post_date_gmt <= '$now' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1"); |
|---|
| 112 | break; |
|---|
| 113 | } |
|---|
| 114 | $cache_lastpostdate[$timezone] = $lastpostdate; |
|---|
| 115 | } else { |
|---|
| 116 | $lastpostdate = $cache_lastpostdate[$timezone]; |
|---|
| 117 | } |
|---|
| 118 | return $lastpostdate; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | function get_lastpostmodified($timezone = 'server') { |
|---|
| 122 | global $tableposts, $cache_lastpostmodified, $pagenow, $wpdb; |
|---|
| 123 | $add_seconds_blog = get_settings('gmt_offset') * 3600; |
|---|
| 124 | $add_seconds_server = date('Z'); |
|---|
| 125 | $now = current_time('mysql', 1); |
|---|
| 126 | if ( !isset($cache_lastpostmodified[$timezone]) ) { |
|---|
| 127 | switch(strtolower($timezone)) { |
|---|
| 128 | case 'gmt': |
|---|
| 129 | $lastpostmodified = $wpdb->get_var("SELECT post_modified_gmt FROM $tableposts WHERE post_modified_gmt <= '$now' AND post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1"); |
|---|
| 130 | break; |
|---|
| 131 | case 'blog': |
|---|
| 132 | $lastpostmodified = $wpdb->get_var("SELECT post_modified FROM $tableposts WHERE post_modified_gmt <= '$now' AND post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1"); |
|---|
| 133 | break; |
|---|
| 134 | case 'server': |
|---|
| 135 | $lastpostmodified = $wpdb->get_var("SELECT DATE_ADD(post_modified_gmt, INTERVAL '$add_seconds_server' SECOND) FROM $tableposts WHERE post_modified_gmt <= '$now' AND post_status = 'publish' ORDER BY post_modified_gmt DESC LIMIT 1"); |
|---|
| 136 | break; |
|---|
| 137 | } |
|---|
| 138 | $lastpostdate = get_lastpostdate($timezone); |
|---|
| 139 | if ($lastpostdate > $lastpostmodified) { |
|---|
| 140 | $lastpostmodified = $lastpostdate; |
|---|
| 141 | } |
|---|
| 142 | $cache_lastpostmodified[$timezone] = $lastpostmodified; |
|---|
| 143 | } else { |
|---|
| 144 | $lastpostmodified = $cache_lastpostmodified[$timezone]; |
|---|
| 145 | } |
|---|
| 146 | return $lastpostmodified; |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | function user_pass_ok($user_login,$user_pass) { |
|---|
| 150 | global $cache_userdata; |
|---|
| 151 | if ( empty($cache_userdata[$user_login]) ) { |
|---|
| 152 | $userdata = get_userdatabylogin($user_login); |
|---|
| 153 | } else { |
|---|
| 154 | $userdata = $cache_userdata[$user_login]; |
|---|
| 155 | } |
|---|
| 156 | return (md5($user_pass) == $userdata->user_pass); |
|---|
| 157 | } |
|---|
| 158 | |
|---|
| 159 | function get_currentuserinfo() { // a bit like get_userdata(), on steroids |
|---|
| 160 | global $user_login, $userdata, $user_level, $user_ID, $user_nickname, $user_email, $user_url, $user_pass_md5, $cookiehash; |
|---|
| 161 | // *** retrieving user's data from cookies and db - no spoofing |
|---|
| 162 | |
|---|
| 163 | if (isset($_COOKIE['wordpressuser_' . $cookiehash])) |
|---|
| 164 | $user_login = $_COOKIE['wordpressuser_' . $cookiehash]; |
|---|
| 165 | $userdata = get_userdatabylogin($user_login); |
|---|
| 166 | $user_level = $userdata->user_level; |
|---|
| 167 | $user_ID = $userdata->ID; |
|---|
| 168 | $user_nickname = $userdata->user_nickname; |
|---|
| 169 | $user_email = $userdata->user_email; |
|---|
| 170 | $user_url = $userdata->user_url; |
|---|
| 171 | $user_pass_md5 = md5($userdata->user_pass); |
|---|
| 172 | } |
|---|
| 173 | |
|---|
| 174 | function get_userdata($userid) { |
|---|
| 175 | global $wpdb, $cache_userdata, $tableusers; |
|---|
| 176 | if ( empty($cache_userdata[$userid]) ) { |
|---|
| 177 | $user = $wpdb->get_row("SELECT * FROM $tableusers WHERE ID = '$userid'"); |
|---|
| 178 | $user->user_nickname = stripslashes($user->user_nickname); |
|---|
| 179 | $user->user_firstname = stripslashes($user->user_firstname); |
|---|
| 180 | $user->user_lastname = stripslashes($user->user_lastname); |
|---|
| 181 | $user->user_description = stripslashes($user->user_description); |
|---|
| 182 | $cache_userdata[$userid] = $user; |
|---|
| 183 | } else { |
|---|
| 184 | $user = $cache_userdata[$userid]; |
|---|
| 185 | } |
|---|
| 186 | return $user; |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | function get_userdatabylogin($user_login) { |
|---|
| 190 | global $tableusers, $cache_userdata, $wpdb; |
|---|
| 191 | if ( empty($cache_userdata["$user_login"]) ) { |
|---|
| 192 | $user = $wpdb->get_row("SELECT * FROM $tableusers WHERE user_login = '$user_login'"); |
|---|
| 193 | $cache_userdata["$user_login"] = $user; |
|---|
| 194 | } else { |
|---|
| 195 | $user = $cache_userdata["$user_login"]; |
|---|
| 196 | } |
|---|
| 197 | return $user; |
|---|
| 198 | } |
|---|
| 199 | |
|---|
| 200 | function get_userid($user_login) { |
|---|
| 201 | global $tableusers, $cache_userdata, $wpdb; |
|---|
| 202 | if ( empty($cache_userdata["$user_login"]) ) { |
|---|
| 203 | $user_id = $wpdb->get_var("SELECT ID FROM $tableusers WHERE user_login = '$user_login'"); |
|---|
| 204 | |
|---|
| 205 | $cache_userdata["$user_login"] = $user_id; |
|---|
| 206 | } else { |
|---|
| 207 | $user_id = $cache_userdata["$user_login"]; |
|---|
| 208 | } |
|---|
| 209 | return $user_id; |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | function get_usernumposts($userid) { |
|---|
| 213 | global $tableposts, $tablecomments, $wpdb; |
|---|
| 214 | return $wpdb->get_var("SELECT COUNT(*) FROM $tableposts WHERE post_author = '$userid'"); |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | // examine a url (supposedly from this blog) and try to |
|---|
| 218 | // determine the post ID it represents. |
|---|
| 219 | function url_to_postid($url = '') { |
|---|
| 220 | global $wpdb, $tableposts; |
|---|
| 221 | |
|---|
| 222 | $siteurl = get_settings('home'); |
|---|
| 223 | // Take a link like 'http://example.com/blog/something' |
|---|
| 224 | // and extract just the '/something': |
|---|
| 225 | $uri = preg_replace("#$siteurl#i", '', $url); |
|---|
| 226 | |
|---|
| 227 | // on failure, preg_replace just returns the subject string |
|---|
| 228 | // so if $uri and $siteurl are the same, they didn't match: |
|---|
| 229 | if ($uri == $siteurl) |
|---|
| 230 | return 0; |
|---|
| 231 | |
|---|
| 232 | // First, check to see if there is a 'p=N' to match against: |
|---|
| 233 | preg_match('#[?&]p=(\d+)#', $uri, $values); |
|---|
| 234 | $p = intval($values[1]); |
|---|
| 235 | if ($p) return $p; |
|---|
| 236 | |
|---|
| 237 | // Match $uri against our permalink structure |
|---|
| 238 | $permalink_structure = get_settings('permalink_structure'); |
|---|
| 239 | |
|---|
| 240 | // Matt's tokenizer code |
|---|
| 241 | $rewritecode = array( |
|---|
| 242 | '%year%', |
|---|
| 243 | '%monthnum%', |
|---|
| 244 | '%day%', |
|---|
| 245 | '%hour%', |
|---|
| 246 | '%minute%', |
|---|
| 247 | '%second%', |
|---|
| 248 | '%postname%', |
|---|
| 249 | '%post_id%' |
|---|
| 250 | ); |
|---|
| 251 | $rewritereplace = array( |
|---|
| 252 | '([0-9]{4})?', |
|---|
| 253 | '([0-9]{1,2})?', |
|---|
| 254 | '([0-9]{1,2})?', |
|---|
| 255 | '([0-9]{1,2})?', |
|---|
| 256 | '([0-9]{1,2})?', |
|---|
| 257 | '([0-9]{1,2})?', |
|---|
| 258 | '([_0-9a-z-]+)?', |
|---|
| 259 | '([0-9]+)?' |
|---|
| 260 | ); |
|---|
| 261 | |
|---|
| 262 | // Turn the structure into a regular expression |
|---|
| 263 | $matchre = str_replace('/', '/?', $permalink_structure); |
|---|
| 264 | $matchre = str_replace($rewritecode, $rewritereplace, $matchre); |
|---|
| 265 | |
|---|
| 266 | // Extract the key values from the uri: |
|---|
| 267 | preg_match("#$matchre#",$uri,$values); |
|---|
| 268 | |
|---|
| 269 | // Extract the token names from the structure: |
|---|
| 270 | preg_match_all("#%(.+?)%#", $permalink_structure, $tokens); |
|---|
| 271 | |
|---|
| 272 | for($i = 0; $i < count($tokens[1]); $i++) { |
|---|
| 273 | $name = $tokens[1][$i]; |
|---|
| 274 | $value = $values[$i+1]; |
|---|
| 275 | |
|---|
| 276 | // Create a variable named $year, $monthnum, $day, $postname, or $post_id: |
|---|
| 277 | $$name = $value; |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | // If using %post_id%, we're done: |
|---|
| 281 | if (intval($post_id)) return intval($post_id); |
|---|
| 282 | |
|---|
| 283 | // Otherwise, build a WHERE clause, making the values safe along the way: |
|---|
| 284 | if ($year) $where .= " AND YEAR(post_date) = '" . intval($year) . "'"; |
|---|
| 285 | if ($monthnum) $where .= " AND MONTH(post_date) = '" . intval($monthnum) . "'"; |
|---|
| 286 | if ($day) $where .= " AND DAYOFMONTH(post_date) = '" . intval($day) . "'"; |
|---|
| 287 | if ($hour) $where .= " AND HOUR(post_date) = '" . intval($hour) . "'"; |
|---|
| 288 | if ($minute) $where .= " AND MINUTE(post_date) = '" . intval($minute) . "'"; |
|---|
| 289 | if ($second) $where .= " AND SECOND(post_date) = '" . intval($second) . "'"; |
|---|
| 290 | if ($postname) $where .= " AND post_name = '" . $wpdb->escape($postname) . "' "; |
|---|
| 291 | |
|---|
| 292 | // Run the query to get the post ID: |
|---|
| 293 | $id = intval($wpdb->get_var("SELECT ID FROM $tableposts WHERE 1 = 1 " . $where)); |
|---|
| 294 | |
|---|
| 295 | return $id; |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | /* Options functions */ |
|---|
| 300 | |
|---|
| 301 | function get_settings($setting) { |
|---|
| 302 | global $wpdb, $cache_settings; |
|---|
| 303 | if (strstr($_SERVER['REQUEST_URI'], 'install.php')) { |
|---|
| 304 | return false; |
|---|
| 305 | } |
|---|
| 306 | |
|---|
| 307 | if ( (empty($cache_settings)) ) { |
|---|
| 308 | $settings = get_alloptions(); |
|---|
| 309 | $cache_settings = $settings; |
|---|
| 310 | } else { |
|---|
| 311 | $settings = $cache_settings; |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | if ('home' == $setting && '' == $settings->home) return $settings->siteurl; |
|---|
| 315 | |
|---|
| 316 | if (!isset($settings->$setting)) { |
|---|
| 317 | return false; |
|---|
| 318 | } else { |
|---|
| 319 | return stripslashes($settings->$setting); |
|---|
| 320 | } |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | function get_alloptions() { |
|---|
| 324 | global $tableoptions, $wpdb; |
|---|
| 325 | $options = $wpdb->get_results("SELECT option_name, option_value FROM $tableoptions"); |
|---|
| 326 | if ($options) { |
|---|
| 327 | foreach ($options as $option) { |
|---|
| 328 | // "When trying to design a foolproof system, |
|---|
| 329 | // never underestimate the ingenuity of the fools :)" |
|---|
| 330 | if ('siteurl' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value); |
|---|
| 331 | if ('home' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value); |
|---|
| 332 | if ('category_base' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value); |
|---|
| 333 | |
|---|
| 334 | $all_options->{$option->option_name} = $option->option_value; |
|---|
| 335 | } |
|---|
| 336 | } |
|---|
| 337 | return $all_options; |
|---|
| 338 | } |
|---|
| 339 | |
|---|
| 340 | function update_option($option_name, $newvalue) { |
|---|
| 341 | global $wpdb, $tableoptions, $cache_settings; |
|---|
| 342 | $newvalue = stripslashes($newvalue); |
|---|
| 343 | $newvalue = trim($newvalue); // I can't think of any situation we wouldn't want to trim |
|---|
| 344 | $newvalue = $wpdb->escape($newvalue); |
|---|
| 345 | $wpdb->query("UPDATE $tableoptions SET option_value = '$newvalue' WHERE option_name = '$option_name'"); |
|---|
| 346 | $cache_settings = get_alloptions(); // Re cache settings |
|---|
| 347 | return true; |
|---|
| 348 | } |
|---|
| 349 | |
|---|
| 350 | |
|---|
| 351 | // thx Alex Stapleton, http://alex.vort-x.net/blog/ |
|---|
| 352 | function add_option($name, $value='') { |
|---|
| 353 | // Adds an option if it doesn't already exist |
|---|
| 354 | global $wpdb, $tableoptions; |
|---|
| 355 | if(!get_settings($name)) { |
|---|
| 356 | $name = $wpdb->escape($name); |
|---|
| 357 | $value = $wpdb->escape($value); |
|---|
| 358 | $wpdb->query("INSERT INTO $tableoptions (option_name, option_value) VALUES ('$name', '$value')"); |
|---|
| 359 | |
|---|
| 360 | if($wpdb->insert_id) { |
|---|
| 361 | global $cache_settings; |
|---|
| 362 | $cache_settings->{$name} = $value; |
|---|
| 363 | } |
|---|
| 364 | } |
|---|
| 365 | return; |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | function delete_option($name) { |
|---|
| 369 | global $wpdb, $tableoptions, $tableoptiongroup_options; |
|---|
| 370 | // Get the ID, if no ID then return |
|---|
| 371 | $option_id = $wpdb->get_var("SELECT option_id FROM $tableoptions WHERE option_name = '$name'"); |
|---|
| 372 | if (!$option_id) return false; |
|---|
| 373 | $wpdb->query("DELETE FROM $tableoptiongroup_options WHERE option_id = '$option_id'"); |
|---|
| 374 | $wpdb->query("DELETE FROM $tableoptions WHERE option_name = '$name'"); |
|---|
| 375 | return true; |
|---|
| 376 | } |
|---|
| 377 | |
|---|
| 378 | function get_postdata($postid) { |
|---|
| 379 | global $post, $tableposts, $wpdb; |
|---|
| 380 | |
|---|
| 381 | $post = $wpdb->get_row("SELECT * FROM $tableposts WHERE ID = '$postid'"); |
|---|
| 382 | |
|---|
| 383 | $postdata = array ( |
|---|
| 384 | 'ID' => $post->ID, |
|---|
| 385 | 'Author_ID' => $post->post_author, |
|---|
| 386 | 'Date' => $post->post_date, |
|---|
| 387 | 'Content' => $post->post_content, |
|---|
| 388 | 'Excerpt' => $post->post_excerpt, |
|---|
| 389 | 'Title' => $post->post_title, |
|---|
| 390 | 'Category' => $post->post_category, |
|---|
| 391 | 'Lat' => $post->post_lat, |
|---|
| 392 | 'Lon' => $post->post_lon, |
|---|
| 393 | 'post_status' => $post->post_status, |
|---|
| 394 | 'comment_status' => $post->comment_status, |
|---|
| 395 | 'ping_status' => $post->ping_status, |
|---|
| 396 | 'post_password' => $post->post_password, |
|---|
| 397 | 'to_ping' => $post->to_ping, |
|---|
| 398 | 'pinged' => $post->pinged, |
|---|
| 399 | 'post_name' => $post->post_name |
|---|
| 400 | ); |
|---|
| 401 | return $postdata; |
|---|
| 402 | } |
|---|
| 403 | |
|---|
| 404 | function get_commentdata($comment_ID,$no_cache=0,$include_unapproved=false) { // less flexible, but saves DB queries |
|---|
| 405 | global $postc,$id,$commentdata,$tablecomments, $wpdb; |
|---|
| 406 | if ($no_cache) { |
|---|
| 407 | $query = "SELECT * FROM $tablecomments WHERE comment_ID = '$comment_ID'"; |
|---|
| 408 | if (false == $include_unapproved) { |
|---|
| 409 | $query .= " AND comment_approved = '1'"; |
|---|
| 410 | } |
|---|
| 411 | $myrow = $wpdb->get_row($query, ARRAY_A); |
|---|
| 412 | } else { |
|---|
| 413 | $myrow['comment_ID']=$postc->comment_ID; |
|---|
| 414 | $myrow['comment_post_ID']=$postc->comment_post_ID; |
|---|
| 415 | $myrow['comment_author']=$postc->comment_author; |
|---|
| 416 | $myrow['comment_author_email']=$postc->comment_author_email; |
|---|
| 417 | $myrow['comment_author_url']=$postc->comment_author_url; |
|---|
| 418 | $myrow['comment_author_IP']=$postc->comment_author_IP; |
|---|
| 419 | $myrow['comment_date']=$postc->comment_date; |
|---|
| 420 | $myrow['comment_content']=$postc->comment_content; |
|---|
| 421 | $myrow['comment_karma']=$postc->comment_karma; |
|---|
| 422 | if (strstr($myrow['comment_content'], '<trackback />')) { |
|---|
| 423 | $myrow['comment_type'] = 'trackback'; |
|---|
| 424 | } elseif (strstr($myrow['comment_content'], '<pingback />')) { |
|---|
| 425 | $myrow['comment_type'] = 'pingback'; |
|---|
| 426 | } else { |
|---|
| 427 | $myrow['comment_type'] = 'comment'; |
|---|
| 428 | } |
|---|
| 429 | } |
|---|
| 430 | return $myrow; |
|---|
| 431 | } |
|---|
| 432 | |
|---|
| 433 | function get_catname($cat_ID) { |
|---|
| 434 | global $tablecategories, $cache_catnames, $wpdb; |
|---|
| 435 | if ( !$cache_catnames ) { |
|---|
| 436 | $results = $wpdb->get_results("SELECT * FROM $tablecategories") or die('Oops, couldn\'t query the db for categories.'); |
|---|
| 437 | foreach ($results as $post) { |
|---|
| 438 | $cache_catnames[$post->cat_ID] = $post->cat_name; |
|---|
| 439 | } |
|---|
| 440 | } |
|---|
| 441 | $cat_name = $cache_catnames[$cat_ID]; |
|---|
| 442 | return $cat_name; |
|---|
| 443 | } |
|---|
| 444 | |
|---|
| 445 | function gzip_compression() { |
|---|
| 446 | global $gzip_compressed; |
|---|
| 447 | if (strstr($_SERVER['PHP_SELF'], 'wp-admin')) return true; |
|---|
| 448 | if (!$gzip_compressed) { |
|---|
| 449 | $phpver = phpversion(); //start gzip compression |
|---|
| 450 | if($phpver >= "4.0.4pl1") { |
|---|
| 451 | if(extension_loaded("zlib")) { |
|---|
| 452 | ob_start("ob_gzhandler"); |
|---|
| 453 | } |
|---|
| 454 | } else if($phpver > "4.0") { |
|---|
| 455 | if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) { |
|---|
| 456 | if(extension_loaded("zlib")) { |
|---|
| 457 | $do_gzip_compress = TRUE; |
|---|
| 458 | ob_start(); |
|---|
| 459 | ob_implicit_flush(0); |
|---|
| 460 | header("Content-Encoding: gzip"); |
|---|
| 461 | } |
|---|
| 462 | } |
|---|
| 463 | } //end gzip compression - that piece of script courtesy of the phpBB dev team |
|---|
| 464 | $gzip_compressed=1; |
|---|
| 465 | } |
|---|
| 466 | } |
|---|
| 467 | |
|---|
| 468 | |
|---|
| 469 | // functions to count the page generation time (from phpBB2) |
|---|
| 470 | // ( or just any time between timer_start() and timer_stop() ) |
|---|
| 471 | |
|---|
| 472 | function timer_start() { |
|---|
| 473 | global $timestart; |
|---|
| 474 | $mtime = microtime(); |
|---|
| 475 | $mtime = explode(" ",$mtime); |
|---|
| 476 | $mtime = $mtime[1] + $mtime[0]; |
|---|
| 477 | $timestart = $mtime; |
|---|
| 478 | return true; |
|---|
| 479 | } |
|---|
| 480 | |
|---|
| 481 | function timer_stop($display=0,$precision=3) { //if called like timer_stop(1), will echo $timetotal |
|---|
| 482 | global $timestart,$timeend; |
|---|
| 483 | $mtime = microtime(); |
|---|
| 484 | $mtime = explode(" ",$mtime); |
|---|
| 485 | $mtime = $mtime[1] + $mtime[0]; |
|---|
| 486 | $timeend = $mtime; |
|---|
| 487 | $timetotal = $timeend-$timestart; |
|---|
| 488 | if ($display) |
|---|
| 489 | echo number_format($timetotal,$precision); |
|---|
| 490 | return $timetotal; |
|---|
| 491 | } |
|---|
| 492 | |
|---|
| 493 | function weblog_ping($server = '', $path = '') { |
|---|
| 494 | $debug = false; |
|---|
| 495 | include_once (ABSPATH . WPINC . '/class-xmlrpc.php'); |
|---|
| 496 | include_once (ABSPATH . WPINC . '/class-xmlrpcs.php'); |
|---|
| 497 | |
|---|
| 498 | $f = new xmlrpcmsg('weblogUpdates.ping', |
|---|
| 499 | array(new xmlrpcval(get_settings('blogname'), 'string'), |
|---|
| 500 | new xmlrpcval(get_settings('home') ,'string'))); |
|---|
| 501 | |
|---|
| 502 | // must check for empty path |
|---|
| 503 | if (!$path) { |
|---|
| 504 | $path = '/'; |
|---|
| 505 | } |
|---|
| 506 | |
|---|
| 507 | $c = new xmlrpc_client($path, $server, 80); |
|---|
| 508 | $r = $c->send($f); |
|---|
| 509 | |
|---|
| 510 | if ('0' != $r) { |
|---|
| 511 | if ($debug) { |
|---|
| 512 | echo "<h3>Response Object Dump:</h3> |
|---|
| 513 | <pre>\n"; |
|---|
| 514 | print_r($r); |
|---|
| 515 | echo "</pre>\n"; |
|---|
| 516 | } |
|---|
| 517 | |
|---|
| 518 | $v = @phpxmlrpc_decode($r->value()); |
|---|
| 519 | if (!$r->faultCode()) { |
|---|
| 520 | $result['message'] = "<p class=\"rpcmsg\">"; |
|---|
| 521 | $result['message'] = $result['message'] . $v["message"] . "<br />\n"; |
|---|
| 522 | $result['message'] = $result['message'] . "</p>"; |
|---|
| 523 | } else { |
|---|
| 524 | $result['err'] = $r->faultCode(); |
|---|
| 525 | $result['message'] = "<!--\n"; |
|---|
| 526 | $result['message'] = $result['message'] . "Fault: "; |
|---|
| 527 | $result['message'] = $result['message'] . "Code: " . $r->faultCode(); |
|---|
| 528 | $result['message'] = $result['message'] . " Reason '" .$r->faultString()."'<BR>"; |
|---|
| 529 | $result['message'] = $result['message'] . "-->\n"; |
|---|
| 530 | } |
|---|
| 531 | |
|---|
| 532 | if ($debug) print '<blockquote>' . $result['message'] . '</blockquote>'; |
|---|
| 533 | } |
|---|
| 534 | } |
|---|
| 535 | |
|---|
| 536 | function generic_ping($post_id = 0) { |
|---|
| 537 | $services = get_settings('ping_sites'); |
|---|
| 538 | $services = preg_replace("|(\s)+|", '$1', $services); // Kill dupe lines |
|---|
| 539 | $services = trim($services); |
|---|
| 540 | if ('' != $services) { |
|---|
| 541 | $services = explode("\n", $services); |
|---|
| 542 | foreach ($services as $service) { |
|---|
| 543 | $uri = parse_url($service); |
|---|
| 544 | weblog_ping($uri['host'], $uri['path']); |
|---|
| 545 | } |
|---|
| 546 | } |
|---|
| 547 | } |
|---|
| 548 | |
|---|
| 549 | add_action('publish_post', 'generic_ping'); |
|---|
| 550 | |
|---|
| 551 | // Send a Trackback |
|---|
| 552 | function trackback($trackback_url, $title, $excerpt, $ID) { |
|---|
| 553 | global $wpdb, $tableposts; |
|---|
| 554 | $title = urlencode(stripslashes($title)); |
|---|
| 555 | $excerpt = urlencode(stripslashes($excerpt)); |
|---|
| 556 | $blog_name = urlencode(stripslashes(get_settings('blogname'))); |
|---|
| 557 | $tb_url = $trackback_url; |
|---|
| 558 | $url = urlencode(get_permalink($ID)); |
|---|
| 559 | $query_string = "title=$title&url=$url&blog_name=$blog_name&excerpt=$excerpt"; |
|---|
| 560 | $trackback_url = parse_url($trackback_url); |
|---|
| 561 | $http_request = 'POST ' . $trackback_url['path'] . $trackback_url['query'] . " HTTP/1.0\r\n"; |
|---|
| 562 | $http_request .= 'Host: '.$trackback_url['host']."\r\n"; |
|---|
| 563 | $http_request .= 'Content-Type: application/x-www-form-urlencoded'."\r\n"; |
|---|
| 564 | $http_request .= 'Content-Length: '.strlen($query_string)."\r\n"; |
|---|
| 565 | $http_request .= "\r\n"; |
|---|
| 566 | $http_request .= $query_string; |
|---|
| 567 | $fs = @fsockopen($trackback_url['host'], 80); |
|---|
| 568 | @fputs($fs, $http_request); |
|---|
| 569 | /* |
|---|
| 570 | $debug_file = 'trackback.log'; |
|---|
| 571 | $fp = fopen($debug_file, 'a'); |
|---|
| 572 | fwrite($fp, "\n*****\nRequest:\n\n$http_request\n\nResponse:\n\n"); |
|---|
| 573 | while(!@feof($fs)) { |
|---|
| 574 | fwrite($fp, @fgets($fs, 4096)); |
|---|
| 575 | } |
|---|
| 576 | fwrite($fp, "\n\n"); |
|---|
| 577 | fclose($fp); |
|---|
| 578 | */ |
|---|
| 579 | @fclose($fs); |
|---|
| 580 | |
|---|
| 581 | $wpdb->query("UPDATE $tableposts SET pinged = CONCAT(pinged, '\n', '$tb_url') WHERE ID = '$ID'"); |
|---|
| 582 | $wpdb->query("UPDATE $tableposts SET to_ping = REPLACE(to_ping, '$tb_url', '') WHERE ID = '$ID'"); |
|---|
| 583 | return $result; |
|---|
| 584 | } |
|---|
| 585 | |
|---|
| 586 | // trackback - reply |
|---|
| 587 | function trackback_response($error = 0, $error_message = '') { |
|---|
| 588 | if ($error) { |
|---|
| 589 | echo '<?xml version="1.0" encoding="iso-8859-1"?'.">\n"; |
|---|
| 590 | echo "<response>\n"; |
|---|
| 591 | echo "<error>1</error>\n"; |
|---|
| 592 | echo "<message>$error_message</message>\n"; |
|---|
| 593 | echo "</response>"; |
|---|
| 594 | } else { |
|---|
| 595 | echo '<?xml version="1.0" encoding="iso-8859-1"?'.">\n"; |
|---|
| 596 | echo "<response>\n"; |
|---|
| 597 | echo "<error>0</error>\n"; |
|---|
| 598 | echo "</response>"; |
|---|
| 599 | } |
|---|
| 600 | die(); |
|---|
| 601 | } |
|---|
| 602 | |
|---|
| 603 | function make_url_footnote($content) { |
|---|
| 604 | preg_match_all('/<a(.+?)href=\"(.+?)\"(.*?)>(.+?)<\/a>/', $content, $matches); |
|---|
| 605 | $j = 0; |
|---|
| 606 | for ($i=0; $i<count($matches[0]); $i++) { |
|---|
| 607 | $links_summary = (!$j) ? "\n" : $links_summary; |
|---|
| 608 | $j++; |
|---|
| 609 | $link_match = $matches[0][$i]; |
|---|
| 610 | $link_number = '['.($i+1).']'; |
|---|
| 611 | $link_url = $matches[2][$i]; |
|---|
| 612 | $link_text = $matches[4][$i]; |
|---|
| 613 | $content = str_replace($link_match, $link_text.' '.$link_number, $content); |
|---|
| 614 | $link_url = (strtolower(substr($link_url,0,7)) != 'http://') ? get_settings('home') . $link_url : $link_url; |
|---|
| 615 | $links_summary .= "\n".$link_number.' '.$link_url; |
|---|
| 616 | } |
|---|
| 617 | $content = strip_tags($content); |
|---|
| 618 | $content .= $links_summary; |
|---|
| 619 | return $content; |
|---|
| 620 | } |
|---|
| 621 | |
|---|
| 622 | |
|---|
| 623 | function xmlrpc_getposttitle($content) { |
|---|
| 624 | global $post_default_title; |
|---|
| 625 | if (preg_match('/<title>(.+?)<\/title>/is', $content, $matchtitle)) { |
|---|
| 626 | $post_title = $matchtitle[0]; |
|---|
| 627 | $post_title = preg_replace('/<title>/si', '', $post_title); |
|---|
| 628 | $post_title = preg_replace('/<\/title>/si', '', $post_title); |
|---|
| 629 | } else { |
|---|
| 630 | $post_title = $post_default_title; |
|---|
| 631 | } |
|---|
| 632 | return $post_title; |
|---|
| 633 | } |
|---|
| 634 | |
|---|
| 635 | function xmlrpc_getpostcategory($content) { |
|---|
| 636 | global $post_default_category; |
|---|
| 637 | if (preg_match('/<category>(.+?)<\/category>/is', $content, $matchcat)) { |
|---|
| 638 | $post_category = $matchcat[0]; |
|---|
| 639 | $post_category = preg_replace('/<category>/si', '', $post_category); |
|---|
| 640 | $post_category = preg_replace('/<\/category>/si', '', $post_category); |
|---|
| 641 | |
|---|
| 642 | } else { |
|---|
| 643 | $post_category = $post_default_category; |
|---|
| 644 | } |
|---|
| 645 | return $post_category; |
|---|
| 646 | } |
|---|
| 647 | |
|---|
| 648 | function xmlrpc_removepostdata($content) { |
|---|
| 649 | $content = preg_replace('/<title>(.+?)<\/title>/si', '', $content); |
|---|
| 650 | $content = preg_replace('/<category>(.+?)<\/category>/si', '', $content); |
|---|
| 651 | $content = trim($content); |
|---|
| 652 | return $content; |
|---|
| 653 | } |
|---|
| 654 | |
|---|
| 655 | function debug_fopen($filename, $mode) { |
|---|
| 656 | global $debug; |
|---|
| 657 | if ($debug == 1) { |
|---|
| 658 | $fp = fopen($filename, $mode); |
|---|
| 659 | return $fp; |
|---|
| 660 | } else { |
|---|
| 661 | return false; |
|---|
| 662 | } |
|---|
| 663 | } |
|---|
| 664 | |
|---|
| 665 | function debug_fwrite($fp, $string) { |
|---|
| 666 | global $debug; |
|---|
| 667 | if ($debug == 1) { |
|---|
| 668 | fwrite($fp, $string); |
|---|
| 669 | } |
|---|
| 670 | } |
|---|
| 671 | |
|---|
| 672 | function debug_fclose($fp) { |
|---|
| 673 | global $debug; |
|---|
| 674 | if ($debug == 1) { |
|---|
| 675 | fclose($fp); |
|---|
| 676 | } |
|---|
| 677 | } |
|---|
| 678 | |
|---|
| 679 | function pingback($content, $post_ID) { |
|---|
| 680 | include_once (ABSPATH . WPINC . '/class-xmlrpc.php'); |
|---|
| 681 | include_once (ABSPATH . WPINC . '/class-xmlrpcs.php'); |
|---|
| 682 | // original code by Mort (http://mort.mine.nu:8080) |
|---|
| 683 | global $wp_version; |
|---|
| 684 | $log = debug_fopen('./pingback.log', 'a'); |
|---|
| 685 | $post_links = array(); |
|---|
| 686 | debug_fwrite($log, 'BEGIN '.time()."\n"); |
|---|
| 687 | |
|---|
| 688 | // Variables |
|---|
| 689 | $ltrs = '\w'; |
|---|
| 690 | $gunk = '/#~:.?+=&%@!\-'; |
|---|
| 691 | $punc = '.:?\-'; |
|---|
| 692 | $any = $ltrs.$gunk.$punc; |
|---|
| 693 | $pingback_str_dquote = 'rel="pingback"'; |
|---|
| 694 | $pingback_str_squote = 'rel=\'pingback\''; |
|---|
| 695 | $x_pingback_str = 'x-pingback: '; |
|---|
| 696 | $pingback_href_original_pos = 27; |
|---|
| 697 | |
|---|
| 698 | // Step 1 |
|---|
| 699 | // Parsing the post, external links (if any) are stored in the $post_links array |
|---|
| 700 | // This regexp comes straight from phpfreaks.com |
|---|
| 701 | // http://www.phpfreaks.com/quickcode/Extract_All_URLs_on_a_Page/15.php |
|---|
| 702 | preg_match_all("{\b http : [$any] +? (?= [$punc] * [^$any] | $)}x", $content, $post_links_temp); |
|---|
| 703 | |
|---|
| 704 | // Debug |
|---|
| 705 | debug_fwrite($log, 'Post contents:'); |
|---|
| 706 | debug_fwrite($log, $content."\n"); |
|---|
| 707 | |
|---|
| 708 | // Step 2. |
|---|
| 709 | // Walking thru the links array |
|---|
| 710 | // first we get rid of links pointing to sites, not to specific files |
|---|
| 711 | // Example: |
|---|
| 712 | // http://dummy-weblog.org |
|---|
| 713 | // http://dummy-weblog.org/ |
|---|
| 714 | // http://dummy-weblog.org/post.php |
|---|
| 715 | // We don't wanna ping first and second types, even if they have a valid <link/> |
|---|
| 716 | |
|---|
| 717 | foreach($post_links_temp[0] as $link_test){ |
|---|
| 718 | $test = parse_url($link_test); |
|---|
| 719 | if (isset($test['query'])) { |
|---|
| 720 | $post_links[] = $link_test; |
|---|
| 721 | } elseif(($test['path'] != '/') && ($test['path'] != '')) { |
|---|
| 722 | $post_links[] = $link_test; |
|---|
| 723 | } |
|---|
| 724 | } |
|---|
| 725 | |
|---|
| 726 | foreach ($post_links as $pagelinkedto){ |
|---|
| 727 | debug_fwrite($log, 'Processing -- '.$pagelinkedto."\n\n"); |
|---|
| 728 | |
|---|
| 729 | $bits = parse_url($pagelinkedto); |
|---|
| 730 | if (!isset($bits['host'])) { |
|---|
| 731 | debug_fwrite($log, 'Couldn\'t find a hostname for '.$pagelinkedto."\n\n"); |
|---|
| 732 | continue; |
|---|
| 733 | } |
|---|
| 734 | $host = $bits['host']; |
|---|
| 735 | $path = isset($bits['path']) ? $bits['path'] : ''; |
|---|
| 736 | if (isset($bits['query'])) { |
|---|
| 737 | $path .= '?'.$bits['query']; |
|---|
| 738 | } |
|---|
| 739 | if (!$path) { |
|---|
| 740 | $path = '/'; |
|---|
| 741 | } |
|---|
| 742 | $port = isset($bits['port']) ? $bits['port'] : 80; |
|---|
| 743 | |
|---|
| 744 | // Try to connect to the server at $host |
|---|
| 745 | $fp = fsockopen($host, $port, $errno, $errstr, 30); |
|---|
| 746 | if (!$fp) { |
|---|
| 747 | debug_fwrite($log, 'Couldn\'t open a connection to '.$host."\n\n"); |
|---|
| 748 | continue; |
|---|
| 749 | } |
|---|
| 750 | |
|---|
| 751 | // Send the GET request |
|---|
| 752 | $request = "GET $path HTTP/1.1\r\nHost: $host\r\nUser-Agent: WordPress/$wp_version PHP/" . phpversion() . "\r\n\r\n"; |
|---|
| 753 | ob_end_flush(); |
|---|
| 754 | fputs($fp, $request); |
|---|
| 755 | |
|---|
| 756 | // Start receiving headers and content |
|---|
| 757 | $contents = ''; |
|---|
| 758 | $headers = ''; |
|---|
| 759 | $gettingHeaders = true; |
|---|
| 760 | $found_pingback_server = 0; |
|---|
| 761 | while (!feof($fp)) { |
|---|
| 762 | $line = fgets($fp, 4096); |
|---|
| 763 | if (trim($line) == '') { |
|---|
| 764 | $gettingHeaders = false; |
|---|
| 765 | } |
|---|
| 766 | if (!$gettingHeaders) { |
|---|
| 767 | $contents .= trim($line)."\n"; |
|---|
| 768 | $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote); |
|---|
| 769 | $pingback_link_offset_squote = strpos($contents, $pingback_str_squote); |
|---|
| 770 | } else { |
|---|
| 771 | $headers .= trim($line)."\n"; |
|---|
| 772 | $x_pingback_header_offset = strpos(strtolower($headers), $x_pingback_str); |
|---|
| 773 | } |
|---|
| 774 | if ($x_pingback_header_offset) { |
|---|
| 775 | preg_match('#x-pingback: (.+)#is', $headers, $matches); |
|---|
| 776 | $pingback_server_url = trim($matches[1]); |
|---|
| 777 | debug_fwrite($log, "Pingback server found from X-Pingback header @ $pingback_server_url\n"); |
|---|
| 778 | $found_pingback_server = 1; |
|---|
| 779 | break; |
|---|
| 780 | } |
|---|
| 781 | if ($pingback_link_offset_dquote || $pingback_link_offset_squote) { |
|---|
| 782 | $quote = ($pingback_link_offset_dquote) ? '"' : '\''; |
|---|
| 783 | $pingback_link_offset = ($quote=='"') ? $pingback_link_offset_dquote : $pingback_link_offset_squote; |
|---|
| 784 | $pingback_href_pos = @strpos($contents, 'href=', $pingback_link_offset); |
|---|
| 785 | $pingback_href_start = $pingback_href_pos+6; |
|---|
| 786 | $pingback_href_end = @strpos($contents, $quote, $pingback_href_start); |
|---|
| 787 | $pingback_server_url_len = $pingback_href_end-$pingback_href_start; |
|---|
| 788 | $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len); |
|---|
| 789 | debug_fwrite($log, "Pingback server found from Pingback <link /> tag @ $pingback_server_url\n"); |
|---|
| 790 | $found_pingback_server = 1; |
|---|
| 791 | break; |
|---|
| 792 | } |
|---|
| 793 | } |
|---|
| 794 | |
|---|
| 795 | if (!$found_pingback_server) { |
|---|
| 796 | debug_fwrite($log, "Pingback server not found\n\n*************************\n\n"); |
|---|
| 797 | @fclose($fp); |
|---|
| 798 | } else { |
|---|
| 799 | debug_fwrite($log,"\n\nPingback server data\n"); |
|---|
| 800 | |
|---|
| 801 | // Assuming there's a "http://" bit, let's get rid of it |
|---|
| 802 | $host_clear = substr($pingback_server_url, 7); |
|---|
| 803 | |
|---|
| 804 | // the trailing slash marks the end of the server name |
|---|
| 805 | $host_end = strpos($host_clear, '/'); |
|---|
| 806 | |
|---|
| 807 | // Another clear cut |
|---|
| 808 | $host_len = $host_end-$host_start; |
|---|
| 809 | $host = substr($host_clear, 0, $host_len); |
|---|
| 810 | debug_fwrite($log, 'host: '.$host."\n"); |
|---|
| 811 | |
|---|
| 812 | // If we got the server name right, the rest of the string is the server path |
|---|
| 813 | $path = substr($host_clear,$host_end); |
|---|
| 814 | debug_fwrite($log, 'path: '.$path."\n\n"); |
|---|
| 815 | |
|---|
| 816 | // Now, the RPC call |
|---|
| 817 | $method = 'pingback.ping'; |
|---|
| 818 | debug_fwrite($log, 'Page Linked To: '.$pagelinkedto."\n"); |
|---|
| 819 | debug_fwrite($log, 'Page Linked From: '); |
|---|
| 820 | $pagelinkedfrom = get_permalink($post_ID); |
|---|
| 821 | debug_fwrite($log, $pagelinkedfrom."\n"); |
|---|
| 822 | |
|---|
| 823 | $client = new xmlrpc_client($path, $host, 80); |
|---|
| 824 | $message = new xmlrpcmsg($method, array(new xmlrpcval($pagelinkedfrom), new xmlrpcval($pagelinkedto))); |
|---|
| 825 | $result = $client->send($message); |
|---|
| 826 | if ($result){ |
|---|
| 827 | if (!$result->value()){ |
|---|
| 828 | debug_fwrite($log, $result->faultCode().' -- '.$result->faultString()); |
|---|
| 829 | } else { |
|---|
| 830 | $value = phpxmlrpc_decode($result->value()); |
|---|
| 831 | if (is_array($value)) { |
|---|
| 832 | $value_arr = ''; |
|---|
| 833 | foreach($value as $blah) { |
|---|
| 834 | $value_arr .= $blah.' |||| '; |
|---|
| 835 | } |
|---|
| 836 | debug_fwrite($log, $value_arr); |
|---|
| 837 | } else { |
|---|
| 838 | debug_fwrite($log, $value); |
|---|
| 839 | } |
|---|
| 840 | } |
|---|
| 841 | } |
|---|
| 842 | @fclose($fp); |
|---|
| 843 | } |
|---|
| 844 | } |
|---|
| 845 | |
|---|
| 846 | debug_fwrite($log, "\nEND: ".time()."\n****************************\n\r"); |
|---|
| 847 | debug_fclose($log); |
|---|
| 848 | } |
|---|
| 849 | |
|---|
| 850 | function doGeoUrlHeader($post_list = '') { |
|---|
| 851 | global $posts; |
|---|
| 852 | |
|---|
| 853 | if ($posts && 1 === count($posts) && ! empty($posts[0]->post_lat)) { |
|---|
| 854 | // there's only one result see if it has a geo code |
|---|
| 855 | $row = $posts[0]; |
|---|
| 856 | $lat = $row->post_lat; |
|---|
| 857 | $lon = $row->post_lon; |
|---|
| 858 | $title = $row->post_title; |
|---|
| 859 | if(($lon != null) && ($lat != null) ) { |
|---|
| 860 | echo "<meta name=\"ICBM\" content=\"".$lat.", ".$lon."\" />\n"; |
|---|
| 861 | echo "<meta name=\"DC.title\" content=\"".convert_chars(strip_tags(get_bloginfo("name")))." - ".$title."\" />\n"; |
|---|
| 862 | echo "<meta name=\"geo.position\" content=\"".$lat.";".$lon."\" />\n"; |
|---|
| 863 | return; |
|---|
| 864 | } |
|---|
| 865 | } else { |
|---|
| 866 | if(get_settings('use_default_geourl')) { |
|---|
| 867 | // send the default here |
|---|
| 868 | echo "<meta name='ICBM' content=\"". get_settings('default_geourl_lat') .", ". get_settings('default_geourl_lon') ."\" />\n"; |
|---|
| 869 | echo "<meta name='DC.title' content=\"".convert_chars(strip_tags(get_bloginfo("name")))."\" />\n"; |
|---|
| 870 | echo "<meta name='geo.position' content=\"". get_settings('default_geourl_lat') .";". get_settings('default_geourl_lon') ."\" />\n"; |
|---|
| 871 | } |
|---|
| 872 | } |
|---|
| 873 | } |
|---|
| 874 | |
|---|
| 875 | function getRemoteFile($host,$path) { |
|---|
| 876 | $fp = fsockopen($host, 80, $errno, $errstr); |
|---|
| 877 | if ($fp) { |
|---|
| 878 | fputs($fp,"GET $path HTTP/1.0\r\nHost: $host\r\n\r\n"); |
|---|
| 879 | while ($line = fgets($fp, 4096)) { |
|---|
| 880 | $lines[] = $line; |
|---|
| 881 | } |
|---|
| 882 | fclose($fp); |
|---|
| 883 | return $lines; |
|---|
| 884 | } else { |
|---|
| 885 | return false; |
|---|
| 886 | } |
|---|
| 887 | } |
|---|
| 888 | |
|---|
| 889 | function pingGeoURL($blog_ID) { |
|---|
| 890 | |
|---|
| 891 | $ourUrl = get_settings('home') ."/index.php?p=".$blog_ID; |
|---|
| 892 | $host="geourl.org"; |
|---|
| 893 | $path="/ping/?p=".$ourUrl; |
|---|
| 894 | getRemoteFile($host,$path); |
|---|
| 895 | } |
|---|
| 896 | |
|---|
| 897 | /* wp_set_comment_status: |
|---|
| 898 | part of otaku42's comment moderation hack |
|---|
| 899 | changes the status of a comment according to $comment_status. |
|---|
| 900 | allowed values: |
|---|
| 901 | hold : set comment_approve field to 0 |
|---|
| 902 | approve: set comment_approve field to 1 |
|---|
| 903 | delete : remove comment out of database |
|---|
| 904 | |
|---|
| 905 | returns true if change could be applied |
|---|
| 906 | returns false on database error or invalid value for $comment_status |
|---|
| 907 | */ |
|---|
| 908 | function wp_set_comment_status($comment_id, $comment_status) { |
|---|
| 909 | global $wpdb, $tablecomments; |
|---|
| 910 | |
|---|
| 911 | switch($comment_status) { |
|---|
| 912 | case 'hold': |
|---|
| 913 | $query = "UPDATE $tablecomments SET comment_approved='0' WHERE comment_ID='$comment_id' LIMIT 1"; |
|---|
| 914 | break; |
|---|
| 915 | case 'approve': |
|---|
| 916 | $query = "UPDATE $tablecomments SET comment_approved='1' WHERE comment_ID='$comment_id' LIMIT 1"; |
|---|
| 917 | break; |
|---|
| 918 | case 'delete': |
|---|
| 919 | $query = "DELETE FROM $tablecomments WHERE comment_ID='$comment_id' LIMIT 1"; |
|---|
| 920 | break; |
|---|
| 921 | default: |
|---|
| 922 | return false; |
|---|
| 923 | } |
|---|
| 924 | |
|---|
| 925 | if ($wpdb->query($query)) { |
|---|
| 926 | return true; |
|---|
| 927 | } else { |
|---|
| 928 | return false; |
|---|
| 929 | } |
|---|
| 930 | } |
|---|
| 931 | |
|---|
| 932 | |
|---|
| 933 | /* wp_get_comment_status |
|---|
| 934 | part of otaku42's comment moderation hack |
|---|
| 935 | gets the current status of a comment |
|---|
| 936 | |
|---|
| 937 | returned values: |
|---|
| 938 | "approved" : comment has been approved |
|---|
| 939 | "unapproved": comment has not been approved |
|---|
| 940 | "deleted ": comment not found in database |
|---|
| 941 | |
|---|
| 942 | a (boolean) false signals an error |
|---|
| 943 | */ |
|---|
| 944 | function wp_get_comment_status($comment_id) { |
|---|
| 945 | global $wpdb, $tablecomments; |
|---|
| 946 | |
|---|
| 947 | $result = $wpdb->get_var("SELECT comment_approved FROM $tablecomments WHERE comment_ID='$comment_id' LIMIT 1"); |
|---|
| 948 | if ($result == NULL) { |
|---|
| 949 | return "deleted"; |
|---|
| 950 | } else if ($result == "1") { |
|---|
| 951 | return "approved"; |
|---|
| 952 | } else if ($result == "0") { |
|---|
| 953 | return "unapproved"; |
|---|
| 954 | } else { |
|---|
| 955 | return false; |
|---|
| 956 | } |
|---|
| 957 | } |
|---|
| 958 | |
|---|
| 959 | function wp_notify_postauthor($comment_id, $comment_type='comment') { |
|---|
| 960 | global $wpdb, $tablecomments, $tableposts, $tableusers; |
|---|
| 961 | global $querystring_start, $querystring_equal, $querystring_separator; |
|---|
| 962 | |
|---|
| 963 | $comment = $wpdb->get_row("SELECT * FROM $tablecomments WHERE comment_ID='$comment_id' LIMIT 1"); |
|---|
| 964 | $post = $wpdb->get_row("SELECT * FROM $tableposts WHERE ID='$comment->comment_post_ID' LIMIT 1"); |
|---|
| 965 | $user = $wpdb->get_row("SELECT * FROM $tableusers WHERE ID='$post->post_author' LIMIT 1"); |
|---|
| 966 | |
|---|
| 967 | if ('' == $user->user_email) return false; // If there's no email to send the comment to |
|---|
| 968 | |
|---|
| 969 | $comment_author_domain = gethostbyaddr($comment->comment_author_IP); |
|---|
| 970 | |
|---|
| 971 | $blogname = stripslashes(get_settings('blogname')); |
|---|
| 972 | |
|---|
| 973 | if ('comment' == $comment_type) { |
|---|
| 974 | $notify_message = "New comment on your post #$comment->comment_post_ID \"".stripslashes($post->post_title)."\"\r\n\r\n"; |
|---|
| 975 | $notify_message .= "Author : $comment->comment_author (IP: $comment->comment_author_IP , $comment_author_domain)\r\n"; |
|---|
| 976 | $notify_message .= "E-mail : $comment->comment_author_email\r\n"; |
|---|
| 977 | $notify_message .= "URI : $comment->comment_author_url\r\n"; |
|---|
| 978 | $notify_message .= "Whois : http://ws.arin.net/cgi-bin/whois.pl?queryinput=$comment->comment_author_IP\r\n"; |
|---|
| 979 | $notify_message .= "Comment:\r\n".stripslashes($comment->comment_content)."\r\n\r\n"; |
|---|
| 980 | $notify_message .= "You can see all comments on this post here: \r\n"; |
|---|
| 981 | $subject = '[' . $blogname . '] Comment: "' .stripslashes($post->post_title).'"'; |
|---|
| 982 | } elseif ('trackback' == $comment_type) { |
|---|
| 983 | $notify_message = "New trackback on your post #$comment_post_ID \"".stripslashes($post->post_title)."\"\r\n\r\n"; |
|---|
| 984 | $notify_message .= "Website: $comment->comment_author (IP: $comment->comment_author_IP , $comment_author_domain)\r\n"; |
|---|
| 985 | $notify_message .= "URI : $comment->comment_author_url\r\n"; |
|---|
| 986 | $notify_message .= "Excerpt: \n".stripslashes($comment->comment_content)."\r\n\r\n"; |
|---|
| 987 | $notify_message .= "You can see all trackbacks on this post here: \r\n"; |
|---|
| 988 | $subject = '[' . $blogname . '] Trackback: "' .stripslashes($post->post_title).'"'; |
|---|
| 989 | } elseif ('pingback' == $comment_type) { |
|---|
| 990 | $notify_message = "New pingback on your post #$comment_post_ID \"".stripslashes($post->post_title)."\"\r\n\r\n"; |
|---|
| 991 | $notify_message .= "Website: $comment->comment_author\r\n"; |
|---|
| 992 | $notify_message .= "URI : $comment->comment_author_url\r\n"; |
|---|
| 993 | $notify_message .= "Excerpt: \n[...] $original_context [...]\r\n\r\n"; |
|---|
| 994 | $notify_message .= "You can see all pingbacks on this post here: \r\n"; |
|---|
| 995 | $subject = '[' . $blogname . '] Pingback: "' .stripslashes($post->post_title).'"'; |
|---|
| 996 | } |
|---|
| 997 | $notify_message .= get_permalink($comment->comment_post_ID) . '#comments'; |
|---|
| 998 | |
|---|
| 999 | if ('' == $comment->comment_author_email || '' == $comment->comment_author) { |
|---|
| 1000 | $from = "From: \"$blogname\" <wordpress@" . $_SERVER['SERVER_NAME'] . '>'; |
|---|
| 1001 | } else { |
|---|
| 1002 | $from = 'From: "' . stripslashes($comment->comment_author) . "\" <$comment->comment_author_email>"; |
|---|
| 1003 | } |
|---|
| 1004 | |
|---|
| 1005 | $message_headers = "MIME-Version: 1.0\r\n" |
|---|
| 1006 | . "$from\r\n" |
|---|
| 1007 | . "Content-Type: text/plain; charset=\"" . get_settings('blog_charset') . "\"\r\n"; |
|---|
| 1008 | |
|---|
| 1009 | @mail($user->user_email, $subject, $notify_message, $message_headers); |
|---|
| 1010 | |
|---|
| 1011 | return true; |
|---|
| 1012 | } |
|---|
| 1013 | |
|---|
| 1014 | /* wp_notify_moderator |
|---|
| 1015 | notifies the moderator of the blog (usually the admin) |
|---|
| 1016 | about a new comment that waits for approval |
|---|
| 1017 | always returns true |
|---|
| 1018 | */ |
|---|
| 1019 | function wp_notify_moderator($comment_id) { |
|---|
| 1020 | global $wpdb, $tablecomments, $tableposts, $tableusers; |
|---|
| 1021 | global $querystring_start, $querystring_equal, $querystring_separator; |
|---|
| 1022 | |
|---|
| 1023 | $comment = $wpdb->get_row("SELECT * FROM $tablecomments WHERE comment_ID='$comment_id' LIMIT 1"); |
|---|
| 1024 | $post = $wpdb->get_row("SELECT * FROM $tableposts WHERE ID='$comment->comment_post_ID' LIMIT 1"); |
|---|
| 1025 | $user = $wpdb->get_row("SELECT * FROM $tableusers WHERE ID='$post->post_author' LIMIT 1"); |
|---|
| 1026 | |
|---|
| 1027 | $comment_author_domain = gethostbyaddr($comment->comment_author_IP); |
|---|
| 1028 | $comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $tablecomments WHERE comment_approved = '0'"); |
|---|
| 1029 | |
|---|
| 1030 | $notify_message = "A new comment on the post #$comment->comment_post_ID \"".stripslashes($post->post_title)."\" is waiting for your approval\r\n\r\n"; |
|---|
| 1031 | $notify_message .= "Author : $comment->comment_author (IP: $comment->comment_author_IP , $comment_author_domain)\r\n"; |
|---|
| 1032 | $notify_message .= "E-mail : $comment->comment_author_email\r\n"; |
|---|
| 1033 | $notify_message .= "URL : $comment->comment_author_url\r\n"; |
|---|
| 1034 | $notify_message .= "Whois : http://ws.arin.net/cgi-bin/whois.pl?queryinput=$comment->comment_author_IP\r\n"; |
|---|
| 1035 | $notify_message .= "Comment:\r\n".stripslashes($comment->comment_content)."\r\n\r\n"; |
|---|
| 1036 | $notify_message .= "To approve this comment, visit: " . get_settings('siteurl') . "/wp-admin/post.php?action=mailapprovecomment&p=".$comment->comment_post_ID."&comment=$comment_id\r\n"; |
|---|
| 1037 | $notify_message .= "To delete this comment, visit: " . get_settings('siteurl') . "/wp-admin/post.php?action=confirmdeletecomment&p=".$comment->comment_post_ID."&comment=$comment_id\r\n"; |
|---|
| 1038 | $notify_message .= "Currently $comments_waiting comments are waiting for approval. Please visit the moderation panel:\r\n"; |
|---|
| 1039 | $notify_message .= get_settings('siteurl') . "/wp-admin/moderation.php\r\n"; |
|---|
| 1040 | |
|---|
| 1041 | $subject = '[' . stripslashes(get_settings('blogname')) . '] Please approve: "' .stripslashes($post->post_title).'"'; |
|---|
| 1042 | $admin_email = get_settings("admin_email"); |
|---|
| 1043 | $from = "From: $admin_email"; |
|---|
| 1044 | |
|---|
| 1045 | $message_headers = "MIME-Version: 1.0\r\n" |
|---|
| 1046 | . "$from\r\n" |
|---|
| 1047 | . "Content-Type: text/plain; charset=\"" . get_settings('blog_charset') . "\"\r\n"; |
|---|
| 1048 | |
|---|
| 1049 | @mail($admin_email, $subject, $notify_message, $message_headers); |
|---|
| 1050 | |
|---|
| 1051 | return true; |
|---|
| 1052 | } |
|---|
| 1053 | |
|---|
| 1054 | |
|---|
| 1055 | function start_wp() { |
|---|
| 1056 | global $post, $id, $postdata, $authordata, $day, $preview, $page, $pages, $multipage, $more, $numpages; |
|---|
| 1057 | global $pagenow; |
|---|
| 1058 | if (!$preview) { |
|---|
| 1059 | $id = $post->ID; |
|---|
| 1060 | } else { |
|---|
| 1061 | $id = 0; |
|---|
| 1062 | $postdata = array ( |
|---|
| 1063 | 'ID' => 0, |
|---|
| 1064 | 'Author_ID' => $_GET['preview_userid'], |
|---|
| 1065 | 'Date' => $_GET['preview_date'], |
|---|
| 1066 | 'Content' => $_GET['preview_content'], |
|---|
| 1067 | 'Excerpt' => $_GET['preview_excerpt'], |
|---|
| 1068 | 'Title' => $_GET['preview_title'], |
|---|
| 1069 | 'Category' => $_GET['preview_category'], |
|---|
| 1070 | 'Notify' => 1 |
|---|
| 1071 | ); |
|---|
| 1072 | } |
|---|
| 1073 | $authordata = get_userdata($post->post_author); |
|---|
| 1074 | |
|---|
| 1075 | $day = mysql2date('d.m.y', $post->post_date); |
|---|
| 1076 | $currentmonth = mysql2date('m', $post->post_date); |
|---|
| 1077 | $numpages = 1; |
|---|
| 1078 | if (!$page) |
|---|
| 1079 | $page = 1; |
|---|
| 1080 | if (isset($p)) |
|---|
| 1081 | $more = 1; |
|---|
| 1082 | $content = $post->post_content; |
|---|
| 1083 | if (preg_match('/<!--nextpage-->/', $post->post_content)) { |
|---|
| 1084 | if ($page > 1) |
|---|
| 1085 | $more = 1; |
|---|
| 1086 | $multipage = 1; |
|---|
| 1087 | $content = stripslashes($post->post_content); |
|---|
| 1088 | $content = str_replace("\n<!--nextpage-->\n", '<!--nextpage-->', $content); |
|---|
| 1089 | $content = str_replace("\n<!--nextpage-->", '<!--nextpage-->', $content); |
|---|
| 1090 | $content = str_replace("<!--nextpage-->\n", '<!--nextpage-->', $content); |
|---|
| 1091 | $pages = explode('<!--nextpage-->', $content); |
|---|
| 1092 | $numpages = count($pages); |
|---|
| 1093 | } else { |
|---|
| 1094 | $pages[0] = stripslashes($post->post_content); |
|---|
| 1095 | $multipage = 0; |
|---|
| 1096 | } |
|---|
| 1097 | return true; |
|---|
| 1098 | } |
|---|
| 1099 | |
|---|
| 1100 | function is_new_day() { |
|---|
| 1101 | global $day, $previousday; |
|---|
| 1102 | if ($day != $previousday) { |
|---|
| 1103 | return(1); |
|---|
| 1104 | } else { |
|---|
| 1105 | return(0); |
|---|
| 1106 | } |
|---|
| 1107 | } |
|---|
| 1108 | |
|---|
| 1109 | // Filters: these are the core of WP's plugin architecture |
|---|
| 1110 | |
|---|
| 1111 | function apply_filters($tag, $string) { |
|---|
| 1112 | global $wp_filter; |
|---|
| 1113 | if (isset($wp_filter['all'])) { |
|---|
| 1114 | foreach ($wp_filter['all'] as $priority => $functions) { |
|---|
| 1115 | if (isset($wp_filter[$tag][$priority])) |
|---|
| 1116 | $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], $wp_filter[$tag][$priority]); |
|---|
| 1117 | else |
|---|
| 1118 | $wp_filter[$tag][$priority] = array_merge($wp_filter['all'][$priority], array()); |
|---|
| 1119 | $wp_filter[$tag][$priority] = array_unique($wp_filter[$tag][$priority]); |
|---|
| 1120 | } |
|---|
| 1121 | |
|---|
| 1122 | } |
|---|
| 1123 | |
|---|
| 1124 | if (isset($wp_filter[$tag])) { |
|---|
| 1125 | ksort($wp_filter[$tag]); |
|---|
| 1126 | foreach ($wp_filter[$tag] as $priority => $functions) { |
|---|
| 1127 | foreach($functions as $function) { |
|---|
| 1128 | $string = $function($string); |
|---|
| 1129 | } |
|---|
| 1130 | } |
|---|
| 1131 | } |
|---|
| 1132 | return $string; |
|---|
| 1133 | } |
|---|
| 1134 | |
|---|
| 1135 | function add_filter($tag, $function_to_add, $priority = 10) { |
|---|
| 1136 | global $wp_filter; |
|---|
| 1137 | // So the format is wp_filter['tag']['array of priorities']['array of functions'] |
|---|
| 1138 | if (!@in_array($function_to_add, $wp_filter[$tag]["$priority"])) { |
|---|
| 1139 | $wp_filter[$tag]["$priority"][] = $function_to_add; |
|---|
| 1140 | } |
|---|
| 1141 | return true; |
|---|
| 1142 | } |
|---|
| 1143 | |
|---|
| 1144 | function remove_filter($tag, $function_to_remove, $priority = 10) { |
|---|
| 1145 | global $wp_filter; |
|---|
| 1146 | if (@in_array($function_to_remove, $wp_filter[$tag]["$priority"])) { |
|---|
| 1147 | foreach ($wp_filter[$tag]["$priority"] as $function) { |
|---|
| 1148 | if ($function_to_remove != $function) { |
|---|
| 1149 | $new_function_list[] = $function; |
|---|
| 1150 | } |
|---|
| 1151 | } |
|---|
| 1152 | $wp_filter[$tag]["$priority"] = $new_function_list; |
|---|
| 1153 | } |
|---|
| 1154 | //die(var_dump($wp_filter)); |
|---|
| 1155 | return true; |
|---|
| 1156 | } |
|---|
| 1157 | |
|---|
| 1158 | // The *_action functions are just aliases for the *_filter functions, they take special strings instead of generic content |
|---|
| 1159 | |
|---|
| 1160 | function do_action($tag, $string) { |
|---|
| 1161 | return apply_filters($tag, $string); |
|---|
| 1162 | } |
|---|
| 1163 | |
|---|
| 1164 | function add_action($tag, $function_to_add, $priority = 10) { |
|---|
| 1165 | add_filter($tag, $function_to_add, $priority); |
|---|
| 1166 | } |
|---|
| 1167 | |
|---|
| 1168 | function remove_action($tag, $function_to_remove, $priority = 10) { |
|---|
| 1169 | remove_filter($tag, $function_to_remove, $priority); |
|---|
| 1170 | } |
|---|
| 1171 | |
|---|
| 1172 | /* rewrite_rules |
|---|
| 1173 | * Construct rewrite matches and queries from permalink structure. |
|---|
| 1174 | * matches - The name of the match array to use in the query strings. |
|---|
| 1175 | * If empty, $1, $2, $3, etc. are used. |
|---|
| 1176 | * Returns an associate array of matches and queries. |
|---|
| 1177 | */ |
|---|
| 1178 | function rewrite_rules($matches = '', $permalink_structure = '') { |
|---|
| 1179 | |
|---|
| 1180 | function preg_index($number, $matches = '') { |
|---|
| 1181 | $match_prefix = '$'; |
|---|
| 1182 | $match_suffix = ''; |
|---|
| 1183 | |
|---|
| 1184 | if (! empty($matches)) { |
|---|
| 1185 | $match_prefix = '$' . $matches . '['; |
|---|
| 1186 | $match_suffix = ']'; |
|---|
| 1187 | } |
|---|
| 1188 | |
|---|
| 1189 | return "$match_prefix$number$match_suffix"; |
|---|
| 1190 | } |
|---|
| 1191 | |
|---|
| 1192 | $rewrite = array(); |
|---|
| 1193 | |
|---|
| 1194 | if (empty($permalink_structure)) { |
|---|
| 1195 | $permalink_structure = get_settings('permalink_structure'); |
|---|
| 1196 | |
|---|
| 1197 | if (empty($permalink_structure)) { |
|---|
| 1198 | return $rewrite; |
|---|
| 1199 | } |
|---|
| 1200 | } |
|---|
| 1201 | |
|---|
| 1202 | $rewritecode = |
|---|
| 1203 | array( |
|---|
| 1204 | '%year%', |
|---|
| 1205 | '%monthnum%', |
|---|
| 1206 | '%day%', |
|---|
| 1207 | '%hour%', |
|---|
| 1208 | '%minute%', |
|---|
| 1209 | '%second%', |
|---|
| 1210 | '%postname%', |
|---|
| 1211 | '%post_id%' |
|---|
| 1212 | ); |
|---|
| 1213 | |
|---|
| 1214 | $rewritereplace = |
|---|
| 1215 | array( |
|---|
| 1216 | '([0-9]{4})?', |
|---|
| 1217 | '([0-9]{1,2})?', |
|---|
| 1218 | '([0-9]{1,2})?', |
|---|
| 1219 | '([0-9]{1,2})?', |
|---|
| 1220 | '([0-9]{1,2})?', |
|---|
| 1221 | '([0-9]{1,2})?', |
|---|
| 1222 | '([_0-9a-z-]+)?', |
|---|
| 1223 | '([0-9]+)?' |
|---|
| 1224 | ); |
|---|
| 1225 | |
|---|
| 1226 | $queryreplace = |
|---|
| 1227 | array ( |
|---|
| 1228 | 'year=', |
|---|
| 1229 | 'monthnum=', |
|---|
| 1230 | 'day=', |
|---|
| 1231 | 'hour=', |
|---|
| 1232 | 'minute=', |
|---|
| 1233 | 'second=', |
|---|
| 1234 | 'name=', |
|---|
| 1235 | 'p=' |
|---|
| 1236 | ); |
|---|
| 1237 | |
|---|
| 1238 | |
|---|
| 1239 | $match = str_replace('/', '/?', $permalink_structure); |
|---|
| 1240 | $match = preg_replace('|/[?]|', '', $match, 1); |
|---|
| 1241 | |
|---|
| 1242 | $match = str_replace($rewritecode, $rewritereplace, $match); |
|---|
| 1243 | $match = preg_replace('|[?]|', '', $match, 1); |
|---|
| 1244 | |
|---|
| 1245 | $feedmatch = trailingslashit(str_replace('?/?', '/', $match)); |
|---|
| 1246 | $trackbackmatch = $feedmatch; |
|---|
| 1247 | |
|---|
| 1248 | preg_match_all('/%.+?%/', $permalink_structure, $tokens); |
|---|
| 1249 | |
|---|
| 1250 | $query = 'index.php?'; |
|---|
| 1251 | $feedquery = 'wp-feed.php?'; |
|---|
| 1252 | $trackbackquery = 'wp-trackback.php?'; |
|---|
| 1253 | for ($i = 0; $i < count($tokens[0]); ++$i) { |
|---|
| 1254 | if (0 < $i) { |
|---|
| 1255 | $query .= '&'; |
|---|
| 1256 | $feedquery .= '&'; |
|---|
| 1257 | $trackbackquery .= '&'; |
|---|
| 1258 | } |
|---|
| 1259 | |
|---|
| 1260 | $query_token = str_replace($rewritecode, $queryreplace, $tokens[0][$i]) . preg_index($i+1, $matches); |
|---|
| 1261 | $query .= $query_token; |
|---|
| 1262 | $feedquery .= $query_token; |
|---|
| 1263 | $trackbackquery .= $query_token; |
|---|
| 1264 | } |
|---|
| 1265 | ++$i; |
|---|
| 1266 | |
|---|
| 1267 | // Add post paged stuff |
|---|
| 1268 | $match .= '([0-9]+)?/?$'; |
|---|
| 1269 | $query .= '&page=' . preg_index($i, $matches); |
|---|
| 1270 | |
|---|
| 1271 | // Add post feed stuff |
|---|
| 1272 | $feedregex = '(feed|rdf|rss|rss2|atom)/?$'; |
|---|
| 1273 | $feedmatch .= $feedregex; |
|---|
| 1274 | $feedquery .= '&feed=' . preg_index($i, $matches); |
|---|
| 1275 | |
|---|
| 1276 | // Add post trackback stuff |
|---|
| 1277 | $trackbackregex = 'trackback/?$'; |
|---|
| 1278 | $trackbackmatch .= $trackbackregex; |
|---|
| 1279 | |
|---|
| 1280 | // Site feed |
|---|
| 1281 | $sitefeedmatch = 'feed/?([_0-9a-z-]+)?/?$'; |
|---|
| 1282 | $sitefeedquery = 'wp-feed.php?feed=' . preg_index(1, $matches); |
|---|
| 1283 | |
|---|
| 1284 | // Site comment feed |
|---|
| 1285 | $sitecommentfeedmatch = 'comments/feed/?([_0-9a-z-]+)?/?$'; |
|---|
| 1286 | $sitecommentfeedquery = 'wp-feed.php?feed=' . preg_index(1, $matches) . '&withcomments=1'; |
|---|
| 1287 | |
|---|
| 1288 | // Code for nice categories and authors, currently not very flexible |
|---|
| 1289 | $front = substr($permalink_structure, 0, strpos($permalink_structure, '%')); |
|---|
| 1290 | if ( '' == get_settings('category_base') ) |
|---|
| 1291 | $catmatch = $front . 'category/'; |
|---|
| 1292 | else |
|---|
| 1293 | $catmatch = get_settings('category_base') . '/'; |
|---|
| 1294 | $catmatch = preg_replace('|^/+|', '', $catmatch); |
|---|
| 1295 | |
|---|
| 1296 | $catfeedmatch = $catmatch . '(.*)/' . $feedregex; |
|---|
| 1297 | $catfeedquery = 'wp-feed.php?category_name=' . preg_index(1, $matches) . '&feed=' . preg_index(2, $matches); |
|---|
| 1298 | |
|---|
| 1299 | $catmatch = $catmatch . '?(.*)'; |
|---|
| 1300 | $catquery = 'index.php?category_name=' . preg_index(1, $matches); |
|---|
| 1301 | |
|---|
| 1302 | $authormatch = $front . 'author/'; |
|---|
| 1303 | $authormatch = preg_replace('|^/+|', '', $authormatch); |
|---|
| 1304 | |
|---|
| 1305 | $authorfeedmatch = $authormatch . '(.*)/' . $feedregex; |
|---|
| 1306 | $authorfeedquery = 'wp-feed.php?author_name=' . preg_index(1, $matches) . '&feed=' . preg_index(2, $matches); |
|---|
| 1307 | |
|---|
| 1308 | $authormatch = $authormatch . '?(.*)'; |
|---|
| 1309 | $authorquery = 'index.php?author_name=' . preg_index(1, $matches); |
|---|
| 1310 | |
|---|
| 1311 | $rewrite = array( |
|---|
| 1312 | $catfeedmatch => $catfeedquery, |
|---|
| 1313 | $catmatch => $catquery, |
|---|
| 1314 | $authorfeedmatch => $authorfeedquery, |
|---|
| 1315 | $authormatch => $authorquery, |
|---|
| 1316 | $match => $query, |
|---|
| 1317 | $feedmatch => $feedquery, |
|---|
| 1318 | $trackbackmatch => $trackbackquery, |
|---|
| 1319 | $sitefeedmatch => $sitefeedquery, |
|---|
| 1320 | $sitecommentfeedmatch => $sitecommentfeedquery |
|---|
| 1321 | ); |
|---|
| 1322 | |
|---|
| 1323 | return $rewrite; |
|---|
| 1324 | } |
|---|
| 1325 | |
|---|
| 1326 | function get_posts($args) { |
|---|
| 1327 | global $wpdb, $tableposts; |
|---|
| 1328 | parse_str($args, $r); |
|---|
| 1329 | if (!isset($r['numberposts'])) $r['numberposts'] = 5; |
|---|
| 1330 | if (!isset($r['offset'])) $r['offset'] = 0; |
|---|
| 1331 | // The following not implemented yet |
|---|
| 1332 | if (!isset($r['category'])) $r['category'] = ''; |
|---|
| 1333 | if (!isset($r['orderby'])) $r['orderby'] = ''; |
|---|
| 1334 | if (!isset($r['order'])) $r['order'] = ''; |
|---|
| 1335 | |
|---|
| 1336 | $now = current_time('mysql'); |
|---|
| 1337 | |
|---|
| 1338 | $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']); |
|---|
| 1339 | |
|---|
| 1340 | return $posts; |
|---|
| 1341 | } |
|---|
| 1342 | |
|---|
| 1343 | function check_comment($author, $email, $url, $comment, $user_ip) { |
|---|
| 1344 | if (1 == get_settings('comment_moderation')) return false; // If moderation is set to manual |
|---|
| 1345 | |
|---|
| 1346 | if ( (count(explode('http:', $comment)) - 1) >= get_settings('comment_max_links') ) |
|---|
| 1347 | return false; // Check # of external links |
|---|
| 1348 | |
|---|
| 1349 | if ('' == trim( get_settings('moderation_keys') ) ) return true; // If moderation keys are empty |
|---|
| 1350 | $words = explode("\n", get_settings('moderation_keys') ); |
|---|
| 1351 | foreach ($words as $word) { |
|---|
| 1352 | $word = trim($word); |
|---|
| 1353 | $pattern = "#$word#i"; |
|---|
| 1354 | if ( preg_match($pattern, $author) ) return false; |
|---|
| 1355 | if ( preg_match($pattern, $email) ) return false; |
|---|
| 1356 | if ( preg_match($pattern, $url) ) return false; |
|---|
| 1357 | if ( preg_match($pattern, $comment) ) return false; |
|---|
| 1358 | if ( preg_match($pattern, $user_ip) ) return false; |
|---|
| 1359 | } |
|---|
| 1360 | |
|---|
| 1361 | return true; |
|---|
| 1362 | } |
|---|
| 1363 | |
|---|
| 1364 | function wp_head() { |
|---|
| 1365 | do_action('wp_head', ''); |
|---|
| 1366 | } |
|---|
| 1367 | |
|---|
| 1368 | ?> |
|---|