| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* You must make sure that the information at these URLs is in sync. No point |
|---|
| 4 | * in telling you there's a new version out when the download page doesn't |
|---|
| 5 | * contain that version yet. This is very important for Internationalization: |
|---|
| 6 | * don't provide your translated version of WordPress in one URL and not the |
|---|
| 7 | * other. |
|---|
| 8 | */ |
|---|
| 9 | |
|---|
| 10 | $resturl = __("http://www.freecharity.org.uk/versions/"); |
|---|
| 11 | $upgradeurl = __("http://wordpress.org/download/"); |
|---|
| 12 | |
|---|
| 13 | $minutes_between_checks = 24*60; |
|---|
| 14 | |
|---|
| 15 | $message[101] = __("This release fixes a critical security issue"); |
|---|
| 16 | $message[102] = __("This release fixes a security issue"); |
|---|
| 17 | $message[103] = __("This release fixes a minor security issue"); |
|---|
| 18 | $message[201] = __("This release fixes a critical bug"); |
|---|
| 19 | $message[202] = __("This release fixes a bug"); |
|---|
| 20 | $message[203] = __("This release fixes a minor bug"); |
|---|
| 21 | $message[301] = __("This release adds major new functionality"); |
|---|
| 22 | $message[302] = __("This release adds new functionality"); |
|---|
| 23 | $message[303] = __("This release adds minor new functionality"); |
|---|
| 24 | |
|---|
| 25 | function branch_from_version(){ |
|---|
| 26 | // Work out which branch from the version number |
|---|
| 27 | global $wp_version; |
|---|
| 28 | $t = preg_replace("/-|[a-zA-Z]/","",$wp_version); |
|---|
| 29 | $c = preg_match("/\./",$t); |
|---|
| 30 | $n = preg_split("/\./",$t); |
|---|
| 31 | if ($c == 0) { return "$n[0].0"; } |
|---|
| 32 | else { return "$n[0].$n[1]";} |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | function set_latest_version(){ |
|---|
| 36 | /* Set the latest version. Store the results in the options table. |
|---|
| 37 | * Store the time when it was fetched in the options table, use this |
|---|
| 38 | * cached result for the next $minutes_between_checks minutes. Returns |
|---|
| 39 | * false on failure. |
|---|
| 40 | * |
|---|
| 41 | * The REST server doesn't need to concern itself with versions before |
|---|
| 42 | * the inclusion of this code (since they'll not be querying it). When |
|---|
| 43 | * future branches are depriciated point the REST resource too the |
|---|
| 44 | * latest branch ('ln -s versions/2.2 versions/2.1' for example) |
|---|
| 45 | */ |
|---|
| 46 | |
|---|
| 47 | global $minutes_between_checks; |
|---|
| 48 | global $resturl; |
|---|
| 49 | global $wp_version; |
|---|
| 50 | |
|---|
| 51 | $branch = branch_from_version(); |
|---|
| 52 | |
|---|
| 53 | $last_version_check = get_option("wp_version_check_time"); |
|---|
| 54 | |
|---|
| 55 | if($last_version_check == "" || time() > $minutes_between_checks*60 + $last_version_check){ |
|---|
| 56 | $c = curl_init($resturl.$branch); |
|---|
| 57 | curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); |
|---|
| 58 | curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 2); |
|---|
| 59 | curl_setopt($c, CURLOPT_TIMEOUT, 3); |
|---|
| 60 | $r = curl_exec($c); |
|---|
| 61 | curl_close($c); |
|---|
| 62 | if(!$r) return $r; |
|---|
| 63 | update_option("wp_version_check_time",time()); |
|---|
| 64 | update_option("wp_version_check_results",$r); |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | /* do we need to trigger hooks? */ |
|---|
| 68 | list($latest,$m,$blog) = split(",",get_latest_version()); |
|---|
| 69 | if(version_compare($latest,$wp_version)==1 && !get_option("wp_version_notified")) { |
|---|
| 70 | do_action('update_notification',$wp_version,$latest); |
|---|
| 71 | update_option("wp_version_notified",1); |
|---|
| 72 | } |
|---|
| 73 | if(version_compare($latest,$wp_version)!=1) { |
|---|
| 74 | update_option("wp_version_notified",0); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | return true; |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | function get_latest_version(){ |
|---|
| 81 | // Retrieve the latet version from the options table. Return false if |
|---|
| 82 | // it's not there. |
|---|
| 83 | $version = get_option("wp_version_check_results"); |
|---|
| 84 | if($version == "") return false; |
|---|
| 85 | else return $version; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | function latest_version(){ |
|---|
| 89 | global $wp_version; |
|---|
| 90 | global $upgradeurl; |
|---|
| 91 | global $message; |
|---|
| 92 | |
|---|
| 93 | //Check to see if we're running a development version. |
|---|
| 94 | if (preg_match("/[a-zA-Z]/",$wp_version)>0) { |
|---|
| 95 | echo "<div id=\"wpurg\">".__("\"Please do not shoot the developer. He is doing his best\" - you are runing an unsupported development version of WordPress.")."</div>"; |
|---|
| 96 | return; |
|---|
| 97 | } |
|---|
| 98 | //We're not. Check the options database, failing gracefully. |
|---|
| 99 | set_latest_version(); //If we go with cron, remove this line |
|---|
| 100 | list($latest,$m,$blog) = split(",",get_latest_version()); |
|---|
| 101 | if(!$latest) return; |
|---|
| 102 | if(version_compare($latest,$wp_version)==1) echo "<div id=\"wpurg\">".__("Please ") . "<a href=\"$upgradeurl\">" . __("upgrade to version "). $latest. "</a>. $message[$m] " . "(<a href=\"$blog\">". __("detailed information") . "</a>)." ."</div>"; |
|---|
| 103 | return; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | // This code schedules an hourly cron based update. If this is ever enabled, |
|---|
| 107 | // don't forget to remove the marked line above. |
|---|
| 108 | |
|---|
| 109 | /* |
|---|
| 110 | *add_action('set_latest_version_hook', 'set_latest_version'); |
|---|
| 111 | *if (!wp_next_scheduled('set_latest_version_hook')) { |
|---|
| 112 | * wp_schedule_event( time(), 'hourly', 'set_latest_version_hook' ); |
|---|
| 113 | *} |
|---|
| 114 | */ |
|---|
| 115 | |
|---|
| 116 | ?> |
|---|