00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 include('TranslationBackend.php');
00023 include_once('export/TranslationExport.php');
00024
00033 class WebBackend extends TranslationBackend
00034 {
00035 public $xStringStack;
00036 public $xBrowserHelper;
00042 function __construct()
00043 {
00044 parent::__construct();
00045 }
00046
00051 public function EventHandler()
00052 {
00053 global $_POST;
00054
00055
00056 $this->Event = (empty($_POST["__Event"]) ? "" : $_POST["__Event"] );
00057
00058 if($this->Event != "")
00059 {
00060
00061
00062
00063 $this->xBrowserHelper = (empty($_POST["xBrowserHelper"]) ? "" : $_POST["xBrowserHelper"]);
00064 $this->txtEditString = (empty($_POST["txtEditString_".$this->xBrowserHelper]) ? "" : $_POST["txtEditString_".$this->xBrowserHelper] );
00065 $this->txtEditString = trim($this->txtEditString);
00066
00067 $this->txtFindText = (empty($_POST["txtFindText"]) ? "" : $_POST["txtFindText"] );
00068 $this->ddlFindPercent = (empty($_POST["ddlFindPercent"]) ? 60 : $_POST["ddlFindPercent"]);
00069 $this->xStringID = (empty($_POST["xStringID"]) ? "" : $_POST["xStringID"]);
00070 $this->xProjectID = (empty($_POST["xProjectID"]) ? "" : $_POST["xProjectID"]);
00071 $this->ddlLocaleID = (empty($_POST["xOldLocaleID"]) ? "" : $_POST["xOldLocaleID"]);
00072 $this->xOldLocaleID = (empty($_POST["xOldLocaleID"]) ? "" : $_POST["xOldLocaleID"]);
00073 $this->ddlSearchType = (empty($_POST["ddlSearchType"]) ? 0 : $_POST["ddlSearchType"]);
00074 $this->xStringStack = (empty($_POST["xStringStack"]) ? "" : $_POST["xStringStack"]);
00075 $this->xDelStringID = (empty($_POST["xDelStringID"]) ? "" : $_POST["xDelStringID"]);
00076
00077
00078 if($this->xProjectID == 0)
00079 {
00080 $this->InitLanguage();
00081 }
00082
00083
00084
00085 switch($this->Event)
00086 {
00087 case "find":
00088 $this->Event_FindCustomString();
00089 break;
00090
00091 case "editstring":
00092 $this->Event_EditString();
00093 break;
00094
00095 case "deletestring":
00096 $this->Event_DeleteString();
00097 break;
00098
00099 case "savenextmissing":
00100 case "savepopstack":
00101 case "savenext":
00102 case "nextmissing":
00103 case "next":
00104 case "save":
00105 $this->Event_SaveNavigate();
00106 break;
00107
00108 case "setproject":
00109 $this->Event_SetProject();
00110 break;
00111
00112 case "setlocale":
00113 $this->Event_SetLocale();
00114 break;
00115
00116 case "exportpack":
00117 $this->Event_ExportPack();
00118 break;
00119
00120 }
00121
00122
00123
00124 if(!empty($this->LocatedString))
00125 {
00126 $this->xBrowserHelper = md5($this->LocatedString->GetOriginal());
00127 }
00128
00129
00130 }
00131 }
00132
00137 private function Event_FindCustomString()
00138 {
00139
00140 $this->FindStrings();
00141
00142 $this->SyncToString();
00143 }
00144
00145
00150 private function Event_EditString()
00151 {
00152
00153 $this->SyncToString();
00154
00155
00156 if(!empty($this->LocatedString))
00157 {
00158 $this->ddlSearchType = 0;
00159 $this->txtFindText = $this->LocatedString->GetOriginal();
00160 $this->FindStrings();
00161 }
00162 }
00163
00168 private function Event_DeleteString()
00169 {
00170 $this->DeleteString();
00171
00172 if($this->xDelStringID == $this->xStringID)
00173 {
00174
00175 $this->xStringID = 0;
00176 $this->SyncToProject();
00177 }
00178 else
00179 {
00180
00181 $this->SyncToString();
00182 }
00183
00184
00185 $this->FindStrings();
00186 }
00187
00192 private function Event_SaveNavigate()
00193 {
00194
00195 if($this->Event == "savenext" ||
00196 $this->Event == "savenextmissing" ||
00197 $this->Event == "savepopstack" ||
00198 $this->Event == "save")
00199 {
00200 $this->SaveString();
00201 }
00202
00203
00204 $locType = LOCATE_CURR;
00205
00206 if($this->Event == "savenext" || $this->Event == "next")
00207 {
00208 $locType = LOCATE_NEXT;
00209 }
00210 else if($this->Event == "savenextmissing" || $this->Event == "nextmissing")
00211 {
00212 $locType = LOCATE_NEXTMISSING;
00213 }
00214 else if($this->Event == "savepopstack")
00215 {
00216
00217 $locType = LOCATE_CURR;
00218
00219 $stack = split(",", $this->xStringStack);
00220 $this->xStringID = array_pop($stack);
00221 $this->xStringStack = join($stack, ",");
00222 }
00223
00224
00225 $this->LocateString($locType);
00226
00227 $this->SyncToString();
00228
00229
00230 if(!empty($this->LocatedString))
00231 {
00232 $this->ddlSearchType = 0;
00233 $this->txtFindText = $this->LocatedString->GetOriginal();
00234 $this->FindStrings();
00235 }
00236 }
00237
00242 private function Event_SetProject()
00243 {
00244 $this->SyncToProject();
00245
00246
00247 if(!empty($this->LocatedString))
00248 {
00249 $this->ddlSearchType = 0;
00250 $this->txtFindText = $this->LocatedString->GetOriginal();
00251 $this->FindStrings();
00252 }
00253
00254 }
00255
00260 private function Event_SetLocale()
00261 {
00262 $this->xOldLocaleID = (empty($_POST["ddlLocaleID"]) ? "" : $_POST["ddlLocaleID"]);
00263 $this->ddlLocaleID = $this->xOldLocaleID;
00264 $this->InitLanguage();
00265
00266 $this->SyncToProject();
00267 }
00268
00273 private function Event_ExportPack()
00274 {
00275 global $CONFIG;
00276
00277
00278 if(!$CONFIG['enable_web_export'])
00279 {
00280 throw new Exception("Web GUI export function is disabled in configuration.");
00281 }
00282
00283
00284 $localeName = "";
00285 foreach(TranslationProject::$LocaleIDCache as $name => $id)
00286 {
00287 if($id == $this->ddlLocaleID)
00288 {
00289 $localeName = $name;
00290 break;
00291 }
00292 }
00293
00294 if($localeName == "")
00295 {
00296 throw new Exception("Cannot find locale name for current locale id: " + $this->ddlLocaleID);
00297 }
00298
00299
00300
00301 $factory = new CreateExporter();
00302 $proc = $factory->NewExporter("Xaraya");
00303
00304
00305 $proc->Export($localeName, true);
00306
00307
00308 $languagePack = $localeName."_".date('Y-m-d').".tar.gz";
00309 system("tar -C ".$CONFIG['export_path']." --exclude $localeName/php -czf ".$CONFIG['language_pack_dir']."/$languagePack $localeName", $ret);
00310 if($ret != 0)
00311 {
00312 echo("<p>Tar returned $ret, the package may be incomplete.</p>");
00313 }
00314 $link = $CONFIG['language_pack_url']."/$languagePack";
00315 echo("<p>Language pack saved to: <a href=\"$link\">$link</a>.</p>");
00316 }
00317
00322 private function SyncToProject()
00323 {
00324 $this->xStringID = 0;
00325
00326 if($this->xProjectID == 0)
00327 {
00328 return;
00329 }
00330
00331
00332 $this->LoadProjectStrings();
00333
00334 if($this->CurrentStrings->valid())
00335 {
00336
00337 $this->xStringID = $this->CurrentStrings->current()->GetStringID();
00338 $this->LocateString();
00339
00340
00341 $this->txtFindText = $this->LocatedString->GetOriginal();
00342 $this->FindStrings();
00343 }
00344 else
00345 {
00346
00347 $this->xStringID = 0;
00348 }
00349
00350
00351 $this->FindProjectPath();
00352 }
00353
00358 private function SyncToString()
00359 {
00360 if($this->xStringID == 0)
00361 {
00362 return;
00363 }
00364
00365 $this->LocateString();
00366
00367 if(!empty($this->LocatedString))
00368 {
00369
00370 $this->xProjectID = $this->LocatedString->GetProjectID();
00371 $this->LoadProjectStrings();
00372 }
00373
00374
00375 $this->FindProjectPath();
00376 }
00377
00378 }