Advertisement
johnburn

functionsa.php

Apr 26th, 2011
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 89.74 KB | None | 0 0
  1. <?php
  2. function mysql2date($dateformatstring, $mysqlstring, $translate = TRUE) {
  3.     $m = $mysqlstring;
  4.     if (empty($m)) {
  5.         return FALSE;
  6.     }
  7.     if ("G" == $dateformatstring) {
  8.         return strtotime($m . " +0000");
  9.     }
  10.     $i = strtotime($m);
  11.     if ("U" == $dateformatstring) {
  12.         return $i;
  13.     }
  14.     if ($translate) {
  15.         return date_i18n($dateformatstring, $i);
  16.     }
  17.     return date($dateformatstring, $i);
  18. }
  19. function current_time($type, $gmt = 0) {
  20.     switch ($type) {
  21.         case "mysql":
  22.             if ($gmt) {
  23.                 return gmdate("Y-m-d H:i:s");
  24.             }
  25.             return gmdate("Y-m-d H:i:s", time() + get_option("gmt_offset") * 3600);
  26.         case "timestamp":
  27.             if ($gmt) {
  28.                 return time();
  29.             }
  30.             return time() + get_option("gmt_offset") * 3600;
  31.     }
  32. }
  33. function date_i18n($dateformatstring, $unixtimestamp = FALSE, $gmt = FALSE) {
  34.     global $wp_locale;
  35.     $i = $unixtimestamp;
  36.     if (FALSE === $i || intval($i) < 0) {
  37.         if (!$gmt) {
  38.             $i = current_time("timestamp");
  39.         } else {
  40.             $i = time();
  41.         }
  42.         $gmt = TRUE;
  43.     }
  44.     $req_format = $dateformatstring;
  45.     $datefunc = $gmt ? "gmdate" : "date";
  46.     if (!empty($wp_locale->month) || !empty($wp_locale->weekday)) {
  47.         $datemonth = $wp_locale->get_month($datefunc("m", $i));
  48.         $datemonth_abbrev = $wp_locale->get_month_abbrev($datemonth);
  49.         $dateweekday = $wp_locale->get_weekday($datefunc("w", $i));
  50.         $dateweekday_abbrev = $wp_locale->get_weekday_abbrev($dateweekday);
  51.         $datemeridiem = $wp_locale->get_meridiem($datefunc("a", $i));
  52.         $datemeridiem_capital = $wp_locale->get_meridiem($datefunc("A", $i));
  53.         $dateformatstring = " " . $dateformatstring;
  54.         $dateformatstring = preg_replace("/([^\\\\])D/", "\\1" . backslashit($dateweekday_abbrev), $dateformatstring);
  55.         $dateformatstring = preg_replace("/([^\\\\])F/", "\\1" . backslashit($datemonth), $dateformatstring);
  56.         $dateformatstring = preg_replace("/([^\\\\])l/", "\\1" . backslashit($dateweekday), $dateformatstring);
  57.         $dateformatstring = preg_replace("/([^\\\\])M/", "\\1" . backslashit($datemonth_abbrev), $dateformatstring);
  58.         $dateformatstring = preg_replace("/([^\\\\])a/", "\\1" . backslashit($datemeridiem), $dateformatstring);
  59.         $dateformatstring = preg_replace("/([^\\\\])A/", "\\1" . backslashit($datemeridiem_capital), $dateformatstring);
  60.         $dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring) - 1);
  61.     }
  62.     $timezone_formats = array("P", "I", "O", "T", "Z", "e");
  63.     $timezone_formats_re = implode("|", $timezone_formats);
  64.     if (preg_match("/" . $timezone_formats_re . "/", $dateformatstring) && wp_timezone_supported()) {
  65.         $timezone_string = get_option("timezone_string");
  66.         if ($timezone_string) {
  67.             $timezone_object = timezone_open($timezone_string);
  68.             $date_object = date_create(NULL, $timezone_object);
  69.             foreach($timezone_formats as $timezone_format) {
  70.                 if (FALSE !== strpos($dateformatstring, $timezone_format)) {
  71.                     $formatted = date_format($date_object, $timezone_format);
  72.                     $dateformatstring = " " . $dateformatstring;
  73.                     $dateformatstring = preg_replace("/([^\\\\])" . $timezone_format . "/", "\\1" . backslashit($formatted), $dateformatstring);
  74.                     $dateformatstring = substr($dateformatstring, 1, strlen($dateformatstring) - 1);
  75.                 }
  76.             }
  77.         }
  78.     }
  79.     $j = @$datefunc($dateformatstring, $i);
  80.     $j = apply_filters("date_i18n", $j, $req_format, $i, $gmt);
  81.     return $j;
  82. }
  83. function number_format_i18n($number, $decimals = 0) {
  84.     global $wp_locale;
  85.     $formatted = number_format($number, absint($decimals), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep']);
  86.     return apply_filters("number_format_i18n", $formatted);
  87. }
  88. function size_format($bytes, $decimals = 0) {
  89.     $quant = array("TB" => 1.09951e+012, "GB" => 1073741824, "MB" => 1048576, "kB" => 1024, "B " => 1);
  90.     foreach($quant as $unit => $mag) {
  91.         if (!($mag <= doubleval($bytes))) {
  92.             continue;
  93.         }
  94.         return number_format_i18n($bytes / $mag, $decimals) . " " . $unit;
  95.     }
  96.     return FALSE;
  97. }
  98. function get_weekstartend($mysqlstring, $start_of_week = "") {
  99.     $my = substr($mysqlstring, 0, 4);
  100.     $mm = substr($mysqlstring, 8, 2);
  101.     $md = substr($mysqlstring, 5, 2);
  102.     $day = mktime(0, 0, 0, $md, $mm, $my);
  103.     $weekday = date("w", $day);
  104.     if (!is_numeric($start_of_week)) {
  105.         $start_of_week = get_option("start_of_week");
  106.     }
  107.     if ($weekday < $start_of_week) {
  108.         $weekday+= 7;
  109.     }
  110.     $start = $day - 86400 * ($weekday - $start_of_week);
  111.     $end = $start + 604799;
  112.     return compact("start", "end");
  113. }
  114. function maybe_unserialize($original) {
  115.     if (is_serialized($original)) {
  116.         return unserialize($original);
  117.     }
  118.     return $original;
  119. }
  120. function is_serialized($data) {
  121.     if (!is_string($data)) {
  122.         return FALSE;
  123.     }
  124.     $data = trim($data);
  125.     if ("N;" == $data) {
  126.         return TRUE;
  127.     }
  128.     $length = strlen($data);
  129.     if ($length < 4) {
  130.         return FALSE;
  131.     }
  132.     if (":" !== $data[1]) {
  133.         return FALSE;
  134.     }
  135.     $lastc = $data[$length - 1];
  136.     if (";" !== $lastc && "}" !== $lastc) {
  137.         return FALSE;
  138.     }
  139.     $token = $data[0];
  140.     switch ($token) {
  141.         case "s":
  142.             return FALSE;
  143.         case "a":
  144.         case "O":
  145.             return preg_match("/^" . $token . ":[0-9]+:/s", $data);
  146.         case "b":
  147.         case "i":
  148.         case "d":
  149.             return preg_match("/^" . $token . ":[0-9.E-]+;\$/", $data);
  150.     }
  151.     return FALSE;
  152. }
  153. function is_serialized_string($data) {
  154.     if (!is_string($data)) {
  155.         return FALSE;
  156.     }
  157.     $data = trim($data);
  158.     if (preg_match("/^s:[0-9]+:.*;\$/s", $data)) {
  159.         return TRUE;
  160.     }
  161.     return FALSE;
  162. }
  163. function get_option($option, $default = FALSE) {
  164.     global $wpdb;
  165.     $pre = apply_filters("pre_option_" . $option, FALSE);
  166.     if (FALSE !== $pre) {
  167.         return $pre;
  168.     }
  169.     $option = trim($option);
  170.     if (empty($option)) {
  171.         return FALSE;
  172.     }
  173.     if (defined("WP_SETUP_CONFIG")) {
  174.         return FALSE;
  175.     }
  176.     if (!defined("WP_INSTALLING")) {
  177.         $notoptions = wp_cache_get("notoptions", "options");
  178.         if (isset($notoptions[$option])) {
  179.             return $default;
  180.         }
  181.         $alloptions = wp_load_alloptions();
  182.         if (isset($alloptions[$option])) {
  183.             $value = $alloptions[$option];
  184.         } else {
  185.             $value = wp_cache_get($option, "options");
  186.             if (FALSE === $value) {
  187.                 $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM " . $wpdb->options . " WHERE option_name = %s LIMIT 1", $option));
  188.                 if (is_object($row)) {
  189.                     $value = $row->option_value;
  190.                     wp_cache_add($option, $value, "options");
  191.                 } else {
  192.                     $notoptions[$option] = TRUE;
  193.                     wp_cache_set("notoptions", $notoptions, "options");
  194.                     return $default;
  195.                 }
  196.             }
  197.         }
  198.     } else {
  199.         $suppress = $wpdb->suppress_errors();
  200.         $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM " . $wpdb->options . " WHERE option_name = %s LIMIT 1", $option));
  201.         $wpdb->suppress_errors($suppress);
  202.         if (is_object($row)) {
  203.             $value = $row->option_value;
  204.         } else {
  205.             return $default;
  206.         }
  207.     }
  208.     if ("home" == $option && "" == $value) {
  209.         return get_option("siteurl");
  210.     }
  211.     if (in_array($option, array("siteurl", "home", "category_base", "tag_base"))) {
  212.         $value = untrailingslashit($value);
  213.     }
  214.     return apply_filters("option_" . $option, maybe_unserialize($value));
  215. }
  216. function wp_protect_special_option($option) {
  217.     $protected = array("alloptions", "notoptions");
  218.     if (in_array($option, $protected)) {
  219.         wp_die(sprintf(__("%s is a protected WP option and may not be modified"), esc_html($option)));
  220.     }
  221. }
  222. function form_option($option) {
  223.     echo esc_attr(get_option($option));
  224. }
  225. function wp_load_alloptions() {
  226.     global $wpdb;
  227.     if (defined("WP_INSTALLING")) {
  228.     }
  229.     if (!is_multisite()) {
  230.         $alloptions = wp_cache_get("alloptions", "options");
  231.     } else {
  232.         $alloptions = FALSE;
  233.     }
  234.     if (!$alloptions) {
  235.         $suppress = $wpdb->suppress_errors();
  236.         if (!($alloptions_db = $wpdb->get_results("SELECT option_name, option_value FROM " . $wpdb->options . " WHERE autoload = 'yes'"))) {
  237.             $alloptions_db = $wpdb->get_results("SELECT option_name, option_value FROM " . $wpdb->options);
  238.         }
  239.         $wpdb->suppress_errors($suppress);
  240.         $alloptions = array();
  241.         foreach(( array )$alloptions_db as $o) {
  242.             $alloptions[$o->option_name] = $o->option_value;
  243.         }
  244.         if (defined("WP_INSTALLING")) {
  245.         }
  246.         if (!is_multisite()) {
  247.             wp_cache_add("alloptions", $alloptions, "options");
  248.         }
  249.     }
  250.     return $alloptions;
  251. }
  252. function wp_load_core_site_options($site_id = NULL) {
  253.     global $wpdb;
  254.     global $_wp_using_ext_object_cache;
  255.     if (!is_multisite() && $_wp_using_ext_object_cache || defined("WP_INSTALLING")) {
  256.         return;
  257.     }
  258.     if (empty($site_id)) {
  259.         $site_id = $wpdb->siteid;
  260.     }
  261.     $core_options = array("site_name", "siteurl", "active_sitewide_plugins", "_site_transient_timeout_theme_roots", "_site_transient_theme_roots", "site_admins", "can_compress_scripts", "global_terms_enabled");
  262.     $core_options_in = "'" . implode("', '", $core_options) . "'";
  263.     $options = $wpdb->get_results($wpdb->prepare("SELECT meta_key, meta_value FROM " . $wpdb->sitemeta . " WHERE meta_key IN ({$core_options_in}) AND site_id = %d", $site_id));
  264.     foreach($options as $option) {
  265.         $key = $option->meta_key;
  266.         $cache_key = "{$site_id}:{$key}";
  267.         $option->meta_value = maybe_unserialize($option->meta_value);
  268.         wp_cache_set($cache_key, $option->meta_value, "site-options");
  269.     }
  270. }
  271. function update_option($option, $newvalue) {
  272.     global $wpdb;
  273.     $option = trim($option);
  274.     if (empty($option)) {
  275.         return FALSE;
  276.     }
  277.     wp_protect_special_option($option);
  278.     if (is_object($newvalue)) {
  279.         $newvalue = wp_clone($newvalue);
  280.     }
  281.     $newvalue = sanitize_option($option, $newvalue);
  282.     $oldvalue = get_option($option);
  283.     $newvalue = apply_filters("pre_update_option_" . $option, $newvalue, $oldvalue);
  284.     if ($newvalue === $oldvalue) {
  285.         return FALSE;
  286.     }
  287.     if (FALSE === $oldvalue) {
  288.         return add_option($option, $newvalue);
  289.     }
  290.     $notoptions = wp_cache_get("notoptions", "options");
  291.     if (is_array($notoptions) && isset($notoptions[$option])) {
  292.         unset($notoptions[$option]);
  293.         wp_cache_set("notoptions", $notoptions, "options");
  294.     }
  295.     $_newvalue = $newvalue;
  296.     $newvalue = maybe_serialize($newvalue);
  297.     do_action("update_option", $option, $oldvalue, $_newvalue);
  298.     if (!defined("WP_INSTALLING")) {
  299.         $alloptions = wp_load_alloptions();
  300.         if (isset($alloptions[$option])) {
  301.             $alloptions[$option] = $_newvalue;
  302.             wp_cache_set("alloptions", $alloptions, "options");
  303.         } else {
  304.             wp_cache_set($option, $_newvalue, "options");
  305.         }
  306.     }
  307.     $result = $wpdb->update($wpdb->options, array("option_value" => $newvalue), array("option_name" => $option));
  308.     if ($result) {
  309.         do_action("update_option_" . $option, $oldvalue, $_newvalue);
  310.         do_action("updated_option", $option, $oldvalue, $_newvalue);
  311.         return TRUE;
  312.     }
  313.     return FALSE;
  314. }
  315. function add_option($option, $value = "", $deprecated = "", $autoload = "yes") {
  316.     global $wpdb;
  317.     if (!empty($deprecated)) {
  318.         _deprecated_argument("add_option", "2.3");
  319.     }
  320.     $option = trim($option);
  321.     if (empty($option)) {
  322.         return FALSE;
  323.     }
  324.     wp_protect_special_option($option);
  325.     if (is_object($value)) {
  326.         $value = wp_clone($value);
  327.     }
  328.     $value = sanitize_option($option, $value);
  329.     $notoptions = wp_cache_get("notoptions", "options");
  330.     if ((!is_array($notoptions) && !isset($notoptions[$option])) || FALSE !== get_option($option)) {
  331.         return;
  332.     }
  333.     $_value = $value;
  334.     $value = maybe_serialize($value);
  335.     $autoload = "no" === $autoload ? "no" : "yes";
  336.     do_action("add_option", $option, $_value);
  337.     if (!defined("WP_INSTALLING")) {
  338.         if ("yes" == $autoload) {
  339.             $alloptions = wp_load_alloptions();
  340.             $alloptions[$option] = $value;
  341.             wp_cache_set("alloptions", $alloptions, "options");
  342.         } else {
  343.             wp_cache_set($option, $value, "options");
  344.         }
  345.     }
  346.     $notoptions = wp_cache_get("notoptions", "options");
  347.     if (is_array($notoptions) && isset($notoptions[$option])) {
  348.         unset($notoptions[$option]);
  349.         wp_cache_set("notoptions", $notoptions, "options");
  350.     }
  351.     $result = $wpdb->query($wpdb->prepare("INSERT INTO `" . $wpdb->options . "` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $value, $autoload));
  352.     if ($result) {
  353.         do_action("add_option_" . $option, $option, $_value);
  354.         do_action("added_option", $option, $_value);
  355.         return TRUE;
  356.     }
  357.     return FALSE;
  358. }
  359. function delete_option($option) {
  360.     global $wpdb;
  361.     wp_protect_special_option($option);
  362.     $row = $wpdb->get_row($wpdb->prepare("SELECT autoload FROM " . $wpdb->options . " WHERE option_name = %s", $option));
  363.     if (is_null($row)) {
  364.         return FALSE;
  365.     }
  366.     do_action("delete_option", $option);
  367.     $result = $wpdb->query($wpdb->prepare("DELETE FROM " . $wpdb->options . " WHERE option_name = %s", $option));
  368.     if (!defined("WP_INSTALLING")) {
  369.         if ("yes" == $row->autoload) {
  370.             $alloptions = wp_load_alloptions();
  371.             if (is_array($alloptions) && isset($alloptions[$option])) {
  372.                 unset($alloptions[$option]);
  373.                 wp_cache_set("alloptions", $alloptions, "options");
  374.             }
  375.         } else {
  376.             wp_cache_delete($option, "options");
  377.         }
  378.     }
  379.     if ($result) {
  380.         do_action("delete_option_" . $option, $option);
  381.         do_action("deleted_option", $option);
  382.         return TRUE;
  383.     }
  384.     return FALSE;
  385. }
  386. function delete_transient($transient) {
  387.     global $_wp_using_ext_object_cache;
  388.     do_action("delete_transient_" . $transient, $transient);
  389.     if ($_wp_using_ext_object_cache) {
  390.         $result = wp_cache_delete($transient, "transient");
  391.     } else {
  392.         $option_timeout = "_transient_timeout_" . $transient;
  393.         $option = "_transient_" . $transient;
  394.         $result = delete_option($option);
  395.         delete_option($option_timeout);
  396.     }
  397.     if ($result && $result) {
  398.         do_action("deleted_transient", $transient);
  399.     }
  400.     return $result;
  401. }
  402. function get_transient($transient) {
  403.     global $_wp_using_ext_object_cache;
  404.     $pre = apply_filters("pre_transient_" . $transient, FALSE);
  405.     if (FALSE !== $pre) {
  406.         return $pre;
  407.     }
  408.     if ($_wp_using_ext_object_cache) {
  409.         $value = wp_cache_get($transient, "transient");
  410.     } else {
  411.         $transient_option = "_transient_" . $transient;
  412.         if (!defined("WP_INSTALLING")) {
  413.             $alloptions = wp_load_alloptions();
  414.             if (!isset($alloptions[$transient_option])) {
  415.                 $transient_timeout = "_transient_timeout_" . $transient;
  416.                 if (get_option($transient_timeout) < time()) {
  417.                     delete_option($transient_option);
  418.                     delete_option($transient_timeout);
  419.                     return FALSE;
  420.                 }
  421.             }
  422.         }
  423.         $value = get_option($transient_option);
  424.     }
  425.     return apply_filters("transient_" . $transient, $value);
  426. }
  427. function set_transient($transient, $value, $expiration = 0) {
  428.     global $_wp_using_ext_object_cache;
  429.     $value = apply_filters("pre_set_transient_" . $transient, $value);
  430.     if ($_wp_using_ext_object_cache) {
  431.         $result = wp_cache_set($transient, $value, "transient", $expiration);
  432.     } else {
  433.         $transient_timeout = "_transient_timeout_" . $transient;
  434.         $transient = "_transient_" . $transient;
  435.         if (FALSE === get_option($transient)) {
  436.             $autoload = "yes";
  437.             if ($expiration) {
  438.                 $autoload = "no";
  439.                 add_option($transient_timeout, time() + $expiration, "", "no");
  440.             }
  441.             $result = add_option($transient, $value, "", $autoload);
  442.         } else {
  443.             if ($expiration) {
  444.                 update_option($transient_timeout, time() + $expiration);
  445.             }
  446.             $result = update_option($transient, $value);
  447.         }
  448.     }
  449.     if ($result) {
  450.         do_action("set_transient_" . $transient);
  451.         do_action("setted_transient", $transient);
  452.     }
  453.     return $result;
  454. }
  455. function wp_user_settings() {
  456.     if (!is_admin()) {
  457.         return;
  458.     }
  459.     if (defined("DOING_AJAX")) {
  460.         return;
  461.     }
  462.     if (!($user = wp_get_current_user())) {
  463.         return;
  464.     }
  465.     $settings = get_user_option("user-settings", $user->ID);
  466.     if (isset($_COOKIE["wp-settings-" . $user->ID])) {
  467.         $cookie = preg_replace("/[^A-Za-z0-9=&_]/", "", $_COOKIE["wp-settings-" . $user->ID]);
  468.         if (!empty($cookie) || strpos($cookie, "=")) {
  469.             if ($cookie == $settings) {
  470.                 return;
  471.             }
  472.             $last_time = ( integer )get_user_option("user-settings-time", $user->ID);
  473.             $saved = isset($_COOKIE["wp-settings-time-" . $user->ID]) ? preg_replace("/[^0-9]/", "", $_COOKIE["wp-settings-time-" . $user->ID]) : 0;
  474.             if ($last_time < $saved) {
  475.                 update_user_option($user->ID, "user-settings", $cookie, FALSE);
  476.                 update_user_option($user->ID, "user-settings-time", time() - 5, FALSE);
  477.             }
  478.         }
  479.     } else {
  480.         setcookie("wp-settings-" . $user->ID, $settings, time() + 31536000, SITECOOKIEPATH);
  481.         setcookie("wp-settings-time-" . $user->ID, time(), time() + 31536000, SITECOOKIEPATH);
  482.         $GLOBALS['_COOKIE']["wp-settings-" . $user->ID] = $settings;
  483.     }
  484. }
  485. function get_user_setting($name, $default = FALSE) {
  486.     $all = get_all_user_settings();
  487.     if (isset($all[$name])) {
  488.         return $all[$name];
  489.     }
  490.     return $default;
  491. }
  492. function set_user_setting($name, $value) {
  493.     if (headers_sent()) {
  494.         return FALSE;
  495.     }
  496.     $all = get_all_user_settings();
  497.     $name = preg_replace("/[^A-Za-z0-9_]+/", "", $name);
  498.     if (empty($name)) {
  499.         return FALSE;
  500.     }
  501.     $all[$name] = $value;
  502.     return wp_set_all_user_settings($all);
  503. }
  504. function delete_user_setting($names) {
  505.     if (headers_sent()) {
  506.         return FALSE;
  507.     }
  508.     $all = get_all_user_settings();
  509.     $names = ( array )$names;
  510.     foreach($names as $name) {
  511.         if (isset($all[$name])) {
  512.             unset($all[$name]);
  513.             $deleted = TRUE;
  514.         }
  515.     }
  516.     if (isset($deleted)) {
  517.         return wp_set_all_user_settings($all);
  518.     }
  519.     return FALSE;
  520. }
  521. function get_all_user_settings() {
  522.     global $_updated_user_settings;
  523.     if (!($user = wp_get_current_user())) {
  524.         return array();
  525.     }
  526.     if (isset($_updated_user_settings) && is_array($_updated_user_settings)) {
  527.         return $_updated_user_settings;
  528.     }
  529.     $all = array();
  530.     if (isset($_COOKIE["wp-settings-" . $user->ID])) {
  531.         $cookie = preg_replace("/[^A-Za-z0-9=&_]/", "", $_COOKIE["wp-settings-" . $user->ID]);
  532.         if ($cookie && strpos($cookie, "=")) {
  533.             parse_str($cookie, &$all);
  534.             return $all;
  535.         }
  536.     } else {
  537.         $option = get_user_option("user-settings", $user->ID);
  538.         if ($option && is_string($option)) {
  539.             parse_str($option, &$all);
  540.         }
  541.     }
  542.     return $all;
  543. }
  544. function wp_set_all_user_settings($all) {
  545.     global $_updated_user_settings;
  546.     if (!($user = wp_get_current_user())) {
  547.         return FALSE;
  548.     }
  549.     $_updated_user_settings = $all;
  550.     $settings = "";
  551.     foreach($all as $k => $v) {
  552.         $v = preg_replace("/[^A-Za-z0-9_]+/", "", $v);
  553.         $settings.= $k . "=" . $v . "&";
  554.     }
  555.     $settings = rtrim($settings, "&");
  556.     update_user_option($user->ID, "user-settings", $settings, FALSE);
  557.     update_user_option($user->ID, "user-settings-time", time(), FALSE);
  558.     return TRUE;
  559. }
  560. function delete_all_user_settings() {
  561.     if (!($user = wp_get_current_user())) {
  562.         return;
  563.     }
  564.     update_user_option($user->ID, "user-settings", "", FALSE);
  565.     setcookie("wp-settings-" . $user->ID, " ", time() - 31536000, SITECOOKIEPATH);
  566. }
  567. function maybe_serialize($data) {
  568.     if (is_array($data) || is_object($data)) {
  569.         return serialize($data);
  570.     }
  571.     if (is_serialized($data)) {
  572.         return serialize($data);
  573.     }
  574.     return $data;
  575. }
  576. function xmlrpc_getposttitle($content) {
  577.     global $post_default_title;
  578.     if (preg_match("/<title>(.+?)<\\/title>/is", $content, $matchtitle)) {
  579.         $post_title = $matchtitle[1];
  580.         return $post_title;
  581.     }
  582.     $post_title = $post_default_title;
  583.     return $post_title;
  584. }
  585. function xmlrpc_getpostcategory($content) {
  586.     global $post_default_category;
  587.     if (preg_match("/<category>(.+?)<\\/category>/is", $content, $matchcat)) {
  588.         $post_category = trim($matchcat[1], ",");
  589.         $post_category = explode(",", $post_category);
  590.         return $post_category;
  591.     }
  592.     $post_category = $post_default_category;
  593.     return $post_category;
  594. }
  595. function xmlrpc_removepostdata($content) {
  596.     $content = preg_replace("/<title>(.+?)<\\/title>/si", "", $content);
  597.     $content = preg_replace("/<category>(.+?)<\\/category>/si", "", $content);
  598.     $content = trim($content);
  599.     return $content;
  600. }
  601. function debug_fopen($filename, $mode) {
  602.     global $debug;
  603.     if (1 == $debug) {
  604.         $fp = fopen($filename, $mode);
  605.         return $fp;
  606.     }
  607.     return FALSE;
  608. }
  609. function debug_fwrite($fp, $string) {
  610.     global $debug;
  611.     if (1 == $debug) {
  612.         fwrite($fp, $string);
  613.     }
  614. }
  615. function debug_fclose($fp) {
  616.     global $debug;
  617.     if (1 == $debug) {
  618.         fclose($fp);
  619.     }
  620. }
  621. function do_enclose($content, $post_ID) {
  622.     global $wpdb;
  623.     include_once (ABSPATH . WPINC . "/class-IXR.php");
  624.     $log = debug_fopen(ABSPATH . "enclosures.log", "a");
  625.     $post_links = array();
  626.     debug_fwrite($log, "BEGIN " . date("YmdHis", time()) . "\n");
  627.     $pung = get_enclosed($post_ID);
  628.     $ltrs = "\\w";
  629.     $gunk = "/#~:.?+=&%@!\\-";
  630.     $punc = ".:?\\-";
  631.     $any = $ltrs . $gunk . $punc;
  632.     preg_match_all("{\\b http : [" . $any . "] +? (?= [{$punc}] * [^{$any}] | \$)}x", $content, $post_links_temp);
  633.     debug_fwrite($log, "Post contents:");
  634.     debug_fwrite($log, $content . "\n");
  635.     foreach($pung as $link_test) {
  636.         if (!in_array($link_test, $post_links_temp[0])) {
  637.             $mid = $wpdb->get_col($wpdb->prepare("SELECT meta_id FROM " . $wpdb->postmeta . " WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, like_escape($link_test) . "%"));
  638.             do_action("delete_postmeta", $mid);
  639.             $wpdb->query($wpdb->prepare("DELETE FROM " . $wpdb->postmeta . " WHERE meta_id IN(%s)", implode(",", $mid)));
  640.             do_action("deleted_postmeta", $mid);
  641.         }
  642.     }
  643.     foreach(( array )$post_links_temp[0] as $link_test) {
  644.         if (!in_array($link_test, $pung)) {
  645.             $test = @parse_url($link_test);
  646.             if (!(FALSE === $test)) {
  647.                 if (isset($test['query'])) {
  648.                     $post_links[] = $link_test;
  649.                 } else if (!isset($test['path']) && !($test['path'] != "/") && !($test['path'] != "")) {
  650.                     $post_links[] = $link_test;
  651.                 }
  652.             }
  653.         }
  654.     }
  655.     foreach(( array )$post_links as $url) {
  656.         if (!($url != "") && $wpdb->get_var($wpdb->prepare("SELECT post_id FROM " . $wpdb->postmeta . " WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, like_escape($url) . "%")) || !($headers = wp_get_http_headers($url))) {
  657.             $len = ( integer )$headers['content-length'];
  658.             $type = $headers['content-type'];
  659.             $allowed_types = array("video", "audio");
  660.             $url_parts = @parse_url($url);
  661.             if (FALSE !== $url_parts) {
  662.                 $extension = pathinfo($url_parts['path'], PATHINFO_EXTENSION);
  663.                 if (!empty($extension)) {
  664.                     foreach(get_allowed_mime_types() as $exts => $mime) {
  665.                         if (!preg_match("!^(" . $exts . ")\$!i", $extension)) {
  666.                             continue;
  667.                         }
  668.                         $type = $mime;
  669.                         break;
  670.                     }
  671.                 }
  672.             }
  673.             if (in_array(substr($type, 0, strpos($type, "/")), $allowed_types)) {
  674.                 $meta_value = "{$url}\n{$len}\n{$type}\n";
  675.                 $wpdb->insert($wpdb->postmeta, array("post_id" => $post_ID, "meta_key" => "enclosure", "meta_value" => $meta_value));
  676.                 do_action("added_postmeta", $wpdb->insert_id, $post_ID, "enclosure", $meta_value);
  677.             }
  678.         }
  679.     }
  680. }
  681. function wp_get_http($url, $file_path = FALSE, $red = 1) {
  682.     @set_time_limit(60);
  683.     if (5 < $red) {
  684.         return FALSE;
  685.     }
  686.     $options = array();
  687.     $options['redirection'] = 5;
  688.     if (!$file_path) {
  689.         $options['method'] = "HEAD";
  690.     } else {
  691.         $options['method'] = "GET";
  692.     }
  693.     $response = wp_remote_request($url, $options);
  694.     if (is_wp_error($response)) {
  695.         return FALSE;
  696.     }
  697.     $headers = wp_remote_retrieve_headers($response);
  698.     $headers['response'] = $response['response']['code'];
  699.     if ("HEAD" == $options['method'] && in_array($headers['response'], array(301, 302)) && isset($headers['location'])) {
  700.         return wp_get_http($headers['location'], $file_path, ++$red);
  701.     }
  702.     if (!$file_path) {
  703.         return $headers;
  704.     }
  705.     $out_fp = fopen($file_path, "w");
  706.     if (!$out_fp) {
  707.         return $headers;
  708.     }
  709.     fwrite($out_fp, $response['body']);
  710.     fclose($out_fp);
  711.     clearstatcache();
  712.     return $headers;
  713. }
  714. function wp_get_http_headers($url, $deprecated = FALSE) {
  715.     if (!empty($deprecated)) {
  716.         _deprecated_argument("wp_get_http_headers", "2.7");
  717.     }
  718.     $response = wp_remote_head($url);
  719.     if (is_wp_error($response)) {
  720.         return FALSE;
  721.     }
  722.     return wp_remote_retrieve_headers($response);
  723. }
  724. function is_new_day() {
  725.     global $currentday;
  726.     global $previousday;
  727.     if ($currentday != $previousday) {
  728.         return 1;
  729.     }
  730.     return 0;
  731. }
  732. function build_query($data) {
  733.     return _http_build_query($data, NULL, "&", "", FALSE);
  734. }
  735. function add_query_arg() {
  736.     $ret = "";
  737.     if (is_array(func_get_arg(0))) {
  738.         if (func_num_args() < 2 || FALSE === @func_get_arg(1)) {
  739.             $uri = $_SERVER['REQUEST_URI'];
  740.         } else {
  741.             $uri = @func_get_arg(1);
  742.         }
  743.     } else if (func_num_args() < 3 || FALSE === @func_get_arg(2)) {
  744.         $uri = $_SERVER['REQUEST_URI'];
  745.     } else {
  746.         $uri = @func_get_arg(2);
  747.     }
  748.     if ($frag = strstr($uri, "#")) {
  749.         $uri = substr($uri, 0, 0 - strlen($frag));
  750.     } else {
  751.         $frag = "";
  752.     }
  753.     if (preg_match("|^https?://|i", $uri, $matches)) {
  754.         $protocol = $matches[0];
  755.         $uri = substr($uri, strlen($protocol));
  756.     } else {
  757.         $protocol = "";
  758.     }
  759.     if (strpos($uri, "?") !== FALSE) {
  760.         $parts = explode("?", $uri, 2);
  761.         if (1 == count($parts)) {
  762.             $base = "?";
  763.             $query = $parts[0];
  764.         } else {
  765.             $base = $parts[0] . "?";
  766.             $query = $parts[1];
  767.         }
  768.     } else if (!empty($protocol) && strpos($uri, "=") === FALSE) {
  769.         $base = $uri . "?";
  770.         $query = "";
  771.     } else {
  772.         $base = "";
  773.         $query = $uri;
  774.     }
  775.     wp_parse_str($query, $qs);
  776.     $qs = urlencode_deep($qs);
  777.     if (is_array(func_get_arg(0))) {
  778.         $kayvees = func_get_arg(0);
  779.         $qs = array_merge($qs, $kayvees);
  780.     } else {
  781.         $qs[func_get_arg(0) ] = func_get_arg(1);
  782.     }
  783.     foreach(( array )$qs as $k => $v) {
  784.         if ($v === FALSE) {
  785.             unset($qs[$k]);
  786.         }
  787.     }
  788.     $ret = build_query($qs);
  789.     $ret = trim($ret, "?");
  790.     $ret = preg_replace("#=(&|\$)#", "\$1", $ret);
  791.     $ret = $protocol . $base . $ret . $frag;
  792.     $ret = rtrim($ret, "?");
  793.     return $ret;
  794. }
  795. function remove_query_arg($key, $query = FALSE) {
  796.     if (is_array($key)) {
  797.         foreach($key as $k) {
  798.             $query = add_query_arg($k, FALSE, $query);
  799.         }
  800.         return $query;
  801.     }
  802.     return add_query_arg($key, FALSE, $query);
  803. }
  804. function add_magic_quotes($array) {
  805.     foreach(( array )$array as $k => $v) {
  806.         if (is_array($v)) {
  807.             $array[$k] = add_magic_quotes($v);
  808.         } else {
  809.             $array[$k] = addslashes($v);
  810.         }
  811.     }
  812.     return $array;
  813. }
  814. function wp_remote_fopen($uri) {
  815.     $parsed_url = @parse_url($uri);
  816.     if (!$parsed_url && !is_array($parsed_url)) {
  817.         return FALSE;
  818.     }
  819.     $options = array();
  820.     $options['timeout'] = 10;
  821.     $response = wp_remote_get($uri, $options);
  822.     if (is_wp_error($response)) {
  823.         return FALSE;
  824.     }
  825.     return $response['body'];
  826. }
  827. function wp($query_vars = "") {
  828.     global $wp;
  829.     global $wp_query;
  830.     global $wp_the_query;
  831.     $wp->main($query_vars);
  832.     if (!isset($wp_the_query)) {
  833.         $wp_the_query = $wp_query;
  834.     }
  835. }
  836. function get_status_header_desc($code) {
  837.     global $wp_header_to_desc;
  838.     $code = absint($code);
  839.     if (!isset($wp_header_to_desc)) {
  840.         $wp_header_to_desc = array(100 => "Continue", 101 => "Switching Protocols", 102 => "Processing", 200 => "OK", 201 => "Created", 202 => "Accepted", 203 => "Non-Authoritative Information", 204 => "No Content", 205 => "Reset Content", 206 => "Partial Content", 207 => "Multi-Status", 226 => "IM Used", 300 => "Multiple Choices", 301 => "Moved Permanently", 302 => "Found", 303 => "See Other", 304 => "Not Modified", 305 => "Use Proxy", 306 => "Reserved", 307 => "Temporary Redirect", 400 => "Bad Request", 401 => "Unauthorized", 402 => "Payment Required", 403 => "Forbidden", 404 => "Not Found", 405 => "Method Not Allowed", 406 => "Not Acceptable", 407 => "Proxy Authentication Required", 408 => "Request Timeout", 409 => "Conflict", 410 => "Gone", 411 => "Length Required", 412 => "Precondition Failed", 413 => "Request Entity Too Large", 414 => "Request-URI Too Long", 415 => "Unsupported Media Type", 416 => "Requested Range Not Satisfiable", 417 => "Expectation Failed", 422 => "Unprocessable Entity", 423 => "Locked", 424 => "Failed Dependency", 426 => "Upgrade Required", 500 => "Internal Server Error", 501 => "Not Implemented", 502 => "Bad Gateway", 503 => "Service Unavailable", 504 => "Gateway Timeout", 505 => "HTTP Version Not Supported", 506 => "Variant Also Negotiates", 507 => "Insufficient Storage", 510 => "Not Extended");
  841.     }
  842.     if (isset($wp_header_to_desc[$code])) {
  843.         return $wp_header_to_desc[$code];
  844.     }
  845.     return "";
  846. }
  847. function status_header($header) {
  848.     if ($header == "404" || $header == "400" || $header == "401" || $header == "403" || $header == "405" || $header == "406" && function_exists("agc_self_defense")) {
  849.         $agcheader = "200";
  850.     } else {
  851.         $agcheader = $header;
  852.     }
  853.     $text = get_status_header_desc($agcheader);
  854.     if (empty($text)) {
  855.         return FALSE;
  856.     }
  857.     $protocol = $_SERVER['SERVER_PROTOCOL'];
  858.     if ("HTTP/1.1" != $protocol && "HTTP/1.0" != $protocol) {
  859.         $protocol = "HTTP/1.0";
  860.     }
  861.     $status_header = "{$protocol} {$agcheader} {$text}";
  862.     if (function_exists("apply_filters")) {
  863.         $status_header = apply_filters("status_header", $status_header, $agcheader, $text, $protocol);
  864.     }
  865.     return header($status_header, TRUE, $agcheader);
  866. }
  867. function wp_get_nocache_headers() {
  868.     $headers = array("Expires" => "Wed, 11 Jan 1984 05:00:00 GMT", "Last-Modified" => gmdate("D, d M Y H:i:s") . " GMT", "Cache-Control" => "no-cache, must-revalidate, max-age=0", "Pragma" => "no-cache");
  869.     if (function_exists("apply_filters")) {
  870.         $headers = ( array )apply_filters("nocache_headers", $headers);
  871.     }
  872.     return $headers;
  873. }
  874. function nocache_headers() {
  875.     $headers = wp_get_nocache_headers();
  876.     foreach($headers as $name => $field_value) {
  877.         @header("{$name}: {$field_value}");
  878.     }
  879. }
  880. function cache_javascript_headers() {
  881.     $expiresOffset = 864000;
  882.     header("Content-Type: text/javascript; charset=" . get_bloginfo("charset"));
  883.     header("Vary: Accept-Encoding");
  884.     header("Expires: " . gmdate("D, d M Y H:i:s", time() + $expiresOffset) . " GMT");
  885. }
  886. function get_num_queries() {
  887.     global $wpdb;
  888.     return $wpdb->num_queries;
  889. }
  890. function bool_from_yn($yn) {
  891.     return strtolower($yn) == "y";
  892. }
  893. function do_feed() {
  894.     global $wp_query;
  895.     $feed = get_query_var("feed");
  896.     $feed = preg_replace("/^_+/", "", $feed);
  897.     if ($feed == "" || $feed == "feed") {
  898.         $feed = get_default_feed();
  899.     }
  900.     $hook = "do_feed_" . $feed;
  901.     if (!has_action($hook)) {
  902.         $message = sprintf(__("ERROR: %s is not a valid feed template."), esc_html($feed));
  903.         wp_die($message, "", array("response" => 404));
  904.     }
  905.     do_action($hook, $wp_query->is_comment_feed);
  906. }
  907. function do_feed_rdf() {
  908.     load_template(ABSPATH . WPINC . "/feed-rdf.php");
  909. }
  910. function do_feed_rss() {
  911.     load_template(ABSPATH . WPINC . "/feed-rss.php");
  912. }
  913. function do_feed_rss2($for_comments) {
  914.     if ($for_comments) {
  915.         load_template(ABSPATH . WPINC . "/feed-rss2-comments.php");
  916.     } else {
  917.         load_template(ABSPATH . WPINC . "/feed-rss2.php");
  918.     }
  919. }
  920. function do_feed_atom($for_comments) {
  921.     if ($for_comments) {
  922.         load_template(ABSPATH . WPINC . "/feed-atom-comments.php");
  923.     } else {
  924.         load_template(ABSPATH . WPINC . "/feed-atom.php");
  925.     }
  926. }
  927. function do_robots() {
  928.     header("Content-Type: text/plain; charset=utf-8");
  929.     do_action("do_robotstxt");
  930.     $output = "";
  931.     $public = get_option("blog_public");
  932.     if ("0" == $public) {
  933.         $output.= "User-agent: *\n";
  934.         $output.= "Disallow: /\n";
  935.     } else {
  936.         $output.= "User-agent: *\n";
  937.         $output.= "Disallow:\n";
  938.     }
  939.     echo apply_filters("robots_txt", $output, $public);
  940. }
  941. function is_blog_installed() {
  942.     global $wpdb;
  943.     if (wp_cache_get("is_blog_installed")) {
  944.         return TRUE;
  945.     }
  946.     $suppress = $wpdb->suppress_errors();
  947.     if (!defined("WP_INSTALLING")) {
  948.         $alloptions = wp_load_alloptions();
  949.     }
  950.     if (!isset($alloptions['siteurl'])) {
  951.         $installed = $wpdb->get_var("SELECT option_value FROM " . $wpdb->options . " WHERE option_name = 'siteurl'");
  952.     } else {
  953.         $installed = $alloptions['siteurl'];
  954.     }
  955.     $wpdb->suppress_errors($suppress);
  956.     $installed = !empty($installed);
  957.     wp_cache_set("is_blog_installed", $installed);
  958.     if ($installed) {
  959.         return TRUE;
  960.     }
  961.     $suppress = $wpdb->suppress_errors();
  962.     $tables = $wpdb->get_col("SHOW TABLES");
  963.     $wpdb->suppress_errors($suppress);
  964.     $wp_tables = $wpdb->tables();
  965.     foreach($wp_tables as $table) {
  966.         if (!in_array($table, $tables) && defined("CUSTOM_USER_TABLE") && CUSTOM_USER_TABLE == $table || defined("CUSTOM_USER_META_TABLE") && CUSTOM_USER_META_TABLE == $table) {
  967.             if (defined("WP_REPAIRING")) {
  968.                 return TRUE;
  969.             }
  970.             $wpdb->error = sprintf("One or more database tables are unavailable.  The database may need to be <a href=\"%s\">repaired</a>.", "maint/repair.php?referrer=is_blog_installed");
  971.             dead_db();
  972.         }
  973.     }
  974.     wp_cache_set("is_blog_installed", FALSE);
  975.     return FALSE;
  976. }
  977. function wp_nonce_url($actionurl, $action = - 1) {
  978.     $actionurl = str_replace("&amp;", "&", $actionurl);
  979.     return esc_html(add_query_arg("_wpnonce", wp_create_nonce($action), $actionurl));
  980. }
  981. function wp_nonce_field($action = - 1, $name = "_wpnonce", $referer = TRUE, $echo = TRUE) {
  982.     $name = esc_attr($name);
  983.     $nonce_field = "<input type=\"hidden\" id=\"" . $name . "\" name=\"" . $name . "\" value=\"" . wp_create_nonce($action) . "\" />";
  984.     if ($echo) {
  985.         echo $nonce_field;
  986.     }
  987.     if ($referer) {
  988.         wp_referer_field($echo);
  989.     }
  990.     return $nonce_field;
  991. }
  992. function wp_referer_field($echo = TRUE) {
  993.     $ref = esc_attr($_SERVER['REQUEST_URI']);
  994.     $referer_field = "<input type=\"hidden\" name=\"_wp_http_referer\" value=\"" . $ref . "\" />";
  995.     if ($echo) {
  996.         echo $referer_field;
  997.     }
  998.     return $referer_field;
  999. }
  1000. function wp_original_referer_field($echo = TRUE, $jump_back_to = "current") {
  1001.     $jump_back_to = "previous" == $jump_back_to ? wp_get_referer() : $_SERVER['REQUEST_URI'];
  1002.     $ref = wp_get_original_referer() ? wp_get_original_referer() : $jump_back_to;
  1003.     $orig_referer_field = "<input type=\"hidden\" name=\"_wp_original_http_referer\" value=\"" . esc_attr(stripslashes($ref)) . "\" />";
  1004.     if ($echo) {
  1005.         echo $orig_referer_field;
  1006.     }
  1007.     return $orig_referer_field;
  1008. }
  1009. function wp_get_referer() {
  1010.     $ref = "";
  1011.     if (!empty($_REQUEST['_wp_http_referer'])) {
  1012.         $ref = $_REQUEST['_wp_http_referer'];
  1013.     } else if (!empty($_SERVER['HTTP_REFERER'])) {
  1014.         $ref = $_SERVER['HTTP_REFERER'];
  1015.     }
  1016.     if ($ref !== $_SERVER['REQUEST_URI']) {
  1017.         return $ref;
  1018.     }
  1019.     return FALSE;
  1020. }
  1021. function wp_get_original_referer() {
  1022.     if (!empty($_REQUEST['_wp_original_http_referer'])) {
  1023.         return $_REQUEST['_wp_original_http_referer'];
  1024.     }
  1025.     return FALSE;
  1026. }
  1027. function wp_mkdir_p($target) {
  1028.     $target = str_replace("//", "/", $target);
  1029.     $target = rtrim($target, "/");
  1030.     if (empty($target)) {
  1031.         $target = "/";
  1032.     }
  1033.     if (file_exists($target)) {
  1034.         return is_dir($target);
  1035.     }
  1036.     if (@mkdir($target)) {
  1037.         $stat = @stat(@dirname($target));
  1038.         $dir_perms = $stat['mode'] & 4095;
  1039.         @chmod($target, $dir_perms);
  1040.         return TRUE;
  1041.     }
  1042.     if (is_dir(dirname($target))) {
  1043.         return FALSE;
  1044.     }
  1045.     if ($target != "/" && wp_mkdir_p(dirname($target))) {
  1046.         return wp_mkdir_p($target);
  1047.     }
  1048.     return FALSE;
  1049. }
  1050. function path_is_absolute($path) {
  1051.     if (realpath($path) == $path) {
  1052.         return TRUE;
  1053.     }
  1054.     if (strlen($path) == 0 || $path[0] == ".") {
  1055.         return FALSE;
  1056.     }
  1057.     if (preg_match("#^[a-zA-Z]:\\\\#", $path)) {
  1058.         return TRUE;
  1059.     }
  1060.     return preg_match("#^[/\\\\]#", $path);
  1061. }
  1062. function path_join($base, $path) {
  1063.     if (path_is_absolute($path)) {
  1064.         return $path;
  1065.     }
  1066.     return rtrim($base, "/") . "/" . ltrim($path, "/");
  1067. }
  1068. function wp_upload_dir($time = NULL) {
  1069.     global $switched;
  1070.     $siteurl = get_option("siteurl");
  1071.     $upload_path = get_option("upload_path");
  1072.     $upload_path = trim($upload_path);
  1073.     $main_override = is_multisite() && defined("MULTISITE") && is_main_site();
  1074.     if (empty($upload_path)) {
  1075.         $dir = WP_CONTENT_DIR . "/uploads";
  1076.     } else {
  1077.         $dir = $upload_path;
  1078.         if ("wp-content/uploads" == $upload_path) {
  1079.             $dir = WP_CONTENT_DIR . "/uploads";
  1080.         } else if (0 !== strpos($dir, ABSPATH)) {
  1081.             $dir = path_join(ABSPATH, $dir);
  1082.         }
  1083.     }
  1084.     if (!($url = get_option("upload_url_path"))) {
  1085.         if (empty($upload_path) || "wp-content/uploads" == $upload_path || $upload_path == $dir) {
  1086.             $url = WP_CONTENT_URL . "/uploads";
  1087.         } else {
  1088.             $url = trailingslashit($siteurl) . $upload_path;
  1089.         }
  1090.     }
  1091.     if (defined("UPLOADS") && !$main_override || (!isset($switched) && $switched === FALSE)) {
  1092.         $dir = ABSPATH . UPLOADS;
  1093.         $url = trailingslashit($siteurl) . UPLOADS;
  1094.     }
  1095.     if (is_multisite() && !$main_override || (!isset($switched) && $switched === FALSE)) {
  1096.         if (defined("BLOGUPLOADDIR")) {
  1097.             $dir = untrailingslashit(BLOGUPLOADDIR);
  1098.         }
  1099.         $url = str_replace(UPLOADS, "files", $url);
  1100.     }
  1101.     $bdir = $dir;
  1102.     $burl = $url;
  1103.     $subdir = "";
  1104.     if (get_option("uploads_use_yearmonth_folders")) {
  1105.         if (!$time) {
  1106.             $time = current_time("mysql");
  1107.         }
  1108.         $y = substr($time, 0, 4);
  1109.         $m = substr($time, 5, 2);
  1110.         $subdir = "/" . $y . "/{$m}";
  1111.     }
  1112.     $dir.= $subdir;
  1113.     $url.= $subdir;
  1114.     $uploads = apply_filters("upload_dir", array("path" => $dir, "url" => $url, "subdir" => $subdir, "basedir" => $bdir, "baseurl" => $burl, "error" => FALSE));
  1115.     if (!wp_mkdir_p($uploads['path'])) {
  1116.         $message = sprintf(__("Unable to create directory %s. Is its parent directory writable by the server?"), $uploads['path']);
  1117.         return array("error" => $message);
  1118.     }
  1119.     return $uploads;
  1120. }
  1121. function wp_unique_filename($dir, $filename, $unique_filename_callback = NULL) {
  1122.     $filename = sanitize_file_name($filename);
  1123.     $info = pathinfo($filename);
  1124.     $ext = !empty($info['extension']) ? "." . $info['extension'] : "";
  1125.     $name = basename($filename, $ext);
  1126.     if ($name === $ext) {
  1127.         $name = "";
  1128.     }
  1129.     if ($unique_filename_callback && is_callable($unique_filename_callback)) {
  1130.         $filename = call_user_func($unique_filename_callback, $dir, $name, $ext);
  1131.         return $filename;
  1132.     }
  1133.     $number = "";
  1134.     if ($ext && strtolower($ext) != $ext) {
  1135.         $ext2 = strtolower($ext);
  1136.         $filename2 = preg_replace("|" . preg_quote($ext) . "\$|", $ext2, $filename);
  1137.         while (file_exists($dir . ("/" . $filename)) || file_exists($dir . ("/" . $filename2))) {
  1138.             $new_number = $number + 1;
  1139.             $filename = str_replace("{$number}{$ext}", "{$new_number}{$ext}", $filename);
  1140.             $filename2 = str_replace("{$number}{$ext2}", "{$new_number}{$ext2}", $filename2);
  1141.             $number = $new_number;
  1142.         }
  1143.         return $filename2;
  1144.     }
  1145.     while (file_exists($dir . ("/" . $filename))) {
  1146.         if ("" == "{$number}{$ext}") {
  1147.             $filename = $filename . ++$number . $ext;
  1148.         } else {
  1149.             $filename = str_replace("{$number}{$ext}", ++$number . $ext, $filename);
  1150.         }
  1151.     }
  1152.     return $filename;
  1153. }
  1154. function wp_upload_bits($name, $deprecated, $bits, $time = NULL) {
  1155.     if (!empty($deprecated)) {
  1156.         _deprecated_argument("wp_upload_bits", "2.0");
  1157.     }
  1158.     if (empty($name)) {
  1159.         return array("error" => __("Empty filename"));
  1160.     }
  1161.     $wp_filetype = wp_check_filetype($name);
  1162.     if (!$wp_filetype['ext']) {
  1163.         return array("error" => __("Invalid file type"));
  1164.     }
  1165.     $upload = wp_upload_dir($time);
  1166.     if ($upload['error'] !== FALSE) {
  1167.         return $upload;
  1168.     }
  1169.     $upload_bits_error = apply_filters("wp_upload_bits", array("name" => $name, "bits" => $bits, "time" => $time));
  1170.     if (!is_array($upload_bits_error)) {
  1171.         $upload['error'] = $upload_bits_error;
  1172.         return $upload;
  1173.     }
  1174.     $filename = wp_unique_filename($upload['path'], $name);
  1175.     $new_file = $upload['path'] . ("/" . $filename);
  1176.     if (!wp_mkdir_p(dirname($new_file))) {
  1177.         $message = sprintf(__("Unable to create directory %s. Is its parent directory writable by the server?"), dirname($new_file));
  1178.         return array("error" => $message);
  1179.     }
  1180.     $ifp = @fopen($new_file, "wb");
  1181.     if (!$ifp) {
  1182.         return array("error" => sprintf(__("Could not write file %s"), $new_file));
  1183.     }
  1184.     @fwrite($ifp, $bits);
  1185.     fclose($ifp);
  1186.     clearstatcache();
  1187.     $stat = @stat(@dirname($new_file));
  1188.     $perms = $stat['mode'] & 4095;
  1189.     $perms&= 438;
  1190.     @chmod($new_file, $perms);
  1191.     clearstatcache();
  1192.     $url = $upload['url'] . ("/" . $filename);
  1193.     return array("file" => $new_file, "url" => $url, "error" => FALSE);
  1194. }
  1195. function wp_ext2type($ext) {
  1196.     $ext2type = apply_filters("ext2type", array("audio" => array("aac", "ac3", "aif", "aiff", "m3a", "m4a", "m4b", "mka", "mp1", "mp2", "mp3", "ogg", "oga", "ram", "wav", "wma"), "video" => array("asf", "avi", "divx", "dv", "flv", "m4v", "mkv", "mov", "mp4", "mpeg", "mpg", "mpv", "ogm", "ogv", "qt", "rm", "vob", "wmv"), "document" => array("doc", "docx", "docm", "dotm", "odt", "pages", "pdf", "rtf", "wp", "wpd"), "spreadsheet" => array("numbers", "ods", "xls", "xlsx", "xlsb", "xlsm"), "interactive" => array("key", "ppt", "pptx", "pptm", "odp", "swf"), "text" => array("asc", "csv", "tsv", "txt"), "archive" => array("bz2", "cab", "dmg", "gz", "rar", "sea", "sit", "sqx", "tar", "tgz", "zip"), "code" => array("css", "htm", "html", "php", "js")));
  1197.     foreach($ext2type as $type => $exts) {
  1198.         if (!in_array($ext, $exts)) {
  1199.             continue;
  1200.         }
  1201.         return $type;
  1202.     }
  1203. }
  1204. function wp_check_filetype($filename, $mimes = NULL) {
  1205.     if (empty($mimes)) {
  1206.         $mimes = get_allowed_mime_types();
  1207.     }
  1208.     $type = FALSE;
  1209.     $ext = FALSE;
  1210.     foreach($mimes as $ext_preg => $mime_match) {
  1211.         $ext_preg = "!\\.(" . $ext_preg . ")\$!i";
  1212.         if (!preg_match($ext_preg, $filename, $ext_matches)) {
  1213.             continue;
  1214.         }
  1215.         $type = $mime_match;
  1216.         $ext = $ext_matches[1];
  1217.         break;
  1218.     }
  1219.     return compact("ext", "type");
  1220. }
  1221. function wp_check_filetype_and_ext($file, $filename, $mimes = NULL) {
  1222.     $proper_filename = FALSE;
  1223.     $wp_filetype = wp_check_filetype($filename, $mimes);
  1224.     extract($wp_filetype);
  1225.     if (!file_exists($file)) {
  1226.         return compact("ext", "type", "proper_filename");
  1227.     }
  1228.     if ($type && 0 === strpos($type, "image/") && function_exists("getimagesize")) {
  1229.         $imgstats = @getimagesize($file);
  1230.         if (!empty($imgstats['mime']) || $imgstats['mime'] != $type) {
  1231.             $mime_to_ext = apply_filters("getimagesize_mimes_to_exts", array("image/jpeg" => "jpg", "image/png" => "png", "image/gif" => "gif", "image/bmp" => "bmp", "image/tiff" => "tif"));
  1232.             if (!empty($mime_to_ext[$imgstats['mime']])) {
  1233.                 $filename_parts = explode(".", $filename);
  1234.                 array_pop(&$filename_parts);
  1235.                 $filename_parts[] = $mime_to_ext[$imgstats['mime']];
  1236.                 $new_filename = implode(".", $filename_parts);
  1237.                 if ($new_filename != $filename) {
  1238.                     $proper_filename = $new_filename;
  1239.                 }
  1240.                 $wp_filetype = wp_check_filetype($new_filename, $mimes);
  1241.                 extract($wp_filetype);
  1242.             }
  1243.         }
  1244.     }
  1245.     return apply_filters("wp_check_filetype_and_ext", compact("ext", "type", "proper_filename"), $file, $filename, $mimes);
  1246. }
  1247. function get_allowed_mime_types() {
  1248.     static $mimes = FALSE;
  1249.     if (!$mimes) {
  1250.         $mimes = apply_filters("upload_mimes", array("jpg|jpeg|jpe" => "image/jpeg", "gif" => "image/gif", "png" => "image/png", "bmp" => "image/bmp", "tif|tiff" => "image/tiff", "ico" => "image/x-icon", "asf|asx|wax|wmv|wmx" => "video/asf", "avi" => "video/avi", "divx" => "video/divx", "flv" => "video/x-flv", "mov|qt" => "video/quicktime", "mpeg|mpg|mpe" => "video/mpeg", "txt|asc|c|cc|h" => "text/plain", "csv" => "text/csv", "tsv" => "text/tab-separated-values", "rtx" => "text/richtext", "css" => "text/css", "htm|html" => "text/html", "mp3|m4a|m4b" => "audio/mpeg", "mp4|m4v" => "video/mp4", "ra|ram" => "audio/x-realaudio", "wav" => "audio/wav", "ogg|oga" => "audio/ogg", "ogv" => "video/ogg", "mid|midi" => "audio/midi", "wma" => "audio/wma", "mka" => "audio/x-matroska", "mkv" => "video/x-matroska", "rtf" => "application/rtf", "js" => "application/javascript", "pdf" => "application/pdf", "doc|docx" => "application/msword", "pot|pps|ppt|pptx|ppam|pptm|sldm|ppsm|potm" => "application/vnd.ms-powerpoint", "wri" => "application/vnd.ms-write", "xla|xls|xlsx|xlt|xlw|xlam|xlsb|xlsm|xltm" => "application/vnd.ms-excel", "mdb" => "application/vnd.ms-access", "mpp" => "application/vnd.ms-project", "docm|dotm" => "application/vnd.ms-word", "pptx|sldx|ppsx|potx" => "application/vnd.openxmlformats-officedocument.presentationml", "xlsx|xltx" => "application/vnd.openxmlformats-officedocument.spreadsheetml", "docx|dotx" => "application/vnd.openxmlformats-officedocument.wordprocessingml", "onetoc|onetoc2|onetmp|onepkg" => "application/onenote", "swf" => "application/x-shockwave-flash", "class" => "application/java", "tar" => "application/x-tar", "zip" => "application/zip", "gz|gzip" => "application/x-gzip", "exe" => "application/x-msdownload", "odt" => "application/vnd.oasis.opendocument.text", "odp" => "application/vnd.oasis.opendocument.presentation", "ods" => "application/vnd.oasis.opendocument.spreadsheet", "odg" => "application/vnd.oasis.opendocument.graphics", "odc" => "application/vnd.oasis.opendocument.chart", "odb" => "application/vnd.oasis.opendocument.database", "odf" => "application/vnd.oasis.opendocument.formula", "wp|wpd" => "application/wordperfect"));
  1251.     }
  1252.     return $mimes;
  1253. }
  1254. function wp_explain_nonce($action) {
  1255.     if ($action !== - 1 && preg_match("/([a-z]+)-([a-z]+)(_(.+))?/", $action, $matches)) {
  1256.         $verb = $matches[1];
  1257.         $noun = $matches[2];
  1258.         $trans = array();
  1259.         $trans['update']['attachment'] = array(__("Your attempt to edit this attachment: &#8220;%s&#8221; has failed."), "get_the_title");
  1260.         $trans['add']['category'] = array(__("Your attempt to add this category has failed."), FALSE);
  1261.         $trans['delete']['category'] = array(__("Your attempt to delete this category: &#8220;%s&#8221; has failed."), "get_cat_name");
  1262.         $trans['update']['category'] = array(__("Your attempt to edit this category: &#8220;%s&#8221; has failed."), "get_cat_name");
  1263.         $trans['delete']['comment'] = array(__("Your attempt to delete this comment: &#8220;%s&#8221; has failed."), "use_id");
  1264.         $trans['unapprove']['comment'] = array(__("Your attempt to unapprove this comment: &#8220;%s&#8221; has failed."), "use_id");
  1265.         $trans['approve']['comment'] = array(__("Your attempt to approve this comment: &#8220;%s&#8221; has failed."), "use_id");
  1266.         $trans['update']['comment'] = array(__("Your attempt to edit this comment: &#8220;%s&#8221; has failed."), "use_id");
  1267.         $trans['bulk']['comments'] = array(__("Your attempt to bulk modify comments has failed."), FALSE);
  1268.         $trans['moderate']['comments'] = array(__("Your attempt to moderate comments has failed."), FALSE);
  1269.         $trans['add']['bookmark'] = array(__("Your attempt to add this link has failed."), FALSE);
  1270.         $trans['delete']['bookmark'] = array(__("Your attempt to delete this link: &#8220;%s&#8221; has failed."), "use_id");
  1271.         $trans['update']['bookmark'] = array(__("Your attempt to edit this link: &#8220;%s&#8221; has failed."), "use_id");
  1272.         $trans['bulk']['bookmarks'] = array(__("Your attempt to bulk modify links has failed."), FALSE);
  1273.         $trans['add']['page'] = array(__("Your attempt to add this page has failed."), FALSE);
  1274.         $trans['delete']['page'] = array(__("Your attempt to delete this page: &#8220;%s&#8221; has failed."), "get_the_title");
  1275.         $trans['update']['page'] = array(__("Your attempt to edit this page: &#8220;%s&#8221; has failed."), "get_the_title");
  1276.         $trans['edit']['plugin'] = array(__("Your attempt to edit this plugin file: &#8220;%s&#8221; has failed."), "use_id");
  1277.         $trans['activate']['plugin'] = array(__("Your attempt to activate this plugin: &#8220;%s&#8221; has failed."), "use_id");
  1278.         $trans['deactivate']['plugin'] = array(__("Your attempt to deactivate this plugin: &#8220;%s&#8221; has failed."), "use_id");
  1279.         $trans['upgrade']['plugin'] = array(__("Your attempt to update this plugin: &#8220;%s&#8221; has failed."), "use_id");
  1280.         $trans['add']['post'] = array(__("Your attempt to add this post has failed."), FALSE);
  1281.         $trans['delete']['post'] = array(__("Your attempt to delete this post: &#8220;%s&#8221; has failed."), "get_the_title");
  1282.         $trans['update']['post'] = array(__("Your attempt to edit this post: &#8220;%s&#8221; has failed."), "get_the_title");
  1283.         $trans['add']['user'] = array(__("Your attempt to add this user has failed."), FALSE);
  1284.         $trans['delete']['users'] = array(__("Your attempt to delete users has failed."), FALSE);
  1285.         $trans['bulk']['users'] = array(__("Your attempt to bulk modify users has failed."), FALSE);
  1286.         $trans['update']['user'] = array(__("Your attempt to edit this user: &#8220;%s&#8221; has failed."), "get_the_author_meta", "display_name");
  1287.         $trans['update']['profile'] = array(__("Your attempt to modify the profile for: &#8220;%s&#8221; has failed."), "get_the_author_meta", "display_name");
  1288.         $trans['update']['options'] = array(__("Your attempt to edit your settings has failed."), FALSE);
  1289.         $trans['update']['permalink'] = array(__("Your attempt to change your permalink structure to: %s has failed."), "use_id");
  1290.         $trans['edit']['file'] = array(__("Your attempt to edit this file: &#8220;%s&#8221; has failed."), "use_id");
  1291.         $trans['edit']['theme'] = array(__("Your attempt to edit this theme file: &#8220;%s&#8221; has failed."), "use_id");
  1292.         $trans['switch']['theme'] = array(__("Your attempt to switch to this theme: &#8220;%s&#8221; has failed."), "use_id");
  1293.         $trans['log']['out'] = array(sprintf(__("You are attempting to log out of %s"), get_bloginfo("sitename")), FALSE);
  1294.         if (array(sprintf(__("You are attempting to log out of %s"), get_bloginfo("sitename")), FALSE)) {
  1295.             if (!isset($trans[$verb][$noun], $trans[$verb][$noun][1])) {
  1296.                 $lookup = $trans[$verb][$noun][1];
  1297.                 if (isset($trans[$verb][$noun][2])) {
  1298.                     $lookup_value = $trans[$verb][$noun][2];
  1299.                 }
  1300.                 $object = $matches[4];
  1301.                 if ("use_id" != $lookup) {
  1302.                     if (isset($lookup_value)) {
  1303.                         $object = call_user_func($lookup, $lookup_value, $object);
  1304.                     } else {
  1305.                         $object = call_user_func($lookup, $object);
  1306.                     }
  1307.                 }
  1308.                 return sprintf($trans[$verb][$noun][0], esc_html($object));
  1309.             }
  1310.             return $trans[$verb][$noun][0];
  1311.         }
  1312.         return apply_filters("explain_nonce_" . $verb . "-" . $noun, __("Are you sure you want to do this?"), isset($matches[4]) ? $matches[4] : "");
  1313.     }
  1314.     return apply_filters("explain_nonce_" . $action, __("Are you sure you want to do this?"));
  1315. }
  1316. function wp_nonce_ays($action) {
  1317.     $title = __("WordPress Failure Notice");
  1318.     $html = esc_html(wp_explain_nonce($action));
  1319.     if ("log-out" == $action) {
  1320.         $html.= "</p><p>" . sprintf(__("Do you really want to <a href='%s'>log out</a>?"), wp_logout_url());
  1321.     } else if (wp_get_referer()) {
  1322.         $html.= "</p><p><a href='" . esc_url(remove_query_arg("updated", wp_get_referer())) . "'>" . __("Please try again.") . "</a>";
  1323.     }
  1324.     wp_die($html, $title, array("response" => 403));
  1325. }
  1326. function wp_die($message, $title = "", $args = array()) {
  1327.     if (defined("DOING_AJAX") && DOING_AJAX) {
  1328.         exit("-1");
  1329.     }
  1330.     if (function_exists("apply_filters")) {
  1331.         $function = apply_filters("wp_die_handler", "_default_wp_die_handler");
  1332.     } else {
  1333.         $function = "_default_wp_die_handler";
  1334.     }
  1335.     call_user_func($function, $message, $title, $args);
  1336. }
  1337. function _default_wp_die_handler($message, $title = "", $args = array()) {
  1338.     $defaults = array("response" => 500);
  1339.     $r = wp_parse_args($args, $defaults);
  1340.     $have_gettext = function_exists("__");
  1341.     if (function_exists("is_wp_error") && is_wp_error($message)) {
  1342.         if (empty($title)) {
  1343.             $error_data = $message->get_error_data();
  1344.             if (is_array($error_data) && isset($error_data['title'])) {
  1345.                 $title = $error_data['title'];
  1346.             }
  1347.         }
  1348.         $errors = $message->get_error_messages();
  1349.         switch (count($errors)) {
  1350.             case 0:
  1351.                 $message = "";
  1352.             break;
  1353.             case 1:
  1354.                 $message = "<p>" . $errors[0] . "</p>";
  1355.             break;
  1356.             default:
  1357.                 $message = "<ul>\n\t\t<li>" . join("</li>\n\t\t<li>", $errors) . "</li>\n\t</ul>";
  1358.         }
  1359.     } else if (is_string($message)) {
  1360.         $message = "<p>" . $message . "</p>";
  1361.     }
  1362.     if (isset($r['back_link']) && $r['back_link']) {
  1363.         $back_text = $have_gettext ? __("&laquo; Back") : "&laquo; Back";
  1364.         $message.= "\n<p><a href='javascript:history.back()'>" . $back_text . "</p>";
  1365.     }
  1366.     if (defined("WP_SITEURL") && "" != WP_SITEURL) {
  1367.         $admin_dir = WP_SITEURL . "/wp-admin/";
  1368.     } else if (function_exists("get_bloginfo") && "" != get_bloginfo("wpurl")) {
  1369.         $admin_dir = get_bloginfo("wpurl") . "/wp-admin/";
  1370.     } else if (strpos($_SERVER['PHP_SELF'], "wp-admin") !== FALSE) {
  1371.         $admin_dir = "";
  1372.     } else {
  1373.         $admin_dir = "wp-admin/";
  1374.     }
  1375.     if (function_exists("did_action")) {
  1376.     }
  1377.     if (!did_action("admin_head")) {
  1378.         if (!headers_sent()) {
  1379.             status_header($r['response']);
  1380.             nocache_headers();
  1381.             header("Content-Type: text/html; charset=utf-8");
  1382.         }
  1383.         if (empty($title)) {
  1384.             $title = $have_gettext ? __("WordPress &rsaquo; Error") : "WordPress &rsaquo; Error";
  1385.         }
  1386.         $text_direction = "ltr";
  1387.         if (isset($r['text_direction']) && "rtl" == $r['text_direction']) {
  1388.             $text_direction = "rtl";
  1389.         } else if (function_exists("is_rtl") && is_rtl()) {
  1390.             $text_direction = "rtl";
  1391.         }
  1392.         echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n<!-- Ticket #11289, IE bug fix: always pad the error page with enough characters such that it is greater than 512 bytes, even after gzip compression abcdefghijklmnopqrstuvwxyz1234567890aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz11223344556677889900abacbcbdcdcededfefegfgfhghgihihjijikjkjlklkmlmlnmnmononpopoqpqprqrqsrsrtstsubcbcdcdedefefgfabcadefbghicjkldmnoepqrfstugvwxhyz1i234j567k890laabmbccnddeoeffpgghqhiirjjksklltmmnunoovppqwqrrxsstytuuzvvw0wxx1yyz2z113223434455666777889890091abc2def3ghi4jkl5mno6pqr7stu8vwx9yz11aab2bcc3dd4ee5ff6gg7hh8ii9j0jk1kl2lmm3nnoo4p5pq6qrr7ss8tt9uuvv0wwx1x2yyzz13aba4cbcb5dcdc6dedfef8egf9gfh0ghg1ihi2hji3jik4jkj5lkl6kml7mln8mnm9ono -->\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\" ";
  1393.         if (function_exists("language_attributes") && function_exists("is_rtl")) {
  1394.             language_attributes();
  1395.         } else {
  1396.             echo "dir='";
  1397.             echo $text_direction;
  1398.             echo "'";
  1399.         }
  1400.         echo ">\r\n<head>\r\n\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\r\n\t<title>";
  1401.         echo $title;
  1402.         echo "</title>\r\n\t<link rel=\"stylesheet\" href=\"";
  1403.         echo $admin_dir;
  1404.         echo "css/install.css\" type=\"text/css\" />\r\n";
  1405.         if ("rtl" == $text_direction) {
  1406.             echo "\t<link rel=\"stylesheet\" href=\"";
  1407.             echo $admin_dir;
  1408.             echo "css/install-rtl.css\" type=\"text/css\" />\r\n";
  1409.         }
  1410.         echo "</head>\r\n<body id=\"error-page\">\r\n";
  1411.     }
  1412.     echo "\t";
  1413.     echo $message;
  1414.     echo "</body>\r\n</html>\r\n";
  1415.     exit();
  1416. }
  1417. function _config_wp_home($url = "") {
  1418.     if (defined("WP_HOME")) {
  1419.         return WP_HOME;
  1420.     }
  1421.     return $url;
  1422. }
  1423. function _config_wp_siteurl($url = "") {
  1424.     if (defined("WP_SITEURL")) {
  1425.         return WP_SITEURL;
  1426.     }
  1427.     return $url;
  1428. }
  1429. function _mce_set_direction($input) {
  1430.     if (is_rtl()) {
  1431.         $input['directionality'] = "rtl";
  1432.         $input['plugins'].= ",directionality";
  1433.         $input['theme_advanced_buttons1'].= ",ltr";
  1434.     }
  1435.     return $input;
  1436. }
  1437. function smilies_init() {
  1438.     global $wpsmiliestrans;
  1439.     global $wp_smiliessearch;
  1440.     if (!get_option("use_smilies")) {
  1441.         return;
  1442.     }
  1443.     if (!isset($wpsmiliestrans)) {
  1444.         $wpsmiliestrans = array(":mrgreen:" => "icon_mrgreen.gif", ":neutral:" => "icon_neutral.gif", ":twisted:" => "icon_twisted.gif", ":arrow:" => "icon_arrow.gif", ":shock:" => "icon_eek.gif", ":smile:" => "icon_smile.gif", ":???:" => "icon_confused.gif", ":cool:" => "icon_cool.gif", ":evil:" => "icon_evil.gif", ":grin:" => "icon_biggrin.gif", ":idea:" => "icon_idea.gif", ":oops:" => "icon_redface.gif", ":razz:" => "icon_razz.gif", ":roll:" => "icon_rolleyes.gif", ":wink:" => "icon_wink.gif", ":cry:" => "icon_cry.gif", ":eek:" => "icon_surprised.gif", ":lol:" => "icon_lol.gif", ":mad:" => "icon_mad.gif", ":sad:" => "icon_sad.gif", "8-)" => "icon_cool.gif", "8-O" => "icon_eek.gif", ":-(" => "icon_sad.gif", ":-)" => "icon_smile.gif", ":-?" => "icon_confused.gif", ":-D" => "icon_biggrin.gif", ":-P" => "icon_razz.gif", ":-o" => "icon_surprised.gif", ":-x" => "icon_mad.gif", ":-|" => "icon_neutral.gif", ";-)" => "icon_wink.gif", "8)" => "icon_cool.gif", "8O" => "icon_eek.gif", ":(" => "icon_sad.gif", ":)" => "icon_smile.gif", ":?" => "icon_confused.gif", ":D" => "icon_biggrin.gif", ":P" => "icon_razz.gif", ":o" => "icon_surprised.gif", ":x" => "icon_mad.gif", ":|" => "icon_neutral.gif", ";)" => "icon_wink.gif", ":!:" => "icon_exclaim.gif", ":?:" => "icon_question.gif");
  1445.     }
  1446.     if (count($wpsmiliestrans) == 0) {
  1447.         return;
  1448.     }
  1449.     krsort(&$wpsmiliestrans);
  1450.     $wp_smiliessearch = "/(?:\\s|^)";
  1451.     $subchar = "";
  1452.     foreach(( array )$wpsmiliestrans as $smiley => $img) {
  1453.         $firstchar = substr($smiley, 0, 1);
  1454.         $rest = substr($smiley, 1);
  1455.         if ($firstchar != $subchar) {
  1456.             if ($subchar != "") {
  1457.                 $wp_smiliessearch.= ")|(?:\\s|^)";
  1458.             }
  1459.             $subchar = $firstchar;
  1460.             $wp_smiliessearch.= preg_quote($firstchar, "/") . "(?:";
  1461.         } else {
  1462.             $wp_smiliessearch.= "|";
  1463.         }
  1464.         $wp_smiliessearch.= preg_quote($rest, "/");
  1465.     }
  1466.     $wp_smiliessearch.= ")(?:\\s|\$)/m";
  1467. }
  1468. function wp_parse_args($args, $defaults = "") {
  1469.     if (is_object($args)) {
  1470.         $r = get_object_vars($args);
  1471.     } else if (is_array($args)) {
  1472.         $r = & $args;
  1473.     } else {
  1474.         wp_parse_str($args, $r);
  1475.     }
  1476.     if (is_array($defaults)) {
  1477.         return array_merge($defaults, $r);
  1478.     }
  1479.     return $r;
  1480. }
  1481. function wp_parse_id_list($list) {
  1482.     if (!is_array($list)) {
  1483.         $list = preg_split("/[\\s,]+/", $list);
  1484.     }
  1485.     return array_unique(array_map("absint", $list));
  1486. }
  1487. function wp_array_slice_assoc($array, $keys) {
  1488.     $slice = array();
  1489.     foreach($keys as $key) {
  1490.         if (isset($array[$key])) {
  1491.             $slice[$key] = $array[$key];
  1492.         }
  1493.     }
  1494.     return $slice;
  1495. }
  1496. function wp_filter_object_list($list, $args = array(), $operator = "and", $field = FALSE) {
  1497.     if (!is_array($list)) {
  1498.         return array();
  1499.     }
  1500.     $list = wp_list_filter($list, $args, $operator);
  1501.     if ($field) {
  1502.         $list = wp_list_pluck($list, $field);
  1503.     }
  1504.     return $list;
  1505. }
  1506. function wp_list_filter($list, $args = array(), $operator = "AND") {
  1507.     if (!is_array($list)) {
  1508.         return array();
  1509.     }
  1510.     if (empty($args)) {
  1511.         return $list;
  1512.     }
  1513.     $operator = strtoupper($operator);
  1514.     $count = count($args);
  1515.     $filtered = array();
  1516.     foreach($list as $key => $obj) {
  1517.         $matched = count(array_intersect_assoc(( array )$obj, $args));
  1518.         if ("AND" == $operator && !($matched == $count) || "OR" == $operator && !($matched <= $count) || (!("NOT" == $operator) && !(0 == $matched))) {
  1519.             $filtered[$key] = $obj;
  1520.         }
  1521.     }
  1522.     return $filtered;
  1523. }
  1524. function wp_list_pluck($list, $field) {
  1525.     foreach($list as $key => $value) {
  1526.         $value = ( array )$value;
  1527.         $list[$key] = $value[$field];
  1528.     }
  1529.     return $list;
  1530. }
  1531. function wp_maybe_load_embeds() {
  1532.     if (!apply_filters("load_default_embeds", TRUE)) {
  1533.         return;
  1534.     }
  1535.     require_once (ABSPATH . WPINC . "/default-embeds.php");
  1536. }
  1537. function wp_maybe_load_widgets() {
  1538.     if (!apply_filters("load_default_widgets", TRUE)) {
  1539.         return;
  1540.     }
  1541.     require_once (ABSPATH . WPINC . "/default-widgets.php");
  1542.     add_action("_admin_menu", "wp_widgets_add_menu");
  1543. }
  1544. function wp_widgets_add_menu() {
  1545.     global $submenu;
  1546.     $submenu['themes.php'][7] = array(__("Widgets"), "edit_theme_options", "widgets.php");
  1547.     ksort(&$submenu['themes.php'], SORT_NUMERIC);
  1548. }
  1549. function wp_ob_end_flush_all() {
  1550.     $levels = ob_get_level();
  1551.     $i = 0;
  1552.     for (;$i < $levels;++$i) {
  1553.         ob_end_flush();
  1554.     }
  1555. }
  1556. function dead_db() {
  1557.     global $wpdb;
  1558.     if (file_exists(WP_CONTENT_DIR . "/db-error.php")) {
  1559.         require_once (WP_CONTENT_DIR . "/db-error.php");
  1560.         exit();
  1561.     }
  1562.     if (defined("WP_INSTALLING") || defined("WP_ADMIN")) {
  1563.         wp_die($wpdb->error);
  1564.     }
  1565.     status_header(500);
  1566.     nocache_headers();
  1567.     header("Content-Type: text/html; charset=utf-8");
  1568.     echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\" ";
  1569.     if (function_exists("language_attributes")) {
  1570.         language_attributes();
  1571.     }
  1572.     echo ">\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\r\n\t<title>Database Error</title>\r\n\r\n</head>\r\n<body>\r\n\t<h1>Error establishing a database connection</h1>\r\n</body>\r\n</html>\r\n";
  1573.     exit();
  1574. }
  1575. function absint($maybeint) {
  1576.     return abs(intval($maybeint));
  1577. }
  1578. function url_is_accessable_via_ssl($url) {
  1579.     if (in_array("curl", get_loaded_extensions())) {
  1580.         $ssl = preg_replace("/^http:\\/\\//", "https://", $url);
  1581.         $ch = curl_init();
  1582.         curl_setopt($ch, CURLOPT_URL, $ssl);
  1583.         curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
  1584.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  1585.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  1586.         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  1587.         curl_exec($ch);
  1588.         $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  1589.         curl_close($ch);
  1590.         if ($status == 200 || $status == 401) {
  1591.             return TRUE;
  1592.         }
  1593.     }
  1594.     return FALSE;
  1595. }
  1596. function atom_service_url_filter($url) {
  1597.     if (url_is_accessable_via_ssl($url)) {
  1598.         return preg_replace("/^http:\\/\\//", "https://", $url);
  1599.     }
  1600.     return $url;
  1601. }
  1602. function _deprecated_function($function, $version, $replacement = NULL) {
  1603.     do_action("deprecated_function_run", $function, $replacement, $version);
  1604.     if (WP_DEBUG && apply_filters("deprecated_function_trigger_error", TRUE)) {
  1605.         if (!is_null($replacement)) {
  1606.             trigger_error(sprintf(__("%1\$s is <strong>deprecated</strong> since version %2\$s! Use %3\$s instead."), $function, $version, $replacement));
  1607.         } else {
  1608.             trigger_error(sprintf(__("%1\$s is <strong>deprecated</strong> since version %2\$s with no alternative available."), $function, $version));
  1609.         }
  1610.     }
  1611. }
  1612. function _deprecated_file($file, $version, $replacement = NULL, $message = "") {
  1613.     do_action("deprecated_file_included", $file, $replacement, $version, $message);
  1614.     if (WP_DEBUG && apply_filters("deprecated_file_trigger_error", TRUE)) {
  1615.         $message = empty($message) ? "" : " " . $message;
  1616.         if (!is_null($replacement)) {
  1617.             trigger_error(sprintf(__("%1\$s is <strong>deprecated</strong> since version %2\$s! Use %3\$s instead."), $file, $version, $replacement) . $message);
  1618.         } else {
  1619.             trigger_error(sprintf(__("%1\$s is <strong>deprecated</strong> since version %2\$s with no alternative available."), $file, $version) . $message);
  1620.         }
  1621.     }
  1622. }
  1623. function _deprecated_argument($function, $version, $message = NULL) {
  1624.     do_action("deprecated_argument_run", $function, $message, $version);
  1625.     if (WP_DEBUG && apply_filters("deprecated_argument_trigger_error", TRUE)) {
  1626.         if (!is_null($message)) {
  1627.             trigger_error(sprintf(__("%1\$s was called with an argument that is <strong>deprecated</strong> since version %2\$s! %3\$s"), $function, $version, $message));
  1628.         } else {
  1629.             trigger_error(sprintf(__("%1\$s was called with an argument that is <strong>deprecated</strong> since version %2\$s with no alternative available."), $function, $version));
  1630.         }
  1631.     }
  1632. }
  1633. function _doing_it_wrong($function, $message, $version) {
  1634.     do_action("doing_it_wrong_run", $function, $message, $version);
  1635.     if (WP_DEBUG && apply_filters("doing_it_wrong_trigger_error", TRUE)) {
  1636.         $version = is_null($version) ? "" : sprintf(__("(This message was added in version %s.)"), $version);
  1637.         trigger_error(sprintf(__("%1\$s was called <strong>incorrectly</strong>. %2\$s %3\$s"), $function, $message, $version));
  1638.     }
  1639. }
  1640. function is_lighttpd_before_150() {
  1641.     $server_parts = explode("/", isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : "");
  1642.     $server_parts[1] = isset($server_parts[1]) ? $server_parts[1] : "";
  1643.     return -1 == version_compare($server_parts[1], "1.5.0");
  1644. }
  1645. function apache_mod_loaded($mod, $default = FALSE) {
  1646.     global $is_apache;
  1647.     if (!$is_apache) {
  1648.         return FALSE;
  1649.     }
  1650.     if (function_exists("apache_get_modules")) {
  1651.         $mods = apache_get_modules();
  1652.         return TRUE;
  1653.     }
  1654.     if (in_array($mod, $mods) && function_exists("phpinfo")) {
  1655.         ob_start();
  1656.         phpinfo(8);
  1657.         $phpinfo = ob_get_clean();
  1658.         if (FALSE !== strpos($phpinfo, $mod)) {
  1659.             return TRUE;
  1660.         }
  1661.     }
  1662.     return $default;
  1663. }
  1664. function iis7_supports_permalinks() {
  1665.     global $is_iis7;
  1666.     $supports_permalinks = FALSE;
  1667.     if ($is_iis7) {
  1668.         $supports_permalinks = php_sapi_name() == "cgi-fcgi";
  1669.     }
  1670.     return apply_filters("iis7_supports_permalinks", $supports_permalinks);
  1671. }
  1672. function validate_file($file, $allowed_files = "") {
  1673.     if (FALSE !== strpos($file, "..")) {
  1674.         return 1;
  1675.     }
  1676.     if (FALSE !== strpos($file, "./")) {
  1677.         return 1;
  1678.     }
  1679.     if (!empty($allowed_files) || !in_array($file, $allowed_files)) {
  1680.         return 3;
  1681.     }
  1682.     if (":" == substr($file, 1, 1)) {
  1683.         return 2;
  1684.     }
  1685.     return 0;
  1686. }
  1687. function is_ssl() {
  1688.     if (isset($_SERVER['HTTPS'])) {
  1689.         if ("on" == strtolower($_SERVER['HTTPS'])) {
  1690.             return TRUE;
  1691.         }
  1692.         return TRUE;
  1693.     }
  1694.     if ("1" == $_SERVER['HTTPS'] && isset($_SERVER['SERVER_PORT']) && "443" == $_SERVER['SERVER_PORT']) {
  1695.         return TRUE;
  1696.     }
  1697.     return FALSE;
  1698. }
  1699. function force_ssl_login($force = NULL) {
  1700.     static $forced = FALSE;
  1701.     if (!is_null($force)) {
  1702.         $old_forced = $forced;
  1703.         $forced = $force;
  1704.         return $old_forced;
  1705.     }
  1706.     return $forced;
  1707. }
  1708. function force_ssl_admin($force = NULL) {
  1709.     static $forced = FALSE;
  1710.     if (!is_null($force)) {
  1711.         $old_forced = $forced;
  1712.         $forced = $force;
  1713.         return $old_forced;
  1714.     }
  1715.     return $forced;
  1716. }
  1717. function wp_guess_url() {
  1718.     if (defined("WP_SITEURL") && "" != WP_SITEURL) {
  1719.         $url = WP_SITEURL;
  1720.     } else {
  1721.         $schema = is_ssl() ? "https://" : "http://";
  1722.         $url = preg_replace("|/wp-admin/.*|i", "", $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
  1723.     }
  1724.     return rtrim($url, "/");
  1725. }
  1726. function wp_suspend_cache_invalidation($suspend = TRUE) {
  1727.     global $_wp_suspend_cache_invalidation;
  1728.     $current_suspend = $_wp_suspend_cache_invalidation;
  1729.     $_wp_suspend_cache_invalidation = $suspend;
  1730.     return $current_suspend;
  1731. }
  1732. function get_site_option($option, $default = FALSE, $use_cache = TRUE) {
  1733.     global $wpdb;
  1734.     $pre = apply_filters("pre_site_option_" . $option, FALSE);
  1735.     if (FALSE !== $pre) {
  1736.         return $pre;
  1737.     }
  1738.     if (!is_multisite()) {
  1739.         $value = get_option($option, $default);
  1740.     } else {
  1741.         $cache_key = "{$wpdb->siteid}:{$option}";
  1742.         if ($use_cache) {
  1743.             $value = wp_cache_get($cache_key, "site-options");
  1744.         }
  1745.         if (!isset($value) && FALSE === $value) {
  1746.             $row = $wpdb->get_row($wpdb->prepare("SELECT meta_value FROM " . $wpdb->sitemeta . " WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid));
  1747.             if (is_object($row)) {
  1748.                 $value = $row->meta_value;
  1749.             } else {
  1750.                 $value = $default;
  1751.             }
  1752.             $value = maybe_unserialize($value);
  1753.             wp_cache_set($cache_key, $value, "site-options");
  1754.         }
  1755.     }
  1756.     return apply_filters("site_option_" . $option, $value);
  1757. }
  1758. function add_site_option($option, $value) {
  1759.     global $wpdb;
  1760.     $value = apply_filters("pre_add_site_option_" . $option, $value);
  1761.     if (!is_multisite()) {
  1762.         $result = add_option($option, $value);
  1763.     } else {
  1764.         $cache_key = "{$wpdb->siteid}:{$option}";
  1765.         if ($wpdb->get_row($wpdb->prepare("SELECT meta_value FROM " . $wpdb->sitemeta . " WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid))) {
  1766.             return update_site_option($option, $value);
  1767.         }
  1768.         $value = sanitize_option($option, $value);
  1769.         wp_cache_set($cache_key, $value, "site-options");
  1770.         $_value = $value;
  1771.         $value = maybe_serialize($value);
  1772.         $result = $wpdb->insert($wpdb->sitemeta, array("site_id" => $wpdb->siteid, "meta_key" => $option, "meta_value" => $value));
  1773.         $value = $_value;
  1774.     }
  1775.     do_action("add_site_option_" . $option, $option, $value);
  1776.     do_action("add_site_option", $option, $value);
  1777.     return $result;
  1778. }
  1779. function delete_site_option($option) {
  1780.     global $wpdb;
  1781.     do_action("pre_delete_site_option_" . $option);
  1782.     if (!is_multisite()) {
  1783.         $result = delete_option($option);
  1784.     } else {
  1785.         $row = $wpdb->get_row($wpdb->prepare("SELECT meta_id FROM " . $wpdb->sitemeta . " WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid));
  1786.         if (is_null($row) || !$row->meta_id) {
  1787.             return FALSE;
  1788.         }
  1789.         $cache_key = "{$wpdb->siteid}:{$option}";
  1790.         wp_cache_delete($cache_key, "site-options");
  1791.         $result = $wpdb->query($wpdb->prepare("DELETE FROM " . $wpdb->sitemeta . " WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid));
  1792.     }
  1793.     if ($result) {
  1794.         do_action("delete_site_option_" . $option, $option);
  1795.         do_action("delete_site_option", $option);
  1796.         return TRUE;
  1797.     }
  1798.     return FALSE;
  1799. }
  1800. function update_site_option($option, $value) {
  1801.     global $wpdb;
  1802.     $oldvalue = get_site_option($option);
  1803.     $value = apply_filters("pre_update_site_option_" . $option, $value, $oldvalue);
  1804.     if ($value === $oldvalue) {
  1805.         return FALSE;
  1806.     }
  1807.     if (!is_multisite()) {
  1808.         $result = update_option($option, $value);
  1809.     } else {
  1810.         $cache_key = "{$wpdb->siteid}:{$option}";
  1811.         if ($value && !$wpdb->get_row($wpdb->prepare("SELECT meta_value FROM " . $wpdb->sitemeta . " WHERE meta_key = %s AND site_id = %d", $option, $wpdb->siteid))) {
  1812.             return add_site_option($option, $value);
  1813.         }
  1814.         $value = sanitize_option($option, $value);
  1815.         wp_cache_set($cache_key, $value, "site-options");
  1816.         $_value = $value;
  1817.         $value = maybe_serialize($value);
  1818.         $result = $wpdb->update($wpdb->sitemeta, array("meta_value" => $value), array("site_id" => $wpdb->siteid, "meta_key" => $option));
  1819.         $value = $_value;
  1820.     }
  1821.     if ($result) {
  1822.         do_action("update_site_option_" . $option, $option, $value);
  1823.         do_action("update_site_option", $option, $value);
  1824.         return TRUE;
  1825.     }
  1826.     return FALSE;
  1827. }
  1828. function delete_site_transient($transient) {
  1829.     global $_wp_using_ext_object_cache;
  1830.     do_action("delete_site_transient_" . $transient, $transient);
  1831.     if ($_wp_using_ext_object_cache) {
  1832.         $result = wp_cache_delete($transient, "site-transient");
  1833.     } else {
  1834.         $option_timeout = "_site_transient_timeout_" . $transient;
  1835.         $option = "_site_transient_" . $transient;
  1836.         $result = delete_site_option($option);
  1837.         delete_site_option($option_timeout);
  1838.     }
  1839.     if ($result && $result) {
  1840.         do_action("deleted_site_transient", $transient);
  1841.     }
  1842.     return $result;
  1843. }
  1844. function get_site_transient($transient) {
  1845.     global $_wp_using_ext_object_cache;
  1846.     $pre = apply_filters("pre_site_transient_" . $transient, FALSE);
  1847.     if (FALSE !== $pre) {
  1848.         return $pre;
  1849.     }
  1850.     if ($_wp_using_ext_object_cache) {
  1851.         $value = wp_cache_get($transient, "site-transient");
  1852.     } else {
  1853.         $no_timeout = array("update_core", "update_plugins", "update_themes");
  1854.         $transient_option = "_site_transient_" . $transient;
  1855.         if (!in_array($transient, $no_timeout)) {
  1856.             $transient_timeout = "_site_transient_timeout_" . $transient;
  1857.             $timeout = get_site_option($transient_timeout);
  1858.             if (FALSE !== $timeout && $timeout < time()) {
  1859.                 delete_site_option($transient_option);
  1860.                 delete_site_option($transient_timeout);
  1861.                 return FALSE;
  1862.             }
  1863.         }
  1864.         $value = get_site_option($transient_option);
  1865.     }
  1866.     return apply_filters("site_transient_" . $transient, $value);
  1867. }
  1868. function set_site_transient($transient, $value, $expiration = 0) {
  1869.     global $_wp_using_ext_object_cache;
  1870.     $value = apply_filters("pre_set_site_transient_" . $transient, $value);
  1871.     if ($_wp_using_ext_object_cache) {
  1872.         $result = wp_cache_set($transient, $value, "site-transient", $expiration);
  1873.     } else {
  1874.         $transient_timeout = "_site_transient_timeout_" . $transient;
  1875.         $transient = "_site_transient_" . $transient;
  1876.         if (FALSE === get_site_option($transient)) {
  1877.             if ($expiration) {
  1878.                 add_site_option($transient_timeout, time() + $expiration);
  1879.             }
  1880.             $result = add_site_option($transient, $value);
  1881.         } else {
  1882.             if ($expiration) {
  1883.                 update_site_option($transient_timeout, time() + $expiration);
  1884.             }
  1885.             $result = update_site_option($transient, $value);
  1886.         }
  1887.     }
  1888.     if ($result) {
  1889.         do_action("set_site_transient_" . $transient);
  1890.         do_action("setted_site_transient", $transient);
  1891.     }
  1892.     return $result;
  1893. }
  1894. function is_main_site($blog_id = "") {
  1895.     global $current_site;
  1896.     global $current_blog;
  1897.     if (!is_multisite()) {
  1898.         return TRUE;
  1899.     }
  1900.     if (!$blog_id) {
  1901.         $blog_id = $current_blog->blog_id;
  1902.     }
  1903.     return $blog_id == $current_site->blog_id;
  1904. }
  1905. function global_terms_enabled() {
  1906.     if (!is_multisite()) {
  1907.         return FALSE;
  1908.     }
  1909.     static $global_terms = NULL;
  1910.     if (is_null($global_terms)) {
  1911.         $filter = apply_filters("global_terms_enabled", NULL);
  1912.         if (!is_null($filter)) {
  1913.             $global_terms = $filter;
  1914.             return $global_terms;
  1915.         }
  1916.         $global_terms = get_site_option("global_terms_enabled", FALSE);
  1917.     }
  1918.     return $global_terms;
  1919. }
  1920. function wp_timezone_override_offset() {
  1921.     if (!wp_timezone_supported()) {
  1922.         return FALSE;
  1923.     }
  1924.     if (!($timezone_string = get_option("timezone_string"))) {
  1925.         return FALSE;
  1926.     }
  1927.     $timezone_object = timezone_open($timezone_string);
  1928.     $datetime_object = date_create();
  1929.     if (FALSE === $timezone_object || FALSE === $datetime_object) {
  1930.         return FALSE;
  1931.     }
  1932.     return round(timezone_offset_get($timezone_object, $datetime_object) / 3600, 2);
  1933. }
  1934. function wp_timezone_supported() {
  1935.     $support = FALSE;
  1936.     if (function_exists("date_create") && function_exists("date_default_timezone_set") && function_exists("timezone_identifiers_list") && function_exists("timezone_open") && function_exists("timezone_offset_get")) {
  1937.         $support = TRUE;
  1938.     }
  1939.     return apply_filters("timezone_support", $support);
  1940. }
  1941. function _wp_timezone_choice_usort_callback($a, $b) {
  1942.     if ("Etc" === $a['continent'] && "Etc" === $b['continent']) {
  1943.         if ("GMT+" === substr($a['city'], 0, 4) && "GMT+" === substr($b['city'], 0, 4)) {
  1944.             return 0 - 1 * strnatcasecmp($a['city'], $b['city']);
  1945.         }
  1946.         if ("UTC" === $a['city']) {
  1947.             if ("GMT+" === substr($b['city'], 0, 4)) {
  1948.                 return 1;
  1949.             }
  1950.             return -1;
  1951.         }
  1952.         if ("UTC" === $b['city']) {
  1953.             if ("GMT+" === substr($a['city'], 0, 4)) {
  1954.                 return -1;
  1955.             }
  1956.             return 1;
  1957.         }
  1958.         return strnatcasecmp($a['city'], $b['city']);
  1959.     }
  1960.     if ($a['t_continent'] == $b['t_continent']) {
  1961.         if ($a['t_city'] == $b['t_city']) {
  1962.             return strnatcasecmp($a['t_subcity'], $b['t_subcity']);
  1963.         }
  1964.         return strnatcasecmp($a['t_city'], $b['t_city']);
  1965.     }
  1966.     if ("Etc" === $a['continent']) {
  1967.         return 1;
  1968.     }
  1969.     if ("Etc" === $b['continent']) {
  1970.         return -1;
  1971.     }
  1972.     return strnatcasecmp($a['t_continent'], $b['t_continent']);
  1973. }
  1974. function wp_timezone_choice($selected_zone) {
  1975.     static $mo_loaded = FALSE;
  1976.     $continents = array("Africa", "America", "Antarctica", "Arctic", "Asia", "Atlantic", "Australia", "Europe", "Indian", "Pacific");
  1977.     if (!$mo_loaded) {
  1978.         $locale = get_locale();
  1979.         $mofile = WP_LANG_DIR . "/continents-cities-" . $locale . ".mo";
  1980.         load_textdomain("continents-cities", $mofile);
  1981.         $mo_loaded = TRUE;
  1982.     }
  1983.     $zonen = array();
  1984.     foreach(timezone_identifiers_list() as $zone) {
  1985.         $zone = explode("/", $zone);
  1986.         if (!in_array($zone[0], $continents)) {
  1987.         } else {
  1988.             $exists = array(0 => isset($zone[0]) && $zone[0], 1 => isset($zone[1]) && $zone[1], 2 => isset($zone[2]) && $zone[2]);
  1989.             $exists[3] = "Etc" !== $zone[0];
  1990.             $exists[4] = $exists[1] && $exists[3];
  1991.             $exists[5] = $exists[2] && $exists[3];
  1992.             $zonen[] = array("continent" => $exists[0] ? $zone[0] : "", "city" => $exists[1] ? $zone[1] : "", "subcity" => $exists[2] ? $zone[2] : "", "t_continent" => $exists[3] ? translate(str_replace("_", " ", $zone[0]), "continents-cities") : "", "t_city" => $exists[4] ? translate(str_replace("_", " ", $zone[1]), "continents-cities") : "", "t_subcity" => $exists[5] ? translate(str_replace("_", " ", $zone[2]), "continents-cities") : "");
  1993.         }
  1994.     }
  1995.     usort(&$zonen, "_wp_timezone_choice_usort_callback");
  1996.     $structure = array();
  1997.     if (empty($selected_zone)) {
  1998.         $structure[] = "<option selected=\"selected\" value=\"\">" . __("Select a city") . "</option>";
  1999.     }
  2000.     foreach($zonen as $key => $zone) {
  2001.         $value = array($zone['continent']);
  2002.         if (empty($zone['city'])) {
  2003.             $display = $zone['t_continent'];
  2004.         } else {
  2005.             if (!isset($zonen[$key - 1]) && $zonen[$key - 1]['continent'] !== $zone['continent']) {
  2006.                 $label = $zone['t_continent'];
  2007.                 $structure[] = "<optgroup label=\"" . esc_attr($label) . "\">";
  2008.             }
  2009.             $value[] = $zone['city'];
  2010.             $display = $zone['t_city'];
  2011.             if (!empty($zone['subcity'])) {
  2012.                 $value[] = $zone['subcity'];
  2013.                 $display.= " - " . $zone['t_subcity'];
  2014.             }
  2015.         }
  2016.         $value = join("/", $value);
  2017.         $selected = "";
  2018.         if ($value === $selected_zone) {
  2019.             $selected = "selected=\"selected\" ";
  2020.         }
  2021.         $structure[] = "<option " . $selected . "value=\"" . esc_attr($value) . "\">" . esc_html($display) . "</option>";
  2022.         if (!empty($zone['city'])) {
  2023.             if (!isset($zonen[$key + 1], $zonen[$key + 1]) && !($zonen[$key + 1]['continent'] !== $zone['continent'])) {
  2024.                 $structure[] = "</optgroup>";
  2025.             }
  2026.         }
  2027.     }
  2028.     $structure[] = "<optgroup label=\"" . esc_attr__("UTC") . "\">";
  2029.     $selected = "";
  2030.     if ("UTC" === $selected_zone) {
  2031.         $selected = "selected=\"selected\" ";
  2032.     }
  2033.     $structure[] = "<option " . $selected . "value=\"" . esc_attr("UTC") . "\">" . __("UTC") . "</option>";
  2034.     $structure[] = "</optgroup>";
  2035.     $structure[] = "<optgroup label=\"" . esc_attr__("Manual Offsets") . "\">";
  2036.     $offset_range = array(-12, -11.5, -11, -10.5, -10, -9.5, -9, -8.5, -8, -7.5, -7, -6.5, -6, -5.5, -5, -4.5, -4, -3.5, -3, -2.5, -2, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 5.75, 6, 6.5, 7, 7.5, 8, 8.5, 8.75, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.75, 13, 13.75, 14);
  2037.     foreach($offset_range as $offset) {
  2038.         if (0 <= $offset) {
  2039.             $offset_name = "+" . $offset;
  2040.         } else {
  2041.             $offset_name = ( boolean )$offset;
  2042.         }
  2043.         $offset_value = $offset_name;
  2044.         $offset_name = str_replace(array(".25", ".5", ".75"), array(":15", ":30", ":45"), $offset_name);
  2045.         $offset_name = "UTC" . $offset_name;
  2046.         $offset_value = "UTC" . $offset_value;
  2047.         $selected = "";
  2048.         if ($offset_value === $selected_zone) {
  2049.             $selected = "selected=\"selected\" ";
  2050.         }
  2051.         $structure[] = "<option " . $selected . "value=\"" . esc_attr($offset_value) . "\">" . esc_html($offset_name) . "</option>";
  2052.     }
  2053.     $structure[] = "</optgroup>";
  2054.     return join("\n", $structure);
  2055. }
  2056. function _cleanup_header_comment($str) {
  2057.     return trim(preg_replace("/\\s*(?:\\*\\/|\\?>).*/", "", $str));
  2058. }
  2059. function wp_scheduled_delete() {
  2060.     global $wpdb;
  2061.     $delete_timestamp = time() - 86400 * EMPTY_TRASH_DAYS;
  2062.     $posts_to_delete = $wpdb->get_results($wpdb->prepare("SELECT post_id FROM " . $wpdb->postmeta . " WHERE meta_key = '_wp_trash_meta_time' AND meta_value < '%d'", $delete_timestamp), ARRAY_A);
  2063.     foreach(( array )$posts_to_delete as $post) {
  2064.         $post_id = ( integer )$post['post_id'];
  2065.         if (!$post_id) {
  2066.         } else {
  2067.             $del_post = get_post($post_id);
  2068.             if (!$del_post && "trash" != $del_post->post_status) {
  2069.                 delete_post_meta($post_id, "_wp_trash_meta_status");
  2070.                 delete_post_meta($post_id, "_wp_trash_meta_time");
  2071.             } else {
  2072.                 wp_delete_post($post_id);
  2073.             }
  2074.         }
  2075.     }
  2076.     $comments_to_delete = $wpdb->get_results($wpdb->prepare("SELECT comment_id FROM " . $wpdb->commentmeta . " WHERE meta_key = '_wp_trash_meta_time' AND meta_value < '%d'", $delete_timestamp), ARRAY_A);
  2077.     foreach(( array )$comments_to_delete as $comment) {
  2078.         $comment_id = ( integer )$comment['comment_id'];
  2079.         if (!$comment_id) {
  2080.         } else {
  2081.             $del_comment = get_comment($comment_id);
  2082.             if (!$del_comment && "trash" != $del_comment->comment_approved) {
  2083.                 delete_comment_meta($comment_id, "_wp_trash_meta_time");
  2084.                 delete_comment_meta($comment_id, "_wp_trash_meta_status");
  2085.             } else {
  2086.                 wp_delete_comment($comment_id);
  2087.             }
  2088.         }
  2089.     }
  2090. }
  2091. function get_file_data($file, $default_headers, $context = "") {
  2092.     $fp = fopen($file, "r");
  2093.     $file_data = fread($fp, 8192);
  2094.     fclose($fp);
  2095.     if ($context != "") {
  2096.         $extra_headers = apply_filters("extra_" . $context . "_headers", array());
  2097.         $extra_headers = array_flip($extra_headers);
  2098.         foreach($extra_headers as $key => $value) {
  2099.             $extra_headers[$key] = $key;
  2100.         }
  2101.         $all_headers = array_merge($extra_headers, ( array )$default_headers);
  2102.     } else {
  2103.         $all_headers = $default_headers;
  2104.     }
  2105.     foreach($all_headers as $field => $regex) {
  2106.         preg_match("/^[ \\t\\/*#]*" . preg_quote($regex, "/") . ":(.*)\$/mi", $file_data, $$field);
  2107.         if (!empty($field)) {
  2108.             $$field = _cleanup_header_comment($$field[1]);
  2109.         } else {
  2110.             $$field = "";
  2111.         }
  2112.     }
  2113.     $file_data = compact(array_keys($all_headers));
  2114.     return $file_data;
  2115. }
  2116. function _search_terms_tidy($t) {
  2117.     return trim($t, "\"'\n\r ");
  2118. }
  2119. function __return_true() {
  2120.     return TRUE;
  2121. }
  2122. function __return_false() {
  2123.     return FALSE;
  2124. }
  2125. function __return_zero() {
  2126.     return 0;
  2127. }
  2128. function __return_empty_array() {
  2129.     return array();
  2130. }
  2131. function send_nosniff_header() {
  2132.     @header("X-Content-Type-Options: nosniff");
  2133. }
  2134. function _wp_mysql_week($column) {
  2135. case 0:
  2136. default:
  2137.     switch ($start_of_week = ( integer )get_option("start_of_week")) {
  2138.             return "WEEK( " . $column . ", 0 )";
  2139.         case 1:
  2140.             return "WEEK( " . $column . ", 1 )";
  2141.         case 2:
  2142.         case 3:
  2143.         case 4:
  2144.         case 5:
  2145.         case 6:
  2146.     }
  2147.     return "WEEK( DATE_SUB( " . $column . ", INTERVAL {$start_of_week} DAY ), 0 )";
  2148. }
  2149. function wp_find_hierarchy_loop($callback, $start, $start_parent, $callback_args = array()) {
  2150.     $override = is_null($start_parent) ? array() : array($start => $start_parent);
  2151.     if (!($arbitrary_loop_member = wp_find_hierarchy_loop_tortoise_hare($callback, $start, $override, $callback_args))) {
  2152.         return array();
  2153.     }
  2154.     return wp_find_hierarchy_loop_tortoise_hare($callback, $arbitrary_loop_member, $override, $callback_args, TRUE);
  2155. }
  2156. function wp_find_hierarchy_loop_tortoise_hare($callback, $start, $override = array(), $callback_args = array(), $_return_loop = FALSE) {
  2157.     $tortoise = $hare = $evanescent_hare = $start;
  2158.     $return = array();
  2159.     while ($tortoise) {
  2160.         if (!($evanescent_hare = isset($override[$hare]) ? $override[$hare] : call_user_func_array($callback, array_merge(array($hare), $callback_args)))) {
  2161.             break;
  2162.         }
  2163.         if (!($hare = isset($override[$evanescent_hare]) ? $override[$evanescent_hare] : call_user_func_array($callback, array_merge(array($evanescent_hare), $callback_args)))) {
  2164.             break;
  2165.         }
  2166.         if ($_return_loop) {
  2167.             $return[$tortoise] = $return[$evanescent_hare] = $return[$hare] = TRUE;
  2168.         }
  2169.         if ($tortoise == $evanescent_hare || $tortoise == $hare) {
  2170.             if ($_return_loop) {
  2171.                 return $return;
  2172.             }
  2173.             return $tortoise;
  2174.         }
  2175.         $tortoise = isset($override[$tortoise]) ? $override[$tortoise] : call_user_func_array($callback, array_merge(array($tortoise), $callback_args));
  2176.     }
  2177.     return FALSE;
  2178. }
  2179. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement