DiscussionCustomPrefix: Added new icons and translations
[vanilla-miry.git] / ajax / updatecheck.php
blobf35099eca09b6993e43d5ef27b7f601d8a64f67b
1 <?php
2 /*
3 * Copyright 2003 Mark O'Sullivan
4 * This file is part of Vanilla.
5 * Vanilla is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
6 * Vanilla is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
7 * You should have received a copy of the GNU General Public License along with Vanilla; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8 * The latest source code for Vanilla is available at www.lussumo.com
9 * Contact Mark O'Sullivan at mark [at] lussumo [dot] com
11 * Description: File used by the Extension management form to handle turning extensions on and off
14 include('../appg/settings.php');
15 include('../appg/init_ajax.php');
17 // Process the ajax request
18 $PostBackKey = ForceIncomingString('PostBackKey', '');
19 $ExtensionKey = ForceIncomingString('ExtensionKey', '');
20 $RequestName = ForceIncomingString('RequestName', '');
21 $SafeRequestName = htmlentities($RequestName);
23 if ($PostBackKey != ''
24 && $PostBackKey != $Context->Session->GetCsrfValidationKey()
25 ) {
26 echo $SafeRequestName.'|[ERROR]'.$Context->GetDefinition('ErrPostBackKeyInvalid');
27 } else if ($RequestName == 'Core') {
28 // Ping the Lussumo server with core version information
29 $VersionStatus = OpenUrl($Context->Configuration['UPDATE_URL']
30 .'?Application=VanillaCore'
31 .'&Version='.APPLICATION_VERSION
32 .'&Language='.$Context->Configuration['LANGUAGE']
33 .'&RequestUrl='.$Context->Configuration['BASE_URL'],
34 $Context);
36 // Also record that the check occurred
37 $SettingsFile = $Context->Configuration['APPLICATION_PATH'].'conf/settings.php';
38 $ConfigurationManager = $Context->ObjectFactory->NewContextObject($Context, "ConfigurationManager");
39 $ConfigurationManager->DefineSetting('LAST_UPDATE', mktime(), 1);
40 $ConfigurationManager->SaveSettingsToFile($SettingsFile);
42 // Spit out the core message
43 if ($VersionStatus == "GOOD") {
44 echo 'First|'.$Context->GetDefinition('ApplicationStatusGood');
45 } else {
46 $aVersionStatus = explode("|", $VersionStatus);
47 if (count($aVersionStatus) == 2) {
48 echo 'First|[OLD]'.str_replace(array('\\1','\\2'), array($aVersionStatus[0], $aVersionStatus[1]), $Context->GetDefinition('NewVersionAvailable'));
49 } else {
50 // There was some kind of error
51 echo 'First|[ERROR]'.$VersionStatus;
54 } else {
55 // Load all extensions for version information
56 $Extensions = DefineExtensions($Context);
57 if (!is_array($Extensions)) {
58 echo $SafeRequestName.'|[ERROR]'.$Context->WarningCollector->GetPlainMessages();
59 } elseif (count($Extensions) > 0) {
60 // All of the extensions were loaded successfully.
61 // Ping the Lussumo server with the next extension
62 $CheckExtension = '';
63 while (list($ExtensionKey, $Extension) = each($Extensions)) {
64 if ($RequestName == 'First') {
65 $CheckExtension = $ExtensionKey;
66 $RequestName = '';
67 break;
68 } else if ($RequestName == $ExtensionKey) {
69 $RequestName = '[NEXT]';
70 } else if ($RequestName == '[NEXT]') {
71 $CheckExtension = $ExtensionKey;
72 $RequestName = '';
73 break;
77 // Ping the CheckExtension value if it isn't empty
78 if ($CheckExtension != '') {
79 $Extension = $Extensions[$CheckExtension];
80 // Ping the Lussumo server with extension version information
81 $VersionStatus = OpenUrl($Context->Configuration['UPDATE_URL']
82 .'?Extension='.unhtmlspecialchars($Extension->Name)
83 .'&Version='.unhtmlspecialchars($Extension->Version),
84 $Context);
85 if ($VersionStatus == "GOOD") {
86 echo $CheckExtension.'|[GOOD]'.$Context->GetDefinition('ExtensionStatusGood');
87 } elseif ($VersionStatus == "UNKNOWN") {
88 echo $CheckExtension.'|[UNKNOWN]'.$Context->GetDefinition('ExtensionStatusUnknown');
89 } else {
90 // If an item is out of date, it contains two bits of information
91 // separated by pipes
92 // eg. Version|URL
93 $aVersionStatus = explode("|", $VersionStatus);
94 if (count($aVersionStatus) == 2) {
95 echo $CheckExtension.'|[OLD]'.str_replace(array('\\1','\\2'), array($aVersionStatus[0], $aVersionStatus[1]), $Context->GetDefinition('NewVersionAvailable'));
96 } else {
97 // There was some kind of error
98 echo $CheckExtension.'|[ERROR]'.$VersionStatus;
101 } else {
102 if ($RequestName == '[NEXT]') {
103 echo 'COMPLETE';
104 } else {
105 echo $RequestName.'Failed to get extension name from ajax call.';
108 } else {
109 echo 'COMPLETE';
112 $Context->Unload();