예제 #1
0
 protected function updateFiles()
 {
     if (isset($this->newFiles['static']) && ComponentbuilderHelper::checkArray($this->newFiles['static']) && isset($this->newFiles['dynamic']) && ComponentbuilderHelper::checkArray($this->newFiles['dynamic'])) {
         // get the bom file
         $bom = JFile::read($this->bomPath);
         // first we do the static files
         foreach ($this->newFiles['static'] as $static) {
             if (JFile::exists($static['path'])) {
                 $this->fileContentStatic['###FILENAME###'] = $static['name'];
                 $php = '';
                 if (ComponentbuilderHelper::checkFileType($static['name'], 'php')) {
                     $php = "<?php\n";
                 }
                 $string = JFile::read($static['path']);
                 if (strpos($string, '###BOM###') !== false) {
                     list($wast, $code) = explode('###BOM###', $string);
                     $answer = str_replace(array_keys($this->fileContentStatic), array_values($this->fileContentStatic), $php . $bom . $code);
                     // add to zip array
                     $this->writeFile($static['path'], $answer);
                 } else {
                     $answer = str_replace(array_keys($this->fileContentStatic), array_values($this->fileContentStatic), $string);
                     // add to zip array
                     $this->writeFile($static['path'], $answer);
                 }
                 $this->lineCount = $this->lineCount + substr_count($answer, PHP_EOL);
             }
         }
         // now we do the dynamic files
         foreach ($this->newFiles['dynamic'] as $view => $files) {
             if (isset($this->fileContentDynamic[$view]) && ComponentbuilderHelper::checkArray($this->fileContentDynamic[$view])) {
                 foreach ($files as $file) {
                     if ($file['view'] == $view) {
                         if (JFile::exists($file['path'])) {
                             $this->fileContentStatic['###FILENAME###'] = $file['name'];
                             $php = '';
                             if (ComponentbuilderHelper::checkFileType($file['name'], 'php')) {
                                 $php = "<?php\n";
                             }
                             $string = JFile::read($file['path']);
                             if (strpos($string, '###BOM###') !== false) {
                                 list($bin, $code) = explode('###BOM###', $string);
                                 $answer = str_replace(array_keys($this->fileContentStatic), array_values($this->fileContentStatic), $php . $bom . $code);
                                 $answer = str_replace(array_keys($this->fileContentDynamic[$view]), array_values($this->fileContentDynamic[$view]), $answer);
                                 // add to zip array
                                 $this->writeFile($file['path'], $answer);
                             } else {
                                 $answer = str_replace(array_keys($this->fileContentStatic), array_values($this->fileContentStatic), $string);
                                 $answer = str_replace(array_keys($this->fileContentDynamic[$view]), array_values($this->fileContentDynamic[$view]), $answer);
                                 // add to zip array
                                 $this->writeFile($file['path'], $answer);
                             }
                             $this->lineCount = $this->lineCount + substr_count($answer, PHP_EOL);
                         }
                     }
                 }
             }
         }
         // do a final run to update the readme file
         $two = 0;
         foreach ($this->newFiles['static'] as $static) {
             if (('README.md' == $static['name'] || 'README.txt' == $static['name']) && $this->componentData->addreadme && JFile::exists($static['path'])) {
                 $this->buildReadMe($static['path']);
                 $two++;
             }
             if ($two == 2) {
                 break;
             }
         }
         // move the update server to host
         if ($this->componentData->add_update_server && isset($this->updateServerFileName) && $this->add2SalesServer) {
             $xml_update_server_path = $this->componentPath . '/' . $this->updateServerFileName . '.xml';
             // make sure we have the correct file
             if (JFile::exists($xml_update_server_path) && isset($this->componentData->update_server_ftp)) {
                 // Get the basic encription.
                 $basickey = ComponentbuilderHelper::getCryptKey('basic');
                 // Get the encription object.
                 $basic = new FOFEncryptAes($basickey, 128);
                 if (!empty($this->componentData->update_server_ftp) && $basickey && !is_numeric($this->componentData->update_server_ftp) && $this->componentData->update_server_ftp === base64_encode(base64_decode($this->componentData->update_server_ftp, true))) {
                     // basic decript data update_server_ftp.
                     $this->componentData->update_server_ftp = rtrim($basic->decryptString($this->componentData->update_server_ftp), "");
                 }
                 // now move the file
                 $this->moveFileToFtpServer($xml_update_server_path, $this->componentData->update_server_ftp);
             }
         }
         return true;
     }
     return false;
 }