Add a central include file

This commit is contained in:
Yorin Anne De Jong 2018-02-13 19:08:41 +01:00
parent f2b75c81c1
commit 73efba625b
9 changed files with 49 additions and 59 deletions

33
inc/include.php Normal file
View File

@ -0,0 +1,33 @@
<?php
// Set up database and user system,
// and include common files such as HTML includes or SimplSAMLphp.
require_once __DIR__ . DIRECTORY_SEPARATOR . 'agenda.php';
require_once __DIR__ . DIRECTORY_SEPARATOR . 'navbar.php';
require_once dirname(__DIR__) . implode(DIRECTORY_SEPARATOR, ['', 'lib', 'OAuth2-Client', 'OAuth2Client.php']);
require_once dirname(__DIR__) . implode(DIRECTORY_SEPARATOR, ['', 'dataporten_config.php']);
require_once dirname(__DIR__) . implode(DIRECTORY_SEPARATOR, ['', 'sql_config.php']);
require_once dirname(__DIR__) . implode(DIRECTORY_SEPARATOR, ['', 'src', '_autoload.php']);
require_once dirname(__DIR__) . implode(DIRECTORY_SEPARATOR, ['', 'vendor', 'simplesamlphp', 'simplesamlphp', 'lib', '_autoload.php']);
date_default_timezone_set('Europe/Oslo');
setlocale(LC_ALL, 'nb_NO');
$pdo = new \PDO($dbDsn, $dbUser, $dbPass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$userManager = new \pvv\admin\UserManager($pdo);
$sp = 'default-sp';
$as = new SimpleSAML_Auth_Simple($sp);
use \pvv\side\Agenda;
$agenda = new \pvv\side\Agenda([
new \pvv\side\social\NerdepitsaActivity,
new \pvv\side\social\AnimekveldActivity,
new \pvv\side\DBActivity($pdo),
]);
$months_translations = ['januar', 'februar', 'mars', 'april', 'mai', 'juni', 'juli', 'august', 'september', 'oktober', 'november', 'desember'];

View File

@ -1,14 +1,6 @@
<?php
require __DIR__ . '/../../inc/navbar.php';
require __DIR__ . '/../../src/_autoload.php';
require_once __DIR__ . '/../../vendor/simplesamlphp/simplesamlphp/lib/_autoload.php';
require __DIR__ . '/../../sql_config.php';
require_once dirname(__DIR__, 2) . implode(DIRECTORY_SEPARATOR, ['', 'inc', 'include.php']);
$pdo = new \PDO($dbDsn, $dbUser, $dbPass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$userManager = new \pvv\admin\UserManager($pdo);
$as = new SimpleSAML_Auth_Simple('default-sp');
$as->requireAuth();
$attrs = $as->getAttributes();
$uname = $attrs['uid'][0];

View File

@ -1,18 +1,5 @@
<?php
date_default_timezone_set('Europe/Oslo');
setlocale(LC_ALL, 'nb_NO');
require_once __DIR__ . '/../../inc/navbar.php';
require_once __DIR__ . '/../../src/_autoload.php';
require_once __DIR__ . '/../../sql_config.php';
$pdo = new \PDO($dbDsn, $dbUser, $dbPass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
use \pvv\side\Agenda;
$agenda = new \pvv\side\Agenda([
new \pvv\side\social\NerdepitsaActivity,
new \pvv\side\social\AnimekveldActivity,
new \pvv\side\DBActivity($pdo),
]);
require_once dirname(__DIR__, 2) . implode(DIRECTORY_SEPARATOR, ['', 'inc', 'include.php']);
$year = (isset($_GET['year']))
? $_GET['year']
@ -80,5 +67,5 @@ foreach($events as $event) {
<nav>
<?= navbar(1, 'aktiviteter'); ?>
<?= loginbar(null, $pdo); ?>
<?= loginbar($sp, $pdo); ?>
</nav>

View File

@ -1,8 +1,5 @@
<?php
date_default_timezone_set('Europe/Oslo');
setlocale(LC_ALL, 'nb_NO');
require __DIR__ . '/../inc/navbar.php';
require __DIR__ . '/../inc/agenda.php';
require_once dirname(__DIR__, 1) . implode(DIRECTORY_SEPARATOR, ['', 'inc', 'include.php']);
$translation = ['i dag', 'i morgen', 'denne uka', 'neste uke', 'denne måneden', 'neste måned'];
?>
@ -91,5 +88,5 @@ For å bli med i våre prosjekter og komitéer må du søke.
<nav>
<?php echo navbar(0, ''); ?>
<?php echo loginbar(); ?>
<?php echo loginbar($sp, $pdo); ?>
</nav>

View File

@ -1,10 +1,5 @@
<?php
date_default_timezone_set('Europe/Oslo');
setlocale(LC_ALL, 'nb_NO');
require __DIR__ . '/../../inc/navbar.php';
require __DIR__ . '/../../inc/agenda.php';
$months_translations = ['januar', 'februar', 'mars', 'april', 'mai', 'juni', 'juli', 'august', 'september', 'oktober', 'november', 'desember'];
require_once dirname(__DIR__, 2) . implode(DIRECTORY_SEPARATOR, ['', 'inc', 'include.php']);
$year = (isset($_GET['year']))
? $_GET['year']
@ -93,5 +88,5 @@ $days_in_month = date('t', mktime(0, 0, 0, $month, 1, $year));
<nav>
<?= navbar(1, 'kalender'); ?>
<?= loginbar(); ?>
<?= loginbar($sp, $pdo); ?>
</nav>

View File

@ -1,11 +1,6 @@
<!DOCTYPE html>
<?php
date_default_timezone_set('Europe/Oslo');
setlocale(LC_ALL, 'nb_NO');
require __DIR__ . '/../../inc/navbar.php';
require __DIR__ . '/../../src/_autoload.php';
require __DIR__ . '/../../sql_config.php';
?>
require_once dirname(__DIR__, 2) . implode(DIRECTORY_SEPARATOR, ['', 'inc', 'include.php']);
?><!DOCTYPE html>
<html lang="no">
<title>Kommunikasjonsverkstedet</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
@ -39,5 +34,5 @@ Det er også mulig å ta i bruk analog kontakt ved å møte opp <a href="https:/
<nav>
<?= navbar(1, 'kontakt'); ?>
<?= loginbar(null, $pdo); ?>
<?= loginbar($sp, $pdo); ?>
</nav>

View File

@ -1,5 +1,5 @@
<?php
require_once __DIR__ . '/../../inc/navbar.php';
require_once dirname(__DIR__, 2) . implode(DIRECTORY_SEPARATOR, ['', 'inc', 'include.php']);
?>
<!DOCTYPE html>
<html lang=no>
@ -59,5 +59,5 @@ p {hyphens: auto;}
<nav>
<?= navbar(1); ?>
<?= loginbar(); ?>
<?= loginbar($sp, $pdo); ?>
</nav>

View File

@ -1,11 +1,8 @@
<?php
require_once __DIR__ . '/../../inc/navbar.php';
require_once __DIR__ . '/../../lib/OAuth2-Client/OAuth2Client.php';
require_once __DIR__ . '/../../dataporten_config.php';
require_once __DIR__ . '/../../vendor/simplesamlphp/simplesamlphp/lib/_autoload.php';
require_once dirname(__DIR__, 2) . implode(DIRECTORY_SEPARATOR, ['', 'inc', 'include.php']);
session_start();
$as = new SimpleSAML_Auth_Simple('default-sp');
$attrs = $as->getAttributes();
$oauth2 = new Kasperrt\Oauth2($dataportenConfig);

View File

@ -1,13 +1,7 @@
<?php
error_reporting(E_ALL);
date_default_timezone_set('Europe/Oslo');
require __DIR__ . '/../../inc/navbar.php';
require __DIR__ . '/../../src/_autoload.php';
require __DIR__ . '/../../sql_config.php';
require_once dirname(__DIR__, 2) . implode(DIRECTORY_SEPARATOR, ['', 'inc', 'include.php']);
$translation = ['i dag', 'i morgen', 'denne uka', 'neste uke', 'denne måneden', 'neste måned'];
$pdo = new \PDO($dbDsn, $dbUser, $dbPass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$projectManager = new \pvv\side\ProjectManager($pdo);
$projects = $projectManager->getAll();
?>
@ -69,5 +63,5 @@ $projects = $projectManager->getAll();
<nav>
<?= navbar(1, 'prosjekt'); ?>
<?= loginbar(null, $pdo); ?>
<?= loginbar($sp, $pdo); ?>
</nav>