예제 #1
0
 /**
  * Imports all templates from the templates directory into the database
  */
 public function importTemplatesFromDevelopment()
 {
     $db = $this->_getDb();
     $templateDir = $this->getTemplateDevelopmentDirectory();
     if (!$templateDir && !is_dir($templateDir)) {
         throw new XenForo_Exception("Template development directory not enabled or doesn't exist");
     }
     $files = glob("{$templateDir}/*.html");
     if (!$files) {
         throw new XenForo_Exception("Template development directory does not have any templates");
     }
     $metaData = XenForo_Helper_DevelopmentXml::readMetaDataFile($templateDir . '/_metadata.xml');
     $addOnTemplates = $this->getMasterTemplatesInAddOn('XenForo');
     XenForo_Db::beginTransaction($db);
     $titles = array();
     foreach ($files as $templateFile) {
         $filename = basename($templateFile);
         if (preg_match('/^(.+)\\.html$/', $filename, $match)) {
             $titles[] = $match[1];
         }
     }
     $existingTemplates = $this->getTemplatesInStyleByTitles($titles, 0);
     foreach ($files as $templateFile) {
         if (!is_readable($templateFile)) {
             throw new XenForo_Exception("Template file '{$templateFile}' not readable");
         }
         $filename = basename($templateFile);
         if (preg_match('/^(.+)\\.html$/', $filename, $match)) {
             $templateName = $match[1];
             $data = file_get_contents($templateFile);
             $dw = XenForo_DataWriter::create('XenForo_DataWriter_Template');
             if (isset($existingTemplates[$templateName])) {
                 $dw->setExistingData($existingTemplates[$templateName], true);
             }
             $dw->setOption(XenForo_DataWriter_Template::OPTION_DEV_OUTPUT_DIR, '');
             $dw->setOption(XenForo_DataWriter_Template::OPTION_FULL_COMPILE, false);
             $dw->setOption(XenForo_DataWriter_Template::OPTION_TEST_COMPILE, false);
             $dw->setOption(XenForo_DataWriter_Template::OPTION_CHECK_DUPLICATE, false);
             $dw->setOption(XenForo_DataWriter_Template::OPTION_REBUILD_TEMPLATE_MAP, false);
             $dw->bulkSet(array('style_id' => 0, 'title' => $templateName, 'template' => $data, 'addon_id' => 'XenForo', 'version_id' => 0, 'version_string' => ''));
             if (isset($metaData[$templateName])) {
                 $dw->bulkSet($metaData[$templateName]);
             }
             $dw->save();
             unset($addOnTemplates[$templateName]);
         }
     }
     // removed templates
     foreach ($addOnTemplates as $addOnTemplate) {
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_Template');
         $dw->setExistingData($addOnTemplate, true);
         $dw->setOption(XenForo_DataWriter_Template::OPTION_DEV_OUTPUT_DIR, '');
         $dw->setOption(XenForo_DataWriter_Template::OPTION_FULL_COMPILE, false);
         $dw->setOption(XenForo_DataWriter_Template::OPTION_TEST_COMPILE, false);
         $dw->setOption(XenForo_DataWriter_Template::OPTION_CHECK_DUPLICATE, false);
         $dw->setOption(XenForo_DataWriter_Template::OPTION_REBUILD_TEMPLATE_MAP, false);
         $dw->delete();
     }
     XenForo_Db::commit($db);
 }
예제 #2
0
파일: Phrase.php 프로젝트: Sywooch/forums
 /**
  * Imports all phrases from the phrases directory into the database
  */
 public function importPhrasesFromDevelopment()
 {
     $db = $this->_getDb();
     $phraseDir = $this->getPhraseDevelopmentDirectory();
     if (!$phraseDir && !is_dir($phraseDir)) {
         throw new XenForo_Exception("Phrase development directory not enabled or doesn't exist");
     }
     $files = glob("{$phraseDir}/*.txt");
     if (!$files) {
         throw new XenForo_Exception("Phrase development directory does not have any phrases");
     }
     $metaData = XenForo_Helper_DevelopmentXml::readMetaDataFile($phraseDir . '/_metadata.xml');
     XenForo_Db::beginTransaction($db);
     $this->deletePhrasesForAddOn('XenForo');
     $titles = array();
     foreach ($files as $templateFile) {
         $filename = basename($templateFile);
         if (preg_match('/^(.+)\\.txt$/', $filename, $match)) {
             $titles[] = $match[1];
         }
     }
     $existingPhrases = $this->getPhrasesInLanguageByTitles($titles, 0);
     foreach ($files as $file) {
         if (!is_readable($file)) {
             throw new XenForo_Exception("Phrase file '{$file}' not readable");
         }
         $filename = basename($file);
         if (preg_match('/^(.+)\\.txt$/', $filename, $match)) {
             $title = $match[1];
             $dw = XenForo_DataWriter::create('XenForo_DataWriter_Phrase');
             if (isset($existingPhrases[$title])) {
                 $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' => file_get_contents($file), 'language_id' => 0, 'addon_id' => 'XenForo', 'version_id' => 0, 'version_string' => ''));
             if (isset($metaData[$title])) {
                 $dw->bulkSet($metaData[$title]);
             }
             $dw->save();
             unset($dw);
         }
     }
     XenForo_Db::commit($db);
 }