<?PHP

/**************************************
    Webutler V3.0 - www.webutler.de
    Copyright (c) 2008 - 2014
    Autor: Sven Zinke
    Free for any use
    Lizenz: GPL
**************************************/

if(preg_match('#/modules/news/view.php#i', $_SERVER['REQUEST_URI']))
    exit('no access');

$news_stylesheet = '<link type="text/css" rel="stylesheet" href="'.$webutlercouple->config['homepage'].'/modules/news/view/news.css" />';
if(!in_array($news_stylesheet, $webutlercouple->autoheaderdata)) {
    $webutlercouple->autoheaderdata[] = $news_stylesheet;
}

$news_langpath = $webutlercouple->config['server_path'].'/modules/news/view/lang';
$news_language = (isset($_SESSION['language']) && file_exists($news_langpath.'/'.$_SESSION['language'].'.php')) ? $_SESSION['language'] : $webutlercouple->config['defaultlang'];
require_once $news_langpath.'/'.$news_language.'.php';

require $webutlercouple->config['server_path'].'/modules/news/data/config.php';


if(isset($_MMBLOCK['newsnewest']) && $_MMBLOCK['newsnewest'] == '1') {
	unset($_MMBLOCK['newsnewest']);
	$newsnewest_class = new MMViewClass;
	$newsnewest_class->getpage = $webutlercouple->getpage;
	$newsnewest_class->modname = 'news';
	$newsnewest_class->serverpath = $webutlercouple->config['server_path'];
	$newsnewest_class->fileconfig = $news_conf;
	$newsnewest_class->pagelang = $news_language;
	$newsnewest_class->get = $_GET;
	if(isset($_MMBLOCK['newsmodpage']) && $_MMBLOCK['newsmodpage'] != '') {
		$newsnewest_class->modpage = $_MMBLOCK['newsmodpage'];
	}
	$newsnewest_class->connectdb();
	echo $newsnewest_class->loadnewestblock();

}
else {


	$news_class = (isset($_POST['newspostsave'])) ? new MMInputClass : new MMViewClass;
	$news_class->modname = 'news';
	$news_class->fileconfig = $news_conf;
    $news_class->userisadmin = $webutlercouple->checkadmin();
	$news_class->sessgrpids = isset($_SESSION['userauth']['groupid']) ? $_SESSION['userauth']['groupid'] : array();
	$news_class->getpage = $webutlercouple->getpage;
	$news_class->serverpath = $webutlercouple->config['server_path'];
	$news_class->pagelang = $news_language;
	$news_class->get = $_GET;
	$news_class->connectdb();
	if(isset($_POST['newspostsave']) && ($news_class->userisadmin || $news_class->getwritepermission())) {
		$news_class->post = $_POST;
		$news_class->files = $_FILES;
//print_r($news_class->post);
		$news_class->saveuserpost();
	}


    if($news_class->dbconfig == '') {
        echo _NEWSLANG_NOTINSTALLED_;
        return false;
    }
	
    if(array_key_exists('lightbox', $news_class->dbconfig)) {
		$webutlercouple->autoheaderdata[] = '<script type="text/javascript" src="'.$webutlercouple->config['homepage'].'/includes/javascript/lightbox/lightbox_plus.js"></script>';
	}

	
	if($webutlercouple->checkadmin() || $news_class->getwritepermission()) {
		$webutlercouple->autoheaderdata[] = '';
	}
	
    $news_result = $news_class->loadmodule();
	
	if(count($news_class->metadata) > 0) {
		if(isset($news_class->metadata['title']))
			$webutlercouple->setnewtitlefrommod = $news_class->metadata['title'];
		if(isset($news_class->metadata['description']))
			$webutlercouple->autoheaderdata[] = '<meta name="description" content="'.$news_class->metadata['description'].'" />';
		if(isset($news_class->metadata['keywords']))
			$webutlercouple->autoheaderdata[] = '<meta name="keywords" content="'.$news_class->metadata['keywords'].'" />';
	}
    
    echo $news_result;

}

?>
