Ejemplo n.º 1
0
 public static function getInstance()
 {
     if (!self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Ejemplo n.º 2
0
 protected function _loadTemplateFilePath($templateName)
 {
     if ($this->_usingTemplateFiles() and preg_match('#^__(?<name>.+)_(?<style>\\d+)_(?<language>\\d+)$#', $templateName, $matches)) {
         return XenForo_Template_FileHandler::get($matches['name'], $matches['style'], $matches['language']);
     } else {
         return '';
     }
 }
Ejemplo n.º 3
0
 protected function _loadTemplateFilePath($templateName)
 {
     if ($this->_usingTemplateFiles() and preg_match('#^__(.+)_(\\d+)$#', $templateName, $matches)) {
         $templateName = $matches[1];
         $styleId = XenForo_Application::getOptions()->get('defaultStyleId');
         $languageId = $matches[2];
         return XenForo_Template_FileHandler::get($templateName, $styleId, $languageId);
     } else {
         return '';
     }
 }
Ejemplo n.º 4
0
 /**
  * Deletes the file versions of all templates
  */
 public function deleteTemplateFiles()
 {
     XenForo_Template_FileHandler::delete(null, null, null);
 }
Ejemplo n.º 5
0
 /**
  * Deletes mapped data (template map entries, includes, compiled info) and determines
  * what templates (if any need to be recompiled). A deletion can be a "revert" or it
  * can actually remove a template from the hierarchy.
  *
  * @return boolean|array If true, recompile this template and includes; if array, recompile specified map IDs; else, no recompile
  */
 protected function _deleteMappedData()
 {
     $templateModel = $this->_getTemplateModel();
     $mappedTemplates = $templateModel->getMappedTemplatesByTemplateId($this->get('template_id'));
     if ($mappedTemplates) {
         $myTemplateMapId = 0;
         $templateMapIds = array();
         $styleIds = array();
         foreach ($mappedTemplates as $mappedTemplate) {
             if ($mappedTemplate['style_id'] == $this->get('style_id')) {
                 $myTemplateMapId = $mappedTemplate['template_map_id'];
             }
             $templateMapIds[] = $mappedTemplate['template_map_id'];
             $styleIds[] = $mappedTemplate['style_id'];
         }
         $templateMapIdsQuoted = $this->_db->quote($templateMapIds);
         $parentMappedTemplate = $templateModel->getParentMappedTemplateByTitle($this->get('title'), $this->get('style_id'));
         if ($parentMappedTemplate) {
             // point everything pointing at this template to the parent
             $this->_db->update('xf_template_map', array('template_id' => $parentMappedTemplate['template_id']), 'template_map_id IN (' . $templateMapIdsQuoted . ')');
             // template_include and template_compiled will be updated on a recompile
             return true;
         } else {
             // no parent, remove template - this should primarily happen when deleting a master or custom template
             $this->_db->delete('xf_template_map', 'template_map_id IN (' . $templateMapIdsQuoted . ')');
             $this->_db->delete('xf_template_phrase', 'template_map_id IN (' . $templateMapIdsQuoted . ')');
             $this->_db->delete('xf_template_include', 'source_map_id IN (' . $templateMapIdsQuoted . ')');
             $this->_db->delete('xf_template_compiled', 'style_id IN (' . $this->_db->quote($styleIds) . ') AND title = ' . $this->_db->quote($this->get('title')));
             if (XenForo_Application::get('options')->templateFiles) {
                 XenForo_Template_FileHandler::delete($this->get('title'), $styleIds, null);
             }
             if ($myTemplateMapId) {
                 // need to recompile includes
                 return $templateModel->getIncludingTemplateMapIds($myTemplateMapId);
             }
         }
     }
     return false;
 }
Ejemplo n.º 6
0
 /**
  * Internal post-delete handler.
  */
 protected function _postDelete()
 {
     $languageId = $this->get('language_id');
     $db = $this->_db;
     $languageModel = $this->_getLanguageModel();
     $phraseModel = $this->_getPhraseModel();
     $directChildren = $languageModel->getDirectChildLanguageIds($languageId);
     if ($directChildren) {
         // re-parent child styles
         $db->update('xf_language', array('parent_id' => $this->get('parent_id')), 'parent_id = ' . $db->quote($languageId));
         $languageModel->resetLocalCacheData('allLanguages');
         foreach ($directChildren as $childLanguageId) {
             $languageModel->rebuildLanguageParentListRecursive($childLanguageId);
         }
     }
     $db->delete('xf_phrase', 'language_id = ' . $db->quote($languageId));
     $db->delete('xf_phrase_map', 'language_id = ' . $db->quote($languageId));
     $db->delete('xf_phrase_compiled', 'language_id = ' . $db->quote($languageId));
     $db->delete('xf_template_compiled', 'language_id = ' . $db->quote($languageId));
     if (XenForo_Application::get('options')->templateFiles) {
         XenForo_Template_FileHandler::delete(null, null, $languageId);
     }
     $db->delete('xf_admin_template_compiled', 'language_id = ' . $db->quote($languageId));
     $db->delete('xf_email_template_compiled', 'language_id = ' . $db->quote($languageId));
     $db->update('xf_user', array('language_id' => XenForo_Application::get('options')->defaultLanguageId), 'language_id = ' . $db->quote($languageId));
     $this->_getLanguageModel()->rebuildLanguageCaches();
     $this->_getLanguageModel()->triggerLanguageRebuildDeferred();
 }
Ejemplo n.º 7
0
 /**
  * Loads the file path where a template is located in the file system, if
  * templates are being stored in the file system.
  *
  * @param string Template name
  *
  * @param string Empty string (not using file system) or file path
  */
 protected function _loadTemplateFilePath($templateName)
 {
     if ($this->_usingTemplateFiles()) {
         return XenForo_Template_FileHandler::get($templateName, self::$_styleId, self::$_languageId);
     } else {
         return '';
     }
 }
Ejemplo n.º 8
0
 /**
  * Internal post-delete handler.
  */
 protected function _postDelete()
 {
     $db = $this->_db;
     $styleModel = $this->_getStyleModel();
     $templateModel = $this->_getTemplateModel();
     $styleId = $this->get('style_id');
     $styleIdQuoted = $db->quote($styleId);
     $directChildren = $styleModel->getDirectChildStyleIds($styleId);
     if ($directChildren) {
         // re-parent child styles
         $db->update('xf_style', array('parent_id' => $this->get('parent_id')), 'parent_id = ' . $db->quote($styleId));
         $styleModel->resetLocalCacheData('allStyles');
         foreach ($directChildren as $childStyleId) {
             $styleModel->rebuildStyleParentListRecursive($childStyleId);
         }
     }
     $db->delete('xf_template_map', 'style_id = ' . $styleIdQuoted);
     $db->delete('xf_template_compiled', 'style_id = ' . $styleIdQuoted);
     if (XenForo_Application::get('options')->templateFiles) {
         XenForo_Template_FileHandler::delete(null, $styleId, null);
     }
     $db->delete('xf_style_property', 'style_id = ' . $styleIdQuoted);
     $db->delete('xf_style_property_definition', 'definition_style_id = ' . $styleIdQuoted);
     $db->delete('xf_style_property_group', 'group_style_id = ' . $styleIdQuoted);
     $templates = $templateModel->getAllTemplatesInStyle($styleId);
     foreach ($templates as $template) {
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_Template', XenForo_DataWriter::ERROR_SILENT);
         $dw->setExistingData($template, true);
         $dw->setOption(XenForo_DataWriter_Template::OPTION_FULL_COMPILE, false);
         $dw->delete();
     }
     foreach ($directChildren as $childStyleId) {
         $templateModel->insertTemplateMapForStyles($templateModel->buildTemplateMapForStyleTree($childStyleId));
     }
     $db->update('xf_node', array('style_id' => 0, 'effective_style_id' => 0), "style_id = {$styleIdQuoted} OR effective_style_id = {$styleIdQuoted}");
     $db->update('xf_user', array('style_id' => 0), "style_id = {$styleIdQuoted}");
     XenForo_Application::defer('Template', array(), 'templateRebuild', true);
     $this->_rebuildCache();
 }