logo

blog

Unnamed repository; edit this file 'description' to name the repository.
commit 02cd3ff0f7d625bf3b355743725aa653605f0293
parent 8be7061a48e64e721f1ac99cae6ddd52a7655292
Author: lanodan <lanodan.delta@free.fr>
Date:   Sun,  8 Jun 2014 01:10:02 +0200

This is only an Update

Diffstat:
css/basic.css | 15++++++++++-----
css/navbar.css | 1+
index.php | 32++++++++++++++++++++------------
lang/lang.php | 7+++----
post.php | 22++++++++++++++--------
rss.php | 24++++++++++++++----------
6 files changed, 62 insertions(+), 39 deletions(-)

diff --git a/css/basic.css b/css/basic.css @@ -12,7 +12,7 @@ a { text-decoration: none; } a:hover {text-decoration: underline;} -article { +section.post { box-shadow: 0px 0px 10px 0px; padding: 10px; margin: 10px; @@ -25,6 +25,11 @@ code { text-align: left; font: monospace; } +h1,h2,h3,h4,h5,h6 { + text-decoration: underline; +} +strong.bold {display: block;} +ul,ol {margin-left: 2em;} #content { margin: 20px; text-align: center; @@ -34,7 +39,7 @@ code { background-color: rgba(255, 60, 0, 0.2); border-bottom: 2px solid #FF3C00; } -.bold {font-weight: bold;} -.code_comment {color: blue;} -strong.bold {display: block;} -ol, ul, li {list-style: none;} +.tags { + font-family: monospace; + font-style: italic; +} diff --git a/css/navbar.css b/css/navbar.css @@ -13,6 +13,7 @@ nav a { nav ul { list-style: none; display: inline-block; + margin-left: 0; } nav ul li { transition: 0.5s; diff --git a/index.php b/index.php @@ -2,15 +2,15 @@ require_once 'lang/lang.php'; require_once 'config.php'; - $link = mysqli_connect($mysql['host'], $mysql['user'], $mysql['passwd'], $mysql['database']); - $query = 'SELECT * FROM '.$mysql['table'].' ORDER by id'; + $mysqli = new mysqli($mysql['host'], $mysql['user'], $mysql['passwd'], $mysql['database']); if (mysqli_connect_errno()) { print 'Connect failed: '.mysqli_connect_error(); exit(); } - $result = mysqli_query($link, $query); + $query = 'SELECT * FROM '.$mysql['table'].' ORDER by id DESC'; + $result = $mysqli->query($query); ?> <!DOCTYPE html> @@ -26,16 +26,24 @@ <?php include 'navbar.php'; ?> <section id=content> <?php - /* fetch associative array */ - $row = mysqli_fetch_array($result, MYSQLI_ASSOC); - print ' <article> - <a href="post?id='.$row['id'].'"><h1>'.$row['title'].'</h1></a> - <p>'.$row['content'].'</p> - <div class="tags">'.$row['tags'].'</div> - </article>'."\n"; + while($row = $result->fetch_array()) { + $rows[] = $row; + } - mysqli_free_result($result); - mysqli_close($link); + foreach($rows as $row) { + print ' <article> + <a href="post?id='.$row['id'].'"><h1>'.$row['title'].'</h1></a> + '.$row['content'].' + <span class="tags">'.$row['tags'].'</span> + </article> + <hr/>'."\n"; + } + + # free result set + $result->close(); + + # close connection + $mysqli->close(); ?> </section> <?php include 'footer.php';?> diff --git a/lang/lang.php b/lang/lang.php @@ -1,12 +1,11 @@ <?php - $known_languages = array('fr', 'en'); //just add new language here when you need + $langs = array('fr', 'fr-FR', 'en', 'en-US', 'en-UK'); //just add new language here when you need if (empty($_COOKIE['lang'])) { - setcookie('lang', 'fr', '0', '/'); - $lang = 'fr'; + http_negociate_language($langs, $lang); + setcookie('lang', $lang, '0', '/'); } else { $lang = $_COOKIE['lang']; } - include 'lang/'.$lang.'.php'; ?> diff --git a/post.php b/post.php @@ -2,15 +2,22 @@ require_once 'lang/lang.php'; require_once 'config.php'; - $link = mysqli_connect($mysql['host'], $mysql['user'], $mysql['passwd'], $mysql['database']); - $query = 'SELECT * FROM '.$mysql['table'].' WHERE id = '.$_GET['id']; + $mysqli = new mysqli($mysql['host'], $mysql['user'], $mysql['passwd'], $mysql['database']); if (mysqli_connect_errno()) { print 'Connect failed: '.mysqli_connect_error(); exit(); } - $result = mysqli_query($link, $query); + $_id = $_GET['id']; + + if (!is_numeric($_id)) { + print '?id is not a number'; + exit(); + } + + $query = 'SELECT * FROM '.$mysql['table'].' WHERE id = '.$_id; + $result = $mysqli->query($query); ?> <!DOCTYPE html> @@ -27,15 +34,14 @@ <section id=content> <?php /* fetch associative array */ - $row = mysqli_fetch_array($result, MYSQLI_ASSOC); + $row = $result->fetch_array(); print ' <article> - <h1>'.$row['title'].'</h1> - <p>'.$row['content'].'</p> + '.$row['content'].' <div class="tags">'.$row['tags'].'</div> </article>'."\n"; - mysqli_free_result($result); - mysqli_close($link); + $result->close(); + $mysqli->close(); ?> </section> <?php include 'footer.php';?> diff --git a/rss.php b/rss.php @@ -8,29 +8,33 @@ header('Content-Type: application/xml; charset=UTF-8'); require_once 'config.php'; - $link = mysqli_connect($mysql['host'], $mysql['user'], $mysql['passwd'], $mysql['database']); - $query = 'SELECT * FROM '.$mysql['table'].' ORDER by id'; + $mysqli = new mysqli($mysql['host'], $mysql['user'], $mysql['passwd'], $mysql['database']); if (mysqli_connect_errno()) { print 'Connect failed: '.mysqli_connect_error(); exit(); } + $query = 'SELECT * FROM '.$mysql['table'].' ORDER by id DESC'; + $result = $mysqli->query($query); - $result = mysqli_query($link, $query); + while($row = $result->fetch_array()){ + $rows[] = $row; + } - /* fetch associative array */ - $row = mysqli_fetch_array($result, MYSQLI_ASSOC); - print ' <item> + foreach($rows as $row) { + print ' <item> + <title>'.$row['title'].'</title> <description>'.$row['description'].'</description> - <link>http://'.$_SERVER['HTTP_HOST'].'/post?id='.$row['id'].'</link> - <guid>'.$row['id'].'</guid> + <link>'.$row['link'].'</link> + <guid permalink>http://'.$_SERVER['HTTP_HOST'].'/post?id='.$row['id'].'</guid> <pubDate>'.$row['pubDate'].'</pubDate> <category>'.$row['tags'].'</category> </item>'."\n"; + } - mysqli_free_result($result); //print the results + $result->close(); - mysqli_close($link);//close the mysql connection + $mysqli->close(); ?> </channel> </rss>