Avatar billede crjensen Juniormester
16. oktober 2016 - 23:43 Der er 6 kommentarer og
1 løsning

Ændre rutine i julekalender-phpscript

Jeg har et julekalenderscript, hvor klik på en dag de 24 låger åbner en side med et billede og en lille tekst.
Klikker man på låge 1, åbner scriptet en php-side '1' og søger efter '1.jpg' og viser dét inklusiv eventuel tekst.
I stedet for dette vil jeg gerne have lavet scriptet om, så det i stedet åbner en færdigdesignet html eller php-side.
Altså: Jeg laver 24 færdigdesignede html eller php-sider, og når man klikker på en låg, åbnes den tilsvarende side, fx 1.html eller 2.html, osv.

Den del af julekalenderscriptet, der udfører kommandoen med at åbne en side, ser ud som her nedenfor. Jeg går ud fra, at det er denne del, der skal ændres.
Resten af index.php filen har jeg puttet ind længere nede.

Vil nogen kunne hjælpe mig med at ændre disse linjer i index.php, så et klik på 1-24 åbner tilsvarende 1-24.html eller php?

DEN DEL AF INDEX.PHP SOM SKABER EN SIDE:
    static function getDayHtml($day) {
        $result = '<div class="container day">';

        $d = self::getDay($day);
        $title = $d->title;
        $legend = $d->legend;
        $text = $d->text;

        // set the day number block
        $result .= '<a href="./?'. URL_DAY.'='. $day .'" class="day-row '. self::getDayColorClass($day, TRUE) .'"><span>'. $day .'</span></a>';
        // set the title
        $result .= '<h1><span>';
        if (!empty($title)) { $result .= $title; }
        else { $result .= 'december'; }
        $result .= '</span></h1>';
        // clearfix
        $result .= '<div class="clearfix"></div>';

        // display image
        $result .= '<div class="text-center"><img src="./?'.URL_PHOTO.'='. $day .'" class="img-responsive img-thumbnail" alt="'. $day .'. december" />';
        // do we have a legend?
        if (!empty($legend)) { $result .= '<p class="legend">&mdash; '.$legend.'</p>'; }
        $result .= '</div>';
        // clearfix
        $result .= '<div class="clearfix"></div>';

        // do we have a text?
        if (!empty($text)) { $result .= '<div class="text panel panel-default"><div class="panel-body">'.$text.'</div></div>'; }

        // we do not forget the pagination
        $result .= '<ul class="pager"><li class="previous';
        if (self::isActiveDay($day-1) && ($day-1)>=FIRST_DAY) { $result .= '"><a href="?'. URL_DAY .'='. ($day-1) .'" title="i går" class="tip" data-placement="right">'; }
        else { $result .= ' disabled"><a>'; }
        $result .= '<i class="glyphicon glyphicon-hand-left"></i></a></li><li class="next';
        if (self::isActiveDay($day+1) && ($day+1)<=LAST_DAY) { $result .= '"><a href="?'. URL_DAY .'='. ($day+1) .'" title="i morgen" class="tip" data-placement="left">'; }
        else { $result .= ' disabled"><a>'; }
        $result .= '<i class="glyphicon glyphicon-hand-right"></i></a></li></ul>';

        return $result.'</div>';
    }


HELE INDEX.PHP-FILEN:
<?php

error_reporting(0);

// constants to be used
define('ADVENT_CALENDAR', 'Julekalender');
define('URL_DAY', 'day');
define('URL_PHOTO', 'photo');
define('URL_ABOUT', 'about');
define('URL_RSS', 'rss');
define('PRIVATE_FOLDER', './private');
define('SETTINGS_FILE', PRIVATE_FOLDER.'/settings.json');
define('CALENDAR_FILE', PRIVATE_FOLDER.'/calendar.json');
define('RSS_CACHE_FILE', PRIVATE_FOLDER.'/rss_cache.xml');

// load settings from file
if (file_exists(SETTINGS_FILE)) {
    $settings = json_decode(file_get_contents(SETTINGS_FILE));

    define('TITLE', $settings->title);
    define('YEAR', $settings->year);

    // is it an other month?
    if (isset($settings->month) && !empty($settings->month) && $settings->month > 1 && $settings->month <= 12) { define('MONTH', date('m', mktime(0, 0, 0, $settings->month+0))); }
    else { define('MONTH', 12); }
    // is it an other begin day?
    if (isset($settings->first_day) && !empty($settings->first_day) && $settings->first_day > 0 && $settings->first_day <= 31) { define('FIRST_DAY', date('d', mktime(0, 0, 0, MONTH, $settings->first_day))); }
    else { define('FIRST_DAY', '01'); }
    // is it an other last day?
    if (isset($settings->last_day) && !empty($settings->last_day) && $settings->last_day > FIRST_DAY && $settings->last_day <= 31) { define('LAST_DAY', date('d', mktime(0, 0, 0, MONTH, $settings->last_day))); }
    else { define('LAST_DAY', '24'); }

    // is it a private calendar?
    if (isset($settings->passkey) && !empty($settings->passkey)) { define('PASSKEY', $settings->passkey); }

    // do the user want an other background?
    if (isset($settings->background) && $settings->background == 'alternate') { define('ALTERNATE_BACKGROUND', TRUE); }

    }
}
else { die('<!doctype html><html><head><title>'.ADVENT_CALENDAR.'</title><style>body{width:600px;margin:50px auto 20px;}</style></head><body><div style="font-size:30px;"><strong>Oups!</strong> Settings file not found.</div><div><p>Edit <code>private/settings.example.json</code> to personnalize title and year and rename it <code>settings.json</code>.</p><p>If it is not already done, put your photos in the <code>private/</code> folder, and name them with the number of the day you want to illustrate.</p></div></body></html>'); }

// is the directory writable ?
if (!is_writable(realpath(dirname(__FILE__)))) die('<div><strong>Oups!</strong> Application does not have the right to write in its own directory <code>'.realpath(dirname(__FILE__)).'</code>.</div>');
// is the private folder already created? yes, with a .htaccess file
/*if (!is_dir(PRIVATE_FOLDER)) { mkdir(PRIVATE_FOLDER,0705); chmod($_CONFIG['data'],0705); }*/
// are photos deny from web access? [just in case]
if (!is_file(PRIVATE_FOLDER.'/.htaccess')) { file_put_contents(PRIVATE_FOLDER.'/.htaccess', 'Deny from all'); }
if (!is_file(PRIVATE_FOLDER.'/.htaccess')) die('<div><strong>Oups!</strong> Application does not have the right to write in its own directory <code>'.realpath(dirname(__FILE__)).'</code>.</div>');

