Exemple #1
0
    /**
     * Load a compiled template if possible, if not, recompile it
     * @access private
     */
    function _tpl_load(&$handle)
    {
        global $user, $phpEx, $config;
        if (!isset($this->filename[$handle])) {
            trigger_error("template->_tpl_load(): No file specified for handle {$handle}", E_USER_ERROR);
        }
        $filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . '.' . $phpEx;
        $this->files_template[$handle] = isset($user->theme['template_id']) ? $user->theme['template_id'] : 0;
        $recompile = false;
        if (!file_exists($filename) || @filesize($filename) === 0) {
            $recompile = true;
        } else {
            if ($config['load_tplcompile']) {
                // No way around it: we need to check inheritance here
                if ($user->theme['template_inherits_id'] && !file_exists($this->files[$handle])) {
                    $this->files[$handle] = $this->files_inherit[$handle];
                    $this->files_template[$handle] = $user->theme['template_inherits_id'];
                }
                $recompile = @filemtime($filename) < filemtime($this->files[$handle]) ? true : false;
            }
        }
        // Recompile page if the original template is newer, otherwise load the compiled version
        if (!$recompile) {
            return $filename;
        }
        global $db, $phpbb_root_path;
        if (!class_exists('template_compile')) {
            include $phpbb_root_path . 'includes/functions_template.' . $phpEx;
        }
        // Inheritance - we point to another template file for this one. Equality is also used for store_db
        if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($this->files[$handle])) {
            $this->files[$handle] = $this->files_inherit[$handle];
            $this->files_template[$handle] = $user->theme['template_inherits_id'];
        }
        $compile = new template_compile($this);
        // If we don't have a file assigned to this handle, die.
        if (!isset($this->files[$handle])) {
            trigger_error("template->_tpl_load(): No file specified for handle {$handle}", E_USER_ERROR);
        }
        // Just compile if no user object is present (happens within the installer)
        if (!$user) {
            $compile->_tpl_load_file($handle);
            return false;
        }
        if (isset($user->theme['template_storedb']) && $user->theme['template_storedb']) {
            $rows = array();
            $ids = array();
            // Inheritance
            if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id']) {
                $ids[] = $user->theme['template_inherits_id'];
            }
            $ids[] = $user->theme['template_id'];
            foreach ($ids as $id) {
                $sql = 'SELECT *
				FROM ' . STYLES_TEMPLATE_DATA_TABLE . '
				WHERE template_id = ' . $id . "\n\t\t\t\t\tAND (template_filename = '" . $db->sql_escape($this->filename[$handle]) . "'\n\t\t\t\t\t\tOR template_included " . $db->sql_like_expression($db->any_char . $this->filename[$handle] . ':' . $db->any_char) . ')';
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $rows[$row['template_filename']] = $row;
                }
                $db->sql_freeresult($result);
            }
            if (sizeof($rows)) {
                foreach ($rows as $row) {
                    $file = $this->root . '/' . $row['template_filename'];
                    $force_reload = false;
                    if ($row['template_id'] != $user->theme['template_id']) {
                        // make sure that we are not overlooking a file not in the db yet
                        if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($file)) {
                            $file = $this->inherit_root . '/' . $row['template_filename'];
                            $this->files[$row['template_filename']] = $file;
                            $this->files_inherit[$row['template_filename']] = $file;
                            $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id'];
                        } else {
                            if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id']) {
                                // Ok, we have a situation. There is a file in the subtemplate, but nothing in the DB. We have to fix that.
                                $force_reload = true;
                                $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id'];
                            }
                        }
                    } else {
                        $this->files_template[$row['template_filename']] = $user->theme['template_id'];
                    }
                    if ($force_reload || $row['template_mtime'] < filemtime($file)) {
                        if ($row['template_filename'] == $this->filename[$handle]) {
                            $compile->_tpl_load_file($handle, true);
                        } else {
                            $this->files[$row['template_filename']] = $file;
                            $this->filename[$row['template_filename']] = $row['template_filename'];
                            $compile->_tpl_load_file($row['template_filename'], true);
                            unset($this->compiled_code[$row['template_filename']]);
                            unset($this->files[$row['template_filename']]);
                            unset($this->filename[$row['template_filename']]);
                        }
                    }
                    if ($row['template_filename'] == $this->filename[$handle]) {
                        $this->compiled_code[$handle] = $compile->compile(trim($row['template_data']));
                        $compile->compile_write($handle, $this->compiled_code[$handle]);
                    } else {
                        // Only bother compiling if it doesn't already exist
                        if (!file_exists($this->cachepath . str_replace('/', '.', $row['template_filename']) . '.' . $phpEx)) {
                            $this->filename[$row['template_filename']] = $row['template_filename'];
                            $compile->compile_write($row['template_filename'], $compile->compile(trim($row['template_data'])));
                            unset($this->filename[$row['template_filename']]);
                        }
                    }
                }
            } else {
                $file = $this->root . '/' . $row['template_filename'];
                if (isset($user->theme['template_inherits_id']) && $user->theme['template_inherits_id'] && !file_exists($file)) {
                    $file = $this->inherit_root . '/' . $row['template_filename'];
                    $this->files[$row['template_filename']] = $file;
                    $this->files_inherit[$row['template_filename']] = $file;
                    $this->files_template[$row['template_filename']] = $user->theme['template_inherits_id'];
                }
                // Try to load from filesystem and instruct to insert into the styles table...
                $compile->_tpl_load_file($handle, true);
                return false;
            }
            return false;
        }
        $compile->_tpl_load_file($handle);
        return false;
    }
