Location: PHPKode > projects > Php4dvd - movie database > php4dvd/common.inc.php
<?php
/**
================================================================================ 
 LISENCE
================================================================================

    This file is part of php4dvd.

    php4dvd 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.

    php4dvd 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 php4dvd. If not, see <http://www.gnu.org/licenses/>.
**/

/**
 * Common functionality needed by the site.
 *
 * Do not change this file unless you know exactly what you are doing!
 */
// Local path
$loc = dirname(__FILE__);

// Load user class, because this can be stored in session
require_once($loc."/lib/objects/DataObject.class.php");
require_once($loc."/lib/objects/User.class.php");
// Start session
session_start();

// Installer
if(file_exists("install/index.php")) {
	header("Location: install/index.php");
	exit();
}

/**
 * Make this site PHP5 compatible.
 */
if (PHP_VERSION < 5) include_once($loc."/lib/db/PHP5Compatible.class.php");

// Load the config file
if(!file_exists($loc."/config/config.php")) {
	echo "<h1>Fatal error</h1>The file <tt>config/config.php</tt> was not found!";
	exit();
}
require_once($loc."/config/config.php");

// Classes
require_once($loc."/lib/Website.class.php");
require_once($loc."/lib/db/Database.class.php");
require_once($loc."/lib/db/DataManager.class.php");

/**
 * Load the website template engine: Smarty.
 */
$w = new Website($settings);

// Version
require_once("config/version.inc.php");
$w->assign("version", VERSION);

/**
 * Connect to the database. Settings can be found in config.php
 */
$db = new Database($settings['db']);

/**
 * Did the database failed to connect? Display the error page.
 */
if($db->error) {
        // Include
        $template_dir = $settings["smarty"]["template_include_dir"];
        $w->assign("template_dir", $template_dir);
        
        // Template
        $template = "error.html";
        $w->assign("error", $db->errormessage);
        $w->assign("host", $_SERVER["REMOTE_ADDR"]." @ http://".$_SERVER["SERVER_NAME"].$_SERVER["SCRIPT_NAME"]);
        $w->addStyle($template_dir."css/style.css");
        $w->display($template);
        exit();
}

/**
 * Extra common functions
 */
// Is the browser IE?
function isIE() {
        $agent = $_SERVER['HTTP_USER_AGENT'];
        return eregi("msie",$agent) && !eregi("opera",$agent);
}

// Is the browser IE7?
function isIE7() {
        $agent = $_SERVER['HTTP_USER_AGENT'];
        
        return eregi("msie 7",$agent) && !eregi("opera",$agent);
}

// Make path recursive
function mkpath($path) {
        $dirs=array();
        $path=preg_replace('/(\/){2,}|(\\\){1,}/','/',$path); //only forward-slash
        $dirs=explode("/",$path);
        $path="";
        foreach ($dirs as $element) {
                $path.=$element."/";
                if(!is_dir($path)) {
                        mkdir($path);
                }         
        }
}

// Strip the tags from IMDb summary
function stripTags($tekst) {
        $tekst = preg_replace("/<i>.*?<\/i>/is", "\n", $tekst);
        return $tekst;
}

// Find the extention of a filename
function findExtention($filename) {
        $array = explode(".", $filename);
        $pos = count($array) - 1;
        $extention = $array[$pos];
        return $extention;
}

// Go back to previous page
function goBack() {
        header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
        header("Expires: Mon, 01 Jan 1970 00:00:00 GMT");       // Date in the past
        if(isset($_SERVER["HTTP_REFERER"]))
                header("Location: ".$_SERVER["HTTP_REFERER"]);
        else
                header("Location: ./");
        exit();
}
?>
Return current item: Php4dvd - movie database