00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 include_once('config.inc.php');
00023 include_once('lib/Common.php');
00024
00025 $DB = NewADOConnection(GetConfigVar('db_software'));
00026 $DB->Connect(GetConfigVar('db_host'), GetConfigVar('db_username') , GetConfigVar('db_password'), GetConfigVar('db_database'));
00027 $DB->Execute("SET NAMES utf8");
00028 CacheIndexes();
00029
00030 define('LOCATE_CURR', 0);
00031 define('LOCATE_NEXT', 1);
00032 define('LOCATE_NEXTMISSING', 2);
00033 define('LOCATE_PREV', 3);
00034 define('LOCATE_PREVMISSING', 4);
00035
00044 class TranslationBackend
00045 {
00046 public $Event;
00048
00049
00050 public $txtFindText;
00051 public $ddlSearchType;
00052 public $ddlFindPercent;
00053 public $ddlLocaleID;
00054 public $xOldLocaleID;
00055 public $xStringID;
00056 public $xDelStringID;
00057 public $txtEditString;
00059
00060
00061 public $Translations;
00062 public $LocatedString;
00063 public $LocatedProjects;
00064 public $ChildProjects;
00065 public $CurrentStrings;
00066 public $RootLastSeen;
00068
00069
00070 private $String;
00079 function __construct()
00080 {
00081
00082 $localeName = GetConfigVar('default_locale');
00083 $localeID = TranslationProject::$LocaleIDCache[$localeName];
00084 if(empty($localeID))
00085 {
00086 throw new Exception("Invalid default locale in the configuration: $localeName");
00087 }
00088
00089
00090 $this->String = new TranslationString();
00091 $this->DB = GetDbConn();
00092 $this->Tables = GetTables();
00093
00094 $this->txtFindText = "";
00095 $this->ddlSearchType = 0;
00096 $this->ddlFindPercent = 60;
00097 $this->ddlLocaleID = $localeID;
00098 $this->xOldLocaleID = $localeID;
00099 $this->xStringID = 0;
00100 $this->xProjectID = 0;
00101
00102 $this->InitLanguage();
00103 }
00104
00109 public function InitLanguage()
00110 {
00111
00112 $proj = new TranslationProject();
00113 if($proj->LoadRoot("Xaraya", $this->ddlLocaleID))
00114 {
00115 $this->xProjectID = $proj->GetID();
00116 $this->FindProjectPath();
00117 }
00118 }
00119
00135 function FindStrings()
00136 {
00137 switch($this->ddlSearchType)
00138 {
00139
00140 case 1:
00141
00142 $this->Translations = $this->String->FindText($this->txtFindText, $this->ddlLocaleID, true);
00143 break;
00144
00145 case 2:
00146
00147 $this->Translations = $this->String->FindText($this->txtFindText, $this->ddlLocaleID, false);
00148 break;
00149
00150 default:
00151
00152 $this->Translations = $this->String->FindSimilar($this->txtFindText, $this->ddlLocaleID, $this->ddlFindPercent);
00153 break;
00154 }
00155 }
00156
00169 function LocateString($locate = LOCATE_CURR)
00170 {
00171
00172 switch($locate)
00173 {
00174 case LOCATE_CURR:
00175 $this->LocatedString = new TranslationString($this->xStringID);
00176 break;
00177
00178 case LOCATE_NEXT:
00179 case LOCATE_NEXTMISSING:
00180 $this->LocateStringNext( ($locate == LOCATE_NEXTMISSING) );
00181 break;
00182 }
00183 }
00184
00189 private function LocateStringNext($missingOnly)
00190 {
00191 unset($this->LocatedString);
00192
00193
00194
00195
00196 if($this->xStringID != 0)
00197 {
00198
00199 $currentString = new TranslationString($this->xStringID);
00200 $stringIter = new StringIterator($currentString->GetProjectID());
00201
00202
00203
00204
00205 $takeString = false;
00206 foreach($stringIter as $str)
00207 {
00208 if($takeString)
00209 {
00210 $this->LocatedString = new TranslationString($str->GetStringID());
00211
00212
00213 if($missingOnly && $this->LocatedString->GetTranslation() != "")
00214 {
00215
00216 unset($this->LocatedString);
00217 }
00218 else
00219 {
00220
00221 $this->xStringID = $str->GetStringID();
00222 break;
00223 }
00224 }
00225
00226
00227 if($str->GetStringID() == $currentString->GetStringID())
00228 {
00229 $takeString = true;
00230 }
00231 }
00232 }
00233
00234
00235
00236
00237 $currentProject = new TranslationProject($this->xProjectID);
00238
00239
00240 $rootHit = false;
00241
00242
00243 while(empty($this->LocatedString) && !$rootHit)
00244 {
00245 $takeProject = false;
00246
00247
00248 $parentProjects = new RecursiveIteratorIterator(
00249 new ProjectIterator($currentProject->GetParentID(), $this->ddlLocaleID),
00250 RecursiveIteratorIterator::SELF_FIRST);
00251
00252
00253 foreach($parentProjects as $proj)
00254 {
00255
00256 if($takeProject)
00257 {
00258
00259 $stringIter = new StringIterator($proj->GetID());
00260
00261
00262 if(!$missingOnly)
00263 {
00264
00265 if($stringIter->valid())
00266 {
00267 $this->xStringID = $stringIter->current()->GetStringID();
00268 $this->LocatedString = new TranslationString($this->xStringID);
00269 break;
00270 }
00271 }
00272 else
00273 {
00274 $foundEmpty = false;
00275
00276
00277 foreach($stringIter as $str)
00278 {
00279 if($str->GetTranslation() == "")
00280 {
00281 $this->xStringID = $str->GetStringID();
00282 $this->LocatedString = new TranslationString($this->xStringID);
00283 $foundEmpty = true;
00284 break;
00285 }
00286 }
00287
00288
00289 if($foundEmpty)
00290 {
00291 break;
00292 }
00293 }
00294 }
00295
00296
00297 if($proj->GetID() == $this->xProjectID)
00298 {
00299 $takeProject = true;
00300 }
00301 }
00302
00303
00304 $rootHit = ($currentProject->GetParentID() == 0);
00305
00306
00307 if($currentProject->GetParentID() != 0 && empty($this->LocatedString))
00308 {
00309 $currentProject = new TranslationProject($currentProject->GetParentID());
00310 }
00311
00312 }
00313 }
00327 function FindProjectPath()
00328 {
00329 unset ($this->LocatedProjects);
00330 unset ($this->ChildProjects);
00331
00332 $pid = $this->xProjectID;
00333
00334
00335 while($pid != 0)
00336 {
00337 $proj = new TranslationProject($pid);
00338 $this->LocatedProjects[] = $proj;
00339 $pid = $proj->GetParentID();
00340
00341
00342 if($pid == 0)
00343 {
00344 $this->RootLastSeen = $proj->GetLastSeen();
00345 }
00346 }
00347
00348
00349 $this->ChildProjects = new ProjectIterator($this->xProjectID, $this->ddlLocaleID);
00350 }
00351
00360 function SaveString()
00361 {
00362
00363 $string = new TranslationString($this->xStringID);
00364 $string->SetTranslation($this->txtEditString);
00365 $string->Save();
00366 }
00367
00372 function DeleteString()
00373 {
00374
00375 $string = new TranslationString($this->xDelStringID);
00376 $string->DestroyData();
00377 }
00378
00385 function DeleteProject($projectID)
00386 {
00387 $project = new TranslationProject($projectID);
00388 $parent = $project->GetParentID();
00389 $project->DestroyData();
00390 return $parent;
00391 }
00392
00397 function LoadProjectStrings()
00398 {
00399 $this->CurrentStrings = new StringIterator($this->xProjectID);
00400 }
00401 }
00402
00403 ?>