/*
*  Core classes
*/
abstract class AddOns {
    const Data = 'data';
    const Name = 'name';

    static private $addons = Array();

    static function Register(Array $addon) {
        if (empty($addon[self::Data])) { $addon[self::Data] = TRUE; }
        self::$addons[$addon['name']] = $addon[self::Data];
    }

    static function AddOn($name, $data = TRUE) {
        return array(self::Name => $name, self::Data => $data);
    }

    static function Found($name) {
        return isset(self::$addons[$name]);
    }

    static function Get($name) {
        if (! self::Found($name)) { return; }
        return self::$addons[$name];
    }

    static function JavaScriptRegistred() {
        self::Register(self::AddOn('js'));
    }

    static function JsonToArray($json) {
        return json_decode(json_encode($json), TRUE);
    }
}

abstract class Image {
    static function get($day) {

        $img = self::getInfo($day);

        if (!empty($img)) {
            header('Content-type: '.$img['type']);
            exit(file_get_contents($img['path']));
        }

        header('Location: ./');
        exit();
    }

    static function getInfo($day) {
        $result = array();
        // check if we can display the request photo
        if (Advent::acceptDay($day) && Advent::isActiveDay($day)) {
            $day = $day;
            $result['url'] = '?'.URL_PHOTO.'='.$day;

            $extension = '.jpg';
            // if .jpg does not exist, load .jpeg photo
            if (! self::exists($day.$extension)) {
                $extension = '.jpeg';
                // in case of .jpg or .jpeg file is not found
                if (! self::exists($day.$extension)) {
                    // enhancement #8: use a default image when not found
                    $result['type'] = 'image/png';
                    $result['path'] = './assets/404.png';
                    return $result;
                }
            }
            $result['type'] = 'image/jpeg';
            $result['path'] = PRIVATE_FOLDER.'/'.$day.$extension;

            return $result;
        }
        return NULL;
    }

    static private function exists($file) {
        return file_exists(PRIVATE_FOLDER.'/'.$file);
    }
}

class Day {

    public $day;
    public $active;
    public $url;
    public $title = NULL;
    public $legend = NULL;
    public $text = NULL;

    public function __default($day) {
        $this->day = $day;
        $this->active = Advent::isActiveDay($day);
        $this->url = '?'. URL_DAY .'='. ($this->day);
    }
    public function __construct($day, $title = NULL, $legend = NULL, $text = NULL) {
        $this->__default($day);
        $this->title = $title;
        $this->legend = $legend;
        $this->text = $text;
    }
}

abstract class Advent {

    const BEFORE_ADVENT = -1;
    const CURRENT_ADVENT = 0;
    const AFTER_ADVENT = 1;

    static function state() {
        $now = date('Ymd');

        // if we are before the advent
        if ($now < YEAR.MONTH.FIRST_DAY) { return self::BEFORE_ADVENT; }
        // if we are after
        if ($now > YEAR.MONTH.LAST_DAY) { return self::AFTER_ADVENT; }
        // else we are currently in advent \o/
        return self::CURRENT_ADVENT;
    }

    static function acceptDay($day) {
        return $day >= FIRST_DAY && $day <= LAST_DAY;
    }

    static function isActiveDay($day) {
        $state = self::state();
        return ($state == self::CURRENT_ADVENT && $day <= date('d')) || $state == self::AFTER_ADVENT;
    }

    static private function getDayColorClass($day, $active = FALSE) {
        $result = '';
        // is the day active ?
        if ($active) { $result .= 'active '; }
        // set a color for the background
        $result .= 'day-color-'.($day%4 + 1);
        return $result;
    }

    static function getDays() {
        $result = array();
        for ($i=FIRST_DAY+0; $i<=LAST_DAY; $i++) {
            $result[] = new Day($i);
        }
        return $result;
    }

    static function getFullDays() {
        $result = array();
        for ($i=FIRST_DAY+0; $i<=LAST_DAY; $i++) {
            $result[] = self::getDay($i);
        }
        return $result;
    }

    static function getDaysHtml() {
        $result = '<div class="container days">';
        foreach (self::getDays() as $d) {
            if ($d->active) { $result .= '<a href="'. $d->url .'" title="'. ($d->day) .'. december"'; }
            else { $result .= '<div'; }
            $result .= ' class="day-row '. self::getDayColorClass($d->day, $d->active) .'"><span>'. ($d->day) .'</span>';
            if ($d->active) { $result .= '</a>'; }
            else { $result .= '</div>'; }
        }
        return $result.'</div>';
    }

    static function getDay($day) {
        $title = NULL;
        $legend = NULL;
        $text = NULL;
        // check if we have info to display
        if (file_exists(CALENDAR_FILE)) {
            $file = json_decode(file_get_contents(CALENDAR_FILE));
            $day = $day == FIRST_DAY ? ($day+0) : $day;
            if (!empty($file->{$day})) {
                if (!empty($file->{$day}->title)) { $title = htmlspecialchars($file->{$day}->title); }
                if (!empty($file->{$day}->legend)) { $legend = htmlspecialchars($file->{$day}->legend); }
                if (!empty($file->{$day}->text)) { $text = $file->{$day}->text; }
            }
        }
        return new Day($day, $title, $legend, $text);
    }

