示例#1
0
    /**
     * Compiles a single admin template
     *
     * @param array Template
     */
    public function compileParsedAdminTemplate($templateId, array $parsedTemplate, $title)
    {
        $isCss = substr($title, -4) == '.css';
        $languages = $this->getModelFromCache('XenForo_Model_Language')->getAllLanguages();
        $db = $this->_getDb();
        $compiler = new XenForo_Template_Compiler_Admin('');
        if ($isCss) {
            $compiledTemplate = $compiler->compileParsed($parsedTemplate, $title, 0, 0);
            $db->query('
				INSERT INTO xf_admin_template_compiled
					(language_id, title, template_compiled)
				VALUES
					(?, ?, ?)
				ON DUPLICATE KEY UPDATE template_compiled = VALUES(template_compiled)
			', array(0, $title, $compiledTemplate));
        } else {
            foreach ($languages as $language) {
                $compiledTemplate = $compiler->compileParsed($parsedTemplate, $title, 0, $language['language_id']);
                $db->query('
					INSERT INTO xf_admin_template_compiled
						(language_id, title, template_compiled)
					VALUES
						(?, ?, ?)
					ON DUPLICATE KEY UPDATE template_compiled = VALUES(template_compiled)
				', array($language['language_id'], $title, $compiledTemplate));
            }
        }
        $ins = array();
        foreach ($compiler->getIncludedTemplates() as $includedId) {
            $ins[] = '(' . $db->quote($templateId) . ', ' . $db->quote($includedId) . ')';
            //TODO: this system doesn't handle includes for templates that don't exist yet
        }
        $db->delete('xf_admin_template_include', 'source_id = ' . $db->quote($templateId));
        if ($ins) {
            $db->query("\r\n\t\t\t\tINSERT IGNORE INTO xf_admin_template_include\r\n\t\t\t\t\t(source_id, target_id)\r\n\t\t\t\tVALUES\r\n\t\t\t\t\t" . implode(',', $ins));
        }
        $ins = array();
        foreach ($compiler->getIncludedPhrases() as $includedPhrase) {
            if (strlen($includedPhrase) > 75) {
                continue;
                // too long, can't be a valid phrase
            }
            $ins[] = '(' . $db->quote($templateId) . ', ' . $db->quote($includedPhrase) . ')';
        }
        $db->delete('xf_admin_template_phrase', 'template_id = ' . $db->quote($templateId));
        if ($ins) {
            $db->query('
				INSERT IGNORE INTO xf_admin_template_phrase
					(template_id, phrase_title)
				VALUES
					' . implode(',', $ins));
        }
    }
示例#2
0
    public function deleteAdminTemplates(array $adminTemplateTitles)
    {
        if (empty($adminTemplateTitles)) {
            return false;
        }
        $templateIds = array_keys($adminTemplateTitles);
        $this->_deleteAdminTemplates($templateIds);
        $db = $this->_getDb();
        $db->query('
			DELETE FROM xf_brivium_admin_template_compiled
			WHERE style_id = 0
				AND title IN (' . $db->quote($adminTemplateTitles) . ')
		');
        if (XenForo_Application::get('options')->templateFiles) {
            XenForo_Template_FileHandler::delete($adminTemplateTitles, 0, null);
        }
        XenForo_Template_Compiler_Admin::resetTemplateCache();
        return true;
    }
示例#3
0
    /**
     * Compiles a single admin template
     *
     * @param array Template
     */
    public function compileParsedAdminTemplate($templateId, array $parsedTemplate, $title)
    {
        $isCss = substr($title, -4) == '.css';
        $languages = $this->getModelFromCache('XenForo_Model_Language')->getAllLanguages();
        $db = $this->_getDb();
        $compiler = new XenForo_Template_Compiler_Admin('');
        if ($isCss) {
            $compiledTemplate = $compiler->compileParsed($parsedTemplate, $title, 0, 0);
            $db->query('
				INSERT INTO xf_admin_template_compiled
					(language_id, title, template_compiled)
				VALUES
					(?, ?, ?)
				ON DUPLICATE KEY UPDATE template_compiled = VALUES(template_compiled)
			', array(0, $title, $compiledTemplate));
        } else {
            foreach ($languages as $language) {
                $compiledTemplate = $compiler->compileParsed($parsedTemplate, $title, 0, $language['language_id']);
                $db->query('
					INSERT INTO xf_admin_template_compiled
						(language_id, title, template_compiled)
					VALUES
						(?, ?, ?)
					ON DUPLICATE KEY UPDATE template_compiled = VALUES(template_compiled)
				', array($language['language_id'], $title, $compiledTemplate));
            }
        }
        $db->delete('xf_admin_template_include', 'source_id = ' . $db->quote($templateId));
        foreach ($compiler->getIncludedTemplates() as $includedId) {
            $db->insert('xf_admin_template_include', array('source_id' => $templateId, 'target_id' => $includedId));
            //TODO: this system doesn't handle includes for templates that don't exist yet
        }
        $db->delete('xf_admin_template_phrase', 'template_id = ' . $db->quote($templateId));
        foreach ($compiler->getIncludedPhrases() as $includedPhrase) {
            $db->insert('xf_admin_template_phrase', array('template_id' => $templateId, 'phrase_title' => $includedPhrase));
        }
    }
示例#4
0
 /**
  * Post-save handler.
  */
 protected function _postSave()
 {
     if ($this->isUpdate() && $this->isChanged('title')) {
         $this->_db->delete('xf_admin_template_compiled', 'title = ' . $this->_db->quote($this->getExisting('title')));
         $this->_db->delete('xf_admin_template_include', 'source_id = ' . $this->_db->quote($this->get('template_id')));
         $this->_db->delete('xf_admin_template_phrase', 'template_id = ' . $this->_db->quote($this->get('template_id')));
     }
     if ($this->getOption(self::OPTION_FULL_COMPILE)) {
         XenForo_Template_Compiler_Admin::removeTemplateFromCache($this->get('title'));
         XenForo_Template_Compiler_Admin::removeTemplateFromCache($this->getExisting('title'));
         $this->_recompileTemplate();
         $this->_recompileDependentTemplates();
         $this->_getAdminTemplateModel()->updateAdminStyleLastModifiedDate();
     }
     if ($devDir = $this->_getDevOutputDir()) {
         $this->_writeDevFileOutput($devDir);
     }
 }
示例#5
0
 /**
  * Post-save handler.
  */
 protected function _postSave()
 {
     $adminTemplateModel = $this->_getAdminTemplateModel();
     if ($this->isUpdate() && $this->isChanged('template')) {
         $this->_db->insert('xf_brivium_admin_template_history', array('title' => $this->get('title'), 'style_id' => $this->get('style_id'), 'template' => $this->getExisting('template'), 'edit_date' => $this->getExisting('last_edit_date'), 'log_date' => XenForo_Application::$time));
     }
     if (is_array($this->_modificationStatuses)) {
         $this->_getModificationModel()->updateTemplateModificationLog($this->get('template_id'), $this->_modificationStatuses);
     }
     if ($this->getOption(self::OPTION_REBUILD_TEMPLATE_MAP)) {
         if ($this->isChanged('title')) {
             $adminTemplateModel->buildAdminTemplateMap($this->get('title'));
             if ($existingTitle = $this->getExisting('title')) {
                 if ($this->getOption(self::OPTION_FULL_COMPILE)) {
                     // need to recompile anything including this template
                     $mappedAdminTemplates = $adminTemplateModel->getAdminTemplateMappedsByAdminTemplateId($this->get('template_id'));
                     $mappedAdminTemplateIds = array();
                     foreach ($mappedAdminTemplates as $mappedAdminTemplate) {
                         $mappedAdminTemplateIds[] = $mappedAdminTemplate['template_map_id'];
                     }
                     $adminTemplateModel->buildAdminTemplateMap($existingTitle);
                     $adminTemplateModel->compileAdminTemplateMappedsInStyleTree($adminTemplateModel->getIncludingAdminTemplateMapIds($mappedAdminTemplateIds));
                 } else {
                     $adminTemplateModel->buildAdminTemplateMap($existingTitle);
                 }
             }
         } else {
             if ($this->isChanged('style_id')) {
                 $adminTemplateModel->buildAdminTemplateMap($this->get('title'));
             }
         }
     }
     if ($this->getOption(self::OPTION_FULL_COMPILE)) {
         XenForo_Template_Compiler_Admin::removeTemplateFromCache($this->get('title'));
         XenForo_Template_Compiler_Admin::removeTemplateFromCache($this->getExisting('title'));
         $this->_recompileAdminTemplate();
         $styleModel = $this->getModelFromCache('XenForo_Model_Style');
         $styleModel->setAdminStyles(true);
         $styleModel->updateAllStylesLastModifiedDate();
         $this->getModelFromCache('XenForo_Model_AdminTemplate')->updateAdminStyleLastModifiedDate();
     }
     if ($devDir = $this->_getDevOutputDir()) {
         $this->_writeDevFileOutput($devDir);
     }
     if ($this->getOption(self::OPTION_REBUILD_XENFORO_ADMIN_TEMPLATE) && !$this->get('style_id')) {
         $this->_updateToXfAdminTemplate();
     }
 }