Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like LocaliseModelTranslation often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use LocaliseModelTranslation, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 23 | class LocaliseModelTranslation extends JModelAdmin |
||
| 24 | { |
||
| 25 | protected $item; |
||
| 26 | |||
| 27 | protected $contents; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Method to auto-populate the model state. |
||
| 31 | * |
||
| 32 | * Note. Calling getState in this method will result in recursion. |
||
| 33 | * |
||
| 34 | * @param string $ordering An optional ordering field. |
||
| 35 | * @param string $direction An optional direction (asc|desc). |
||
| 36 | * |
||
| 37 | * @return void |
||
| 38 | * |
||
| 39 | * @since 1.6 |
||
| 40 | */ |
||
| 41 | protected function populateState($ordering = null, $direction = null) |
||
| 42 | { |
||
| 43 | $input = JFactory::getApplication()->input; |
||
| 44 | |||
| 45 | // Get the infos |
||
| 46 | $client = $input->getCmd('client', ''); |
||
| 47 | $tag = $input->getCmd('tag', ''); |
||
| 48 | $filename = $input->getCmd('filename', ''); |
||
| 49 | $storage = $input->getCmd('storage', ''); |
||
| 50 | |||
| 51 | $this->setState('translation.client', !empty($client) ? $client : 'site'); |
||
| 52 | $this->setState('translation.tag', $tag); |
||
| 53 | $this->setState('translation.filename', $filename); |
||
| 54 | $this->setState('translation.storage', $storage); |
||
| 55 | |||
| 56 | // Get the id |
||
| 57 | $id = $input->getInt('id', '0'); |
||
| 58 | $this->setState('translation.id', $id); |
||
| 59 | |||
| 60 | // Get the layout |
||
| 61 | $layout = $input->getCmd('layout', 'edit'); |
||
| 62 | $this->setState('translation.layout', $layout); |
||
| 63 | |||
| 64 | // Get the parameters |
||
| 65 | $params = JComponentHelper::getParams('com_localise'); |
||
| 66 | |||
| 67 | // Get the reference tag |
||
| 68 | $ref = $params->get('reference', 'en-GB'); |
||
| 69 | $this->setState('translation.reference', $ref); |
||
| 70 | |||
| 71 | // Get the paths |
||
| 72 | $path = LocaliseHelper::getTranslationPath($client, $tag, $filename, $storage); |
||
| 73 | |||
| 74 | if ($filename == 'lib_joomla') |
||
| 75 | { |
||
| 76 | $refpath = LocaliseHelper::findTranslationPath('administrator', $ref, $filename); |
||
| 77 | |||
| 78 | if (!JFile::exists($path)) |
||
| 79 | { |
||
| 80 | $path2 = LocaliseHelper::getTranslationPath($client == 'administrator' ? 'site' : 'administrator', $tag, $filename, $storage); |
||
| 81 | |||
| 82 | if (JFile::exists($path2)) |
||
| 83 | { |
||
| 84 | $path = $path2; |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } |
||
| 88 | else |
||
| 89 | { |
||
| 90 | $refpath = LocaliseHelper::findTranslationPath($client, $ref, $filename); |
||
| 91 | } |
||
| 92 | |||
| 93 | $this->setState('translation.path', $path); |
||
| 94 | $this->setState('translation.refpath', $refpath); |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Returns a Table object, always creating it. |
||
| 99 | * |
||
| 100 | * @param type $type The table type to instantiate |
||
| 101 | * @param string $prefix A prefix for the table class name. Optional. |
||
| 102 | * @param array $config Configuration array for model. Optional. |
||
| 103 | * |
||
| 104 | * @return JTable A database object |
||
| 105 | */ |
||
| 106 | public function getTable($type = 'Localise', $prefix = 'LocaliseTable', $config = array()) |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Get contents |
||
| 113 | * |
||
| 114 | * @return string |
||
| 115 | */ |
||
| 116 | public function getContents() |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Get a translation |
||
| 137 | * |
||
| 138 | * @param integer $pk The id of the primary key (Note unused by the function). |
||
| 139 | * |
||
| 140 | * @return JObject|null Object on success, null on failure. |
||
| 141 | */ |
||
| 142 | public function getItem($pk = null) |
||
| 143 | { |
||
| 144 | if (!isset($this->item)) |
||
| 145 | { |
||
| 146 | $conf = JFactory::getConfig(); |
||
| 147 | $caching = $conf->get('caching') >= 1; |
||
| 148 | |||
| 149 | if ($caching) |
||
| 150 | { |
||
| 151 | $keycache = $this->getState('translation.client') . '.' . $this->getState('translation.tag') . '.' . |
||
| 152 | $this->getState('translation.filename') . '.' . 'translation'; |
||
| 153 | $cache = JFactory::getCache('com_localise', ''); |
||
| 154 | $this->item = $cache->get($keycache); |
||
| 155 | |||
| 156 | if ($this->item && $this->item->reference != $this->getState('translation.reference')) |
||
| 157 | { |
||
| 158 | $this->item = null; |
||
| 159 | } |
||
| 160 | } |
||
| 161 | else |
||
| 162 | { |
||
| 163 | $this->item = null; |
||
| 164 | } |
||
| 165 | |||
| 166 | if (!$this->item) |
||
| 167 | { |
||
| 168 | $path = JFile::exists($this->getState('translation.path')) |
||
| 169 | ? $this->getState('translation.path') |
||
| 170 | : $this->getState('translation.refpath'); |
||
| 171 | |||
| 172 | $params = JComponentHelper::getParams('com_localise'); |
||
| 173 | $allow_develop = $params->get('gh_allow_develop', 0); |
||
| 174 | $gh_client = $this->getState('translation.client'); |
||
| 175 | $tag = $this->getState('translation.tag'); |
||
| 176 | $reftag = $this->getState('translation.reference'); |
||
| 177 | $refpath = $this->getState('translation.refpath'); |
||
| 178 | $istranslation = 0; |
||
| 179 | |||
| 180 | if (!empty($tag) && $tag != $reftag) |
||
| 181 | { |
||
| 182 | $istranslation = 1; |
||
| 183 | } |
||
| 184 | |||
| 185 | $this->setState('translation.translatedkeys', array()); |
||
| 186 | $this->setState('translation.untranslatedkeys', array()); |
||
| 187 | $this->setState('translation.unchangedkeys', array()); |
||
| 188 | $this->setState('translation.textchangedkeys', array()); |
||
| 189 | $this->setState('translation.revisedchanges', array()); |
||
| 190 | $this->setState('translation.developdata', array()); |
||
| 191 | |||
| 192 | $translatedkeys = $this->getState('translation.translatedkeys'); |
||
| 193 | $untranslatedkeys = $this->getState('translation.untranslatedkeys'); |
||
| 194 | $unchangedkeys = $this->getState('translation.unchangedkeys'); |
||
| 195 | $textchangedkeys = $this->getState('translation.textchangedkeys'); |
||
| 196 | $revisedchanges = $this->getState('translation.revisedchanges'); |
||
| 197 | $developdata = $this->getState('translation.developdata'); |
||
| 198 | |||
| 199 | $this->item = new JObject( |
||
| 200 | array |
||
| 201 | ( |
||
| 202 | 'reference' => $this->getState('translation.reference'), |
||
| 203 | 'bom' => 'UTF-8', |
||
| 204 | 'svn' => '', |
||
| 205 | 'version' => '', |
||
| 206 | 'description' => '', |
||
| 207 | 'creationdate' => '', |
||
| 208 | 'author' => '', |
||
| 209 | 'maincopyright' => '', |
||
| 210 | 'additionalcopyright' => array(), |
||
| 211 | 'license' => '', |
||
| 212 | 'exists' => JFile::exists($this->getState('translation.path')), |
||
| 213 | 'istranslation' => $istranslation, |
||
| 214 | 'developdata' => (array) $developdata, |
||
| 215 | 'translatedkeys' => (array) $translatedkeys, |
||
| 216 | 'untranslatedkeys' => (array) $untranslatedkeys, |
||
| 217 | 'unchangedkeys' => (array) $unchangedkeys, |
||
| 218 | 'textchangedkeys' => (array) $textchangedkeys, |
||
| 219 | 'revisedchanges' => (array) $revisedchanges, |
||
| 220 | 'unrevised' => 0, |
||
| 221 | 'translatednews' => 0, |
||
| 222 | 'unchangednews' => 0, |
||
| 223 | 'translated' => 0, |
||
| 224 | 'untranslated' => 0, |
||
| 225 | 'unchanged' => 0, |
||
| 226 | 'extra' => 0, |
||
| 227 | 'total' => 0, |
||
| 228 | 'linespath' => 0, |
||
| 229 | 'linesrefpath' => 0, |
||
| 230 | 'linesdevpath' => 0, |
||
| 231 | 'linescustompath' => 0, |
||
| 232 | 'complete' => false, |
||
| 233 | 'source' => '', |
||
| 234 | 'error' => array() |
||
| 235 | ) |
||
| 236 | ); |
||
| 237 | |||
| 238 | if (JFile::exists($path)) |
||
| 239 | { |
||
| 240 | $devpath = LocaliseHelper::searchDevpath($gh_client, $refpath); |
||
| 241 | $custompath = LocaliseHelper::searchCustompath($gh_client, $refpath); |
||
| 242 | |||
| 243 | if ($istranslation == 0 && $reftag == 'en-GB') |
||
| 244 | { |
||
| 245 | if (!empty($devpath)) |
||
| 246 | { |
||
| 247 | if (!empty($custompath)) |
||
| 248 | { |
||
| 249 | $this->item->source = LocaliseHelper::combineReferences($custompath, $devpath); |
||
| 250 | } |
||
| 251 | else |
||
| 252 | { |
||
| 253 | $this->item->source = LocaliseHelper::combineReferences($path, $devpath); |
||
| 254 | } |
||
| 255 | } |
||
| 256 | } |
||
| 257 | else |
||
| 258 | { |
||
| 259 | $this->item->source = file_get_contents($path); |
||
| 260 | } |
||
| 261 | |||
| 262 | $stream = new JStream; |
||
| 263 | $stream->open($path); |
||
| 264 | $begin = $stream->read(4); |
||
| 265 | $bom = strtolower(bin2hex($begin)); |
||
| 266 | |||
| 267 | if ($bom == '0000feff') |
||
| 268 | { |
||
| 269 | $this->item->bom = 'UTF-32 BE'; |
||
| 270 | } |
||
| 271 | else |
||
| 272 | { |
||
| 273 | if ($bom == 'feff0000') |
||
| 274 | { |
||
| 275 | $this->item->bom = 'UTF-32 LE'; |
||
| 276 | } |
||
| 277 | else |
||
| 278 | { |
||
| 279 | if (substr($bom, 0, 4) == 'feff') |
||
| 280 | { |
||
| 281 | $this->item->bom = 'UTF-16 BE'; |
||
| 282 | } |
||
| 283 | else |
||
| 284 | { |
||
| 285 | if (substr($bom, 0, 4) == 'fffe') |
||
| 286 | { |
||
| 287 | $this->item->bom = 'UTF-16 LE'; |
||
| 288 | } |
||
| 289 | } |
||
| 290 | } |
||
| 291 | } |
||
| 292 | |||
| 293 | $stream->seek(0); |
||
| 294 | $continue = true; |
||
|
|
|||
| 295 | $lineNumber = 0; |
||
| 296 | |||
| 297 | $isTranslationsView = JFactory::getApplication()->input->get('view') == 'translations'; |
||
| 298 | |||
| 299 | while (!$stream->eof()) |
||
| 300 | { |
||
| 301 | $line = $stream->gets(); |
||
| 302 | $lineNumber++; |
||
| 303 | |||
| 304 | if ($line[0] == '#') |
||
| 305 | { |
||
| 306 | $this->item->error[] = $lineNumber; |
||
| 307 | } |
||
| 308 | elseif ($line[0] == ';') |
||
| 309 | { |
||
| 310 | if (preg_match('/^(;).*(\$Id.*\$)/', $line, $matches)) |
||
| 311 | { |
||
| 312 | $this->item->svn = $matches[2]; |
||
| 313 | } |
||
| 314 | elseif (preg_match('/(;)\s*@?(\pL+):?.*/', $line, $matches)) |
||
| 315 | { |
||
| 316 | switch (strtolower($matches[2])) |
||
| 317 | { |
||
| 318 | case 'note': |
||
| 319 | preg_match('/(;)\s*@?(\pL+):?\s+(.*)/', $line, $matches2); |
||
| 320 | $this->item->complete = $this->item->complete || strtolower($matches2[3]) == 'complete'; |
||
| 321 | break; |
||
| 322 | case 'version': |
||
| 323 | preg_match('/(;)\s*@?(\pL+):?\s+(.*)/', $line, $matches2); |
||
| 324 | $this->item->version = $matches2[3]; |
||
| 325 | break; |
||
| 326 | case 'desc': |
||
| 327 | case 'description': |
||
| 328 | preg_match('/(;)\s*@?(\pL+):?\s+(.*)/', $line, $matches2); |
||
| 329 | $this->item->description = $matches2[3]; |
||
| 330 | break; |
||
| 331 | case 'date': |
||
| 332 | preg_match('/(;)\s*@?(\pL+):?\s+(.*)/', $line, $matches2); |
||
| 333 | $this->item->creationdate = $matches2[3]; |
||
| 334 | break; |
||
| 335 | View Code Duplication | case 'author': |
|
| 336 | if ($params->get('author') && !$isTranslationsView) |
||
| 337 | { |
||
| 338 | $this->item->author = $params->get('author'); |
||
| 339 | } |
||
| 340 | else |
||
| 341 | { |
||
| 342 | preg_match('/(;)\s*@?(\pL+):?\s+(.*)/', $line, $matches2); |
||
| 343 | $this->item->author = $matches2[3]; |
||
| 344 | } |
||
| 345 | break; |
||
| 346 | case 'copyright': |
||
| 347 | preg_match('/(;)\s*@?(\pL+):?\s+(.*)/', $line, $matches2); |
||
| 348 | |||
| 349 | if (empty($this->item->maincopyright)) |
||
| 350 | { |
||
| 351 | if ($params->get('copyright') && !$isTranslationsView) |
||
| 352 | { |
||
| 353 | $this->item->maincopyright = $params->get('copyright'); |
||
| 354 | } |
||
| 355 | else |
||
| 356 | { |
||
| 357 | $this->item->maincopyright = $matches2[3]; |
||
| 358 | } |
||
| 359 | } |
||
| 360 | |||
| 361 | if (empty($this->item->additionalcopyright)) |
||
| 362 | { |
||
| 363 | if ($params->get('additionalcopyright') && !$isTranslationsView) |
||
| 364 | { |
||
| 365 | $this->item->additionalcopyright[] = $params->get('additionalcopyright'); |
||
| 366 | } |
||
| 367 | else |
||
| 368 | { |
||
| 369 | $this->item->additionalcopyright[] = $matches2[3]; |
||
| 370 | } |
||
| 371 | } |
||
| 372 | break; |
||
| 373 | View Code Duplication | case 'license': |
|
| 374 | if ($params->get('license') && !$isTranslationsView) |
||
| 375 | { |
||
| 376 | $this->item->license = $params->get('license'); |
||
| 377 | } |
||
| 378 | else |
||
| 379 | { |
||
| 380 | preg_match('/(;)\s*@?(\pL+):?\s+(.*)/', $line, $matches2); |
||
| 381 | $this->item->license = $matches2[3]; |
||
| 382 | } |
||
| 383 | break; |
||
| 384 | case 'package': |
||
| 385 | preg_match('/(;)\s*@?(\pL+):?\s+(.*)/', $line, $matches2); |
||
| 386 | $this->item->package = $matches2[3]; |
||
| 387 | break; |
||
| 388 | case 'subpackage': |
||
| 389 | preg_match('/(;)\s*@?(\pL+):?\s+(.*)/', $line, $matches2); |
||
| 390 | $this->item->subpackage = $matches2[3]; |
||
| 391 | break; |
||
| 392 | case 'link': |
||
| 393 | break; |
||
| 394 | View Code Duplication | default: |
|
| 395 | if (empty($this->item->author)) |
||
| 396 | { |
||
| 397 | if ($params->get('author') && !$isTranslationsView) |
||
| 398 | { |
||
| 399 | $this->item->author = $params->get('author'); |
||
| 400 | } |
||
| 401 | else |
||
| 402 | { |
||
| 403 | preg_match('/(;)\s*(.*)/', $line, $matches2); |
||
| 404 | $this->item->author = $matches2[2]; |
||
| 405 | } |
||
| 406 | } |
||
| 407 | break; |
||
| 408 | } |
||
| 409 | } |
||
| 410 | } |
||
| 411 | else |
||
| 412 | { |
||
| 413 | break; |
||
| 414 | } |
||
| 415 | } |
||
| 416 | |||
| 417 | if (empty($this->item->author) && $params->get('author') && !$isTranslationsView) |
||
| 418 | { |
||
| 419 | $this->item->author = $params->get('author'); |
||
| 420 | } |
||
| 421 | |||
| 422 | if (empty($this->item->license) && $params->get('license') && !$isTranslationsView) |
||
| 423 | { |
||
| 424 | $this->item->license = $params->get('license'); |
||
| 425 | } |
||
| 426 | |||
| 427 | if (empty($this->item->maincopyright) && $params->get('copyright') && !$isTranslationsView) |
||
| 428 | { |
||
| 429 | $this->item->maincopyright = $params->get('copyright'); |
||
| 430 | } |
||
| 431 | |||
| 432 | if (empty($this->item->additionalcopyright) && $params->get('additionalcopyright') && !$isTranslationsView) |
||
| 433 | { |
||
| 434 | $this->item->additionalcopyright[] = $params->get('additionalcopyright'); |
||
| 435 | } |
||
| 436 | |||
| 437 | while (!$stream->eof()) |
||
| 438 | { |
||
| 439 | $line = $stream->gets(); |
||
| 440 | $lineNumber++; |
||
| 441 | |||
| 442 | if (!preg_match('/^(|(\[[^\]]*\])|([A-Z][A-Z0-9_\*\-\.]*\s*=(\s*(("[^"]*")|(_QQ_)))+))\s*(;.*)?$/', $line)) |
||
| 443 | { |
||
| 444 | $this->item->error[] = $lineNumber; |
||
| 445 | } |
||
| 446 | } |
||
| 447 | |||
| 448 | if ($tag != $reftag) |
||
| 449 | { |
||
| 450 | if (JFile::exists($custompath)) |
||
| 451 | { |
||
| 452 | $this->item->linescustompath = count(file($custompath)); |
||
| 453 | } |
||
| 454 | } |
||
| 455 | |||
| 456 | $stream->close(); |
||
| 457 | } |
||
| 458 | |||
| 459 | $this->item->additionalcopyright = implode("\n", $this->item->additionalcopyright); |
||
| 460 | |||
| 461 | if ($this->getState('translation.layout') != 'raw' && empty($this->item->error)) |
||
| 462 | { |
||
| 463 | $sections = LocaliseHelper::parseSections($this->getState('translation.path')); |
||
| 464 | |||
| 465 | if (!empty($custompath)) |
||
| 466 | { |
||
| 467 | $refsections = LocaliseHelper::parseSections($custompath); |
||
| 468 | } |
||
| 469 | else |
||
| 470 | { |
||
| 471 | $refsections = LocaliseHelper::parseSections($this->getState('translation.refpath')); |
||
| 472 | } |
||
| 473 | |||
| 474 | $develop_client_path = JPATH_ROOT |
||
| 475 | . '/media/com_localise/develop/github/joomla-cms/en-GB/' |
||
| 476 | . $gh_client; |
||
| 477 | $develop_client_path = JFolder::makeSafe($develop_client_path); |
||
| 478 | $ref_file = basename($this->getState('translation.refpath')); |
||
| 479 | $develop_file_path = "$develop_client_path/$ref_file"; |
||
| 480 | $new_keys = array(); |
||
| 481 | |||
| 482 | if (JFile::exists($develop_file_path) && $allow_develop == 1 && $reftag == 'en-GB') |
||
| 483 | { |
||
| 484 | $info = array(); |
||
| 485 | $info['client'] = $gh_client; |
||
| 486 | $info['reftag'] = 'en-GB'; |
||
| 487 | $info['tag'] = 'en-GB'; |
||
| 488 | $info['filename'] = $ref_file; |
||
| 489 | $info['istranslation'] = $istranslation; |
||
| 490 | |||
| 491 | $develop_sections = LocaliseHelper::parseSections($develop_file_path); |
||
| 492 | $developdata = LocaliseHelper::getDevelopchanges($info, $refsections, $develop_sections); |
||
| 493 | $developdata['develop_file_path'] = ''; |
||
| 494 | |||
| 495 | if ($developdata['extra_keys']['amount'] > 0 || $developdata['text_changes']['amount'] > 0) |
||
| 496 | { |
||
| 497 | if ($developdata['extra_keys']['amount'] > 0) |
||
| 498 | { |
||
| 499 | $new_keys = $developdata['extra_keys']['keys']; |
||
| 500 | } |
||
| 501 | |||
| 502 | if ($developdata['text_changes']['amount'] > 0) |
||
| 503 | { |
||
| 504 | $textchangedkeys = $developdata['text_changes']['keys']; |
||
| 505 | $this->item->textchangedkeys = $textchangedkeys; |
||
| 506 | $this->setState('translation.textchangedkeys', $textchangedkeys); |
||
| 507 | |||
| 508 | $changesdata['client'] = $gh_client; |
||
| 509 | $changesdata['reftag'] = $reftag; |
||
| 510 | |||
| 511 | if ($istranslation == 0) |
||
| 512 | { |
||
| 513 | $changesdata['tag'] = $reftag; |
||
| 514 | } |
||
| 515 | else |
||
| 516 | { |
||
| 517 | $changesdata['tag'] = $tag; |
||
| 518 | } |
||
| 519 | |||
| 520 | $changesdata['filename'] = $ref_file; |
||
| 521 | |||
| 522 | foreach ($textchangedkeys as $key_changed) |
||
| 523 | { |
||
| 524 | $target_text = $developdata['text_changes']['ref_in_dev'][$key_changed]; |
||
| 525 | $source_text = $developdata['text_changes']['ref'][$key_changed]; |
||
| 526 | |||
| 527 | $changesdata['revised'] = '0'; |
||
| 528 | $changesdata['key'] = $key_changed; |
||
| 529 | $changesdata['target_text'] = $target_text; |
||
| 530 | $changesdata['source_text'] = $source_text; |
||
| 531 | $changesdata['istranslation'] = $istranslation; |
||
| 532 | $changesdata['catch_grammar'] = '0'; |
||
| 533 | |||
| 534 | $change_status = LocaliseHelper::searchRevisedvalue($changesdata); |
||
| 535 | $revisedchanges[$key_changed] = $change_status; |
||
| 536 | |||
| 537 | if ($change_status == 1) |
||
| 538 | { |
||
| 539 | $developdata['text_changes']['revised']++; |
||
| 540 | } |
||
| 541 | else |
||
| 542 | { |
||
| 543 | $developdata['text_changes']['unrevised']++; |
||
| 544 | } |
||
| 545 | } |
||
| 546 | |||
| 547 | $this->item->revisedchanges = $revisedchanges; |
||
| 548 | $this->setState('translation.revisedchanges', $revisedchanges); |
||
| 549 | } |
||
| 550 | |||
| 551 | // When develop changes are present, replace the reference keys |
||
| 552 | $refsections = $develop_sections; |
||
| 553 | |||
| 554 | // And store the path for future calls |
||
| 555 | $developdata['develop_file_path'] = $develop_file_path; |
||
| 556 | } |
||
| 557 | } |
||
| 558 | |||
| 559 | if (!empty($refsections['keys'])) |
||
| 560 | { |
||
| 561 | foreach ($refsections['keys'] as $key => $string) |
||
| 562 | { |
||
| 563 | $this->item->total++; |
||
| 564 | |||
| 565 | if (!empty($sections['keys']) && array_key_exists($key, $sections['keys']) && $sections['keys'][$key] != '') |
||
| 566 | { |
||
| 567 | if ($sections['keys'][$key] != $string && $istranslation == 1) |
||
| 568 | { |
||
| 569 | if (array_key_exists($key, $revisedchanges) && $revisedchanges[$key] == 0) |
||
| 570 | { |
||
| 571 | $this->item->unrevised++; |
||
| 572 | $translatedkeys[] = $key; |
||
| 573 | } |
||
| 574 | elseif (in_array($key, $new_keys)) |
||
| 575 | { |
||
| 576 | $this->item->translatednews++; |
||
| 577 | $translatedkeys[] = $key; |
||
| 578 | } |
||
| 579 | else |
||
| 580 | { |
||
| 581 | $this->item->translated++; |
||
| 582 | $translatedkeys[] = $key; |
||
| 583 | } |
||
| 584 | } |
||
| 585 | elseif ($istranslation == 0) |
||
| 586 | { |
||
| 587 | if (array_key_exists($key, $revisedchanges) && $revisedchanges[$key] == 0) |
||
| 588 | { |
||
| 589 | $this->item->unrevised++; |
||
| 590 | } |
||
| 591 | elseif (in_array($key, $new_keys)) |
||
| 592 | { |
||
| 593 | $untranslatedkeys[] = $key; |
||
| 594 | } |
||
| 595 | |||
| 596 | $this->item->translated++; |
||
| 597 | } |
||
| 598 | else |
||
| 599 | { |
||
| 600 | if (in_array($key, $new_keys)) |
||
| 601 | { |
||
| 602 | $this->item->unchangednews++; |
||
| 603 | } |
||
| 604 | else |
||
| 605 | { |
||
| 606 | $this->item->unchanged++; |
||
| 607 | } |
||
| 608 | |||
| 609 | $unchangedkeys[] = $key; |
||
| 610 | } |
||
| 611 | } |
||
| 612 | elseif (!array_key_exists($key, $sections['keys'])) |
||
| 613 | { |
||
| 614 | $this->item->untranslated++; |
||
| 615 | $untranslatedkeys[] = $key; |
||
| 616 | } |
||
| 617 | } |
||
| 618 | } |
||
| 619 | |||
| 620 | $this->item->translatedkeys = $translatedkeys; |
||
| 621 | $this->item->untranslatedkeys = $untranslatedkeys; |
||
| 622 | $this->item->unchangedkeys = $unchangedkeys; |
||
| 623 | $this->item->developdata = $developdata; |
||
| 624 | |||
| 625 | $this->setState('translation.translatedkeys', $translatedkeys); |
||
| 626 | $this->setState('translation.untranslatedkeys', $untranslatedkeys); |
||
| 627 | $this->setState('translation.unchangedkeys', $unchangedkeys); |
||
| 628 | $this->setState('translation.developdata', $developdata); |
||
| 629 | |||
| 630 | if (!empty($sections['keys']) && $istranslation == 1) |
||
| 631 | { |
||
| 632 | foreach ($sections['keys'] as $key => $string) |
||
| 633 | { |
||
| 634 | if (empty($refsections['keys']) || !array_key_exists($key, $refsections['keys'])) |
||
| 635 | { |
||
| 636 | $this->item->extra++; |
||
| 637 | } |
||
| 638 | } |
||
| 639 | } |
||
| 640 | |||
| 641 | $done = $this->item->translated + $this->item->translatednews + $this->item->unchangednews; |
||
| 642 | |||
| 643 | $this->item->completed = $this->item->total |
||
| 644 | ? intval(100 * $done / $this->item->total) |
||
| 645 | : 100; |
||
| 646 | |||
| 647 | $this->item->complete = $this->item->complete == 1 && $this->item->untranslated == 0 && $this->item->unrevised == 0 |
||
| 648 | ? 1 |
||
| 649 | : ($this->item->completed == 100 |
||
| 650 | ? 1 |
||
| 651 | : 0); |
||
| 652 | } |
||
| 653 | |||
| 654 | if ($this->getState('translation.id')) |
||
| 655 | { |
||
| 656 | $table = $this->getTable(); |
||
| 657 | $table->load($this->getState('translation.id')); |
||
| 658 | $user = JFactory::getUser($table->checked_out); |
||
| 659 | $this->item->setProperties($table->getProperties()); |
||
| 660 | |||
| 661 | if ($this->item->checked_out == JFactory::getUser()->id) |
||
| 662 | { |
||
| 663 | $this->item->checked_out = 0; |
||
| 664 | } |
||
| 665 | |||
| 666 | $this->item->editor = JText::sprintf('COM_LOCALISE_TEXT_TRANSLATION_EDITOR', $user->name, $user->username); |
||
| 667 | } |
||
| 668 | |||
| 669 | if ($caching) |
||
| 670 | { |
||
| 671 | $cache->store($this->item, $keycache); |
||
| 672 | } |
||
| 673 | |||
| 674 | // Count the number of lines in the ini file to check max_input_vars |
||
| 675 | if ($tag != $reftag) |
||
| 676 | { |
||
| 677 | if (JFile::exists($path)) |
||
| 678 | { |
||
| 679 | $this->item->linespath = count(file($path)); |
||
| 680 | } |
||
| 681 | |||
| 682 | if (JFile::exists($refpath)) |
||
| 683 | { |
||
| 684 | $this->item->linesrefpath = count(file($refpath)); |
||
| 685 | } |
||
| 686 | |||
| 687 | if (JFile::exists($develop_file_path)) |
||
| 688 | { |
||
| 689 | $this->item->linesdevpath = count(file($develop_file_path)); |
||
| 690 | } |
||
| 691 | } |
||
| 692 | else |
||
| 693 | { |
||
| 694 | if (JFile::exists($path)) |
||
| 695 | { |
||
| 696 | $this->item->linespath = count(file($path)); |
||
| 697 | } |
||
| 698 | } |
||
| 699 | } |
||
| 700 | } |
||
| 701 | |||
| 702 | return $this->item; |
||
| 703 | } |
||
| 704 | |||
| 705 | /** |
||
| 706 | * Method to get the record form. |
||
| 707 | * |
||
| 708 | * @param array $data Data for the form. |
||
| 709 | * @param boolean $loadData True if the form is to load its own data (default case), false if not. |
||
| 710 | * |
||
| 711 | * @return mixed A JForm object on success, false on failure |
||
| 712 | */ |
||
| 713 | public function getForm($data = array(), $loadData = true) |
||
| 743 | |||
| 744 | /** |
||
| 745 | * Method to get the data that should be injected in the form. |
||
| 746 | * |
||
| 747 | * @return array The default data is an empty array. |
||
| 748 | */ |
||
| 749 | protected function loadFormData() |
||
| 753 | |||
| 754 | /** |
||
| 755 | * Method to get the ftp form. |
||
| 756 | * |
||
| 757 | * @return mixed A JForm object on success, false on failure or not ftp |
||
| 758 | */ |
||
| 759 | View Code Duplication | public function getFormFtp() |
|
| 779 | |||
| 780 | /** |
||
| 781 | * Method to allow derived classes to preprocess the form. |
||
| 782 | * |
||
| 783 | * @param JForm $form A form object. |
||
| 784 | * @param mixed $item The data expected for the form. |
||
| 785 | * @param string $group The name of the plugin group to import (defaults to "content"). |
||
| 786 | * |
||
| 787 | * @throws Exception if there is an error in the form event. |
||
| 788 | * @return JForm |
||
| 789 | */ |
||
| 790 | protected function preprocessForm(JForm $form, $item, $group = 'content') |
||
| 1133 | |||
| 1134 | /** |
||
| 1135 | * Save a file |
||
| 1136 | * |
||
| 1137 | * @param array $data Array that represents a file |
||
| 1138 | * |
||
| 1139 | * @return bool |
||
| 1140 | */ |
||
| 1141 | public function saveFile($data) |
||
| 1449 | |||
| 1450 | /** |
||
| 1451 | * Saves a translation |
||
| 1452 | * |
||
| 1453 | * @param array $data translation to be saved |
||
| 1454 | * |
||
| 1455 | * @return bool |
||
| 1456 | */ |
||
| 1457 | public function save($data) |
||
| 1560 | } |
||
| 1561 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.