    static function getDayHtml($day) {
        $result = '<div class="container day">';

        $d = self::getDay($day);
        $title = $d->title;
        $legend = $d->legend;
        $text = $d->text;

        // set the day number block
        $result .= '<a href="./?'. URL_DAY.'='. $day .'" class="day-row '. self::getDayColorClass($day, TRUE) .'"><span>'. $day .'</span></a>';
        // set the title
        $result .= '<h1><span>';
        if (!empty($title)) { $result .= $title; }
        else { $result .= 'december'; }
        $result .= '</span></h1>';
        // clearfix
        $result .= '<div class="clearfix"></div>';

        // display image
        $result .= '<div class="text-center"><img src="./?'.URL_PHOTO.'='. $day .'" class="img-responsive img-thumbnail" alt="'. $day .'. december" />';
        // do we have a legend?
        if (!empty($legend)) { $result .= '<p class="legend">&mdash; '.$legend.'</p>'; }
        $result .= '</div>';
        // clearfix
        $result .= '<div class="clearfix"></div>';

        // do we have a text?
        if (!empty($text)) { $result .= '<div class="text panel panel-default"><div class="panel-body">'.$text.'</div></div>'; }

        // we do not forget the pagination
        $result .= '<ul class="pager"><li class="previous';
        if (self::isActiveDay($day-1) && ($day-1)>=FIRST_DAY) { $result .= '"><a href="?'. URL_DAY .'='. ($day-1) .'" title="i går" class="tip" data-placement="right">'; }
        else { $result .= ' disabled"><a>'; }
        $result .= '<i class="glyphicon glyphicon-hand-left"></i></a></li><li class="next';
        if (self::isActiveDay($day+1) && ($day+1)<=LAST_DAY) { $result .= '"><a href="?'. URL_DAY .'='. ($day+1) .'" title="i morgen" class="tip" data-placement="left">'; }
        else { $result .= ' disabled"><a>'; }
        $result .= '<i class="glyphicon glyphicon-hand-right"></i></a></li></ul>';

        return $result.'</div>';
    }

    function bePatient($day) {
        return '<div class="container error"><div class="panel panel-info"><div class="panel-heading"><h3 class="panel-title">Juleaften nærmer sig!</h3></div><div class="panel-body">Men vær <strong>tålmodig</strong>, den '. $day .' december er om få dage. <a href="./" class="illustration text-center tip" title="forsiden"><i class="glyphicon glyphicon-home"></i></a></div></div></div>';
    }

}

abstract class RSS {

    static protected function escape($string) {
        return '<![CDATA['.$string.']]>';
    }

    static function url() {
        return (empty($_SERVER['REQUEST_SCHEME']) ? 'http' : $_SERVER['REQUEST_SCHEME']).'://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']).'/';
    }

    static public function get() {
        header('Content-Type: application/rss+xml; charset=utf-8');

        // can we display the cache?
        if (file_exists(RSS_CACHE_FILE) && date("j", filemtime(RSS_CACHE_FILE)) <= date("j")) {
            exit(file_get_contents(RSS_CACHE_FILE));
        }

        $URL = self::url();
        $xml  = '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
        $xml .= '<rss version="2.0"  xmlns:atom="http://www.w3.org/2005/Atom">'.PHP_EOL;
        $xml .= '<channel>'.PHP_EOL;
        $xml .= '<atom:link href="'.$URL.'?'.URL_RSS.'" rel="self" type="application/rss+xml" />'.PHP_EOL;
        $xml .= '<title>'.self::escape(TITLE).'</title>'.PHP_EOL;
        $xml .= '<link>'.$URL.'</link>'.PHP_EOL;
        $xml .= '<description>'.self::escape('RSS feed of '.TITLE. ' · Julekalender').'</description>'.PHP_EOL;
        $xml .= '<pubDate>'.date("D, d M Y H:i:s O", (file_exists(RSS_CACHE_FILE) ? filemtime(RSS_CACHE_FILE) : time())).'</pubDate>'.PHP_EOL;
        $xml .= '<ttl>1440</ttl>'.PHP_EOL; // 24 hours
        $xml .= '<copyright>'.$URL.'</copyright>'.PHP_EOL;
        $xml .= '<language>da-DK</language>'.PHP_EOL;
        $xml .= '<generator>Julekalender</generator>'.PHP_EOL;
        $xml .= '<image>'.PHP_EOL;
        $xml .= '<title>'.self::escape(TITLE).'</title>'.PHP_EOL;
        $xml .= '<url>'.$URL.'assets/favicon.png</url>'.PHP_EOL;
        $xml .= '<link>'.$URL.'</link>'.PHP_EOL;
        $xml .= '<width>48</width>'.PHP_EOL;
        $xml .= '<height>48</height>'.PHP_EOL;
        $xml .= '</image>'.PHP_EOL;
        foreach (Advent::getFullDays() as $day) {
            if ($day->active) {
            $xml .= '<item>'.PHP_EOL;
            $xml .= '<title>'. (empty($day->title) ? 'Day '.$day->day : self::escape($day->title)) .'</title>'.PHP_EOL;
            $xml .= '<link>'.$URL.$day->url.'</link>'.PHP_EOL;
            $xml .= '<description>'.(empty($day->text) ? '' : self::escape($day->text)).'</description>'.PHP_EOL;
            $img = Image::getInfo($day->day);
            $xml .= '<enclosure url="'.$URL.$img['url'].'" length="'.filesize($img['path']).'" type="'.$img['type'].'" />'.PHP_EOL;
            $xml .= '<guid isPermaLink="false">'.$day->day.'</guid>'.PHP_EOL;
            $xml .= '<pubDate>'.date("D, d M Y 00:00:00 O", mktime(0, 0, 0, MONTH, $day->day, YEAR)).'</pubDate>'.PHP_EOL;
            $xml .= '<source url="'.$URL.'?'.URL_RSS.'">'.self::escape(TITLE).'</source>'.PHP_EOL;
            $xml .= '</item>'.PHP_EOL;
            }
        }
        $xml .= '</channel>'.PHP_EOL;
        $xml .= '</rss>'.PHP_EOL;

        file_put_contents(RSS_CACHE_FILE, $xml);
        exit($xml);
    }

    public function getLink() {
        return self::url().'?'.URL_RSS;
    }
}

/*
* Session management
*/

if (defined('PASSKEY')) {
    // for calendars on same server, set a different cookie name based on the script path
    session_name(md5($_SERVER['SCRIPT_NAME']));

    session_start();

    // want to log out
    if (isset($_GET['logout'])) {
        $_SESSION['welcome'] = FALSE;
        session_destroy();
        header('Location: ./');
        exit();
    }

    // want to log in
    if (isset($_POST['credential']) && !empty($_POST['credential'])) {
        if ($_POST['credential'] == PASSKEY) {
            $_SESSION['welcome'] = TRUE;
            header('Location: ./');
            exit();
        }
    }

    // not logged in: we ask passkey
    if (!isset($_SESSION['welcome']) || !$_SESSION['welcome']) {
        $loginRequested = TRUE;
    }
}

/*
* Load template
*/

$template = NULL;

