Location: PHPKode > projects > SimpleQuizzz > Trunk/include/viewersmarty.class.php
<?php
/*
	Template
    Copyright (C) 2008 Mathieu Lory <hide@address.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
    
    Project started on 2008-11-22

/**
 * @package    Template
 * @subpackage viewerSmarty
 * @author     Mathieu Lory <hide@address.com>
 */

if (basename($_SERVER["SCRIPT_NAME"])==basename(__FILE__))die();

final class viewerSmarty extends Viewer
{

  private static $template;
  public static $smarty;
  
	public function __construct()
	{
		require SMARTY_DIR.'Smarty.class.php';
		self::$smarty = new Smarty;
		self::$smarty->compile_check = true;
		self::$smarty->debugging = false;
	}

	public static function AddData($data_name, $data)
	{
		$data_name = strtolower($data_name);
		//self::$data_items[$data_name] = $data;
		self::$smarty->assign($data_name, $data);
	}

	/**
   * 
   * @static
   * 
   */
	public static function UseTemplate($filename)
	{
		self::$template = $filename; 
	}
	
	/**
   * 
   * @static
   * 
   */
	public static function test()
	{
        echo "testing start:<br />\n";
        echo "template_dir is '" . self::$smarty->$template_dir . "'<br />\n";
        echo "real system path: " . realpath(self::$template_dir) . "<br />\n";
        echo "file perms: " . substr(sprintf('%o', fileperms(self::$template_dir)), -4) . "<br />\n";
        if(!file_exists(self::$template_dir)) {
            echo "error: template_dir '" . self::$template_dir . "' does not exist.<br />\n";
        } elseif (!is_dir(self::$template_dir)) {
            echo "error: template dir '" . self::$template_dir . "' is not a directory.<br />\n";           
        } elseif (!is_readable(self::$template_dir)) {
            echo "error: template dir '" . self::$template_dir . "' is not readable.<br />\n";           
        } else {
            echo "OK.<br />\n";
        }
        echo "config_dir is '" . self::$config_dir . "'<br />\n";
        echo "real system path: " . realpath(self::$config_dir) . "<br />\n";
        echo "file perms: " . substr(sprintf('%o', fileperms(self::$config_dir)), -4) . "<br />\n";
        if(!file_exists(self::$config_dir)) {
            echo "error: config_dir '" . self::$config_dir . "' does not exist.<br />\n";
        } elseif (!is_dir(self::$config_dir)) {
            echo "error: config_dir '" . self::$config_dir . "' is not a directory.<br />\n";           
        } elseif (!is_readable(self::$config_dir)) {
            echo "error: config_dir '" . self::$config_dir . "' is not readable.<br />\n";           
        } else {
            echo "OK.<br />\n";
        }
        foreach(self::$plugins_dir as $_key => $_plugin_dir) {
            echo "plugins_dir ($_key) is '" . $_plugin_dir . "'<br />\n";
            echo "real system path: " . realpath($_plugin_dir) . "<br />\n";
           echo "file perms: " . substr(sprintf('%o', fileperms($_plugin_dir)), -4) . "<br />\n";
            if(!file_exists($_plugin_dir)) {
                echo "error: plugins_dir '" . $_plugin_dir . "' does not exist.<br />\n";
            } elseif (!is_dir($_plugin_dir)) {
                echo "error: plugins_dir '" . $_plugin_dir . "' is not a directory.<br />\n";           
            } elseif (!is_readable($_plugin_dir)) {
                echo "error: plugins_dir '" . $_plugin_dir . "' is not readable.<br />\n"; 
            } else {
                echo "OK.<br />\n";
            }
        }
        echo "compile_dir is '" . self::$compile_dir . "'<br />\n";
        echo "real system path: " . realpath(self::$compile_dir) . "<br />\n";
        echo "file perms: " . substr(sprintf('%o', fileperms(self::$compile_dir)), -4) . "<br />\n";
        if(!file_exists(self::$compile_dir)) {
            echo "error: compile_dir '" . self::$compile_dir . "' does not exist.<br />\n";
        } elseif (!is_dir(self::$compile_dir)) {
            echo "error: compile_dir '" . self::$compile_dir . "' is not a directory.<br />\n";           
        } elseif (!is_readable(self::$compile_dir)) {
            echo "error: compile_dir '" . self::$compile_dir . "' is not readable.<br />\n";           
        } elseif (!is_writable(self::$compile_dir)) {
            echo "error: compile_dir '" . self::$compile_dir . "' is not writable.<br />\n";           
        } else {
            $_test_file = self::$compile_dir . '/test_file';
            if(($_fp = fopen($_test_file, 'w')) !== false) {
                if(!fwrite($_fp,'test')) {
                    echo "error: unable to write to $_test_file<br />\n";
                } else {
                    unlink($_test_file);
                    fclose($_fp);
                    echo "OK.<br />\n";
                }
            } else {
                echo "error: unable to open $_test_file<br />\n";   
            }
        }
        echo "cache_dir is '" . self::$cache_dir . "'<br />\n";
        echo "real system path: " . realpath(self::$cache_dir) . "<br />\n";
        echo "file perms: " . substr(sprintf('%o', fileperms(self::$cache_dir)), -4) . "<br />\n";
        if(!file_exists(self::$cache_dir)) {
            echo "error: cache_dir '" . self::$cache_dir . "' does not exist.<br />\n";
        } elseif (!is_dir(self::$cache_dir)) {
            echo "error: cache_dir '" . self::$cache_dir . "' is not a directory.<br />\n";           
        } elseif (!is_readable(self::$cache_dir)) {
            echo "error: cache_dir '" . self::$cache_dir . "' is not readable.<br />\n";           
        } elseif (!is_writable(self::$cache_dir)) {
            echo "error: cache_dir '" . self::$cache_dir . "' is not writable.<br />\n";           
        } else {
            $_test_file = self::$cache_dir . '/test_file';
            if(($_fp = fopen($_test_file, 'w')) !== false) {
                if(!fwrite($_fp,'test')) {
                    echo "error: unable to write to $_test_file<br />\n";
                } else {
                    fclose($_fp);
                    unlink($_test_file);
                    echo "OK.<br />\n";
                }
            } else {
                echo "error: unable to open $_test_file<br />\n";   
            }
        }
        echo "testing complete.<br />\n";
	}

  /**
   * 
   * @static
   * @return bool
   */
	public static function Show()
	{
      $path = THEME_PREFIX.Settings::$page_templates_path;
      $path_c = PREFIX.Settings::$page_templates_path_c;
  		//print $path;
		self::$smarty->template_dir = $path;
		self::$smarty->compile_dir = $path_c;
		self::$smarty->display(self::$template);
	}


  /**
   * 
   * @static
   */
  public static function RequestError()
  {
    Viewer::AddData("title","Error");
    Viewer::AddData("errorDescription","Error.......");
    Viewer::UseTemplate("request_error.tpl");
  }



  /**
   * 
   * @static
   */
  public static function Restricted()
  {
    Viewer::AddData("title","Restricted");
    Viewer::UseTemplate("unregistered.tpl");
  }
}
?>
Return current item: SimpleQuizzz