Пример #1
0
 /**
  * Internal function to import phrase XML. This does not remove any phrases
  * that may conflict; that is the responsibility of the caller.
  *
  * @param SimpleXMLElement $xml Root XML node; must have "phrase" children
  * @param integer $languageId Target language ID
  * @param string|null $addOnId Add-on the phrases belong to; if null, read from xml
  * @param array $existingPhrases Existing phrases; used to detect and resolve conflicts
  * @param integer $maxExecution Maximum run time in seconds
  * @param integer $offset Number of elements to skip
  */
 public function importPhrasesXml(SimpleXMLElement $xml, $languageId, $addOnId = null, array $existingPhrases = array(), $maxExecution = 0, $offset = 0)
 {
     $startTime = microtime(true);
     $phrases = XenForo_Helper_DevelopmentXml::fixPhpBug50670($xml->phrase);
     $current = 0;
     $restartOffset = false;
     foreach ($phrases as $phrase) {
         $current++;
         if ($current <= $offset) {
             continue;
         }
         $title = (string) $phrase['title'];
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_Phrase');
         if (isset($existingPhrases[$title])) {
             if ($languageId == 0 && $existingPhrases[$title]['addon_id'] == 'XenForo' && $addOnId != 'XenForo') {
                 // trying to overwrite a built in phrase - don't let it
                 continue;
             }
             $dw->setExistingData($existingPhrases[$title], true);
         }
         $dw->setOption(XenForo_DataWriter_Phrase::OPTION_DEV_OUTPUT_DIR, '');
         $dw->setOption(XenForo_DataWriter_Phrase::OPTION_REBUILD_LANGUAGE_CACHE, false);
         $dw->setOption(XenForo_DataWriter_Phrase::OPTION_FULL_RECOMPILE, false);
         $dw->setOption(XenForo_DataWriter_Phrase::OPTION_REBUILD_PHRASE_MAP, false);
         $dw->setOption(XenForo_DataWriter_Phrase::OPTION_CHECK_DUPLICATE, false);
         $dw->bulkSet(array('title' => $title, 'phrase_text' => (string) $phrase, 'global_cache' => (int) $phrase['global_cache'], 'version_id' => (int) $phrase['version_id'], 'version_string' => (string) $phrase['version_string'], 'language_id' => $languageId, 'addon_id' => $addOnId === null ? (string) $phrase['addon_id'] : $addOnId));
         $dw->save();
         if ($maxExecution && microtime(true) - $startTime > $maxExecution) {
             $restartOffset = $current;
             break;
         }
     }
     XenForo_Template_Compiler::resetPhraseCache();
     if (!$restartOffset) {
         $this->_getLanguageModel()->rebuildLanguageCaches();
     }
     return $restartOffset ? $restartOffset : true;
 }
Пример #2
0
 /**
  * Recompiles all templates (admin and public) that include this phrase.
  */
 protected function _recompileTemplatesIncludingPhrase()
 {
     XenForo_Template_Compiler::resetPhraseCache();
     $templateModel = $this->_getTemplateModel();
     $adminTemplateModel = $this->_getAdminTemplateModel();
     $emailTemplateModel = $this->_getEmailTemplateModel();
     $title = $this->get('title');
     $templateModel->compileTemplatesThatIncludePhrase($title);
     $adminTemplateModel->compileAdminTemplatesThatIncludePhrase($title);
     $emailTemplateModel->compileEmailTemplatesThatIncludePhrase($title);
     if ($this->isChanged('title') && $this->isUpdate()) {
         $existingTitle = $this->getExisting('title');
         $templateModel->compileTemplatesThatIncludePhrase($existingTitle);
         $adminTemplateModel->compileAdminTemplatesThatIncludePhrase($existingTitle);
         $emailTemplateModel->compileEmailTemplatesThatIncludePhrase($existingTitle);
     }
 }