// need to display log form?
if (defined('PASSKEY') && isset($loginRequested)) {
    $template = '
    <div class="container text-center">
        <div class="page-header"><h1 class="text-danger">This is a private area!</h1></div>
        <p>Please sign in with your <span class="font-normal">passkey</span> to continue.</p>
        <form method="post" role="form" class="espace-lg form-inline">
            <div class="form-group"><input type="password" name="credential" id="credential" class="form-control input-lg" autofocus required /></div>
            <button type="submit" class="btn btn-default btn-lg tip" data-placement="right" data-title="sign in"><i class="glyphicon glyphicon-user"></i></button>
        </form>
    </div>';
}
// want to see a photo ?
else if (isset($_GET[URL_PHOTO])) { Image::get($_GET[URL_PHOTO]+0); }
// nothing asked, display homepage
else if (empty($_GET)) {
    $template = Advent::getDaysHtml();
}
// want to display a day
else if (isset($_GET['day'])) {
    $day = $_GET['day'] + 0;
    if (! Advent::acceptDay($day)) { header('Location: ./'); exit(); }
    if (Advent::isActiveDay($day)) {
        $template = Advent::getDayHtml($day);
    }
    else { $template = Advent::bePatient($day); }
}

// rss feed is requested (only supported for no procted Advent Calendar)
if (isset($_GET[URL_RSS])) {
    if (!defined('PASSKEY')) { RSS::get(); }
    else {
        header('HTTP/1.1 501 Not Implemented', true, 501);
        $template = '
        <div class="container text-center">
            <div class="page-header"><h1 class="text-warning">Functionality not supported</h1></div>
            <div class="espace-lg">
                <p>The RSS feed is not available for a protected '.ADVENT_CALENDAR.'.</p>
                <p><a href="./" class="text-center tip" title="forsiden" data-placement="bottom"><i class="glyphicon glyphicon-home"></i></a></p>
            </div>
        </div>';
    }
}

// want to display about page [no need to be logged in to access]
if (isset($_GET[URL_ABOUT])) {
    // if ugly URL
    if (!empty($_GET[URL_ABOUT])) { header('Location: ./?'.URL_ABOUT); exit(); }
    $template = file_get_contents('./assets/about.html');
}

// default template is 404
if (empty($template)) {
    $template = '<div class="container error"><div class="panel panel-danger"><div class="panel-heading"><h3 class="panel-title">404 Not Found</h3></div><div class="panel-body">The requested URL was not found on this server. <a href="./" class="illustration illustration-danger text-center tip" title="forsiden"><i class="glyphicon glyphicon-home"></i></a></div></div></div>';
    header('HTTP/1.1 404 Not Found', true, 404);
}

// helper
$authentificated = defined('PASSKEY') && isset($_SESSION['welcome']);

?><!doctype html>
<html lang="fr">
    <head>
        <meta charset="UTF-8" />
        <title><?php echo TITLE, ' &middot; ', ADVENT_CALENDAR; ?></title>

        <!-- Parce quâ??il y a toujours un peu dâ??humain derrière un site... -->

        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <link rel="shortcut icon" type="image/x-icon" href="assets/favicon.ico" />
        <link rel="icon" type="image/png" href="assets/favicon.png" />

        <link href="assets/bootstrap.min.css" rel="stylesheet">
        <link href="assets/adventcalendar.css" rel="stylesheet">
        <link href="//fonts.googleapis.com/css?family=Lato:300,400,700" rel="stylesheet" type="text/css">

        <?php if (!defined('PASSKEY')): ?><link rel="alternate" type="application/rss+xml" href="<?php echo RSS::getLink(); ?>" title="<?php echo TITLE; ?>" /><?php endif; ?>
    </head>

    <body>

        <nav class="navbar navbar-default navbar-static-top" role="navigation">
        <div class="container">
        <div class="navbar-header">
        <a class="navbar-brand tip" href="./" title="forsiden" data-placement="right"><i class="glyphicon glyphicon-home"></i> <?php echo TITLE; ?></a>
        </div>

        <div class="collapse navbar-collapse" id="navbar-collapse">
        <ul class="nav navbar-nav navbar-right">
            <li><a href="./?<?php echo URL_ABOUT; ?>" class="tip" data-placement="left" title="hvorfor fejrer vi jul?"><i class="glyphicon glyphicon-tree-conifer"></i> Hvorfor fejrer vi jul?</a></li>
            <?php
            // logout
            if ($authentificated) { echo '<li><a href="./?logout" title="logout" class="tip" data-placement="bottom"><i class="glyphicon glyphicon-user"></i></a></li>'; }
            ?>
        </ul>
        </div>
        </div>
        </nav>

        <div class="background<?php if(defined('ALTERNATE_BACKGROUND')) { echo ' alternate-background'; } ?>">
        <?php
            echo $template;
        ?>
        </div>

        <footer>
        <hr />
        <div class="container">
            <p class="pull-right"><a href="#" id="goHomeYouAreDrunk" class="tip" data-placement="left" title="til toppen"><i class="glyphicon glyphicon-tree-conifer"></i></a></p>
            <div class="notice">
                <a href="http://www.forkyndelse.dk" rel="external"><?php echo ADVENT_CALENDAR; ?></a> &middot; Copyright Forkyndelse.dk og Carsten Riis Jensen
            </div>
        </div>
        </footer>

        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script src="assets/bootstrap.min.js"></script>
        <script src="assets/adventcalendar.js"></script>
        <?php if (AddOns::Found('js')): ?>
        <script>
            <?php if (AddOns::Found('disqus')): ?>
            var disqus_shortname = '<?php echo AddOns::Get("disqus"); ?>';
            (function() {
                var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
                dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
                (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
            })();
            <?php endif; ?>
            <?php if (AddOns::Found('ga')): $ga = AddOns::Get('ga'); ?>
            (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
                ga('create', '<?php echo $ga["tracking_id"]; ?>', '<?php echo $ga["domain"]; ?>');
                ga('send', 'pageview');
            <?php endif; ?>
            <?php if (AddOns::Found('piwik')): $piwik = AddOns::Get('piwik'); ?>
            var _paq = _paq || [];
            (function(){ var u='//<?php echo $piwik["piwik_url"]; ?>/'; _paq.push(['setSiteId', '<?php echo $piwik["site_id"]; ?>']); _paq.push(['setTrackerUrl', u+'piwik.php']); _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); })();
            <?php endif; ?>
        </script>
        <?php endif; ?>
    </body>
</html>
Avatar billede Mik2000 Professor
21. oktober 2016 - 14:06 #1
Uden på nogen måde at have kigget det igennem, så kunne jeg forstille mig at du blot kan ændre getDayHtml() til at indeholde

static function getDayHtml($day) {
    header("Location: "$day".html");
}

Så åbner den html fil der svarer til nummeret, såfremt day er et nummer svarende til datoen i december

Hvis den skal åbne i noget kan du hente indhold med file_get_contents eller lign. og hvis den skal åbne i noget overlay kan du benytte javascript og evt. AJAX.
Avatar billede crjensen Juniormester
21. oktober 2016 - 19:20 #2
Mange tak for dit forslag. Jeg vil lige sikre mig, at jeg har forstået dig rigtigt:

Hvis du kigger i den lange index.php fil ovenfor i mit indlæg, så har til getDayHtml($day) rettet, så det indeholder header("Location: "$day".html");
}