Exemple #2
0
 /**
  * Load a compiled template if possible, if not, recompile it
  * @access private
  */
 function _tpl_load(&$handle)
 {
     global $system;
     $filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . '.php';
     $this->files_template[$handle] = $system->SETTINGS['theme'];
     $recompile = false;
     if (!file_exists($filename) || @filesize($filename) === 0 || $system->SETTINGS['cache_theme'] == 'n') {
         $recompile = true;
     }
     // Recompile page if the original template is newer, otherwise load the compiled version
     if (!$recompile) {
         return $filename;
     }
     global $include_path;
     if (!class_exists('template_compile')) {
         include $include_path . 'class_template_compile.php';
     }
     $compile = new template_compile($this);
     // If we don't have a file assigned to this handle, die.
     if (!isset($this->files[$handle])) {
         trigger_error("template->_tpl_load(): No file specified for handle {$handle}", E_USER_ERROR);
     }
     $compile->_tpl_load_file($handle);
     return false;
 }
Exemple #3
0
	/**
	* Load a compiled template if possible, if not, recompile it
	* @access private
	*/
	function _tpl_load(&$handle)
	{
		global $user, $phpEx, $config;

		$filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . '.' . $phpEx;

		$recompile = (($config['load_tplcompile'] && @filemtime($filename) < filemtime($this->files[$handle])) || !file_exists($filename) || @filesize($filename) === 0) ? true : false;

		// Recompile page if the original template is newer, otherwise load the compiled version
		if (!$recompile)
		{
			return $filename;
		}

		global $db, $phpbb_root_path;

		if (!class_exists('template_compile'))
		{
			include($phpbb_root_path . 'includes/functions_template.' . $phpEx);
		}

		$compile = new template_compile($this);

		// If we don't have a file assigned to this handle, die.
		if (!isset($this->files[$handle]))
		{
			trigger_error("template->_tpl_load(): No file specified for handle $handle", E_USER_ERROR);
		}

		// Just compile if no user object is present (happens within the installer)
		if (!$user)
		{
			$compile->_tpl_load_file($handle);
			return false;
		}

		if (isset($user->theme['template_storedb']) && $user->theme['template_storedb'])
		{
			$sql = 'SELECT *
				FROM ' . STYLES_TEMPLATE_DATA_TABLE . '
				WHERE template_id = ' . $user->theme['template_id'] . "
					AND (template_filename = '" . $db->sql_escape($this->filename[$handle]) . "'
						OR template_included " . $db->sql_like_expression($db->any_char . $this->filename[$handle] . ':' . $db->any_char) . ')';
			$result = $db->sql_query($sql);
			$row = $db->sql_fetchrow($result);

			if ($row)
			{
				do
				{
					if ($row['template_mtime'] < filemtime($phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/' . $row['template_filename']))
					{
						if ($row['template_filename'] == $this->filename[$handle])
						{
							$compile->_tpl_load_file($handle);
						}
						else
						{
							$this->files[$row['template_filename']] = $this->root . '/' . $row['template_filename'];
							$compile->_tpl_load_file($row['template_filename']);
							unset($this->compiled_code[$row['template_filename']]);
							unset($this->files[$row['template_filename']]);
							unset($this->filename[$row['template_filename']]);
						}
					}

					if ($row['template_filename'] == $this->filename[$handle])
					{
						$this->compiled_code[$handle] = $compile->compile(trim($row['template_data']));
						$compile->compile_write($handle, $this->compiled_code[$handle]);
					}
					else
					{
						// Only bother compiling if it doesn't already exist
						if (!file_exists($this->cachepath . str_replace('/', '.', $row['template_filename']) . '.' . $phpEx))
						{
							$this->filename[$row['template_filename']] = $row['template_filename'];
							$compile->compile_write($row['template_filename'], $compile->compile(trim($row['template_data'])));
							unset($this->filename[$row['template_filename']]);
						}
					}
				}
				while ($row = $db->sql_fetchrow($result));
			}
			else
			{
				// Try to load from filesystem and instruct to insert into the styles table...
				$compile->_tpl_load_file($handle, true);
				return false;
			}
			$db->sql_freeresult($result);

			return false;
		}

		$compile->_tpl_load_file($handle);
		return false;
	}
<?php
Exemple #5
0
    /**
     * Load a compiled template if possible, if not, recompile it
     * @access: private
     */
    function _tpl_load(&$handle)
    {
        global $user, $phpEx, $config;
        $filename = $this->cachepath . str_replace('/', '.', $this->filename[$handle]) . '.' . $phpEx;
        $recompile = $config['load_tplcompile'] && @filemtime($filename) < filemtime($this->files[$handle]) || !file_exists($filename) ? true : false;
        // Recompile page if the original template is newer, otherwise load the compiled version
        if (!$recompile) {
            return $filename;
        }
        global $db, $phpbb_root_path;
        include_once $phpbb_root_path . 'includes/functions_template.' . $phpEx;
        $compile = new template_compile($this);
        // If the file for this handle is already loaded and compiled, do nothing.
        if (!empty($this->uncompiled_code[$handle])) {
            return true;
        }
        // If we don't have a file assigned to this handle, die.
        if (!isset($this->files[$handle])) {
            trigger_error("template->_tpl_load(): No file specified for handle {$handle}", E_USER_ERROR);
        }
        // Just compile if no user object is present (happens within the installer)
        if (!$user) {
            $compile->_tpl_load_file($handle);
            return false;
        }
        if (isset($user->theme['template_storedb']) && $user->theme['template_storedb']) {
            $sql = 'SELECT * FROM ' . STYLES_TEMPLATE_DATA_TABLE . '
				WHERE template_id = ' . $user->theme['template_id'] . "\n\t\t\t\t\tAND (template_filename = '" . $db->sql_escape($this->filename[$handle]) . "'\n\t\t\t\t\t\tOR template_included LIKE '%" . $db->sql_escape($this->filename[$handle]) . ":%')";
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                if ($row['template_mtime'] < filemtime($phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/' . $row['template_filename'])) {
                    if ($row['template_filename'] == $this->filename[$handle]) {
                        $compile->_tpl_load_file($handle);
                    } else {
                        $this->files[$row['template_filename']] = $this->root . '/' . $row['template_filename'];
                        $compile->_tpl_load_file($row['template_filename']);
                        unset($this->compiled_code[$row['template_filename']]);
                        unset($this->files[$row['template_filename']]);
                    }
                }
                if ($row['template_filename'] == $this->filename[$handle]) {
                    $this->compiled_code[$handle] = $compile->compile(trim($row['template_data']));
                    $compile->compile_write($handle, $this->compiled_code[$handle]);
                } else {
                    // Only bother compiling if it doesn't already exist
                    if (!file_exists($this->cachepath . str_replace('/', '.', $row['template_filename']) . '.' . $phpEx)) {
                        $this->filename[$row['template_filename']] = $row['template_filename'];
                        $compile->compile_write($row['template_filename'], $compile->compile(trim($row['template_data'])));
                        unset($this->filename[$row['template_filename']]);
                    }
                }
            }
            $db->sql_freeresult($result);
            return false;
        }
        $compile->_tpl_load_file($handle);
        return false;
    }