Jeg har så også SLETTET de efterfølgende linjer, FRA "$result = '<div... TIL  <div id="disqus_thread"></div>'; }

index.php ser derfor ud som nedenstående, men giver, når jeg uploader filen, en 500-fejl (se www.riisjensen.dk/julekalender). Har du tid og mulighed for at se, hvad jeg gør forkert, om jeg har slettet for meget, osv.?
De linjer, jeg har slettet, består jo af de rutiner i scriptet der fremstiller en julekalenderside, og de er jo overflødige, når jeg i stedet ønsker, at når folk klikker på en låge, så åbnes en færdiglavet html-side med nummer efter dagens nummer.

INDEX.PHP EFTER RETTELSE OG SLETNING:
<?php

error_reporting(0);

// constants to be used
define('ADVENT_CALENDAR', 'Julekalender');
define('URL_DAY', 'day');
define('URL_PHOTO', 'photo');
define('URL_ABOUT', 'about');
define('URL_RSS', 'rss');
define('PRIVATE_FOLDER', './private');
define('SETTINGS_FILE', PRIVATE_FOLDER.'/settings.json');
define('CALENDAR_FILE', PRIVATE_FOLDER.'/calendar.json');
define('RSS_CACHE_FILE', PRIVATE_FOLDER.'/rss_cache.xml');

// load settings from file
if (file_exists(SETTINGS_FILE)) {
    $settings = json_decode(file_get_contents(SETTINGS_FILE));

    define('TITLE', $settings->title);
    define('YEAR', $settings->year);

    // is it an other month?
    if (isset($settings->month) && !empty($settings->month) && $settings->month > 1 && $settings->month <= 12) { define('MONTH', date('m', mktime(0, 0, 0, $settings->month+0))); }
    else { define('MONTH', 12); }
    // is it an other begin day?
    if (isset($settings->first_day) && !empty($settings->first_day) && $settings->first_day > 0 && $settings->first_day <= 31) { define('FIRST_DAY', date('d', mktime(0, 0, 0, MONTH, $settings->first_day))); }
    else { define('FIRST_DAY', '01'); }
    // is it an other last day?
    if (isset($settings->last_day) && !empty($settings->last_day) && $settings->last_day > FIRST_DAY && $settings->last_day <= 31) { define('LAST_DAY', date('d', mktime(0, 0, 0, MONTH, $settings->last_day))); }
    else { define('LAST_DAY', '24'); }

    // is it a private calendar?
    if (isset($settings->passkey) && !empty($settings->passkey)) { define('PASSKEY', $settings->passkey); }

    // do the user want an other background?
    if (isset($settings->background) && $settings->background == 'alternate') { define('ALTERNATE_BACKGROUND', TRUE); }

    // want to add disqus thread?
    if (isset($settings->disqus_shortname) && !empty($settings->disqus_shortname)) {
        AddOns::Register(AddOns::AddOn('disqus', $settings->disqus_shortname));
        AddOns::JavaScriptRegistred();
    }
    // want to add google analytics?
    if (isset($settings->google_analytics) && !empty($settings->google_analytics) && isset($settings->google_analytics->tracking_id) && isset($settings->google_analytics->domain) ) {
        AddOns::Register(AddOns::AddOn('ga', AddOns::JsonToArray($settings->google_analytics)));
        AddOns::JavaScriptRegistred();
    }
    // want to add piwik?
    if (isset($settings->piwik) && !empty($settings->piwik) && isset($settings->piwik->piwik_url) && isset($settings->piwik->site_id) ) {
        AddOns::Register(AddOns::AddOn('piwik', AddOns::JsonToArray($settings->piwik)));
        AddOns::JavaScriptRegistred();
    }
}
else { die('<!doctype html><html><head><title>'.ADVENT_CALENDAR.'</title><style>body{width:600px;margin:50px auto 20px;}</style></head><body><div style="font-size:30px;"><strong>Oups!</strong> Settings file not found.</div><div><p>Edit <code>private/settings.example.json</code> to personnalize title and year and rename it <code>settings.json</code>.</p><p>If it is not already done, put your photos in the <code>private/</code> folder, and name them with the number of the day you want to illustrate.</p></div></body></html>'); }

// is the directory writable ?
if (!is_writable(realpath(dirname(__FILE__)))) die('<div><strong>Oups!</strong> Application does not have the right to write in its own directory <code>'.realpath(dirname(__FILE__)).'</code>.</div>');
// is the private folder already created? yes, with a .htaccess file
/*if (!is_dir(PRIVATE_FOLDER)) { mkdir(PRIVATE_FOLDER,0705); chmod($_CONFIG['data'],0705); }*/
// are photos deny from web access? [just in case]
if (!is_file(PRIVATE_FOLDER.'/.htaccess')) { file_put_contents(PRIVATE_FOLDER.'/.htaccess', 'Deny from all'); }
if (!is_file(PRIVATE_FOLDER.'/.htaccess')) die('<div><strong>Oups!</strong> Application does not have the right to write in its own directory <code>'.realpath(dirname(__FILE__)).'</code>.</div>');

/*
*  Core classes
*/
abstract class AddOns {
    const Data = 'data';
    const Name = 'name';

    static private $addons = Array();

    static function Register(Array $addon) {
        if (empty($addon[self::Data])) { $addon[self::Data] = TRUE; }
        self::$addons[$addon['name']] = $addon[self::Data];
    }

    static function AddOn($name, $data = TRUE) {
        return array(self::Name => $name, self::Data => $data);
    }

    static function Found($name) {
        return isset(self::$addons[$name]);
    }

    static function Get($name) {
        if (! self::Found($name)) { return; }
        return self::$addons[$name];
    }

    static function JavaScriptRegistred() {
        self::Register(self::AddOn('js'));
    }

    static function JsonToArray($json) {
        return json_decode(json_encode($json), TRUE);
    }
}

abstract class Image {
    static function get($day) {

        $img = self::getInfo($day);

        if (!empty($img)) {
            header('Content-type: '.$img['type']);
            exit(file_get_contents($img['path']));
        }

        header('Location: ./');
        exit();
    }

    static function getInfo($day) {
        $result = array();
        // check if we can display the request photo
        if (Advent::acceptDay($day) && Advent::isActiveDay($day)) {
            $day = $day;
            $result['url'] = '?'.URL_PHOTO.'='.$day;

            $extension = '.jpg';
            // if .jpg does not exist, load .jpeg photo
            if (! self::exists($day.$extension)) {
                $extension = '.jpeg';
                // in case of .jpg or .jpeg file is not found
                if (! self::exists($day.$extension)) {
                    // enhancement #8: use a default image when not found
                    $result['type'] = 'image/png';
                    $result['path'] = './assets/404.png';
                    return $result;
                }
            }
            $result['type'] = 'image/jpeg';
            $result['path'] = PRIVATE_FOLDER.'/'.$day.$extension;

            return $result;
        }
        return NULL;
    }

    static private function exists($file) {
        return file_exists(PRIVATE_FOLDER.'/'.$file);
    }
}

class Day {

    public $day;
    public $active;
    public $url;
    public $title = NULL;
    public $legend = NULL;
    public $text = NULL;

    public function __default($day) {
        $this->day = $day;
        $this->active = Advent::isActiveDay($day);
        $this->url = '?'. URL_DAY .'='. ($this->day);
    }
    public function __construct($day, $title = NULL, $legend = NULL, $text = NULL) {
        $this->__default($day);
        $this->title = $title;
        $this->legend = $legend;
        $this->text = $text;
    }
}

abstract class Advent {

    const BEFORE_ADVENT = -1;
    const CURRENT_ADVENT = 0;
    const AFTER_ADVENT = 1;

    static function state() {
        $now = date('Ymd');

        // if we are before the advent
        if ($now < YEAR.MONTH.FIRST_DAY) { return self::BEFORE_ADVENT; }
        // if we are after
        if ($now > YEAR.MONTH.LAST_DAY) { return self::AFTER_ADVENT; }
        // else we are currently in advent \o/
        return self::CURRENT_ADVENT;
    }

    static function acceptDay($day) {
        return $day >= FIRST_DAY && $day <= LAST_DAY;
    }

    static function isActiveDay($day) {
        $state = self::state();
        return ($state == self::CURRENT_ADVENT && $day <= date('d')) || $state == self::AFTER_ADVENT;
    }

    static private function getDayColorClass($day, $active = FALSE) {
        $result = '';
        // is the day active ?
        if ($active) { $result .= 'active '; }
        // set a color for the background
        $result .= 'day-color-'.($day%4 + 1);
        return $result;
    }

    static function getDays() {
        $result = array();
        for ($i=FIRST_DAY+0; $i<=LAST_DAY; $i++) {
            $result[] = new Day($i);
        }
        return $result;
    }

    static function getFullDays() {
        $result = array();
        for ($i=FIRST_DAY+0; $i<=LAST_DAY; $i++) {
            $result[] = self::getDay($i);
        }
        return $result;
    }

    static function getDaysHtml() {
        $result = '<div class="container days">';
        foreach (self::getDays() as $d) {
            if ($d->active) { $result .= '<a href="'. $d->url .'" title="'. ($d->day) .'. december"'; }
            else { $result .= '<div'; }
            $result .= ' class="day-row '. self::getDayColorClass($d->day, $d->active) .'"><span>'. ($d->day) .'</span>';
            if ($d->active) { $result .= '</a>'; }
            else { $result .= '</div>'; }
        }
        return $result.'</div>';
    }

    static function getDay($day) {
        $title = NULL;
        $legend = NULL;
        $text = NULL;
        // check if we have info to display
        if (file_exists(CALENDAR_FILE)) {
            $file = json_decode(file_get_contents(CALENDAR_FILE));
            $day = $day == FIRST_DAY ? ($day+0) : $day;
            if (!empty($file->{$day})) {
                if (!empty($file->{$day}->title)) { $title = htmlspecialchars($file->{$day}->title); }
                if (!empty($file->{$day}->legend)) { $legend = htmlspecialchars($file->{$day}->legend); }
                if (!empty($file->{$day}->text)) { $text = $file->{$day}->text; }
            }
        }
        return new Day($day, $title, $legend, $text);
    }

    static function getDayHtml($day) {
        header("Location: "$day".html");
}
        return $result.'</div>';
    }

    function bePatient($day) {
        return '<div class="container error"><div class="panel panel-info"><div class="panel-heading"><h3 class="panel-title">Juleaften nærmer sig!</h3></div><div class="panel-body">Men vær <strong>tålmodig</strong>, den '. $day .' december er om få dage. <a href="./" class="illustration text-center tip" title="forsiden"><i class="glyphicon glyphicon-home"></i></a></div></div></div>';
    }

}

abstract class RSS {

    static protected function escape($string) {
        return '<![CDATA['.$string.']]>';
    }

    static function url() {
        return (empty($_SERVER['REQUEST_SCHEME']) ? 'http' : $_SERVER['REQUEST_SCHEME']).'://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['SCRIPT_NAME']).'/';
    }

    static public function get() {
        header('Content-Type: application/rss+xml; charset=utf-8');

        // can we display the cache?
        if (file_exists(RSS_CACHE_FILE) && date("j", filemtime(RSS_CACHE_FILE)) <= date("j")) {
            exit(file_get_contents(RSS_CACHE_FILE));
        }

        $URL = self::url();
        $xml  = '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
        $xml .= '<rss version="2.0"  xmlns:atom="http://www.w3.org/2005/Atom">'.PHP_EOL;
        $xml .= '<channel>'.PHP_EOL;
        $xml .= '<atom:link href="'.$URL.'?'.URL_RSS.'" rel="self" type="application/rss+xml" />'.PHP_EOL;
        $xml .= '<title>'.self::escape(TITLE).'</title>'.PHP_EOL;
        $xml .= '<link>'.$URL.'</link>'.PHP_EOL;
        $xml .= '<description>'.self::escape('RSS feed of '.TITLE. ' · Julekalender').'</description>'.PHP_EOL;
        $xml .= '<pubDate>'.date("D, d M Y H:i:s O", (file_exists(RSS_CACHE_FILE) ? filemtime(RSS_CACHE_FILE) : time())).'</pubDate>'.PHP_EOL;
        $xml .= '<ttl>1440</ttl>'.PHP_EOL; // 24 hours
        $xml .= '<copyright>'.$URL.'</copyright>'.PHP_EOL;
        $xml .= '<language>da-DK</language>'.PHP_EOL;
        $xml .= '<generator>Julekalender</generator>'.PHP_EOL;
        $xml .= '<image>'.PHP_EOL;
        $xml .= '<title>'.self::escape(TITLE).'</title>'.PHP_EOL;
        $xml .= '<url>'.$URL.'assets/favicon.png</url>'.PHP_EOL;
        $xml .= '<link>'.$URL.'</link>'.PHP_EOL;
        $xml .= '<width>48</width>'.PHP_EOL;
        $xml .= '<height>48</height>'.PHP_EOL;
        $xml .= '</image>'.PHP_EOL;
        foreach (Advent::getFullDays() as $day) {
            if ($day->active) {
            $xml .= '<item>'.PHP_EOL;
            $xml .= '<title>'. (empty($day->title) ? 'Day '.$day->day : self::escape($day->title)) .'</title>'.PHP_EOL;
            $xml .= '<link>'.$URL.$day->url.'</link>'.PHP_EOL;
            $xml .= '<description>'.(empty($day->text) ? '' : self::escape($day->text)).'</description>'.PHP_EOL;
            $img = Image::getInfo($day->day);
            $xml .= '<enclosure url="'.$URL.$img['url'].'" length="'.filesize($img['path']).'" type="'.$img['type'].'" />'.PHP_EOL;
            $xml .= '<guid isPermaLink="false">'.$day->day.'</guid>'.PHP_EOL;
            $xml .= '<pubDate>'.date("D, d M Y 00:00:00 O", mktime(0, 0, 0, MONTH, $day->day, YEAR)).'</pubDate>'.PHP_EOL;
            $xml .= '<source url="'.$URL.'?'.URL_RSS.'">'.self::escape(TITLE).'</source>'.PHP_EOL;
            $xml .= '</item>'.PHP_EOL;
            }
        }
        $xml .= '</channel>'.PHP_EOL;
        $xml .= '</rss>'.PHP_EOL;

        file_put_contents(RSS_CACHE_FILE, $xml);
        exit($xml);
    }

    public function getLink() {
        return self::url().'?'.URL_RSS;
    }
}

/*
* Session management
*/

if (defined('PASSKEY')) {
    // for calendars on same server, set a different cookie name based on the script path
    session_name(md5($_SERVER['SCRIPT_NAME']));

    session_start();

    // want to log out
    if (isset($_GET['logout'])) {
        $_SESSION['welcome'] = FALSE;
        session_destroy();
        header('Location: ./');
        exit();
    }

    // want to log in
    if (isset($_POST['credential']) && !empty($_POST['credential'])) {
        if ($_POST['credential'] == PASSKEY) {
            $_SESSION['welcome'] = TRUE;
            header('Location: ./');
            exit();
        }
    }

    // not logged in: we ask passkey
    if (!isset($_SESSION['welcome']) || !$_SESSION['welcome']) {
        $loginRequested = TRUE;
    }
}

/*
* Load template
*/

$template = NULL;

// need to display log form?
if (defined('PASSKEY') && isset($loginRequested)) {
    $template = '
    <div class="container text-center">
        <div class="page-header"><h1 class="text-danger">This is a private area!</h1></div>
        <p>Please sign in with your <span class="font-normal">passkey</span> to continue.</p>
        <form method="post" role="form" class="espace-lg form-inline">
            <div class="form-group"><input type="password" name="credential" id="credential" class="form-control input-lg" autofocus required /></div>
            <button type="submit" class="btn btn-default btn-lg tip" data-placement="right" data-title="sign in"><i class="glyphicon glyphicon-user"></i></button>
        </form>
    </div>';
}
// want to see a photo ?
else if (isset($_GET[URL_PHOTO])) { Image::get($_GET[URL_PHOTO]+0); }
// nothing asked, display homepage
else if (empty($_GET)) {
    $template = Advent::getDaysHtml();
}
// want to display a day
else if (isset($_GET['day'])) {
    $day = $_GET['day'] + 0;
    if (! Advent::acceptDay($day)) { header('Location: ./'); exit(); }
    if (Advent::isActiveDay($day)) {
        $template = Advent::getDayHtml($day);
    }
    else { $template = Advent::bePatient($day); }
}

// rss feed is requested (only supported for no procted Advent Calendar)
if (isset($_GET[URL_RSS])) {
    if (!defined('PASSKEY')) { RSS::get(); }
    else {
        header('HTTP/1.1 501 Not Implemented', true, 501);
        $template = '
        <div class="container text-center">
            <div class="page-header"><h1 class="text-warning">Functionality not supported</h1></div>
            <div class="espace-lg">
                <p>The RSS feed is not available for a protected '.ADVENT_CALENDAR.'.</p>
                <p><a href="./" class="text-center tip" title="forsiden" data-placement="bottom"><i class="glyphicon glyphicon-home"></i></a></p>
            </div>
        </div>';
    }
}

// want to display about page [no need to be logged in to access]
if (isset($_GET[URL_ABOUT])) {
    // if ugly URL
    if (!empty($_GET[URL_ABOUT])) { header('Location: ./?'.URL_ABOUT); exit(); }
    $template = file_get_contents('./assets/about.html');
}

// default template is 404
if (empty($template)) {
    $template = '<div class="container error"><div class="panel panel-danger"><div class="panel-heading"><h3 class="panel-title">404 Not Found</h3></div><div class="panel-body">The requested URL was not found on this server. <a href="./" class="illustration illustration-danger text-center tip" title="forsiden"><i class="glyphicon glyphicon-home"></i></a></div></div></div>';
    header('HTTP/1.1 404 Not Found', true, 404);
}

// helper
$authentificated = defined('PASSKEY') && isset($_SESSION['welcome']);

?><!doctype html>
<html lang="fr">
    <head>
        <meta charset="UTF-8" />
        <title><?php echo TITLE, ' &middot; ', ADVENT_CALENDAR; ?></title>

        <!-- Parce quâ??il y a toujours un peu dâ??humain derrière un site... -->

        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <link rel="shortcut icon" type="image/x-icon" href="assets/favicon.ico" />
        <link rel="icon" type="image/png" href="assets/favicon.png" />

        <link href="assets/bootstrap.min.css" rel="stylesheet">
        <link href="assets/adventcalendar.css" rel="stylesheet">
        <link href="//fonts.googleapis.com/css?family=Lato:300,400,700" rel="stylesheet" type="text/css">

        <?php if (!defined('PASSKEY')): ?><link rel="alternate" type="application/rss+xml" href="<?php echo RSS::getLink(); ?>" title="<?php echo TITLE; ?>" /><?php endif; ?>
    </head>

    <body>

        <nav class="navbar navbar-default navbar-static-top" role="navigation">
        <div class="container">
        <div class="navbar-header">
        <a class="navbar-brand tip" href="./" title="forsiden" data-placement="right"><i class="glyphicon glyphicon-home"></i> <?php echo TITLE; ?></a>
        </div>

        <div class="collapse navbar-collapse" id="navbar-collapse">
        <ul class="nav navbar-nav navbar-right">
            <li><a href="./?<?php echo URL_ABOUT; ?>" class="tip" data-placement="left" title="hvorfor fejrer vi jul?"><i class="glyphicon glyphicon-tree-conifer"></i> Hvorfor fejrer vi jul?</a></li>
            <?php
            // logout
            if ($authentificated) { echo '<li><a href="./?logout" title="logout" class="tip" data-placement="bottom"><i class="glyphicon glyphicon-user"></i></a></li>'; }
            ?>
        </ul>
        </div>
        </div>
        </nav>

        <div class="background<?php if(defined('ALTERNATE_BACKGROUND')) { echo ' alternate-background'; } ?>">
        <?php
            echo $template;
        ?>
        </div>

        <footer>
        <hr />
        <div class="container">
            <p class="pull-right"><a href="#" id="goHomeYouAreDrunk" class="tip" data-placement="left" title="til toppen"><i class="glyphicon glyphicon-tree-conifer"></i></a></p>
            <div class="notice">
                <a href="http://www.forkyndelse.dk" rel="external"><?php echo ADVENT_CALENDAR; ?></a> &middot; Copyright Forkyndelse.dk og Carsten Riis Jensen
            </div>
        </div>
        </footer>

        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script src="assets/bootstrap.min.js"></script>
        <script src="assets/adventcalendar.js"></script>
        <?php if (AddOns::Found('js')): ?>
        <script>
            <?php if (AddOns::Found('disqus')): ?>
            var disqus_shortname = '<?php echo AddOns::Get("disqus"); ?>';
            (function() {
                var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
                dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
                (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
            })();
            <?php endif; ?>
            <?php if (AddOns::Found('ga')): $ga = AddOns::Get('ga'); ?>
            (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
                ga('create', '<?php echo $ga["tracking_id"]; ?>', '<?php echo $ga["domain"]; ?>');
                ga('send', 'pageview');
            <?php endif; ?>
            <?php if (AddOns::Found('piwik')): $piwik = AddOns::Get('piwik'); ?>
            var _paq = _paq || [];
            (function(){ var u='//<?php echo $piwik["piwik_url"]; ?>/'; _paq.push(['setSiteId', '<?php echo $piwik["site_id"]; ?>']); _paq.push(['setTrackerUrl', u+'piwik.php']); _paq.push(['trackPageView']); _paq.push(['enableLinkTracking']); var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s); })();
            <?php endif; ?>
        </script>
        <?php endif; ?>
    </body>
</html>
Avatar billede olsensweb.dk Ekspert
21. oktober 2016 - 23:01 #3
prøv at slå error_reporting til
lave denne linje
error_reporting(0);
om til
error_reporting(E_ALL);
eller
error_reporting(-1);

det kunne muligvis give et hint hvad der fejler


prøv at lave denne

static function getDayHtml($day) {
    header("Location: "$day".html");
    }
    return $result . '</div>';
}

om til

static function getDayHtml($day) {
    header("Location: ".$day.".html");
    }
    return $result . '</div>';
}

her melder netbeans syntax fejl

hvor ville det være rart hvis man kunne pakke coden ind i en block der var foldet sammen, så ville indlægget være nemmere at læse.
det er noget af det, jeg godt kan lide ved udvikleren.dk
Avatar billede olsensweb.dk Ekspert
21. oktober 2016 - 23:04 #4
ups skal se sådan ud

static function getDayHtml($day) {
    header("Location: ".$day.".html");   
}
Avatar billede crjensen Juniormester
21. oktober 2016 - 23:42 #5
Tak for hjælpen, Olsen:
Som du kan se på www.riisjensen.dk/julekalender så har jeg uploadet den nu tilrettede fil, hvor jeg har indført dit forslag og slettet de linjer, der skaber en php-side.
Som du kan se, nærmer vi os målet - men når man fører musen hen over en "låge", kan man se at scriptet stadig forsøger at lave en "?day=N" side.
Hvis du har tid og mulighed for at hjælpe mig igen, vil jeg være meget taknemmelig:
Som det ser ud nu, mangler der kun lidt i, at et klik på en låge kan åbne en N.html eller for den sags skyld N.php side.
Jeg har lavet to RAR-pakker, så du kan se alle filerne:
Første pakke indeholder den originale index.php fil og den rettede, som er uploadet pt. (www.riisjensen.dk/julekalender/julekalender.rar)
Den anden pakke indeholder hele det originale julekalender-script, inklusiv alle de øvrige filer der hører til (www.riisjensen.dk/julekalender/julekalenderpakke.rar)

Carsten.
Avatar billede olsensweb.dk Ekspert
22. oktober 2016 - 00:21 #6
i class Day
ret

public function __default($day) {
    $this->day = $day;
    $this->active = Advent::isActiveDay($day);
    $this->url = '?'. URL_DAY .'='. ($this->day);   
}


til

public function __default($day) {
    $this->day = $day;
    $this->active = Advent::isActiveDay($day);
    $this->url = $this->day.".html";
}
Avatar billede crjensen Juniormester
22. oktober 2016 - 00:31 #7
Olsen, tusind tak for din hjælp! Det fungerer!
Carsten.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester